Mercurial > mplayer.hg
annotate libmpcodecs/dec_audio.c @ 15477:15f012150986
more efficient read() without memcpy()
author | nicodvb |
---|---|
date | Sun, 15 May 2005 07:59:30 +0000 |
parents | 601e2c8a2922 |
children | 32d9c8a0a02b |
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" | |
14245 | 17 #include "../libaf/af_format.h" |
5342 | 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 |
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 { |
14815
56fb33e23ad4
If -af-adv force=4 is in effect, use ADCTRL_QUERY_FORMAT to query the
hzoli
parents:
14814
diff
changeset
|
50 if ((af_cfg.force & AF_INIT_FORMAT_MASK) == AF_INIT_FLOAT) { |
56fb33e23ad4
If -af-adv force=4 is in effect, use ADCTRL_QUERY_FORMAT to query the
hzoli
parents:
14814
diff
changeset
|
51 int fmt = AF_FORMAT_FLOAT_NE; |
14819
601e2c8a2922
Remove file-global mpadec, add ad_driver member to sh_audio_t instead.
hzoli
parents:
14818
diff
changeset
|
52 if (sh_audio->ad_driver->control(sh_audio, ADCTRL_QUERY_FORMAT, |
14815
56fb33e23ad4
If -af-adv force=4 is in effect, use ADCTRL_QUERY_FORMAT to query the
hzoli
parents:
14814
diff
changeset
|
53 &fmt) == CONTROL_TRUE) { |
56fb33e23ad4
If -af-adv force=4 is in effect, use ADCTRL_QUERY_FORMAT to query the
hzoli
parents:
14814
diff
changeset
|
54 sh_audio->sample_format = fmt; |
56fb33e23ad4
If -af-adv force=4 is in effect, use ADCTRL_QUERY_FORMAT to query the
hzoli
parents:
14814
diff
changeset
|
55 sh_audio->samplesize = 4; |
56fb33e23ad4
If -af-adv force=4 is in effect, use ADCTRL_QUERY_FORMAT to query the
hzoli
parents:
14814
diff
changeset
|
56 } |
56fb33e23ad4
If -af-adv force=4 is in effect, use ADCTRL_QUERY_FORMAT to query the
hzoli
parents:
14814
diff
changeset
|
57 } |
14819
601e2c8a2922
Remove file-global mpadec, add ad_driver member to sh_audio_t instead.
hzoli
parents:
14818
diff
changeset
|
58 if(!sh_audio->ad_driver->preinit(sh_audio)) |
5342 | 59 { |
6989 | 60 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_ADecoderPreinitFailed); |
5342 | 61 return 0; |
62 } | |
63 | |
5458 | 64 /* allocate audio in buffer: */ |
65 if(sh_audio->audio_in_minsize>0){ | |
66 sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize; | |
6989 | 67 mp_msg(MSGT_DECAUDIO,MSGL_V,MSGTR_AllocatingBytesForInputBuffer, |
5458 | 68 sh_audio->a_in_buffer_size); |
69 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size); | |
70 memset(sh_audio->a_in_buffer,0,sh_audio->a_in_buffer_size); | |
71 sh_audio->a_in_buffer_len=0; | |
72 } | |
73 | |
5342 | 74 /* allocate audio out buffer: */ |
75 sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST; /* worst case calc.*/ | |
76 | |
6989 | 77 mp_msg(MSGT_DECAUDIO,MSGL_V,MSGTR_AllocatingBytesForOutputBuffer, |
5342 | 78 sh_audio->audio_out_minsize,MAX_OUTBURST,sh_audio->a_buffer_size); |
79 | |
80 sh_audio->a_buffer=malloc(sh_audio->a_buffer_size); | |
81 if(!sh_audio->a_buffer){ | |
82 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_CantAllocAudioBuf); | |
83 return 0; | |
84 } | |
85 memset(sh_audio->a_buffer,0,sh_audio->a_buffer_size); | |
86 sh_audio->a_buffer_len=0; | |
87 | |
14819
601e2c8a2922
Remove file-global mpadec, add ad_driver member to sh_audio_t instead.
hzoli
parents:
14818
diff
changeset
|
88 if(!sh_audio->ad_driver->init(sh_audio)){ |
6989 | 89 mp_msg(MSGT_DECAUDIO,MSGL_WARN,MSGTR_ADecoderInitFailed); |
5458 | 90 uninit_audio(sh_audio); // free buffers |
5342 | 91 return 0; |
92 } | |
5458 | 93 |
5342 | 94 sh_audio->inited=1; |
95 | |
96 if(!sh_audio->channels || !sh_audio->samplerate){ | |
97 mp_msg(MSGT_DECAUDIO,MSGL_WARN,MSGTR_UnknownAudio); | |
5458 | 98 uninit_audio(sh_audio); // free buffers |
5342 | 99 return 0; |
100 } | |
101 | |
102 if(!sh_audio->o_bps) | |
103 sh_audio->o_bps=sh_audio->channels*sh_audio->samplerate*sh_audio->samplesize; | |
7522 | 104 |
14814 | 105 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"AUDIO: %d Hz, %d ch, %s, %3.1f kbit/%3.2f%% (ratio: %d->%d)\n", |
7522 | 106 sh_audio->samplerate,sh_audio->channels, |
14814 | 107 af_fmt2str_short(sh_audio->sample_format), |
108 sh_audio->i_bps*8*0.001,((float)sh_audio->i_bps/sh_audio->o_bps)*100.0, | |
109 sh_audio->i_bps,sh_audio->o_bps); | |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
110 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
111 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
|
112 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
|
113 sh_audio->a_out_buffer_len=sh_audio->a_buffer_len; |
5458 | 114 |
115 return 1; | |
5342 | 116 } |
117 | |
7522 | 118 int init_audio(sh_audio_t *sh_audio,char* codecname,char* afm,int status){ |
119 unsigned int orig_fourcc=sh_audio->wf?sh_audio->wf->wFormatTag:0; | |
120 sh_audio->codec=NULL; | |
121 while(1){ | |
14819
601e2c8a2922
Remove file-global mpadec, add ad_driver member to sh_audio_t instead.
hzoli
parents:
14818
diff
changeset
|
122 ad_functions_t* mpadec; |
7522 | 123 int i; |
14819
601e2c8a2922
Remove file-global mpadec, add ad_driver member to sh_audio_t instead.
hzoli
parents:
14818
diff
changeset
|
124 sh_audio->ad_driver = 0; |
7522 | 125 // restore original fourcc: |
126 if(sh_audio->wf) sh_audio->wf->wFormatTag=i=orig_fourcc; | |
127 if(!(sh_audio->codec=find_codec(sh_audio->format, | |
128 sh_audio->wf?(&i):NULL, sh_audio->codec,1) )) break; | |
129 if(sh_audio->wf) sh_audio->wf->wFormatTag=i; | |
130 // ok we found one codec | |
131 if(sh_audio->codec->flags&CODECS_FLAG_SELECTED) continue; // already tried & failed | |
132 if(codecname && strcmp(sh_audio->codec->name,codecname)) continue; // -ac | |
133 if(afm && strcmp(sh_audio->codec->drv,afm)) continue; // afm doesn't match | |
134 if(sh_audio->codec->status<status) continue; // too unstable | |
135 sh_audio->codec->flags|=CODECS_FLAG_SELECTED; // tagging it | |
136 // ok, it matches all rules, let's find the driver! | |
137 for (i=0; mpcodecs_ad_drivers[i] != NULL; i++) | |
138 if(!strcmp(mpcodecs_ad_drivers[i]->info->short_name,sh_audio->codec->drv)) break; | |
139 mpadec=mpcodecs_ad_drivers[i]; | |
8152 | 140 #ifdef DYNAMIC_PLUGINS |
141 if (!mpadec) | |
142 { | |
143 /* try to open shared decoder plugin */ | |
144 int buf_len; | |
145 char *buf; | |
146 ad_functions_t *funcs_sym; | |
147 ad_info_t *info_sym; | |
148 | |
10272
7b0bc557987b
renames: DATADIR->MPLAYER_DATADIR, CONFDIR->MPLAYER_CONFDIR, LIBDIR->MPLAYER_LIBDIR
arpi
parents:
9132
diff
changeset
|
149 buf_len = strlen(MPLAYER_LIBDIR)+strlen(sh_audio->codec->drv)+16; |
8152 | 150 buf = malloc(buf_len); |
151 if (!buf) | |
152 break; | |
10272
7b0bc557987b
renames: DATADIR->MPLAYER_DATADIR, CONFDIR->MPLAYER_CONFDIR, LIBDIR->MPLAYER_LIBDIR
arpi
parents:
9132
diff
changeset
|
153 snprintf(buf, buf_len, "%s/mplayer/ad_%s.so", MPLAYER_LIBDIR, sh_audio->codec->drv); |
8152 | 154 mp_msg(MSGT_DECAUDIO, MSGL_DBG2, "Trying to open external plugin: %s\n", buf); |
155 sh_audio->dec_handle = dlopen(buf, RTLD_LAZY); | |
156 if (!sh_audio->dec_handle) | |
157 break; | |
158 snprintf(buf, buf_len, "mpcodecs_ad_%s", sh_audio->codec->drv); | |
159 funcs_sym = dlsym(sh_audio->dec_handle, buf); | |
160 if (!funcs_sym || !funcs_sym->info || !funcs_sym->preinit || | |
161 !funcs_sym->init || !funcs_sym->uninit || !funcs_sym->control || | |
162 !funcs_sym->decode_audio) | |
163 break; | |
164 info_sym = funcs_sym->info; | |
165 if (strcmp(info_sym->short_name, sh_audio->codec->drv)) | |
166 break; | |
167 free(buf); | |
168 mpadec = funcs_sym; | |
169 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
|
170 MPLAYER_LIBDIR, sh_audio->codec->drv); |
8152 | 171 } |
172 #endif | |
7522 | 173 if(!mpadec){ // driver not available (==compiled in) |
174 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_AudioCodecFamilyNotAvailableStr, | |
175 sh_audio->codec->name, sh_audio->codec->drv); | |
176 continue; | |
177 } | |
178 // it's available, let's try to init! | |
179 // init() | |
180 mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_OpeningAudioDecoder,mpadec->info->short_name,mpadec->info->name); | |
14819
601e2c8a2922
Remove file-global mpadec, add ad_driver member to sh_audio_t instead.
hzoli
parents:
14818
diff
changeset
|
181 sh_audio->ad_driver = mpadec; |
7522 | 182 if(!init_audio_codec(sh_audio)){ |
183 mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_ADecoderInitFailed); | |
184 continue; // try next... | |
185 } | |
186 // Yeah! We got it! | |
187 return 1; | |
188 } | |
189 return 0; | |
190 } | |
191 | |
8123
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
8027
diff
changeset
|
192 extern char *get_path(char *filename); |
9fc45fe0d444
*HUGE* set of compiler warning fixes, unused variables removal
arpi
parents:
8027
diff
changeset
|
193 |
7522 | 194 int init_best_audio_codec(sh_audio_t *sh_audio,char** audio_codec_list,char** audio_fm_list){ |
195 char* ac_l_default[2]={"",(char*)NULL}; | |
196 // hack: | |
197 if(!audio_codec_list) audio_codec_list=ac_l_default; | |
198 // Go through the codec.conf and find the best codec... | |
199 sh_audio->inited=0; | |
200 codecs_reset_selection(1); | |
201 while(!sh_audio->inited && *audio_codec_list){ | |
202 char* audio_codec=*(audio_codec_list++); | |
203 if(audio_codec[0]){ | |
204 if(audio_codec[0]=='-'){ | |
205 // disable this codec: | |
206 select_codec(audio_codec+1,1); | |
207 } else { | |
208 // forced codec by name: | |
209 mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_ForcedAudioCodec,audio_codec); | |
210 init_audio(sh_audio,audio_codec,NULL,-1); | |
211 } | |
212 } else { | |
213 int status; | |
214 // try in stability order: UNTESTED, WORKING, BUGGY. never try CRASHING. | |
215 if(audio_fm_list){ | |
216 char** fmlist=audio_fm_list; | |
217 // try first the preferred codec families: | |
218 while(!sh_audio->inited && *fmlist){ | |
219 char* audio_fm=*(fmlist++); | |
220 mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_TryForceAudioFmtStr,audio_fm); | |
221 for(status=CODECS_STATUS__MAX;status>=CODECS_STATUS__MIN;--status) | |
222 if(init_audio(sh_audio,NULL,audio_fm,status)) break; | |
223 } | |
224 } | |
225 if(!sh_audio->inited) | |
226 for(status=CODECS_STATUS__MAX;status>=CODECS_STATUS__MIN;--status) | |
227 if(init_audio(sh_audio,NULL,NULL,status)) break; | |
228 } | |
229 } | |
230 | |
231 if(!sh_audio->inited){ | |
232 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_CantFindAudioCodec,sh_audio->format); | |
10683 | 233 mp_msg(MSGT_DECAUDIO,MSGL_HINT, MSGTR_RTFMCodecs); |
7522 | 234 return 0; // failed |
235 } | |
236 | |
237 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"Selected audio codec: [%s] afm:%s (%s)\n", | |
238 sh_audio->codec->name,sh_audio->codec->drv,sh_audio->codec->info); | |
239 return 1; // success | |
240 } | |
241 | |
5342 | 242 void uninit_audio(sh_audio_t *sh_audio) |
243 { | |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
244 if(sh_audio->afilter){ |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
245 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
|
246 af_uninit(sh_audio->afilter); |
10803 | 247 free(sh_audio->afilter); |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
248 sh_audio->afilter=NULL; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
249 } |
7240 | 250 if(sh_audio->inited){ |
251 mp_msg(MSGT_DECAUDIO,MSGL_V,MSGTR_UninitAudioStr,sh_audio->codec->drv); | |
14819
601e2c8a2922
Remove file-global mpadec, add ad_driver member to sh_audio_t instead.
hzoli
parents:
14818
diff
changeset
|
252 sh_audio->ad_driver->uninit(sh_audio); |
8152 | 253 #ifdef DYNAMIC_PLUGINS |
254 if (sh_audio->dec_handle) | |
255 dlclose(sh_audio->dec_handle); | |
256 #endif | |
7240 | 257 sh_audio->inited=0; |
258 } | |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
259 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
|
260 sh_audio->a_out_buffer=NULL; |
5458 | 261 if(sh_audio->a_buffer) free(sh_audio->a_buffer); |
262 sh_audio->a_buffer=NULL; | |
263 if(sh_audio->a_in_buffer) free(sh_audio->a_in_buffer); | |
264 sh_audio->a_in_buffer=NULL; | |
5342 | 265 } |
266 | |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
267 /* Init audio filters */ |
8995
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
268 int preinit_audio_filters(sh_audio_t *sh_audio, |
14818
663c1ea5f595
finally remove the refences to bps outside libaf. also simplification of some messages and removed redundants
alex
parents:
14815
diff
changeset
|
269 int in_samplerate, int in_channels, int in_format, |
663c1ea5f595
finally remove the refences to bps outside libaf. also simplification of some messages and removed redundants
alex
parents:
14815
diff
changeset
|
270 int* out_samplerate, int* out_channels, int* out_format){ |
8995
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
271 af_stream_t* afs=malloc(sizeof(af_stream_t)); |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
272 memset(afs,0,sizeof(af_stream_t)); |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
273 |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
274 // input format: same as codec's output format: |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
275 afs->input.rate = in_samplerate; |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
276 afs->input.nch = in_channels; |
14245 | 277 afs->input.format = in_format; |
14818
663c1ea5f595
finally remove the refences to bps outside libaf. also simplification of some messages and removed redundants
alex
parents:
14815
diff
changeset
|
278 af_fix_parameters(&(afs->input)); |
8995
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
279 |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
280 // 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
|
281 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
|
282 afs->output.nch = *out_channels ? *out_channels : afs->input.nch; |
14245 | 283 afs->output.format = *out_format ? *out_format : afs->input.format; |
14818
663c1ea5f595
finally remove the refences to bps outside libaf. also simplification of some messages and removed redundants
alex
parents:
14815
diff
changeset
|
284 af_fix_parameters(&(afs->output)); |
8995
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
285 |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
286 // filter config: |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
287 memcpy(&afs->cfg,&af_cfg,sizeof(af_cfg_t)); |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
288 |
14818
663c1ea5f595
finally remove the refences to bps outside libaf. also simplification of some messages and removed redundants
alex
parents:
14815
diff
changeset
|
289 mp_msg(MSGT_DECAUDIO, MSGL_INFO, "Checking audio filter chain for %dHz/%dch/%s -> %dHz/%dch/%s...\n", |
663c1ea5f595
finally remove the refences to bps outside libaf. also simplification of some messages and removed redundants
alex
parents:
14815
diff
changeset
|
290 afs->input.rate,afs->input.nch,af_fmt2str_short(afs->input.format), |
663c1ea5f595
finally remove the refences to bps outside libaf. also simplification of some messages and removed redundants
alex
parents:
14815
diff
changeset
|
291 afs->output.rate,afs->output.nch,af_fmt2str_short(afs->output.format)); |
8995
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
292 |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
293 // let's autoprobe it! |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
294 if(0 != af_init(afs,0)){ |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
295 free(afs); |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
296 return 0; // failed :( |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
297 } |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
298 |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
299 *out_samplerate=afs->output.rate; |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
300 *out_channels=afs->output.nch; |
14245 | 301 *out_format=afs->output.format; |
14818
663c1ea5f595
finally remove the refences to bps outside libaf. also simplification of some messages and removed redundants
alex
parents:
14815
diff
changeset
|
302 |
663c1ea5f595
finally remove the refences to bps outside libaf. also simplification of some messages and removed redundants
alex
parents:
14815
diff
changeset
|
303 mp_msg(MSGT_DECAUDIO, MSGL_INFO, "AF_pre: %dHz/%dch/%s\n", |
663c1ea5f595
finally remove the refences to bps outside libaf. also simplification of some messages and removed redundants
alex
parents:
14815
diff
changeset
|
304 afs->output.rate, afs->output.nch, |
663c1ea5f595
finally remove the refences to bps outside libaf. also simplification of some messages and removed redundants
alex
parents:
14815
diff
changeset
|
305 af_fmt2str_short(afs->output.format)); |
8995
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 sh_audio->afilter=(void*)afs; |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
308 return 1; |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
309 } |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
310 |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
311 /* Init audio filters */ |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
312 int init_audio_filters(sh_audio_t *sh_audio, |
14818
663c1ea5f595
finally remove the refences to bps outside libaf. also simplification of some messages and removed redundants
alex
parents:
14815
diff
changeset
|
313 int in_samplerate, int in_channels, int in_format, |
663c1ea5f595
finally remove the refences to bps outside libaf. also simplification of some messages and removed redundants
alex
parents:
14815
diff
changeset
|
314 int out_samplerate, int out_channels, int out_format, |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
315 int out_minsize, int out_maxsize){ |
8995
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
316 af_stream_t* afs=sh_audio->afilter; |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
317 if(!afs){ |
9018 | 318 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
|
319 memset(afs,0,sizeof(af_stream_t)); |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
320 } |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
321 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
322 // input format: same as codec's output format: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
323 afs->input.rate = in_samplerate; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
324 afs->input.nch = in_channels; |
14245 | 325 afs->input.format = in_format; |
14818
663c1ea5f595
finally remove the refences to bps outside libaf. also simplification of some messages and removed redundants
alex
parents:
14815
diff
changeset
|
326 af_fix_parameters(&(afs->input)); |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
327 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
328 // 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
|
329 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
|
330 afs->output.nch = out_channels ? out_channels : afs->input.nch; |
14245 | 331 afs->output.format = out_format ? out_format : afs->input.format; |
14818
663c1ea5f595
finally remove the refences to bps outside libaf. also simplification of some messages and removed redundants
alex
parents:
14815
diff
changeset
|
332 af_fix_parameters(&(afs->output)); |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
333 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
334 // filter config: |
7614 | 335 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
|
336 |
14818
663c1ea5f595
finally remove the refences to bps outside libaf. also simplification of some messages and removed redundants
alex
parents:
14815
diff
changeset
|
337 mp_msg(MSGT_DECAUDIO, MSGL_INFO, "Building audio filter chain for %dHz/%dch/%s -> %dHz/%dch/%s...\n", |
663c1ea5f595
finally remove the refences to bps outside libaf. also simplification of some messages and removed redundants
alex
parents:
14815
diff
changeset
|
338 afs->input.rate,afs->input.nch,af_fmt2str_short(afs->input.format), |
663c1ea5f595
finally remove the refences to bps outside libaf. also simplification of some messages and removed redundants
alex
parents:
14815
diff
changeset
|
339 afs->output.rate,afs->output.nch,af_fmt2str_short(afs->output.format)); |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
340 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
341 // let's autoprobe it! |
8969
a892e5f051e1
Adding support for more logical libaf configuration
anders
parents:
8167
diff
changeset
|
342 if(0 != af_init(afs,1)){ |
9132 | 343 sh_audio->afilter=NULL; |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
344 free(afs); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
345 return 0; // failed :( |
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 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
348 // allocate the a_out_* buffers: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
349 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
|
350 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
|
351 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
352 sh_audio->a_out_buffer_size=out_maxsize; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
353 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
|
354 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
|
355 sh_audio->a_out_buffer_len=0; |
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 // ok! |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
358 sh_audio->afilter=(void*)afs; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
359 return 1; |
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 |
5342 | 362 int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen) |
363 { | |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
364 int declen; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
365 af_data_t afd; // filter input |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
366 af_data_t* pafd; // filter output |
14819
601e2c8a2922
Remove file-global mpadec, add ad_driver member to sh_audio_t instead.
hzoli
parents:
14818
diff
changeset
|
367 ad_functions_t* mpadec = sh_audio->ad_driver; |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
368 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
369 if(!sh_audio->inited) return -1; // no codec |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
370 if(!sh_audio->afilter){ |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
371 // no filter, just decode: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
372 // 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
|
373 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
|
374 } |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
375 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
376 // declen=af_inputlen(sh_audio->afilter,minlen); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
377 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
|
378 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
|
379 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
380 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
|
381 minlen, maxlen, declen, sh_audio->a_buffer_size); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
382 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
383 if(declen<=0) return -1; // error! |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
384 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
385 // 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
|
386 // 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
|
387 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
388 // decode if needed: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
389 while(declen>sh_audio->a_buffer_len){ |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
390 int len=declen-sh_audio->a_buffer_len; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
391 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
|
392 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
393 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
|
394 len, maxlen, sh_audio->audio_out_minsize); |
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(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
|
397 // 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
|
398 len=mpadec->decode_audio(sh_audio, |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
399 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
|
400 if(len<=0) break; // EOF? |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
401 sh_audio->a_buffer_len+=len; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
402 } |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
403 if(declen>sh_audio->a_buffer_len) |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
404 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
|
405 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
406 // round to whole samples: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
407 // declen/=sh_audio->samplesize*sh_audio->channels; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
408 // declen*=sh_audio->samplesize*sh_audio->channels; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
409 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
410 // run the filters: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
411 afd.audio=sh_audio->a_buffer; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
412 afd.len=declen; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
413 afd.rate=sh_audio->samplerate; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
414 afd.nch=sh_audio->channels; |
14245 | 415 afd.format=sh_audio->sample_format; |
14818
663c1ea5f595
finally remove the refences to bps outside libaf. also simplification of some messages and removed redundants
alex
parents:
14815
diff
changeset
|
416 af_fix_parameters(&afd); |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
417 //pafd=&afd; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
418 // printf("\nAF: %d --> ",declen); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
419 pafd=af_play(sh_audio->afilter,&afd); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
420 // printf("%d \n",pafd->len); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
421 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
422 if(!pafd) return -1; // error |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
423 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
424 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
|
425 declen, pafd->len, maxlen); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
426 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
427 // copy filter==>out: |
11857
6107e58dcc28
not pretty, but at least it prevents the channels from getting out of order...
rfelker
parents:
11855
diff
changeset
|
428 if(maxlen < pafd->len) { |
6107e58dcc28
not pretty, but at least it prevents the channels from getting out of order...
rfelker
parents:
11855
diff
changeset
|
429 maxlen -= maxlen % (sh_audio->channels * sh_audio->samplesize); |
11855 | 430 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"%i bytes of audio data lost due to buffer overflow, len = %i\n", pafd->len - maxlen,pafd->len); |
11857
6107e58dcc28
not pretty, but at least it prevents the channels from getting out of order...
rfelker
parents:
11855
diff
changeset
|
431 } |
5342 | 432 else |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
433 maxlen=pafd->len; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
434 memmove(buf, pafd->audio, maxlen); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
435 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
436 // remove processed data from decoder buffer: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
437 sh_audio->a_buffer_len-=declen; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
438 if(sh_audio->a_buffer_len>0) |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
439 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
|
440 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
441 return maxlen; |
5342 | 442 } |
443 | |
444 void resync_audio_stream(sh_audio_t *sh_audio) | |
445 { | |
6049 | 446 sh_audio->a_in_buffer_len=0; // clear audio input buffer |
5342 | 447 if(!sh_audio->inited) return; |
14819
601e2c8a2922
Remove file-global mpadec, add ad_driver member to sh_audio_t instead.
hzoli
parents:
14818
diff
changeset
|
448 sh_audio->ad_driver->control(sh_audio,ADCTRL_RESYNC_STREAM,NULL); |
5342 | 449 } |
450 | |
451 void skip_audio_frame(sh_audio_t *sh_audio) | |
452 { | |
453 if(!sh_audio->inited) return; | |
14819
601e2c8a2922
Remove file-global mpadec, add ad_driver member to sh_audio_t instead.
hzoli
parents:
14818
diff
changeset
|
454 if(sh_audio->ad_driver->control(sh_audio,ADCTRL_SKIP_FRAME,NULL)==CONTROL_TRUE) return; |
5342 | 455 // default skip code: |
456 ds_fill_buffer(sh_audio->ds); // skip block | |
457 } | |
14818
663c1ea5f595
finally remove the refences to bps outside libaf. also simplification of some messages and removed redundants
alex
parents:
14815
diff
changeset
|
458 |
663c1ea5f595
finally remove the refences to bps outside libaf. also simplification of some messages and removed redundants
alex
parents:
14815
diff
changeset
|
459 void adjust_volume() |
663c1ea5f595
finally remove the refences to bps outside libaf. also simplification of some messages and removed redundants
alex
parents:
14815
diff
changeset
|
460 { |
663c1ea5f595
finally remove the refences to bps outside libaf. also simplification of some messages and removed redundants
alex
parents:
14815
diff
changeset
|
461 } |