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