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