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