Mercurial > mplayer.hg
annotate libmpcodecs/dec_audio.c @ 11112:1d2c30ef6c11
Prefer TOOLS/cpuinfo over /proc/cpuinfo on Cygwin, approved by Sascha.
author | diego |
---|---|
date | Tue, 14 Oct 2003 12:14:48 +0000 |
parents | 15425a07e13f |
children | 27ba230ec5d4 |
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 #include "stream.h" | |
10 #include "demuxer.h" | |
11 | |
12 #include "codec-cfg.h" | |
13 #include "stheader.h" | |
14 | |
15 #include "dec_audio.h" | |
16 #include "ad.h" | |
17 #include "../libao2/afmt.h" | |
18 | |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
19 #include "../libaf/af.h" |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
20 |
8152 | 21 #ifdef DYNAMIC_PLUGINS |
22 #include <dlfcn.h> | |
23 #endif | |
24 | |
5342 | 25 #ifdef USE_FAKE_MONO |
26 int fakemono=0; | |
27 #endif | |
28 /* used for ac3surround decoder - set using -channels option */ | |
29 int audio_output_channels = 2; | |
7614 | 30 af_cfg_t af_cfg; // Configuration for audio filters |
5342 | 31 |
32 static ad_functions_t* mpadec; | |
33 | |
7191
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
34 void afm_help(){ |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
35 int i; |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
36 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
|
37 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
|
38 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
|
39 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
|
40 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
|
41 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
|
42 mpcodecs_ad_drivers[i]->info->name, |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
43 mpcodecs_ad_drivers[i]->info->comment); |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
44 else |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
45 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
|
46 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
|
47 mpcodecs_ad_drivers[i]->info->name); |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
48 } |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
49 |
7522 | 50 int init_audio_codec(sh_audio_t *sh_audio) |
5342 | 51 { |
5458 | 52 |
53 // reset in/out buffer size/pointer: | |
54 sh_audio->a_buffer_size=0; | |
55 sh_audio->a_buffer=NULL; | |
56 sh_audio->a_in_buffer_size=0; | |
57 sh_audio->a_in_buffer=NULL; | |
58 | |
59 // Set up some common usefull defaults. ad->preinit() can override these: | |
5342 | 60 |
61 sh_audio->samplesize=2; | |
62 #ifdef WORDS_BIGENDIAN | |
63 sh_audio->sample_format=AFMT_S16_BE; | |
64 #else | |
65 sh_audio->sample_format=AFMT_S16_LE; | |
66 #endif | |
67 sh_audio->samplerate=0; | |
7669 | 68 sh_audio->channels=0; |
5458 | 69 sh_audio->i_bps=0; // input rate (bytes/sec) |
70 sh_audio->o_bps=0; // output rate (bytes/sec) | |
5342 | 71 |
72 sh_audio->audio_out_minsize=8192;/* default size, maybe not enough for Win32/ACM*/ | |
5458 | 73 sh_audio->audio_in_minsize=0; |
5342 | 74 |
75 if(!mpadec->preinit(sh_audio)) | |
76 { | |
6989 | 77 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_ADecoderPreinitFailed); |
5342 | 78 return 0; |
79 } | |
80 | |
5458 | 81 /* allocate audio in buffer: */ |
82 if(sh_audio->audio_in_minsize>0){ | |
83 sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize; | |
6989 | 84 mp_msg(MSGT_DECAUDIO,MSGL_V,MSGTR_AllocatingBytesForInputBuffer, |
5458 | 85 sh_audio->a_in_buffer_size); |
86 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size); | |
87 memset(sh_audio->a_in_buffer,0,sh_audio->a_in_buffer_size); | |
88 sh_audio->a_in_buffer_len=0; | |
89 } | |
90 | |
5342 | 91 /* allocate audio out buffer: */ |
92 sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST; /* worst case calc.*/ | |
93 | |
6989 | 94 mp_msg(MSGT_DECAUDIO,MSGL_V,MSGTR_AllocatingBytesForOutputBuffer, |
5342 | 95 sh_audio->audio_out_minsize,MAX_OUTBURST,sh_audio->a_buffer_size); |
96 | |
97 sh_audio->a_buffer=malloc(sh_audio->a_buffer_size); | |
98 if(!sh_audio->a_buffer){ | |
99 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_CantAllocAudioBuf); | |
100 return 0; | |
101 } | |
102 memset(sh_audio->a_buffer,0,sh_audio->a_buffer_size); | |
103 sh_audio->a_buffer_len=0; | |
104 | |
105 if(!mpadec->init(sh_audio)){ | |
6989 | 106 mp_msg(MSGT_DECAUDIO,MSGL_WARN,MSGTR_ADecoderInitFailed); |
5458 | 107 uninit_audio(sh_audio); // free buffers |
5342 | 108 return 0; |
109 } | |
5458 | 110 |
5342 | 111 sh_audio->inited=1; |
112 | |
113 if(!sh_audio->channels || !sh_audio->samplerate){ | |
114 mp_msg(MSGT_DECAUDIO,MSGL_WARN,MSGTR_UnknownAudio); | |
5458 | 115 uninit_audio(sh_audio); // free buffers |
5342 | 116 return 0; |
117 } | |
118 | |
119 if(!sh_audio->o_bps) | |
120 sh_audio->o_bps=sh_audio->channels*sh_audio->samplerate*sh_audio->samplesize; | |
7522 | 121 |
7561 | 122 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"AUDIO: %d Hz, %d ch, %d bit (0x%X), ratio: %d->%d (%3.1f kbit)\n", |
7522 | 123 sh_audio->samplerate,sh_audio->channels, |
7561 | 124 sh_audio->samplesize*8,sh_audio->sample_format, |
7522 | 125 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
|
126 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
127 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
|
128 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
|
129 sh_audio->a_out_buffer_len=sh_audio->a_buffer_len; |
5458 | 130 |
131 return 1; | |
5342 | 132 } |
133 | |
7522 | 134 int init_audio(sh_audio_t *sh_audio,char* codecname,char* afm,int status){ |
135 unsigned int orig_fourcc=sh_audio->wf?sh_audio->wf->wFormatTag:0; | |
136 sh_audio->codec=NULL; | |
137 while(1){ | |
138 int i; | |
139 // restore original fourcc: | |
140 if(sh_audio->wf) sh_audio->wf->wFormatTag=i=orig_fourcc; | |
141 if(!(sh_audio->codec=find_codec(sh_audio->format, | |
142 sh_audio->wf?(&i):NULL, sh_audio->codec,1) )) break; | |
143 if(sh_audio->wf) sh_audio->wf->wFormatTag=i; | |
144 // ok we found one codec | |
145 if(sh_audio->codec->flags&CODECS_FLAG_SELECTED) continue; // already tried & failed | |
146 if(codecname && strcmp(sh_audio->codec->name,codecname)) continue; // -ac | |
147 if(afm && strcmp(sh_audio->codec->drv,afm)) continue; // afm doesn't match | |
148 if(sh_audio->codec->status<status) continue; // too unstable | |
149 sh_audio->codec->flags|=CODECS_FLAG_SELECTED; // tagging it | |
150 // ok, it matches all rules, let's find the driver! | |
151 for (i=0; mpcodecs_ad_drivers[i] != NULL; i++) | |
152 if(!strcmp(mpcodecs_ad_drivers[i]->info->short_name,sh_audio->codec->drv)) break; | |
153 mpadec=mpcodecs_ad_drivers[i]; | |
8152 | 154 #ifdef DYNAMIC_PLUGINS |
155 if (!mpadec) | |
156 { | |
157 /* try to open shared decoder plugin */ | |
158 int buf_len; | |
159 char *buf; | |
160 ad_functions_t *funcs_sym; | |
161 ad_info_t *info_sym; | |
162 | |
10272
7b0bc557987b
renames: DATADIR->MPLAYER_DATADIR, CONFDIR->MPLAYER_CONFDIR, LIBDIR->MPLAYER_LIBDIR
arpi
parents:
9132
diff
changeset
|
163 buf_len = strlen(MPLAYER_LIBDIR)+strlen(sh_audio->codec->drv)+16; |
8152 | 164 buf = malloc(buf_len); |
165 if (!buf) | |
166 break; | |
10272
7b0bc557987b
renames: DATADIR->MPLAYER_DATADIR, CONFDIR->MPLAYER_CONFDIR, LIBDIR->MPLAYER_LIBDIR
arpi
parents:
9132
diff
changeset
|
167 snprintf(buf, buf_len, "%s/mplayer/ad_%s.so", MPLAYER_LIBDIR, sh_audio->codec->drv); |
8152 | 168 mp_msg(MSGT_DECAUDIO, MSGL_DBG2, "Trying to open external plugin: %s\n", buf); |
169 sh_audio->dec_handle = dlopen(buf, RTLD_LAZY); | |
170 if (!sh_audio->dec_handle) | |
171 break; | |
172 snprintf(buf, buf_len, "mpcodecs_ad_%s", sh_audio->codec->drv); | |
173 funcs_sym = dlsym(sh_audio->dec_handle, buf); | |
174 if (!funcs_sym || !funcs_sym->info || !funcs_sym->preinit || | |
175 !funcs_sym->init || !funcs_sym->uninit || !funcs_sym->control || | |
176 !funcs_sym->decode_audio) | |
177 break; | |
178 info_sym = funcs_sym->info; | |
179 if (strcmp(info_sym->short_name, sh_audio->codec->drv)) | |
180 break; | |
181 free(buf); | |
182 mpadec = funcs_sym; | |
183 mp_msg(MSGT_DECAUDIO, MSGL_V, "Using external decoder plugin (%s/mplayer/ad_%s.so)!\n", | |
10272
7b0bc557987b
renames: DATADIR->MPLAYER_DATADIR, CONFDIR->MPLAYER_CONFDIR, LIBDIR->MPLAYER_LIBDIR
arpi
parents:
9132
diff
changeset
|
184 MPLAYER_LIBDIR, sh_audio->codec->drv); |
8152 | 185 } |
186 #endif | |
7522 | 187 if(!mpadec){ // driver not available (==compiled in) |
188 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_AudioCodecFamilyNotAvailableStr, | |
189 sh_audio->codec->name, sh_audio->codec->drv); | |
190 continue; | |
191 } | |
192 // it's available, let's try to init! | |
193 // init() | |
194 mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_OpeningAudioDecoder,mpadec->info->short_name,mpadec->info->name); | |
195 if(!init_audio_codec(sh_audio)){ | |
196 mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_ADecoderInitFailed); | |
197 continue; // try next... | |
198 } | |
199 // Yeah! We got it! | |
200 return 1; | |
201 } | |
202 return 0; | |
203 } | |
204 | |
8123
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
8027
diff
changeset
|
205 extern char *get_path(char *filename); |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
8027
diff
changeset
|
206 |
7522 | 207 int init_best_audio_codec(sh_audio_t *sh_audio,char** audio_codec_list,char** audio_fm_list){ |
208 char* ac_l_default[2]={"",(char*)NULL}; | |
209 // hack: | |
210 if(!audio_codec_list) audio_codec_list=ac_l_default; | |
211 // Go through the codec.conf and find the best codec... | |
212 sh_audio->inited=0; | |
213 codecs_reset_selection(1); | |
214 while(!sh_audio->inited && *audio_codec_list){ | |
215 char* audio_codec=*(audio_codec_list++); | |
216 if(audio_codec[0]){ | |
217 if(audio_codec[0]=='-'){ | |
218 // disable this codec: | |
219 select_codec(audio_codec+1,1); | |
220 } else { | |
221 // forced codec by name: | |
222 mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_ForcedAudioCodec,audio_codec); | |
223 init_audio(sh_audio,audio_codec,NULL,-1); | |
224 } | |
225 } else { | |
226 int status; | |
227 // try in stability order: UNTESTED, WORKING, BUGGY. never try CRASHING. | |
228 if(audio_fm_list){ | |
229 char** fmlist=audio_fm_list; | |
230 // try first the preferred codec families: | |
231 while(!sh_audio->inited && *fmlist){ | |
232 char* audio_fm=*(fmlist++); | |
233 mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_TryForceAudioFmtStr,audio_fm); | |
234 for(status=CODECS_STATUS__MAX;status>=CODECS_STATUS__MIN;--status) | |
235 if(init_audio(sh_audio,NULL,audio_fm,status)) break; | |
236 } | |
237 } | |
238 if(!sh_audio->inited) | |
239 for(status=CODECS_STATUS__MAX;status>=CODECS_STATUS__MIN;--status) | |
240 if(init_audio(sh_audio,NULL,NULL,status)) break; | |
241 } | |
242 } | |
243 | |
244 if(!sh_audio->inited){ | |
245 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_CantFindAudioCodec,sh_audio->format); | |
10683 | 246 mp_msg(MSGT_DECAUDIO,MSGL_HINT, MSGTR_RTFMCodecs); |
7522 | 247 return 0; // failed |
248 } | |
249 | |
250 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"Selected audio codec: [%s] afm:%s (%s)\n", | |
251 sh_audio->codec->name,sh_audio->codec->drv,sh_audio->codec->info); | |
252 return 1; // success | |
253 } | |
254 | |
5342 | 255 void uninit_audio(sh_audio_t *sh_audio) |
256 { | |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
257 if(sh_audio->afilter){ |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
258 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
|
259 af_uninit(sh_audio->afilter); |
10803 | 260 free(sh_audio->afilter); |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
261 sh_audio->afilter=NULL; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
262 } |
7240 | 263 if(sh_audio->inited){ |
264 mp_msg(MSGT_DECAUDIO,MSGL_V,MSGTR_UninitAudioStr,sh_audio->codec->drv); | |
265 mpadec->uninit(sh_audio); | |
8152 | 266 #ifdef DYNAMIC_PLUGINS |
267 if (sh_audio->dec_handle) | |
268 dlclose(sh_audio->dec_handle); | |
269 #endif | |
7240 | 270 sh_audio->inited=0; |
271 } | |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
272 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
|
273 sh_audio->a_out_buffer=NULL; |
5458 | 274 if(sh_audio->a_buffer) free(sh_audio->a_buffer); |
275 sh_audio->a_buffer=NULL; | |
276 if(sh_audio->a_in_buffer) free(sh_audio->a_in_buffer); | |
277 sh_audio->a_in_buffer=NULL; | |
5342 | 278 } |
279 | |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
280 /* Init audio filters */ |
8995
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
281 int preinit_audio_filters(sh_audio_t *sh_audio, |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
282 int in_samplerate, int in_channels, int in_format, int in_bps, |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
283 int* out_samplerate, int* out_channels, int* out_format, int out_bps){ |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
284 char strbuf[200]; |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
285 af_stream_t* afs=malloc(sizeof(af_stream_t)); |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
286 memset(afs,0,sizeof(af_stream_t)); |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
287 |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
288 // input format: same as codec's output format: |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
289 afs->input.rate = in_samplerate; |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
290 afs->input.nch = in_channels; |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
291 afs->input.format = af_format_decode(in_format); |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
292 afs->input.bps = in_bps; |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
293 |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
294 // output format: same as ao driver's input format (if missing, fallback to input) |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
295 afs->output.rate = *out_samplerate ? *out_samplerate : afs->input.rate; |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
296 afs->output.nch = *out_channels ? *out_channels : afs->input.nch; |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
297 afs->output.format = af_format_decode(*out_format ? *out_format : afs->input.format); |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
298 afs->output.bps = out_bps ? out_bps : afs->input.bps; |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
299 |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
300 // filter config: |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
301 memcpy(&afs->cfg,&af_cfg,sizeof(af_cfg_t)); |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
302 |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
303 mp_msg(MSGT_DECAUDIO, MSGL_INFO, "Checking audio filter chain for %dHz/%dch/%dbit -> %dHz/%dch/%dbit...\n", |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
304 afs->input.rate,afs->input.nch,afs->input.bps*8, |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
305 afs->output.rate,afs->output.nch,afs->output.bps*8); |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
306 |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
307 // let's autoprobe it! |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
308 if(0 != af_init(afs,0)){ |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
309 free(afs); |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
310 return 0; // failed :( |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
311 } |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
312 |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
313 *out_samplerate=afs->output.rate; |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
314 *out_channels=afs->output.nch; |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
315 *out_format=af_format_encode((void*)(&afs->output)); |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
316 |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
317 mp_msg(MSGT_DECAUDIO, MSGL_INFO, "AF_pre: af format: %d bps, %d ch, %d hz, %s\n", |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
318 afs->output.bps, afs->output.nch, afs->output.rate, |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
319 fmt2str(afs->output.format,strbuf,200)); |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
320 |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
321 sh_audio->afilter=(void*)afs; |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
322 return 1; |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
323 } |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
324 |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
325 /* Init audio filters */ |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
326 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
|
327 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
|
328 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
|
329 int out_minsize, int out_maxsize){ |
8995
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
330 af_stream_t* afs=sh_audio->afilter; |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
331 if(!afs){ |
9018 | 332 afs = (af_stream_t*)malloc(sizeof(af_stream_t)); |
8995
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
333 memset(afs,0,sizeof(af_stream_t)); |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
334 } |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
335 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
336 // input format: same as codec's output format: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
337 afs->input.rate = in_samplerate; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
338 afs->input.nch = in_channels; |
8167 | 339 afs->input.format = af_format_decode(in_format); |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
340 afs->input.bps = in_bps; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
341 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
342 // 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
|
343 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
|
344 afs->output.nch = out_channels ? out_channels : afs->input.nch; |
8167 | 345 afs->output.format = af_format_decode(out_format ? out_format : afs->input.format); |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
346 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
|
347 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
348 // filter config: |
7614 | 349 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
|
350 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
351 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
|
352 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
|
353 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
|
354 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
355 // let's autoprobe it! |
8969
a892e5f051e1
Adding support for more logical libaf configuration
anders
parents:
8167
diff
changeset
|
356 if(0 != af_init(afs,1)){ |
9132 | 357 sh_audio->afilter=NULL; |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
358 free(afs); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
359 return 0; // failed :( |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
360 } |
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 // allocate the a_out_* buffers: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
363 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
|
364 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
|
365 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
366 sh_audio->a_out_buffer_size=out_maxsize; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
367 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
|
368 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
|
369 sh_audio->a_out_buffer_len=0; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
370 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
371 // ok! |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
372 sh_audio->afilter=(void*)afs; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
373 return 1; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
374 } |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
375 |
5342 | 376 int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen) |
377 { | |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
378 int declen; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
379 af_data_t afd; // filter input |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
380 af_data_t* pafd; // filter output |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
381 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
382 if(!sh_audio->inited) return -1; // no codec |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
383 if(!sh_audio->afilter){ |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
384 // no filter, just decode: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
385 // 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
|
386 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
|
387 } |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
388 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
389 // declen=af_inputlen(sh_audio->afilter,minlen); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
390 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
|
391 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
|
392 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
393 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
|
394 minlen, maxlen, declen, sh_audio->a_buffer_size); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
395 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
396 if(declen<=0) return -1; // error! |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
397 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
398 // 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
|
399 // 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
|
400 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
401 // decode if needed: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
402 while(declen>sh_audio->a_buffer_len){ |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
403 int len=declen-sh_audio->a_buffer_len; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
404 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
|
405 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
406 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
|
407 len, maxlen, sh_audio->audio_out_minsize); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
408 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
409 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
|
410 // 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
|
411 len=mpadec->decode_audio(sh_audio, |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
412 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
|
413 if(len<=0) break; // EOF? |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
414 sh_audio->a_buffer_len+=len; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
415 } |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
416 if(declen>sh_audio->a_buffer_len) |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
417 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
|
418 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
419 // round to whole samples: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
420 // declen/=sh_audio->samplesize*sh_audio->channels; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
421 // declen*=sh_audio->samplesize*sh_audio->channels; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
422 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
423 // run the filters: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
424 afd.audio=sh_audio->a_buffer; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
425 afd.len=declen; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
426 afd.rate=sh_audio->samplerate; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
427 afd.nch=sh_audio->channels; |
8167 | 428 afd.format=af_format_decode(sh_audio->sample_format); |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
429 afd.bps=sh_audio->samplesize; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
430 //pafd=&afd; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
431 // printf("\nAF: %d --> ",declen); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
432 pafd=af_play(sh_audio->afilter,&afd); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
433 // printf("%d \n",pafd->len); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
434 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
435 if(!pafd) return -1; // error |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
436 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
437 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
|
438 declen, pafd->len, maxlen); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
439 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
440 // copy filter==>out: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
441 if(maxlen < pafd->len) |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
442 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"%i bytes of audio data lost due to buffer overflow, len = %i", pafd->len - maxlen,pafd->len); |
5342 | 443 else |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
444 maxlen=pafd->len; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
445 memmove(buf, pafd->audio, maxlen); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
446 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
447 // remove processed data from decoder buffer: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
448 sh_audio->a_buffer_len-=declen; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
449 if(sh_audio->a_buffer_len>0) |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
450 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
|
451 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
452 return maxlen; |
5342 | 453 } |
454 | |
455 void resync_audio_stream(sh_audio_t *sh_audio) | |
456 { | |
6049 | 457 sh_audio->a_in_buffer_len=0; // clear audio input buffer |
5342 | 458 if(!sh_audio->inited) return; |
6049 | 459 mpadec->control(sh_audio,ADCTRL_RESYNC_STREAM,NULL); |
5342 | 460 } |
461 | |
462 void skip_audio_frame(sh_audio_t *sh_audio) | |
463 { | |
464 if(!sh_audio->inited) return; | |
465 if(mpadec->control(sh_audio,ADCTRL_SKIP_FRAME,NULL)==CONTROL_TRUE) return; | |
466 // default skip code: | |
467 ds_fill_buffer(sh_audio->ds); // skip block | |
468 } |