Fri Jul 24 00:41:43 2009

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

static void __reg_module (void)
static void __unreg_module (void)
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_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Raw H.263 data" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, }
static struct ast_module_infoast_module_info = &__mod_info
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

static void __reg_module ( void   )  [static]

Definition at line 186 of file format_h263.c.

static void __unreg_module ( void   )  [static]

Definition at line 186 of file format_h263.c.

static int h263_open ( struct ast_filestream s  )  [static]

Definition at line 52 of file format_h263.c.

References ast_log(), LOG_WARNING, and s.

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]

Definition at line 64 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.

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(), errno, ast_filestream::f, f, len(), and LOG_WARNING.

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, AST_MODULE_LOAD_SUCCESS, and h263_f.

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(), h263_f, and ast_format::name.

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


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Raw H.263 data" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } [static]

Definition at line 186 of file format_h263.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 186 of file format_h263.c.

struct ast_format h263_f [static]

Definition at line 160 of file format_h263.c.

Referenced by load_module(), and unload_module().


Generated on Fri Jul 24 00:41:43 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7