Save to raw, headerless GSM data. More...
#include "asterisk.h"#include "asterisk/mod_format.h"#include "asterisk/module.h"#include "asterisk/endian.h"#include "msgsm.h"
Go to the source code of this file.
Defines | |
| #define | GSM_FRAME_SIZE 33 |
| #define | GSM_SAMPLES 160 |
Functions | |
| AST_MODULE_INFO (ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER,"Raw GSM data",.load=load_module,.unload=unload_module,.load_pri=10,) | |
| static struct ast_frame * | gsm_read (struct ast_filestream *s, int *whennext) |
| static int | gsm_seek (struct ast_filestream *fs, off_t sample_offset, int whence) |
| static off_t | gsm_tell (struct ast_filestream *fs) |
| static int | gsm_trunc (struct ast_filestream *fs) |
| static int | gsm_write (struct ast_filestream *fs, struct ast_frame *f) |
| static int | load_module (void) |
| static int | unload_module (void) |
Variables | |
| static struct ast_format | gsm_f |
| char | gsm_silence [] |
Save to raw, headerless GSM data.
Definition in file format_gsm.c.
| #define GSM_FRAME_SIZE 33 |
Definition at line 40 of file format_gsm.c.
Referenced by gsm_read(), gsm_seek(), gsm_tell(), gsm_write(), wav_read(), and wav_write().
| #define GSM_SAMPLES 160 |
Definition at line 41 of file format_gsm.c.
| AST_MODULE_INFO | ( | ASTERISK_GPL_KEY | , | |
| AST_MODFLAG_LOAD_ORDER | , | |||
| "Raw GSM data" | , | |||
| . | load = load_module, |
|||
| . | unload = unload_module, |
|||
| . | load_pri = 10 | |||
| ) |
| static struct ast_frame* gsm_read | ( | struct ast_filestream * | s, | |
| int * | whennext | |||
| ) | [static, read] |
Definition at line 51 of file format_gsm.c.
References AST_FORMAT_GSM, AST_FRAME_SET_BUFFER, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), ast_filestream::buf, ast_frame::data, errno, ast_filestream::f, ast_filestream::fr, ast_frame::frametype, GSM_FRAME_SIZE, GSM_SAMPLES, LOG_WARNING, ast_frame::mallocd, ast_frame::ptr, ast_frame::samples, and ast_frame::subclass.
00052 { 00053 int res; 00054 00055 s->fr.frametype = AST_FRAME_VOICE; 00056 s->fr.subclass = AST_FORMAT_GSM; 00057 AST_FRAME_SET_BUFFER(&(s->fr), s->buf, AST_FRIENDLY_OFFSET, GSM_FRAME_SIZE) 00058 s->fr.mallocd = 0; 00059 if ((res = fread(s->fr.data.ptr, 1, GSM_FRAME_SIZE, s->f)) != GSM_FRAME_SIZE) { 00060 if (res) 00061 ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno)); 00062 return NULL; 00063 } 00064 *whennext = s->fr.samples = GSM_SAMPLES; 00065 return &s->fr; 00066 }
| static int gsm_seek | ( | struct ast_filestream * | fs, | |
| off_t | sample_offset, | |||
| int | whence | |||
| ) | [static] |
Definition at line 105 of file format_gsm.c.
References ast_log(), errno, ast_filestream::f, fwrite, GSM_FRAME_SIZE, GSM_SAMPLES, LOG_WARNING, ast_frame::offset, and SEEK_FORCECUR.
00106 { 00107 off_t offset=0,min,cur,max,distance; 00108 00109 min = 0; 00110 cur = ftello(fs->f); 00111 fseeko(fs->f, 0, SEEK_END); 00112 max = ftello(fs->f); 00113 /* have to fudge to frame here, so not fully to sample */ 00114 distance = (sample_offset/GSM_SAMPLES) * GSM_FRAME_SIZE; 00115 if(whence == SEEK_SET) 00116 offset = distance; 00117 else if(whence == SEEK_CUR || whence == SEEK_FORCECUR) 00118 offset = distance + cur; 00119 else if(whence == SEEK_END) 00120 offset = max - distance; 00121 /* Always protect against seeking past the begining. */ 00122 offset = (offset < min)?min:offset; 00123 if (whence != SEEK_FORCECUR) { 00124 offset = (offset > max)?max:offset; 00125 } else if (offset > max) { 00126 int i; 00127 fseeko(fs->f, 0, SEEK_END); 00128 for (i=0; i< (offset - max) / GSM_FRAME_SIZE; i++) { 00129 if (!fwrite(gsm_silence, 1, GSM_FRAME_SIZE, fs->f)) { 00130 ast_log(LOG_WARNING, "fwrite() failed: %s\n", strerror(errno)); 00131 } 00132 } 00133 } 00134 return fseeko(fs->f, offset, SEEK_SET); 00135 }
| static off_t gsm_tell | ( | struct ast_filestream * | fs | ) | [static] |
Definition at line 142 of file format_gsm.c.
References ast_filestream::f, GSM_FRAME_SIZE, GSM_SAMPLES, and ast_frame::offset.
00143 { 00144 off_t offset = ftello(fs->f); 00145 return (offset/GSM_FRAME_SIZE)*GSM_SAMPLES; 00146 }
| static int gsm_trunc | ( | struct ast_filestream * | fs | ) | [static] |
Definition at line 137 of file format_gsm.c.
References ast_filestream::f.
| static int gsm_write | ( | struct ast_filestream * | fs, | |
| struct ast_frame * | f | |||
| ) | [static] |
Definition at line 68 of file format_gsm.c.
References AST_FORMAT_GSM, AST_FRAME_VOICE, ast_log(), conv65(), ast_frame::data, ast_frame::datalen, errno, ast_filestream::f, ast_frame::frametype, fwrite, GSM_FRAME_SIZE, len(), LOG_WARNING, ast_frame::ptr, and ast_frame::subclass.
00069 { 00070 int res; 00071 unsigned char gsm[2*GSM_FRAME_SIZE]; 00072 00073 if (f->frametype != AST_FRAME_VOICE) { 00074 ast_log(LOG_WARNING, "Asked to write non-voice frame!\n"); 00075 return -1; 00076 } 00077 if (f->subclass != AST_FORMAT_GSM) { 00078 ast_log(LOG_WARNING, "Asked to write non-GSM frame (%d)!\n", f->subclass); 00079 return -1; 00080 } 00081 if (!(f->datalen % 65)) { 00082 /* This is in MSGSM format, need to be converted */ 00083 int len=0; 00084 while(len < f->datalen) { 00085 conv65(f->data.ptr + len, gsm); 00086 if ((res = fwrite(gsm, 1, 2*GSM_FRAME_SIZE, fs->f)) != 2*GSM_FRAME_SIZE) { 00087 ast_log(LOG_WARNING, "Bad write (%d/66): %s\n", res, strerror(errno)); 00088 return -1; 00089 } 00090 len += 65; 00091 } 00092 } else { 00093 if (f->datalen % GSM_FRAME_SIZE) { 00094 ast_log(LOG_WARNING, "Invalid data length, %d, should be multiple of 33\n", f->datalen); 00095 return -1; 00096 } 00097 if ((res = fwrite(f->data.ptr, 1, f->datalen, fs->f)) != f->datalen) { 00098 ast_log(LOG_WARNING, "Bad write (%d/33): %s\n", res, strerror(errno)); 00099 return -1; 00100 } 00101 } 00102 return 0; 00103 }
| static int load_module | ( | void | ) | [static] |
Definition at line 160 of file format_gsm.c.
References ast_format_register, AST_MODULE_LOAD_FAILURE, and AST_MODULE_LOAD_SUCCESS.
00161 { 00162 if (ast_format_register(&gsm_f)) 00163 return AST_MODULE_LOAD_FAILURE; 00164 return AST_MODULE_LOAD_SUCCESS; 00165 }
| static int unload_module | ( | void | ) | [static] |
Definition at line 167 of file format_gsm.c.
References ast_format_unregister(), and ast_format::name.
00168 { 00169 return ast_format_unregister(gsm_f.name); 00170 }
struct ast_format gsm_f [static] |
Definition at line 148 of file format_gsm.c.
| char gsm_silence[] |
{0xD8,0x20,0xA2,0xE1,0x5A,0x50,0x00,0x49,0x24,0x92,0x49,0x24,0x50,0x00,0x49
,0x24,0x92,0x49,0x24,0x50,0x00,0x49,0x24,0x92,0x49,0x24,0x50,0x00,0x49,0x24
,0x92,0x49,0x24}
Definition at line 45 of file format_gsm.c.
1.6.1