Mercurial > mplayer.hg
annotate dec_audio.c @ 1332:cba6d263bf85
Poprawki wprowadzone przez: Justyna Bia?a <nell@skrzynka.pl>
author | eyck |
---|---|
date | Mon, 16 Jul 2001 16:59:47 +0000 |
parents | b12e1817bcc2 |
children | 71ad3e1ba014 |
rev | line source |
---|---|
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
1 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
2 #include <stdio.h> |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
3 #include <stdlib.h> |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
4 |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
5 #include "config.h" |
1058 | 6 #include "libao2/afmt.h" |
758 | 7 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
8 extern int verbose; // defined in mplayer.c |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
9 |
732
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
10 #ifdef USE_FAKE_MONO |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
11 int fakemono=0; |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
12 #endif |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
13 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
14 #include "stream.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
15 #include "demuxer.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
16 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
17 #include "wine/mmreg.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
18 #include "wine/avifmt.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
19 #include "wine/vfw.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
20 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
21 #include "codec-cfg.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
22 #include "stheader.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
23 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
24 #include "mp3lib/mp3.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
25 #include "libac3/ac3.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
26 |
883 | 27 #include "alaw.h" |
28 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
29 #include "xa/xa_gsm.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
30 |
1291 | 31 #ifdef USE_DIRECTSHOW |
604 | 32 #include "loader/DirectShow/DS_AudioDec.h" |
1291 | 33 #endif |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
34 |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
35 extern int init_acm_audio_codec(sh_audio_t *sh_audio); |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
36 extern int acm_decode_audio(sh_audio_t *sh_audio, void* a_buffer,int minlen,int maxlen); |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
37 |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
38 |
1289 | 39 static sh_audio_t* dec_audio_sh=NULL; |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
40 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
41 // AC3 decoder buffer callback: |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
42 static void ac3_fill_buffer(uint8_t **start,uint8_t **end){ |
1289 | 43 int len=ds_get_packet(dec_audio_sh->ds,start); |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
44 //printf("<ac3:%d>\n",len); |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
45 if(len<0) |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
46 *start = *end = NULL; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
47 else |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
48 *end = *start + len; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
49 } |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
50 |
1289 | 51 // MP3 decoder buffer callback: |
52 int mplayer_audio_read(char *buf,int size){ | |
53 int len; | |
54 len=demux_read_data(dec_audio_sh->ds,buf,size); | |
55 return len; | |
56 } | |
57 | |
296 | 58 int init_audio(sh_audio_t *sh_audio){ |
303 | 59 int driver=sh_audio->codec->driver; |
296 | 60 |
61 sh_audio->samplesize=2; | |
1320
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1313
diff
changeset
|
62 #if WORDS_BIGENDIAN |
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1313
diff
changeset
|
63 sh_audio->sample_format=AFMT_S16_BE; |
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1313
diff
changeset
|
64 #else |
758 | 65 sh_audio->sample_format=AFMT_S16_LE; |
1320
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1313
diff
changeset
|
66 #endif |
303 | 67 sh_audio->samplerate=0; |
401 | 68 //sh_audio->pcm_bswap=0; |
303 | 69 |
758 | 70 sh_audio->a_buffer_size=0; |
303 | 71 sh_audio->a_buffer=NULL; |
296 | 72 |
746 | 73 sh_audio->a_in_buffer_len=0; |
74 | |
758 | 75 // setup required min. in/out buffer size: |
76 sh_audio->audio_out_minsize=8192;// default size, maybe not enough for Win32/ACM | |
77 | |
78 switch(driver){ | |
79 case 4: | |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
80 #ifndef ARCH_X86 |
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
81 printf("Win32/ACM audio codec unavailable on non-x86 CPU -> force nosound :(\n"); |
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
82 driver=0; |
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
83 #else |
296 | 84 // Win32 ACM audio codec: |
85 if(init_acm_audio_codec(sh_audio)){ | |
746 | 86 sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec; |
296 | 87 sh_audio->channels=sh_audio->o_wf.nChannels; |
88 sh_audio->samplerate=sh_audio->o_wf.nSamplesPerSec; | |
758 | 89 // if(sh_audio->audio_out_minsize>16384) sh_audio->audio_out_minsize=16384; |
90 // sh_audio->a_buffer_size=sh_audio->audio_out_minsize; | |
91 // if(sh_audio->a_buffer_size<sh_audio->audio_out_minsize+MAX_OUTBURST) | |
92 // sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST; | |
296 | 93 } else { |
94 printf("Could not load/initialize Win32/ACM AUDIO codec (missing DLL file?)\n"); | |
303 | 95 driver=0; |
296 | 96 } |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
97 #endif |
758 | 98 break; |
99 case 7: | |
296 | 100 #ifndef USE_DIRECTSHOW |
101 printf("Compiled without DirectShow support -> force nosound :(\n"); | |
303 | 102 driver=0; |
296 | 103 #else |
104 // Win32 DShow audio codec: | |
340 | 105 // printf("DShow_audio: channs=%d rate=%d\n",sh_audio->channels,sh_audio->samplerate); |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
106 if(DS_AudioDecoder_Open(sh_audio->codec->dll,&sh_audio->codec->guid,sh_audio->wf)){ |
303 | 107 printf("ERROR: Could not load/initialize Win32/DirctShow AUDIO codec: %s\n",sh_audio->codec->dll); |
108 driver=0; | |
109 } else { | |
746 | 110 sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec; |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
111 sh_audio->channels=sh_audio->wf->nChannels; |
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
112 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; |
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
113 sh_audio->audio_in_minsize=2*sh_audio->wf->nBlockAlign; |
296 | 114 if(sh_audio->audio_in_minsize<8192) sh_audio->audio_in_minsize=8192; |
115 sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize; | |
116 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size); | |
117 sh_audio->a_in_buffer_len=0; | |
758 | 118 sh_audio->audio_out_minsize=16384; |
296 | 119 } |
120 #endif | |
758 | 121 break; |
122 case 2: | |
123 case 8: | |
124 case 5: | |
125 // PCM, aLaw | |
126 sh_audio->audio_out_minsize=2048; | |
127 break; | |
128 case 3: | |
129 // Dolby AC3 audio: | |
130 sh_audio->audio_out_minsize=4*256*6; | |
131 break; | |
132 case 6: | |
133 // MS-GSM audio codec: | |
134 sh_audio->audio_out_minsize=4*320; | |
135 break; | |
136 case 1: | |
137 // MPEG Audio: | |
138 sh_audio->audio_out_minsize=4608; | |
139 break; | |
296 | 140 } |
141 | |
303 | 142 if(!driver) return 0; |
296 | 143 |
144 // allocate audio out buffer: | |
758 | 145 sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST; // worst case calc. |
146 | |
147 printf("dec_audio: Allocating %d + %d = %d bytes for output buffer\n", | |
148 sh_audio->audio_out_minsize,MAX_OUTBURST,sh_audio->a_buffer_size); | |
149 | |
296 | 150 sh_audio->a_buffer=malloc(sh_audio->a_buffer_size); |
758 | 151 if(!sh_audio->a_buffer){ |
152 printf("Cannot allocate audio out buffer\n"); | |
153 return 0; | |
154 } | |
296 | 155 memset(sh_audio->a_buffer,0,sh_audio->a_buffer_size); |
156 sh_audio->a_buffer_len=0; | |
157 | |
303 | 158 switch(driver){ |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
159 #ifdef ARCH_X86 |
303 | 160 case 4: { |
758 | 161 int ret=acm_decode_audio(sh_audio,sh_audio->a_buffer,4096,sh_audio->a_buffer_size); |
296 | 162 if(ret<0){ |
303 | 163 printf("ACM decoding error: %d\n",ret); |
164 driver=0; | |
296 | 165 } |
640 | 166 sh_audio->a_buffer_len=ret; |
303 | 167 break; |
296 | 168 } |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
169 #endif |
303 | 170 case 2: { |
296 | 171 // AVI PCM Audio: |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
172 WAVEFORMATEX *h=sh_audio->wf; |
746 | 173 sh_audio->i_bps=h->nAvgBytesPerSec; |
296 | 174 sh_audio->channels=h->nChannels; |
175 sh_audio->samplerate=h->nSamplesPerSec; | |
176 sh_audio->samplesize=(h->wBitsPerSample+7)/8; | |
758 | 177 switch(sh_audio->format){ // hardware formats: |
178 case 0x6: sh_audio->sample_format=AFMT_A_LAW;break; | |
179 case 0x7: sh_audio->sample_format=AFMT_MU_LAW;break; | |
180 case 0x11: sh_audio->sample_format=AFMT_IMA_ADPCM;break; | |
181 case 0x50: sh_audio->sample_format=AFMT_MPEG;break; | |
182 // case 0x2000: sh_audio->sample_format=AFMT_AC3; | |
183 default: sh_audio->sample_format=(sh_audio->samplesize==2)?AFMT_S16_LE:AFMT_U8; | |
184 } | |
401 | 185 break; |
186 } | |
187 case 8: { | |
188 // DVD PCM Audio: | |
189 sh_audio->channels=2; | |
190 sh_audio->samplerate=48000; | |
746 | 191 sh_audio->i_bps=2*2*48000; |
296 | 192 // sh_audio->pcm_bswap=1; |
303 | 193 break; |
194 } | |
195 case 3: { | |
296 | 196 // Dolby AC3 audio: |
1289 | 197 dec_audio_sh=sh_audio; // save sh_audio for the callback: |
296 | 198 ac3_config.fill_buffer_callback = ac3_fill_buffer; |
199 ac3_config.num_output_ch = 2; | |
200 ac3_config.flags = 0; | |
201 #ifdef HAVE_MMX | |
202 ac3_config.flags |= AC3_MMX_ENABLE; | |
203 #endif | |
204 #ifdef HAVE_3DNOW | |
205 ac3_config.flags |= AC3_3DNOW_ENABLE; | |
206 #endif | |
207 ac3_init(); | |
208 sh_audio->ac3_frame = ac3_decode_frame(); | |
209 if(sh_audio->ac3_frame){ | |
746 | 210 ac3_frame_t* fr=(ac3_frame_t*)sh_audio->ac3_frame; |
211 sh_audio->samplerate=fr->sampling_rate; | |
296 | 212 sh_audio->channels=2; |
746 | 213 // 1 frame: 6*256 samples 1 sec: sh_audio->samplerate samples |
214 //sh_audio->i_bps=fr->frame_size*fr->sampling_rate/(6*256); | |
215 sh_audio->i_bps=fr->bit_rate*(1000/8); | |
303 | 216 } else { |
217 driver=0; // bad frame -> disable audio | |
218 } | |
219 break; | |
220 } | |
221 case 5: { | |
296 | 222 // aLaw audio codec: |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
223 sh_audio->channels=sh_audio->wf->nChannels; |
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
224 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; |
746 | 225 sh_audio->i_bps=sh_audio->channels*sh_audio->samplerate; |
303 | 226 break; |
227 } | |
228 case 6: { | |
296 | 229 // MS-GSM audio codec: |
230 GSM_Init(); | |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
231 sh_audio->channels=sh_audio->wf->nChannels; |
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
232 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; |
746 | 233 // decodes 65 byte -> 320 short |
234 // 1 sec: sh_audio->channels*sh_audio->samplerate samples | |
235 // 1 frame: 320 samples | |
236 sh_audio->i_bps=65*(sh_audio->channels*sh_audio->samplerate)/320; // 1:10 | |
303 | 237 break; |
296 | 238 } |
303 | 239 case 1: { |
296 | 240 // MPEG Audio: |
1289 | 241 dec_audio_sh=sh_audio; // save sh_audio for the callback: |
732
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
242 #ifdef USE_FAKE_MONO |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
243 MP3_Init(fakemono); |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
244 #else |
296 | 245 MP3_Init(); |
732
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
246 #endif |
296 | 247 MP3_samplerate=MP3_channels=0; |
248 // printf("[\n"); | |
249 sh_audio->a_buffer_len=MP3_DecodeFrame(sh_audio->a_buffer,-1); | |
250 // printf("]\n"); | |
251 sh_audio->channels=2; // hack | |
252 sh_audio->samplerate=MP3_samplerate; | |
746 | 253 sh_audio->i_bps=MP3_bitrate*(1000/8); |
303 | 254 break; |
255 } | |
296 | 256 } |
257 | |
258 if(!sh_audio->channels || !sh_audio->samplerate){ | |
259 printf("Unknown/missing audio format, using nosound\n"); | |
303 | 260 driver=0; |
296 | 261 } |
262 | |
303 | 263 if(!driver){ |
264 if(sh_audio->a_buffer) free(sh_audio->a_buffer); | |
1313
d797ecb9778f
sh_audio->a_buffer is freed twice (here and in mplayer.c), can result to
jkeil
parents:
1309
diff
changeset
|
265 sh_audio->a_buffer=NULL; |
303 | 266 sh_audio->o_bps=0; |
267 return 0; | |
268 } | |
296 | 269 |
303 | 270 sh_audio->o_bps=sh_audio->channels*sh_audio->samplerate*sh_audio->samplesize; |
271 return driver; | |
296 | 272 } |
291 | 273 |
746 | 274 // Audio decoding: |
291 | 275 |
746 | 276 // Decode a single frame (mp3,acm etc) or 'minlen' bytes (pcm/alaw etc) |
277 // buffer length is 'maxlen' bytes, it shouldn't be exceeded... | |
278 | |
279 int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen){ | |
291 | 280 int len=-1; |
303 | 281 switch(sh_audio->codec->driver){ |
291 | 282 case 1: // MPEG layer 2 or 3 |
283 len=MP3_DecodeFrame(buf,-1); | |
284 break; | |
401 | 285 case 2: // AVI PCM |
1058 | 286 len=demux_read_data(sh_audio->ds,buf,minlen); |
401 | 287 break; |
288 case 8: // DVD PCM | |
289 { int j; | |
746 | 290 len=demux_read_data(sh_audio->ds,buf,minlen); |
291 | 291 //if(i&1){ printf("Warning! pcm_audio_size&1 !=0 (%d)\n",i);i&=~1; } |
746 | 292 // swap endian: |
291 | 293 for(j=0;j<len;j+=2){ |
294 char x=buf[j]; | |
295 buf[j]=buf[j+1]; | |
296 buf[j+1]=x; | |
297 } | |
298 break; | |
299 } | |
300 case 5: // aLaw decoder | |
746 | 301 { int l=demux_read_data(sh_audio->ds,buf,minlen/2); |
291 | 302 unsigned short *d=(unsigned short *) buf; |
303 unsigned char *s=buf; | |
304 len=2*l; | |
758 | 305 if(sh_audio->format==6){ |
306 // aLaw | |
883 | 307 while(l>0){ --l; d[l]=alaw2short[s[l]]; } |
758 | 308 } else { |
309 // uLaw | |
883 | 310 while(l>0){ --l; d[l]=ulaw2short[s[l]]; } |
291 | 311 } |
312 break; | |
313 } | |
314 case 6: // MS-GSM decoder | |
315 { unsigned char buf[65]; // 65 bytes / frame | |
746 | 316 if(demux_read_data(sh_audio->ds,buf,65)!=65) break; // EOF |
317 XA_MSGSM_Decoder(buf,(unsigned short *) buf); // decodes 65 byte -> 320 short | |
318 // XA_GSM_Decoder(buf,(unsigned short *) &sh_audio->a_buffer[sh_audio->a_buffer_len]); // decodes 33 byte -> 160 short | |
319 len=2*320; | |
291 | 320 break; |
321 } | |
322 case 3: // AC3 decoder | |
323 //printf("{1:%d}",avi_header.idx_pos);fflush(stdout); | |
324 if(!sh_audio->ac3_frame) sh_audio->ac3_frame=ac3_decode_frame(); | |
325 //printf("{2:%d}",avi_header.idx_pos);fflush(stdout); | |
326 if(sh_audio->ac3_frame){ | |
296 | 327 len = 256 * 6 *sh_audio->channels*sh_audio->samplesize; |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
328 memcpy(buf,((ac3_frame_t*)sh_audio->ac3_frame)->audio_data,len); |
291 | 329 sh_audio->ac3_frame=NULL; |
330 } | |
331 //printf("{3:%d}",avi_header.idx_pos);fflush(stdout); | |
332 break; | |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
333 #ifdef ARCH_X86 |
291 | 334 case 4: |
758 | 335 // len=sh_audio->audio_out_minsize; // optimal decoded fragment size |
336 // if(len<minlen) len=minlen; else | |
337 // if(len>maxlen) len=maxlen; | |
338 // len=acm_decode_audio(sh_audio,buf,len); | |
339 len=acm_decode_audio(sh_audio,buf,minlen,maxlen); | |
291 | 340 break; |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
341 #endif |
746 | 342 |
291 | 343 #ifdef USE_DIRECTSHOW |
344 case 7: // DirectShow | |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
345 { int size_in=0; |
291 | 346 int size_out=0; |
347 int srcsize=DS_AudioDecoder_GetSrcSize(maxlen); | |
348 if(verbose>2)printf("DShow says: srcsize=%d (buffsize=%d) out_size=%d\n",srcsize,sh_audio->a_in_buffer_size,maxlen); | |
349 if(srcsize>sh_audio->a_in_buffer_size) srcsize=sh_audio->a_in_buffer_size; // !!!!!! | |
350 if(sh_audio->a_in_buffer_len<srcsize){ | |
351 sh_audio->a_in_buffer_len+= | |
352 demux_read_data(sh_audio->ds,&sh_audio->a_in_buffer[sh_audio->a_in_buffer_len], | |
353 srcsize-sh_audio->a_in_buffer_len); | |
354 } | |
355 DS_AudioDecoder_Convert(sh_audio->a_in_buffer,sh_audio->a_in_buffer_len, | |
356 buf,maxlen, &size_in,&size_out); | |
754 | 357 if(verbose) |
358 printf("DShow: audio %d -> %d converted (in_buf_len=%d of %d) %d\n",size_in,size_out,sh_audio->a_in_buffer_len,sh_audio->a_in_buffer_size,ds_tell_pts(sh_audio->ds)); | |
291 | 359 if(size_in>=sh_audio->a_in_buffer_len){ |
360 sh_audio->a_in_buffer_len=0; | |
361 } else { | |
362 sh_audio->a_in_buffer_len-=size_in; | |
363 memcpy(sh_audio->a_in_buffer,&sh_audio->a_in_buffer[size_in],sh_audio->a_in_buffer_len); | |
364 } | |
365 len=size_out; | |
366 break; | |
367 } | |
368 #endif | |
369 } | |
370 return len; | |
371 } | |
372 | |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
373 void resync_audio_stream(sh_audio_t *sh_audio){ |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
374 switch(sh_audio->codec->driver){ |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
375 case 1: |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
376 MP3_DecodeFrame(NULL,-2); // resync |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
377 MP3_DecodeFrame(NULL,-2); // resync |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
378 MP3_DecodeFrame(NULL,-2); // resync |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
379 break; |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
380 case 3: |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
381 ac3_bitstream_reset(); // reset AC3 bitstream buffer |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
382 // if(verbose){ printf("Resyncing AC3 audio...");fflush(stdout);} |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
383 sh_audio->ac3_frame=ac3_decode_frame(); // resync |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
384 // if(verbose) printf(" OK!\n"); |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
385 break; |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
386 case 4: |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
387 case 7: |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
388 sh_audio->a_in_buffer_len=0; // reset ACM/DShow audio buffer |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
389 break; |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
390 } |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
391 } |
291 | 392 |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
393 void skip_audio_frame(sh_audio_t *sh_audio){ |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
394 switch(sh_audio->codec->driver){ |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
395 case 1: MP3_DecodeFrame(NULL,-2);break; // skip MPEG frame |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
396 case 3: sh_audio->ac3_frame=ac3_decode_frame();break; // skip AC3 frame |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
397 default: ds_fill_buffer(sh_audio->ds); // skip PCM frame |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
398 } |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
399 } |