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