43 #define GSM_FRAME_SIZE 33
44 #define GSM_SAMPLES 160
48 static const char gsm_silence[] =
49 {0xD8,0x20,0xA2,0xE1,0x5A,0x50,0x00,0x49,0x24,0x92,0x49,0x24,0x50,0x00,0x49
50 ,0x24,0x92,0x49,0x24,0x50,0x00,0x49,0x24,0x92,0x49,0x24,0x50,0x00,0x49,0x24
59 if ((res = fread(s->
fr.
data.ptr, 1, GSM_FRAME_SIZE, s->f)) != GSM_FRAME_SIZE) {
61 ast_log(LOG_WARNING,
"Short read of %s data (expected %d bytes, read %zu): %s\n",
74 unsigned char gsm[2*GSM_FRAME_SIZE];
80 conv65(f->
data.ptr + len, gsm);
81 if ((res = fwrite(gsm, 1, 2*GSM_FRAME_SIZE, fs->f)) != 2*GSM_FRAME_SIZE) {
82 ast_log(LOG_WARNING,
"Bad write (%d/66): %s\n", res, strerror(errno));
88 if (f->
datalen % GSM_FRAME_SIZE) {
89 ast_log(LOG_WARNING,
"Invalid data length, %d, should be multiple of 33\n", f->
datalen);
93 ast_log(LOG_WARNING,
"Bad write (%d/33): %s\n", res, strerror(errno));
100 static int gsm_seek(
struct ast_filestream *fs, off_t sample_offset,
int whence)
102 off_t
offset = 0, min = 0, cur, max, distance;
104 if ((cur = ftello(fs->f)) < 0) {
105 ast_log(AST_LOG_WARNING,
"Unable to determine current position in g719 filestream %p: %s\n", fs, strerror(errno));
109 if (fseeko(fs->f, 0, SEEK_END) < 0) {
110 ast_log(AST_LOG_WARNING,
"Unable to seek to end of g719 filestream %p: %s\n", fs, strerror(errno));
114 if ((max = ftello(fs->f)) < 0) {
115 ast_log(AST_LOG_WARNING,
"Unable to determine max position in g719 filestream %p: %s\n", fs, strerror(errno));
120 distance = (sample_offset / GSM_SAMPLES) * GSM_FRAME_SIZE;
121 if (whence == SEEK_SET) {
123 }
else if (whence == SEEK_CUR || whence == SEEK_FORCECUR) {
124 offset = distance + cur;
125 }
else if (whence == SEEK_END) {
126 offset = max - distance;
130 offset = (offset < min)?min:offset;
131 if (whence != SEEK_FORCECUR) {
132 offset = (offset > max)?max:offset;
133 }
else if (offset > max) {
135 fseeko(fs->f, 0, SEEK_END);
136 for (i=0; i< (offset - max) / GSM_FRAME_SIZE; i++) {
137 if (fwrite(gsm_silence, 1, GSM_FRAME_SIZE, fs->f) != GSM_FRAME_SIZE) {
138 ast_log(LOG_WARNING,
"fwrite() failed: %s\n", strerror(errno));
142 return fseeko(fs->f, offset, SEEK_SET);
150 if ((fd = fileno(fs->f)) < 0) {
151 ast_log(AST_LOG_WARNING,
"Unable to determine file descriptor for gsm filestream %p: %s\n", fs, strerror(errno));
154 if ((cur = ftello(fs->f)) < 0) {
155 ast_log(AST_LOG_WARNING,
"Unable to determine current position in gsm filestream %p: %s\n", fs, strerror(errno));
159 return ftruncate(fd, cur);
164 off_t offset = ftello(fs->f);
167 ast_log(AST_LOG_WARNING,
"Unable to determine offset for gsm filestream %p: %s\n", fs, strerror(errno));
171 return (offset / GSM_FRAME_SIZE) * GSM_SAMPLES;
185 static int load_module(
void)
188 if (ast_format_def_register(&gsm_f))
193 static int unload_module(
void)
199 .support_level = AST_MODULE_SUPPORT_CORE,
201 .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_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.