Mercurial > mplayer.hg
annotate dec_audio.c @ 1831:57afd6a8ae78
Ehh colaCounter++
author | atmos4 |
---|---|
date | Sat, 01 Sep 2001 20:15:21 +0000 |
parents | 46347c4075da |
children | 3f8da9408f04 |
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 |
1828 | 40 #ifdef HAVE_OGGVORBIS |
41 /* XXX is math.h really needed? - atmos */ | |
42 #include <math.h> | |
43 #include <vorbis/codec.h> | |
44 #endif | |
45 | |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
46 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
|
47 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
|
48 |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
49 |
1289 | 50 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
|
51 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
52 // AC3 decoder buffer callback: |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
53 static void ac3_fill_buffer(uint8_t **start,uint8_t **end){ |
1289 | 54 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
|
55 //printf("<ac3:%d>\n",len); |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
56 if(len<0) |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
57 *start = *end = NULL; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
58 else |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
59 *end = *start + len; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
60 } |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
61 |
1289 | 62 // MP3 decoder buffer callback: |
63 int mplayer_audio_read(char *buf,int size){ | |
64 int len; | |
65 len=demux_read_data(dec_audio_sh->ds,buf,size); | |
66 return len; | |
67 } | |
68 | |
296 | 69 int init_audio(sh_audio_t *sh_audio){ |
303 | 70 int driver=sh_audio->codec->driver; |
296 | 71 |
72 sh_audio->samplesize=2; | |
1320
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1313
diff
changeset
|
73 #if WORDS_BIGENDIAN |
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1313
diff
changeset
|
74 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
|
75 #else |
758 | 76 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
|
77 #endif |
303 | 78 sh_audio->samplerate=0; |
401 | 79 //sh_audio->pcm_bswap=0; |
1529 | 80 sh_audio->o_bps=0; |
303 | 81 |
758 | 82 sh_audio->a_buffer_size=0; |
303 | 83 sh_audio->a_buffer=NULL; |
296 | 84 |
746 | 85 sh_audio->a_in_buffer_len=0; |
86 | |
758 | 87 // setup required min. in/out buffer size: |
88 sh_audio->audio_out_minsize=8192;// default size, maybe not enough for Win32/ACM | |
89 | |
90 switch(driver){ | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
91 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
|
92 #ifndef USE_WIN32DLL |
1567 | 93 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
|
94 driver=0; |
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
95 #else |
296 | 96 // Win32 ACM audio codec: |
97 if(init_acm_audio_codec(sh_audio)){ | |
746 | 98 sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec; |
296 | 99 sh_audio->channels=sh_audio->o_wf.nChannels; |
100 sh_audio->samplerate=sh_audio->o_wf.nSamplesPerSec; | |
758 | 101 // if(sh_audio->audio_out_minsize>16384) sh_audio->audio_out_minsize=16384; |
102 // sh_audio->a_buffer_size=sh_audio->audio_out_minsize; | |
103 // if(sh_audio->a_buffer_size<sh_audio->audio_out_minsize+MAX_OUTBURST) | |
104 // sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST; | |
296 | 105 } else { |
1567 | 106 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"Could not load/initialize Win32/ACM AUDIO codec (missing DLL file?)\n"); |
303 | 107 driver=0; |
296 | 108 } |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
109 #endif |
758 | 110 break; |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
111 case AFM_DSHOW: |
296 | 112 #ifndef USE_DIRECTSHOW |
1567 | 113 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"Compiled without DirectShow support -> force nosound :(\n"); |
303 | 114 driver=0; |
296 | 115 #else |
116 // Win32 DShow audio codec: | |
340 | 117 // 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
|
118 if(DS_AudioDecoder_Open(sh_audio->codec->dll,&sh_audio->codec->guid,sh_audio->wf)){ |
1828 | 119 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"ERROR: Could not load/initialize Win32/DirectShow AUDIO codec: %s\n",sh_audio->codec->dll); |
303 | 120 driver=0; |
121 } else { | |
746 | 122 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
|
123 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
|
124 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
|
125 sh_audio->audio_in_minsize=2*sh_audio->wf->nBlockAlign; |
296 | 126 if(sh_audio->audio_in_minsize<8192) sh_audio->audio_in_minsize=8192; |
127 sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize; | |
128 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size); | |
129 sh_audio->a_in_buffer_len=0; | |
758 | 130 sh_audio->audio_out_minsize=16384; |
296 | 131 } |
132 #endif | |
758 | 133 break; |
1828 | 134 case AFM_VORBIS: |
135 #ifndef HAVE_OGGVORBIS | |
136 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"OggVorbis audio codec disabled -> force nosound :(\n"); | |
137 driver=0; | |
138 #else | |
139 /* OggVorbis audio via libvorbis, compatible with files created by nandub and zorannt codec */ | |
140 sh_audio->audio_out_minsize=4096; | |
141 #endif | |
142 break; | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
143 case AFM_PCM: |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
144 case AFM_DVDPCM: |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
145 case AFM_ALAW: |
758 | 146 // PCM, aLaw |
147 sh_audio->audio_out_minsize=2048; | |
148 break; | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
149 case AFM_AC3: |
758 | 150 // Dolby AC3 audio: |
151 sh_audio->audio_out_minsize=4*256*6; | |
152 break; | |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
153 case AFM_HWAC3: |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
154 // Dolby AC3 audio: |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
155 sh_audio->audio_out_minsize=4*256*6; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
156 sh_audio->sample_format = AFMT_AC3; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
157 break; |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
158 case AFM_GSM: |
758 | 159 // MS-GSM audio codec: |
160 sh_audio->audio_out_minsize=4*320; | |
161 break; | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
162 case AFM_MPEG: |
758 | 163 // MPEG Audio: |
164 sh_audio->audio_out_minsize=4608; | |
165 break; | |
296 | 166 } |
167 | |
303 | 168 if(!driver) return 0; |
296 | 169 |
170 // allocate audio out buffer: | |
758 | 171 sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST; // worst case calc. |
172 | |
1567 | 173 mp_msg(MSGT_DECAUDIO,MSGL_V,"dec_audio: Allocating %d + %d = %d bytes for output buffer\n", |
758 | 174 sh_audio->audio_out_minsize,MAX_OUTBURST,sh_audio->a_buffer_size); |
175 | |
296 | 176 sh_audio->a_buffer=malloc(sh_audio->a_buffer_size); |
758 | 177 if(!sh_audio->a_buffer){ |
1567 | 178 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"Cannot allocate audio out buffer\n"); |
758 | 179 return 0; |
180 } | |
296 | 181 memset(sh_audio->a_buffer,0,sh_audio->a_buffer_size); |
182 sh_audio->a_buffer_len=0; | |
183 | |
303 | 184 switch(driver){ |
1517
0e9c29538a86
Use USE_WIN32DLL define instead of ARCH_X86 to decide whether or not to compile
jkeil
parents:
1485
diff
changeset
|
185 #ifdef USE_WIN32DLL |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
186 case AFM_ACM: { |
758 | 187 int ret=acm_decode_audio(sh_audio,sh_audio->a_buffer,4096,sh_audio->a_buffer_size); |
296 | 188 if(ret<0){ |
1567 | 189 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"ACM decoding error: %d\n",ret); |
303 | 190 driver=0; |
296 | 191 } |
640 | 192 sh_audio->a_buffer_len=ret; |
303 | 193 break; |
296 | 194 } |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
195 #endif |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
196 case AFM_PCM: { |
296 | 197 // 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
|
198 WAVEFORMATEX *h=sh_audio->wf; |
746 | 199 sh_audio->i_bps=h->nAvgBytesPerSec; |
296 | 200 sh_audio->channels=h->nChannels; |
201 sh_audio->samplerate=h->nSamplesPerSec; | |
202 sh_audio->samplesize=(h->wBitsPerSample+7)/8; | |
758 | 203 switch(sh_audio->format){ // hardware formats: |
204 case 0x6: sh_audio->sample_format=AFMT_A_LAW;break; | |
205 case 0x7: sh_audio->sample_format=AFMT_MU_LAW;break; | |
206 case 0x11: sh_audio->sample_format=AFMT_IMA_ADPCM;break; | |
207 case 0x50: sh_audio->sample_format=AFMT_MPEG;break; | |
208 // case 0x2000: sh_audio->sample_format=AFMT_AC3; | |
209 default: sh_audio->sample_format=(sh_audio->samplesize==2)?AFMT_S16_LE:AFMT_U8; | |
210 } | |
401 | 211 break; |
212 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
213 case AFM_DVDPCM: { |
401 | 214 // DVD PCM Audio: |
215 sh_audio->channels=2; | |
216 sh_audio->samplerate=48000; | |
746 | 217 sh_audio->i_bps=2*2*48000; |
296 | 218 // sh_audio->pcm_bswap=1; |
303 | 219 break; |
220 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
221 case AFM_AC3: { |
296 | 222 // Dolby AC3 audio: |
1289 | 223 dec_audio_sh=sh_audio; // save sh_audio for the callback: |
296 | 224 ac3_config.fill_buffer_callback = ac3_fill_buffer; |
225 ac3_config.num_output_ch = 2; | |
226 ac3_config.flags = 0; | |
227 #ifdef HAVE_MMX | |
228 ac3_config.flags |= AC3_MMX_ENABLE; | |
229 #endif | |
230 #ifdef HAVE_3DNOW | |
231 ac3_config.flags |= AC3_3DNOW_ENABLE; | |
232 #endif | |
233 ac3_init(); | |
234 sh_audio->ac3_frame = ac3_decode_frame(); | |
235 if(sh_audio->ac3_frame){ | |
746 | 236 ac3_frame_t* fr=(ac3_frame_t*)sh_audio->ac3_frame; |
237 sh_audio->samplerate=fr->sampling_rate; | |
296 | 238 sh_audio->channels=2; |
746 | 239 // 1 frame: 6*256 samples 1 sec: sh_audio->samplerate samples |
240 //sh_audio->i_bps=fr->frame_size*fr->sampling_rate/(6*256); | |
241 sh_audio->i_bps=fr->bit_rate*(1000/8); | |
303 | 242 } else { |
243 driver=0; // bad frame -> disable audio | |
244 } | |
245 break; | |
246 } | |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
247 case AFM_HWAC3: { |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
248 unsigned char *buffer; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
249 struct hwac3info ai; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
250 int len, skipped; |
1529 | 251 len = ds_get_packet(sh_audio->ds, &buffer); // maybe 1 packet is not enough, |
252 // 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
|
253 if(ac3_iec958_parse_syncinfo(buffer, len, &ai, &skipped) < 0) { |
1567 | 254 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
|
255 driver = 0; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
256 break; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
257 } |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
258 if(ai.samplerate != 48000) { |
1567 | 259 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
|
260 driver = 0; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
261 break; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
262 } |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
263 sh_audio->samplerate=ai.samplerate; |
1529 | 264 sh_audio->samplesize=ai.framesize; |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
265 sh_audio->channels=1; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
266 sh_audio->i_bps=ai.bitrate*(1000/8); |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
267 sh_audio->ac3_frame=malloc(6144); |
1529 | 268 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
|
269 break; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
270 } |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
271 case AFM_ALAW: { |
296 | 272 // 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
|
273 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
|
274 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; |
746 | 275 sh_audio->i_bps=sh_audio->channels*sh_audio->samplerate; |
303 | 276 break; |
277 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
278 case AFM_GSM: { |
296 | 279 // MS-GSM audio codec: |
280 GSM_Init(); | |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
281 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
|
282 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; |
746 | 283 // decodes 65 byte -> 320 short |
284 // 1 sec: sh_audio->channels*sh_audio->samplerate samples | |
285 // 1 frame: 320 samples | |
286 sh_audio->i_bps=65*(sh_audio->channels*sh_audio->samplerate)/320; // 1:10 | |
303 | 287 break; |
296 | 288 } |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
289 case AFM_MPEG: { |
296 | 290 // MPEG Audio: |
1289 | 291 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
|
292 #ifdef USE_FAKE_MONO |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
293 MP3_Init(fakemono); |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
294 #else |
296 | 295 MP3_Init(); |
732
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
296 #endif |
296 | 297 MP3_samplerate=MP3_channels=0; |
298 // printf("[\n"); | |
299 sh_audio->a_buffer_len=MP3_DecodeFrame(sh_audio->a_buffer,-1); | |
300 // printf("]\n"); | |
301 sh_audio->channels=2; // hack | |
302 sh_audio->samplerate=MP3_samplerate; | |
746 | 303 sh_audio->i_bps=MP3_bitrate*(1000/8); |
303 | 304 break; |
305 } | |
1828 | 306 #ifdef HAVE_OGGVORBIS |
307 case AFM_VORBIS: { | |
308 // OggVorbis Audio: | |
309 #if 0 /* just here for reference - atmos */ | |
310 ogg_sync_state oy; /* sync and verify incoming physical bitstream */ | |
311 ogg_stream_state os; /* take physical pages, weld into a logical | |
312 stream of packets */ | |
313 ogg_page og; /* one Ogg bitstream page. Vorbis packets are inside */ | |
314 ogg_packet op; /* one raw packet of data for decode */ | |
315 | |
316 vorbis_info vi; /* struct that stores all the static vorbis bitstream | |
317 settings */ | |
318 vorbis_comment vc; /* struct that stores all the bitstream user comments */ | |
319 vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */ | |
320 vorbis_block vb; /* local working space for packet->PCM decode */ | |
321 #else | |
322 /* nix, nada, rien, nothing, nem, nüx */ | |
323 #endif | |
324 | |
325 uint32_t hdrsizes[3];/* stores vorbis header sizes from AVI audio header, | |
326 maybe use ogg_uint32_t */ | |
327 //int i; | |
328 int ret; | |
329 char *buffer; | |
330 ogg_packet hdr; | |
331 //ov_struct_t *s=&sh_audio->ov; | |
332 sh_audio->ov=malloc(sizeof(ov_struct_t)); | |
333 //s=&sh_audio->ov; | |
334 | |
335 vorbis_info_init(&sh_audio->ov->vi); | |
336 vorbis_comment_init(&sh_audio->ov->vc); | |
337 | |
338 printf("OggVorbis: cbsize: %i\n", sh_audio->wf->cbSize); | |
339 memcpy(hdrsizes, ((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX), 3*sizeof(uint32_t)); | |
340 printf("OggVorbis: Read header sizes: initial: %i comment: %i codebook: %i\n", hdrsizes[0], hdrsizes[1], hdrsizes[2]); | |
341 /*for(i=12; i <= 40; i+=2) { // header bruteforce :) | |
342 memcpy(hdrsizes, ((unsigned char*)sh_audio->wf)+i, 3*sizeof(uint32_t)); | |
343 printf("OggVorbis: Read header sizes (%i): %ld %ld %ld\n", i, hdrsizes[0], hdrsizes[1], hdrsizes[2]); | |
344 }*/ | |
345 | |
346 /* read headers */ // FIXME disable sound on errors here, we absolutely need this headers! - atmos | |
347 hdr.packet=NULL; | |
348 hdr.b_o_s = 1; /* beginning of stream for first packet */ | |
349 hdr.bytes = hdrsizes[0]; | |
350 hdr.packet = realloc(hdr.packet,hdr.bytes); | |
351 memcpy(hdr.packet,((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX)+3*sizeof(uint32_t),hdr.bytes); | |
352 if(vorbis_synthesis_headerin(&sh_audio->ov->vi,&sh_audio->ov->vc,&hdr)<0) | |
353 printf("OggVorbis: initial (identification) header broken!\n"); | |
354 hdr.b_o_s = 0; | |
355 hdr.bytes = hdrsizes[1]; | |
356 hdr.packet = realloc(hdr.packet,hdr.bytes); | |
357 memcpy(hdr.packet,((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX)+3*sizeof(uint32_t)+hdrsizes[0],hdr.bytes); | |
358 if(vorbis_synthesis_headerin(&sh_audio->ov->vi,&sh_audio->ov->vc,&hdr)<0) | |
359 printf("OggVorbis: comment header broken!\n"); | |
360 hdr.bytes = hdrsizes[2]; | |
361 hdr.packet = realloc(hdr.packet,hdr.bytes); | |
362 memcpy(hdr.packet,((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX)+3*sizeof(uint32_t)+hdrsizes[0]+hdrsizes[1],hdr.bytes); | |
363 if(vorbis_synthesis_headerin(&sh_audio->ov->vi,&sh_audio->ov->vc,&hdr)<0) | |
364 printf("OggVorbis: codebook header broken!\n"); | |
365 hdr.bytes=0; | |
366 hdr.packet = realloc(hdr.packet,hdr.bytes); /* free */ | |
367 /* done with the headers */ | |
368 | |
369 | |
370 /* Throw the comments plus a few lines about the bitstream we're | |
371 decoding */ | |
372 { | |
373 char **ptr=sh_audio->ov->vc.user_comments; | |
374 while(*ptr){ | |
375 printf("OggVorbisComment: %s\n",*ptr); | |
376 ++ptr; | |
377 } | |
378 printf("OggVorbis: Bitstream is %d channel, %ldHz, %ldkbit/s %cBR\n",sh_audio->ov->vi.channels,sh_audio->ov->vi.rate,sh_audio->ov->vi.bitrate_nominal/1000, (sh_audio->ov->vi.bitrate_lower!=sh_audio->ov->vi.bitrate_nominal)||(sh_audio->ov->vi.bitrate_upper!=sh_audio->ov->vi.bitrate_nominal)?'V':'C'); | |
379 printf("OggVorbis: Encoded by: %s\n",sh_audio->ov->vc.vendor); | |
380 } | |
381 sh_audio->channels=sh_audio->ov->vi.channels; | |
382 sh_audio->samplerate=sh_audio->ov->vi.rate; | |
383 sh_audio->i_bps=sh_audio->ov->vi.bitrate_nominal/8; | |
384 | |
385 // printf("[\n"); | |
386 sh_audio->a_buffer_len=sh_audio->audio_out_minsize;///ov->vi.channels; | |
387 // printf("]\n"); | |
388 | |
389 /* OK, got and parsed all three headers. Initialize the Vorbis | |
390 packet->PCM decoder. */ | |
391 vorbis_synthesis_init(&sh_audio->ov->vd,&sh_audio->ov->vi); /* central decode state */ | |
392 vorbis_block_init(&sh_audio->ov->vd,&sh_audio->ov->vb); /* local state for most of the decode | |
393 so multiple block decodes can | |
394 proceed in parallel. We could init | |
395 multiple vorbis_block structures | |
396 for vd here */ | |
397 //printf("OggVorbis: synthesis and block init done.\n"); | |
398 ogg_sync_init(&sh_audio->ov->oy); /* Now we can read pages */ | |
399 | |
400 while((ret = ogg_sync_pageout(&sh_audio->ov->oy,&sh_audio->ov->og))!=1) { | |
401 if(ret == -1) | |
402 printf("OggVorbis: Pageout: not properly synced, had to skip some bytes.\n"); | |
403 else | |
404 if(ret == 0) { | |
405 printf("OggVorbis: Pageout: need more data to verify page, reading more data.\n"); | |
406 /* submit a a_buffer_len block to libvorbis' Ogg layer */ | |
407 buffer=ogg_sync_buffer(&sh_audio->ov->oy,sh_audio->a_buffer_len); | |
408 ogg_sync_wrote(&sh_audio->ov->oy,demux_read_data(sh_audio->ds,buffer,sh_audio->a_buffer_len)); | |
409 } | |
410 } | |
411 printf("OggVorbis: Pageout: successfull.\n"); | |
412 /* commenting out pagein to leave data (hopefully) to the decoder - atmos */ | |
413 //ogg_stream_pagein(&sh_audio->ov->os,&sh_audio->ov->og); /* we can ignore any errors here | |
414 // as they'll also become apparent | |
415 // at packetout */ | |
416 | |
417 /* Get the serial number and set up the rest of decode. */ | |
418 /* serialno first; use it to set up a logical stream */ | |
419 ogg_stream_init(&sh_audio->ov->os,ogg_page_serialno(&sh_audio->ov->og)); | |
420 | |
421 printf("OggVorbis: Init OK!\n"); | |
422 | |
423 break; | |
424 } | |
425 #endif | |
296 | 426 } |
427 | |
428 if(!sh_audio->channels || !sh_audio->samplerate){ | |
1567 | 429 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"Unknown/missing audio format, using nosound\n"); |
303 | 430 driver=0; |
296 | 431 } |
432 | |
303 | 433 if(!driver){ |
434 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
|
435 sh_audio->a_buffer=NULL; |
303 | 436 return 0; |
437 } | |
296 | 438 |
1529 | 439 if(!sh_audio->o_bps) |
303 | 440 sh_audio->o_bps=sh_audio->channels*sh_audio->samplerate*sh_audio->samplesize; |
441 return driver; | |
296 | 442 } |
291 | 443 |
746 | 444 // Audio decoding: |
291 | 445 |
746 | 446 // Decode a single frame (mp3,acm etc) or 'minlen' bytes (pcm/alaw etc) |
447 // buffer length is 'maxlen' bytes, it shouldn't be exceeded... | |
448 | |
449 int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen){ | |
291 | 450 int len=-1; |
303 | 451 switch(sh_audio->codec->driver){ |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
452 case AFM_MPEG: // MPEG layer 2 or 3 |
291 | 453 len=MP3_DecodeFrame(buf,-1); |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1456
diff
changeset
|
454 // len=MP3_DecodeFrame(buf,3); |
291 | 455 break; |
1830 | 456 #ifdef HAVE_OGGVORBIS |
1828 | 457 case AFM_VORBIS: { // OggVorbis |
458 /* note: good minlen would be 4k or 8k IMHO - atmos */ | |
459 int ret; | |
460 char *buffer; | |
461 int bytes; | |
462 int samples; | |
463 float **pcm; | |
464 ogg_int16_t convbuffer[4096]; | |
465 int convsize; | |
466 minlen=4096; // XXX hack, not neccessarily needed - atmos | |
467 convsize=minlen/sh_audio->ov->vi.channels; | |
468 while((ret = ogg_sync_pageout(&sh_audio->ov->oy,&sh_audio->ov->og))!=1) { | |
469 if(ret == -1) | |
470 printf("OggVorbis: Pageout: not properly synced, had to skip some bytes.\n"); | |
471 else | |
472 if(ret == 0) { | |
473 //printf("OggVorbis: Pageout: need more data to verify page, reading more data.\n"); | |
474 /* submit a minlen k block to libvorbis' Ogg layer */ | |
475 buffer=ogg_sync_buffer(&sh_audio->ov->oy,minlen); | |
476 bytes=demux_read_data(sh_audio->ds,buffer,minlen); | |
477 ogg_sync_wrote(&sh_audio->ov->oy,bytes); | |
478 if(bytes==0) | |
479 printf("OggVorbis: 0Bytes written, possible End of Stream\n"); | |
480 } | |
481 } | |
482 //printf("OggVorbis: Pageout: successfull, pagin in.\n"); | |
483 if(ogg_stream_pagein(&sh_audio->ov->os,&sh_audio->ov->og)<0) | |
484 printf("OggVorbis: Pagein failed!\n"); | |
485 | |
486 ret=ogg_stream_packetout(&sh_audio->ov->os,&sh_audio->ov->op); | |
487 if(ret==0) | |
488 printf("OggVorbis: Packetout: need more data, FIXME!\n"); | |
489 else | |
490 if(ret<0) | |
491 printf("OggVorbis: Packetout: missing or corrupt data, skipping packet!\n"); | |
492 else { | |
493 | |
494 /* we have a packet. Decode it */ | |
495 | |
496 if(vorbis_synthesis(&sh_audio->ov->vb,&sh_audio->ov->op)==0) /* test for success! */ | |
497 vorbis_synthesis_blockin(&sh_audio->ov->vd,&sh_audio->ov->vb); | |
498 | |
499 /* **pcm is a multichannel float vector. In stereo, for | |
500 example, pcm[0] is left, and pcm[1] is right. samples is | |
501 the size of each channel. Convert the float values | |
502 (-1.<=range<=1.) to whatever PCM format and write it out */ | |
503 | |
504 while((samples=vorbis_synthesis_pcmout(&sh_audio->ov->vd,&pcm))>0){ | |
505 int i,j; | |
506 int clipflag=0; | |
507 int bout=(samples<convsize?samples:convsize); | |
508 | |
509 /* convert floats to 16 bit signed ints (host order) and | |
510 interleave */ | |
511 for(i=0;i<sh_audio->ov->vi.channels;i++){ | |
512 ogg_int16_t *ptr=convbuffer+i; | |
513 float *mono=pcm[i]; | |
514 for(j=0;j<bout;j++){ | |
515 #if 1 | |
516 int val=mono[j]*32767.f; | |
517 #else /* optional dither */ | |
518 int val=mono[j]*32767.f+drand48()-0.5f; | |
519 #endif | |
520 /* might as well guard against clipping */ | |
521 if(val>32767){ | |
522 val=32767; | |
523 clipflag=1; | |
524 } | |
525 if(val<-32768){ | |
526 val=-32768; | |
527 clipflag=1; | |
528 } | |
529 *ptr=val; | |
530 ptr+=sh_audio->ov->vi.channels; | |
531 } | |
532 } | |
533 | |
534 if(clipflag) | |
535 printf("Clipping in frame %ld\n",(long)(sh_audio->ov->vd.sequence)); | |
536 | |
537 //fwrite(convbuffer,2*sh_audio->ov->vi.channels,bout,stderr); //dump pcm to file for debugging | |
538 len=2*sh_audio->ov->vi.channels*bout; | |
539 memcpy(buf,convbuffer,len); | |
540 | |
541 vorbis_synthesis_read(&sh_audio->ov->vd,bout); /* tell libvorbis how | |
542 many samples we | |
543 actually consumed */ | |
544 } | |
545 if(ogg_page_eos(&sh_audio->ov->og)) | |
546 printf("OggVorbis: End of Stream reached!\n"); // FIXME clearup decoder, notify mplayer - atmos | |
547 | |
548 } // from else, packetout ok | |
549 | |
550 break; | |
1831 | 551 } |
1830 | 552 #endif |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
553 case AFM_PCM: // AVI PCM |
1058 | 554 len=demux_read_data(sh_audio->ds,buf,minlen); |
401 | 555 break; |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
556 case AFM_DVDPCM: // DVD PCM |
401 | 557 { int j; |
746 | 558 len=demux_read_data(sh_audio->ds,buf,minlen); |
291 | 559 //if(i&1){ printf("Warning! pcm_audio_size&1 !=0 (%d)\n",i);i&=~1; } |
746 | 560 // swap endian: |
291 | 561 for(j=0;j<len;j+=2){ |
562 char x=buf[j]; | |
563 buf[j]=buf[j+1]; | |
564 buf[j+1]=x; | |
565 } | |
566 break; | |
567 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
568 case AFM_ALAW: // aLaw decoder |
746 | 569 { int l=demux_read_data(sh_audio->ds,buf,minlen/2); |
291 | 570 unsigned short *d=(unsigned short *) buf; |
571 unsigned char *s=buf; | |
572 len=2*l; | |
758 | 573 if(sh_audio->format==6){ |
574 // aLaw | |
883 | 575 while(l>0){ --l; d[l]=alaw2short[s[l]]; } |
758 | 576 } else { |
577 // uLaw | |
883 | 578 while(l>0){ --l; d[l]=ulaw2short[s[l]]; } |
291 | 579 } |
580 break; | |
581 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
582 case AFM_GSM: // MS-GSM decoder |
291 | 583 { unsigned char buf[65]; // 65 bytes / frame |
746 | 584 if(demux_read_data(sh_audio->ds,buf,65)!=65) break; // EOF |
585 XA_MSGSM_Decoder(buf,(unsigned short *) buf); // decodes 65 byte -> 320 short | |
586 // XA_GSM_Decoder(buf,(unsigned short *) &sh_audio->a_buffer[sh_audio->a_buffer_len]); // decodes 33 byte -> 160 short | |
587 len=2*320; | |
291 | 588 break; |
589 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
590 case AFM_AC3: // AC3 decoder |
291 | 591 //printf("{1:%d}",avi_header.idx_pos);fflush(stdout); |
592 if(!sh_audio->ac3_frame) sh_audio->ac3_frame=ac3_decode_frame(); | |
593 //printf("{2:%d}",avi_header.idx_pos);fflush(stdout); | |
594 if(sh_audio->ac3_frame){ | |
296 | 595 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
|
596 memcpy(buf,((ac3_frame_t*)sh_audio->ac3_frame)->audio_data,len); |
291 | 597 sh_audio->ac3_frame=NULL; |
598 } | |
599 //printf("{3:%d}",avi_header.idx_pos);fflush(stdout); | |
600 break; | |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
601 case AFM_HWAC3: // AC3 through SPDIF |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
602 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
|
603 break; //EOF |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
604 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
|
605 len = 6144; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
606 break; |
1517
0e9c29538a86
Use USE_WIN32DLL define instead of ARCH_X86 to decide whether or not to compile
jkeil
parents:
1485
diff
changeset
|
607 #ifdef USE_WIN32DLL |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
608 case AFM_ACM: |
758 | 609 // len=sh_audio->audio_out_minsize; // optimal decoded fragment size |
610 // if(len<minlen) len=minlen; else | |
611 // if(len>maxlen) len=maxlen; | |
612 // len=acm_decode_audio(sh_audio,buf,len); | |
613 len=acm_decode_audio(sh_audio,buf,minlen,maxlen); | |
291 | 614 break; |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
615 #endif |
746 | 616 |
291 | 617 #ifdef USE_DIRECTSHOW |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
618 case AFM_DSHOW: // DirectShow |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
619 { int size_in=0; |
291 | 620 int size_out=0; |
621 int srcsize=DS_AudioDecoder_GetSrcSize(maxlen); | |
1567 | 622 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 | 623 if(srcsize>sh_audio->a_in_buffer_size) srcsize=sh_audio->a_in_buffer_size; // !!!!!! |
624 if(sh_audio->a_in_buffer_len<srcsize){ | |
625 sh_audio->a_in_buffer_len+= | |
626 demux_read_data(sh_audio->ds,&sh_audio->a_in_buffer[sh_audio->a_in_buffer_len], | |
627 srcsize-sh_audio->a_in_buffer_len); | |
628 } | |
629 DS_AudioDecoder_Convert(sh_audio->a_in_buffer,sh_audio->a_in_buffer_len, | |
630 buf,maxlen, &size_in,&size_out); | |
1567 | 631 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 | 632 if(size_in>=sh_audio->a_in_buffer_len){ |
633 sh_audio->a_in_buffer_len=0; | |
634 } else { | |
635 sh_audio->a_in_buffer_len-=size_in; | |
636 memcpy(sh_audio->a_in_buffer,&sh_audio->a_in_buffer[size_in],sh_audio->a_in_buffer_len); | |
637 } | |
638 len=size_out; | |
639 break; | |
640 } | |
641 #endif | |
642 } | |
643 return len; | |
644 } | |
645 | |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
646 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
|
647 switch(sh_audio->codec->driver){ |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
648 case AFM_MPEG: |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
649 MP3_DecodeFrame(NULL,-2); // resync |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
650 MP3_DecodeFrame(NULL,-2); // resync |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
651 MP3_DecodeFrame(NULL,-2); // resync |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
652 break; |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
653 case AFM_AC3: |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
654 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
|
655 // 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
|
656 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
|
657 // if(verbose) printf(" OK!\n"); |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
658 break; |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
659 case AFM_ACM: |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
660 case AFM_DSHOW: |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
661 case AFM_HWAC3: |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
662 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
|
663 break; |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
664 } |
1408 | 665 |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
666 } |
291 | 667 |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
668 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
|
669 switch(sh_audio->codec->driver){ |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
670 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
|
671 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
|
672 case AFM_ACM: |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
673 case AFM_DSHOW: { |
1408 | 674 int skip=sh_audio->wf->nBlockAlign; |
675 if(skip<16){ | |
676 skip=(sh_audio->wf->nAvgBytesPerSec/16)&(~7); | |
677 if(skip<16) skip=16; | |
678 } | |
679 demux_read_data(sh_audio->ds,NULL,skip); | |
680 break; | |
681 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
682 case AFM_PCM: |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
683 case AFM_DVDPCM: |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
684 case AFM_ALAW: { |
1408 | 685 int skip=sh_audio->i_bps/16; |
686 skip=skip&(~3); | |
687 demux_read_data(sh_audio->ds,NULL,skip); | |
688 break; | |
689 } | |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
690 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
|
691 } |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
692 } |