50 #define BUF_SIZE (5*FRAME_TIME)
52 static int frame_size[4] = {
70 ast_debug(1,
"Created filestream G.726-%dk.\n", 40 - s->rate * 8);
76 return g726_open(s, RATE_40);
81 return g726_open(s, RATE_32);
86 return g726_open(s, RATE_24);
91 return g726_open(s, RATE_16);
94 static int g726_40_rewrite(
struct ast_filestream *s,
const char *comment)
96 return g726_open(s, RATE_40);
99 static int g726_32_rewrite(
struct ast_filestream *s,
const char *comment)
101 return g726_open(s, RATE_32);
104 static int g726_24_rewrite(
struct ast_filestream *s,
const char *comment)
106 return g726_open(s, RATE_24);
109 static int g726_16_rewrite(
struct ast_filestream *s,
const char *comment)
111 return g726_open(s, RATE_16);
128 ast_log(LOG_WARNING,
"Short read of %s data (expected %d bytes, read %zu): %s\n",
143 if (f->
datalen % frame_size[fs->rate]) {
144 ast_log(LOG_WARNING,
"Invalid data length %d, should be multiple of %d\n",
145 f->
datalen, frame_size[fs->rate]);
149 ast_log(LOG_WARNING,
"Bad write (%d/%d): %s\n",
150 res, frame_size[fs->rate], strerror(errno));
156 static int g726_seek(
struct ast_filestream *fs, off_t sample_offset,
int whence)
158 off_t offset = 0, min = 0, cur, max, distance;
160 if ((cur = ftello(fs->f)) < 0) {
161 ast_log(AST_LOG_WARNING,
"Unable to determine current position in g726 filestream %p: %s\n", fs, strerror(errno));
165 if (fseeko(fs->f, 0, SEEK_END) < 0) {
166 ast_log(AST_LOG_WARNING,
"Unable to seek to end of g726 filestream %p: %s\n", fs, strerror(errno));
170 if ((max = ftello(fs->f)) < 0) {
171 ast_log(AST_LOG_WARNING,
"Unable to determine max position in g726 filestream %p: %s\n", fs, strerror(errno));
176 distance = sample_offset / 2;
177 if (whence == SEEK_SET) {
179 }
else if (whence == SEEK_CUR || whence == SEEK_FORCECUR) {
180 offset = distance + cur;
181 }
else if (whence == SEEK_END) {
182 offset = max - distance;
185 if (whence != SEEK_FORCECUR) {
186 offset = offset > max ? max : offset;
187 offset = offset < min ? min : offset;
189 return fseeko(fs->f, offset, SEEK_SET);
199 return ftello(fs->f) << 1;
206 .open = g726_40_open,
207 .rewrite = g726_40_rewrite,
219 .open = g726_32_open,
220 .rewrite = g726_32_rewrite,
232 .open = g726_24_open,
233 .rewrite = g726_24_rewrite,
245 .open = g726_16_open,
246 .rewrite = g726_16_rewrite,
258 static int unload_module(
void)
264 ast_log(LOG_WARNING,
"Failed to unregister format %s.\n", f_def[i].name);
269 static int load_module(
void)
275 if (ast_format_def_register(&f_def[i])) {
276 ast_log(LOG_WARNING,
"Failed to register format %s.\n", f_def[i].name);
284 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER,
"Raw G.726 (16/24/32/40kbps) data",
285 .support_level = AST_MODULE_SUPPORT_CORE,
287 .unload = unload_module,
Asterisk main include file. File version handling, generic pbx functions.
struct ast_frame_subclass subclass
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
Asterisk architecture endianess compatibility definitions.
struct ast_frame fr
frame produced by read, typically
#define ast_debug(level,...)
Log a DEBUG message.
#define AST_FRAME_SET_BUFFER(fr, _base, _ofs, _datalen)
union ast_frame::@224 data
Module has failed to load, may be in an inconsistent state.
This structure is allocated by file.c in one chunk, together with buf_size and desc_size bytes of mem...
Data structure associated with a single frame of data.
struct ast_format * format
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.