Mercurial > mplayer.hg
annotate dec_audio.c @ 752:a40ee717336e
some more printfs
author | arpi_esp |
---|---|
date | Thu, 10 May 2001 13:20:56 +0000 |
parents | cd1f0d4de0b8 |
children | 32a8e9e43d94 |
rev | line source |
---|---|
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
1 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
2 #include <stdio.h> |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
3 #include <stdlib.h> |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
4 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
5 #include "config.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
6 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
7 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
|
8 |
732
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
9 #ifdef USE_FAKE_MONO |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
10 int fakemono=0; |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
11 #endif |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
12 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
13 #include "stream.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
14 #include "demuxer.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
15 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
16 #include "wine/mmreg.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
17 #include "wine/avifmt.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
18 #include "wine/vfw.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 "codec-cfg.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
21 #include "stheader.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
22 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
23 #include "mp3lib/mp3.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
24 #include "libac3/ac3.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
25 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
26 #include "alaw.c" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
27 #include "xa/xa_gsm.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
28 |
604 | 29 #include "loader/DirectShow/DS_AudioDec.h" |
30 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
31 static sh_audio_t* ac3_audio_sh=NULL; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
32 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
33 // AC3 decoder buffer callback: |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
34 static void ac3_fill_buffer(uint8_t **start,uint8_t **end){ |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
35 int len=ds_get_packet(ac3_audio_sh->ds,start); |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
36 //printf("<ac3:%d>\n",len); |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
37 if(len<0) |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
38 *start = *end = NULL; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
39 else |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
40 *end = *start + len; |
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 |
296 | 43 |
44 int init_audio(sh_audio_t *sh_audio){ | |
303 | 45 |
46 int driver=sh_audio->codec->driver; | |
296 | 47 |
604 | 48 extern int init_acm_audio_codec(sh_audio_t *sh_audio); |
49 extern int acm_decode_audio(sh_audio_t *sh_audio, void* a_buffer,int len); | |
50 | |
296 | 51 sh_audio->samplesize=2; |
303 | 52 sh_audio->samplerate=0; |
401 | 53 //sh_audio->pcm_bswap=0; |
303 | 54 |
746 | 55 sh_audio->a_buffer_size=2*MAX_OUTBURST; // default size, maybe not enough for Win32/ACM |
303 | 56 sh_audio->a_buffer=NULL; |
296 | 57 |
746 | 58 sh_audio->a_in_buffer_len=0; |
59 | |
303 | 60 if(driver==4){ |
296 | 61 // Win32 ACM audio codec: |
62 if(init_acm_audio_codec(sh_audio)){ | |
746 | 63 sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec; |
296 | 64 sh_audio->channels=sh_audio->o_wf.nChannels; |
65 sh_audio->samplerate=sh_audio->o_wf.nSamplesPerSec; | |
746 | 66 if(sh_audio->a_buffer_size<sh_audio->audio_out_minsize+MAX_OUTBURST) |
67 sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST; | |
296 | 68 } else { |
69 printf("Could not load/initialize Win32/ACM AUDIO codec (missing DLL file?)\n"); | |
303 | 70 driver=0; |
296 | 71 } |
72 } | |
73 | |
303 | 74 if(driver==7){ |
296 | 75 #ifndef USE_DIRECTSHOW |
76 printf("Compiled without DirectShow support -> force nosound :(\n"); | |
303 | 77 driver=0; |
296 | 78 #else |
79 // Win32 DShow audio codec: | |
340 | 80 // printf("DShow_audio: channs=%d rate=%d\n",sh_audio->channels,sh_audio->samplerate); |
296 | 81 |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
82 if(DS_AudioDecoder_Open(sh_audio->codec->dll,&sh_audio->codec->guid,sh_audio->wf)){ |
303 | 83 printf("ERROR: Could not load/initialize Win32/DirctShow AUDIO codec: %s\n",sh_audio->codec->dll); |
84 driver=0; | |
85 } else { | |
746 | 86 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
|
87 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
|
88 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
|
89 sh_audio->audio_in_minsize=2*sh_audio->wf->nBlockAlign; |
296 | 90 if(sh_audio->audio_in_minsize<8192) sh_audio->audio_in_minsize=8192; |
91 sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize; | |
92 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size); | |
93 sh_audio->a_in_buffer_len=0; | |
94 } | |
95 #endif | |
96 } | |
97 | |
303 | 98 if(!driver) return 0; |
296 | 99 |
100 // allocate audio out buffer: | |
101 sh_audio->a_buffer=malloc(sh_audio->a_buffer_size); | |
102 memset(sh_audio->a_buffer,0,sh_audio->a_buffer_size); | |
103 sh_audio->a_buffer_len=0; | |
104 | |
303 | 105 switch(driver){ |
106 case 4: { | |
296 | 107 int ret=acm_decode_audio(sh_audio,sh_audio->a_buffer,sh_audio->a_buffer_size); |
108 if(ret<0){ | |
303 | 109 printf("ACM decoding error: %d\n",ret); |
110 driver=0; | |
296 | 111 } |
640 | 112 sh_audio->a_buffer_len=ret; |
303 | 113 break; |
296 | 114 } |
303 | 115 case 2: { |
296 | 116 // 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
|
117 WAVEFORMATEX *h=sh_audio->wf; |
746 | 118 sh_audio->i_bps=h->nAvgBytesPerSec; |
296 | 119 sh_audio->channels=h->nChannels; |
120 sh_audio->samplerate=h->nSamplesPerSec; | |
121 sh_audio->samplesize=(h->wBitsPerSample+7)/8; | |
401 | 122 break; |
123 } | |
124 case 8: { | |
125 // DVD PCM Audio: | |
126 sh_audio->channels=2; | |
127 sh_audio->samplerate=48000; | |
746 | 128 sh_audio->i_bps=2*2*48000; |
296 | 129 // sh_audio->pcm_bswap=1; |
303 | 130 break; |
131 } | |
132 case 3: { | |
296 | 133 // Dolby AC3 audio: |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
134 ac3_audio_sh=sh_audio; // save sh_audio for the callback: |
296 | 135 ac3_config.fill_buffer_callback = ac3_fill_buffer; |
136 ac3_config.num_output_ch = 2; | |
137 ac3_config.flags = 0; | |
138 #ifdef HAVE_MMX | |
139 ac3_config.flags |= AC3_MMX_ENABLE; | |
140 #endif | |
141 #ifdef HAVE_3DNOW | |
142 ac3_config.flags |= AC3_3DNOW_ENABLE; | |
143 #endif | |
144 ac3_init(); | |
145 sh_audio->ac3_frame = ac3_decode_frame(); | |
146 if(sh_audio->ac3_frame){ | |
746 | 147 ac3_frame_t* fr=(ac3_frame_t*)sh_audio->ac3_frame; |
148 sh_audio->samplerate=fr->sampling_rate; | |
296 | 149 sh_audio->channels=2; |
746 | 150 // 1 frame: 6*256 samples 1 sec: sh_audio->samplerate samples |
151 //sh_audio->i_bps=fr->frame_size*fr->sampling_rate/(6*256); | |
152 sh_audio->i_bps=fr->bit_rate*(1000/8); | |
303 | 153 } else { |
154 driver=0; // bad frame -> disable audio | |
155 } | |
156 break; | |
157 } | |
158 case 5: { | |
296 | 159 // aLaw audio codec: |
160 Gen_aLaw_2_Signed(); // init table | |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
161 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
|
162 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; |
746 | 163 sh_audio->i_bps=sh_audio->channels*sh_audio->samplerate; |
303 | 164 break; |
165 } | |
166 case 6: { | |
296 | 167 // MS-GSM audio codec: |
168 GSM_Init(); | |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
169 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
|
170 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; |
746 | 171 // decodes 65 byte -> 320 short |
172 // 1 sec: sh_audio->channels*sh_audio->samplerate samples | |
173 // 1 frame: 320 samples | |
174 sh_audio->i_bps=65*(sh_audio->channels*sh_audio->samplerate)/320; // 1:10 | |
303 | 175 break; |
296 | 176 } |
303 | 177 case 1: { |
296 | 178 // MPEG Audio: |
732
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
179 #ifdef USE_FAKE_MONO |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
180 MP3_Init(fakemono); |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
181 #else |
296 | 182 MP3_Init(); |
732
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
183 #endif |
296 | 184 MP3_samplerate=MP3_channels=0; |
185 // printf("[\n"); | |
186 sh_audio->a_buffer_len=MP3_DecodeFrame(sh_audio->a_buffer,-1); | |
187 // printf("]\n"); | |
188 sh_audio->channels=2; // hack | |
189 sh_audio->samplerate=MP3_samplerate; | |
746 | 190 sh_audio->i_bps=MP3_bitrate*(1000/8); |
303 | 191 break; |
192 } | |
296 | 193 } |
194 | |
195 if(!sh_audio->channels || !sh_audio->samplerate){ | |
196 printf("Unknown/missing audio format, using nosound\n"); | |
303 | 197 driver=0; |
296 | 198 } |
199 | |
303 | 200 if(!driver){ |
201 if(sh_audio->a_buffer) free(sh_audio->a_buffer); | |
202 sh_audio->o_bps=0; | |
203 return 0; | |
204 } | |
296 | 205 |
303 | 206 sh_audio->o_bps=sh_audio->channels*sh_audio->samplerate*sh_audio->samplesize; |
207 return driver; | |
296 | 208 } |
291 | 209 |
746 | 210 // Audio decoding: |
291 | 211 |
746 | 212 // Decode a single frame (mp3,acm etc) or 'minlen' bytes (pcm/alaw etc) |
213 // buffer length is 'maxlen' bytes, it shouldn't be exceeded... | |
214 | |
215 int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen){ | |
291 | 216 int len=-1; |
303 | 217 switch(sh_audio->codec->driver){ |
291 | 218 case 1: // MPEG layer 2 or 3 |
219 len=MP3_DecodeFrame(buf,-1); | |
296 | 220 sh_audio->channels=2; // hack |
291 | 221 break; |
401 | 222 case 2: // AVI PCM |
746 | 223 { len=demux_read_data(sh_audio->ds,buf,minlen); |
401 | 224 break; |
225 } | |
226 case 8: // DVD PCM | |
227 { int j; | |
746 | 228 len=demux_read_data(sh_audio->ds,buf,minlen); |
291 | 229 //if(i&1){ printf("Warning! pcm_audio_size&1 !=0 (%d)\n",i);i&=~1; } |
746 | 230 // swap endian: |
291 | 231 for(j=0;j<len;j+=2){ |
232 char x=buf[j]; | |
233 buf[j]=buf[j+1]; | |
234 buf[j+1]=x; | |
235 } | |
236 break; | |
237 } | |
238 case 5: // aLaw decoder | |
746 | 239 { int l=demux_read_data(sh_audio->ds,buf,minlen/2); |
291 | 240 unsigned short *d=(unsigned short *) buf; |
241 unsigned char *s=buf; | |
242 len=2*l; | |
243 while(l>0){ | |
244 --l; | |
245 d[l]=xa_alaw_2_sign[s[l]]; | |
246 } | |
247 break; | |
248 } | |
249 case 6: // MS-GSM decoder | |
250 { unsigned char buf[65]; // 65 bytes / frame | |
746 | 251 if(demux_read_data(sh_audio->ds,buf,65)!=65) break; // EOF |
252 XA_MSGSM_Decoder(buf,(unsigned short *) buf); // decodes 65 byte -> 320 short | |
253 // XA_GSM_Decoder(buf,(unsigned short *) &sh_audio->a_buffer[sh_audio->a_buffer_len]); // decodes 33 byte -> 160 short | |
254 len=2*320; | |
291 | 255 break; |
256 } | |
257 case 3: // AC3 decoder | |
258 //printf("{1:%d}",avi_header.idx_pos);fflush(stdout); | |
259 if(!sh_audio->ac3_frame) sh_audio->ac3_frame=ac3_decode_frame(); | |
260 //printf("{2:%d}",avi_header.idx_pos);fflush(stdout); | |
261 if(sh_audio->ac3_frame){ | |
296 | 262 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
|
263 memcpy(buf,((ac3_frame_t*)sh_audio->ac3_frame)->audio_data,len); |
291 | 264 sh_audio->ac3_frame=NULL; |
265 } | |
266 //printf("{3:%d}",avi_header.idx_pos);fflush(stdout); | |
267 break; | |
268 case 4: | |
746 | 269 len=acm_decode_audio(sh_audio,buf,maxlen); |
270 // len=acm_decode_audio(sh_audio,buf,minlen); | |
291 | 271 break; |
746 | 272 |
291 | 273 #ifdef USE_DIRECTSHOW |
274 case 7: // DirectShow | |
275 { int ret; | |
276 int size_in=0; | |
277 int size_out=0; | |
278 int srcsize=DS_AudioDecoder_GetSrcSize(maxlen); | |
279 if(verbose>2)printf("DShow says: srcsize=%d (buffsize=%d) out_size=%d\n",srcsize,sh_audio->a_in_buffer_size,maxlen); | |
280 if(srcsize>sh_audio->a_in_buffer_size) srcsize=sh_audio->a_in_buffer_size; // !!!!!! | |
281 if(sh_audio->a_in_buffer_len<srcsize){ | |
282 sh_audio->a_in_buffer_len+= | |
283 demux_read_data(sh_audio->ds,&sh_audio->a_in_buffer[sh_audio->a_in_buffer_len], | |
284 srcsize-sh_audio->a_in_buffer_len); | |
285 } | |
286 DS_AudioDecoder_Convert(sh_audio->a_in_buffer,sh_audio->a_in_buffer_len, | |
287 buf,maxlen, &size_in,&size_out); | |
746 | 288 //if(verbose>2) |
289 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 | 290 if(size_in>=sh_audio->a_in_buffer_len){ |
291 sh_audio->a_in_buffer_len=0; | |
292 } else { | |
293 sh_audio->a_in_buffer_len-=size_in; | |
294 memcpy(sh_audio->a_in_buffer,&sh_audio->a_in_buffer[size_in],sh_audio->a_in_buffer_len); | |
295 } | |
296 len=size_out; | |
297 break; | |
298 } | |
299 #endif | |
300 } | |
301 return len; | |
302 } | |
303 | |
304 |