Tue Aug 24 20:35:56 2010

Asterisk developer's documentation


format_h263.c File Reference

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

#include "asterisk.h"
#include "asterisk/mod_format.h"
#include "asterisk/module.h"
#include "asterisk/endian.h"
Include dependency graph for format_h263.c:

Go to the source code of this file.

Data Structures

struct  h263_desc

Defines

#define BUF_SIZE   32768

Functions

 AST_MODULE_INFO (ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER,"Raw H.263 data",.load=load_module,.unload=unload_module,.load_pri=10,)
static int h263_open (struct ast_filestream *s)
static struct ast_frame * h263_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 45 of file format_h263.c.


Function Documentation

AST_MODULE_INFO ( ASTERISK_GPL_KEY  ,
AST_MODFLAG_LOAD_ORDER  ,
"Raw H.263 data"  ,
.  load = load_module,
.  unload = unload_module,
.  load_pri = 10 
)
static int h263_open ( struct ast_filestream *  s  )  [static]

Definition at line 52 of file format_h263.c.

References ast_log(), ast_filestream::f, and LOG_WARNING.

00053 {
00054    unsigned int ts;
00055    int res;
00056 
00057    if ((res = fread(&ts, 1, sizeof(ts), s->f)) < sizeof(ts)) {
00058       ast_log(LOG_WARNING, "Empty file!\n");
00059       return -1;
00060    }
00061    return 0;
00062 }

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

Definition at line 64 of file format_h263.c.

References ast_filestream::_private, AST_FORMAT_H263, AST_FRAME_SET_BUFFER, AST_FRAME_VIDEO, AST_FRIENDLY_OFFSET, ast_log(), ast_filestream::buf, BUF_SIZE, ast_frame::data, ast_frame::datalen, ast_frame::delivery, errno, ast_filestream::f, ast_filestream::fr, ast_frame::frametype, h263_desc::lastts, len(), LOG_WARNING, ast_frame::mallocd, ast_frame::ptr, ast_frame::samples, ast_frame::subclass, and ast_frame::ts.

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

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

Definition at line 140 of file format_h263.c.

00141 {
00142    /* No way Jose */
00143    return -1;
00144 }

static off_t h263_tell ( struct ast_filestream *  fs  )  [static]

Definition at line 154 of file format_h263.c.

References ast_filestream::f.

00155 {
00156    off_t offset = ftello(fs->f);
00157    return offset; /* XXX totally bogus, needs fixing */
00158 }

static int h263_trunc ( struct ast_filestream *  fs  )  [static]

Definition at line 146 of file format_h263.c.

References ast_filestream::f.

00147 {
00148    /* Truncate file to current length */
00149    if (ftruncate(fileno(fs->f), ftello(fs->f)) < 0)
00150       return -1;
00151    return 0;
00152 }

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

Definition at line 104 of file format_h263.c.

References AST_FORMAT_H263, AST_FRAME_VIDEO, ast_log(), ast_frame::data, ast_frame::datalen, errno, ast_filestream::f, ast_frame::frametype, fwrite, len(), LOG_WARNING, ast_frame::ptr, ast_frame::samples, and ast_frame::subclass.

00105 {
00106    int res;
00107    unsigned int ts;
00108    unsigned short len;
00109    int subclass;
00110    int mark=0;
00111    if (f->frametype != AST_FRAME_VIDEO) {
00112       ast_log(LOG_WARNING, "Asked to write non-video frame!\n");
00113       return -1;
00114    }
00115    subclass = f->subclass;
00116    if (subclass & 0x1)
00117       mark=0x8000;
00118    subclass &= ~0x1;
00119    if (subclass != AST_FORMAT_H263) {
00120       ast_log(LOG_WARNING, "Asked to write non-h263 frame (%d)!\n", f->subclass);
00121       return -1;
00122    }
00123    ts = htonl(f->samples);
00124    if ((res = fwrite(&ts, 1, sizeof(ts), fs->f)) != sizeof(ts)) {
00125          ast_log(LOG_WARNING, "Bad write (%d/4): %s\n", res, strerror(errno));
00126          return -1;
00127    }
00128    len = htons(f->datalen | mark);
00129    if ((res = fwrite(&len, 1, sizeof(len), fs->f)) != sizeof(len)) {
00130          ast_log(LOG_WARNING, "Bad write (%d/2): %s\n", res, strerror(errno));
00131          return -1;
00132    }
00133    if ((res = fwrite(f->data.ptr, 1, f->datalen, fs->f)) != f->datalen) {
00134          ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
00135          return -1;
00136    }
00137    return 0;
00138 }

static int load_module ( void   )  [static]

Definition at line 174 of file format_h263.c.

References ast_format_register, AST_MODULE_LOAD_FAILURE, and AST_MODULE_LOAD_SUCCESS.

00175 {
00176    if (ast_format_register(&h263_f))
00177       return AST_MODULE_LOAD_FAILURE;
00178    return AST_MODULE_LOAD_SUCCESS;
00179 }

static int unload_module ( void   )  [static]

Definition at line 181 of file format_h263.c.

References ast_format_unregister(), and ast_format::name.

00182 {
00183    return ast_format_unregister(h263_f.name);
00184 }  


Variable Documentation

struct ast_format h263_f [static]

Definition at line 160 of file format_h263.c.


Generated on 24 Aug 2010 for Asterisk - the Open Source PBX by  doxygen 1.6.1