Mercurial > mplayer.hg
annotate loader/afl.c @ 3927:b8e0fee75aec
some fixes
author | gabucino |
---|---|
date | Tue, 01 Jan 2002 17:35:09 +0000 |
parents | ce45cce7f7a5 |
children | 174e2a58b4cd |
rev | line source |
---|---|
1 | 1 /************************************************************************** |
2 | |
3 | |
4 This file will contain an interface to ACM drivers. | |
5 Its content will be based mainly on wine/dlls/msacm32 | |
6 actually, for audio decompression only the following functions | |
7 are needed: | |
8 | |
9 acmStreamOpen ( takes formats of src and dest, returns stream handle ) | |
10 acmStreamPrepareHeader ( takes stream handler and info on data ) | |
11 acmStreamConvert ( the same as PrepareHeader ) | |
12 acmStreamUnprepareHeader | |
13 acmStreamClose | |
14 acmStreamSize | |
15 maybe acmStreamReset | |
16 | |
17 In future I'll also add functions for format enumeration, | |
18 but not right now. | |
19 | |
20 | |
21 ***************************************************************************/ | |
2069 | 22 #include "config.h" |
1 | 23 |
24 #include <stdio.h> | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1
diff
changeset
|
25 #include <stdlib.h> |
1 | 26 #include <string.h> |
27 | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1
diff
changeset
|
28 #include "win32.h" |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1
diff
changeset
|
29 |
2069 | 30 #include "wine/winbase.h" |
31 #include "wine/windef.h" | |
32 #include "wine/winuser.h" | |
33 #include "wine/vfw.h" | |
34 #include "wine/winestring.h" | |
35 #include "wine/driver.h" | |
36 #include "wine/winerror.h" | |
37 #include "wine/msacm.h" | |
38 #include "wine/msacmdrv.h" | |
1 | 39 #include "wineacm.h" |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1
diff
changeset
|
40 #include "ext.h" |
2069 | 41 |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1
diff
changeset
|
42 #include "driver.h" |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1
diff
changeset
|
43 |
1 | 44 #define OpenDriverA DrvOpen |
45 #define CloseDriver DrvClose | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1
diff
changeset
|
46 |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1
diff
changeset
|
47 #pragma pack(1) |
1 | 48 |
49 static PWINE_ACMSTREAM ACM_GetStream(HACMSTREAM has) | |
50 { | |
51 return (PWINE_ACMSTREAM)has; | |
52 } | |
53 | |
54 /*********************************************************************** | |
55 * acmDriverAddA (MSACM32.2) | |
56 */ | |
57 MMRESULT WINAPI acmDriverAddA(PHACMDRIVERID phadid, HINSTANCE hinstModule, | |
58 LPARAM lParam, DWORD dwPriority, DWORD fdwAdd) | |
59 { | |
60 if (!phadid) | |
61 return MMSYSERR_INVALPARAM; | |
62 | |
63 /* Check if any unknown flags */ | |
64 if (fdwAdd & | |
65 ~(ACM_DRIVERADDF_FUNCTION|ACM_DRIVERADDF_NOTIFYHWND| | |
66 ACM_DRIVERADDF_GLOBAL)) | |
67 return MMSYSERR_INVALFLAG; | |
68 | |
69 /* Check if any incompatible flags */ | |
70 if ((fdwAdd & ACM_DRIVERADDF_FUNCTION) && | |
71 (fdwAdd & ACM_DRIVERADDF_NOTIFYHWND)) | |
72 return MMSYSERR_INVALFLAG; | |
73 | |
74 /* FIXME: in fact, should GetModuleFileName(hinstModule) and do a | |
75 * LoadDriver on it, to be sure we can call SendDriverMessage on the | |
76 * hDrvr handle. | |
77 */ | |
78 *phadid = (HACMDRIVERID) MSACM_RegisterDriver(NULL, NULL, hinstModule); | |
79 | |
80 /* FIXME: lParam, dwPriority and fdwAdd ignored */ | |
81 | |
82 return MMSYSERR_NOERROR; | |
83 } | |
84 | |
85 /*********************************************************************** | |
86 * acmDriverClose (MSACM32.4) | |
87 */ | |
88 MMRESULT WINAPI acmDriverClose(HACMDRIVER had, DWORD fdwClose) | |
89 { | |
90 PWINE_ACMDRIVER p; | |
91 PWINE_ACMDRIVER* tp; | |
92 | |
93 if (fdwClose) | |
94 return MMSYSERR_INVALFLAG; | |
95 | |
96 p = MSACM_GetDriver(had); | |
97 if (!p) | |
98 return MMSYSERR_INVALHANDLE; | |
99 | |
100 for (tp = &(p->obj.pACMDriverID->pACMDriverList); *tp; *tp = (*tp)->pNextACMDriver) { | |
101 if (*tp == p) { | |
102 *tp = (*tp)->pNextACMDriver; | |
103 break; | |
104 } | |
105 } | |
106 | |
107 if (p->hDrvr && !p->obj.pACMDriverID->pACMDriverList) | |
108 CloseDriver(p->hDrvr); | |
109 | |
110 HeapFree(MSACM_hHeap, 0, p); | |
111 | |
112 return MMSYSERR_NOERROR; | |
113 } | |
114 | |
115 /*********************************************************************** | |
116 * acmDriverEnum (MSACM32.7) | |
117 */ | |
118 MMRESULT WINAPI acmDriverEnum(ACMDRIVERENUMCB fnCallback, DWORD dwInstance, DWORD fdwEnum) | |
119 { | |
120 PWINE_ACMDRIVERID p; | |
121 DWORD fdwSupport; | |
122 | |
123 if (!fnCallback) { | |
124 return MMSYSERR_INVALPARAM; | |
125 } | |
126 | |
127 if (fdwEnum && ~(ACM_DRIVERENUMF_NOLOCAL|ACM_DRIVERENUMF_DISABLED)) { | |
128 return MMSYSERR_INVALFLAG; | |
129 } | |
130 | |
131 for (p = MSACM_pFirstACMDriverID; p; p = p->pNextACMDriverID) { | |
132 fdwSupport = ACMDRIVERDETAILS_SUPPORTF_CODEC; | |
133 if (!p->bEnabled) { | |
134 if (fdwEnum & ACM_DRIVERENUMF_DISABLED) | |
135 fdwSupport |= ACMDRIVERDETAILS_SUPPORTF_DISABLED; | |
136 else | |
137 continue; | |
138 } | |
139 (*fnCallback)((HACMDRIVERID) p, dwInstance, fdwSupport); | |
140 } | |
141 | |
142 return MMSYSERR_NOERROR; | |
143 } | |
144 | |
145 /*********************************************************************** | |
146 * acmDriverID (MSACM32.8) | |
147 */ | |
148 MMRESULT WINAPI acmDriverID(HACMOBJ hao, PHACMDRIVERID phadid, DWORD fdwDriverID) | |
149 { | |
150 PWINE_ACMOBJ pao; | |
151 | |
152 pao = MSACM_GetObj(hao); | |
153 if (!pao) | |
154 return MMSYSERR_INVALHANDLE; | |
155 | |
156 if (!phadid) | |
157 return MMSYSERR_INVALPARAM; | |
158 | |
159 if (fdwDriverID) | |
160 return MMSYSERR_INVALFLAG; | |
161 | |
162 *phadid = (HACMDRIVERID) pao->pACMDriverID; | |
163 | |
164 return MMSYSERR_NOERROR; | |
165 } | |
166 | |
167 /*********************************************************************** | |
168 * acmDriverMessage (MSACM32.9) | |
169 * FIXME | |
170 * Not implemented | |
171 */ | |
172 LRESULT WINAPI acmDriverMessage(HACMDRIVER had, UINT uMsg, LPARAM lParam1, LPARAM lParam2) | |
173 { | |
174 PWINE_ACMDRIVER pad = MSACM_GetDriver(had); | |
175 if (!pad) | |
176 return MMSYSERR_INVALPARAM; | |
177 | |
178 /* FIXME: Check if uMsg legal */ | |
179 | |
180 if (!SendDriverMessage(pad->hDrvr, uMsg, lParam1, lParam2)) | |
181 return MMSYSERR_NOTSUPPORTED; | |
182 | |
183 return MMSYSERR_NOERROR; | |
184 } | |
185 | |
186 | |
187 /*********************************************************************** | |
188 * acmDriverOpen (MSACM32.10) | |
189 */ | |
190 MMRESULT WINAPI acmDriverOpen(PHACMDRIVER phad, HACMDRIVERID hadid, DWORD fdwOpen) | |
191 { | |
192 PWINE_ACMDRIVERID padid; | |
193 PWINE_ACMDRIVER pad; | |
194 ICOPEN icopen; | |
195 HDRVR hdrv; | |
196 | |
197 | |
198 | |
199 TRACE("(%p, %x, %08lu)\n", phad, hadid, fdwOpen); | |
200 | |
201 if (!phad) | |
202 return MMSYSERR_INVALPARAM; | |
203 | |
204 padid = MSACM_GetDriverID(hadid); | |
205 if (!padid) | |
206 return MMSYSERR_INVALHANDLE; | |
207 | |
208 if (fdwOpen) | |
209 return MMSYSERR_INVALFLAG; | |
210 | |
211 pad = HeapAlloc(MSACM_hHeap, 0, sizeof(WINE_ACMDRIVER)); | |
212 if (!pad) return MMSYSERR_NOMEM; | |
213 | |
214 pad->obj.pACMDriverID = padid; | |
215 icopen.fccType = mmioFOURCC('a', 'u', 'd', 'c'); | |
216 icopen.fccHandler = (long)padid->pszFileName; | |
217 icopen.dwSize = sizeof(ICOPEN); | |
218 icopen.dwFlags = 0; | |
219 | |
220 if (!padid->hInstModule) | |
221 pad->hDrvr = OpenDriverA((long)&icopen); | |
222 else | |
223 pad->hDrvr = padid->hInstModule; | |
224 | |
225 if (!pad->hDrvr) { | |
226 HeapFree(MSACM_hHeap, 0, pad); | |
227 return MMSYSERR_ERROR; | |
228 } | |
229 | |
230 pad->pfnDriverProc = GetProcAddress(pad->hDrvr, "DriverProc"); | |
231 | |
232 /* insert new pad at beg of list */ | |
233 pad->pNextACMDriver = padid->pACMDriverList; | |
234 padid->pACMDriverList = pad; | |
235 | |
236 /* FIXME: Create a WINE_ACMDRIVER32 */ | |
237 *phad = (HACMDRIVER)pad; | |
238 | |
239 return MMSYSERR_NOERROR; | |
240 } | |
241 | |
242 /*********************************************************************** | |
243 * acmDriverRemove (MSACM32.12) | |
244 */ | |
245 MMRESULT WINAPI acmDriverRemove(HACMDRIVERID hadid, DWORD fdwRemove) | |
246 { | |
247 PWINE_ACMDRIVERID padid; | |
248 | |
249 padid = MSACM_GetDriverID(hadid); | |
250 if (!padid) | |
251 return MMSYSERR_INVALHANDLE; | |
252 | |
253 if (fdwRemove) | |
254 return MMSYSERR_INVALFLAG; | |
255 | |
256 MSACM_UnregisterDriver(padid); | |
257 | |
258 return MMSYSERR_NOERROR; | |
259 } | |
260 | |
261 | |
262 | |
263 /**********************************************************************/ | |
264 | |
265 HANDLE MSACM_hHeap = (HANDLE) NULL; | |
266 PWINE_ACMDRIVERID MSACM_pFirstACMDriverID = NULL; | |
267 PWINE_ACMDRIVERID MSACM_pLastACMDriverID = NULL; | |
268 | |
269 /*********************************************************************** | |
270 * MSACM_RegisterDriver32() | |
271 */ | |
272 PWINE_ACMDRIVERID MSACM_RegisterDriver(LPSTR pszDriverAlias, LPSTR pszFileName, | |
273 HINSTANCE hinstModule) | |
274 // | |
275 // File names are stored in driver.c. I reuse this variable to store driver ID | |
276 // in it. If it's <0x10000, it is primary codec for corresponding format. | |
277 // | |
278 { | |
279 PWINE_ACMDRIVERID padid; | |
280 | |
281 TRACE("('%s', '%x', 0x%08x)\n", pszDriverAlias, pszFileName, hinstModule); | |
282 | |
283 padid = (PWINE_ACMDRIVERID) HeapAlloc(MSACM_hHeap, 0, sizeof(WINE_ACMDRIVERID)); | |
284 padid->pszDriverAlias = (char*)malloc(strlen(pszDriverAlias)+1); | |
285 strcpy(padid->pszDriverAlias, pszDriverAlias); | |
286 // 1~strdup(pszDriverAlias); | |
287 padid->pszFileName = pszFileName; | |
288 padid->hInstModule = hinstModule; | |
289 padid->bEnabled = TRUE; | |
290 padid->pACMDriverList = NULL; | |
291 padid->pNextACMDriverID = NULL; | |
292 padid->pPrevACMDriverID = MSACM_pLastACMDriverID; | |
293 if (MSACM_pLastACMDriverID) | |
294 MSACM_pLastACMDriverID->pNextACMDriverID = padid; | |
295 MSACM_pLastACMDriverID = padid; | |
296 if (!MSACM_pFirstACMDriverID) | |
297 MSACM_pFirstACMDriverID = padid; | |
298 | |
299 return padid; | |
300 } | |
301 | |
302 /*********************************************************************** | |
303 * MSACM_RegisterAllDrivers32() | |
304 */ | |
305 void MSACM_RegisterAllDrivers(void) | |
306 { | |
307 LPSTR pszBuffer; | |
308 DWORD dwBufferLength; | |
309 | |
310 if (MSACM_pFirstACMDriverID) | |
311 return; | |
312 | |
313 MSACM_RegisterDriver("divxa32", (LPSTR)0x161, 0); // DivX/WMA [07] | |
314 MSACM_RegisterDriver("msadp32", (LPSTR)0x2, 0); // MS ADPCM [08] | |
315 MSACM_RegisterDriver("l3codeca", (LPSTR)0x55, 0); // MPEG Layer-3 [12] | |
316 // MSACM_RegisterDriver("imaadp32", (LPSTR)0x11, 0); // IMA ADPCM [13] | |
317 // MSACM_RegisterDriver("msgsm32", (LPSTR)0x32, 0); // MS GSM 6.10 [14] | |
318 } | |
319 | |
320 /*********************************************************************** | |
321 * MSACM_UnregisterDriver32() | |
322 */ | |
323 PWINE_ACMDRIVERID MSACM_UnregisterDriver(PWINE_ACMDRIVERID p) | |
324 { | |
325 PWINE_ACMDRIVERID pNextACMDriverID; | |
326 | |
327 while (p->pACMDriverList) | |
328 acmDriverClose((HACMDRIVER) p->pACMDriverList, 0); | |
329 | |
330 if (p->pszDriverAlias) | |
331 HeapFree(MSACM_hHeap, 0, p->pszDriverAlias); | |
332 // if (p->pszFileName) | |
333 // HeapFree(MSACM_hHeap, 0, p->pszFileName); | |
334 | |
335 if (p == MSACM_pFirstACMDriverID) | |
336 MSACM_pFirstACMDriverID = p->pNextACMDriverID; | |
337 if (p == MSACM_pLastACMDriverID) | |
338 MSACM_pLastACMDriverID = p->pPrevACMDriverID; | |
339 | |
340 if (p->pPrevACMDriverID) | |
341 p->pPrevACMDriverID->pNextACMDriverID = p->pNextACMDriverID; | |
342 if (p->pNextACMDriverID) | |
343 p->pNextACMDriverID->pPrevACMDriverID = p->pPrevACMDriverID; | |
344 | |
345 pNextACMDriverID = p->pNextACMDriverID; | |
346 | |
347 HeapFree(MSACM_hHeap, 0, p); | |
348 | |
349 return pNextACMDriverID; | |
350 } | |
351 | |
352 /*********************************************************************** | |
353 * MSACM_UnregisterAllDrivers32() | |
354 * FIXME | |
355 * Where should this function be called? | |
356 */ | |
357 void MSACM_UnregisterAllDrivers(void) | |
358 { | |
359 PWINE_ACMDRIVERID p; | |
360 | |
361 for (p = MSACM_pFirstACMDriverID; p; p = MSACM_UnregisterDriver(p)); | |
362 } | |
363 | |
364 /*********************************************************************** | |
365 * MSACM_GetDriverID32() | |
366 */ | |
367 PWINE_ACMDRIVERID MSACM_GetDriverID(HACMDRIVERID hDriverID) | |
368 { | |
369 return (PWINE_ACMDRIVERID)hDriverID; | |
370 } | |
371 | |
372 /*********************************************************************** | |
373 * MSACM_GetDriver32() | |
374 */ | |
375 PWINE_ACMDRIVER MSACM_GetDriver(HACMDRIVER hDriver) | |
376 { | |
377 return (PWINE_ACMDRIVER)hDriver; | |
378 } | |
379 | |
380 /*********************************************************************** | |
381 * MSACM_GetObj32() | |
382 */ | |
383 PWINE_ACMOBJ MSACM_GetObj(HACMOBJ hObj) | |
384 { | |
385 return (PWINE_ACMOBJ)hObj; | |
386 } | |
387 | |
388 | |
389 | |
390 /*********************************************************************** | |
391 * acmStreamOpen (MSACM32.40) | |
392 */ | |
393 MMRESULT WINAPI acmStreamOpen(PHACMSTREAM phas, HACMDRIVER had, PWAVEFORMATEX pwfxSrc, | |
394 PWAVEFORMATEX pwfxDst, PWAVEFILTER pwfltr, DWORD dwCallback, | |
395 DWORD dwInstance, DWORD fdwOpen) | |
396 { | |
397 PWINE_ACMSTREAM was; | |
398 PWINE_ACMDRIVER wad; | |
399 MMRESULT ret; | |
400 int wfxSrcSize; | |
401 int wfxDstSize; | |
402 | |
1307
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1
diff
changeset
|
403 //printf("gcc-3.0 bug, pwfxSrc=%p, pwfxSrc->cbSize=%d\n", pwfxSrc, pwfxSrc->cbSize); |
d8c1b0b38edc
Add prototypes to wine/loader stuff, so that we can catch __stdcall function
jkeil
parents:
1
diff
changeset
|
404 |
1 | 405 TRACE("(%p, 0x%08x, %p, %p, %p, %ld, %ld, %ld)\n", |
406 phas, had, pwfxSrc, pwfxDst, pwfltr, dwCallback, dwInstance, fdwOpen); | |
407 | |
408 TRACE("src [wFormatTag=%u, nChannels=%u, nSamplesPerSec=%lu, nAvgBytesPerSec=%lu, nBlockAlign=%u, wBitsPerSample=%u, cbSize=%u]\n", | |
409 pwfxSrc->wFormatTag, pwfxSrc->nChannels, pwfxSrc->nSamplesPerSec, pwfxSrc->nAvgBytesPerSec, | |
410 pwfxSrc->nBlockAlign, pwfxSrc->wBitsPerSample, pwfxSrc->cbSize); | |
411 | |
412 TRACE("dst [wFormatTag=%u, nChannels=%u, nSamplesPerSec=%lu, nAvgBytesPerSec=%lu, nBlockAlign=%u, wBitsPerSample=%u, cbSize=%u]\n", | |
413 pwfxDst->wFormatTag, pwfxDst->nChannels, pwfxDst->nSamplesPerSec, pwfxDst->nAvgBytesPerSec, | |
414 pwfxDst->nBlockAlign, pwfxDst->wBitsPerSample, pwfxDst->cbSize); | |
415 | |
416 #define SIZEOF_WFX(wfx) (sizeof(WAVEFORMATEX) + ((wfx->wFormatTag == WAVE_FORMAT_PCM) ? 0 : wfx->cbSize)) | |
417 wfxSrcSize = SIZEOF_WFX(pwfxSrc); | |
418 wfxDstSize = SIZEOF_WFX(pwfxDst); | |
419 #undef SIZEOF_WFX | |
420 | |
421 was = HeapAlloc(MSACM_hHeap, 0, sizeof(*was) + wfxSrcSize + wfxDstSize + ((pwfltr) ? sizeof(WAVEFILTER) : 0)); | |
422 if (was == NULL) | |
423 return MMSYSERR_NOMEM; | |
424 | |
425 was->drvInst.cbStruct = sizeof(was->drvInst); | |
426 was->drvInst.pwfxSrc = (PWAVEFORMATEX)((LPSTR)was + sizeof(*was)); | |
427 memcpy(was->drvInst.pwfxSrc, pwfxSrc, wfxSrcSize); | |
428 was->drvInst.pwfxDst = (PWAVEFORMATEX)((LPSTR)was + sizeof(*was) + wfxSrcSize); | |
429 memcpy(was->drvInst.pwfxDst, pwfxDst, wfxDstSize); | |
430 if (pwfltr) { | |
431 was->drvInst.pwfltr = (PWAVEFILTER)((LPSTR)was + sizeof(*was) + wfxSrcSize + wfxDstSize); | |
432 memcpy(was->drvInst.pwfltr, pwfltr, sizeof(WAVEFILTER)); | |
433 } else { | |
434 was->drvInst.pwfltr = NULL; | |
435 } | |
436 was->drvInst.dwCallback = dwCallback; | |
437 was->drvInst.dwInstance = dwInstance; | |
438 was->drvInst.fdwOpen = fdwOpen; | |
439 was->drvInst.fdwDriver = 0L; | |
440 was->drvInst.dwDriver = 0L; | |
441 was->drvInst.has = (HACMSTREAM)was; | |
442 | |
443 if (had) { | |
444 if (!(wad = MSACM_GetDriver(had))) { | |
445 ret = MMSYSERR_INVALPARAM; | |
446 goto errCleanUp; | |
447 } | |
448 | |
449 was->obj.pACMDriverID = wad->obj.pACMDriverID; | |
450 was->pDrv = wad; | |
451 was->hAcmDriver = 0; /* not to close it in acmStreamClose */ | |
452 | |
453 ret = SendDriverMessage(wad->hDrvr, ACMDM_STREAM_OPEN, (DWORD)&was->drvInst, 0L); | |
454 if (ret != MMSYSERR_NOERROR) | |
455 goto errCleanUp; | |
456 } else { | |
457 PWINE_ACMDRIVERID wadi; | |
458 short drv_tag; | |
459 ret = ACMERR_NOTPOSSIBLE; | |
460 /* if(pwfxSrc->wFormatTag==1)//compression | |
461 drv_tag=pwfxDst->wFormatTag; | |
462 else | |
463 if(pwfxDst->wFormatTag==1)//decompression | |
464 drv_tag=pwfxSrc->wFormatTag; | |
465 else | |
466 goto errCleanUp; | |
467 | |
468 ret=acmDriverOpen2(drv_tag); | |
469 if (ret == MMSYSERR_NOERROR) { | |
470 if ((wad = MSACM_GetDriver(had)) != 0) { | |
471 was->obj.pACMDriverID = wad->obj.pACMDriverID; | |
472 was->pDrv = wad; | |
473 was->hAcmDriver = had; | |
474 | |
475 ret = SendDriverMessage(wad->hDrvr, ACMDM_STREAM_OPEN, (DWORD)&was->drvInst, 0L); | |
476 if (ret == MMSYSERR_NOERROR) { | |
477 if (fdwOpen & ACM_STREAMOPENF_QUERY) { | |
478 acmDriverClose(had, 0L); | |
479 } | |
480 break; | |
481 } | |
482 } | |
483 acmDriverClose(had, 0L);*/ | |
484 if(MSACM_pFirstACMDriverID==NULL) | |
485 MSACM_RegisterAllDrivers(); | |
486 | |
487 for (wadi = MSACM_pFirstACMDriverID; wadi; wadi = wadi->pNextACMDriverID) { | |
488 ret = acmDriverOpen(&had, (HACMDRIVERID)wadi, 0L); | |
489 if (ret == MMSYSERR_NOERROR) { | |
490 if ((wad = MSACM_GetDriver(had)) != 0) { | |
491 was->obj.pACMDriverID = wad->obj.pACMDriverID; | |
492 was->pDrv = wad; | |
493 was->hAcmDriver = had; | |
494 | |
495 ret = SendDriverMessage(wad->hDrvr, ACMDM_STREAM_OPEN, (DWORD)&was->drvInst, 0L); | |
496 if (ret == MMSYSERR_NOERROR) { | |
497 if (fdwOpen & ACM_STREAMOPENF_QUERY) { | |
498 acmDriverClose(had, 0L); | |
499 } | |
500 break; | |
501 } | |
502 } | |
503 // no match, close this acm driver and try next one | |
504 acmDriverClose(had, 0L); | |
505 } | |
506 } | |
507 if (ret != MMSYSERR_NOERROR) { | |
508 ret = ACMERR_NOTPOSSIBLE; | |
509 goto errCleanUp; | |
510 } | |
511 } | |
512 ret = MMSYSERR_NOERROR; | |
513 if (!(fdwOpen & ACM_STREAMOPENF_QUERY)) { | |
514 if (phas) | |
515 *phas = (HACMSTREAM)was; | |
516 TRACE("=> (%d)\n", ret); | |
517 return ret; | |
518 } | |
519 errCleanUp: | |
520 if (phas) | |
521 *phas = (HACMSTREAM)0; | |
522 HeapFree(MSACM_hHeap, 0, was); | |
523 TRACE("=> (%d)\n", ret); | |
524 return ret; | |
525 } | |
526 | |
527 | |
528 MMRESULT WINAPI acmStreamClose(HACMSTREAM has, DWORD fdwClose) | |
529 { | |
530 PWINE_ACMSTREAM was; | |
531 MMRESULT ret; | |
532 | |
533 TRACE("(0x%08x, %ld)\n", has, fdwClose); | |
534 | |
535 if ((was = ACM_GetStream(has)) == NULL) { | |
536 return MMSYSERR_INVALHANDLE; | |
537 } | |
538 ret = SendDriverMessage(was->pDrv->hDrvr, ACMDM_STREAM_CLOSE, (DWORD)&was->drvInst, 0); | |
539 if (ret == MMSYSERR_NOERROR) { | |
540 if (was->hAcmDriver) | |
541 acmDriverClose(was->hAcmDriver, 0L); | |
542 HeapFree(MSACM_hHeap, 0, was); | |
543 } | |
544 TRACE("=> (%d)\n", ret); | |
545 return ret; | |
546 } | |
547 | |
548 /*********************************************************************** | |
549 * acmStreamConvert (MSACM32.38) | |
550 */ | |
551 MMRESULT WINAPI acmStreamConvert(HACMSTREAM has, PACMSTREAMHEADER pash, | |
552 DWORD fdwConvert) | |
553 { | |
554 PWINE_ACMSTREAM was; | |
555 MMRESULT ret = MMSYSERR_NOERROR; | |
556 PACMDRVSTREAMHEADER padsh; | |
557 | |
558 TRACE("(0x%08x, %p, %ld)\n", has, pash, fdwConvert); | |
559 | |
560 if ((was = ACM_GetStream(has)) == NULL) | |
561 return MMSYSERR_INVALHANDLE; | |
562 if (!pash || pash->cbStruct < sizeof(ACMSTREAMHEADER)) | |
563 return MMSYSERR_INVALPARAM; | |
564 | |
565 if (!(pash->fdwStatus & ACMSTREAMHEADER_STATUSF_PREPARED)) | |
566 return ACMERR_UNPREPARED; | |
567 | |
568 /* Note: the ACMSTREAMHEADER and ACMDRVSTREAMHEADER structs are of same | |
569 * size. some fields are private to msacm internals, and are exposed | |
570 * in ACMSTREAMHEADER in the dwReservedDriver array | |
571 */ | |
572 padsh = (PACMDRVSTREAMHEADER)pash; | |
573 | |
574 /* check that pointers have not been modified */ | |
575 if (padsh->pbPreparedSrc != padsh->pbSrc || | |
576 padsh->cbPreparedSrcLength < padsh->cbSrcLength || | |
577 padsh->pbPreparedDst != padsh->pbDst || | |
578 padsh->cbPreparedDstLength < padsh->cbDstLength) { | |
579 return MMSYSERR_INVALPARAM; | |
580 } | |
581 | |
582 padsh->fdwConvert = fdwConvert; | |
583 | |
584 ret = SendDriverMessage(was->pDrv->hDrvr, ACMDM_STREAM_CONVERT, (DWORD)&was->drvInst, (DWORD)padsh); | |
585 if (ret == MMSYSERR_NOERROR) { | |
586 padsh->fdwStatus |= ACMSTREAMHEADER_STATUSF_DONE; | |
587 } | |
588 TRACE("=> (%d)\n", ret); | |
589 return ret; | |
590 } | |
591 | |
592 | |
593 /*********************************************************************** | |
594 * acmStreamPrepareHeader (MSACM32.41) | |
595 */ | |
596 MMRESULT WINAPI acmStreamPrepareHeader(HACMSTREAM has, PACMSTREAMHEADER pash, | |
597 DWORD fdwPrepare) | |
598 { | |
599 PWINE_ACMSTREAM was; | |
600 MMRESULT ret = MMSYSERR_NOERROR; | |
601 PACMDRVSTREAMHEADER padsh; | |
602 | |
603 TRACE("(0x%08x, %p, %ld)\n", has, pash, fdwPrepare); | |
604 | |
605 if ((was = ACM_GetStream(has)) == NULL) | |
606 return MMSYSERR_INVALHANDLE; | |
607 if (!pash || pash->cbStruct < sizeof(ACMSTREAMHEADER)) | |
608 return MMSYSERR_INVALPARAM; | |
609 if (fdwPrepare) | |
610 ret = MMSYSERR_INVALFLAG; | |
611 | |
612 if (pash->fdwStatus & ACMSTREAMHEADER_STATUSF_DONE) | |
613 return MMSYSERR_NOERROR; | |
614 | |
615 /* Note: the ACMSTREAMHEADER and ACMDRVSTREAMHEADER structs are of same | |
616 * size. some fields are private to msacm internals, and are exposed | |
617 * in ACMSTREAMHEADER in the dwReservedDriver array | |
618 */ | |
619 padsh = (PACMDRVSTREAMHEADER)pash; | |
620 | |
621 padsh->fdwConvert = fdwPrepare; | |
622 padsh->padshNext = NULL; | |
623 padsh->fdwDriver = padsh->dwDriver = 0L; | |
624 | |
625 padsh->fdwPrepared = 0; | |
626 padsh->dwPrepared = 0; | |
627 padsh->pbPreparedSrc = 0; | |
628 padsh->cbPreparedSrcLength = 0; | |
629 padsh->pbPreparedDst = 0; | |
630 padsh->cbPreparedDstLength = 0; | |
631 | |
632 ret = SendDriverMessage(was->pDrv->hDrvr, ACMDM_STREAM_PREPARE, (DWORD)&was->drvInst, (DWORD)padsh); | |
633 if (ret == MMSYSERR_NOERROR || ret == MMSYSERR_NOTSUPPORTED) { | |
634 ret = MMSYSERR_NOERROR; | |
635 padsh->fdwStatus &= ~(ACMSTREAMHEADER_STATUSF_DONE|ACMSTREAMHEADER_STATUSF_INQUEUE); | |
636 padsh->fdwStatus |= ACMSTREAMHEADER_STATUSF_PREPARED; | |
637 padsh->fdwPrepared = padsh->fdwStatus; | |
638 padsh->dwPrepared = 0; | |
639 padsh->pbPreparedSrc = padsh->pbSrc; | |
640 padsh->cbPreparedSrcLength = padsh->cbSrcLength; | |
641 padsh->pbPreparedDst = padsh->pbDst; | |
642 padsh->cbPreparedDstLength = padsh->cbDstLength; | |
643 } else { | |
644 padsh->fdwPrepared = 0; | |
645 padsh->dwPrepared = 0; | |
646 padsh->pbPreparedSrc = 0; | |
647 padsh->cbPreparedSrcLength = 0; | |
648 padsh->pbPreparedDst = 0; | |
649 padsh->cbPreparedDstLength = 0; | |
650 } | |
651 TRACE("=> (%d)\n", ret); | |
652 return ret; | |
653 } | |
654 | |
655 /*********************************************************************** | |
656 * acmStreamReset (MSACM32.42) | |
657 */ | |
658 MMRESULT WINAPI acmStreamReset(HACMSTREAM has, DWORD fdwReset) | |
659 { | |
660 PWINE_ACMSTREAM was; | |
661 MMRESULT ret = MMSYSERR_NOERROR; | |
662 | |
663 TRACE("(0x%08x, %ld)\n", has, fdwReset); | |
664 | |
665 if (fdwReset) { | |
666 ret = MMSYSERR_INVALFLAG; | |
667 } else if ((was = ACM_GetStream(has)) == NULL) { | |
668 return MMSYSERR_INVALHANDLE; | |
669 } else if (was->drvInst.fdwOpen & ACM_STREAMOPENF_ASYNC) { | |
670 ret = SendDriverMessage(was->pDrv->hDrvr, ACMDM_STREAM_RESET, (DWORD)&was->drvInst, 0); | |
671 } | |
672 TRACE("=> (%d)\n", ret); | |
673 return ret; | |
674 } | |
675 | |
676 /*********************************************************************** | |
677 * acmStreamSize (MSACM32.43) | |
678 */ | |
679 MMRESULT WINAPI acmStreamSize(HACMSTREAM has, DWORD cbInput, | |
680 LPDWORD pdwOutputBytes, DWORD fdwSize) | |
681 { | |
682 PWINE_ACMSTREAM was; | |
683 ACMDRVSTREAMSIZE adss; | |
684 MMRESULT ret; | |
685 | |
686 TRACE("(0x%08x, %ld, %p, %ld)\n", has, cbInput, pdwOutputBytes, fdwSize); | |
687 | |
688 if ((was = ACM_GetStream(has)) == NULL) { | |
689 return MMSYSERR_INVALHANDLE; | |
690 } | |
691 if ((fdwSize & ~ACM_STREAMSIZEF_QUERYMASK) != 0) { | |
692 return MMSYSERR_INVALFLAG; | |
693 } | |
694 | |
695 *pdwOutputBytes = 0L; | |
696 | |
697 switch (fdwSize & ACM_STREAMSIZEF_QUERYMASK) { | |
698 case ACM_STREAMSIZEF_DESTINATION: | |
699 adss.cbDstLength = cbInput; | |
700 adss.cbSrcLength = 0; | |
701 break; | |
702 case ACM_STREAMSIZEF_SOURCE: | |
703 adss.cbSrcLength = cbInput; | |
704 adss.cbDstLength = 0; | |
705 break; | |
706 default: | |
707 return MMSYSERR_INVALFLAG; | |
708 } | |
709 | |
710 adss.cbStruct = sizeof(adss); | |
711 adss.fdwSize = fdwSize; | |
712 ret = SendDriverMessage(was->pDrv->hDrvr, ACMDM_STREAM_SIZE, | |
713 (DWORD)&was->drvInst, (DWORD)&adss); | |
714 if (ret == MMSYSERR_NOERROR) { | |
715 switch (fdwSize & ACM_STREAMSIZEF_QUERYMASK) { | |
716 case ACM_STREAMSIZEF_DESTINATION: | |
717 *pdwOutputBytes = adss.cbSrcLength; | |
718 break; | |
719 case ACM_STREAMSIZEF_SOURCE: | |
720 *pdwOutputBytes = adss.cbDstLength; | |
721 break; | |
722 } | |
723 } | |
724 TRACE("=> (%d) [%lu]\n", ret, *pdwOutputBytes); | |
725 return ret; | |
726 } | |
727 | |
728 /*********************************************************************** | |
729 * acmStreamUnprepareHeader (MSACM32.44) | |
730 */ | |
731 MMRESULT WINAPI acmStreamUnprepareHeader(HACMSTREAM has, PACMSTREAMHEADER pash, | |
732 DWORD fdwUnprepare) | |
733 { | |
734 PWINE_ACMSTREAM was; | |
735 MMRESULT ret = MMSYSERR_NOERROR; | |
736 PACMDRVSTREAMHEADER padsh; | |
737 | |
738 TRACE("(0x%08x, %p, %ld)\n", has, pash, fdwUnprepare); | |
739 | |
740 if ((was = ACM_GetStream(has)) == NULL) | |
741 return MMSYSERR_INVALHANDLE; | |
742 if (!pash || pash->cbStruct < sizeof(ACMSTREAMHEADER)) | |
743 return MMSYSERR_INVALPARAM; | |
744 | |
745 if (!(pash->fdwStatus & ACMSTREAMHEADER_STATUSF_PREPARED)) | |
746 return ACMERR_UNPREPARED; | |
747 | |
748 /* Note: the ACMSTREAMHEADER and ACMDRVSTREAMHEADER structs are of same | |
749 * size. some fields are private to msacm internals, and are exposed | |
750 * in ACMSTREAMHEADER in the dwReservedDriver array | |
751 */ | |
752 padsh = (PACMDRVSTREAMHEADER)pash; | |
753 | |
754 /* check that pointers have not been modified */ | |
755 if (padsh->pbPreparedSrc != padsh->pbSrc || | |
756 padsh->cbPreparedSrcLength < padsh->cbSrcLength || | |
757 padsh->pbPreparedDst != padsh->pbDst || | |
758 padsh->cbPreparedDstLength < padsh->cbDstLength) { | |
759 return MMSYSERR_INVALPARAM; | |
760 } | |
761 | |
762 padsh->fdwConvert = fdwUnprepare; | |
763 | |
764 ret = SendDriverMessage(was->pDrv->hDrvr, ACMDM_STREAM_UNPREPARE, (DWORD)&was->drvInst, (DWORD)padsh); | |
765 if (ret == MMSYSERR_NOERROR || ret == MMSYSERR_NOTSUPPORTED) { | |
766 ret = MMSYSERR_NOERROR; | |
767 padsh->fdwStatus &= ~(ACMSTREAMHEADER_STATUSF_DONE|ACMSTREAMHEADER_STATUSF_INQUEUE|ACMSTREAMHEADER_STATUSF_PREPARED); | |
768 } | |
769 TRACE("=> (%d)\n", ret); | |
770 return ret; | |
771 } |