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