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