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
33 static PWINE_ACMSTREAM
ACM_GetStream(HACMSTREAM has
)
37 return (PWINE_ACMSTREAM
)has
;
40 /***********************************************************************
41 * acmStreamClose (MSACM32.@)
43 MMRESULT WINAPI
acmStreamClose(HACMSTREAM has
, DWORD fdwClose
)
48 TRACE("(%p, %d)\n", has
, fdwClose
);
50 if ((was
= ACM_GetStream(has
)) == NULL
) {
51 WARN("invalid handle\n");
52 return MMSYSERR_INVALHANDLE
;
54 ret
= MSACM_Message((HACMDRIVER
)was
->pDrv
, ACMDM_STREAM_CLOSE
, (LPARAM
)&was
->drvInst
, 0);
55 if (ret
== MMSYSERR_NOERROR
) {
57 acmDriverClose(was
->hAcmDriver
, 0L);
58 HeapFree(MSACM_hHeap
, 0, was
);
60 TRACE("=> (%d)\n", ret
);
64 /***********************************************************************
65 * acmStreamConvert (MSACM32.@)
67 MMRESULT WINAPI
acmStreamConvert(HACMSTREAM has
, PACMSTREAMHEADER pash
,
71 MMRESULT ret
= MMSYSERR_NOERROR
;
72 PACMDRVSTREAMHEADER padsh
;
74 TRACE("(%p, %p, %d)\n", has
, pash
, fdwConvert
);
76 if ((was
= ACM_GetStream(has
)) == NULL
) {
77 WARN("invalid handle\n");
78 return MMSYSERR_INVALHANDLE
;
80 if (!pash
|| pash
->cbStruct
< sizeof(ACMSTREAMHEADER
)) {
81 WARN("invalid parameter\n");
82 return MMSYSERR_INVALPARAM
;
84 if (!(pash
->fdwStatus
& ACMSTREAMHEADER_STATUSF_PREPARED
)) {
85 WARN("unprepared header\n");
86 return ACMERR_UNPREPARED
;
89 pash
->cbSrcLengthUsed
= 0;
90 pash
->cbDstLengthUsed
= 0;
92 /* Note: the ACMSTREAMHEADER and ACMDRVSTREAMHEADER structs are of same
93 * size. some fields are private to msacm internals, and are exposed
94 * in ACMSTREAMHEADER in the dwReservedDriver array
96 padsh
= (PACMDRVSTREAMHEADER
)pash
;
98 /* check that pointers have not been modified */
99 if (padsh
->pbPreparedSrc
!= padsh
->pbSrc
||
100 padsh
->cbPreparedSrcLength
< padsh
->cbSrcLength
||
101 padsh
->pbPreparedDst
!= padsh
->pbDst
||
102 padsh
->cbPreparedDstLength
< padsh
->cbDstLength
) {
103 WARN("invalid parameter\n");
104 return MMSYSERR_INVALPARAM
;
107 padsh
->fdwConvert
= fdwConvert
;
109 ret
= MSACM_Message((HACMDRIVER
)was
->pDrv
, ACMDM_STREAM_CONVERT
, (LPARAM
)&was
->drvInst
, (LPARAM
)padsh
);
110 if (ret
== MMSYSERR_NOERROR
) {
111 padsh
->fdwStatus
|= ACMSTREAMHEADER_STATUSF_DONE
;
113 TRACE("=> (%d)\n", ret
);
117 /***********************************************************************
118 * acmStreamMessage (MSACM32.@)
120 MMRESULT WINAPI
acmStreamMessage(HACMSTREAM has
, UINT uMsg
, LPARAM lParam1
,
123 FIXME("(%p, %u, %ld, %ld): stub\n", has
, uMsg
, lParam1
, lParam2
);
124 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
125 return MMSYSERR_ERROR
;
128 /***********************************************************************
129 * acmStreamOpen (MSACM32.@)
131 MMRESULT WINAPI
acmStreamOpen(PHACMSTREAM phas
, HACMDRIVER had
,
132 PWAVEFORMATEX pwfxSrc
, PWAVEFORMATEX pwfxDst
,
133 PWAVEFILTER pwfltr
, DWORD_PTR dwCallback
,
134 DWORD_PTR dwInstance
, DWORD fdwOpen
)
141 WAVEFORMATEX wfxSrc
, wfxDst
;
143 TRACE("(%p, %p, %p, %p, %p, %ld, %ld, %d)\n",
144 phas
, had
, pwfxSrc
, pwfxDst
, pwfltr
, dwCallback
, dwInstance
, fdwOpen
);
146 /* NOTE: pwfxSrc and/or pwfxDst can point to a structure smaller than
147 * WAVEFORMATEX so don't use them directly when not sure */
148 if (pwfxSrc
->wFormatTag
== WAVE_FORMAT_PCM
) {
149 memcpy(&wfxSrc
, pwfxSrc
, sizeof(PCMWAVEFORMAT
));
150 wfxSrc
.wBitsPerSample
= pwfxSrc
->wBitsPerSample
;
155 if (pwfxDst
->wFormatTag
== WAVE_FORMAT_PCM
) {
156 memcpy(&wfxDst
, pwfxDst
, sizeof(PCMWAVEFORMAT
));
157 wfxDst
.wBitsPerSample
= pwfxDst
->wBitsPerSample
;
162 TRACE("src [wFormatTag=%u, nChannels=%u, nSamplesPerSec=%u, nAvgBytesPerSec=%u, nBlockAlign=%u, wBitsPerSample=%u, cbSize=%u]\n",
163 pwfxSrc
->wFormatTag
, pwfxSrc
->nChannels
, pwfxSrc
->nSamplesPerSec
, pwfxSrc
->nAvgBytesPerSec
,
164 pwfxSrc
->nBlockAlign
, pwfxSrc
->wBitsPerSample
, pwfxSrc
->cbSize
);
166 TRACE("dst [wFormatTag=%u, nChannels=%u, nSamplesPerSec=%u, nAvgBytesPerSec=%u, nBlockAlign=%u, wBitsPerSample=%u, cbSize=%u]\n",
167 pwfxDst
->wFormatTag
, pwfxDst
->nChannels
, pwfxDst
->nSamplesPerSec
, pwfxDst
->nAvgBytesPerSec
,
168 pwfxDst
->nBlockAlign
, pwfxDst
->wBitsPerSample
, pwfxDst
->cbSize
);
170 /* (WS) In query mode, phas should be NULL. If it is not, then instead
171 * of returning an error we are making sure it is NULL, preventing some
172 * applications that pass garbage for phas from crashing.
174 if (fdwOpen
& ACM_STREAMOPENF_QUERY
) phas
= NULL
;
176 if (pwfltr
&& (pwfxSrc
->wFormatTag
!= pwfxDst
->wFormatTag
)) {
177 WARN("invalid parameter\n");
178 return MMSYSERR_INVALPARAM
;
181 wfxSrcSize
= wfxDstSize
= sizeof(WAVEFORMATEX
);
182 if (pwfxSrc
->wFormatTag
!= WAVE_FORMAT_PCM
) wfxSrcSize
+= pwfxSrc
->cbSize
;
183 if (pwfxDst
->wFormatTag
!= WAVE_FORMAT_PCM
) wfxDstSize
+= pwfxDst
->cbSize
;
185 was
= HeapAlloc(MSACM_hHeap
, 0, sizeof(*was
) + wfxSrcSize
+ wfxDstSize
+
186 ((pwfltr
) ? sizeof(WAVEFILTER
) : 0));
189 return MMSYSERR_NOMEM
;
192 was
->drvInst
.cbStruct
= sizeof(was
->drvInst
);
193 was
->drvInst
.pwfxSrc
= (PWAVEFORMATEX
)((LPSTR
)was
+ sizeof(*was
));
194 memcpy(was
->drvInst
.pwfxSrc
, pwfxSrc
, wfxSrcSize
);
195 was
->drvInst
.pwfxDst
= (PWAVEFORMATEX
)((LPSTR
)was
+ sizeof(*was
) + wfxSrcSize
);
196 memcpy(was
->drvInst
.pwfxDst
, pwfxDst
, wfxDstSize
);
198 was
->drvInst
.pwfltr
= (PWAVEFILTER
)((LPSTR
)was
+ sizeof(*was
) + wfxSrcSize
+ wfxDstSize
);
199 memcpy(was
->drvInst
.pwfltr
, pwfltr
, sizeof(WAVEFILTER
));
201 was
->drvInst
.pwfltr
= NULL
;
203 was
->drvInst
.dwCallback
= dwCallback
;
204 was
->drvInst
.dwInstance
= dwInstance
;
205 was
->drvInst
.fdwOpen
= fdwOpen
;
206 was
->drvInst
.fdwDriver
= 0L;
207 was
->drvInst
.dwDriver
= 0L;
208 /* real value will be stored once ACMDM_STREAM_OPEN succeeds */
209 was
->drvInst
.has
= 0L;
212 if (!(wad
= MSACM_GetDriver(had
))) {
213 ret
= MMSYSERR_INVALPARAM
;
217 was
->obj
.dwType
= WINE_ACMOBJ_STREAM
;
218 was
->obj
.pACMDriverID
= wad
->obj
.pACMDriverID
;
220 was
->hAcmDriver
= 0; /* not to close it in acmStreamClose */
222 ret
= MSACM_Message((HACMDRIVER
)wad
, ACMDM_STREAM_OPEN
, (LPARAM
)&was
->drvInst
, 0L);
223 if (ret
!= MMSYSERR_NOERROR
)
226 PWINE_ACMDRIVERID wadi
;
228 ret
= ACMERR_NOTPOSSIBLE
;
229 for (wadi
= MSACM_pFirstACMDriverID
; wadi
; wadi
= wadi
->pNextACMDriverID
) {
230 if ((wadi
->fdwSupport
& ACMDRIVERDETAILS_SUPPORTF_DISABLED
) ||
231 !MSACM_FindFormatTagInCache(wadi
, pwfxSrc
->wFormatTag
, NULL
) ||
232 !MSACM_FindFormatTagInCache(wadi
, pwfxDst
->wFormatTag
, NULL
))
234 ret
= acmDriverOpen(&had
, (HACMDRIVERID
)wadi
, 0L);
235 if (ret
!= MMSYSERR_NOERROR
)
237 if ((wad
= MSACM_GetDriver(had
)) != 0) {
238 was
->obj
.dwType
= WINE_ACMOBJ_STREAM
;
239 was
->obj
.pACMDriverID
= wad
->obj
.pACMDriverID
;
241 was
->hAcmDriver
= had
;
243 ret
= MSACM_Message((HACMDRIVER
)wad
, ACMDM_STREAM_OPEN
, (LPARAM
)&was
->drvInst
, 0L);
244 TRACE("%s => %08x\n", debugstr_w(wadi
->pszDriverAlias
), ret
);
245 if (ret
== MMSYSERR_NOERROR
) {
246 if (fdwOpen
& ACM_STREAMOPENF_QUERY
) {
247 MSACM_Message((HACMDRIVER
)wad
, ACMDM_STREAM_CLOSE
, (LPARAM
)&was
->drvInst
, 0);
248 acmDriverClose(had
, 0L);
253 /* no match, close this acm driver and try next one */
254 acmDriverClose(had
, 0L);
256 if (ret
!= MMSYSERR_NOERROR
) {
257 ret
= ACMERR_NOTPOSSIBLE
;
261 ret
= MMSYSERR_NOERROR
;
262 was
->drvInst
.has
= (HACMSTREAM
)was
;
263 if (!(fdwOpen
& ACM_STREAMOPENF_QUERY
)) {
265 *phas
= (HACMSTREAM
)was
;
266 TRACE("=> (%d)\n", ret
);
272 HeapFree(MSACM_hHeap
, 0, was
);
273 TRACE("=> (%d)\n", ret
);
278 /***********************************************************************
279 * acmStreamPrepareHeader (MSACM32.@)
281 MMRESULT WINAPI
acmStreamPrepareHeader(HACMSTREAM has
, PACMSTREAMHEADER pash
,
285 MMRESULT ret
= MMSYSERR_NOERROR
;
286 PACMDRVSTREAMHEADER padsh
;
288 TRACE("(%p, %p, %d)\n", has
, pash
, fdwPrepare
);
290 if ((was
= ACM_GetStream(has
)) == NULL
) {
291 WARN("invalid handle\n");
292 return MMSYSERR_INVALHANDLE
;
294 if (!pash
|| pash
->cbStruct
< sizeof(ACMSTREAMHEADER
)) {
295 WARN("invalid parameter\n");
296 return MMSYSERR_INVALPARAM
;
299 ret
= MMSYSERR_INVALFLAG
;
301 /* Note: the ACMSTREAMHEADER and ACMDRVSTREAMHEADER structs are of same
302 * size. some fields are private to msacm internals, and are exposed
303 * in ACMSTREAMHEADER in the dwReservedDriver array
305 padsh
= (PACMDRVSTREAMHEADER
)pash
;
307 padsh
->fdwConvert
= fdwPrepare
;
308 padsh
->padshNext
= NULL
;
309 padsh
->fdwDriver
= padsh
->dwDriver
= 0L;
311 padsh
->fdwPrepared
= 0;
312 padsh
->dwPrepared
= 0;
313 padsh
->pbPreparedSrc
= 0;
314 padsh
->cbPreparedSrcLength
= 0;
315 padsh
->pbPreparedDst
= 0;
316 padsh
->cbPreparedDstLength
= 0;
318 ret
= MSACM_Message((HACMDRIVER
)was
->pDrv
, ACMDM_STREAM_PREPARE
, (LPARAM
)&was
->drvInst
, (LPARAM
)padsh
);
319 if (ret
== MMSYSERR_NOERROR
|| ret
== MMSYSERR_NOTSUPPORTED
) {
320 ret
= MMSYSERR_NOERROR
;
321 padsh
->fdwStatus
&= ~ACMSTREAMHEADER_STATUSF_INQUEUE
;
322 padsh
->fdwStatus
|= ACMSTREAMHEADER_STATUSF_PREPARED
;
323 padsh
->fdwPrepared
= padsh
->fdwStatus
;
324 padsh
->dwPrepared
= 0;
325 padsh
->pbPreparedSrc
= padsh
->pbSrc
;
326 padsh
->cbPreparedSrcLength
= padsh
->cbSrcLength
;
327 padsh
->pbPreparedDst
= padsh
->pbDst
;
328 padsh
->cbPreparedDstLength
= padsh
->cbDstLength
;
330 padsh
->fdwPrepared
= 0;
331 padsh
->dwPrepared
= 0;
332 padsh
->pbPreparedSrc
= 0;
333 padsh
->cbPreparedSrcLength
= 0;
334 padsh
->pbPreparedDst
= 0;
335 padsh
->cbPreparedDstLength
= 0;
337 TRACE("=> (%d)\n", ret
);
341 /***********************************************************************
342 * acmStreamReset (MSACM32.@)
344 MMRESULT WINAPI
acmStreamReset(HACMSTREAM has
, DWORD fdwReset
)
347 MMRESULT ret
= MMSYSERR_NOERROR
;
349 TRACE("(%p, %d)\n", has
, fdwReset
);
352 WARN("invalid flag\n");
353 ret
= MMSYSERR_INVALFLAG
;
354 } else if ((was
= ACM_GetStream(has
)) == NULL
) {
355 WARN("invalid handle\n");
356 return MMSYSERR_INVALHANDLE
;
357 } else if (was
->drvInst
.fdwOpen
& ACM_STREAMOPENF_ASYNC
) {
358 ret
= MSACM_Message((HACMDRIVER
)was
->pDrv
, ACMDM_STREAM_RESET
, (LPARAM
)&was
->drvInst
, 0);
360 TRACE("=> (%d)\n", ret
);
364 /***********************************************************************
365 * acmStreamSize (MSACM32.@)
367 MMRESULT WINAPI
acmStreamSize(HACMSTREAM has
, DWORD cbInput
,
368 LPDWORD pdwOutputBytes
, DWORD fdwSize
)
371 ACMDRVSTREAMSIZE adss
;
374 TRACE("(%p, %d, %p, %d)\n", has
, cbInput
, pdwOutputBytes
, fdwSize
);
376 if ((was
= ACM_GetStream(has
)) == NULL
) {
377 WARN("invalid handle\n");
378 return MMSYSERR_INVALHANDLE
;
380 if ((fdwSize
& ~ACM_STREAMSIZEF_QUERYMASK
) != 0) {
381 WARN("invalid flag\n");
382 return MMSYSERR_INVALFLAG
;
385 *pdwOutputBytes
= 0L;
387 switch (fdwSize
& ACM_STREAMSIZEF_QUERYMASK
) {
388 case ACM_STREAMSIZEF_DESTINATION
:
389 adss
.cbDstLength
= cbInput
;
390 adss
.cbSrcLength
= 0;
392 case ACM_STREAMSIZEF_SOURCE
:
393 adss
.cbSrcLength
= cbInput
;
394 adss
.cbDstLength
= 0;
397 WARN("invalid flag\n");
398 return MMSYSERR_INVALFLAG
;
401 adss
.cbStruct
= sizeof(adss
);
402 adss
.fdwSize
= fdwSize
;
403 ret
= MSACM_Message((HACMDRIVER
)was
->pDrv
, ACMDM_STREAM_SIZE
,
404 (LPARAM
)&was
->drvInst
, (LPARAM
)&adss
);
405 if (ret
== MMSYSERR_NOERROR
) {
406 switch (fdwSize
& ACM_STREAMSIZEF_QUERYMASK
) {
407 case ACM_STREAMSIZEF_DESTINATION
:
408 *pdwOutputBytes
= adss
.cbSrcLength
;
410 case ACM_STREAMSIZEF_SOURCE
:
411 *pdwOutputBytes
= adss
.cbDstLength
;
415 TRACE("=> (%d) [%u]\n", ret
, *pdwOutputBytes
);
419 /***********************************************************************
420 * acmStreamUnprepareHeader (MSACM32.@)
422 MMRESULT WINAPI
acmStreamUnprepareHeader(HACMSTREAM has
, PACMSTREAMHEADER pash
,
426 MMRESULT ret
= MMSYSERR_NOERROR
;
427 PACMDRVSTREAMHEADER padsh
;
429 TRACE("(%p, %p, %d)\n", has
, pash
, fdwUnprepare
);
431 if ((was
= ACM_GetStream(has
)) == NULL
) {
432 WARN("invalid handle\n");
433 return MMSYSERR_INVALHANDLE
;
435 if (!pash
|| pash
->cbStruct
< sizeof(ACMSTREAMHEADER
)) {
436 WARN("invalid parameter\n");
437 return MMSYSERR_INVALPARAM
;
439 if (!(pash
->fdwStatus
& ACMSTREAMHEADER_STATUSF_PREPARED
)) {
440 WARN("unprepared header\n");
441 return ACMERR_UNPREPARED
;
444 /* Note: the ACMSTREAMHEADER and ACMDRVSTREAMHEADER structs are of same
445 * size. some fields are private to msacm internals, and are exposed
446 * in ACMSTREAMHEADER in the dwReservedDriver array
448 padsh
= (PACMDRVSTREAMHEADER
)pash
;
450 /* check that pointers have not been modified */
451 if (padsh
->pbPreparedSrc
!= padsh
->pbSrc
||
452 padsh
->cbPreparedSrcLength
< padsh
->cbSrcLength
||
453 padsh
->pbPreparedDst
!= padsh
->pbDst
||
454 padsh
->cbPreparedDstLength
< padsh
->cbDstLength
) {
455 WARN("invalid parameter\n");
456 return MMSYSERR_INVALPARAM
;
459 padsh
->fdwConvert
= fdwUnprepare
;
461 ret
= MSACM_Message((HACMDRIVER
)was
->pDrv
, ACMDM_STREAM_UNPREPARE
, (LPARAM
)&was
->drvInst
, (LPARAM
)padsh
);
462 if (ret
== MMSYSERR_NOERROR
|| ret
== MMSYSERR_NOTSUPPORTED
) {
463 ret
= MMSYSERR_NOERROR
;
464 padsh
->fdwStatus
&= ~(ACMSTREAMHEADER_STATUSF_INQUEUE
|ACMSTREAMHEADER_STATUSF_PREPARED
);
466 TRACE("=> (%d)\n", ret
);