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