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