1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
3 * Wine Wave mapper driver
5 * Copyright 1999,2001 Eric Pouech
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * + better protection against evilish dwUser parameters
24 * + use asynchronous ACM conversion
25 * + don't use callback functions when none is required in open
26 * + the buffer sizes may not be accurate, so there may be some
27 * remaining bytes in src and dst buffers after ACM conversions...
28 * those should be taken care of...
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(msacm);
42 typedef struct tagWAVEMAPDATA {
43 struct tagWAVEMAPDATA* self;
46 HACMSTREAM hAcmStream;
47 /* needed data to filter callbacks. Only needed when hAcmStream is not 0 */
49 DWORD dwClientInstance;
53 static BOOL WAVEMAP_IsData(WAVEMAPDATA* wm)
55 return (!IsBadReadPtr(wm, sizeof(WAVEMAPDATA)) && wm->self == wm);
58 /*======================================================================*
60 *======================================================================*/
62 static void CALLBACK wodCallback(HWAVE hWave, UINT uMsg, DWORD dwInstance,
63 DWORD dwParam1, DWORD dwParam2)
65 WAVEMAPDATA* wom = (WAVEMAPDATA*)dwInstance;
67 TRACE("(0x%x %u %ld %lx %lx);\n", hWave, uMsg, dwInstance, dwParam1, dwParam2);
69 if (!WAVEMAP_IsData(wom)) {
74 if (hWave != wom->hInnerWave && uMsg != WOM_OPEN)
75 ERR("Shouldn't happen (%08x %08x)\n", hWave, wom->hInnerWave);
80 /* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
83 if (wom->hAcmStream) {
84 LPWAVEHDR lpWaveHdrDst = (LPWAVEHDR)dwParam1;
85 PACMSTREAMHEADER ash = (PACMSTREAMHEADER)((LPSTR)lpWaveHdrDst - sizeof(ACMSTREAMHEADER));
86 LPWAVEHDR lpWaveHdrSrc = (LPWAVEHDR)ash->dwUser;
88 lpWaveHdrSrc->dwFlags &= ~WHDR_INQUEUE;
89 lpWaveHdrSrc->dwFlags |= WHDR_DONE;
90 dwParam1 = (DWORD)lpWaveHdrSrc;
94 ERR("Unknown msg %u\n", uMsg);
97 DriverCallback(wom->dwCallback, HIWORD(wom->dwFlags), wom->hOuterWave, uMsg,
98 wom->dwClientInstance, dwParam1, dwParam2);
101 static DWORD wodOpenHelper(WAVEMAPDATA* wom, UINT idx,
102 LPWAVEOPENDESC lpDesc, LPWAVEFORMATEX lpwfx,
107 /* destination is always PCM, so the formulas below apply */
108 lpwfx->nBlockAlign = (lpwfx->nChannels * lpwfx->wBitsPerSample) / 8;
109 lpwfx->nAvgBytesPerSec = lpwfx->nSamplesPerSec * lpwfx->nBlockAlign;
110 if (dwFlags & WAVE_FORMAT_QUERY) {
111 ret = acmStreamOpen(NULL, 0, lpDesc->lpFormat, lpwfx, NULL, 0L, 0L, ACM_STREAMOPENF_QUERY);
113 ret = acmStreamOpen(&wom->hAcmStream, 0, lpDesc->lpFormat, lpwfx, NULL, 0L, 0L, 0L);
115 if (ret == MMSYSERR_NOERROR) {
116 ret = waveOutOpen(&wom->hInnerWave, idx, lpwfx, (DWORD)wodCallback,
117 (DWORD)wom, (dwFlags & ~CALLBACK_TYPEMASK) | CALLBACK_FUNCTION);
118 if (ret != MMSYSERR_NOERROR && !(dwFlags & WAVE_FORMAT_QUERY)) {
119 acmStreamClose(wom->hAcmStream, 0);
126 static DWORD wodOpen(LPDWORD lpdwUser, LPWAVEOPENDESC lpDesc, DWORD dwFlags)
130 WAVEMAPDATA* wom = HeapAlloc(GetProcessHeap(), 0, sizeof(WAVEMAPDATA));
133 TRACE("(%p %p %08lx\n", lpdwUser, lpDesc, dwFlags);
136 return MMSYSERR_NOMEM;
138 ndhi = waveOutGetNumDevs();
139 if (dwFlags & WAVE_MAPPED) {
140 if (lpDesc->uMappedDeviceID >= ndhi) return MMSYSERR_INVALPARAM;
141 ndlo = lpDesc->uMappedDeviceID;
143 dwFlags &= ~WAVE_MAPPED;
148 wom->dwCallback = lpDesc->dwCallback;
149 wom->dwFlags = dwFlags;
150 wom->dwClientInstance = lpDesc->dwInstance;
151 wom->hOuterWave = lpDesc->hWave;
153 for (i = ndlo; i < ndhi; i++) {
154 /* if no ACM stuff is involved, no need to handle callbacks at this
155 * level, this will be done transparently
157 if (waveOutOpen(&wom->hInnerWave, i, lpDesc->lpFormat, (DWORD)wodCallback,
158 (DWORD)wom, (dwFlags & ~CALLBACK_TYPEMASK) | CALLBACK_FUNCTION) == MMSYSERR_NOERROR) {
164 wfx.wFormatTag = WAVE_FORMAT_PCM;
165 wfx.cbSize = 0; /* normally, this field is not used for PCM format, just in case */
166 /* try some ACM stuff */
168 #define TRY(sps,bps) wfx.nSamplesPerSec = (sps); wfx.wBitsPerSample = (bps); \
169 if (wodOpenHelper(wom, i, lpDesc, &wfx, dwFlags) == MMSYSERR_NOERROR) goto found;
171 for (i = ndlo; i < ndhi; i++) {
172 /* first try with same stereo/mono option as source */
173 wfx.nChannels = lpDesc->lpFormat->nChannels;
178 /* 2^3 => 1, 1^3 => 2, so if stereo, try mono (and the other way around) */
184 /* first try with same stereo/mono option as source */
185 wfx.nChannels = lpDesc->lpFormat->nChannels;
190 /* 2^3 => 1, 1^3 => 2, so if stereo, try mono (and the other way around) */
198 HeapFree(GetProcessHeap(), 0, wom);
199 return MMSYSERR_ALLOCATED;
201 if (dwFlags & WAVE_FORMAT_QUERY) {
203 HeapFree(GetProcessHeap(), 0, wom);
205 *lpdwUser = (DWORD)wom;
207 return MMSYSERR_NOERROR;
210 static DWORD wodClose(WAVEMAPDATA* wom)
212 DWORD ret = waveOutClose(wom->hInnerWave);
214 if (ret == MMSYSERR_NOERROR) {
215 if (wom->hAcmStream) {
216 ret = acmStreamClose(wom->hAcmStream, 0);
218 if (ret == MMSYSERR_NOERROR) {
219 HeapFree(GetProcessHeap(), 0, wom);
225 static DWORD wodWrite(WAVEMAPDATA* wom, LPWAVEHDR lpWaveHdrSrc, DWORD dwParam2)
227 PACMSTREAMHEADER ash;
228 LPWAVEHDR lpWaveHdrDst;
230 if (!wom->hAcmStream) {
231 return waveOutWrite(wom->hInnerWave, lpWaveHdrSrc, dwParam2);
234 lpWaveHdrSrc->dwFlags |= WHDR_INQUEUE;
235 ash = (PACMSTREAMHEADER)lpWaveHdrSrc->reserved;
236 /* acmStreamConvert will actually check that the new size is less than initial size */
237 ash->cbSrcLength = lpWaveHdrSrc->dwBufferLength;
238 if (acmStreamConvert(wom->hAcmStream, ash, 0L) != MMSYSERR_NOERROR)
239 return MMSYSERR_ERROR;
241 lpWaveHdrDst = (LPWAVEHDR)((LPSTR)ash + sizeof(ACMSTREAMHEADER));
242 if (ash->cbDstLengthUsed == 0)
244 /* something went wrong in decoding */
245 FIXME("Got 0 length\n");
246 return MMSYSERR_ERROR;
248 lpWaveHdrDst->dwBufferLength = ash->cbDstLengthUsed;
249 return waveOutWrite(wom->hInnerWave, lpWaveHdrDst, sizeof(*lpWaveHdrDst));
252 static DWORD wodPrepare(WAVEMAPDATA* wom, LPWAVEHDR lpWaveHdrSrc, DWORD dwParam2)
254 PACMSTREAMHEADER ash;
257 LPWAVEHDR lpWaveHdrDst;
259 if (!wom->hAcmStream) {
260 return waveOutPrepareHeader(wom->hInnerWave, lpWaveHdrSrc, dwParam2);
262 if (acmStreamSize(wom->hAcmStream, lpWaveHdrSrc->dwBufferLength, &size, ACM_STREAMSIZEF_SOURCE) != MMSYSERR_NOERROR)
263 return MMSYSERR_ERROR;
265 ash = HeapAlloc(GetProcessHeap(), 0, sizeof(ACMSTREAMHEADER) + sizeof(WAVEHDR) + size);
267 return MMSYSERR_NOMEM;
269 ash->cbStruct = sizeof(*ash);
271 ash->dwUser = (DWORD)lpWaveHdrSrc;
272 ash->pbSrc = lpWaveHdrSrc->lpData;
273 ash->cbSrcLength = lpWaveHdrSrc->dwBufferLength;
274 /* ash->cbSrcLengthUsed */
275 ash->dwSrcUser = lpWaveHdrSrc->dwUser; /* FIXME ? */
276 ash->pbDst = (LPSTR)ash + sizeof(ACMSTREAMHEADER) + sizeof(WAVEHDR);
277 ash->cbDstLength = size;
278 /* ash->cbDstLengthUsed */
279 ash->dwDstUser = 0; /* FIXME ? */
280 dwRet = acmStreamPrepareHeader(wom->hAcmStream, ash, 0L);
281 if (dwRet != MMSYSERR_NOERROR)
284 lpWaveHdrDst = (LPWAVEHDR)((LPSTR)ash + sizeof(ACMSTREAMHEADER));
285 lpWaveHdrDst->lpData = ash->pbDst;
286 lpWaveHdrDst->dwBufferLength = size; /* conversion is not done yet */
287 lpWaveHdrDst->dwFlags = 0;
288 lpWaveHdrDst->dwLoops = 0;
289 dwRet = waveOutPrepareHeader(wom->hInnerWave, lpWaveHdrDst, sizeof(*lpWaveHdrDst));
290 if (dwRet != MMSYSERR_NOERROR)
293 lpWaveHdrSrc->reserved = (DWORD)ash;
294 lpWaveHdrSrc->dwFlags = WHDR_PREPARED;
296 return MMSYSERR_NOERROR;
298 TRACE("=> (%ld)\n", dwRet);
299 HeapFree(GetProcessHeap(), 0, ash);
303 static DWORD wodUnprepare(WAVEMAPDATA* wom, LPWAVEHDR lpWaveHdrSrc, DWORD dwParam2)
305 PACMSTREAMHEADER ash;
306 LPWAVEHDR lpWaveHdrDst;
307 DWORD dwRet1, dwRet2;
309 if (!wom->hAcmStream) {
310 return waveOutUnprepareHeader(wom->hInnerWave, lpWaveHdrSrc, dwParam2);
312 ash = (PACMSTREAMHEADER)lpWaveHdrSrc->reserved;
313 dwRet1 = acmStreamUnprepareHeader(wom->hAcmStream, ash, 0L);
315 lpWaveHdrDst = (LPWAVEHDR)((LPSTR)ash + sizeof(ACMSTREAMHEADER));
316 dwRet2 = waveOutUnprepareHeader(wom->hInnerWave, lpWaveHdrDst, sizeof(*lpWaveHdrDst));
318 HeapFree(GetProcessHeap(), 0, ash);
320 lpWaveHdrSrc->dwFlags &= ~WHDR_PREPARED;
321 return (dwRet1 == MMSYSERR_NOERROR) ? dwRet2 : dwRet1;
324 static DWORD wodGetPosition(WAVEMAPDATA* wom, LPMMTIME lpTime, DWORD dwParam2)
327 FIXME("No position conversion done for PCM => non-PCM, returning PCM position\n");
328 return waveOutGetPosition(wom->hInnerWave, lpTime, dwParam2);
331 static DWORD wodGetDevCaps(UINT wDevID, WAVEMAPDATA* wom, LPWAVEOUTCAPSA lpWaveCaps, DWORD dwParam2)
333 /* if opened low driver, forward message */
334 if (WAVEMAP_IsData(wom))
335 return waveOutGetDevCapsA(wom->hInnerWave, lpWaveCaps, dwParam2);
336 /* otherwise, return caps of mapper itself */
337 if (wDevID == (UINT)-1 || wDevID == (UINT16)-1) {
338 lpWaveCaps->wMid = 0x00FF;
339 lpWaveCaps->wPid = 0x0001;
340 lpWaveCaps->vDriverVersion = 0x0100;
341 strcpy(lpWaveCaps->szPname, "Wine wave out mapper");
342 lpWaveCaps->dwFormats =
343 WAVE_FORMAT_4M08 | WAVE_FORMAT_4S08 | WAVE_FORMAT_4M16 | WAVE_FORMAT_4S16 |
344 WAVE_FORMAT_2M08 | WAVE_FORMAT_2S08 | WAVE_FORMAT_2M16 | WAVE_FORMAT_2S16 |
345 WAVE_FORMAT_1M08 | WAVE_FORMAT_1S08 | WAVE_FORMAT_1M16 | WAVE_FORMAT_1S16;
346 lpWaveCaps->wChannels = 2;
347 lpWaveCaps->dwSupport = WAVECAPS_VOLUME | WAVECAPS_LRVOLUME;
349 return MMSYSERR_NOERROR;
351 ERR("This shouldn't happen\n");
352 return MMSYSERR_ERROR;
355 static DWORD wodGetVolume(UINT wDevID, WAVEMAPDATA* wom, LPDWORD lpVol)
357 if (WAVEMAP_IsData(wom))
358 return waveOutGetVolume(wom->hInnerWave, lpVol);
359 return MMSYSERR_NOERROR;
362 static DWORD wodSetVolume(UINT wDevID, WAVEMAPDATA* wom, DWORD vol)
364 if (WAVEMAP_IsData(wom))
365 return waveOutSetVolume(wom->hInnerWave, vol);
366 return MMSYSERR_NOERROR;
369 static DWORD wodPause(WAVEMAPDATA* wom)
371 return waveOutPause(wom->hInnerWave);
374 static DWORD wodRestart(WAVEMAPDATA* wom)
376 return waveOutRestart(wom->hInnerWave);
379 static DWORD wodReset(WAVEMAPDATA* wom)
381 return waveOutReset(wom->hInnerWave);
384 static DWORD wodBreakLoop(WAVEMAPDATA* wom)
386 return waveOutBreakLoop(wom->hInnerWave);
389 static DWORD wodMapperStatus(WAVEMAPDATA* wom, DWORD flags, LPVOID ptr)
392 DWORD ret = MMSYSERR_NOTSUPPORTED;
395 case WAVEOUT_MAPPER_STATUS_DEVICE:
396 ret = waveOutGetID(wom->hInnerWave, &id);
399 case WAVEOUT_MAPPER_STATUS_MAPPED:
400 FIXME("Unsupported flag=%ld\n", flags);
401 *(LPDWORD)ptr = 0; /* FIXME ?? */
403 case WAVEOUT_MAPPER_STATUS_FORMAT:
404 FIXME("Unsupported flag=%ld\n", flags);
405 /* ptr points to a WAVEFORMATEX struct - before or after streaming ? */
409 FIXME("Unsupported flag=%ld\n", flags);
416 /**************************************************************************
417 * wodMessage (MSACMMAP.@)
419 DWORD WINAPI WAVEMAP_wodMessage(UINT wDevID, UINT wMsg, DWORD dwUser,
420 DWORD dwParam1, DWORD dwParam2)
422 TRACE("(%u, %04X, %08lX, %08lX, %08lX);\n",
423 wDevID, wMsg, dwUser, dwParam1, dwParam2);
430 /* FIXME: Pretend this is supported */
432 case WODM_OPEN: return wodOpen ((LPDWORD)dwUser, (LPWAVEOPENDESC)dwParam1,dwParam2);
433 case WODM_CLOSE: return wodClose ((WAVEMAPDATA*)dwUser);
434 case WODM_WRITE: return wodWrite ((WAVEMAPDATA*)dwUser, (LPWAVEHDR)dwParam1, dwParam2);
435 case WODM_PAUSE: return wodPause ((WAVEMAPDATA*)dwUser);
436 case WODM_GETPOS: return wodGetPosition ((WAVEMAPDATA*)dwUser, (LPMMTIME)dwParam1, dwParam2);
437 case WODM_BREAKLOOP: return wodBreakLoop ((WAVEMAPDATA*)dwUser);
438 case WODM_PREPARE: return wodPrepare ((WAVEMAPDATA*)dwUser, (LPWAVEHDR)dwParam1, dwParam2);
439 case WODM_UNPREPARE: return wodUnprepare ((WAVEMAPDATA*)dwUser, (LPWAVEHDR)dwParam1, dwParam2);
440 case WODM_GETDEVCAPS: return wodGetDevCaps (wDevID, (WAVEMAPDATA*)dwUser, (LPWAVEOUTCAPSA)dwParam1,dwParam2);
441 case WODM_GETNUMDEVS: return 1;
442 case WODM_GETPITCH: return MMSYSERR_NOTSUPPORTED;
443 case WODM_SETPITCH: return MMSYSERR_NOTSUPPORTED;
444 case WODM_GETPLAYBACKRATE: return MMSYSERR_NOTSUPPORTED;
445 case WODM_SETPLAYBACKRATE: return MMSYSERR_NOTSUPPORTED;
446 case WODM_GETVOLUME: return wodGetVolume (wDevID, (WAVEMAPDATA*)dwUser, (LPDWORD)dwParam1);
447 case WODM_SETVOLUME: return wodSetVolume (wDevID, (WAVEMAPDATA*)dwUser, dwParam1);
448 case WODM_RESTART: return wodRestart ((WAVEMAPDATA*)dwUser);
449 case WODM_RESET: return wodReset ((WAVEMAPDATA*)dwUser);
450 case WODM_MAPPER_STATUS: return wodMapperStatus ((WAVEMAPDATA*)dwUser, dwParam1, (LPVOID)dwParam2);
452 FIXME("unknown message %d!\n", wMsg);
454 return MMSYSERR_NOTSUPPORTED;
457 /*======================================================================*
459 *======================================================================*/
461 static void CALLBACK widCallback(HWAVE hWave, UINT uMsg, DWORD dwInstance,
462 DWORD dwParam1, DWORD dwParam2)
464 WAVEMAPDATA* wim = (WAVEMAPDATA*)dwInstance;
466 TRACE("(0x%x %u %ld %lx %lx);\n", hWave, uMsg, dwInstance, dwParam1, dwParam2);
468 if (!WAVEMAP_IsData(wim)) {
473 if (hWave != wim->hInnerWave && uMsg != WIM_OPEN)
474 ERR("Shouldn't happen (%08x %08x)\n", hWave, wim->hInnerWave);
479 /* dwParam1 & dwParam2 are supposed to be 0, nothing to do */
482 if (wim->hAcmStream) {
483 LPWAVEHDR lpWaveHdrSrc = (LPWAVEHDR)dwParam1;
484 PACMSTREAMHEADER ash = (PACMSTREAMHEADER)((LPSTR)lpWaveHdrSrc - sizeof(ACMSTREAMHEADER));
485 LPWAVEHDR lpWaveHdrDst = (LPWAVEHDR)ash->dwUser;
487 /* convert data just gotten from waveIn into requested format */
488 if (acmStreamConvert(wim->hAcmStream, ash, 0L) != MMSYSERR_NOERROR) {
489 ERR("ACM conversion failed\n");
492 TRACE("Converted %ld bytes into %ld\n", ash->cbSrcLengthUsed, ash->cbDstLengthUsed);
494 /* and setup the wavehdr to return accordingly */
495 lpWaveHdrDst->dwFlags &= ~WHDR_INQUEUE;
496 lpWaveHdrDst->dwFlags |= WHDR_DONE;
497 lpWaveHdrDst->dwBytesRecorded = ash->cbDstLengthUsed;
498 dwParam1 = (DWORD)lpWaveHdrDst;
502 ERR("Unknown msg %u\n", uMsg);
505 DriverCallback(wim->dwCallback, HIWORD(wim->dwFlags), wim->hOuterWave, uMsg,
506 wim->dwClientInstance, dwParam1, dwParam2);
509 static DWORD widOpenHelper(WAVEMAPDATA* wim, UINT idx,
510 LPWAVEOPENDESC lpDesc, LPWAVEFORMATEX lpwfx,
515 /* source is always PCM, so the formulas below apply */
516 lpwfx->nBlockAlign = (lpwfx->nChannels * lpwfx->wBitsPerSample) / 8;
517 lpwfx->nAvgBytesPerSec = lpwfx->nSamplesPerSec * lpwfx->nBlockAlign;
518 if (dwFlags & WAVE_FORMAT_QUERY) {
519 ret = acmStreamOpen(NULL, 0, lpwfx, lpDesc->lpFormat, NULL, 0L, 0L, ACM_STREAMOPENF_QUERY);
521 ret = acmStreamOpen(&wim->hAcmStream, 0, lpwfx, lpDesc->lpFormat, NULL, 0L, 0L, 0L);
523 if (ret == MMSYSERR_NOERROR) {
524 ret = waveInOpen(&wim->hInnerWave, idx, lpwfx, (DWORD)widCallback,
525 (DWORD)wim, (dwFlags & ~CALLBACK_TYPEMASK) | CALLBACK_FUNCTION);
526 if (ret != MMSYSERR_NOERROR && !(dwFlags & WAVE_FORMAT_QUERY)) {
527 acmStreamClose(wim->hAcmStream, 0);
534 static DWORD widOpen(LPDWORD lpdwUser, LPWAVEOPENDESC lpDesc, DWORD dwFlags)
538 WAVEMAPDATA* wim = HeapAlloc(GetProcessHeap(), 0, sizeof(WAVEMAPDATA));
541 TRACE("(%p %p %08lx)\n", lpdwUser, lpDesc, dwFlags);
544 return MMSYSERR_NOMEM;
547 wim->dwCallback = lpDesc->dwCallback;
548 wim->dwFlags = dwFlags;
549 wim->dwClientInstance = lpDesc->dwInstance;
550 wim->hOuterWave = lpDesc->hWave;
552 ndhi = waveOutGetNumDevs();
553 if (dwFlags & WAVE_MAPPED) {
554 if (lpDesc->uMappedDeviceID >= ndhi) return MMSYSERR_INVALPARAM;
555 ndlo = lpDesc->uMappedDeviceID;
557 dwFlags &= ~WAVE_MAPPED;
562 for (i = ndlo; i < ndhi; i++) {
563 if (waveInOpen(&wim->hInnerWave, i, lpDesc->lpFormat, (DWORD)widCallback,
564 (DWORD)wim, (dwFlags & ~CALLBACK_TYPEMASK) | CALLBACK_FUNCTION) == MMSYSERR_NOERROR) {
569 wfx.wFormatTag = WAVE_FORMAT_PCM;
570 wfx.cbSize = 0; /* normally, this field is not used for PCM format, just in case */
571 /* try some ACM stuff */
573 #define TRY(sps,bps) wfx.nSamplesPerSec = (sps); wfx.wBitsPerSample = (bps); \
574 if (widOpenHelper(wim, i, lpDesc, &wfx, dwFlags) == MMSYSERR_NOERROR) goto found;
576 for (i = ndlo; i < ndhi; i++) {
577 /* first try with same stereo/mono option as source */
578 wfx.nChannels = lpDesc->lpFormat->nChannels;
583 /* 2^3 => 1, 1^3 => 2, so if stereo, try mono (and the other way around) */
591 HeapFree(GetProcessHeap(), 0, wim);
592 return MMSYSERR_ALLOCATED;
594 if (dwFlags & WAVE_FORMAT_QUERY) {
596 HeapFree(GetProcessHeap(), 0, wim);
598 *lpdwUser = (DWORD)wim;
600 TRACE("Ok (stream=%08lx)\n", (DWORD)wim->hAcmStream);
601 return MMSYSERR_NOERROR;
604 static DWORD widClose(WAVEMAPDATA* wim)
606 DWORD ret = waveInClose(wim->hInnerWave);
608 if (ret == MMSYSERR_NOERROR) {
609 if (wim->hAcmStream) {
610 ret = acmStreamClose(wim->hAcmStream, 0);
612 if (ret == MMSYSERR_NOERROR) {
613 HeapFree(GetProcessHeap(), 0, wim);
619 static DWORD widAddBuffer(WAVEMAPDATA* wim, LPWAVEHDR lpWaveHdrDst, DWORD dwParam2)
621 PACMSTREAMHEADER ash;
622 LPWAVEHDR lpWaveHdrSrc;
624 if (!wim->hAcmStream) {
625 return waveInAddBuffer(wim->hInnerWave, lpWaveHdrDst, dwParam2);
628 lpWaveHdrDst->dwFlags |= WHDR_INQUEUE;
629 ash = (PACMSTREAMHEADER)lpWaveHdrDst->reserved;
631 lpWaveHdrSrc = (LPWAVEHDR)((LPSTR)ash + sizeof(ACMSTREAMHEADER));
632 return waveInAddBuffer(wim->hInnerWave, lpWaveHdrSrc, sizeof(*lpWaveHdrSrc));
635 static DWORD widPrepare(WAVEMAPDATA* wim, LPWAVEHDR lpWaveHdrDst, DWORD dwParam2)
637 PACMSTREAMHEADER ash;
640 LPWAVEHDR lpWaveHdrSrc;
642 if (!wim->hAcmStream) {
643 return waveInPrepareHeader(wim->hInnerWave, lpWaveHdrDst, dwParam2);
645 if (acmStreamSize(wim->hAcmStream, lpWaveHdrDst->dwBufferLength, &size,
646 ACM_STREAMSIZEF_DESTINATION) != MMSYSERR_NOERROR)
647 return MMSYSERR_ERROR;
649 ash = HeapAlloc(GetProcessHeap(), 0, sizeof(ACMSTREAMHEADER) + sizeof(WAVEHDR) + size);
651 return MMSYSERR_NOMEM;
653 ash->cbStruct = sizeof(*ash);
655 ash->dwUser = (DWORD)lpWaveHdrDst;
656 ash->pbSrc = (LPSTR)ash + sizeof(ACMSTREAMHEADER) + sizeof(WAVEHDR);
657 ash->cbSrcLength = size;
658 /* ash->cbSrcLengthUsed */
659 ash->dwSrcUser = 0L; /* FIXME ? */
660 ash->pbDst = lpWaveHdrDst->lpData;
661 ash->cbDstLength = lpWaveHdrDst->dwBufferLength;
662 /* ash->cbDstLengthUsed */
663 ash->dwDstUser = lpWaveHdrDst->dwUser; /* FIXME ? */
664 dwRet = acmStreamPrepareHeader(wim->hAcmStream, ash, 0L);
665 if (dwRet != MMSYSERR_NOERROR)
668 lpWaveHdrSrc = (LPWAVEHDR)((LPSTR)ash + sizeof(ACMSTREAMHEADER));
669 lpWaveHdrSrc->lpData = ash->pbSrc;
670 lpWaveHdrSrc->dwBufferLength = size; /* conversion is not done yet */
671 lpWaveHdrSrc->dwFlags = 0;
672 lpWaveHdrSrc->dwLoops = 0;
673 dwRet = waveInPrepareHeader(wim->hInnerWave, lpWaveHdrSrc, sizeof(*lpWaveHdrSrc));
674 if (dwRet != MMSYSERR_NOERROR)
677 lpWaveHdrDst->reserved = (DWORD)ash;
678 lpWaveHdrDst->dwFlags = WHDR_PREPARED;
680 return MMSYSERR_NOERROR;
682 TRACE("=> (%ld)\n", dwRet);
683 HeapFree(GetProcessHeap(), 0, ash);
687 static DWORD widUnprepare(WAVEMAPDATA* wim, LPWAVEHDR lpWaveHdrDst, DWORD dwParam2)
689 PACMSTREAMHEADER ash;
690 LPWAVEHDR lpWaveHdrSrc;
691 DWORD dwRet1, dwRet2;
693 if (!wim->hAcmStream) {
694 return waveInUnprepareHeader(wim->hInnerWave, lpWaveHdrDst, dwParam2);
696 ash = (PACMSTREAMHEADER)lpWaveHdrDst->reserved;
697 dwRet1 = acmStreamUnprepareHeader(wim->hAcmStream, ash, 0L);
699 lpWaveHdrSrc = (LPWAVEHDR)((LPSTR)ash + sizeof(ACMSTREAMHEADER));
700 dwRet2 = waveInUnprepareHeader(wim->hInnerWave, lpWaveHdrSrc, sizeof(*lpWaveHdrSrc));
702 HeapFree(GetProcessHeap(), 0, ash);
704 lpWaveHdrDst->dwFlags &= ~WHDR_PREPARED;
705 return (dwRet1 == MMSYSERR_NOERROR) ? dwRet2 : dwRet1;
708 static DWORD widGetPosition(WAVEMAPDATA* wim, LPMMTIME lpTime, DWORD dwParam2)
711 FIXME("No position conversion done for PCM => non-PCM, returning PCM position\n");
712 return waveInGetPosition(wim->hInnerWave, lpTime, dwParam2);
715 static DWORD widGetDevCaps(UINT wDevID, WAVEMAPDATA* wim, LPWAVEINCAPSA lpWaveCaps, DWORD dwParam2)
717 /* if opened low driver, forward message */
718 if (WAVEMAP_IsData(wim))
719 return waveInGetDevCapsA(wim->hInnerWave, lpWaveCaps, dwParam2);
720 /* otherwise, return caps of mapper itself */
721 if (wDevID == (UINT)-1 || wDevID == (UINT16)-1) {
722 lpWaveCaps->wMid = 0x00FF;
723 lpWaveCaps->wPid = 0x0001;
724 lpWaveCaps->vDriverVersion = 0x0001;
725 strcpy(lpWaveCaps->szPname, "Wine wave in mapper");
726 lpWaveCaps->dwFormats =
727 WAVE_FORMAT_4M08 | WAVE_FORMAT_4S08 | WAVE_FORMAT_4M16 | WAVE_FORMAT_4S16 |
728 WAVE_FORMAT_2M08 | WAVE_FORMAT_2S08 | WAVE_FORMAT_2M16 | WAVE_FORMAT_2S16 |
729 WAVE_FORMAT_1M08 | WAVE_FORMAT_1S08 | WAVE_FORMAT_1M16 | WAVE_FORMAT_1S16;
730 lpWaveCaps->wChannels = 2;
731 return MMSYSERR_NOERROR;
733 ERR("This shouldn't happen\n");
734 return MMSYSERR_ERROR;
737 static DWORD widStop(WAVEMAPDATA* wim)
739 return waveInStop(wim->hInnerWave);
742 static DWORD widStart(WAVEMAPDATA* wim)
744 return waveInStart(wim->hInnerWave);
747 static DWORD widReset(WAVEMAPDATA* wim)
749 return waveInReset(wim->hInnerWave);
752 static DWORD widMapperStatus(WAVEMAPDATA* wim, DWORD flags, LPVOID ptr)
755 DWORD ret = MMSYSERR_NOTSUPPORTED;
758 case WAVEIN_MAPPER_STATUS_DEVICE:
759 ret = waveInGetID(wim->hInnerWave, &id);
762 case WAVEIN_MAPPER_STATUS_MAPPED:
763 FIXME("Unsupported yet flag=%ld\n", flags);
764 *(LPDWORD)ptr = 0; /* FIXME ?? */
766 case WAVEIN_MAPPER_STATUS_FORMAT:
767 FIXME("Unsupported flag=%ld\n", flags);
768 /* ptr points to a WAVEFORMATEX struct - before or after streaming ? */
769 *(LPDWORD)ptr = 0; /* FIXME ?? */
772 FIXME("Unsupported flag=%ld\n", flags);
779 /**************************************************************************
780 * widMessage (MSACMMAP.@)
782 DWORD WINAPI WAVEMAP_widMessage(WORD wDevID, WORD wMsg, DWORD dwUser,
783 DWORD dwParam1, DWORD dwParam2)
785 TRACE("(%u, %04X, %08lX, %08lX, %08lX);\n",
786 wDevID, wMsg, dwUser, dwParam1, dwParam2);
793 /* FIXME: Pretend this is supported */
796 case WIDM_OPEN: return widOpen ((LPDWORD)dwUser, (LPWAVEOPENDESC)dwParam1, dwParam2);
797 case WIDM_CLOSE: return widClose ((WAVEMAPDATA*)dwUser);
799 case WIDM_ADDBUFFER: return widAddBuffer ((WAVEMAPDATA*)dwUser, (LPWAVEHDR)dwParam1, dwParam2);
800 case WIDM_PREPARE: return widPrepare ((WAVEMAPDATA*)dwUser, (LPWAVEHDR)dwParam1, dwParam2);
801 case WIDM_UNPREPARE: return widUnprepare ((WAVEMAPDATA*)dwUser, (LPWAVEHDR)dwParam1, dwParam2);
802 case WIDM_GETDEVCAPS: return widGetDevCaps (wDevID, (WAVEMAPDATA*)dwUser, (LPWAVEINCAPSA)dwParam1, dwParam2);
803 case WIDM_GETNUMDEVS: return 1;
804 case WIDM_GETPOS: return widGetPosition ((WAVEMAPDATA*)dwUser, (LPMMTIME)dwParam1, dwParam2);
805 case WIDM_RESET: return widReset ((WAVEMAPDATA*)dwUser);
806 case WIDM_START: return widStart ((WAVEMAPDATA*)dwUser);
807 case WIDM_STOP: return widStop ((WAVEMAPDATA*)dwUser);
808 case WIDM_MAPPER_STATUS: return widMapperStatus ((WAVEMAPDATA*)dwUser, dwParam1, (LPVOID)dwParam2);
810 FIXME("unknown message %u!\n", wMsg);
812 return MMSYSERR_NOTSUPPORTED;
815 /*======================================================================*
817 *======================================================================*/
819 static struct WINE_WAVEMAP* oss = NULL;
821 /**************************************************************************
822 * WAVEMAP_drvOpen [internal]
824 static DWORD WAVEMAP_drvOpen(LPSTR str)
829 /* I know, this is ugly, but who cares... */
830 oss = (struct WINE_WAVEMAP*)1;
834 /**************************************************************************
835 * WAVEMAP_drvClose [internal]
837 static DWORD WAVEMAP_drvClose(DWORD dwDevID)
846 /**************************************************************************
847 * DriverProc (MSACMMAP.@)
849 LONG CALLBACK WAVEMAP_DriverProc(DWORD dwDevID, HDRVR hDriv, DWORD wMsg,
850 DWORD dwParam1, DWORD dwParam2)
852 TRACE("(%08lX, %04X, %08lX, %08lX, %08lX)\n",
853 dwDevID, hDriv, wMsg, dwParam1, dwParam2);
856 case DRV_LOAD: return 1;
857 case DRV_FREE: return 1;
858 case DRV_OPEN: return WAVEMAP_drvOpen((LPSTR)dwParam1);
859 case DRV_CLOSE: return WAVEMAP_drvClose(dwDevID);
860 case DRV_ENABLE: return 1;
861 case DRV_DISABLE: return 1;
862 case DRV_QUERYCONFIGURE: return 1;
863 case DRV_CONFIGURE: MessageBoxA(0, "WAVEMAP MultiMedia Driver !", "OSS Driver", MB_OK); return 1;
864 case DRV_INSTALL: return DRVCNF_RESTART;
865 case DRV_REMOVE: return DRVCNF_RESTART;
867 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);