Mercurial > mplayer.hg
annotate libmpcodecs/ad_qtaudio.c @ 12313:2c43227bde12
spelling, additions, slight reordering
author | diego |
---|---|
date | Tue, 27 Apr 2004 01:42:10 +0000 |
parents | 574f7747d26f |
children | 6a61d694f7d3 |
rev | line source |
---|---|
8008 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <unistd.h> | |
4 #include <inttypes.h> | |
5 | |
6 #include "config.h" | |
12193 | 7 #include "../mp_msg.h" |
8008 | 8 |
9502
241bba8f60e8
MACOSX support patch, based on Dan Christiansens work
alex
parents:
9405
diff
changeset
|
9 #if defined(USE_QTX_CODECS) || defined(MACOSX) |
8008 | 10 |
11 #include "ad_internal.h" | |
12 #include "bswap.h" | |
13 | |
9405
a4444e7ee56a
real cygwin support by Sascha Sommer <saschasommer@freenet.de>
alex
parents:
8632
diff
changeset
|
14 #ifdef WIN32_LOADER |
8451 | 15 #include "ldt_keeper.h" |
16 #endif | |
17 | |
9502
241bba8f60e8
MACOSX support patch, based on Dan Christiansens work
alex
parents:
9405
diff
changeset
|
18 #ifdef MACOSX |
241bba8f60e8
MACOSX support patch, based on Dan Christiansens work
alex
parents:
9405
diff
changeset
|
19 #include <QuickTime/QuickTimeComponents.h> |
241bba8f60e8
MACOSX support patch, based on Dan Christiansens work
alex
parents:
9405
diff
changeset
|
20 #endif |
241bba8f60e8
MACOSX support patch, based on Dan Christiansens work
alex
parents:
9405
diff
changeset
|
21 |
8008 | 22 static ad_info_t info = { |
23 "QuickTime Audio Decoder", | |
24 "qtaudio", | |
25 "A'rpi", | |
26 "Sascha Sommer", | |
27 "uses win32 quicktime DLLs" | |
28 }; | |
29 | |
30 LIBAD_EXTERN(qtaudio) | |
31 | |
9502
241bba8f60e8
MACOSX support patch, based on Dan Christiansens work
alex
parents:
9405
diff
changeset
|
32 #ifdef USE_QTX_CODECS |
8008 | 33 typedef struct OpaqueSoundConverter* SoundConverter; |
34 typedef unsigned long OSType; | |
35 typedef unsigned long UnsignedFixed; | |
36 typedef uint8_t Byte; | |
37 typedef struct SoundComponentData { | |
38 long flags; | |
39 OSType format; | |
40 short numChannels; | |
41 short sampleSize; | |
42 UnsignedFixed sampleRate; | |
43 long sampleCount; | |
44 Byte * buffer; | |
45 long reserved; | |
46 }SoundComponentData; | |
47 | |
48 typedef int (__cdecl* LPFUNC1)(long flag); | |
49 typedef int (__cdecl* LPFUNC2)(const SoundComponentData *, const SoundComponentData *,SoundConverter *); | |
50 typedef int (__cdecl* LPFUNC3)(SoundConverter sc); | |
51 typedef int (__cdecl* LPFUNC4)(void); | |
52 typedef int (__cdecl* LPFUNC5)(SoundConverter sc, OSType selector,void * infoPtr); | |
53 typedef int (__cdecl* LPFUNC6)(SoundConverter sc, | |
54 unsigned long inputBytesTarget, | |
55 unsigned long *inputFrames, | |
56 unsigned long *inputBytes, | |
57 unsigned long *outputBytes ); | |
58 typedef int (__cdecl* LPFUNC7)(SoundConverter sc, | |
59 const void *inputPtr, | |
60 unsigned long inputFrames, | |
61 void *outputPtr, | |
62 unsigned long *outputFrames, | |
63 unsigned long *outputBytes ); | |
64 typedef int (__cdecl* LPFUNC8)(SoundConverter sc, | |
65 void *outputPtr, | |
66 unsigned long *outputFrames, | |
67 unsigned long *outputBytes); | |
68 typedef int (__cdecl* LPFUNC9)(SoundConverter sc) ; | |
69 | |
70 static HINSTANCE qtml_dll; | |
71 static LPFUNC1 InitializeQTML; | |
72 static LPFUNC2 SoundConverterOpen; | |
73 static LPFUNC3 SoundConverterClose; | |
74 static LPFUNC4 TerminateQTML; | |
75 static LPFUNC5 SoundConverterSetInfo; | |
76 static LPFUNC6 SoundConverterGetBufferSizes; | |
77 static LPFUNC7 SoundConverterConvertBuffer; | |
78 static LPFUNC8 SoundConverterEndConversion; | |
79 static LPFUNC9 SoundConverterBeginConversion; | |
80 | |
81 #define siDecompressionParams 2002876005 // siDecompressionParams = FOUR_CHAR_CODE('wave') | |
82 | |
83 HMODULE WINAPI LoadLibraryA(LPCSTR); | |
84 FARPROC WINAPI GetProcAddress(HMODULE,LPCSTR); | |
85 int WINAPI FreeLibrary(HMODULE); | |
86 | |
87 static int loader_init() | |
88 { | |
89 | |
9405
a4444e7ee56a
real cygwin support by Sascha Sommer <saschasommer@freenet.de>
alex
parents:
8632
diff
changeset
|
90 #ifdef WIN32_LOADER |
8270 | 91 Setup_LDT_Keeper(); |
92 #endif | |
8008 | 93 qtml_dll = LoadLibraryA("qtmlClient.dll"); |
94 if( qtml_dll == NULL ) | |
95 { | |
12193 | 96 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"failed loading dll\n" ); |
8008 | 97 return 1; |
98 } | |
99 #if 1 | |
100 InitializeQTML = (LPFUNC1)GetProcAddress(qtml_dll,"InitializeQTML"); | |
101 if ( InitializeQTML == NULL ) | |
102 { | |
12193 | 103 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"failed geting proc address InitializeQTML\n"); |
8008 | 104 return 1; |
105 } | |
106 SoundConverterOpen = (LPFUNC2)GetProcAddress(qtml_dll,"SoundConverterOpen"); | |
107 if ( SoundConverterOpen == NULL ) | |
108 { | |
12193 | 109 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"failed getting proc address SoundConverterOpen\n"); |
8008 | 110 return 1; |
111 } | |
112 SoundConverterClose = (LPFUNC3)GetProcAddress(qtml_dll,"SoundConverterClose"); | |
113 if ( SoundConverterClose == NULL ) | |
114 { | |
12193 | 115 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"failed getting proc address SoundConverterClose\n"); |
8008 | 116 return 1; |
117 } | |
118 TerminateQTML = (LPFUNC4)GetProcAddress(qtml_dll,"TerminateQTML"); | |
119 if ( TerminateQTML == NULL ) | |
120 { | |
12193 | 121 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"failed getting proc address TerminateQTML\n"); |
8008 | 122 return 1; |
123 } | |
124 SoundConverterSetInfo = (LPFUNC5)GetProcAddress(qtml_dll,"SoundConverterSetInfo"); | |
125 if ( SoundConverterSetInfo == NULL ) | |
126 { | |
12193 | 127 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"failed getting proc address SoundConverterSetInfo\n"); |
8008 | 128 return 1; |
129 } | |
130 SoundConverterGetBufferSizes = (LPFUNC6)GetProcAddress(qtml_dll,"SoundConverterGetBufferSizes"); | |
131 if ( SoundConverterGetBufferSizes == NULL ) | |
132 { | |
12193 | 133 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"failed getting proc address SoundConverterGetBufferSizes\n"); |
8008 | 134 return 1; |
135 } | |
136 SoundConverterConvertBuffer = (LPFUNC7)GetProcAddress(qtml_dll,"SoundConverterConvertBuffer"); | |
137 if ( SoundConverterConvertBuffer == NULL ) | |
138 { | |
12193 | 139 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"failed getting proc address SoundConverterConvertBuffer1\n"); |
8008 | 140 return 1; |
141 } | |
142 SoundConverterEndConversion = (LPFUNC8)GetProcAddress(qtml_dll,"SoundConverterEndConversion"); | |
143 if ( SoundConverterEndConversion == NULL ) | |
144 { | |
12193 | 145 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"failed getting proc address SoundConverterEndConversion\n"); |
8008 | 146 return 1; |
147 } | |
148 SoundConverterBeginConversion = (LPFUNC9)GetProcAddress(qtml_dll,"SoundConverterBeginConversion"); | |
149 if ( SoundConverterBeginConversion == NULL ) | |
150 { | |
12193 | 151 mp_msg(MSGT_DECAUDIO,MSGL_ERR,"failed getting proc address SoundConverterBeginConversion\n"); |
8008 | 152 return 1; |
153 } | |
154 #endif | |
12193 | 155 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"loader_init DONE???\n"); |
8008 | 156 return 0; |
157 } | |
9502
241bba8f60e8
MACOSX support patch, based on Dan Christiansens work
alex
parents:
9405
diff
changeset
|
158 #endif /* USE_QTX_CODECS */ |
8008 | 159 |
160 static SoundConverter myConverter = NULL; | |
161 static SoundComponentData InputFormatInfo,OutputFormatInfo; | |
162 | |
163 static int InFrameSize; | |
164 static int OutFrameSize; | |
165 | |
166 static int preinit(sh_audio_t *sh){ | |
167 int error; | |
168 unsigned long FramesToGet=0; //how many frames the demuxer has to get | |
169 unsigned long InputBufferSize=0; //size of the input buffer | |
170 unsigned long OutputBufferSize=0; //size of the output buffer | |
171 unsigned long WantedBufferSize=0; //the size you want your buffers to be | |
172 | |
173 | |
9502
241bba8f60e8
MACOSX support patch, based on Dan Christiansens work
alex
parents:
9405
diff
changeset
|
174 #ifdef MACOSX |
241bba8f60e8
MACOSX support patch, based on Dan Christiansens work
alex
parents:
9405
diff
changeset
|
175 EnterMovies(); |
241bba8f60e8
MACOSX support patch, based on Dan Christiansens work
alex
parents:
9405
diff
changeset
|
176 #else |
8008 | 177 if(loader_init()) return 0; // failed to load DLL |
178 | |
12193 | 179 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"loader_init DONE!\n"); |
8008 | 180 |
8159 | 181 error = InitializeQTML(6+16); |
12193 | 182 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"InitializeQTML:%i\n",error); |
8008 | 183 if(error) return 0; |
9694 | 184 #endif |
8008 | 185 |
9694 | 186 #if 1 |
8008 | 187 OutputFormatInfo.flags = InputFormatInfo.flags = 0; |
188 OutputFormatInfo.sampleCount = InputFormatInfo.sampleCount = 0; | |
189 OutputFormatInfo.buffer = InputFormatInfo.buffer = NULL; | |
190 OutputFormatInfo.reserved = InputFormatInfo.reserved = 0; | |
191 OutputFormatInfo.numChannels = InputFormatInfo.numChannels = sh->wf->nChannels; | |
8159 | 192 InputFormatInfo.sampleSize = sh->wf->wBitsPerSample; |
193 OutputFormatInfo.sampleSize = 16; | |
8008 | 194 OutputFormatInfo.sampleRate = InputFormatInfo.sampleRate = sh->wf->nSamplesPerSec; |
195 InputFormatInfo.format = bswap_32(sh->format); //1363430706;///*1768775988;//*/1902406962;//qdm2//1768775988;//FOUR_CHAR_CODE('ima4'); | |
196 OutputFormatInfo.format = 1313820229;// FOUR_CHAR_CODE('NONE'); | |
197 | |
198 error = SoundConverterOpen(&InputFormatInfo, &OutputFormatInfo, &myConverter); | |
12193 | 199 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"SoundConverterOpen:%i\n",error); |
8008 | 200 if(error) return 0; |
201 | |
202 if(sh->codecdata){ | |
203 error = SoundConverterSetInfo(myConverter,siDecompressionParams,sh->codecdata); | |
12193 | 204 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"SoundConverterSetInfo:%i\n",error); |
8632
9cecfb883d85
don't abort if setparams failed - fixes some Qclp files
arpi
parents:
8451
diff
changeset
|
205 // if(error) return 0; |
8008 | 206 } |
207 | |
208 WantedBufferSize=OutputFormatInfo.numChannels*OutputFormatInfo.sampleRate*2; | |
209 error = SoundConverterGetBufferSizes(myConverter, | |
210 WantedBufferSize,&FramesToGet,&InputBufferSize,&OutputBufferSize); | |
12193 | 211 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"SoundConverterGetBufferSizes:%i\n",error); |
212 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"WantedBufferSize = %li\n",WantedBufferSize); | |
213 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"InputBufferSize = %li\n",InputBufferSize); | |
214 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"OutputBufferSize = %li\n",OutputBufferSize); | |
215 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"FramesToGet = %li\n",FramesToGet); | |
8008 | 216 |
8389
e8c51ec86340
fixed in/out framesize rounding bug (causing low-rate QCLP hangup/looping)
arpi
parents:
8270
diff
changeset
|
217 InFrameSize=(InputBufferSize+FramesToGet-1)/FramesToGet; |
8008 | 218 OutFrameSize=OutputBufferSize/FramesToGet; |
219 | |
12193 | 220 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"FrameSize: %i -> %i\n",InFrameSize,OutFrameSize); |
8008 | 221 |
222 error = SoundConverterBeginConversion(myConverter); | |
12193 | 223 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"SoundConverterBeginConversion:%i\n",error); |
8008 | 224 if(error) return 0; |
225 | |
226 sh->audio_out_minsize=OutputBufferSize; | |
227 sh->audio_in_minsize=InputBufferSize; | |
228 | |
229 sh->channels=sh->wf->nChannels; | |
230 sh->samplerate=sh->wf->nSamplesPerSec; | |
8159 | 231 sh->samplesize=2; //(sh->wf->wBitsPerSample+7)/8; |
8008 | 232 |
233 sh->i_bps=sh->wf->nAvgBytesPerSec; | |
234 //InputBufferSize*WantedBufferSize/OutputBufferSize; | |
235 | |
236 #endif | |
8159 | 237 |
238 if(sh->format==0x3343414D){ | |
239 // MACE 3:1 | |
240 sh->ds->ss_div = 2*3; // 1 samples/packet | |
241 sh->ds->ss_mul = sh->channels*2*1; // 1 bytes/packet | |
242 } else | |
243 if(sh->format==0x3643414D){ | |
244 // MACE 6:1 | |
245 sh->ds->ss_div = 2*6; // 1 samples/packet | |
246 sh->ds->ss_mul = sh->channels*2*1; // 1 bytes/packet | |
247 } | |
248 | |
8008 | 249 return 1; // return values: 1=OK 0=ERROR |
250 } | |
251 | |
252 static int init(sh_audio_t *sh_audio){ | |
253 | |
254 return 1; // return values: 1=OK 0=ERROR | |
255 } | |
256 | |
257 static void uninit(sh_audio_t *sh){ | |
258 int error; | |
259 unsigned long ConvertedFrames=0; | |
260 unsigned long ConvertedBytes=0; | |
261 error=SoundConverterEndConversion(myConverter,NULL,&ConvertedFrames,&ConvertedBytes); | |
12193 | 262 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"SoundConverterEndConversion:%i\n",error); |
8008 | 263 error = SoundConverterClose(myConverter); |
12193 | 264 mp_msg(MSGT_DECAUDIO,MSGL_DBG2,"SoundConverterClose:%i\n",error); |
8389
e8c51ec86340
fixed in/out framesize rounding bug (causing low-rate QCLP hangup/looping)
arpi
parents:
8270
diff
changeset
|
265 // error = TerminateQTML(); |
e8c51ec86340
fixed in/out framesize rounding bug (causing low-rate QCLP hangup/looping)
arpi
parents:
8270
diff
changeset
|
266 // printf("TerminateQTML:%i\n",error); |
e8c51ec86340
fixed in/out framesize rounding bug (causing low-rate QCLP hangup/looping)
arpi
parents:
8270
diff
changeset
|
267 // FreeLibrary( qtml_dll ); |
e8c51ec86340
fixed in/out framesize rounding bug (causing low-rate QCLP hangup/looping)
arpi
parents:
8270
diff
changeset
|
268 // qtml_dll = NULL; |
e8c51ec86340
fixed in/out framesize rounding bug (causing low-rate QCLP hangup/looping)
arpi
parents:
8270
diff
changeset
|
269 // printf("qt dll loader uninit done\n"); |
9502
241bba8f60e8
MACOSX support patch, based on Dan Christiansens work
alex
parents:
9405
diff
changeset
|
270 #ifdef MACOSX |
241bba8f60e8
MACOSX support patch, based on Dan Christiansens work
alex
parents:
9405
diff
changeset
|
271 ExitMovies(); |
241bba8f60e8
MACOSX support patch, based on Dan Christiansens work
alex
parents:
9405
diff
changeset
|
272 #endif |
8008 | 273 } |
274 | |
275 static int decode_audio(sh_audio_t *sh,unsigned char *buf,int minlen,int maxlen){ | |
276 int error; | |
277 unsigned long FramesToGet=0; //how many frames the demuxer has to get | |
278 unsigned long InputBufferSize=0; //size of the input buffer | |
279 unsigned long ConvertedFrames=0; | |
280 unsigned long ConvertedBytes=0; | |
281 | |
282 FramesToGet=minlen/OutFrameSize; | |
283 if(FramesToGet*OutFrameSize<minlen && | |
284 (FramesToGet+1)*OutFrameSize<=maxlen) ++FramesToGet; | |
285 if(FramesToGet*InFrameSize>sh->a_in_buffer_size) | |
286 FramesToGet=sh->a_in_buffer_size/InFrameSize; | |
287 | |
288 InputBufferSize=FramesToGet*InFrameSize; | |
289 | |
8159 | 290 // printf("FramesToGet = %li (%li -> %li bytes)\n",FramesToGet, |
291 // InputBufferSize, FramesToGet*OutFrameSize); | |
8008 | 292 |
293 if(InputBufferSize>sh->a_in_buffer_len){ | |
294 int x=demux_read_data(sh->ds,&sh->a_in_buffer[sh->a_in_buffer_len], | |
295 InputBufferSize-sh->a_in_buffer_len); | |
296 if(x>0) sh->a_in_buffer_len+=x; | |
297 if(InputBufferSize>sh->a_in_buffer_len) | |
298 FramesToGet=sh->a_in_buffer_len/InFrameSize; // not enough data! | |
299 } | |
300 | |
8159 | 301 // printf("\nSoundConverterConvertBuffer(myConv=%p,inbuf=%p,frames=%d,outbuf=%p,&convframes=%p,&convbytes=%p)\n", |
302 // myConverter,sh->a_in_buffer,FramesToGet,buf,&ConvertedFrames,&ConvertedBytes); | |
8008 | 303 error = SoundConverterConvertBuffer(myConverter,sh->a_in_buffer, |
304 FramesToGet,buf,&ConvertedFrames,&ConvertedBytes); | |
8159 | 305 // printf("SoundConverterConvertBuffer:%i\n",error); |
306 // printf("ConvertedFrames = %li\n",ConvertedFrames); | |
307 // printf("ConvertedBytes = %li\n",ConvertedBytes); | |
8008 | 308 |
8389
e8c51ec86340
fixed in/out framesize rounding bug (causing low-rate QCLP hangup/looping)
arpi
parents:
8270
diff
changeset
|
309 // InputBufferSize=(ConvertedBytes/OutFrameSize)*InFrameSize; // FIXME!! |
e8c51ec86340
fixed in/out framesize rounding bug (causing low-rate QCLP hangup/looping)
arpi
parents:
8270
diff
changeset
|
310 InputBufferSize=FramesToGet*InFrameSize; |
8008 | 311 sh->a_in_buffer_len-=InputBufferSize; |
312 if(sh->a_in_buffer_len<0) sh->a_in_buffer_len=0; // should not happen... | |
313 else if(sh->a_in_buffer_len>0){ | |
314 memcpy(sh->a_in_buffer,&sh->a_in_buffer[InputBufferSize],sh->a_in_buffer_len); | |
315 } | |
316 | |
317 return ConvertedBytes; | |
318 } | |
319 | |
320 static int control(sh_audio_t *sh,int cmd,void* arg, ...){ | |
321 // various optional functions you MAY implement: | |
322 return CONTROL_UNKNOWN; | |
323 } | |
324 | |
325 #endif |