Mon Nov 24 15:34:37 2008

Asterisk developer's documentation


format_h263.c File Reference

Save to raw, headerless h263 data. More...

#include "asterisk.h"
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <sys/time.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include "asterisk/lock.h"
#include "asterisk/channel.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/sched.h"
#include "asterisk/module.h"
#include "asterisk/endian.h"

Go to the source code of this file.

Data Structures

struct  h263_desc

Defines

#define BUF_SIZE   32768

Functions

 AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Raw H.263 data")
static int h263_open (struct ast_filestream *s)
static struct ast_frameh263_read (struct ast_filestream *s, int *whennext)
static int h263_seek (struct ast_filestream *fs, off_t sample_offset, int whence)
static off_t h263_tell (struct ast_filestream *fs)
static int h263_trunc (struct ast_filestream *fs)
static int h263_write (struct ast_filestream *fs, struct ast_frame *f)
static int load_module (void)
static int unload_module (void)

Variables

static struct ast_format h263_f


Detailed Description

Save to raw, headerless h263 data.

Definition in file format_h263.c.


Define Documentation

#define BUF_SIZE   32768

Definition at line 58 of file format_h263.c.


Function Documentation

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Raw H.263 data"   
)

static int h263_open ( struct ast_filestream s  )  [static]

Definition at line 65 of file format_h263.c.

References ast_log(), LOG_WARNING, and s.

00066 {
00067    unsigned int ts;
00068    int res;
00069 
00070    if ((res = fread(&ts, 1, sizeof(ts), s->f)) < sizeof(ts)) {
00071       ast_log(LOG_WARNING, "Empty file!\n");
00072       return -1;
00073    }
00074    return 0;
00075 }

static struct ast_frame* h263_read ( struct ast_filestream s,
int *  whennext 
) [static]

Definition at line 77 of file format_h263.c.

References AST_FORMAT_H263, AST_FRAME_SET_BUFFER, AST_FRAME_VIDEO, AST_FRIENDLY_OFFSET, ast_log(), BUF_SIZE, errno, h263_desc::lastts, len, LOG_WARNING, s, and ast_frame::ts.

00078 {
00079    int res;
00080    int mark;
00081    unsigned short len;
00082    unsigned int ts;
00083    struct h263_desc *fs = (struct h263_desc *)s->_private;
00084 
00085    /* Send a frame from the file to the appropriate channel */
00086    if ((res = fread(&len, 1, sizeof(len), s->f)) < 1)
00087       return NULL;
00088    len = ntohs(len);
00089    mark = (len & 0x8000) ? 1 : 0;
00090    len &= 0x7fff;
00091    if (len > BUF_SIZE) {
00092       ast_log(LOG_WARNING, "Length %d is too long\n", len);
00093       return NULL;
00094    }
00095    s->fr.frametype = AST_FRAME_VIDEO;
00096    s->fr.subclass = AST_FORMAT_H263;
00097    s->fr.mallocd = 0;
00098    AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, len);
00099    if ((res = fread(s->fr.data, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
00100       if (res)
00101          ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
00102       return NULL;
00103    }
00104    s->fr.samples = fs->lastts;   /* XXX what ? */
00105    s->fr.datalen = len;
00106    s->fr.subclass |= mark;
00107    s->fr.delivery.tv_sec = 0;
00108    s->fr.delivery.tv_usec = 0;
00109    if ((res = fread(&ts, 1, sizeof(ts), s->f)) == sizeof(ts)) {
00110       fs->lastts = ntohl(ts);
00111       *whennext = fs->lastts * 4/45;
00112    } else
00113       *whennext = 0;
00114    return &s->fr;
00115 }

static int h263_seek ( struct ast_filestream fs,
off_t  sample_offset,
int  whence 
) [static]

Definition at line 153 of file format_h263.c.

00154 {
00155    /* No way Jose */
00156    return -1;
00157 }

static off_t h263_tell ( struct ast_filestream fs  )  [static]

Definition at line 167 of file format_h263.c.

References ast_filestream::f, and offset.

00168 {
00169    off_t offset = ftello(fs->f);
00170    return offset; /* XXX totally bogus, needs fixing */
00171 }

static int h263_trunc ( struct ast_filestream fs  )  [static]

Definition at line 159 of file format_h263.c.

References ast_filestream::f.

00160 {
00161    /* Truncate file to current length */
00162    if (ftruncate(fileno(fs->f), ftello(fs->f)) < 0)
00163       return -1;
00164    return 0;
00165 }

static int h263_write ( struct ast_filestream fs,
struct ast_frame f 
) [static]

Definition at line 117 of file format_h263.c.

References AST_FORMAT_H263, AST_FRAME_VIDEO, ast_log(), errno, ast_filestream::f, f, len, and LOG_WARNING.

00118 {
00119    int res;
00120    unsigned int ts;
00121    unsigned short len;
00122    int subclass;
00123    int mark=0;
00124    if (f->frametype != AST_FRAME_VIDEO) {
00125       ast_log(LOG_WARNING, "Asked to write non-video frame!\n");
00126       return -1;
00127    }
00128    subclass = f->subclass;
00129    if (subclass & 0x1)
00130       mark=0x8000;
00131    subclass &= ~0x1;
00132    if (subclass != AST_FORMAT_H263) {
00133       ast_log(LOG_WARNING, "Asked to write non-h263 frame (%d)!\n", f->subclass);
00134       return -1;
00135    }
00136    ts = htonl(f->samples);
00137    if ((res = fwrite(&ts, 1, sizeof(ts), fs->f)) != sizeof(ts)) {
00138          ast_log(LOG_WARNING, "Bad write (%d/4): %s\n", res, strerror(errno));
00139          return -1;
00140    }
00141    len = htons(f->datalen | mark);
00142    if ((res = fwrite(&len, 1, sizeof(len), fs->f)) != sizeof(len)) {
00143          ast_log(LOG_WARNING, "Bad write (%d/2): %s\n", res, strerror(errno));
00144          return -1;
00145    }
00146    if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) {
00147          ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
00148          return -1;
00149    }
00150    return 0;
00151 }

static int load_module ( void   )  [static]

Definition at line 187 of file format_h263.c.

References ast_format_register, and h263_f.

00188 {
00189    return ast_format_register(&h263_f);
00190 }

static int unload_module ( void   )  [static]

Definition at line 192 of file format_h263.c.

References ast_format_unregister(), h263_f, and ast_format::name.

00193 {
00194    return ast_format_unregister(h263_f.name);
00195 }  


Variable Documentation

struct ast_format h263_f [static]

Definition at line 173 of file format_h263.c.

Referenced by load_module(), and unload_module().


Generated on Mon Nov 24 15:34:37 2008 for Asterisk - the Open Source PBX by  doxygen 1.4.7