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