Mercurial > mplayer.hg
annotate dec_audio.c @ 3415:1602abff75a3
done :)
author | arpi |
---|---|
date | Sun, 09 Dec 2001 19:38:14 +0000 |
parents | 6236baa23bde |
children | 2066402f300d |
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" |
1567 | 7 #include "mp_msg.h" |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
8 #include "help_mp.h" |
1567 | 9 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
10 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
|
11 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
12 #include "stream.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
13 #include "demuxer.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
14 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
15 #include "codec-cfg.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
16 #include "stheader.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
17 |
2563 | 18 #include "dec_audio.h" |
19 | |
20 //========================================================================== | |
21 | |
22 #include "libao2/afmt.h" | |
23 | |
2049
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
24 #include "dll_init.h" |
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
25 |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
26 #include "mp3lib/mp3.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
27 #include "libac3/ac3.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
28 |
3413 | 29 #include "liba52/a52.h" |
30 static sample_t * a52_samples; | |
31 static a52_state_t a52_state; | |
32 | |
33 | |
883 | 34 #include "alaw.h" |
35 | |
587
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
36 #include "xa/xa_gsm.h" |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
37 |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
38 #include "ac3-iec958.h" |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
39 |
2420 | 40 #include "ima4.h" |
41 | |
3145 | 42 #include "cpudetect.h" |
43 | |
3182
95bbd21e8e1f
moved num_audio_channels out of LIBMAD ifdef, where it didn't belong!
steve
parents:
3181
diff
changeset
|
44 /* used for ac3surround decoder - set using -channels option */ |
95bbd21e8e1f
moved num_audio_channels out of LIBMAD ifdef, where it didn't belong!
steve
parents:
3181
diff
changeset
|
45 int audio_output_channels = 2; |
95bbd21e8e1f
moved num_audio_channels out of LIBMAD ifdef, where it didn't belong!
steve
parents:
3181
diff
changeset
|
46 |
2563 | 47 #ifdef USE_FAKE_MONO |
48 int fakemono=0; | |
49 #endif | |
50 | |
1291 | 51 #ifdef USE_DIRECTSHOW |
604 | 52 #include "loader/DirectShow/DS_AudioDec.h" |
1291 | 53 #endif |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1020
diff
changeset
|
54 |
1828 | 55 #ifdef HAVE_OGGVORBIS |
56 /* XXX is math.h really needed? - atmos */ | |
57 #include <math.h> | |
58 #include <vorbis/codec.h> | |
2341 | 59 |
60 typedef struct ov_struct_st { | |
61 ogg_sync_state oy; /* sync and verify incoming physical bitstream */ | |
62 ogg_stream_state os; /* take physical pages, weld into a logical | |
63 stream of packets */ | |
64 ogg_page og; /* one Ogg bitstream page. Vorbis packets are inside */ | |
65 ogg_packet op; /* one raw packet of data for decode */ | |
3145 | 66 |
2341 | 67 vorbis_info vi; /* struct that stores all the static vorbis bitstream |
68 settings */ | |
69 vorbis_comment vc; /* struct that stores all the bitstream user comments */ | |
70 vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */ | |
71 vorbis_block vb; /* local working space for packet->PCM decode */ | |
72 } ov_struct_t; | |
1828 | 73 #endif |
74 | |
1927 | 75 #ifdef USE_LIBAVCODEC |
2496 | 76 #ifdef USE_LIBAVCODEC_SO |
77 #include <libffmpeg/avcodec.h> | |
78 #else | |
1927 | 79 #include "libavcodec/avcodec.h" |
2496 | 80 #endif |
1927 | 81 static AVCodec *lavc_codec=NULL; |
82 static AVCodecContext lavc_context; | |
83 extern int avcodec_inited; | |
84 #endif | |
85 | |
2415 | 86 |
87 | |
88 #ifdef USE_LIBMAD | |
89 #include <mad.h> | |
90 static struct mad_stream mad_stream; | |
91 static struct mad_frame mad_frame; | |
92 static struct mad_synth mad_synth; | |
93 | |
94 // ensure buffer is filled with some data | |
95 static void mad_prepare_buffer(sh_audio_t* sh_audio, struct mad_stream* ms, int length) | |
96 { | |
97 if(sh_audio->a_in_buffer_len < length) { | |
98 int len = demux_read_data(sh_audio->ds, sh_audio->a_in_buffer+sh_audio->a_in_buffer_len, length-sh_audio->a_in_buffer_len); | |
99 sh_audio->a_in_buffer_len += len; | |
100 } | |
101 } | |
102 | |
103 static void mad_postprocess_buffer(sh_audio_t* sh_audio, struct mad_stream* ms) | |
104 { | |
105 int delta = (unsigned char*)ms->next_frame - (unsigned char *)sh_audio->a_in_buffer; | |
106 if(delta != 0) { | |
107 sh_audio->a_in_buffer_len -= delta; | |
108 memcpy(sh_audio->a_in_buffer, ms->next_frame, sh_audio->a_in_buffer_len); | |
109 } | |
110 } | |
111 | |
112 | |
113 static inline | |
114 signed short mad_scale(mad_fixed_t sample) | |
115 { | |
116 /* round */ | |
117 sample += (1L << (MAD_F_FRACBITS - 16)); | |
118 | |
119 /* clip */ | |
120 if (sample >= MAD_F_ONE) | |
121 sample = MAD_F_ONE - 1; | |
122 else if (sample < -MAD_F_ONE) | |
123 sample = -MAD_F_ONE; | |
124 | |
125 /* quantize */ | |
126 return sample >> (MAD_F_FRACBITS + 1 - 16); | |
127 } | |
128 #endif | |
129 | |
130 | |
3413 | 131 static int a52_fillbuff(sh_audio_t *sh_audio){ |
132 int length=0; | |
133 int flags=0; | |
134 int sample_rate=0; | |
135 int bit_rate=0; | |
136 while(1){ | |
137 while(sh_audio->a_in_buffer_len<7){ | |
138 int c=demux_getc(sh_audio->ds); | |
139 if(c<0) return -1; // EOF | |
140 sh_audio->a_in_buffer[sh_audio->a_in_buffer_len++]=c; | |
141 } | |
142 length = a52_syncinfo (sh_audio->a_in_buffer, &flags, &sample_rate, &bit_rate); | |
143 if(!length){ | |
144 // bad file => resync | |
145 memcpy(sh_audio->a_in_buffer,sh_audio->a_in_buffer+1,6); | |
146 --sh_audio->a_in_buffer_len; | |
147 continue; | |
148 } | |
149 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"a52: len=%d flags=0x%X %d Hz %d bit/s\n",length,flags,sample_rate,bit_rate); | |
150 if(length<7 || length>3840){ | |
151 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"a52: invalid frame length: %d\n",length); | |
152 continue; | |
153 } | |
154 sh_audio->samplerate=sample_rate; | |
155 sh_audio->i_bps=bit_rate/8; | |
156 demux_read_data(sh_audio->ds,sh_audio->a_in_buffer+7,length-7); | |
157 return length; | |
158 } | |
159 } | |
2415 | 160 |
1927 | 161 int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen); |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
162 |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
163 |
1289 | 164 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
|
165 |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
166 // AC3 decoder buffer callback: |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
167 static void ac3_fill_buffer(uint8_t **start,uint8_t **end){ |
1289 | 168 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
|
169 //printf("<ac3:%d>\n",len); |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
170 if(len<0) |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
171 *start = *end = NULL; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
172 else |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
173 *end = *start + len; |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
174 } |
8511095c5283
stage#1 completed: c files no more included from mplayer.c
arpi_esp
parents:
432
diff
changeset
|
175 |
1289 | 176 // MP3 decoder buffer callback: |
177 int mplayer_audio_read(char *buf,int size){ | |
178 int len; | |
179 len=demux_read_data(dec_audio_sh->ds,buf,size); | |
180 return len; | |
181 } | |
182 | |
296 | 183 int init_audio(sh_audio_t *sh_audio){ |
303 | 184 int driver=sh_audio->codec->driver; |
296 | 185 |
186 sh_audio->samplesize=2; | |
1320
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1313
diff
changeset
|
187 #if WORDS_BIGENDIAN |
18374d49befa
On big-endian architectures, all audio decoders default to big-endian 16-bit
jkeil
parents:
1313
diff
changeset
|
188 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
|
189 #else |
758 | 190 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
|
191 #endif |
303 | 192 sh_audio->samplerate=0; |
401 | 193 //sh_audio->pcm_bswap=0; |
1529 | 194 sh_audio->o_bps=0; |
303 | 195 |
758 | 196 sh_audio->a_buffer_size=0; |
303 | 197 sh_audio->a_buffer=NULL; |
296 | 198 |
746 | 199 sh_audio->a_in_buffer_len=0; |
200 | |
758 | 201 // setup required min. in/out buffer size: |
202 sh_audio->audio_out_minsize=8192;// default size, maybe not enough for Win32/ACM | |
203 | |
204 switch(driver){ | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
205 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
|
206 #ifndef USE_WIN32DLL |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
207 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_NoACMSupport); |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
208 driver=0; |
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
209 #else |
296 | 210 // Win32 ACM audio codec: |
211 if(init_acm_audio_codec(sh_audio)){ | |
746 | 212 sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec; |
296 | 213 sh_audio->channels=sh_audio->o_wf.nChannels; |
214 sh_audio->samplerate=sh_audio->o_wf.nSamplesPerSec; | |
758 | 215 // if(sh_audio->audio_out_minsize>16384) sh_audio->audio_out_minsize=16384; |
216 // sh_audio->a_buffer_size=sh_audio->audio_out_minsize; | |
217 // if(sh_audio->a_buffer_size<sh_audio->audio_out_minsize+MAX_OUTBURST) | |
218 // sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST; | |
296 | 219 } else { |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
220 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_ACMiniterror); |
303 | 221 driver=0; |
296 | 222 } |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
223 #endif |
758 | 224 break; |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
225 case AFM_DSHOW: |
296 | 226 #ifndef USE_DIRECTSHOW |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
227 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_NoDShowAudio); |
303 | 228 driver=0; |
296 | 229 #else |
230 // Win32 DShow audio codec: | |
340 | 231 // 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
|
232 if(DS_AudioDecoder_Open(sh_audio->codec->dll,&sh_audio->codec->guid,sh_audio->wf)){ |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
233 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_MissingDLLcodec,sh_audio->codec->dll); |
303 | 234 driver=0; |
235 } else { | |
746 | 236 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
|
237 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
|
238 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
|
239 sh_audio->audio_in_minsize=2*sh_audio->wf->nBlockAlign; |
296 | 240 if(sh_audio->audio_in_minsize<8192) sh_audio->audio_in_minsize=8192; |
241 sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize; | |
242 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size); | |
243 sh_audio->a_in_buffer_len=0; | |
758 | 244 sh_audio->audio_out_minsize=16384; |
296 | 245 } |
246 #endif | |
758 | 247 break; |
1828 | 248 case AFM_VORBIS: |
249 #ifndef HAVE_OGGVORBIS | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
250 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_NoOggVorbis); |
1828 | 251 driver=0; |
252 #else | |
253 /* OggVorbis audio via libvorbis, compatible with files created by nandub and zorannt codec */ | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
254 sh_audio->audio_out_minsize=1024*4; // 1024 samples/frame |
1828 | 255 #endif |
256 break; | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
257 case AFM_PCM: |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
258 case AFM_DVDPCM: |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
259 case AFM_ALAW: |
758 | 260 // PCM, aLaw |
261 sh_audio->audio_out_minsize=2048; | |
262 break; | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
263 case AFM_AC3: |
3413 | 264 case AFM_A52: |
758 | 265 // Dolby AC3 audio: |
3181
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3145
diff
changeset
|
266 // however many channels, 2 bytes in a word, 256 samples in a block, 6 blocks in a frame |
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3145
diff
changeset
|
267 sh_audio->audio_out_minsize=audio_output_channels*2*256*6; |
758 | 268 break; |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
269 case AFM_HWAC3: |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
270 // Dolby AC3 audio: |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
271 sh_audio->audio_out_minsize=4*256*6; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
272 sh_audio->sample_format = AFMT_AC3; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
273 break; |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
274 case AFM_GSM: |
758 | 275 // MS-GSM audio codec: |
276 sh_audio->audio_out_minsize=4*320; | |
277 break; | |
2420 | 278 case AFM_IMA4: |
279 // IMA-ADPCM 4:1 audio codec: | |
280 sh_audio->audio_out_minsize=4096; //4*IMA4_SAMPLES_PER_BLOCK; | |
281 sh_audio->ds->ss_div=IMA4_SAMPLES_PER_BLOCK; | |
282 sh_audio->ds->ss_mul=IMA4_BLOCK_SIZE; | |
283 break; | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
284 case AFM_MPEG: |
758 | 285 // MPEG Audio: |
286 sh_audio->audio_out_minsize=4608; | |
287 break; | |
1927 | 288 case AFM_FFMPEG: |
289 #ifndef USE_LIBAVCODEC | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
290 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_NoLAVCsupport); |
1927 | 291 return 0; |
292 #else | |
293 // FFmpeg Audio: | |
294 sh_audio->audio_out_minsize=AVCODEC_MAX_AUDIO_FRAME_SIZE; | |
295 break; | |
296 #endif | |
2415 | 297 |
298 #ifdef USE_LIBMAD | |
299 case AFM_MAD: | |
300 printf(__FILE__ ":%d:mad: setting minimum outputsize\n", __LINE__); | |
301 sh_audio->audio_out_minsize=4608; | |
302 if(sh_audio->audio_in_minsize<8192) sh_audio->audio_in_minsize=8192; | |
303 sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize; | |
304 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size); | |
305 sh_audio->a_in_buffer_len=0; | |
306 break; | |
307 #endif | |
296 | 308 } |
309 | |
303 | 310 if(!driver) return 0; |
296 | 311 |
312 // allocate audio out buffer: | |
758 | 313 sh_audio->a_buffer_size=sh_audio->audio_out_minsize+MAX_OUTBURST; // worst case calc. |
314 | |
1567 | 315 mp_msg(MSGT_DECAUDIO,MSGL_V,"dec_audio: Allocating %d + %d = %d bytes for output buffer\n", |
758 | 316 sh_audio->audio_out_minsize,MAX_OUTBURST,sh_audio->a_buffer_size); |
317 | |
296 | 318 sh_audio->a_buffer=malloc(sh_audio->a_buffer_size); |
758 | 319 if(!sh_audio->a_buffer){ |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
320 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_CantAllocAudioBuf); |
758 | 321 return 0; |
322 } | |
296 | 323 memset(sh_audio->a_buffer,0,sh_audio->a_buffer_size); |
324 sh_audio->a_buffer_len=0; | |
325 | |
303 | 326 switch(driver){ |
1517
0e9c29538a86
Use USE_WIN32DLL define instead of ARCH_X86 to decide whether or not to compile
jkeil
parents:
1485
diff
changeset
|
327 #ifdef USE_WIN32DLL |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
328 case AFM_ACM: { |
758 | 329 int ret=acm_decode_audio(sh_audio,sh_audio->a_buffer,4096,sh_audio->a_buffer_size); |
296 | 330 if(ret<0){ |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
331 mp_msg(MSGT_DECAUDIO,MSGL_INFO,"ACM decoding error: %d\n",ret); |
303 | 332 driver=0; |
296 | 333 } |
640 | 334 sh_audio->a_buffer_len=ret; |
303 | 335 break; |
296 | 336 } |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
337 #endif |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
338 case AFM_PCM: { |
296 | 339 // 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
|
340 WAVEFORMATEX *h=sh_audio->wf; |
746 | 341 sh_audio->i_bps=h->nAvgBytesPerSec; |
296 | 342 sh_audio->channels=h->nChannels; |
343 sh_audio->samplerate=h->nSamplesPerSec; | |
344 sh_audio->samplesize=(h->wBitsPerSample+7)/8; | |
758 | 345 switch(sh_audio->format){ // hardware formats: |
346 case 0x6: sh_audio->sample_format=AFMT_A_LAW;break; | |
347 case 0x7: sh_audio->sample_format=AFMT_MU_LAW;break; | |
348 case 0x11: sh_audio->sample_format=AFMT_IMA_ADPCM;break; | |
349 case 0x50: sh_audio->sample_format=AFMT_MPEG;break; | |
2547 | 350 case 0x736F7774: sh_audio->sample_format=AFMT_S16_LE;sh_audio->codec->driver=AFM_DVDPCM;break; |
758 | 351 // case 0x2000: sh_audio->sample_format=AFMT_AC3; |
352 default: sh_audio->sample_format=(sh_audio->samplesize==2)?AFMT_S16_LE:AFMT_U8; | |
353 } | |
401 | 354 break; |
355 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
356 case AFM_DVDPCM: { |
401 | 357 // DVD PCM Audio: |
358 sh_audio->channels=2; | |
359 sh_audio->samplerate=48000; | |
746 | 360 sh_audio->i_bps=2*2*48000; |
296 | 361 // sh_audio->pcm_bswap=1; |
303 | 362 break; |
363 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
364 case AFM_AC3: { |
296 | 365 // Dolby AC3 audio: |
1289 | 366 dec_audio_sh=sh_audio; // save sh_audio for the callback: |
296 | 367 ac3_config.fill_buffer_callback = ac3_fill_buffer; |
3181
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3145
diff
changeset
|
368 ac3_config.num_output_ch = audio_output_channels; |
296 | 369 ac3_config.flags = 0; |
3145 | 370 if(gCpuCaps.hasMMX){ |
296 | 371 ac3_config.flags |= AC3_MMX_ENABLE; |
3145 | 372 } |
373 if(gCpuCaps.has3DNow){ | |
296 | 374 ac3_config.flags |= AC3_3DNOW_ENABLE; |
3145 | 375 } |
296 | 376 ac3_init(); |
377 sh_audio->ac3_frame = ac3_decode_frame(); | |
378 if(sh_audio->ac3_frame){ | |
746 | 379 ac3_frame_t* fr=(ac3_frame_t*)sh_audio->ac3_frame; |
380 sh_audio->samplerate=fr->sampling_rate; | |
3181
c8edb0691f09
Extended oss output driver and libac3 to support 4 and 6 channel output mixes. added -channels command line option
steve
parents:
3145
diff
changeset
|
381 sh_audio->channels=ac3_config.num_output_ch; |
746 | 382 // 1 frame: 6*256 samples 1 sec: sh_audio->samplerate samples |
383 //sh_audio->i_bps=fr->frame_size*fr->sampling_rate/(6*256); | |
384 sh_audio->i_bps=fr->bit_rate*(1000/8); | |
303 | 385 } else { |
386 driver=0; // bad frame -> disable audio | |
387 } | |
388 break; | |
389 } | |
3413 | 390 case AFM_A52: { |
391 // Dolby AC3 audio: | |
392 int accel=0; // should contain mmx/sse/etc flags | |
393 a52_samples=a52_init (accel); | |
394 if (a52_samples == NULL) { | |
395 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"A52 init failed\n"); | |
396 driver=0;break; | |
397 } | |
398 sh_audio->a_in_buffer_size=3840; | |
399 sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size); | |
400 sh_audio->a_in_buffer_len=0; | |
401 if(a52_fillbuff(sh_audio)<0){ | |
402 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"A52 sync failed\n"); | |
403 driver=0;break; | |
404 } | |
405 sh_audio->channels=audio_output_channels; | |
406 break; | |
407 } | |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
408 case AFM_HWAC3: { |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
409 unsigned char *buffer; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
410 struct hwac3info ai; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
411 int len, skipped; |
1529 | 412 len = ds_get_packet(sh_audio->ds, &buffer); // maybe 1 packet is not enough, |
413 // 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
|
414 if(ac3_iec958_parse_syncinfo(buffer, len, &ai, &skipped) < 0) { |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
415 mp_msg(MSGT_DECAUDIO,MSGL_ERR, MSGTR_AC3notvalid); |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
416 driver = 0; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
417 break; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
418 } |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
419 if(ai.samplerate != 48000) { |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
420 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_AC3only48k); |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
421 driver = 0; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
422 break; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
423 } |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
424 sh_audio->samplerate=ai.samplerate; |
1529 | 425 sh_audio->samplesize=ai.framesize; |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
426 sh_audio->channels=1; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
427 sh_audio->i_bps=ai.bitrate*(1000/8); |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
428 sh_audio->ac3_frame=malloc(6144); |
1529 | 429 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
|
430 break; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
431 } |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
432 case AFM_ALAW: { |
296 | 433 // 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
|
434 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
|
435 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; |
746 | 436 sh_audio->i_bps=sh_audio->channels*sh_audio->samplerate; |
303 | 437 break; |
438 } | |
1927 | 439 #ifdef USE_LIBAVCODEC |
440 case AFM_FFMPEG: { | |
441 int x; | |
442 mp_msg(MSGT_DECAUDIO,MSGL_V,"FFmpeg's libavcodec audio codec\n"); | |
443 if(!avcodec_inited){ | |
444 avcodec_init(); | |
445 avcodec_register_all(); | |
446 avcodec_inited=1; | |
447 } | |
448 lavc_codec = (AVCodec *)avcodec_find_decoder_by_name(sh_audio->codec->dll); | |
449 if(!lavc_codec){ | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
450 mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_MissingLAVCcodec,sh_audio->codec->dll); |
1927 | 451 return 0; |
452 } | |
453 memset(&lavc_context, 0, sizeof(lavc_context)); | |
454 /* open it */ | |
455 if (avcodec_open(&lavc_context, lavc_codec) < 0) { | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
456 mp_msg(MSGT_DECAUDIO,MSGL_ERR, MSGTR_CantOpenCodec); |
1927 | 457 return 0; |
458 } | |
459 mp_msg(MSGT_DECAUDIO,MSGL_V,"INFO: libavcodec init OK!\n"); | |
460 | |
461 // Decode at least 1 byte: (to get header filled) | |
462 x=decode_audio(sh_audio,sh_audio->a_buffer,1,sh_audio->a_buffer_size); | |
463 if(x>0) sh_audio->a_buffer_len=x; | |
464 | |
465 #if 1 | |
466 sh_audio->channels=lavc_context.channels; | |
467 sh_audio->samplerate=lavc_context.sample_rate; | |
468 sh_audio->i_bps=lavc_context.bit_rate/8; | |
469 #else | |
470 sh_audio->channels=sh_audio->wf->nChannels; | |
471 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; | |
472 sh_audio->i_bps=sh_audio->wf->nAvgBytesPerSec; | |
473 #endif | |
474 break; | |
475 } | |
476 #endif | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
477 case AFM_GSM: { |
296 | 478 // MS-GSM audio codec: |
479 GSM_Init(); | |
432
5251b0c57e39
sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents:
401
diff
changeset
|
480 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
|
481 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; |
746 | 482 // decodes 65 byte -> 320 short |
483 // 1 sec: sh_audio->channels*sh_audio->samplerate samples | |
484 // 1 frame: 320 samples | |
485 sh_audio->i_bps=65*(sh_audio->channels*sh_audio->samplerate)/320; // 1:10 | |
303 | 486 break; |
296 | 487 } |
2420 | 488 case AFM_IMA4: { |
489 // IMA-ADPCM 4:1 audio codec: | |
490 sh_audio->channels=sh_audio->wf->nChannels; | |
491 sh_audio->samplerate=sh_audio->wf->nSamplesPerSec; | |
492 // decodes 34 byte -> 64 short | |
493 sh_audio->i_bps=IMA4_BLOCK_SIZE*(sh_audio->channels*sh_audio->samplerate)/IMA4_SAMPLES_PER_BLOCK; // 1:4 | |
494 break; | |
495 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
496 case AFM_MPEG: { |
296 | 497 // MPEG Audio: |
1289 | 498 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
|
499 #ifdef USE_FAKE_MONO |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
500 MP3_Init(fakemono); |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
501 #else |
296 | 502 MP3_Init(); |
732
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
640
diff
changeset
|
503 #endif |
296 | 504 MP3_samplerate=MP3_channels=0; |
505 // printf("[\n"); | |
506 sh_audio->a_buffer_len=MP3_DecodeFrame(sh_audio->a_buffer,-1); | |
507 // printf("]\n"); | |
508 sh_audio->channels=2; // hack | |
509 sh_audio->samplerate=MP3_samplerate; | |
746 | 510 sh_audio->i_bps=MP3_bitrate*(1000/8); |
303 | 511 break; |
512 } | |
1828 | 513 #ifdef HAVE_OGGVORBIS |
514 case AFM_VORBIS: { | |
515 // OggVorbis Audio: | |
516 #if 0 /* just here for reference - atmos */ | |
517 ogg_sync_state oy; /* sync and verify incoming physical bitstream */ | |
518 ogg_stream_state os; /* take physical pages, weld into a logical | |
519 stream of packets */ | |
520 ogg_page og; /* one Ogg bitstream page. Vorbis packets are inside */ | |
521 ogg_packet op; /* one raw packet of data for decode */ | |
522 | |
523 vorbis_info vi; /* struct that stores all the static vorbis bitstream | |
524 settings */ | |
525 vorbis_comment vc; /* struct that stores all the bitstream user comments */ | |
526 vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */ | |
527 vorbis_block vb; /* local working space for packet->PCM decode */ | |
528 #else | |
529 /* nix, nada, rien, nothing, nem, nüx */ | |
530 #endif | |
531 | |
532 uint32_t hdrsizes[3];/* stores vorbis header sizes from AVI audio header, | |
533 maybe use ogg_uint32_t */ | |
534 //int i; | |
535 int ret; | |
536 char *buffer; | |
537 ogg_packet hdr; | |
538 //ov_struct_t *s=&sh_audio->ov; | |
539 sh_audio->ov=malloc(sizeof(ov_struct_t)); | |
540 //s=&sh_audio->ov; | |
541 | |
542 vorbis_info_init(&sh_audio->ov->vi); | |
543 vorbis_comment_init(&sh_audio->ov->vc); | |
544 | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
545 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"OggVorbis: cbsize: %i\n", sh_audio->wf->cbSize); |
1828 | 546 memcpy(hdrsizes, ((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX), 3*sizeof(uint32_t)); |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
547 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"OggVorbis: Read header sizes: initial: %i comment: %i codebook: %i\n", hdrsizes[0], hdrsizes[1], hdrsizes[2]); |
1828 | 548 /*for(i=12; i <= 40; i+=2) { // header bruteforce :) |
549 memcpy(hdrsizes, ((unsigned char*)sh_audio->wf)+i, 3*sizeof(uint32_t)); | |
550 printf("OggVorbis: Read header sizes (%i): %ld %ld %ld\n", i, hdrsizes[0], hdrsizes[1], hdrsizes[2]); | |
551 }*/ | |
552 | |
553 /* read headers */ // FIXME disable sound on errors here, we absolutely need this headers! - atmos | |
554 hdr.packet=NULL; | |
555 hdr.b_o_s = 1; /* beginning of stream for first packet */ | |
556 hdr.bytes = hdrsizes[0]; | |
557 hdr.packet = realloc(hdr.packet,hdr.bytes); | |
558 memcpy(hdr.packet,((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX)+3*sizeof(uint32_t),hdr.bytes); | |
559 if(vorbis_synthesis_headerin(&sh_audio->ov->vi,&sh_audio->ov->vc,&hdr)<0) | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
560 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"OggVorbis: initial (identification) header broken!\n"); |
1828 | 561 hdr.b_o_s = 0; |
562 hdr.bytes = hdrsizes[1]; | |
563 hdr.packet = realloc(hdr.packet,hdr.bytes); | |
564 memcpy(hdr.packet,((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX)+3*sizeof(uint32_t)+hdrsizes[0],hdr.bytes); | |
565 if(vorbis_synthesis_headerin(&sh_audio->ov->vi,&sh_audio->ov->vc,&hdr)<0) | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
566 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"OggVorbis: comment header broken!\n"); |
1828 | 567 hdr.bytes = hdrsizes[2]; |
568 hdr.packet = realloc(hdr.packet,hdr.bytes); | |
569 memcpy(hdr.packet,((unsigned char*)sh_audio->wf)+2*sizeof(WAVEFORMATEX)+3*sizeof(uint32_t)+hdrsizes[0]+hdrsizes[1],hdr.bytes); | |
570 if(vorbis_synthesis_headerin(&sh_audio->ov->vi,&sh_audio->ov->vc,&hdr)<0) | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
571 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"OggVorbis: codebook header broken!\n"); |
1828 | 572 hdr.bytes=0; |
573 hdr.packet = realloc(hdr.packet,hdr.bytes); /* free */ | |
574 /* done with the headers */ | |
575 | |
576 | |
577 /* Throw the comments plus a few lines about the bitstream we're | |
578 decoding */ | |
579 { | |
580 char **ptr=sh_audio->ov->vc.user_comments; | |
581 while(*ptr){ | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
582 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbisComment: %s\n",*ptr); |
1828 | 583 ++ptr; |
584 } | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
585 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Bitstream is %d channel, %ldHz, %ldkbit/s %cBR\n",sh_audio->ov->vi.channels,sh_audio->ov->vi.rate,sh_audio->ov->vi.bitrate_nominal/1000, (sh_audio->ov->vi.bitrate_lower!=sh_audio->ov->vi.bitrate_nominal)||(sh_audio->ov->vi.bitrate_upper!=sh_audio->ov->vi.bitrate_nominal)?'V':'C'); |
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
586 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Encoded by: %s\n",sh_audio->ov->vc.vendor); |
1828 | 587 } |
588 sh_audio->channels=sh_audio->ov->vi.channels; | |
589 sh_audio->samplerate=sh_audio->ov->vi.rate; | |
590 sh_audio->i_bps=sh_audio->ov->vi.bitrate_nominal/8; | |
591 | |
592 // printf("[\n"); | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
593 // sh_audio->a_buffer_len=sh_audio->audio_out_minsize;///ov->vi.channels; |
1828 | 594 // printf("]\n"); |
595 | |
596 /* OK, got and parsed all three headers. Initialize the Vorbis | |
597 packet->PCM decoder. */ | |
598 vorbis_synthesis_init(&sh_audio->ov->vd,&sh_audio->ov->vi); /* central decode state */ | |
599 vorbis_block_init(&sh_audio->ov->vd,&sh_audio->ov->vb); /* local state for most of the decode | |
600 so multiple block decodes can | |
601 proceed in parallel. We could init | |
602 multiple vorbis_block structures | |
603 for vd here */ | |
604 //printf("OggVorbis: synthesis and block init done.\n"); | |
605 ogg_sync_init(&sh_audio->ov->oy); /* Now we can read pages */ | |
606 | |
607 while((ret = ogg_sync_pageout(&sh_audio->ov->oy,&sh_audio->ov->og))!=1) { | |
608 if(ret == -1) | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
609 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"OggVorbis: Pageout: not properly synced, had to skip some bytes.\n"); |
1828 | 610 else |
611 if(ret == 0) { | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
612 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Pageout: need more data to verify page, reading more data.\n"); |
1828 | 613 /* submit a a_buffer_len block to libvorbis' Ogg layer */ |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
614 buffer=ogg_sync_buffer(&sh_audio->ov->oy,256); |
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
615 ogg_sync_wrote(&sh_audio->ov->oy,demux_read_data(sh_audio->ds,buffer,256)); |
1828 | 616 } |
617 } | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
618 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Pageout: successfull.\n"); |
1834
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
619 ogg_stream_pagein(&sh_audio->ov->os,&sh_audio->ov->og); /* we can ignore any errors here |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
620 as they'll also become apparent |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
621 at packetout */ |
1828 | 622 |
623 /* Get the serial number and set up the rest of decode. */ | |
624 /* serialno first; use it to set up a logical stream */ | |
625 ogg_stream_init(&sh_audio->ov->os,ogg_page_serialno(&sh_audio->ov->og)); | |
626 | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
627 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Init OK!\n"); |
1828 | 628 |
629 break; | |
630 } | |
631 #endif | |
2415 | 632 |
633 #ifdef USE_LIBMAD | |
634 case AFM_MAD: | |
635 { | |
636 printf(__FILE__ ":%d:mad: initialising\n", __LINE__); | |
637 mad_frame_init(&mad_frame); | |
638 mad_stream_init(&mad_stream); | |
639 | |
640 printf(__FILE__ ":%d:mad: preparing buffer\n", __LINE__); | |
641 mad_prepare_buffer(sh_audio, &mad_stream, sh_audio->a_in_buffer_size); | |
642 mad_stream_buffer(&mad_stream, (unsigned char*)(sh_audio->a_in_buffer), sh_audio->a_in_buffer_len); | |
643 mad_stream_sync(&mad_stream); | |
644 mad_synth_init(&mad_synth); | |
645 | |
646 if(mad_frame_decode(&mad_frame, &mad_stream) == 0) | |
647 { | |
648 printf(__FILE__ ":%d:mad: post processing buffer\n", __LINE__); | |
649 mad_postprocess_buffer(sh_audio, &mad_stream); | |
650 } | |
651 else | |
652 { | |
653 printf(__FILE__ ":%d:mad: frame decoding failed\n", __LINE__); | |
654 } | |
655 | |
2434
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
656 switch (mad_frame.header.mode) |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
657 { |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
658 case MAD_MODE_SINGLE_CHANNEL: |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
659 sh_audio->channels=1; |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
660 break; |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
661 case MAD_MODE_DUAL_CHANNEL: |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
662 case MAD_MODE_JOINT_STEREO: |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
663 case MAD_MODE_STEREO: |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
664 sh_audio->channels=2; |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
665 break; |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
666 default: |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
667 mp_msg(MSGT_DECAUDIO, MSGL_FATAL, "mad: unknown number of channels\n"); |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
668 } |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
669 mp_msg(MSGT_DECAUDIO, MSGL_HINT, "mad: channels: %d (mad channel mode: %d)\n", |
571538d73e08
audio channels nr is identified from libmad's channel mode
alex
parents:
2432
diff
changeset
|
670 sh_audio->channels, mad_frame.header.mode); |
2432 | 671 /* var. name changed in 0.13.0 (beta) (libmad/CHANGES) -- alex */ |
672 #if (MAD_VERSION_MAJOR >= 0) && (MAD_VERSION_MINOR >= 13) | |
673 sh_audio->samplerate=mad_frame.header.samplerate; | |
674 #else | |
2415 | 675 sh_audio->samplerate=mad_frame.header.sfreq; |
2432 | 676 #endif |
2415 | 677 sh_audio->i_bps=mad_frame.header.bitrate; |
678 printf(__FILE__ ":%d:mad: continuing\n", __LINE__); | |
679 break; | |
680 } | |
681 #endif | |
296 | 682 } |
683 | |
684 if(!sh_audio->channels || !sh_audio->samplerate){ | |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
685 mp_msg(MSGT_DECAUDIO,MSGL_WARN,MSGTR_UnknownAudio); |
303 | 686 driver=0; |
296 | 687 } |
688 | |
303 | 689 if(!driver){ |
690 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
|
691 sh_audio->a_buffer=NULL; |
303 | 692 return 0; |
693 } | |
296 | 694 |
1529 | 695 if(!sh_audio->o_bps) |
303 | 696 sh_audio->o_bps=sh_audio->channels*sh_audio->samplerate*sh_audio->samplesize; |
697 return driver; | |
296 | 698 } |
291 | 699 |
746 | 700 // Audio decoding: |
291 | 701 |
746 | 702 // Decode a single frame (mp3,acm etc) or 'minlen' bytes (pcm/alaw etc) |
703 // buffer length is 'maxlen' bytes, it shouldn't be exceeded... | |
704 | |
705 int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen){ | |
291 | 706 int len=-1; |
303 | 707 switch(sh_audio->codec->driver){ |
1927 | 708 #ifdef USE_LIBAVCODEC |
709 case AFM_FFMPEG: { | |
710 unsigned char *start=NULL; | |
711 int y; | |
712 while(len<minlen){ | |
713 int len2=0; | |
714 int x=ds_get_packet(sh_audio->ds,&start); | |
715 if(x<=0) break; // error | |
2049
df41903fd7d7
VfW stuff moved to dll_init, warnings fixed, using dll_init.h
arpi
parents:
1973
diff
changeset
|
716 y=avcodec_decode_audio(&lavc_context,(INT16*)buf,&len2,start,x); |
1973
5216f108cb4f
all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents:
1927
diff
changeset
|
717 if(y<0){ mp_msg(MSGT_DECAUDIO,MSGL_V,"lavc_audio: error\n");break; } |
1927 | 718 if(y<x) sh_audio->ds->buffer_pos+=y-x; // put back data (HACK!) |
719 if(len2>0){ | |
720 //len=len2;break; | |
721 if(len<0) len=len2; else len+=len2; | |
722 buf+=len2; | |
723 } | |
724 mp_dbg(MSGT_DECAUDIO,MSGL_DBG2,"Decoded %d -> %d \n",y,len2); | |
725 } | |
726 } | |
727 break; | |
728 #endif | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
729 case AFM_MPEG: // MPEG layer 2 or 3 |
291 | 730 len=MP3_DecodeFrame(buf,-1); |
1485
b895f95e7657
AVI demuxer cleanups, fileformat-dependent stuff moved to priv_t
arpi
parents:
1456
diff
changeset
|
731 // len=MP3_DecodeFrame(buf,3); |
291 | 732 break; |
1830 | 733 #ifdef HAVE_OGGVORBIS |
1828 | 734 case AFM_VORBIS: { // OggVorbis |
735 /* note: good minlen would be 4k or 8k IMHO - atmos */ | |
736 int ret; | |
737 char *buffer; | |
738 int bytes; | |
739 int samples; | |
740 float **pcm; | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
741 //ogg_int16_t convbuffer[4096]; |
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
742 // int convsize; |
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
743 int readlen=1024; |
1834
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
744 len=0; |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
745 // convsize=minlen/sh_audio->ov->vi.channels; |
1834
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
746 |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
747 while(len < minlen) { /* double loop allows for break in inner loop */ |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
748 while(len < minlen) { /* without aborting the outer loop - atmos */ |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
749 ret=ogg_stream_packetout(&sh_audio->ov->os,&sh_audio->ov->op); |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
750 if(ret==0) { |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
751 int xxx=0; |
1834
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
752 //printf("OggVorbis: Packetout: need more data, paging!\n"); |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
753 while((ret = ogg_sync_pageout(&sh_audio->ov->oy,&sh_audio->ov->og))!=1) { |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
754 if(ret == -1) |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
755 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Pageout: not properly synced, had to skip some bytes.\n"); |
1834
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
756 else |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
757 if(ret == 0) { |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
758 //printf("OggVorbis: Pageout: need more data to verify page, reading more data.\n"); |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
759 /* submit a readlen k block to libvorbis' Ogg layer */ |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
760 buffer=ogg_sync_buffer(&sh_audio->ov->oy,readlen); |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
761 bytes=demux_read_data(sh_audio->ds,buffer,readlen); |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
762 xxx+=bytes; |
1834
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
763 ogg_sync_wrote(&sh_audio->ov->oy,bytes); |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
764 if(bytes==0) |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
765 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: 0Bytes written, possible End of Stream\n"); |
1834
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
766 } |
1828 | 767 } |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
768 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"\n[sync: %d ]\n",xxx); |
1834
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
769 //printf("OggVorbis: Pageout: successfull, pagin in.\n"); |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
770 if(ogg_stream_pagein(&sh_audio->ov->os,&sh_audio->ov->og)<0) |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
771 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Pagein failed!\n"); |
1834
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
772 break; |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
773 } else if(ret<0) { |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
774 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: Packetout: missing or corrupt data, skipping packet!\n"); |
1834
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
775 break; |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
776 } else { |
1828 | 777 |
778 /* we have a packet. Decode it */ | |
779 | |
780 if(vorbis_synthesis(&sh_audio->ov->vb,&sh_audio->ov->op)==0) /* test for success! */ | |
781 vorbis_synthesis_blockin(&sh_audio->ov->vd,&sh_audio->ov->vb); | |
782 | |
783 /* **pcm is a multichannel float vector. In stereo, for | |
784 example, pcm[0] is left, and pcm[1] is right. samples is | |
785 the size of each channel. Convert the float values | |
786 (-1.<=range<=1.) to whatever PCM format and write it out */ | |
787 | |
788 while((samples=vorbis_synthesis_pcmout(&sh_audio->ov->vd,&pcm))>0){ | |
789 int i,j; | |
790 int clipflag=0; | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
791 int convsize=(maxlen-len)/(2*sh_audio->ov->vi.channels); // max size! |
1828 | 792 int bout=(samples<convsize?samples:convsize); |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
793 |
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
794 if(bout<=0) break; |
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
795 |
1828 | 796 /* convert floats to 16 bit signed ints (host order) and |
797 interleave */ | |
798 for(i=0;i<sh_audio->ov->vi.channels;i++){ | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
799 ogg_int16_t *convbuffer=(ogg_int16_t *)(&buf[len]); |
1828 | 800 ogg_int16_t *ptr=convbuffer+i; |
801 float *mono=pcm[i]; | |
802 for(j=0;j<bout;j++){ | |
803 #if 1 | |
804 int val=mono[j]*32767.f; | |
805 #else /* optional dither */ | |
806 int val=mono[j]*32767.f+drand48()-0.5f; | |
807 #endif | |
808 /* might as well guard against clipping */ | |
809 if(val>32767){ | |
810 val=32767; | |
811 clipflag=1; | |
812 } | |
813 if(val<-32768){ | |
814 val=-32768; | |
815 clipflag=1; | |
816 } | |
817 *ptr=val; | |
818 ptr+=sh_audio->ov->vi.channels; | |
819 } | |
820 } | |
821 | |
822 if(clipflag) | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
823 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"Clipping in frame %ld\n",(long)(sh_audio->ov->vd.sequence)); |
1828 | 824 |
825 //fwrite(convbuffer,2*sh_audio->ov->vi.channels,bout,stderr); //dump pcm to file for debugging | |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
826 //memcpy(buf+len,convbuffer,2*sh_audio->ov->vi.channels*bout); |
1834
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
827 len+=2*sh_audio->ov->vi.channels*bout; |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
828 |
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
829 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"\n[decoded: %d / %d ]\n",bout,samples); |
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
830 |
1828 | 831 vorbis_synthesis_read(&sh_audio->ov->vd,bout); /* tell libvorbis how |
832 many samples we | |
833 actually consumed */ | |
834 } | |
1834
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
835 } // from else, packetout ok |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
836 } // while len |
3f8da9408f04
Now oggvorbis decoding properly works, but a/v sync is bad.
atmos4
parents:
1831
diff
changeset
|
837 } // outer while len |
1828 | 838 if(ogg_page_eos(&sh_audio->ov->og)) |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
839 mp_msg(MSGT_DECAUDIO,MSGL_V,"OggVorbis: End of Stream reached!\n"); // FIXME clearup decoder, notify mplayer - atmos |
1828 | 840 |
1837
9fd8b5e0b864
ogg/vorbis stuff cleanup, buffering fixes, printf->mp_msg
arpi
parents:
1834
diff
changeset
|
841 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"\n[len: %d ]\n",len); |
1828 | 842 |
843 break; | |
1831 | 844 } |
1830 | 845 #endif |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
846 case AFM_PCM: // AVI PCM |
1058 | 847 len=demux_read_data(sh_audio->ds,buf,minlen); |
401 | 848 break; |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
849 case AFM_DVDPCM: // DVD PCM |
401 | 850 { int j; |
746 | 851 len=demux_read_data(sh_audio->ds,buf,minlen); |
291 | 852 //if(i&1){ printf("Warning! pcm_audio_size&1 !=0 (%d)\n",i);i&=~1; } |
746 | 853 // swap endian: |
291 | 854 for(j=0;j<len;j+=2){ |
855 char x=buf[j]; | |
856 buf[j]=buf[j+1]; | |
857 buf[j+1]=x; | |
858 } | |
859 break; | |
860 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
861 case AFM_ALAW: // aLaw decoder |
746 | 862 { int l=demux_read_data(sh_audio->ds,buf,minlen/2); |
291 | 863 unsigned short *d=(unsigned short *) buf; |
864 unsigned char *s=buf; | |
865 len=2*l; | |
758 | 866 if(sh_audio->format==6){ |
867 // aLaw | |
883 | 868 while(l>0){ --l; d[l]=alaw2short[s[l]]; } |
758 | 869 } else { |
870 // uLaw | |
883 | 871 while(l>0){ --l; d[l]=ulaw2short[s[l]]; } |
291 | 872 } |
873 break; | |
874 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
875 case AFM_GSM: // MS-GSM decoder |
2420 | 876 { unsigned char ibuf[65]; // 65 bytes / frame |
877 if(demux_read_data(sh_audio->ds,ibuf,65)!=65) break; // EOF | |
878 XA_MSGSM_Decoder(ibuf,(unsigned short *) buf); // decodes 65 byte -> 320 short | |
746 | 879 // XA_GSM_Decoder(buf,(unsigned short *) &sh_audio->a_buffer[sh_audio->a_buffer_len]); // decodes 33 byte -> 160 short |
880 len=2*320; | |
291 | 881 break; |
882 } | |
2420 | 883 case AFM_IMA4: // IMA-ADPCM 4:1 audio codec: |
884 { unsigned char ibuf[IMA4_BLOCK_SIZE]; // bytes / frame | |
885 if(demux_read_data(sh_audio->ds,ibuf,IMA4_BLOCK_SIZE)!=IMA4_BLOCK_SIZE) break; // EOF | |
2424 | 886 len=2*ima4_decode_block((unsigned short*)buf,ibuf,2*IMA4_SAMPLES_PER_BLOCK); |
2420 | 887 break; |
888 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
889 case AFM_AC3: // AC3 decoder |
291 | 890 //printf("{1:%d}",avi_header.idx_pos);fflush(stdout); |
891 if(!sh_audio->ac3_frame) sh_audio->ac3_frame=ac3_decode_frame(); | |
892 //printf("{2:%d}",avi_header.idx_pos);fflush(stdout); | |
893 if(sh_audio->ac3_frame){ | |
296 | 894 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
|
895 memcpy(buf,((ac3_frame_t*)sh_audio->ac3_frame)->audio_data,len); |
291 | 896 sh_audio->ac3_frame=NULL; |
897 } | |
898 //printf("{3:%d}",avi_header.idx_pos);fflush(stdout); | |
899 break; | |
3413 | 900 case AFM_A52: { // AC3 decoder |
901 int flags=0; | |
902 int i; | |
903 sample_t level=1, bias=384; | |
904 if(!sh_audio->a_in_buffer_len) | |
905 if(a52_fillbuff(sh_audio)<0) break; // EOF | |
906 switch(sh_audio->channels){ | |
907 case 1: flags=A52_MONO; break; | |
908 // case 2: flags=A52_STEREO; break; | |
909 case 2: flags=A52_DOLBY; break; | |
910 // case 3: flags=A52_3F; break; | |
911 case 3: flags=A52_2F1R; break; | |
912 case 4: flags=A52_2F2R; break; // 2+2 | |
913 case 5: flags=A52_3F2R; break; | |
914 case 6: flags=A52_3F2R|A52_LFE; break; // 5.1 | |
915 } | |
916 flags|=A52_ADJUST_LEVEL; | |
917 sh_audio->a_in_buffer_len=0; | |
918 if (a52_frame (&a52_state, sh_audio->a_in_buffer, &flags, &level, bias)){ | |
919 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"a52: error decoding frame\n"); | |
920 break; | |
921 } | |
922 // a52_dynrng (&state, NULL, NULL); // disable dynamic range compensation | |
923 | |
924 // frame decoded, let's resample: | |
925 a52_resample_init(flags,sh_audio->channels); | |
926 len=0; | |
927 for (i = 0; i < 6; i++) { | |
928 if (a52_block (&a52_state, a52_samples)){ | |
929 mp_msg(MSGT_DECAUDIO,MSGL_WARN,"a52: error at resampling\n"); | |
930 break; | |
931 } | |
932 len+=2*a52_resample(a52_samples,&buf[len]); | |
933 } | |
934 printf("len = %d \n",len); | |
935 break; | |
936 } | |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
937 case AFM_HWAC3: // AC3 through SPDIF |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
938 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
|
939 break; //EOF |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
940 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
|
941 len = 6144; |
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
942 break; |
1517
0e9c29538a86
Use USE_WIN32DLL define instead of ARCH_X86 to decide whether or not to compile
jkeil
parents:
1485
diff
changeset
|
943 #ifdef USE_WIN32DLL |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
944 case AFM_ACM: |
758 | 945 // len=sh_audio->audio_out_minsize; // optimal decoded fragment size |
946 // if(len<minlen) len=minlen; else | |
947 // if(len>maxlen) len=maxlen; | |
948 // len=acm_decode_audio(sh_audio,buf,len); | |
949 len=acm_decode_audio(sh_audio,buf,minlen,maxlen); | |
291 | 950 break; |
1309
598e3047ce13
Add some preliminary support for non-x86 architectures to mplayer
jkeil
parents:
1291
diff
changeset
|
951 #endif |
746 | 952 |
291 | 953 #ifdef USE_DIRECTSHOW |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
954 case AFM_DSHOW: // DirectShow |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
955 { int size_in=0; |
291 | 956 int size_out=0; |
957 int srcsize=DS_AudioDecoder_GetSrcSize(maxlen); | |
1567 | 958 mp_msg(MSGT_DECAUDIO,MSGL_DBG3,"DShow says: srcsize=%d (buffsize=%d) out_size=%d\n",srcsize,sh_audio->a_in_buffer_size,maxlen); |
291 | 959 if(srcsize>sh_audio->a_in_buffer_size) srcsize=sh_audio->a_in_buffer_size; // !!!!!! |
960 if(sh_audio->a_in_buffer_len<srcsize){ | |
961 sh_audio->a_in_buffer_len+= | |
962 demux_read_data(sh_audio->ds,&sh_audio->a_in_buffer[sh_audio->a_in_buffer_len], | |
963 srcsize-sh_audio->a_in_buffer_len); | |
964 } | |
965 DS_AudioDecoder_Convert(sh_audio->a_in_buffer,sh_audio->a_in_buffer_len, | |
966 buf,maxlen, &size_in,&size_out); | |
1567 | 967 mp_dbg(MSGT_DECAUDIO,MSGL_DBG2,"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 | 968 if(size_in>=sh_audio->a_in_buffer_len){ |
969 sh_audio->a_in_buffer_len=0; | |
970 } else { | |
971 sh_audio->a_in_buffer_len-=size_in; | |
972 memcpy(sh_audio->a_in_buffer,&sh_audio->a_in_buffer[size_in],sh_audio->a_in_buffer_len); | |
973 } | |
974 len=size_out; | |
975 break; | |
976 } | |
977 #endif | |
2415 | 978 |
979 #ifdef USE_LIBMAD | |
980 case AFM_MAD: | |
981 { | |
982 mad_prepare_buffer(sh_audio, &mad_stream, sh_audio->a_in_buffer_size); | |
983 mad_stream_buffer(&mad_stream, sh_audio->a_in_buffer, sh_audio->a_in_buffer_len); | |
984 if(mad_frame_decode(&mad_frame, &mad_stream) == 0) | |
985 { | |
986 mad_synth_frame(&mad_synth, &mad_frame); | |
987 mad_postprocess_buffer(sh_audio, &mad_stream); | |
988 | |
989 /* and fill buffer */ | |
990 | |
991 { | |
992 int i; | |
993 int end_size = mad_synth.pcm.length; | |
994 signed short* samples = (signed short*)buf; | |
995 if(end_size > maxlen/4) | |
996 end_size=maxlen/4; | |
997 | |
998 for(i=0; i<mad_synth.pcm.length; ++i) { | |
999 *samples++ = mad_scale(mad_synth.pcm.samples[0][i]); | |
1000 *samples++ = mad_scale(mad_synth.pcm.samples[0][i]); | |
1001 // *buf++ = mad_scale(mad_synth.pcm.sampAles[1][i]); | |
1002 } | |
1003 len = end_size*4; | |
1004 } | |
1005 } | |
1006 else | |
1007 { | |
1008 printf(__FILE__ ":%d:mad: frame decoding failed\n", __LINE__); | |
1009 } | |
1010 | |
1011 break; | |
1012 } | |
1013 #endif | |
291 | 1014 } |
1015 return len; | |
1016 } | |
1017 | |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1018 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
|
1019 switch(sh_audio->codec->driver){ |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1020 case AFM_MPEG: |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1021 MP3_DecodeFrame(NULL,-2); // resync |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1022 MP3_DecodeFrame(NULL,-2); // resync |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1023 MP3_DecodeFrame(NULL,-2); // resync |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1024 break; |
1849
5f246fcc2971
Resetting stream and sync for seek, no correct test files yet for proper testing but should be ok.
atmos4
parents:
1837
diff
changeset
|
1025 #ifdef HAVE_OGGVORBIS |
5f246fcc2971
Resetting stream and sync for seek, no correct test files yet for proper testing but should be ok.
atmos4
parents:
1837
diff
changeset
|
1026 case AFM_VORBIS: |
5f246fcc2971
Resetting stream and sync for seek, no correct test files yet for proper testing but should be ok.
atmos4
parents:
1837
diff
changeset
|
1027 //printf("OggVorbis: resetting stream.\n"); |
5f246fcc2971
Resetting stream and sync for seek, no correct test files yet for proper testing but should be ok.
atmos4
parents:
1837
diff
changeset
|
1028 ogg_sync_reset(&sh_audio->ov->oy); |
5f246fcc2971
Resetting stream and sync for seek, no correct test files yet for proper testing but should be ok.
atmos4
parents:
1837
diff
changeset
|
1029 ogg_stream_reset(&sh_audio->ov->os); |
5f246fcc2971
Resetting stream and sync for seek, no correct test files yet for proper testing but should be ok.
atmos4
parents:
1837
diff
changeset
|
1030 break; |
5f246fcc2971
Resetting stream and sync for seek, no correct test files yet for proper testing but should be ok.
atmos4
parents:
1837
diff
changeset
|
1031 #endif |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1032 case AFM_AC3: |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1033 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
|
1034 // 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
|
1035 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
|
1036 // if(verbose) printf(" OK!\n"); |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1037 break; |
3413 | 1038 case AFM_A52: |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1039 case AFM_ACM: |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1040 case AFM_DSHOW: |
1528
a444bd456fcc
ac3/spdif patch by German Gomez Garcia <german@piraos.com>
arpi
parents:
1517
diff
changeset
|
1041 case AFM_HWAC3: |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1042 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
|
1043 break; |
2415 | 1044 |
1045 #ifdef USE_LIBMAD | |
1046 case AFM_MAD: | |
1047 mad_prepare_buffer(sh_audio, &mad_stream, sh_audio->a_in_buffer_size); | |
1048 mad_stream_buffer(&mad_stream, sh_audio->a_in_buffer, sh_audio->a_in_buffer_len); | |
1049 mad_stream_sync(&mad_stream); | |
1050 mad_postprocess_buffer(sh_audio, &mad_stream); | |
1051 break; | |
2418 | 1052 #endif |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1053 } |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1054 } |
291 | 1055 |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1056 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
|
1057 switch(sh_audio->codec->driver){ |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1058 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
|
1059 case AFM_AC3: sh_audio->ac3_frame=ac3_decode_frame();break; // skip AC3 frame |
3413 | 1060 case AFM_A52: a52_fillbuff(sh_audio);break; // skip AC3 frame |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1061 case AFM_ACM: |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1062 case AFM_DSHOW: { |
1408 | 1063 int skip=sh_audio->wf->nBlockAlign; |
1064 if(skip<16){ | |
1065 skip=(sh_audio->wf->nAvgBytesPerSec/16)&(~7); | |
1066 if(skip<16) skip=16; | |
1067 } | |
1068 demux_read_data(sh_audio->ds,NULL,skip); | |
1069 break; | |
1070 } | |
1410
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1071 case AFM_PCM: |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1072 case AFM_DVDPCM: |
eda16e490ae7
using AFM_/VFM_ macros instead of hardcoded constants (idea by al3x)
arpi
parents:
1408
diff
changeset
|
1073 case AFM_ALAW: { |
1408 | 1074 int skip=sh_audio->i_bps/16; |
1075 skip=skip&(~3); | |
1076 demux_read_data(sh_audio->ds,NULL,skip); | |
1077 break; | |
1078 } | |
2415 | 1079 #ifdef USE_LIBMAD |
1080 case AFM_MAD: | |
1081 { | |
1082 mad_prepare_buffer(sh_audio, &mad_stream, sh_audio->a_in_buffer_size); | |
1083 mad_stream_buffer(&mad_stream, sh_audio->a_in_buffer, sh_audio->a_in_buffer_len); | |
1084 mad_stream_skip(&mad_stream, 2); | |
1085 mad_stream_sync(&mad_stream); | |
1086 mad_postprocess_buffer(sh_audio, &mad_stream); | |
1087 break; | |
1088 } | |
1089 #endif | |
1090 | |
1327
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1091 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
|
1092 } |
b12e1817bcc2
some cleanup - fixed warnings, removed old stuff, moved audio resync to dec_audio
arpi
parents:
1320
diff
changeset
|
1093 } |