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 "asterisk/format_cache.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
#define FRAME_ENDED   0x8000

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_LOAD_ORDER , .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 = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND }
static struct ast_module_infoast_module_info = &__mod_info
static struct ast_format_def 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 50 of file format_h263.c.

#define FRAME_ENDED   0x8000

Definition at line 52 of file format_h263.c.

Referenced by h263_read(), h263_write(), h264_read(), and h264_write().


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 189 of file format_h263.c.

static void __unreg_module ( void   )  [static]

Definition at line 189 of file format_h263.c.

static int h263_open ( struct ast_filestream s  )  [static]

Definition at line 59 of file format_h263.c.

References ast_log, ast_filestream::f, and LOG_WARNING.

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

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

Definition at line 70 of file format_h263.c.

References ast_filestream::_private, AST_FRAME_SET_BUFFER, AST_FRIENDLY_OFFSET, ast_log, ast_filestream::buf, BUF_SIZE, ast_frame::data, ast_frame::datalen, errno, ast_filestream::f, ast_filestream::fr, FRAME_ENDED, ast_frame_subclass::frame_ending, h263_desc::lastts, len(), LOG_WARNING, NULL, ast_frame::ptr, ast_frame::samples, ast_frame::subclass, and ast_frame::ts.

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

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

Definition at line 129 of file format_h263.c.

00130 {
00131    /* No way Jose */
00132    return -1;
00133 }

static off_t h263_tell ( struct ast_filestream fs  )  [static]

Definition at line 152 of file format_h263.c.

References ast_filestream::f.

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

static int h263_trunc ( struct ast_filestream fs  )  [static]

Definition at line 135 of file format_h263.c.

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

00136 {
00137    int fd;
00138    off_t cur;
00139 
00140    if ((fd = fileno(fs->f)) < 0) {
00141       ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for h263 filestream %p: %s\n", fs, strerror(errno));
00142       return -1;
00143    }
00144    if ((cur = ftello(fs->f)) < 0) {
00145       ast_log(AST_LOG_WARNING, "Unable to determine current position in h263 filestream %p: %s\n", fs, strerror(errno));
00146       return -1;
00147    }
00148    /* Truncate file to current length */
00149    return ftruncate(fd, cur);
00150 }

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

Definition at line 105 of file format_h263.c.

References ast_log, ast_frame::data, ast_frame::datalen, errno, ast_filestream::f, FRAME_ENDED, ast_frame_subclass::frame_ending, len(), LOG_WARNING, ast_frame::ptr, ast_frame::samples, and ast_frame::subclass.

00106 {
00107    int res;
00108    unsigned int ts;
00109    unsigned short len;
00110    uint32_t mark = 0;
00111    mark = f->subclass.frame_ending ? FRAME_ENDED : 0;
00112    ts = htonl(f->samples);
00113    if ((res = fwrite(&ts, 1, sizeof(ts), fs->f)) != sizeof(ts)) {
00114          ast_log(LOG_WARNING, "Bad write (%d/4): %s\n", res, strerror(errno));
00115          return -1;
00116    }
00117    len = htons(f->datalen | mark);
00118    if ((res = fwrite(&len, 1, sizeof(len), fs->f)) != sizeof(len)) {
00119          ast_log(LOG_WARNING, "Bad write (%d/2): %s\n", res, strerror(errno));
00120          return -1;
00121    }
00122    if ((res = fwrite(f->data.ptr, 1, f->datalen, fs->f)) != f->datalen) {
00123          ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
00124          return -1;
00125    }
00126    return 0;
00127 }

static int load_module ( void   )  [static]

static int unload_module ( void   )  [static]

Definition at line 179 of file format_h263.c.

References ast_format_def_unregister(), and ast_format_def::name.

00180 {
00181    return ast_format_def_unregister(h263_f.name);
00182 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .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 = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND } [static]

Definition at line 189 of file format_h263.c.

Definition at line 189 of file format_h263.c.

struct ast_format_def h263_f [static]

Definition at line 158 of file format_h263.c.


Generated on Thu Apr 16 06:31:06 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6