37 #include "mp3/mpg123.h"
38 #include "mp3/mpglib.h"
45 #define MP3_BUFLEN 320
46 #define MP3_SCACHE 16384
47 #define MP3_DCACHE 8192
68 static const char name[] =
"mp3";
75 #if __BYTE_ORDER == __LITTLE_ENDIAN
81 #if __BYTE_ORDER == __BIG_ENDIAN
83 (((((b) ) & 0xFF) << 24) | \
84 ((((b) >> 8) & 0xFF) << 16) | \
85 ((((b) >> 16) & 0xFF) << 8) | \
86 ((((b) >> 24) & 0xFF) ))
88 (((((b) ) & 0xFF) << 8) | \
89 ((((b) >> 8) & 0xFF) ))
90 #define ltohl(b) htoll(b)
91 #define ltohs(b) htols(b)
93 #error "Endianess not defined"
101 InitMP3(&p->
mp, OUTSCALE);
123 ast_log(LOG_WARNING,
"Error while reading MP3 file: %s\n", strerror(errno));
140 if((res = decodeMP3(&p->
mp,NULL,0,p->
dbuf,MP3_DCACHE,&p->
dbuflen)) == MP3_OK) {
150 int res = 0, bytes = 0;
154 InitMP3(&p->
mp, OUTSCALE);
155 fseek(s->f, 0, SEEK_SET);
157 while(p->offset < p->seek) {
160 while(p->offset < p->seek && ((res = mp3_dqueue(s))) == MP3_OK) {
161 for(bytes = 0 ; bytes < p->
dbuflen ; bytes++) {
164 if(p->offset >= p->seek)
181 if(! p->
sbuflen || res != MP3_OK) {
212 if (p->
buflen < MP3_BUFLEN) {
226 p->
dbuflen -= (MP3_BUFLEN - save);
242 ast_log(LOG_ERROR,
"I Can't write MP3 only read them.\n");
248 static int mp3_seek(
struct ast_filestream *s, off_t sample_offset,
int whence)
252 long offset=0,samples;
253 samples = sample_offset * 2;
256 fseek(s->f, 0, SEEK_END);
257 max = ftell(s->f) * 100;
260 if (whence == SEEK_SET)
261 offset = samples + min;
262 else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
263 offset = samples + cur;
264 else if (whence == SEEK_END)
265 offset = max - samples;
266 if (whence != SEEK_FORCECUR) {
267 offset = (offset > max)?max:offset;
271 return fseek(s->f, offset, SEEK_SET);
275 static int mp3_rewrite(
struct ast_filestream *s,
const char *comment)
277 ast_log(LOG_ERROR,
"I Can't write MP3 only read them.\n");
284 ast_log(LOG_ERROR,
"I Can't write MP3 only read them.\n");
305 .rewrite = mp3_rewrite,
311 .getcomment = mp3_getcomment,
317 static int load_module(
void)
321 return ast_format_def_register(&mp3_f);
324 static int unload_module(
void)
329 AST_MODULE_INFO_STANDARD_EXTENDED(
ASTERISK_GPL_KEY,
"MP3 format [Any rate but 8000hz mono is optimal]");
Asterisk main include file. File version handling, generic pbx functions.
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
struct ast_frame fr
frame produced by read, typically
#define AST_FRAME_SET_BUFFER(fr, _base, _ofs, _datalen)
Support for logging to various files, console and syslog Configuration in file logger.conf.
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.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.