Asterisk - The Open Source Telephony Project  18.5.0
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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .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.

Referenced by h263_read().

◆ FRAME_ENDED

#define FRAME_ENDED   0x8000

Definition at line 50 of file format_h263.c.

Referenced by h263_read(), and h263_write().

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.

References ast_log, ast_filestream::f, and LOG_WARNING.

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 LOG_WARNING
Definition: logger.h:274
#define ast_log
Definition: astobj2.c:42

◆ h263_read()

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

Definition at line 68 of file format_h263.c.

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.

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 }
unsigned int lastts
Definition: format_h263.c:53
#define LOG_WARNING
Definition: logger.h:274
if(!yyg->yy_init)
Definition: ast_expr2f.c:868
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
#define NULL
Definition: resample.c:96
struct ast_frame_subclass subclass
#define ast_log
Definition: astobj2.c:42
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
struct ast_frame fr
frame produced by read, typically
Definition: mod_format.h:122
void * _private
Definition: mod_format.h:124
#define AST_FRAME_SET_BUFFER(fr, _base, _ofs, _datalen)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int errno
#define BUF_SIZE
Definition: format_h263.c:48
union ast_frame::@263 data
#define FRAME_ENDED
Definition: format_h263.c:50
struct ast_format * format

◆ 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.

References ast_filestream::f.

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

◆ h263_trunc()

static int h263_trunc ( struct ast_filestream fs)
static

Definition at line 136 of file format_h263.c.

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

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
Definition: logger.h:279
#define ast_log
Definition: astobj2.c:42
int errno

◆ h263_write()

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

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

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 }
#define LOG_WARNING
Definition: logger.h:274
struct ast_frame_subclass subclass
#define ast_log
Definition: astobj2.c:42
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int errno
union ast_frame::@263 data
#define FRAME_ENDED
Definition: format_h263.c:50

◆ load_module()

static int load_module ( void  )
static

Definition at line 172 of file format_h263.c.

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

Referenced by unload_module().

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

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 180 of file format_h263.c.

References ast_format_def_unregister(), AST_MODFLAG_LOAD_ORDER, AST_MODPRI_APP_DEPEND, AST_MODULE_INFO(), AST_MODULE_SUPPORT_CORE, ASTERISK_GPL_KEY, load_module(), and ast_format_def::name.

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

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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .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.