format_h264.c File Reference

Save to raw, headerless h264 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_h264.c:

Go to the source code of this file.

Data Structures

struct  h264_desc

Defines

#define BUF_SIZE   4096
#define FRAME_ENDED   0x8000

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int h264_open (struct ast_filestream *s)
static struct ast_frameh264_read (struct ast_filestream *s, int *whennext)
static int h264_seek (struct ast_filestream *fs, off_t sample_offset, int whence)
static off_t h264_tell (struct ast_filestream *fs)
static int h264_trunc (struct ast_filestream *fs)
static int h264_write (struct ast_filestream *s, 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.264 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 h264_f


Detailed Description

Save to raw, headerless h264 data.

Definition in file format_h264.c.


Define Documentation

#define BUF_SIZE   4096

Definition at line 47 of file format_h264.c.

#define FRAME_ENDED   0x8000

Todo:
Check this buf size estimate, it may be totally wrong for large frame video

Definition at line 45 of file format_h264.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 182 of file format_h264.c.

static void __unreg_module ( void   )  [static]

Definition at line 182 of file format_h264.c.

static int h264_open ( struct ast_filestream s  )  [static]

Definition at line 52 of file format_h264.c.

References ast_log, ast_filestream::f, and LOG_WARNING.

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

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

Definition at line 62 of file format_h264.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, h264_desc::lastts, len(), LOG_WARNING, NULL, ast_frame::ptr, ast_frame::samples, ast_frame::subclass, and ast_frame::ts.

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

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

Definition at line 122 of file format_h264.c.

00123 {
00124    /* No way Jose */
00125    return -1;
00126 }

static off_t h264_tell ( struct ast_filestream fs  )  [static]

Definition at line 145 of file format_h264.c.

References ast_filestream::f.

00146 {
00147    off_t offset = ftell(fs->f);
00148    return offset; /* XXX totally bogus, needs fixing */
00149 }

static int h264_trunc ( struct ast_filestream fs  )  [static]

Definition at line 128 of file format_h264.c.

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

00129 {
00130    int fd;
00131    off_t cur;
00132 
00133    if ((fd = fileno(fs->f)) < 0) {
00134       ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for h264 filestream %p: %s\n", fs, strerror(errno));
00135       return -1;
00136    }
00137    if ((cur = ftello(fs->f)) < 0) {
00138       ast_log(AST_LOG_WARNING, "Unable to determine current position in h264 filestream %p: %s\n", fs, strerror(errno));
00139       return -1;
00140    }
00141    /* Truncate file to current length */
00142    return ftruncate(fd, cur);
00143 }

static int h264_write ( struct ast_filestream s,
struct ast_frame f 
) [static]

Definition at line 97 of file format_h264.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.

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

static int load_module ( void   )  [static]

static int unload_module ( void   )  [static]

Definition at line 172 of file format_h264.c.

References ast_format_def_unregister(), and ast_format_def::name.

00173 {
00174    return ast_format_def_unregister(h264_f.name);
00175 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Raw H.264 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 182 of file format_h264.c.

Definition at line 182 of file format_h264.c.

struct ast_format_def h264_f [static]

Definition at line 151 of file format_h264.c.


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