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