Static pthread support
[mplayer/kovensky.git] / libmpcodecs / ad_mp3lib.c
blobf10a718b0947f51f4672867d18a853bc749f0a9e
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
5 #include "config.h"
7 #include "ad_internal.h"
9 static const ad_info_t info =
11 "MPEG layer-2, layer-3",
12 "mp3lib",
13 "Nick Kurshev",
14 "mpg123",
15 "Optimized to MMX/SSE/3Dnow!"
18 LIBAD_EXTERN(mp3lib)
20 #include "mp3lib/mp3.h"
22 extern int fakemono;
24 static sh_audio_t* dec_audio_sh=NULL;
26 // MP3 decoder buffer callback:
27 int mplayer_audio_read(char *buf,int size){
28 return demux_read_data(dec_audio_sh->ds,buf,size);
31 static int preinit(sh_audio_t *sh)
33 sh->audio_out_minsize=32*36*2*2; //4608;
34 return 1;
37 static int init(sh_audio_t *sh)
39 // MPEG Audio:
40 dec_audio_sh=sh; // save sh_audio for the callback:
41 // MP3_Init(fakemono,mplayer_accel,&mplayer_audio_read); // TODO!!!
42 #ifdef CONFIG_FAKE_MONO
43 MP3_Init(fakemono);
44 #else
45 MP3_Init();
46 #endif
47 MP3_samplerate=MP3_channels=0;
48 sh->a_buffer_len=MP3_DecodeFrame(sh->a_buffer,-1);
49 if(!sh->a_buffer_len) return 0; // unsupported layer/format
50 sh->channels=2; // hack
51 sh->samplesize=2;
52 sh->samplerate=MP3_samplerate;
53 sh->i_bps=MP3_bitrate*(1000/8);
54 MP3_PrintHeader();
55 return 1;
58 static void uninit(sh_audio_t *sh)
62 static int control(sh_audio_t *sh,int cmd,void* arg, ...)
64 switch(cmd)
66 case ADCTRL_RESYNC_STREAM:
67 MP3_DecodeFrame(NULL,-2); // resync
68 MP3_DecodeFrame(NULL,-2); // resync
69 MP3_DecodeFrame(NULL,-2); // resync
70 return CONTROL_TRUE;
71 case ADCTRL_SKIP_FRAME:
72 MP3_DecodeFrame(NULL,-2); // skip MPEG frame
73 return CONTROL_TRUE;
75 return CONTROL_UNKNOWN;
78 static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen)
80 return MP3_DecodeFrame(buf,-1);