Mercurial > mplayer.hg
annotate libmpcodecs/dec_audio.c @ 7854:d6c29d863f15
dvd chapter detect function from Gregory Kovriga
author | pontscho |
---|---|
date | Tue, 22 Oct 2002 22:45:30 +0000 |
parents | 0b3b1cbebd99 |
children | b9da278e4c92 |
rev | line source |
---|---|
5342 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <unistd.h> | |
4 | |
5 #include "config.h" | |
6 #include "mp_msg.h" | |
7 #include "help_mp.h" | |
8 | |
9 extern int verbose; // defined in mplayer.c | |
10 | |
11 #include "stream.h" | |
12 #include "demuxer.h" | |
13 | |
14 #include "codec-cfg.h" | |
15 #include "stheader.h" | |
16 | |
17 #include "dec_audio.h" | |
18 #include "ad.h" | |
19 #include "../libao2/afmt.h" | |
20 | |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
21 #include "../libaf/af.h" |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
22 |
5342 | 23 #ifdef USE_FAKE_MONO |
24 int fakemono=0; | |
25 #endif | |
26 /* used for ac3surround decoder - set using -channels option */ | |
27 int audio_output_channels = 2; | |
7614 | 28 af_cfg_t af_cfg; // Configuration for audio filters |
5342 | 29 |
30 static ad_functions_t* mpadec; | |
31 | |
7191
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
32 void afm_help(){ |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
33 int i; |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
34 mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_AvailableAudioFm); |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
35 mp_msg(MSGT_DECAUDIO,MSGL_INFO," afm: info: (comment)\n"); |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
36 for (i=0; mpcodecs_ad_drivers[i] != NULL; i++) |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
37 if(mpcodecs_ad_drivers[i]->info->comment && mpcodecs_ad_drivers[i]->info->comment[0]) |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
38 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"%9s %s (%s)\n", |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
39 mpcodecs_ad_drivers[i]->info->short_name, |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
40 mpcodecs_ad_drivers[i]->info->name, |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
41 mpcodecs_ad_drivers[i]->info->comment); |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
42 else |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
43 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"%9s %s\n", |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
44 mpcodecs_ad_drivers[i]->info->short_name, |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
45 mpcodecs_ad_drivers[i]->info->name); |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
46 } |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
47 |
7522 | 48 int init_audio_codec(sh_audio_t *sh_audio) |
5342 | 49 { |
50 unsigned i; | |
5458 | 51 |
52 // reset in/out buffer size/pointer: | |
53 sh_audio->a_buffer_size=0; | |
54 sh_audio->a_buffer=NULL; | |
55 sh_audio->a_in_buffer_size=0; | |
56 sh_audio->a_in_buffer=NULL; | |
57 | |
58 // Set up some common usefull defaults. ad->preinit() can override these: | |
5342 | 59 |
60 sh_audio->samplesize=2; | |
61 #ifdef WORDS_BIGENDIAN | |
62 sh_audio->sample_format=AFMT_S16_BE; | |
63 #else | |
64 sh_audio->sample_format=AFMT_S16_LE; | |
65 #endif | |
66 sh_audio->samplerate=0; | |
7669 | 67 sh_audio->channels=0; |
5458 | 68 sh_audio->i_bps=0; // input rate (bytes/sec) |
69 sh_audio->o_bps=0; // output rate (bytes/sec) | |
5342 | 70 |
71 sh_audio->audio_out_minsize=8192;/* default size, maybe not enough for Win32/ACM*/ | |
5458 | 72 sh_audio->audio_in_minsize=0; |
5342 | 73 |
74 if(!mpadec->preinit(sh_audio)) | |
75 { | |
6989 | 76 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_ADecoderPreinitFailed); |
5342 | 77 return 0; |
78 } | |
79 | |
5458 | 80 /* allocate audio in buffer: */ |
81 if(sh_audio->audio_in_minsize>0){ | |
82 sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize; | |
6989 | 83 mp_msg(MSGT_DECAUDIO,MSGL_V,MSGTR_AllocatingBytesForInputBuffer, |
5458 | 84 sh_audio->a_in_buffer_size); |
85 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size); | |
86 memset(sh_audio->a_in_buffer,0,sh_audio->a_in_buffer_size); | |
87 sh_audio->a_in_buffer_len=0; | |
88 } | |
89 | |
5342 | 90 /* allocate audio out buffer: */ |
91 sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST; /* worst case calc.*/ | |
92 | |
6989 | 93 mp_msg(MSGT_DECAUDIO,MSGL_V,MSGTR_AllocatingBytesForOutputBuffer, |
5342 | 94 sh_audio->audio_out_minsize,MAX_OUTBURST,sh_audio->a_buffer_size); |
95 | |
96 sh_audio->a_buffer=malloc(sh_audio->a_buffer_size); | |
97 if(!sh_audio->a_buffer){ | |
98 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_CantAllocAudioBuf); | |
99 return 0; | |
100 } | |
101 memset(sh_audio->a_buffer,0,sh_audio->a_buffer_size); | |
102 sh_audio->a_buffer_len=0; | |
103 | |
104 if(!mpadec->init(sh_audio)){ | |
6989 | 105 mp_msg(MSGT_DECAUDIO,MSGL_WARN,MSGTR_ADecoderInitFailed); |
5458 | 106 uninit_audio(sh_audio); // free buffers |
5342 | 107 return 0; |
108 } | |
5458 | 109 |
5342 | 110 sh_audio->inited=1; |
111 | |
112 if(!sh_audio->channels || !sh_audio->samplerate){ | |
113 mp_msg(MSGT_DECAUDIO,MSGL_WARN,MSGTR_UnknownAudio); | |
5458 | 114 uninit_audio(sh_audio); // free buffers |
5342 | 115 return 0; |
116 } | |
117 | |
118 if(!sh_audio->o_bps) | |
119 sh_audio->o_bps=sh_audio->channels*sh_audio->samplerate*sh_audio->samplesize; | |
7522 | 120 |
7561 | 121 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"AUDIO: %d Hz, %d ch, %d bit (0x%X), ratio: %d->%d (%3.1f kbit)\n", |
7522 | 122 sh_audio->samplerate,sh_audio->channels, |
7561 | 123 sh_audio->samplesize*8,sh_audio->sample_format, |
7522 | 124 sh_audio->i_bps,sh_audio->o_bps,sh_audio->i_bps*8*0.001); |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
125 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
126 sh_audio->a_out_buffer_size=sh_audio->a_buffer_size; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
127 sh_audio->a_out_buffer=sh_audio->a_buffer; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
128 sh_audio->a_out_buffer_len=sh_audio->a_buffer_len; |
5458 | 129 |
130 return 1; | |
5342 | 131 } |
132 | |
7522 | 133 int init_audio(sh_audio_t *sh_audio,char* codecname,char* afm,int status){ |
134 unsigned int orig_fourcc=sh_audio->wf?sh_audio->wf->wFormatTag:0; | |
135 sh_audio->codec=NULL; | |
136 while(1){ | |
137 int i; | |
138 // restore original fourcc: | |
139 if(sh_audio->wf) sh_audio->wf->wFormatTag=i=orig_fourcc; | |
140 if(!(sh_audio->codec=find_codec(sh_audio->format, | |
141 sh_audio->wf?(&i):NULL, sh_audio->codec,1) )) break; | |
142 if(sh_audio->wf) sh_audio->wf->wFormatTag=i; | |
143 // ok we found one codec | |
144 if(sh_audio->codec->flags&CODECS_FLAG_SELECTED) continue; // already tried & failed | |
145 if(codecname && strcmp(sh_audio->codec->name,codecname)) continue; // -ac | |
146 if(afm && strcmp(sh_audio->codec->drv,afm)) continue; // afm doesn't match | |
147 if(sh_audio->codec->status<status) continue; // too unstable | |
148 sh_audio->codec->flags|=CODECS_FLAG_SELECTED; // tagging it | |
149 // ok, it matches all rules, let's find the driver! | |
150 for (i=0; mpcodecs_ad_drivers[i] != NULL; i++) | |
151 if(!strcmp(mpcodecs_ad_drivers[i]->info->short_name,sh_audio->codec->drv)) break; | |
152 mpadec=mpcodecs_ad_drivers[i]; | |
153 if(!mpadec){ // driver not available (==compiled in) | |
154 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_AudioCodecFamilyNotAvailableStr, | |
155 sh_audio->codec->name, sh_audio->codec->drv); | |
156 continue; | |
157 } | |
158 // it's available, let's try to init! | |
159 // init() | |
160 mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_OpeningAudioDecoder,mpadec->info->short_name,mpadec->info->name); | |
161 if(!init_audio_codec(sh_audio)){ | |
162 mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_ADecoderInitFailed); | |
163 continue; // try next... | |
164 } | |
165 // Yeah! We got it! | |
166 return 1; | |
167 } | |
168 return 0; | |
169 } | |
170 | |
171 int init_best_audio_codec(sh_audio_t *sh_audio,char** audio_codec_list,char** audio_fm_list){ | |
172 char* ac_l_default[2]={"",(char*)NULL}; | |
173 // hack: | |
174 if(!audio_codec_list) audio_codec_list=ac_l_default; | |
175 // Go through the codec.conf and find the best codec... | |
176 sh_audio->inited=0; | |
177 codecs_reset_selection(1); | |
178 while(!sh_audio->inited && *audio_codec_list){ | |
179 char* audio_codec=*(audio_codec_list++); | |
180 if(audio_codec[0]){ | |
181 if(audio_codec[0]=='-'){ | |
182 // disable this codec: | |
183 select_codec(audio_codec+1,1); | |
184 } else { | |
185 // forced codec by name: | |
186 mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_ForcedAudioCodec,audio_codec); | |
187 init_audio(sh_audio,audio_codec,NULL,-1); | |
188 } | |
189 } else { | |
190 int status; | |
191 // try in stability order: UNTESTED, WORKING, BUGGY. never try CRASHING. | |
192 if(audio_fm_list){ | |
193 char** fmlist=audio_fm_list; | |
194 // try first the preferred codec families: | |
195 while(!sh_audio->inited && *fmlist){ | |
196 char* audio_fm=*(fmlist++); | |
197 mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_TryForceAudioFmtStr,audio_fm); | |
198 for(status=CODECS_STATUS__MAX;status>=CODECS_STATUS__MIN;--status) | |
199 if(init_audio(sh_audio,NULL,audio_fm,status)) break; | |
200 } | |
201 } | |
202 if(!sh_audio->inited) | |
203 for(status=CODECS_STATUS__MAX;status>=CODECS_STATUS__MIN;--status) | |
204 if(init_audio(sh_audio,NULL,NULL,status)) break; | |
205 } | |
206 } | |
207 | |
208 if(!sh_audio->inited){ | |
209 mp_msg(MSGT_DECAUDIO,MSGL_HINT, MSGTR_TryUpgradeCodecsConfOrRTFM,get_path("codecs.conf")); | |
210 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_CantFindAudioCodec,sh_audio->format); | |
211 return 0; // failed | |
212 } | |
213 | |
214 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"Selected audio codec: [%s] afm:%s (%s)\n", | |
215 sh_audio->codec->name,sh_audio->codec->drv,sh_audio->codec->info); | |
216 return 1; // success | |
217 } | |
218 | |
5342 | 219 void uninit_audio(sh_audio_t *sh_audio) |
220 { | |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
221 if(sh_audio->afilter){ |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
222 mp_msg(MSGT_DECAUDIO,MSGL_V,"Uninit audio filters...\n"); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
223 af_uninit(sh_audio->afilter); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
224 sh_audio->afilter=NULL; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
225 } |
7240 | 226 if(sh_audio->inited){ |
227 mp_msg(MSGT_DECAUDIO,MSGL_V,MSGTR_UninitAudioStr,sh_audio->codec->drv); | |
228 mpadec->uninit(sh_audio); | |
229 sh_audio->inited=0; | |
230 } | |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
231 if(sh_audio->a_out_buffer!=sh_audio->a_buffer) free(sh_audio->a_out_buffer); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
232 sh_audio->a_out_buffer=NULL; |
5458 | 233 if(sh_audio->a_buffer) free(sh_audio->a_buffer); |
234 sh_audio->a_buffer=NULL; | |
235 if(sh_audio->a_in_buffer) free(sh_audio->a_in_buffer); | |
236 sh_audio->a_in_buffer=NULL; | |
5342 | 237 } |
238 | |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
239 /* Init audio filters */ |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
240 int init_audio_filters(sh_audio_t *sh_audio, |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
241 int in_samplerate, int in_channels, int in_format, int in_bps, |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
242 int out_samplerate, int out_channels, int out_format, int out_bps, |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
243 int out_minsize, int out_maxsize){ |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
244 af_stream_t* afs=malloc(sizeof(af_stream_t)); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
245 memset(afs,0,sizeof(af_stream_t)); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
246 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
247 // input format: same as codec's output format: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
248 afs->input.rate = in_samplerate; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
249 afs->input.nch = in_channels; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
250 afs->input.format = in_format; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
251 afs->input.bps = in_bps; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
252 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
253 // output format: same as ao driver's input format (if missing, fallback to input) |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
254 afs->output.rate = out_samplerate ? out_samplerate : afs->input.rate; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
255 afs->output.nch = out_channels ? out_channels : afs->input.nch; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
256 afs->output.format = out_format ? out_format : afs->input.format; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
257 afs->output.bps = out_bps ? out_bps : afs->input.bps; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
258 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
259 // filter config: |
7614 | 260 memcpy(&afs->cfg,&af_cfg,sizeof(af_cfg_t)); |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
261 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
262 mp_msg(MSGT_DECAUDIO, MSGL_INFO, "Building audio filter chain for %dHz/%dch/%dbit -> %dHz/%dch/%dbit...\n", |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
263 afs->input.rate,afs->input.nch,afs->input.bps*8, |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
264 afs->output.rate,afs->output.nch,afs->output.bps*8); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
265 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
266 // let's autoprobe it! |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
267 if(0 != af_init(afs)){ |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
268 free(afs); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
269 return 0; // failed :( |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
270 } |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
271 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
272 // allocate the a_out_* buffers: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
273 if(out_maxsize<out_minsize) out_maxsize=out_minsize; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
274 if(out_maxsize<8192) out_maxsize=MAX_OUTBURST; // not sure this is ok |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
275 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
276 sh_audio->a_out_buffer_size=out_maxsize; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
277 sh_audio->a_out_buffer=malloc(sh_audio->a_out_buffer_size); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
278 memset(sh_audio->a_out_buffer,0,sh_audio->a_out_buffer_size); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
279 sh_audio->a_out_buffer_len=0; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
280 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
281 // ok! |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
282 sh_audio->afilter=(void*)afs; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
283 return 1; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
284 } |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
285 |
5342 | 286 int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen) |
287 { | |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
288 int declen; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
289 af_data_t afd; // filter input |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
290 af_data_t* pafd; // filter output |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
291 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
292 if(!sh_audio->inited) return -1; // no codec |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
293 if(!sh_audio->afilter){ |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
294 // no filter, just decode: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
295 // FIXME: don't drop initial decoded data in a_buffer! |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
296 return mpadec->decode_audio(sh_audio,buf,minlen,maxlen); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
297 } |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
298 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
299 // declen=af_inputlen(sh_audio->afilter,minlen); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
300 declen=af_calc_insize_constrained(sh_audio->afilter,minlen,maxlen, |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
301 sh_audio->a_buffer_size-sh_audio->audio_out_minsize); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
302 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
303 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"\ndecaudio: minlen=%d maxlen=%d declen=%d (max=%d)\n", |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
304 minlen, maxlen, declen, sh_audio->a_buffer_size); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
305 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
306 if(declen<=0) return -1; // error! |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
307 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
308 // limit declen to buffer size: - DONE by af_calc_insize_constrained |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
309 // if(declen>sh_audio->a_buffer_size) declen=sh_audio->a_buffer_size; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
310 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
311 // decode if needed: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
312 while(declen>sh_audio->a_buffer_len){ |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
313 int len=declen-sh_audio->a_buffer_len; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
314 int maxlen=sh_audio->a_buffer_size-sh_audio->a_buffer_len; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
315 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
316 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"decaudio: decoding %d bytes, max: %d (%d)\n", |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
317 len, maxlen, sh_audio->audio_out_minsize); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
318 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
319 if(maxlen<sh_audio->audio_out_minsize) break; // don't overflow buffer! |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
320 // not enough decoded data waiting, decode 'len' bytes more: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
321 len=mpadec->decode_audio(sh_audio, |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
322 sh_audio->a_buffer+sh_audio->a_buffer_len, len, maxlen); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
323 if(len<=0) break; // EOF? |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
324 sh_audio->a_buffer_len+=len; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
325 } |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
326 if(declen>sh_audio->a_buffer_len) |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
327 declen=sh_audio->a_buffer_len; // still no enough data (EOF) :( |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
328 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
329 // round to whole samples: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
330 // declen/=sh_audio->samplesize*sh_audio->channels; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
331 // declen*=sh_audio->samplesize*sh_audio->channels; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
332 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
333 // run the filters: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
334 afd.audio=sh_audio->a_buffer; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
335 afd.len=declen; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
336 afd.rate=sh_audio->samplerate; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
337 afd.nch=sh_audio->channels; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
338 afd.format=sh_audio->sample_format; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
339 afd.bps=sh_audio->samplesize; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
340 //pafd=&afd; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
341 // printf("\nAF: %d --> ",declen); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
342 pafd=af_play(sh_audio->afilter,&afd); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
343 // printf("%d \n",pafd->len); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
344 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
345 if(!pafd) return -1; // error |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
346 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
347 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"decaudio: declen=%d out=%d (max %d)\n", |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
348 declen, pafd->len, maxlen); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
349 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
350 // copy filter==>out: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
351 if(maxlen < pafd->len) |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
352 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"%i bytes of audio data lost due to buffer overflow, len = %i", pafd->len - maxlen,pafd->len); |
5342 | 353 else |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
354 maxlen=pafd->len; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
355 memmove(buf, pafd->audio, maxlen); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
356 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
357 // remove processed data from decoder buffer: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
358 sh_audio->a_buffer_len-=declen; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
359 if(sh_audio->a_buffer_len>0) |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
360 memmove(sh_audio->a_buffer, sh_audio->a_buffer+declen, sh_audio->a_buffer_len); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
361 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
362 return maxlen; |
5342 | 363 } |
364 | |
365 void resync_audio_stream(sh_audio_t *sh_audio) | |
366 { | |
6049 | 367 sh_audio->a_in_buffer_len=0; // clear audio input buffer |
5342 | 368 if(!sh_audio->inited) return; |
6049 | 369 mpadec->control(sh_audio,ADCTRL_RESYNC_STREAM,NULL); |
5342 | 370 } |
371 | |
372 void skip_audio_frame(sh_audio_t *sh_audio) | |
373 { | |
374 if(!sh_audio->inited) return; | |
375 if(mpadec->control(sh_audio,ADCTRL_SKIP_FRAME,NULL)==CONTROL_TRUE) return; | |
376 // default skip code: | |
377 ds_fill_buffer(sh_audio->ds); // skip block | |
378 } |