1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
6 * Copyright 1998 Patrik Stridvall
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 * + asynchronous conversion is not implemented
26 * + callback/notification
28 * + properly close ACM streams
36 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(msacm
);
46 static PWINE_ACMSTREAM
ACM_GetStream(HACMSTREAM has
)
50 return (PWINE_ACMSTREAM
)has
;
53 /***********************************************************************
54 * acmStreamClose (MSACM32.@)
56 MMRESULT WINAPI
acmStreamClose(HACMSTREAM has
, DWORD fdwClose
)
61 TRACE("(%p, %d)\n", has
, fdwClose
);
63 if ((was
= ACM_GetStream(has
)) == NULL
) {
64 WARN("invalid handle\n");
65 return MMSYSERR_INVALHANDLE
;
67 ret
= MSACM_Message((HACMDRIVER
)was
->pDrv
, ACMDM_STREAM_CLOSE
, (LPARAM
)&was
->drvInst
, 0);
68 if (ret
== MMSYSERR_NOERROR
) {
70 acmDriverClose(was
->hAcmDriver
, 0L);
71 HeapFree(MSACM_hHeap
, 0, was
);
73 TRACE("=> (%d)\n", ret
);
77 /***********************************************************************
78 * acmStreamConvert (MSACM32.@)
80 MMRESULT WINAPI
acmStreamConvert(HACMSTREAM has
, PACMSTREAMHEADER pash
,
84 MMRESULT ret
= MMSYSERR_NOERROR
;
85 PACMDRVSTREAMHEADER padsh
;
87 TRACE("(%p, %p, %d)\n", has
, pash
, fdwConvert
);
89 if ((was
= ACM_GetStream(has
)) == NULL
) {
90 WARN("invalid handle\n");
91 return MMSYSERR_INVALHANDLE
;
93 if (!pash
|| pash
->cbStruct
< sizeof(ACMSTREAMHEADER
)) {
94 WARN("invalid parameter\n");
95 return MMSYSERR_INVALPARAM
;
97 if (!(pash
->fdwStatus
& ACMSTREAMHEADER_STATUSF_PREPARED
)) {
98 WARN("unprepared header\n");
99 return ACMERR_UNPREPARED
;
102 pash
->cbSrcLengthUsed
= 0;
103 pash
->cbDstLengthUsed
= 0;
105 /* Note: the ACMSTREAMHEADER and ACMDRVSTREAMHEADER structs are of same
106 * size. some fields are private to msacm internals, and are exposed
107 * in ACMSTREAMHEADER in the dwReservedDriver array
109 padsh
= (PACMDRVSTREAMHEADER
)pash
;
111 /* check that pointers have not been modified */
112 if (padsh
->pbPreparedSrc
!= padsh
->pbSrc
||
113 padsh
->cbPreparedSrcLength
< padsh
->cbSrcLength
||
114 padsh
->pbPreparedDst
!= padsh
->pbDst
||
115 padsh
->cbPreparedDstLength
< padsh
->cbDstLength
) {
116 WARN("invalid parameter\n");
117 return MMSYSERR_INVALPARAM
;
120 padsh
->fdwConvert
= fdwConvert
;
122 ret
= MSACM_Message((HACMDRIVER
)was
->pDrv
, ACMDM_STREAM_CONVERT
, (LPARAM
)&was
->drvInst
, (LPARAM
)padsh
);
123 if (ret
== MMSYSERR_NOERROR
) {
124 padsh
->fdwStatus
|= ACMSTREAMHEADER_STATUSF_DONE
;
126 TRACE("=> (%d)\n", ret
);
130 /***********************************************************************
131 * acmStreamMessage (MSACM32.@)
133 MMRESULT WINAPI
acmStreamMessage(HACMSTREAM has
, UINT uMsg
, LPARAM lParam1
,
136 FIXME("(%p, %u, %ld, %ld): stub\n", has
, uMsg
, lParam1
, lParam2
);
137 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
138 return MMSYSERR_ERROR
;
141 /***********************************************************************
142 * acmStreamOpen (MSACM32.@)
144 MMRESULT WINAPI
acmStreamOpen(PHACMSTREAM phas
, HACMDRIVER had
,
145 PWAVEFORMATEX pwfxSrc
, PWAVEFORMATEX pwfxDst
,
146 PWAVEFILTER pwfltr
, DWORD_PTR dwCallback
,
147 DWORD_PTR dwInstance
, DWORD fdwOpen
)
154 WAVEFORMATEX wfxSrc
, wfxDst
;
156 TRACE("(%p, %p, %p, %p, %p, %ld, %ld, %d)\n",
157 phas
, had
, pwfxSrc
, pwfxDst
, pwfltr
, dwCallback
, dwInstance
, fdwOpen
);
159 /* NOTE: pwfxSrc and/or pwfxDst can point to a structure smaller than
160 * WAVEFORMATEX so don't use them directly when not sure */
161 if (pwfxSrc
->wFormatTag
== WAVE_FORMAT_PCM
) {
162 memcpy(&wfxSrc
, pwfxSrc
, sizeof(PCMWAVEFORMAT
));
163 wfxSrc
.wBitsPerSample
= pwfxSrc
->wBitsPerSample
;
168 if (pwfxDst
->wFormatTag
== WAVE_FORMAT_PCM
) {
169 memcpy(&wfxDst
, pwfxDst
, sizeof(PCMWAVEFORMAT
));
170 wfxDst
.wBitsPerSample
= pwfxDst
->wBitsPerSample
;
175 TRACE("src [wFormatTag=%u, nChannels=%u, nSamplesPerSec=%u, nAvgBytesPerSec=%u, nBlockAlign=%u, wBitsPerSample=%u, cbSize=%u]\n",
176 pwfxSrc
->wFormatTag
, pwfxSrc
->nChannels
, pwfxSrc
->nSamplesPerSec
, pwfxSrc
->nAvgBytesPerSec
,
177 pwfxSrc
->nBlockAlign
, pwfxSrc
->wBitsPerSample
, pwfxSrc
->cbSize
);
179 TRACE("dst [wFormatTag=%u, nChannels=%u, nSamplesPerSec=%u, nAvgBytesPerSec=%u, nBlockAlign=%u, wBitsPerSample=%u, cbSize=%u]\n",
180 pwfxDst
->wFormatTag
, pwfxDst
->nChannels
, pwfxDst
->nSamplesPerSec
, pwfxDst
->nAvgBytesPerSec
,
181 pwfxDst
->nBlockAlign
, pwfxDst
->wBitsPerSample
, pwfxDst
->cbSize
);
183 /* (WS) In query mode, phas should be NULL. If it is not, then instead
184 * of returning an error we are making sure it is NULL, preventing some
185 * applications that pass garbage for phas from crashing.
187 if (fdwOpen
& ACM_STREAMOPENF_QUERY
) phas
= NULL
;
189 if (pwfltr
&& (pwfxSrc
->wFormatTag
!= pwfxDst
->wFormatTag
)) {
190 WARN("invalid parameter\n");
191 return MMSYSERR_INVALPARAM
;
194 wfxSrcSize
= wfxDstSize
= sizeof(WAVEFORMATEX
);
195 if (pwfxSrc
->wFormatTag
!= WAVE_FORMAT_PCM
) wfxSrcSize
+= pwfxSrc
->cbSize
;
196 if (pwfxDst
->wFormatTag
!= WAVE_FORMAT_PCM
) wfxDstSize
+= pwfxDst
->cbSize
;
198 was
= HeapAlloc(MSACM_hHeap
, 0, sizeof(*was
) + wfxSrcSize
+ wfxDstSize
+
199 ((pwfltr
) ? sizeof(WAVEFILTER
) : 0));
202 return MMSYSERR_NOMEM
;
205 was
->drvInst
.cbStruct
= sizeof(was
->drvInst
);
206 was
->drvInst
.pwfxSrc
= (PWAVEFORMATEX
)((LPSTR
)was
+ sizeof(*was
));
207 memcpy(was
->drvInst
.pwfxSrc
, pwfxSrc
, wfxSrcSize
);
208 was
->drvInst
.pwfxDst
= (PWAVEFORMATEX
)((LPSTR
)was
+ sizeof(*was
) + wfxSrcSize
);
209 memcpy(was
->drvInst
.pwfxDst
, pwfxDst
, wfxDstSize
);
211 was
->drvInst
.pwfltr
= (PWAVEFILTER
)((LPSTR
)was
+ sizeof(*was
) + wfxSrcSize
+ wfxDstSize
);
212 memcpy(was
->drvInst
.pwfltr
, pwfltr
, sizeof(WAVEFILTER
));
214 was
->drvInst
.pwfltr
= NULL
;
216 was
->drvInst
.dwCallback
= dwCallback
;
217 was
->drvInst
.dwInstance
= dwInstance
;
218 was
->drvInst
.fdwOpen
= fdwOpen
;
219 was
->drvInst
.fdwDriver
= 0L;
220 was
->drvInst
.dwDriver
= 0L;
221 /* real value will be stored once ACMDM_STREAM_OPEN succeeds */
222 was
->drvInst
.has
= 0L;
225 if (!(wad
= MSACM_GetDriver(had
))) {
226 ret
= MMSYSERR_INVALPARAM
;
230 was
->obj
.dwType
= WINE_ACMOBJ_STREAM
;
231 was
->obj
.pACMDriverID
= wad
->obj
.pACMDriverID
;
233 was
->hAcmDriver
= 0; /* not to close it in acmStreamClose */
235 ret
= MSACM_Message((HACMDRIVER
)wad
, ACMDM_STREAM_OPEN
, (LPARAM
)&was
->drvInst
, 0L);
236 if (ret
!= MMSYSERR_NOERROR
)
239 PWINE_ACMDRIVERID wadi
;
241 ret
= ACMERR_NOTPOSSIBLE
;
242 for (wadi
= MSACM_pFirstACMDriverID
; wadi
; wadi
= wadi
->pNextACMDriverID
) {
243 if ((wadi
->fdwSupport
& ACMDRIVERDETAILS_SUPPORTF_DISABLED
) ||
244 !MSACM_FindFormatTagInCache(wadi
, pwfxSrc
->wFormatTag
, NULL
) ||
245 !MSACM_FindFormatTagInCache(wadi
, pwfxDst
->wFormatTag
, NULL
))
247 ret
= acmDriverOpen(&had
, (HACMDRIVERID
)wadi
, 0L);
248 if (ret
!= MMSYSERR_NOERROR
)
250 if ((wad
= MSACM_GetDriver(had
)) != 0) {
251 was
->obj
.dwType
= WINE_ACMOBJ_STREAM
;
252 was
->obj
.pACMDriverID
= wad
->obj
.pACMDriverID
;
254 was
->hAcmDriver
= had
;
256 ret
= MSACM_Message((HACMDRIVER
)wad
, ACMDM_STREAM_OPEN
, (LPARAM
)&was
->drvInst
, 0L);
257 TRACE("%s => %08x\n", debugstr_w(wadi
->pszDriverAlias
), ret
);
258 if (ret
== MMSYSERR_NOERROR
) {
259 if (fdwOpen
& ACM_STREAMOPENF_QUERY
) {
260 MSACM_Message((HACMDRIVER
)wad
, ACMDM_STREAM_CLOSE
, (LPARAM
)&was
->drvInst
, 0);
261 acmDriverClose(had
, 0L);
266 /* no match, close this acm driver and try next one */
267 acmDriverClose(had
, 0L);
269 if (ret
!= MMSYSERR_NOERROR
) {
270 ret
= ACMERR_NOTPOSSIBLE
;
274 ret
= MMSYSERR_NOERROR
;
275 was
->drvInst
.has
= (HACMSTREAM
)was
;
276 if (!(fdwOpen
& ACM_STREAMOPENF_QUERY
)) {
278 *phas
= (HACMSTREAM
)was
;
279 TRACE("=> (%d)\n", ret
);
285 HeapFree(MSACM_hHeap
, 0, was
);
286 TRACE("=> (%d)\n", ret
);
291 /***********************************************************************
292 * acmStreamPrepareHeader (MSACM32.@)
294 MMRESULT WINAPI
acmStreamPrepareHeader(HACMSTREAM has
, PACMSTREAMHEADER pash
,
298 MMRESULT ret
= MMSYSERR_NOERROR
;
299 PACMDRVSTREAMHEADER padsh
;
301 TRACE("(%p, %p, %d)\n", has
, pash
, fdwPrepare
);
303 if ((was
= ACM_GetStream(has
)) == NULL
) {
304 WARN("invalid handle\n");
305 return MMSYSERR_INVALHANDLE
;
307 if (!pash
|| pash
->cbStruct
< sizeof(ACMSTREAMHEADER
)) {
308 WARN("invalid parameter\n");
309 return MMSYSERR_INVALPARAM
;
312 ret
= MMSYSERR_INVALFLAG
;
314 if (pash
->fdwStatus
& ACMSTREAMHEADER_STATUSF_DONE
)
315 return MMSYSERR_NOERROR
;
317 /* Note: the ACMSTREAMHEADER and ACMDRVSTREAMHEADER structs are of same
318 * size. some fields are private to msacm internals, and are exposed
319 * in ACMSTREAMHEADER in the dwReservedDriver array
321 padsh
= (PACMDRVSTREAMHEADER
)pash
;
323 padsh
->fdwConvert
= fdwPrepare
;
324 padsh
->padshNext
= NULL
;
325 padsh
->fdwDriver
= padsh
->dwDriver
= 0L;
327 padsh
->fdwPrepared
= 0;
328 padsh
->dwPrepared
= 0;
329 padsh
->pbPreparedSrc
= 0;
330 padsh
->cbPreparedSrcLength
= 0;
331 padsh
->pbPreparedDst
= 0;
332 padsh
->cbPreparedDstLength
= 0;
334 ret
= MSACM_Message((HACMDRIVER
)was
->pDrv
, ACMDM_STREAM_PREPARE
, (LPARAM
)&was
->drvInst
, (LPARAM
)padsh
);
335 if (ret
== MMSYSERR_NOERROR
|| ret
== MMSYSERR_NOTSUPPORTED
) {
336 ret
= MMSYSERR_NOERROR
;
337 padsh
->fdwStatus
&= ~(ACMSTREAMHEADER_STATUSF_DONE
|ACMSTREAMHEADER_STATUSF_INQUEUE
);
338 padsh
->fdwStatus
|= ACMSTREAMHEADER_STATUSF_PREPARED
;
339 padsh
->fdwPrepared
= padsh
->fdwStatus
;
340 padsh
->dwPrepared
= 0;
341 padsh
->pbPreparedSrc
= padsh
->pbSrc
;
342 padsh
->cbPreparedSrcLength
= padsh
->cbSrcLength
;
343 padsh
->pbPreparedDst
= padsh
->pbDst
;
344 padsh
->cbPreparedDstLength
= padsh
->cbDstLength
;
346 padsh
->fdwPrepared
= 0;
347 padsh
->dwPrepared
= 0;
348 padsh
->pbPreparedSrc
= 0;
349 padsh
->cbPreparedSrcLength
= 0;
350 padsh
->pbPreparedDst
= 0;
351 padsh
->cbPreparedDstLength
= 0;
353 TRACE("=> (%d)\n", ret
);
357 /***********************************************************************
358 * acmStreamReset (MSACM32.@)
360 MMRESULT WINAPI
acmStreamReset(HACMSTREAM has
, DWORD fdwReset
)
363 MMRESULT ret
= MMSYSERR_NOERROR
;
365 TRACE("(%p, %d)\n", has
, fdwReset
);
368 WARN("invalid flag\n");
369 ret
= MMSYSERR_INVALFLAG
;
370 } else if ((was
= ACM_GetStream(has
)) == NULL
) {
371 WARN("invalid handle\n");
372 return MMSYSERR_INVALHANDLE
;
373 } else if (was
->drvInst
.fdwOpen
& ACM_STREAMOPENF_ASYNC
) {
374 ret
= MSACM_Message((HACMDRIVER
)was
->pDrv
, ACMDM_STREAM_RESET
, (LPARAM
)&was
->drvInst
, 0);
376 TRACE("=> (%d)\n", ret
);
380 /***********************************************************************
381 * acmStreamSize (MSACM32.@)
383 MMRESULT WINAPI
acmStreamSize(HACMSTREAM has
, DWORD cbInput
,
384 LPDWORD pdwOutputBytes
, DWORD fdwSize
)
387 ACMDRVSTREAMSIZE adss
;
390 TRACE("(%p, %d, %p, %d)\n", has
, cbInput
, pdwOutputBytes
, fdwSize
);
392 if ((was
= ACM_GetStream(has
)) == NULL
) {
393 WARN("invalid handle\n");
394 return MMSYSERR_INVALHANDLE
;
396 if ((fdwSize
& ~ACM_STREAMSIZEF_QUERYMASK
) != 0) {
397 WARN("invalid flag\n");
398 return MMSYSERR_INVALFLAG
;
401 *pdwOutputBytes
= 0L;
403 switch (fdwSize
& ACM_STREAMSIZEF_QUERYMASK
) {
404 case ACM_STREAMSIZEF_DESTINATION
:
405 adss
.cbDstLength
= cbInput
;
406 adss
.cbSrcLength
= 0;
408 case ACM_STREAMSIZEF_SOURCE
:
409 adss
.cbSrcLength
= cbInput
;
410 adss
.cbDstLength
= 0;
413 WARN("invalid flag\n");
414 return MMSYSERR_INVALFLAG
;
417 adss
.cbStruct
= sizeof(adss
);
418 adss
.fdwSize
= fdwSize
;
419 ret
= MSACM_Message((HACMDRIVER
)was
->pDrv
, ACMDM_STREAM_SIZE
,
420 (LPARAM
)&was
->drvInst
, (LPARAM
)&adss
);
421 if (ret
== MMSYSERR_NOERROR
) {
422 switch (fdwSize
& ACM_STREAMSIZEF_QUERYMASK
) {
423 case ACM_STREAMSIZEF_DESTINATION
:
424 *pdwOutputBytes
= adss
.cbSrcLength
;
426 case ACM_STREAMSIZEF_SOURCE
:
427 *pdwOutputBytes
= adss
.cbDstLength
;
431 TRACE("=> (%d) [%u]\n", ret
, *pdwOutputBytes
);
435 /***********************************************************************
436 * acmStreamUnprepareHeader (MSACM32.@)
438 MMRESULT WINAPI
acmStreamUnprepareHeader(HACMSTREAM has
, PACMSTREAMHEADER pash
,
442 MMRESULT ret
= MMSYSERR_NOERROR
;
443 PACMDRVSTREAMHEADER padsh
;
445 TRACE("(%p, %p, %d)\n", has
, pash
, fdwUnprepare
);
447 if ((was
= ACM_GetStream(has
)) == NULL
) {
448 WARN("invalid handle\n");
449 return MMSYSERR_INVALHANDLE
;
451 if (!pash
|| pash
->cbStruct
< sizeof(ACMSTREAMHEADER
)) {
452 WARN("invalid parameter\n");
453 return MMSYSERR_INVALPARAM
;
455 if (!(pash
->fdwStatus
& ACMSTREAMHEADER_STATUSF_PREPARED
)) {
456 WARN("unprepared header\n");
457 return ACMERR_UNPREPARED
;
460 /* Note: the ACMSTREAMHEADER and ACMDRVSTREAMHEADER structs are of same
461 * size. some fields are private to msacm internals, and are exposed
462 * in ACMSTREAMHEADER in the dwReservedDriver array
464 padsh
= (PACMDRVSTREAMHEADER
)pash
;
466 /* check that pointers have not been modified */
467 if (padsh
->pbPreparedSrc
!= padsh
->pbSrc
||
468 padsh
->cbPreparedSrcLength
< padsh
->cbSrcLength
||
469 padsh
->pbPreparedDst
!= padsh
->pbDst
||
470 padsh
->cbPreparedDstLength
< padsh
->cbDstLength
) {
471 WARN("invalid parameter\n");
472 return MMSYSERR_INVALPARAM
;
475 padsh
->fdwConvert
= fdwUnprepare
;
477 ret
= MSACM_Message((HACMDRIVER
)was
->pDrv
, ACMDM_STREAM_UNPREPARE
, (LPARAM
)&was
->drvInst
, (LPARAM
)padsh
);
478 if (ret
== MMSYSERR_NOERROR
|| ret
== MMSYSERR_NOTSUPPORTED
) {
479 ret
= MMSYSERR_NOERROR
;
480 padsh
->fdwStatus
&= ~(ACMSTREAMHEADER_STATUSF_DONE
|ACMSTREAMHEADER_STATUSF_INQUEUE
|ACMSTREAMHEADER_STATUSF_PREPARED
);
482 TRACE("=> (%d)\n", ret
);