Mercurial > mplayer.hg
annotate libmpcodecs/dec_audio.c @ 22365:baeb54a9c3e9
Seek to -ss position, not 0, in per-file loop.
Fixes -ss combined with per-file loop after r22356.
author | uau |
---|---|
date | Thu, 01 Mar 2007 00:22:03 +0000 |
parents | 13815ffcada5 |
children | 4faee1254928 |
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" | |
17012 | 17 #include "libaf/af_format.h" |
5342 | 18 |
17012 | 19 #include "libaf/af.h" |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
20 |
17635
db13b7295651
memalign segfaults when used without declaration on amd64 (default function return type is int so the pointer was trunctated to 32bits)
aurel
parents:
17625
diff
changeset
|
21 #ifdef HAVE_MALLOC_H |
db13b7295651
memalign segfaults when used without declaration on amd64 (default function return type is int so the pointer was trunctated to 32bits)
aurel
parents:
17625
diff
changeset
|
22 #include <malloc.h> |
db13b7295651
memalign segfaults when used without declaration on amd64 (default function return type is int so the pointer was trunctated to 32bits)
aurel
parents:
17625
diff
changeset
|
23 #endif |
db13b7295651
memalign segfaults when used without declaration on amd64 (default function return type is int so the pointer was trunctated to 32bits)
aurel
parents:
17625
diff
changeset
|
24 |
8152 | 25 #ifdef DYNAMIC_PLUGINS |
26 #include <dlfcn.h> | |
27 #endif | |
28 | |
5342 | 29 #ifdef USE_FAKE_MONO |
30 int fakemono=0; | |
31 #endif | |
32 /* used for ac3surround decoder - set using -channels option */ | |
33 int audio_output_channels = 2; | |
15950
4432bb25b13e
-af-adv force=1 is now default (and thus also lavcresample)
reimar
parents:
15811
diff
changeset
|
34 af_cfg_t af_cfg = {1, NULL}; // Configuration for audio filters |
5342 | 35 |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
17427
diff
changeset
|
36 void afm_help(void){ |
7191
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
37 int i; |
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,MSGTR_AvailableAudioFm); |
18237
4231482179b6
Get ride of the several if(identify) messy lines and rearangment of some of the output, both patches by Kiriuja mplayer-patches AT en-directo_net, his changes are barely unrelated, nevertheless Im commiting them thogeter just for the sake of my mental healt, I had both patches already applied on my local three
reynaldo
parents:
17635
diff
changeset
|
39 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_DRIVERS\n"); |
7191
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," afm: info: (comment)\n"); |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
41 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
|
42 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
|
43 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
|
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 mpcodecs_ad_drivers[i]->info->comment); |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
47 else |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
48 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
|
49 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
|
50 mpcodecs_ad_drivers[i]->info->name); |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
51 } |
1eadce15446c
-afm/-vfm help implemenetd, some cosmetics of ad/vd codec names/comments
arpi
parents:
7180
diff
changeset
|
52 |
7522 | 53 int init_audio_codec(sh_audio_t *sh_audio) |
5342 | 54 { |
14815
56fb33e23ad4
If -af-adv force=4 is in effect, use ADCTRL_QUERY_FORMAT to query the
hzoli
parents:
14814
diff
changeset
|
55 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
|
56 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
|
57 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
|
58 &fmt) == CONTROL_TRUE) { |
56fb33e23ad4
If -af-adv force=4 is in effect, use ADCTRL_QUERY_FORMAT to query the
hzoli
parents:
14814
diff
changeset
|
59 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
|
60 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
|
61 } |
56fb33e23ad4
If -af-adv force=4 is in effect, use ADCTRL_QUERY_FORMAT to query the
hzoli
parents:
14814
diff
changeset
|
62 } |
14819
601e2c8a2922
Remove file-global mpadec, add ad_driver member to sh_audio_t instead.
hzoli
parents:
14818
diff
changeset
|
63 if(!sh_audio->ad_driver->preinit(sh_audio)) |
5342 | 64 { |
6989 | 65 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_ADecoderPreinitFailed); |
5342 | 66 return 0; |
67 } | |
68 | |
5458 | 69 /* allocate audio in buffer: */ |
70 if(sh_audio->audio_in_minsize>0){ | |
71 sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize; | |
6989 | 72 mp_msg(MSGT_DECAUDIO,MSGL_V,MSGTR_AllocatingBytesForInputBuffer, |
5458 | 73 sh_audio->a_in_buffer_size); |
17625 | 74 sh_audio->a_in_buffer=memalign(16,sh_audio->a_in_buffer_size); |
5458 | 75 memset(sh_audio->a_in_buffer,0,sh_audio->a_in_buffer_size); |
76 sh_audio->a_in_buffer_len=0; | |
77 } | |
78 | |
5342 | 79 /* allocate audio out buffer: */ |
80 sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST; /* worst case calc.*/ | |
81 | |
6989 | 82 mp_msg(MSGT_DECAUDIO,MSGL_V,MSGTR_AllocatingBytesForOutputBuffer, |
5342 | 83 sh_audio->audio_out_minsize,MAX_OUTBURST,sh_audio->a_buffer_size); |
84 | |
17625 | 85 sh_audio->a_buffer=memalign(16,sh_audio->a_buffer_size); |
5342 | 86 if(!sh_audio->a_buffer){ |
87 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_CantAllocAudioBuf); | |
88 return 0; | |
89 } | |
90 memset(sh_audio->a_buffer,0,sh_audio->a_buffer_size); | |
91 sh_audio->a_buffer_len=0; | |
92 | |
14819
601e2c8a2922
Remove file-global mpadec, add ad_driver member to sh_audio_t instead.
hzoli
parents:
14818
diff
changeset
|
93 if(!sh_audio->ad_driver->init(sh_audio)){ |
6989 | 94 mp_msg(MSGT_DECAUDIO,MSGL_WARN,MSGTR_ADecoderInitFailed); |
5458 | 95 uninit_audio(sh_audio); // free buffers |
5342 | 96 return 0; |
97 } | |
5458 | 98 |
5342 | 99 sh_audio->inited=1; |
100 | |
101 if(!sh_audio->channels || !sh_audio->samplerate){ | |
102 mp_msg(MSGT_DECAUDIO,MSGL_WARN,MSGTR_UnknownAudio); | |
5458 | 103 uninit_audio(sh_audio); // free buffers |
5342 | 104 return 0; |
105 } | |
106 | |
107 if(!sh_audio->o_bps) | |
108 sh_audio->o_bps=sh_audio->channels*sh_audio->samplerate*sh_audio->samplesize; | |
7522 | 109 |
14814 | 110 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"AUDIO: %d Hz, %d ch, %s, %3.1f kbit/%3.2f%% (ratio: %d->%d)\n", |
7522 | 111 sh_audio->samplerate,sh_audio->channels, |
14814 | 112 af_fmt2str_short(sh_audio->sample_format), |
113 sh_audio->i_bps*8*0.001,((float)sh_audio->i_bps/sh_audio->o_bps)*100.0, | |
114 sh_audio->i_bps,sh_audio->o_bps); | |
19403
84a34f62918d
display correct audio bitrate, samplerate and number of channels once
ivo
parents:
19393
diff
changeset
|
115 mp_msg(MSGT_IDENTIFY,MSGL_INFO,"ID_AUDIO_BITRATE=%d\nID_AUDIO_RATE=%d\n" |
20087 | 116 "ID_AUDIO_NCH=%d\n", sh_audio->i_bps*8, sh_audio->samplerate, |
19403
84a34f62918d
display correct audio bitrate, samplerate and number of channels once
ivo
parents:
19393
diff
changeset
|
117 sh_audio->channels ); |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
118 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
119 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
|
120 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
|
121 sh_audio->a_out_buffer_len=sh_audio->a_buffer_len; |
5458 | 122 |
123 return 1; | |
5342 | 124 } |
125 | |
7522 | 126 int init_audio(sh_audio_t *sh_audio,char* codecname,char* afm,int status){ |
127 unsigned int orig_fourcc=sh_audio->wf?sh_audio->wf->wFormatTag:0; | |
16321
efbfac98cab1
Allow forcing of demuxers and codecs by prepending '+'
reimar
parents:
16306
diff
changeset
|
128 int force = 0; |
efbfac98cab1
Allow forcing of demuxers and codecs by prepending '+'
reimar
parents:
16306
diff
changeset
|
129 if (codecname && codecname[0] == '+') { |
efbfac98cab1
Allow forcing of demuxers and codecs by prepending '+'
reimar
parents:
16306
diff
changeset
|
130 codecname = &codecname[1]; |
efbfac98cab1
Allow forcing of demuxers and codecs by prepending '+'
reimar
parents:
16306
diff
changeset
|
131 force = 1; |
efbfac98cab1
Allow forcing of demuxers and codecs by prepending '+'
reimar
parents:
16306
diff
changeset
|
132 } |
7522 | 133 sh_audio->codec=NULL; |
134 while(1){ | |
14819
601e2c8a2922
Remove file-global mpadec, add ad_driver member to sh_audio_t instead.
hzoli
parents:
14818
diff
changeset
|
135 ad_functions_t* mpadec; |
7522 | 136 int i; |
14819
601e2c8a2922
Remove file-global mpadec, add ad_driver member to sh_audio_t instead.
hzoli
parents:
14818
diff
changeset
|
137 sh_audio->ad_driver = 0; |
7522 | 138 // restore original fourcc: |
139 if(sh_audio->wf) sh_audio->wf->wFormatTag=i=orig_fourcc; | |
16321
efbfac98cab1
Allow forcing of demuxers and codecs by prepending '+'
reimar
parents:
16306
diff
changeset
|
140 if(!(sh_audio->codec=find_audio_codec(sh_audio->format, |
efbfac98cab1
Allow forcing of demuxers and codecs by prepending '+'
reimar
parents:
16306
diff
changeset
|
141 sh_audio->wf?(&i):NULL, sh_audio->codec, force) )) break; |
7522 | 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 | |
16321
efbfac98cab1
Allow forcing of demuxers and codecs by prepending '+'
reimar
parents:
16306
diff
changeset
|
147 if(!force && sh_audio->codec->status<status) continue; // too unstable |
7522 | 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]; | |
8152 | 153 #ifdef DYNAMIC_PLUGINS |
154 if (!mpadec) | |
155 { | |
156 /* try to open shared decoder plugin */ | |
157 int buf_len; | |
158 char *buf; | |
159 ad_functions_t *funcs_sym; | |
160 ad_info_t *info_sym; | |
161 | |
10272
7b0bc557987b
renames: DATADIR->MPLAYER_DATADIR, CONFDIR->MPLAYER_CONFDIR, LIBDIR->MPLAYER_LIBDIR
arpi
parents:
9132
diff
changeset
|
162 buf_len = strlen(MPLAYER_LIBDIR)+strlen(sh_audio->codec->drv)+16; |
8152 | 163 buf = malloc(buf_len); |
164 if (!buf) | |
165 break; | |
10272
7b0bc557987b
renames: DATADIR->MPLAYER_DATADIR, CONFDIR->MPLAYER_CONFDIR, LIBDIR->MPLAYER_LIBDIR
arpi
parents:
9132
diff
changeset
|
166 snprintf(buf, buf_len, "%s/mplayer/ad_%s.so", MPLAYER_LIBDIR, sh_audio->codec->drv); |
8152 | 167 mp_msg(MSGT_DECAUDIO, MSGL_DBG2, "Trying to open external plugin: %s\n", buf); |
168 sh_audio->dec_handle = dlopen(buf, RTLD_LAZY); | |
169 if (!sh_audio->dec_handle) | |
170 break; | |
171 snprintf(buf, buf_len, "mpcodecs_ad_%s", sh_audio->codec->drv); | |
172 funcs_sym = dlsym(sh_audio->dec_handle, buf); | |
173 if (!funcs_sym || !funcs_sym->info || !funcs_sym->preinit || | |
174 !funcs_sym->init || !funcs_sym->uninit || !funcs_sym->control || | |
175 !funcs_sym->decode_audio) | |
176 break; | |
177 info_sym = funcs_sym->info; | |
178 if (strcmp(info_sym->short_name, sh_audio->codec->drv)) | |
179 break; | |
180 free(buf); | |
181 mpadec = funcs_sym; | |
182 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
|
183 MPLAYER_LIBDIR, sh_audio->codec->drv); |
8152 | 184 } |
185 #endif | |
7522 | 186 if(!mpadec){ // driver not available (==compiled in) |
187 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_AudioCodecFamilyNotAvailableStr, | |
188 sh_audio->codec->name, sh_audio->codec->drv); | |
189 continue; | |
190 } | |
191 // it's available, let's try to init! | |
192 // init() | |
193 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
|
194 sh_audio->ad_driver = mpadec; |
7522 | 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 | |
18889
e60c8c7399d2
get_path as const, patch by Stefan Huehner, stefan AT huehner-org
reynaldo
parents:
18879
diff
changeset
|
205 extern char *get_path(const char *filename); |
8123
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 | |
16793
8d4fb5469efb
Make a few more messages translatable by moving them into help_mp-en.h.
diego
parents:
16321
diff
changeset
|
250 mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_SelectedAudioCodec, |
7522 | 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); | |
14819
601e2c8a2922
Remove file-global mpadec, add ad_driver member to sh_audio_t instead.
hzoli
parents:
14818
diff
changeset
|
265 sh_audio->ad_driver->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; |
15811
9b4bbb6098f6
make -srate work again, unify audio filter init and preinit.
reimar
parents:
15789
diff
changeset
|
274 sh_audio->a_out_buffer_size=0; |
5458 | 275 if(sh_audio->a_buffer) free(sh_audio->a_buffer); |
276 sh_audio->a_buffer=NULL; | |
277 if(sh_audio->a_in_buffer) free(sh_audio->a_in_buffer); | |
278 sh_audio->a_in_buffer=NULL; | |
5342 | 279 } |
280 | |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
281 /* Init audio filters */ |
8995
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
282 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
|
283 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
|
284 int* out_samplerate, int* out_channels, int* out_format){ |
16306 | 285 return init_audio_filters(sh_audio, in_samplerate, in_channels, in_format, |
15811
9b4bbb6098f6
make -srate work again, unify audio filter init and preinit.
reimar
parents:
15789
diff
changeset
|
286 out_samplerate, out_channels, out_format, 0, 0); |
8995
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 |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
289 /* Init audio filters */ |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
290 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
|
291 int in_samplerate, int in_channels, int in_format, |
15811
9b4bbb6098f6
make -srate work again, unify audio filter init and preinit.
reimar
parents:
15789
diff
changeset
|
292 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
|
293 int out_minsize, int out_maxsize){ |
8995
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
294 af_stream_t* afs=sh_audio->afilter; |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
295 if(!afs){ |
18879 | 296 afs = malloc(sizeof(af_stream_t)); |
8995
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
297 memset(afs,0,sizeof(af_stream_t)); |
865cbed58cf8
2-pass libaf initialization to get better filter chain.
arpi
parents:
8969
diff
changeset
|
298 } |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
299 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
300 // input format: same as codec's output format: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
301 afs->input.rate = in_samplerate; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
302 afs->input.nch = in_channels; |
14245 | 303 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
|
304 af_fix_parameters(&(afs->input)); |
7604
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 // output format: same as ao driver's input format (if missing, fallback to input) |
15811
9b4bbb6098f6
make -srate work again, unify audio filter init and preinit.
reimar
parents:
15789
diff
changeset
|
307 afs->output.rate = *out_samplerate; |
9b4bbb6098f6
make -srate work again, unify audio filter init and preinit.
reimar
parents:
15789
diff
changeset
|
308 afs->output.nch = *out_channels; |
9b4bbb6098f6
make -srate work again, unify audio filter init and preinit.
reimar
parents:
15789
diff
changeset
|
309 afs->output.format = *out_format; |
14818
663c1ea5f595
finally remove the refences to bps outside libaf. also simplification of some messages and removed redundants
alex
parents:
14815
diff
changeset
|
310 af_fix_parameters(&(afs->output)); |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
311 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
312 // filter config: |
7614 | 313 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
|
314 |
17427
ac53dc3093a7
Push "Building audio filter chain" up to verbose level.
diego
parents:
17012
diff
changeset
|
315 mp_msg(MSGT_DECAUDIO, MSGL_V, MSGTR_BuildingAudioFilterChain, |
14818
663c1ea5f595
finally remove the refences to bps outside libaf. also simplification of some messages and removed redundants
alex
parents:
14815
diff
changeset
|
316 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
|
317 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
|
318 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
319 // let's autoprobe it! |
15811
9b4bbb6098f6
make -srate work again, unify audio filter init and preinit.
reimar
parents:
15789
diff
changeset
|
320 if(0 != af_init(afs)){ |
9132 | 321 sh_audio->afilter=NULL; |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
322 free(afs); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
323 return 0; // failed :( |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
324 } |
15811
9b4bbb6098f6
make -srate work again, unify audio filter init and preinit.
reimar
parents:
15789
diff
changeset
|
325 |
9b4bbb6098f6
make -srate work again, unify audio filter init and preinit.
reimar
parents:
15789
diff
changeset
|
326 *out_samplerate=afs->output.rate; |
9b4bbb6098f6
make -srate work again, unify audio filter init and preinit.
reimar
parents:
15789
diff
changeset
|
327 *out_channels=afs->output.nch; |
9b4bbb6098f6
make -srate work again, unify audio filter init and preinit.
reimar
parents:
15789
diff
changeset
|
328 *out_format=afs->output.format; |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
329 |
15811
9b4bbb6098f6
make -srate work again, unify audio filter init and preinit.
reimar
parents:
15789
diff
changeset
|
330 if (out_maxsize || out_minsize) { |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
331 // allocate the a_out_* buffers: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
332 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
|
333 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
|
334 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
335 sh_audio->a_out_buffer_size=out_maxsize; |
22180 | 336 if (sh_audio->a_out_buffer != sh_audio->a_buffer) |
337 free(sh_audio->a_out_buffer); | |
17625 | 338 sh_audio->a_out_buffer=memalign(16,sh_audio->a_out_buffer_size); |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
339 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
|
340 sh_audio->a_out_buffer_len=0; |
15811
9b4bbb6098f6
make -srate work again, unify audio filter init and preinit.
reimar
parents:
15789
diff
changeset
|
341 } |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
342 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
343 // ok! |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
344 sh_audio->afilter=(void*)afs; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
345 return 1; |
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 |
5342 | 348 int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen) |
349 { | |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
350 int declen; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
351 af_data_t afd; // filter input |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
352 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
|
353 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
|
354 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
355 if(!sh_audio->inited) return -1; // no codec |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
356 if(!sh_audio->afilter){ |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
357 // no filter, just decode: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
358 // 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
|
359 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
|
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 // declen=af_inputlen(sh_audio->afilter,minlen); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
363 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
|
364 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
|
365 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
366 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
|
367 minlen, maxlen, declen, sh_audio->a_buffer_size); |
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(declen<=0) return -1; // error! |
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 // 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
|
372 // 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
|
373 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
374 // decode if needed: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
375 while(declen>sh_audio->a_buffer_len){ |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
376 int len=declen-sh_audio->a_buffer_len; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
377 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
|
378 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
379 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
|
380 len, maxlen, sh_audio->audio_out_minsize); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
381 |
19392
925e7643a526
Fix buffer size sanity check to match what is actually required.
uau
parents:
18889
diff
changeset
|
382 // When a decoder sets audio_out_minsize that should guarantee it can |
925e7643a526
Fix buffer size sanity check to match what is actually required.
uau
parents:
18889
diff
changeset
|
383 // write up to audio_out_minsize bytes at a time until total >= minlen |
925e7643a526
Fix buffer size sanity check to match what is actually required.
uau
parents:
18889
diff
changeset
|
384 // without checking maxlen. Thus maxlen must be at least minlen + |
925e7643a526
Fix buffer size sanity check to match what is actually required.
uau
parents:
18889
diff
changeset
|
385 // audio_out_minsize. Check that to guard against buffer overflows. |
925e7643a526
Fix buffer size sanity check to match what is actually required.
uau
parents:
18889
diff
changeset
|
386 if (maxlen < len + sh_audio->audio_out_minsize) |
925e7643a526
Fix buffer size sanity check to match what is actually required.
uau
parents:
18889
diff
changeset
|
387 break; |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
388 // 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
|
389 len=mpadec->decode_audio(sh_audio, |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
390 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
|
391 if(len<=0) break; // EOF? |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
392 sh_audio->a_buffer_len+=len; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
393 } |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
394 if(declen>sh_audio->a_buffer_len) |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
395 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
|
396 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
397 // round to whole samples: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
398 // declen/=sh_audio->samplesize*sh_audio->channels; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
399 // declen*=sh_audio->samplesize*sh_audio->channels; |
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 // run the filters: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
402 afd.audio=sh_audio->a_buffer; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
403 afd.len=declen; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
404 afd.rate=sh_audio->samplerate; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
405 afd.nch=sh_audio->channels; |
14245 | 406 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
|
407 af_fix_parameters(&afd); |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
408 //pafd=&afd; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
409 // printf("\nAF: %d --> ",declen); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
410 pafd=af_play(sh_audio->afilter,&afd); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
411 // printf("%d \n",pafd->len); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
412 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
413 if(!pafd) return -1; // error |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
414 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
415 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
|
416 declen, pafd->len, maxlen); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
417 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
418 // copy filter==>out: |
11857
6107e58dcc28
not pretty, but at least it prevents the channels from getting out of order...
rfelker
parents:
11855
diff
changeset
|
419 if(maxlen < pafd->len) { |
20752
0617c67ad68f
Fix code that cuts audio data if the filters produce too much.
uau
parents:
20087
diff
changeset
|
420 af_stream_t *afs = sh_audio->afilter; |
0617c67ad68f
Fix code that cuts audio data if the filters produce too much.
uau
parents:
20087
diff
changeset
|
421 maxlen -= maxlen % (afs->output.nch * afs->output.bps); |
11855 | 422 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
|
423 } |
5342 | 424 else |
7604
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
425 maxlen=pafd->len; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
426 memmove(buf, pafd->audio, maxlen); |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
427 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
428 // remove processed data from decoder buffer: |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
429 sh_audio->a_buffer_len-=declen; |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
430 if(sh_audio->a_buffer_len>0) |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
431 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
|
432 |
32efb806436e
aufio filter layer (libaf) integration to libmpcodecs, mplayer and mencoder
arpi
parents:
7561
diff
changeset
|
433 return maxlen; |
5342 | 434 } |
435 | |
436 void resync_audio_stream(sh_audio_t *sh_audio) | |
437 { | |
6049 | 438 sh_audio->a_in_buffer_len=0; // clear audio input buffer |
5342 | 439 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
|
440 sh_audio->ad_driver->control(sh_audio,ADCTRL_RESYNC_STREAM,NULL); |
5342 | 441 } |
442 | |
443 void skip_audio_frame(sh_audio_t *sh_audio) | |
444 { | |
445 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
|
446 if(sh_audio->ad_driver->control(sh_audio,ADCTRL_SKIP_FRAME,NULL)==CONTROL_TRUE) return; |
5342 | 447 // default skip code: |
448 ds_fill_buffer(sh_audio->ds); // skip block | |
449 } |