Ignore svn change r30495
[mplayer/kovensky.git] / libmpcodecs / ad_mp3lib.c
blob5b50557c96dcf3e83aa442f0f4dd787c278403cc
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <unistd.h>
23 #include "config.h"
25 #include "ad_internal.h"
27 static const ad_info_t info =
29 "MPEG layer-2, layer-3",
30 "mp3lib",
31 "Nick Kurshev",
32 "mpg123",
33 "Optimized to MMX/SSE/3Dnow!"
36 LIBAD_EXTERN(mp3lib)
38 #include "mp3lib/mp3.h"
40 extern int fakemono;
42 static sh_audio_t* dec_audio_sh=NULL;
44 // MP3 decoder buffer callback:
45 int mplayer_audio_read(char *buf,int size){
46 return demux_read_data(dec_audio_sh->ds,buf,size);
49 static int preinit(sh_audio_t *sh)
51 sh->audio_out_minsize=32*36*2*2; //4608;
52 return 1;
55 static int init(sh_audio_t *sh)
57 // MPEG Audio:
58 dec_audio_sh=sh; // save sh_audio for the callback:
59 // MP3_Init(fakemono,mplayer_accel,&mplayer_audio_read); // TODO!!!
60 #ifdef CONFIG_FAKE_MONO
61 MP3_Init(fakemono);
62 #else
63 MP3_Init();
64 #endif
65 MP3_samplerate=MP3_channels=0;
66 sh->a_buffer_len=MP3_DecodeFrame(sh->a_buffer,-1);
67 if(!sh->a_buffer_len) return 0; // unsupported layer/format
68 sh->channels=2; // hack
69 sh->samplesize=2;
70 sh->samplerate=MP3_samplerate;
71 sh->i_bps=MP3_bitrate*(1000/8);
72 MP3_PrintHeader();
73 return 1;
76 static void uninit(sh_audio_t *sh)
80 static int control(sh_audio_t *sh,int cmd,void* arg, ...)
82 switch(cmd)
84 case ADCTRL_RESYNC_STREAM:
85 MP3_DecodeFrame(NULL,-2); // resync
86 MP3_DecodeFrame(NULL,-2); // resync
87 MP3_DecodeFrame(NULL,-2); // resync
88 return CONTROL_TRUE;
89 case ADCTRL_SKIP_FRAME:
90 MP3_DecodeFrame(NULL,-2); // skip MPEG frame
91 return CONTROL_TRUE;
93 return CONTROL_UNKNOWN;
96 static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen)
98 return MP3_DecodeFrame(buf,-1);