Asterisk - The Open Source Telephony Project GIT-master-f36a736
Data Structures | Macros | Functions | Variables
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
 

Macros

#define BUF_SIZE   32768 /* Four real h.263 Frames */
 
#define FRAME_ENDED   0x8000
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (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 const 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.

Macro Definition Documentation

◆ BUF_SIZE

#define BUF_SIZE   32768 /* Four real h.263 Frames */

Definition at line 48 of file format_h263.c.

◆ FRAME_ENDED

#define FRAME_ENDED   0x8000

Definition at line 50 of file format_h263.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 190 of file format_h263.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 190 of file format_h263.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 190 of file format_h263.c.

◆ h263_open()

static int h263_open ( struct ast_filestream s)
static

Definition at line 57 of file format_h263.c.

58{
59 unsigned int ts;
60
61 if (fread(&ts, 1, sizeof(ts), s->f) != sizeof(ts)) {
62 ast_log(LOG_WARNING, "Empty file!\n");
63 return -1;
64 }
65 return 0;
66}
#define ast_log
Definition: astobj2.c:42
#define LOG_WARNING

References ast_log, ast_filestream::f, and LOG_WARNING.

◆ h263_read()

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

Definition at line 68 of file format_h263.c.

69{
70 size_t res;
71 uint32_t mark;
72 unsigned short len;
73 unsigned int ts;
74 struct h263_desc *fs = (struct h263_desc *)s->_private;
75
76 /* Send a frame from the file to the appropriate channel */
77 if ((res = fread(&len, 1, sizeof(len), s->f)) != sizeof(len))
78 return NULL;
79 len = ntohs(len);
80 mark = (len & FRAME_ENDED) ? 1 : 0;
81 len &= 0x7fff;
82 if (len > BUF_SIZE) {
83 ast_log(LOG_WARNING, "Length %d is too long\n", len);
84 return NULL;
85 }
87 if ((res = fread(s->fr.data.ptr, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
88 if (res) {
89 ast_log(LOG_WARNING, "Short read of %s data (expected %d bytes, read %zu): %s\n",
91 strerror(errno));
92 }
93 return NULL;
94 }
95 s->fr.samples = fs->lastts; /* XXX what ? */
96 s->fr.datalen = len;
97 s->fr.subclass.frame_ending = mark;
98 if ((res = fread(&ts, 1, sizeof(ts), s->f)) == sizeof(ts)) {
99 fs->lastts = ntohl(ts);
100 *whennext = fs->lastts * 4/45;
101 } else
102 *whennext = 0;
103 return &s->fr;
104}
if(!yyg->yy_init)
Definition: ast_expr2f.c:854
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
#define BUF_SIZE
Definition: format_h263.c:48
#define FRAME_ENDED
Definition: format_h263.c:50
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define AST_FRAME_SET_BUFFER(fr, _base, _ofs, _datalen)
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
int errno
#define NULL
Definition: resample.c:96
struct ast_frame fr
frame produced by read, typically
Definition: mod_format.h:122
void * _private
Definition: mod_format.h:124
struct ast_format * format
struct ast_frame_subclass subclass
union ast_frame::@226 data
unsigned int lastts
Definition: format_h263.c:53

References ast_filestream::_private, ast_format_get_name(), 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_frame_subclass::format, ast_filestream::fr, FRAME_ENDED, ast_frame_subclass::frame_ending, if(), h263_desc::lastts, len(), LOG_WARNING, NULL, ast_frame::ptr, ast_frame::samples, ast_frame::subclass, and ast_frame::ts.

◆ h263_seek()

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

Definition at line 130 of file format_h263.c.

131{
132 /* No way Jose */
133 return -1;
134}

◆ h263_tell()

static off_t h263_tell ( struct ast_filestream fs)
static

Definition at line 153 of file format_h263.c.

154{
155 off_t offset = ftello(fs->f);
156 return offset; /* XXX totally bogus, needs fixing */
157}

References ast_filestream::f.

◆ h263_trunc()

static int h263_trunc ( struct ast_filestream fs)
static

Definition at line 136 of file format_h263.c.

137{
138 int fd;
139 off_t cur;
140
141 if ((fd = fileno(fs->f)) < 0) {
142 ast_log(AST_LOG_WARNING, "Unable to determine file descriptor for h263 filestream %p: %s\n", fs, strerror(errno));
143 return -1;
144 }
145 if ((cur = ftello(fs->f)) < 0) {
146 ast_log(AST_LOG_WARNING, "Unable to determine current position in h263 filestream %p: %s\n", fs, strerror(errno));
147 return -1;
148 }
149 /* Truncate file to current length */
150 return ftruncate(fd, cur);
151}
#define AST_LOG_WARNING

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

◆ h263_write()

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

Definition at line 106 of file format_h263.c.

107{
108 int res;
109 unsigned int ts;
110 unsigned short len;
111 uint32_t mark = 0;
112 mark = f->subclass.frame_ending ? FRAME_ENDED : 0;
113 ts = htonl(f->samples);
114 if ((res = fwrite(&ts, 1, sizeof(ts), fs->f)) != sizeof(ts)) {
115 ast_log(LOG_WARNING, "Bad write (%d/4): %s\n", res, strerror(errno));
116 return -1;
117 }
118 len = htons(f->datalen | mark);
119 if ((res = fwrite(&len, 1, sizeof(len), fs->f)) != sizeof(len)) {
120 ast_log(LOG_WARNING, "Bad write (%d/2): %s\n", res, strerror(errno));
121 return -1;
122 }
123 if ((res = fwrite(f->data.ptr, 1, f->datalen, fs->f)) != f->datalen) {
124 ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
125 return -1;
126 }
127 return 0;
128}

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.

◆ load_module()

static int load_module ( void  )
static

Definition at line 172 of file format_h263.c.

173{
178}
struct ast_format * ast_format_h263
Built-in cached h263 format.
Definition: format_cache.c:166
static struct ast_format_def h263_f
Definition: format_h263.c:159
#define ast_format_def_register(f)
Definition: mod_format.h:136
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
struct ast_format * format
Definition: mod_format.h:48

References ast_format_def_register, ast_format_h263, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_format_def::format, and h263_f.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 180 of file format_h263.c.

181{
183}
int ast_format_def_unregister(const char *name)
Unregisters a file format.
Definition: file.c:162
char name[80]
Definition: mod_format.h:44

References ast_format_def_unregister(), h263_f, and ast_format_def::name.

Variable Documentation

◆ __mod_info

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

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 190 of file format_h263.c.

◆ h263_f

struct ast_format_def h263_f
static

Definition at line 159 of file format_h263.c.

Referenced by load_module(), and unload_module().