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