Mercurial > mplayer.hg
annotate dec_audio.c @ 639:520f0e2c1113
URLs fixed
author | arpi_esp |
---|---|
date | Wed, 25 Apr 2001 23:52:11 +0000 |
parents | 18496fdfd419 |
children | ef7249823af2 |
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 } |
303 | 104 break; |
296 | 105 } |
303 | 106 case 2: { |
296 | 107 // 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
|
108 WAVEFORMATEX *h=sh_audio->wf; |
296 | 109 sh_audio->channels=h->nChannels; |
110 sh_audio->samplerate=h->nSamplesPerSec; | |
111 sh_audio->samplesize=(h->wBitsPerSample+7)/8; | |
401 | 112 break; |
113 } | |
114 case 8: { | |
115 // DVD PCM Audio: | |
116 sh_audio->channels=2; | |
117 sh_audio->samplerate=48000; | |
296 | 118 // sh_audio->pcm_bswap=1; |
303 | 119 break; |
120 } | |
121 case 3: { | |
296 | 122 // Dolby AC3 audio: |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
123 ac3_audio_sh=sh_audio; // save sh_audio for the callback: |
296 | 124 ac3_config.fill_buffer_callback = ac3_fill_buffer; |
125 ac3_config.num_output_ch = 2; | |
126 ac3_config.flags = 0; | |
127 #ifdef HAVE_MMX | |
128 ac3_config.flags |= AC3_MMX_ENABLE; | |
129 #endif | |
130 #ifdef HAVE_3DNOW | |
131 ac3_config.flags |= AC3_3DNOW_ENABLE; | |
132 #endif | |
133 ac3_init(); | |
134 sh_audio->ac3_frame = ac3_decode_frame(); | |
135 if(sh_audio->ac3_frame){ | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
136 sh_audio->samplerate=((ac3_frame_t*)sh_audio->ac3_frame)->sampling_rate; |
296 | 137 sh_audio->channels=2; |
303 | 138 } else { |
139 driver=0; // bad frame -> disable audio | |
140 } | |
141 break; | |
142 } | |
143 case 5: { | |
296 | 144 // aLaw audio codec: |
145 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
|
146 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
|
147 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; |
303 | 148 break; |
149 } | |
150 case 6: { | |
296 | 151 // MS-GSM audio codec: |
152 GSM_Init(); | |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
153 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
|
154 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; |
303 | 155 break; |
296 | 156 } |
303 | 157 case 1: { |
296 | 158 // MPEG Audio: |
159 MP3_Init(); | |
160 MP3_samplerate=MP3_channels=0; | |
161 // printf("[\n"); | |
162 sh_audio->a_buffer_len=MP3_DecodeFrame(sh_audio->a_buffer,-1); | |
163 // printf("]\n"); | |
164 sh_audio->channels=2; // hack | |
165 sh_audio->samplerate=MP3_samplerate; | |
303 | 166 break; |
167 } | |
296 | 168 } |
169 | |
170 if(!sh_audio->channels || !sh_audio->samplerate){ | |
171 printf("Unknown/missing audio format, using nosound\n"); | |
303 | 172 driver=0; |
296 | 173 } |
174 | |
303 | 175 if(!driver){ |
176 if(sh_audio->a_buffer) free(sh_audio->a_buffer); | |
177 sh_audio->o_bps=0; | |
178 return 0; | |
179 } | |
296 | 180 |
303 | 181 sh_audio->o_bps=sh_audio->channels*sh_audio->samplerate*sh_audio->samplesize; |
182 return driver; | |
296 | 183 } |
291 | 184 |
185 // Audio decoding | |
186 | |
187 int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int maxlen){ | |
188 int len=-1; | |
303 | 189 switch(sh_audio->codec->driver){ |
291 | 190 case 1: // MPEG layer 2 or 3 |
191 len=MP3_DecodeFrame(buf,-1); | |
296 | 192 sh_audio->channels=2; // hack |
291 | 193 break; |
401 | 194 case 2: // AVI PCM |
291 | 195 { len=demux_read_data(sh_audio->ds,buf,OUTBURST); |
401 | 196 break; |
197 } | |
198 case 8: // DVD PCM | |
199 { int j; | |
200 len=demux_read_data(sh_audio->ds,buf,OUTBURST); | |
291 | 201 //if(i&1){ printf("Warning! pcm_audio_size&1 !=0 (%d)\n",i);i&=~1; } |
202 for(j=0;j<len;j+=2){ | |
203 char x=buf[j]; | |
204 buf[j]=buf[j+1]; | |
205 buf[j+1]=x; | |
206 } | |
207 break; | |
208 } | |
209 case 5: // aLaw decoder | |
210 { int l=demux_read_data(sh_audio->ds,buf,OUTBURST/2); | |
211 unsigned short *d=(unsigned short *) buf; | |
212 unsigned char *s=buf; | |
213 len=2*l; | |
214 while(l>0){ | |
215 --l; | |
216 d[l]=xa_alaw_2_sign[s[l]]; | |
217 } | |
218 break; | |
219 } | |
220 case 6: // MS-GSM decoder | |
221 { unsigned char buf[65]; // 65 bytes / frame | |
222 len=0; | |
223 while(len<OUTBURST){ | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
224 if(demux_read_data(sh_audio->ds,buf,65)!=65) break; // EOF |
291 | 225 XA_MSGSM_Decoder(buf,(unsigned short *) buf); // decodes 65 byte -> 320 short |
296 | 226 // XA_GSM_Decoder(buf,(unsigned short *) &sh_audio->a_buffer[sh_audio->a_buffer_len]); // decodes 33 byte -> 160 short |
291 | 227 len+=2*320; |
228 } | |
229 break; | |
230 } | |
231 case 3: // AC3 decoder | |
232 //printf("{1:%d}",avi_header.idx_pos);fflush(stdout); | |
233 if(!sh_audio->ac3_frame) sh_audio->ac3_frame=ac3_decode_frame(); | |
234 //printf("{2:%d}",avi_header.idx_pos);fflush(stdout); | |
235 if(sh_audio->ac3_frame){ | |
296 | 236 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
|
237 memcpy(buf,((ac3_frame_t*)sh_audio->ac3_frame)->audio_data,len); |
291 | 238 sh_audio->ac3_frame=NULL; |
239 } | |
240 //printf("{3:%d}",avi_header.idx_pos);fflush(stdout); | |
241 break; | |
242 case 4: | |
243 { len=acm_decode_audio(sh_audio,buf,maxlen); | |
244 break; | |
245 } | |
246 #ifdef USE_DIRECTSHOW | |
247 case 7: // DirectShow | |
248 { int ret; | |
249 int size_in=0; | |
250 int size_out=0; | |
251 int srcsize=DS_AudioDecoder_GetSrcSize(maxlen); | |
252 if(verbose>2)printf("DShow says: srcsize=%d (buffsize=%d) out_size=%d\n",srcsize,sh_audio->a_in_buffer_size,maxlen); | |
253 if(srcsize>sh_audio->a_in_buffer_size) srcsize=sh_audio->a_in_buffer_size; // !!!!!! | |
254 if(sh_audio->a_in_buffer_len<srcsize){ | |
255 sh_audio->a_in_buffer_len+= | |
256 demux_read_data(sh_audio->ds,&sh_audio->a_in_buffer[sh_audio->a_in_buffer_len], | |
257 srcsize-sh_audio->a_in_buffer_len); | |
258 } | |
259 DS_AudioDecoder_Convert(sh_audio->a_in_buffer,sh_audio->a_in_buffer_len, | |
260 buf,maxlen, &size_in,&size_out); | |
261 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); | |
262 if(size_in>=sh_audio->a_in_buffer_len){ | |
263 sh_audio->a_in_buffer_len=0; | |
264 } else { | |
265 sh_audio->a_in_buffer_len-=size_in; | |
266 memcpy(sh_audio->a_in_buffer,&sh_audio->a_in_buffer[size_in],sh_audio->a_in_buffer_len); | |
267 } | |
268 len=size_out; | |
269 break; | |
270 } | |
271 #endif | |
272 } | |
273 return len; | |
274 } | |
275 | |
276 |