Wed Jan 27 20:02:39 2016

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"

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=AST_MODPRI_APP_DEPEND)
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 49 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 = AST_MODPRI_APP_DEPEND 
)
static int h263_open ( struct ast_filestream s  )  [static]

Definition at line 56 of file format_h263.c.

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

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

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

Definition at line 68 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_subclass::codec, 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.

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

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

Definition at line 144 of file format_h263.c.

00145 {
00146    /* No way Jose */
00147    return -1;
00148 }

static off_t h263_tell ( struct ast_filestream fs  )  [static]

Definition at line 167 of file format_h263.c.

References ast_filestream::f.

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 150 of file format_h263.c.

References ast_log(), AST_LOG_WARNING, errno, and ast_filestream::f.

00151 {
00152    int fd;
00153    off_t cur;
00154 
00155    if ((fd = fileno(fs->f)) < 0) {
00156       ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for h263 filestream %p: %s\n", fs, strerror(errno));
00157       return -1;
00158    }
00159    if ((cur = ftello(fs->f)) < 0) {
00160       ast_log(AST_LOG_WARNING, "Unable to determine current position in h263 filestream %p: %s\n", fs, strerror(errno));
00161       return -1;
00162    }
00163    /* Truncate file to current length */
00164    return ftruncate(fd, cur);
00165 }

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

Definition at line 108 of file format_h263.c.

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

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

static int load_module ( void   )  [static]

Definition at line 187 of file format_h263.c.

References ast_format_register, AST_MODULE_LOAD_FAILURE, and AST_MODULE_LOAD_SUCCESS.

00188 {
00189    if (ast_format_register(&h263_f))
00190       return AST_MODULE_LOAD_FAILURE;
00191    return AST_MODULE_LOAD_SUCCESS;
00192 }

static int unload_module ( void   )  [static]

Definition at line 194 of file format_h263.c.

References ast_format_unregister(), and ast_format::name.

00195 {
00196    return ast_format_unregister(h263_f.name);
00197 }


Variable Documentation

struct ast_format h263_f [static]

Definition at line 173 of file format_h263.c.


Generated on 27 Jan 2016 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1