Mercurial > mplayer.hg
annotate dec_audio.c @ 1699:7ddc63b84f1f
DGA2 ifdefs, new mainloop/timer stuff
author | arpi |
---|---|
date | Sat, 25 Aug 2001 23:18:17 +0000 |
parents | 5c7760aa4f94 |
children | 60afe3421c04 |
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> |
1430 | 4 #include <unistd.h> |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
5 |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
6 #include "config.h" |
1567 | 7 #include "mp_msg.h" |
8 | |
1058 | 9 #include "libao2/afmt.h" |
758 | 10 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
11 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
|
12 |
732
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
13 #ifdef USE_FAKE_MONO |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
14 int fakemono=0; |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
15 #endif |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
16 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
17 #include "stream.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
18 #include "demuxer.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
19 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
20 #include "wine/mmreg.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
21 #include "wine/avifmt.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
22 #include "wine/vfw.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 "codec-cfg.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
25 #include "stheader.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
26 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
27 #include "mp3lib/mp3.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
28 #include "libac3/ac3.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
29 |
883 | 30 #include "alaw.h" |
31 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
32 #include "xa/xa_gsm.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
33 |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
34 #include "ac3-iec958.h" |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
35 |
1291 | 36 #ifdef USE_DIRECTSHOW |
604 | 37 #include "loader/DirectShow/DS_AudioDec.h" |
1291 | 38 #endif |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
39 |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
40 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
|
41 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
|
42 |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
43 |
1289 | 44 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
|
45 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
46 // AC3 decoder buffer callback: |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
47 static void ac3_fill_buffer(uint8_t **start,uint8_t **end){ |
1289 | 48 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
|
49 //printf("<ac3:%d>\n",len); |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
50 if(len<0) |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
51 *start = *end = NULL; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
52 else |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
53 *end = *start + len; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
54 } |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
55 |
1289 | 56 // MP3 decoder buffer callback: |
57 int mplayer_audio_read(char *buf,int size){ | |
58 int len; | |
59 len=demux_read_data(dec_audio_sh->ds,buf,size); | |
60 return len; | |
61 } | |
62 | |
296 | 63 int init_audio(sh_audio_t *sh_audio){ |
303 | 64 int driver=sh_audio->codec->driver; |
296 | 65 |
66 sh_audio->samplesize=2; | |
1320
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1313
diff
changeset
|
67 #if WORDS_BIGENDIAN |
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1313
diff
changeset
|
68 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
|
69 #else |
758 | 70 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
|
71 #endif |
303 | 72 sh_audio->samplerate=0; |
401 | 73 //sh_audio->pcm_bswap=0; |
1529 | 74 sh_audio->o_bps=0; |
303 | 75 |
758 | 76 sh_audio->a_buffer_size=0; |
303 | 77 sh_audio->a_buffer=NULL; |
296 | 78 |
746 | 79 sh_audio->a_in_buffer_len=0; |
80 | |
758 | 81 // setup required min. in/out buffer size: |
82 sh_audio->audio_out_minsize=8192;// default size, maybe not enough for Win32/ACM | |
83 | |
84 switch(driver){ | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
85 case AFM_ACM: |
1517
0e9c29538a86
Use USE_WIN32DLL define instead of ARCH_X86 to decide whether or not to compile
jkeil
parents:
1485
diff
changeset
|
86 #ifndef USE_WIN32DLL |
1567 | 87 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"Win32/ACM audio codec disabled, or unavailable on non-x86 CPU -> force nosound :(\n"); |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
88 driver=0; |
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
89 #else |
296 | 90 // Win32 ACM audio codec: |
91 if(init_acm_audio_codec(sh_audio)){ | |
746 | 92 sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec; |
296 | 93 sh_audio->channels=sh_audio->o_wf.nChannels; |
94 sh_audio->samplerate=sh_audio->o_wf.nSamplesPerSec; | |
758 | 95 // if(sh_audio->audio_out_minsize>16384) sh_audio->audio_out_minsize=16384; |
96 // sh_audio->a_buffer_size=sh_audio->audio_out_minsize; | |
97 // if(sh_audio->a_buffer_size<sh_audio->audio_out_minsize+MAX_OUTBURST) | |
98 // sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST; | |
296 | 99 } else { |
1567 | 100 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"Could not load/initialize Win32/ACM AUDIO codec (missing DLL file?)\n"); |
303 | 101 driver=0; |
296 | 102 } |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
103 #endif |
758 | 104 break; |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
105 case AFM_DSHOW: |
296 | 106 #ifndef USE_DIRECTSHOW |
1567 | 107 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"Compiled without DirectShow support -> force nosound :(\n"); |
303 | 108 driver=0; |
296 | 109 #else |
110 // Win32 DShow audio codec: | |
340 | 111 // 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
|
112 if(DS_AudioDecoder_Open(sh_audio->codec->dll,&sh_audio->codec->guid,sh_audio->wf)){ |
1567 | 113 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"ERROR: Could not load/initialize Win32/DirctShow AUDIO codec: %s\n",sh_audio->codec->dll); |
303 | 114 driver=0; |
115 } else { | |
746 | 116 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
|
117 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
|
118 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
|
119 sh_audio->audio_in_minsize=2*sh_audio->wf->nBlockAlign; |
296 | 120 if(sh_audio->audio_in_minsize<8192) sh_audio->audio_in_minsize=8192; |
121 sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize; | |
122 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size); | |
123 sh_audio->a_in_buffer_len=0; | |
758 | 124 sh_audio->audio_out_minsize=16384; |
296 | 125 } |
126 #endif | |
758 | 127 break; |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
128 case AFM_PCM: |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
129 case AFM_DVDPCM: |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
130 case AFM_ALAW: |
758 | 131 // PCM, aLaw |
132 sh_audio->audio_out_minsize=2048; | |
133 break; | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
134 case AFM_AC3: |
758 | 135 // Dolby AC3 audio: |
136 sh_audio->audio_out_minsize=4*256*6; | |
137 break; | |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
138 case AFM_HWAC3: |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
139 // Dolby AC3 audio: |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
140 sh_audio->audio_out_minsize=4*256*6; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
141 sh_audio->sample_format = AFMT_AC3; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
142 break; |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
143 case AFM_GSM: |
758 | 144 // MS-GSM audio codec: |
145 sh_audio->audio_out_minsize=4*320; | |
146 break; | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
147 case AFM_MPEG: |
758 | 148 // MPEG Audio: |
149 sh_audio->audio_out_minsize=4608; | |
150 break; | |
296 | 151 } |
152 | |
303 | 153 if(!driver) return 0; |
296 | 154 |
155 // allocate audio out buffer: | |
758 | 156 sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST; // worst case calc. |
157 | |
1567 | 158 mp_msg(MSGT_DECAUDIO,MSGL_V,"dec_audio: Allocating %d + %d = %d bytes for output buffer\n", |
758 | 159 sh_audio->audio_out_minsize,MAX_OUTBURST,sh_audio->a_buffer_size); |
160 | |
296 | 161 sh_audio->a_buffer=malloc(sh_audio->a_buffer_size); |
758 | 162 if(!sh_audio->a_buffer){ |
1567 | 163 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"Cannot allocate audio out buffer\n"); |
758 | 164 return 0; |
165 } | |
296 | 166 memset(sh_audio->a_buffer,0,sh_audio->a_buffer_size); |
167 sh_audio->a_buffer_len=0; | |
168 | |
303 | 169 switch(driver){ |
1517
0e9c29538a86
Use USE_WIN32DLL define instead of ARCH_X86 to decide whether or not to compile
jkeil
parents:
1485
diff
changeset
|
170 #ifdef USE_WIN32DLL |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
171 case AFM_ACM: { |
758 | 172 int ret=acm_decode_audio(sh_audio,sh_audio->a_buffer,4096,sh_audio->a_buffer_size); |
296 | 173 if(ret<0){ |
1567 | 174 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"ACM decoding error: %d\n",ret); |
303 | 175 driver=0; |
296 | 176 } |
640 | 177 sh_audio->a_buffer_len=ret; |
303 | 178 break; |
296 | 179 } |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
180 #endif |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
181 case AFM_PCM: { |
296 | 182 // 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
|
183 WAVEFORMATEX *h=sh_audio->wf; |
746 | 184 sh_audio->i_bps=h->nAvgBytesPerSec; |
296 | 185 sh_audio->channels=h->nChannels; |
186 sh_audio->samplerate=h->nSamplesPerSec; | |
187 sh_audio->samplesize=(h->wBitsPerSample+7)/8; | |
758 | 188 switch(sh_audio->format){ // hardware formats: |
189 case 0x6: sh_audio->sample_format=AFMT_A_LAW;break; | |
190 case 0x7: sh_audio->sample_format=AFMT_MU_LAW;break; | |
191 case 0x11: sh_audio->sample_format=AFMT_IMA_ADPCM;break; | |
192 case 0x50: sh_audio->sample_format=AFMT_MPEG;break; | |
193 // case 0x2000: sh_audio->sample_format=AFMT_AC3; | |
194 default: sh_audio->sample_format=(sh_audio->samplesize==2)?AFMT_S16_LE:AFMT_U8; | |
195 } | |
401 | 196 break; |
197 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
198 case AFM_DVDPCM: { |
401 | 199 // DVD PCM Audio: |
200 sh_audio->channels=2; | |
201 sh_audio->samplerate=48000; | |
746 | 202 sh_audio->i_bps=2*2*48000; |
296 | 203 // sh_audio->pcm_bswap=1; |
303 | 204 break; |
205 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
206 case AFM_AC3: { |
296 | 207 // Dolby AC3 audio: |
1289 | 208 dec_audio_sh=sh_audio; // save sh_audio for the callback: |
296 | 209 ac3_config.fill_buffer_callback = ac3_fill_buffer; |
210 ac3_config.num_output_ch = 2; | |
211 ac3_config.flags = 0; | |
212 #ifdef HAVE_MMX | |
213 ac3_config.flags |= AC3_MMX_ENABLE; | |
214 #endif | |
215 #ifdef HAVE_3DNOW | |
216 ac3_config.flags |= AC3_3DNOW_ENABLE; | |
217 #endif | |
218 ac3_init(); | |
219 sh_audio->ac3_frame = ac3_decode_frame(); | |
220 if(sh_audio->ac3_frame){ | |
746 | 221 ac3_frame_t* fr=(ac3_frame_t*)sh_audio->ac3_frame; |
222 sh_audio->samplerate=fr->sampling_rate; | |
296 | 223 sh_audio->channels=2; |
746 | 224 // 1 frame: 6*256 samples 1 sec: sh_audio->samplerate samples |
225 //sh_audio->i_bps=fr->frame_size*fr->sampling_rate/(6*256); | |
226 sh_audio->i_bps=fr->bit_rate*(1000/8); | |
303 | 227 } else { |
228 driver=0; // bad frame -> disable audio | |
229 } | |
230 break; | |
231 } | |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
232 case AFM_HWAC3: { |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
233 unsigned char *buffer; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
234 struct hwac3info ai; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
235 int len, skipped; |
1529 | 236 len = ds_get_packet(sh_audio->ds, &buffer); // maybe 1 packet is not enough, |
237 // at least for mpeg, PS packets contain about max. 2000 bytes of data. | |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
238 if(ac3_iec958_parse_syncinfo(buffer, len, &ai, &skipped) < 0) { |
1567 | 239 mp_msg(MSGT_DECAUDIO,MSGL_ERR, "AC3 stream not valid.\n"); |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
240 driver = 0; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
241 break; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
242 } |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
243 if(ai.samplerate != 48000) { |
1567 | 244 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"Only 48000 Hz streams supported.\n"); |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
245 driver = 0; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
246 break; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
247 } |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
248 sh_audio->samplerate=ai.samplerate; |
1529 | 249 sh_audio->samplesize=ai.framesize; |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
250 sh_audio->channels=1; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
251 sh_audio->i_bps=ai.bitrate*(1000/8); |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
252 sh_audio->ac3_frame=malloc(6144); |
1529 | 253 sh_audio->o_bps=sh_audio->i_bps; // XXX FIXME!!! XXX |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
254 break; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
255 } |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
256 case AFM_ALAW: { |
296 | 257 // 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
|
258 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
|
259 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; |
746 | 260 sh_audio->i_bps=sh_audio->channels*sh_audio->samplerate; |
303 | 261 break; |
262 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
263 case AFM_GSM: { |
296 | 264 // MS-GSM audio codec: |
265 GSM_Init(); | |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
266 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
|
267 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; |
746 | 268 // decodes 65 byte -> 320 short |
269 // 1 sec: sh_audio->channels*sh_audio->samplerate samples | |
270 // 1 frame: 320 samples | |
271 sh_audio->i_bps=65*(sh_audio->channels*sh_audio->samplerate)/320; // 1:10 | |
303 | 272 break; |
296 | 273 } |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
274 case AFM_MPEG: { |
296 | 275 // MPEG Audio: |
1289 | 276 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
|
277 #ifdef USE_FAKE_MONO |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
278 MP3_Init(fakemono); |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
279 #else |
296 | 280 MP3_Init(); |
732
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
281 #endif |
296 | 282 MP3_samplerate=MP3_channels=0; |
283 // printf("[\n"); | |
284 sh_audio->a_buffer_len=MP3_DecodeFrame(sh_audio->a_buffer,-1); | |
285 // printf("]\n"); | |
286 sh_audio->channels=2; // hack | |
287 sh_audio->samplerate=MP3_samplerate; | |
746 | 288 sh_audio->i_bps=MP3_bitrate*(1000/8); |
303 | 289 break; |
290 } | |
296 | 291 } |
292 | |
293 if(!sh_audio->channels || !sh_audio->samplerate){ | |
1567 | 294 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Unknown/missing audio format, using nosound\n"); |
303 | 295 driver=0; |
296 | 296 } |
297 | |
303 | 298 if(!driver){ |
299 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
|
300 sh_audio->a_buffer=NULL; |
303 | 301 return 0; |
302 } | |
296 | 303 |
1529 | 304 if(!sh_audio->o_bps) |
303 | 305 sh_audio->o_bps=sh_audio->channels*sh_audio->samplerate*sh_audio->samplesize; |
306 return driver; | |
296 | 307 } |
291 | 308 |
746 | 309 // Audio decoding: |
291 | 310 |
746 | 311 // Decode a single frame (mp3,acm etc) or 'minlen' bytes (pcm/alaw etc) |
312 // buffer length is 'maxlen' bytes, it shouldn't be exceeded... | |
313 | |
314 int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen){ | |
291 | 315 int len=-1; |
303 | 316 switch(sh_audio->codec->driver){ |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
317 case AFM_MPEG: // MPEG layer 2 or 3 |
291 | 318 len=MP3_DecodeFrame(buf,-1); |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1456
diff
changeset
|
319 // len=MP3_DecodeFrame(buf,3); |
291 | 320 break; |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
321 case AFM_PCM: // AVI PCM |
1058 | 322 len=demux_read_data(sh_audio->ds,buf,minlen); |
401 | 323 break; |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
324 case AFM_DVDPCM: // DVD PCM |
401 | 325 { int j; |
746 | 326 len=demux_read_data(sh_audio->ds,buf,minlen); |
291 | 327 //if(i&1){ printf("Warning! pcm_audio_size&1 !=0 (%d)\n",i);i&=~1; } |
746 | 328 // swap endian: |
291 | 329 for(j=0;j<len;j+=2){ |
330 char x=buf[j]; | |
331 buf[j]=buf[j+1]; | |
332 buf[j+1]=x; | |
333 } | |
334 break; | |
335 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
336 case AFM_ALAW: // aLaw decoder |
746 | 337 { int l=demux_read_data(sh_audio->ds,buf,minlen/2); |
291 | 338 unsigned short *d=(unsigned short *) buf; |
339 unsigned char *s=buf; | |
340 len=2*l; | |
758 | 341 if(sh_audio->format==6){ |
342 // aLaw | |
883 | 343 while(l>0){ --l; d[l]=alaw2short[s[l]]; } |
758 | 344 } else { |
345 // uLaw | |
883 | 346 while(l>0){ --l; d[l]=ulaw2short[s[l]]; } |
291 | 347 } |
348 break; | |
349 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
350 case AFM_GSM: // MS-GSM decoder |
291 | 351 { unsigned char buf[65]; // 65 bytes / frame |
746 | 352 if(demux_read_data(sh_audio->ds,buf,65)!=65) break; // EOF |
353 XA_MSGSM_Decoder(buf,(unsigned short *) buf); // decodes 65 byte -> 320 short | |
354 // XA_GSM_Decoder(buf,(unsigned short *) &sh_audio->a_buffer[sh_audio->a_buffer_len]); // decodes 33 byte -> 160 short | |
355 len=2*320; | |
291 | 356 break; |
357 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
358 case AFM_AC3: // AC3 decoder |
291 | 359 //printf("{1:%d}",avi_header.idx_pos);fflush(stdout); |
360 if(!sh_audio->ac3_frame) sh_audio->ac3_frame=ac3_decode_frame(); | |
361 //printf("{2:%d}",avi_header.idx_pos);fflush(stdout); | |
362 if(sh_audio->ac3_frame){ | |
296 | 363 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
|
364 memcpy(buf,((ac3_frame_t*)sh_audio->ac3_frame)->audio_data,len); |
291 | 365 sh_audio->ac3_frame=NULL; |
366 } | |
367 //printf("{3:%d}",avi_header.idx_pos);fflush(stdout); | |
368 break; | |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
369 case AFM_HWAC3: // AC3 through SPDIF |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
370 if(demux_read_data(sh_audio->ds,sh_audio->ac3_frame, 6144) != 6144) |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
371 break; //EOF |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
372 ac3_iec958_build_burst(1536, 0x1F, 1, buf, sh_audio->ac3_frame); |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
373 len = 6144; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
374 break; |
1517
0e9c29538a86
Use USE_WIN32DLL define instead of ARCH_X86 to decide whether or not to compile
jkeil
parents:
1485
diff
changeset
|
375 #ifdef USE_WIN32DLL |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
376 case AFM_ACM: |
758 | 377 // len=sh_audio->audio_out_minsize; // optimal decoded fragment size |
378 // if(len<minlen) len=minlen; else | |
379 // if(len>maxlen) len=maxlen; | |
380 // len=acm_decode_audio(sh_audio,buf,len); | |
381 len=acm_decode_audio(sh_audio,buf,minlen,maxlen); | |
291 | 382 break; |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
383 #endif |
746 | 384 |
291 | 385 #ifdef USE_DIRECTSHOW |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
386 case AFM_DSHOW: // DirectShow |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
387 { int size_in=0; |
291 | 388 int size_out=0; |
389 int srcsize=DS_AudioDecoder_GetSrcSize(maxlen); | |
1567 | 390 mp_msg(MSGT_DECAUDIO,MSGL_DBG3,"DShow says: srcsize=%d (buffsize=%d) out_size=%d\n",srcsize,sh_audio->a_in_buffer_size,maxlen); |
291 | 391 if(srcsize>sh_audio->a_in_buffer_size) srcsize=sh_audio->a_in_buffer_size; // !!!!!! |
392 if(sh_audio->a_in_buffer_len<srcsize){ | |
393 sh_audio->a_in_buffer_len+= | |
394 demux_read_data(sh_audio->ds,&sh_audio->a_in_buffer[sh_audio->a_in_buffer_len], | |
395 srcsize-sh_audio->a_in_buffer_len); | |
396 } | |
397 DS_AudioDecoder_Convert(sh_audio->a_in_buffer,sh_audio->a_in_buffer_len, | |
398 buf,maxlen, &size_in,&size_out); | |
1567 | 399 mp_dbg(MSGT_DECAUDIO,MSGL_DBG2,"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 | 400 if(size_in>=sh_audio->a_in_buffer_len){ |
401 sh_audio->a_in_buffer_len=0; | |
402 } else { | |
403 sh_audio->a_in_buffer_len-=size_in; | |
404 memcpy(sh_audio->a_in_buffer,&sh_audio->a_in_buffer[size_in],sh_audio->a_in_buffer_len); | |
405 } | |
406 len=size_out; | |
407 break; | |
408 } | |
409 #endif | |
410 } | |
411 return len; | |
412 } | |
413 | |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
414 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
|
415 switch(sh_audio->codec->driver){ |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
416 case AFM_MPEG: |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
417 MP3_DecodeFrame(NULL,-2); // resync |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
418 MP3_DecodeFrame(NULL,-2); // resync |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
419 MP3_DecodeFrame(NULL,-2); // resync |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
420 break; |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
421 case AFM_AC3: |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
422 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
|
423 // 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
|
424 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
|
425 // if(verbose) printf(" OK!\n"); |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
426 break; |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
427 case AFM_ACM: |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
428 case AFM_DSHOW: |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
429 case AFM_HWAC3: |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
430 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
|
431 break; |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
432 } |
1408 | 433 |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
434 } |
291 | 435 |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
436 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
|
437 switch(sh_audio->codec->driver){ |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
438 case AFM_MPEG: MP3_DecodeFrame(NULL,-2);break; // skip MPEG frame |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
439 case AFM_AC3: sh_audio->ac3_frame=ac3_decode_frame();break; // skip AC3 frame |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
440 case AFM_ACM: |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
441 case AFM_DSHOW: { |
1408 | 442 int skip=sh_audio->wf->nBlockAlign; |
443 if(skip<16){ | |
444 skip=(sh_audio->wf->nAvgBytesPerSec/16)&(~7); | |
445 if(skip<16) skip=16; | |
446 } | |
447 demux_read_data(sh_audio->ds,NULL,skip); | |
448 break; | |
449 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
450 case AFM_PCM: |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
451 case AFM_DVDPCM: |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
452 case AFM_ALAW: { |
1408 | 453 int skip=sh_audio->i_bps/16; |
454 skip=skip&(~3); | |
455 demux_read_data(sh_audio->ds,NULL,skip); | |
456 break; | |
457 } | |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
458 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
|
459 } |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
460 } |