/*********************************************************************** * acmFormatDetailsW (MSACM32.@) */ MMRESULT WINAPI acmFormatDetailsW(HACMDRIVER had, PACMFORMATDETAILSW pafd, DWORD fdwDetails) { MMRESULT mmr; static const WCHAR fmt1[] = {'%','d',' ','H','z',0}; static const WCHAR fmt2[] = {';',' ','%','d',' ','b','i','t','s',0}; TRACE("(%p, %p, %d)\n", had, pafd, fdwDetails); if (pafd->cbStruct < sizeof(*pafd)) return MMSYSERR_INVALPARAM; switch (fdwDetails) { case ACM_FORMATDETAILSF_FORMAT: if (pafd->dwFormatTag != pafd->pwfx->wFormatTag) { mmr = MMSYSERR_INVALPARAM; break; } if (had == NULL) { PWINE_ACMDRIVERID padid; mmr = ACMERR_NOTPOSSIBLE; for (padid = MSACM_pFirstACMDriverID; padid; padid = padid->pNextACMDriverID) { /* should check for codec only */ if (!(padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED) && acmDriverOpen(&had, (HACMDRIVERID)padid, 0) == 0) { mmr = MSACM_Message(had, ACMDM_FORMAT_DETAILS, (LPARAM)pafd, fdwDetails); acmDriverClose(had, 0); if (mmr == MMSYSERR_NOERROR) break; } } } else { mmr = MSACM_Message(had, ACMDM_FORMAT_DETAILS, (LPARAM)pafd, fdwDetails); } break; case ACM_FORMATDETAILSF_INDEX: /* should check pafd->dwFormatIndex < aftd->cStandardFormats */ mmr = MSACM_Message(had, ACMDM_FORMAT_DETAILS, (LPARAM)pafd, fdwDetails); break; default: WARN("Unknown fdwDetails %08x\n", fdwDetails); mmr = MMSYSERR_INVALFLAG; break; } if (mmr == MMSYSERR_NOERROR && pafd->szFormat[0] == 0) { wsprintfW(pafd->szFormat, fmt1, pafd->pwfx->nSamplesPerSec); if (pafd->pwfx->wBitsPerSample) { wsprintfW(pafd->szFormat + lstrlenW(pafd->szFormat), fmt2, pafd->pwfx->wBitsPerSample); } MultiByteToWideChar( CP_ACP, 0, (pafd->pwfx->nChannels == 1) ? "; Mono" : "; Stereo", -1, pafd->szFormat + strlenW(pafd->szFormat), sizeof(pafd->szFormat)/sizeof(WCHAR) - strlenW(pafd->szFormat) ); } TRACE("=> %d\n", mmr); return mmr; }
/*********************************************************************** * acmFilterDetailsW (MSACM32.@) */ MMRESULT WINAPI acmFilterDetailsW(HACMDRIVER had, PACMFILTERDETAILSW pafd, DWORD fdwDetails) { MMRESULT mmr; ACMFILTERTAGDETAILSA aftd; TRACE("(%p, %p, %d)\n", had, pafd, fdwDetails); memset(&aftd, 0, sizeof(aftd)); aftd.cbStruct = sizeof(aftd); if (pafd->cbStruct < sizeof(*pafd)) return MMSYSERR_INVALPARAM; switch (fdwDetails) { case ACM_FILTERDETAILSF_FILTER: if (pafd->dwFilterTag != pafd->pwfltr->dwFilterTag) { mmr = MMSYSERR_INVALPARAM; break; } if (had == NULL) { PWINE_ACMDRIVERID padid; mmr = ACMERR_NOTPOSSIBLE; for (padid = MSACM_pFirstACMDriverID; padid; padid = padid->pNextACMDriverID) { /* should check for codec only */ if (!(padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED) && acmDriverOpen(&had, (HACMDRIVERID)padid, 0) == 0) { mmr = MSACM_Message(had, ACMDM_FILTER_DETAILS, (LPARAM)pafd, (LPARAM)fdwDetails); acmDriverClose(had, 0); if (mmr == MMSYSERR_NOERROR) break; } } } else { mmr = MSACM_Message(had, ACMDM_FILTER_DETAILS, (LPARAM)pafd, fdwDetails); } break; case ACM_FILTERDETAILSF_INDEX: /* should check pafd->dwFilterIndex < aftd->cStandardFilters */ mmr = MSACM_Message(had, ACMDM_FILTER_DETAILS, (LPARAM)pafd, fdwDetails); break; default: WARN("Unknown fdwDetails %08x\n", fdwDetails); mmr = MMSYSERR_INVALFLAG; break; } TRACE("=> %d\n", mmr); return mmr; }
/*********************************************************************** * acmFormatSuggest (MSACM32.@) */ MMRESULT WINAPI acmFormatSuggest(HACMDRIVER had, PWAVEFORMATEX pwfxSrc, PWAVEFORMATEX pwfxDst, DWORD cbwfxDst, DWORD fdwSuggest) { ACMDRVFORMATSUGGEST adfg; MMRESULT mmr; TRACE("(%p, %p, %p, %d, %d)\n", had, pwfxSrc, pwfxDst, cbwfxDst, fdwSuggest); if (!pwfxSrc || !pwfxDst) return MMSYSERR_INVALPARAM; if (fdwSuggest & ~(ACM_FORMATSUGGESTF_NCHANNELS|ACM_FORMATSUGGESTF_NSAMPLESPERSEC| ACM_FORMATSUGGESTF_WBITSPERSAMPLE|ACM_FORMATSUGGESTF_WFORMATTAG)) return MMSYSERR_INVALFLAG; adfg.cbStruct = sizeof(adfg); adfg.fdwSuggest = fdwSuggest; adfg.pwfxSrc = pwfxSrc; adfg.cbwfxSrc = (pwfxSrc->wFormatTag == WAVE_FORMAT_PCM) ? sizeof(WAVEFORMATEX) : (sizeof(WAVEFORMATEX) + pwfxSrc->cbSize); adfg.pwfxDst = pwfxDst; adfg.cbwfxDst = cbwfxDst; if (had == NULL) { PWINE_ACMDRIVERID padid; /* MS doc says: ACM finds the best suggestion. * Well, first found will be the "best" */ mmr = ACMERR_NOTPOSSIBLE; for (padid = MSACM_pFirstACMDriverID; padid; padid = padid->pNextACMDriverID) { /* should check for codec only */ if ((padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED) || acmDriverOpen(&had, (HACMDRIVERID)padid, 0) != MMSYSERR_NOERROR) continue; if (MSACM_Message(had, ACMDM_FORMAT_SUGGEST, (LPARAM)&adfg, 0L) == MMSYSERR_NOERROR) { mmr = MMSYSERR_NOERROR; break; } acmDriverClose(had, 0); } } else { mmr = MSACM_Message(had, ACMDM_FORMAT_SUGGEST, (LPARAM)&adfg, 0L); } return mmr; }
/*********************************************************************** * MSACM_FillCache */ static BOOL MSACM_FillCache(PWINE_ACMDRIVERID padid) { HACMDRIVER had = 0; unsigned int ntag; ACMDRIVERDETAILSW add; ACMFORMATTAGDETAILSW aftd; if (acmDriverOpen(&had, (HACMDRIVERID)padid, 0) != 0) return FALSE; padid->aFormatTag = NULL; add.cbStruct = sizeof(add); if (MSACM_Message(had, ACMDM_DRIVER_DETAILS, (LPARAM)&add, 0)) goto errCleanUp; if (add.cFormatTags > 0) { padid->aFormatTag = HeapAlloc(MSACM_hHeap, HEAP_ZERO_MEMORY, add.cFormatTags * sizeof(padid->aFormatTag[0])); if (!padid->aFormatTag) goto errCleanUp; } padid->cFormatTags = add.cFormatTags; padid->cFilterTags = add.cFilterTags; padid->fdwSupport = add.fdwSupport; aftd.cbStruct = sizeof(aftd); for (ntag = 0; ntag < add.cFormatTags; ntag++) { aftd.dwFormatTagIndex = ntag; if (MSACM_Message(had, ACMDM_FORMATTAG_DETAILS, (LPARAM)&aftd, ACM_FORMATTAGDETAILSF_INDEX)) { TRACE("IIOs (%s)\n", debugstr_w(padid->pszDriverAlias)); goto errCleanUp; } padid->aFormatTag[ntag].dwFormatTag = aftd.dwFormatTag; padid->aFormatTag[ntag].cbwfx = aftd.cbFormatSize; } acmDriverClose(had, 0); return TRUE; errCleanUp: if (had) acmDriverClose(had, 0); HeapFree(MSACM_hHeap, 0, padid->aFormatTag); padid->aFormatTag = NULL; return FALSE; }
/*********************************************************************** * acmStreamSize (MSACM32.@) */ MMRESULT WINAPI acmStreamSize(HACMSTREAM has, DWORD cbInput, LPDWORD pdwOutputBytes, DWORD fdwSize) { PWINE_ACMSTREAM was; ACMDRVSTREAMSIZE adss; MMRESULT ret; TRACE("(%p, %d, %p, %d)\n", has, cbInput, pdwOutputBytes, fdwSize); if ((was = ACM_GetStream(has)) == NULL) { WARN("invalid handle\n"); return MMSYSERR_INVALHANDLE; } if ((fdwSize & ~ACM_STREAMSIZEF_QUERYMASK) != 0) { WARN("invalid flag\n"); return MMSYSERR_INVALFLAG; } *pdwOutputBytes = 0L; switch (fdwSize & ACM_STREAMSIZEF_QUERYMASK) { case ACM_STREAMSIZEF_DESTINATION: adss.cbDstLength = cbInput; adss.cbSrcLength = 0; break; case ACM_STREAMSIZEF_SOURCE: adss.cbSrcLength = cbInput; adss.cbDstLength = 0; break; default: WARN("invalid flag\n"); return MMSYSERR_INVALFLAG; } adss.cbStruct = sizeof(adss); adss.fdwSize = fdwSize; ret = MSACM_Message((HACMDRIVER)was->pDrv, ACMDM_STREAM_SIZE, (LPARAM)&was->drvInst, (LPARAM)&adss); if (ret == MMSYSERR_NOERROR) { switch (fdwSize & ACM_STREAMSIZEF_QUERYMASK) { case ACM_STREAMSIZEF_DESTINATION: *pdwOutputBytes = adss.cbSrcLength; break; case ACM_STREAMSIZEF_SOURCE: *pdwOutputBytes = adss.cbDstLength; break; } } TRACE("=> (%d) [%u]\n", ret, *pdwOutputBytes); return ret; }
/*********************************************************************** * acmStreamConvert (MSACM32.@) */ MMRESULT WINAPI acmStreamConvert(HACMSTREAM has, PACMSTREAMHEADER pash, DWORD fdwConvert) { PWINE_ACMSTREAM was; MMRESULT ret = MMSYSERR_NOERROR; PACMDRVSTREAMHEADER padsh; TRACE("(%p, %p, %d)\n", has, pash, fdwConvert); if ((was = ACM_GetStream(has)) == NULL) { WARN("invalid handle\n"); return MMSYSERR_INVALHANDLE; } if (!pash || pash->cbStruct < sizeof(ACMSTREAMHEADER)) { WARN("invalid parameter\n"); return MMSYSERR_INVALPARAM; } if (!(pash->fdwStatus & ACMSTREAMHEADER_STATUSF_PREPARED)) { WARN("unprepared header\n"); return ACMERR_UNPREPARED; } pash->cbSrcLengthUsed = 0; pash->cbDstLengthUsed = 0; /* Note: the ACMSTREAMHEADER and ACMDRVSTREAMHEADER structs are of same * size. some fields are private to msacm internals, and are exposed * in ACMSTREAMHEADER in the dwReservedDriver array */ padsh = (PACMDRVSTREAMHEADER)pash; /* check that pointers have not been modified */ if (padsh->pbPreparedSrc != padsh->pbSrc || padsh->cbPreparedSrcLength < padsh->cbSrcLength || padsh->pbPreparedDst != padsh->pbDst || padsh->cbPreparedDstLength < padsh->cbDstLength) { WARN("invalid parameter\n"); return MMSYSERR_INVALPARAM; } padsh->fdwConvert = fdwConvert; ret = MSACM_Message((HACMDRIVER)was->pDrv, ACMDM_STREAM_CONVERT, (LPARAM)&was->drvInst, (LPARAM)padsh); if (ret == MMSYSERR_NOERROR) { padsh->fdwStatus |= ACMSTREAMHEADER_STATUSF_DONE; } TRACE("=> (%d)\n", ret); return ret; }
/*********************************************************************** * acmStreamReset (MSACM32.@) */ MMRESULT WINAPI acmStreamReset(HACMSTREAM has, DWORD fdwReset) { PWINE_ACMSTREAM was; MMRESULT ret = MMSYSERR_NOERROR; TRACE("(%p, %d)\n", has, fdwReset); if (fdwReset) { WARN("invalid flag\n"); ret = MMSYSERR_INVALFLAG; } else if ((was = ACM_GetStream(has)) == NULL) { WARN("invalid handle\n"); return MMSYSERR_INVALHANDLE; } else if (was->drvInst.fdwOpen & ACM_STREAMOPENF_ASYNC) { ret = MSACM_Message((HACMDRIVER)was->pDrv, ACMDM_STREAM_RESET, (LPARAM)&was->drvInst, 0); } TRACE("=> (%d)\n", ret); return ret; }
/*********************************************************************** * acmStreamUnprepareHeader (MSACM32.@) */ MMRESULT WINAPI acmStreamUnprepareHeader(HACMSTREAM has, PACMSTREAMHEADER pash, DWORD fdwUnprepare) { PWINE_ACMSTREAM was; MMRESULT ret = MMSYSERR_NOERROR; PACMDRVSTREAMHEADER padsh; TRACE("(%p, %p, %d)\n", has, pash, fdwUnprepare); if ((was = ACM_GetStream(has)) == NULL) { WARN("invalid handle\n"); return MMSYSERR_INVALHANDLE; } if (!pash || pash->cbStruct < sizeof(ACMSTREAMHEADER)) { WARN("invalid parameter\n"); return MMSYSERR_INVALPARAM; } if (!(pash->fdwStatus & ACMSTREAMHEADER_STATUSF_PREPARED)) { WARN("unprepared header\n"); return ACMERR_UNPREPARED; } /* Note: the ACMSTREAMHEADER and ACMDRVSTREAMHEADER structs are of same * size. some fields are private to msacm internals, and are exposed * in ACMSTREAMHEADER in the dwReservedDriver array */ padsh = (PACMDRVSTREAMHEADER)pash; if (!ACM_ValidatePointers(padsh)) { WARN("invalid parameter\n"); return MMSYSERR_INVALPARAM; } padsh->fdwConvert = fdwUnprepare; ret = MSACM_Message((HACMDRIVER)was->pDrv, ACMDM_STREAM_UNPREPARE, (LPARAM)&was->drvInst, (LPARAM)padsh); if (ret == MMSYSERR_NOERROR || ret == MMSYSERR_NOTSUPPORTED) { ret = MMSYSERR_NOERROR; padsh->fdwStatus &= ~(ACMSTREAMHEADER_STATUSF_INQUEUE|ACMSTREAMHEADER_STATUSF_PREPARED); } TRACE("=> (%d)\n", ret); return ret; }
/*********************************************************************** * acmStreamClose (MSACM32.@) */ MMRESULT WINAPI acmStreamClose(HACMSTREAM has, DWORD fdwClose) { PWINE_ACMSTREAM was; MMRESULT ret; TRACE("(%p, %d)\n", has, fdwClose); if ((was = ACM_GetStream(has)) == NULL) { WARN("invalid handle\n"); return MMSYSERR_INVALHANDLE; } ret = MSACM_Message((HACMDRIVER)was->pDrv, ACMDM_STREAM_CLOSE, (LPARAM)&was->drvInst, 0); if (ret == MMSYSERR_NOERROR) { if (was->hAcmDriver) acmDriverClose(was->hAcmDriver, 0L); HeapFree(MSACM_hHeap, 0, was); } TRACE("=> (%d)\n", ret); return ret; }
/*********************************************************************** * acmDriverDetailsW (MSACM32.@) */ MMRESULT WINAPI acmDriverDetailsW(HACMDRIVERID hadid, PACMDRIVERDETAILSW padd, DWORD fdwDetails) { HACMDRIVER acmDrvr; MMRESULT mmr; TRACE("(%p, %p, %08x)\n", hadid, padd, fdwDetails); if (!padd) { WARN("invalid parameter\n"); return MMSYSERR_INVALPARAM; } if (padd->cbStruct < 4) { WARN("invalid parameter\n"); return MMSYSERR_INVALPARAM; } if (fdwDetails) { WARN("invalid flag\n"); return MMSYSERR_INVALFLAG; } mmr = acmDriverOpen(&acmDrvr, hadid, 0); if (mmr == MMSYSERR_NOERROR) { ACMDRIVERDETAILSW paddw; paddw.cbStruct = sizeof(paddw); mmr = MSACM_Message(acmDrvr, ACMDM_DRIVER_DETAILS, (LPARAM)&paddw, 0); acmDriverClose(acmDrvr, 0); paddw.cbStruct = min(padd->cbStruct, sizeof(*padd)); memcpy(padd, &paddw, paddw.cbStruct); } else if (mmr == MMSYSERR_NODRIVER) return MMSYSERR_NOTSUPPORTED; return mmr; }
/*********************************************************************** * acmFormatTagEnumW (MSACM32.@) */ MMRESULT WINAPI acmFormatTagEnumW(HACMDRIVER had, PACMFORMATTAGDETAILSW paftd, ACMFORMATTAGENUMCBW fnCallback, DWORD dwInstance, DWORD fdwEnum) { PWINE_ACMDRIVERID padid; unsigned int i; BOOL bPcmDone = FALSE; TRACE("(%p, %p, %p, %d, %d)\n", had, paftd, fnCallback, dwInstance, fdwEnum); if (!paftd) return MMSYSERR_INVALPARAM; if (paftd->cbStruct < sizeof(*paftd)) return MMSYSERR_INVALPARAM; if (fdwEnum != 0) return MMSYSERR_INVALFLAG; /* (WS) MSDN info page says that if had != 0, then we should find * the specific driver to get its tags from. Therefore I'm removing * the FIXME call and adding a search block below. It also seems * that the lack of this functionality was the responsible for * codecs to be multiply and incorrectly listed. */ /* if (had) FIXME("had != NULL, not supported\n"); */ if (had) { if (acmDriverID((HACMOBJ)had, (HACMDRIVERID *)&padid, 0) != MMSYSERR_NOERROR) return MMSYSERR_INVALHANDLE; for (i = 0; i < padid->cFormatTags; i++) { paftd->dwFormatTagIndex = i; if (MSACM_Message(had, ACMDM_FORMATTAG_DETAILS, (LPARAM)paftd, ACM_FORMATTAGDETAILSF_INDEX) == MMSYSERR_NOERROR) { if (paftd->dwFormatTag == WAVE_FORMAT_PCM) { if (paftd->szFormatTag[0] == 0) MultiByteToWideChar( CP_ACP, 0, "PCM", -1, paftd->szFormatTag, sizeof(paftd->szFormatTag)/sizeof(WCHAR) ); /* (WS) I'm preserving this PCM hack since it seems to be * correct. Please notice this block was borrowed from * below. */ if (bPcmDone) continue; bPcmDone = TRUE; } if (!(fnCallback)((HACMDRIVERID)padid, paftd, dwInstance, padid->fdwSupport)) return MMSYSERR_NOERROR; } } } /* if had==0 then search for the first suitable driver */ else { for (padid = MSACM_pFirstACMDriverID; padid; padid = padid->pNextACMDriverID) { /* should check for codec only */ if (!(padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED) && acmDriverOpen(&had, (HACMDRIVERID)padid, 0) == MMSYSERR_NOERROR) { for (i = 0; i < padid->cFormatTags; i++) { paftd->dwFormatTagIndex = i; if (MSACM_Message(had, ACMDM_FORMATTAG_DETAILS, (LPARAM)paftd, ACM_FORMATTAGDETAILSF_INDEX) == MMSYSERR_NOERROR) { if (paftd->dwFormatTag == WAVE_FORMAT_PCM) { if (paftd->szFormatTag[0] == 0) MultiByteToWideChar( CP_ACP, 0, "PCM", -1, paftd->szFormatTag, sizeof(paftd->szFormatTag)/sizeof(WCHAR) ); /* FIXME (EPP): I'm not sure this is the correct * algorithm (should make more sense to apply the same * for all already loaded formats, but this will do * for now */ if (bPcmDone) continue; bPcmDone = TRUE; } if (!(fnCallback)((HACMDRIVERID)padid, paftd, dwInstance, padid->fdwSupport)) { acmDriverClose(had, 0); return MMSYSERR_NOERROR; } } } } acmDriverClose(had, 0); } } return MMSYSERR_NOERROR; }
/*********************************************************************** * acmFormatTagDetailsW (MSACM32.@) */ MMRESULT WINAPI acmFormatTagDetailsW(HACMDRIVER had, PACMFORMATTAGDETAILSW paftd, DWORD fdwDetails) { PWINE_ACMDRIVERID padid; MMRESULT mmr = ACMERR_NOTPOSSIBLE; TRACE("(%p, %p, %d)\n", had, paftd, fdwDetails); if (fdwDetails & ~(ACM_FORMATTAGDETAILSF_FORMATTAG|ACM_FORMATTAGDETAILSF_INDEX| ACM_FORMATTAGDETAILSF_LARGESTSIZE)) return MMSYSERR_INVALFLAG; switch (fdwDetails) { case ACM_FORMATTAGDETAILSF_FORMATTAG: if (had == NULL) { for (padid = MSACM_pFirstACMDriverID; padid; padid = padid->pNextACMDriverID) { /* should check for codec only */ if (!(padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED) && MSACM_FindFormatTagInCache(padid, paftd->dwFormatTag, NULL) && acmDriverOpen(&had, (HACMDRIVERID)padid, 0) == 0) { mmr = MSACM_Message(had, ACMDM_FORMATTAG_DETAILS, (LPARAM)paftd, fdwDetails); acmDriverClose(had, 0); if (mmr == MMSYSERR_NOERROR) break; } } } else { PWINE_ACMDRIVER pad = MSACM_GetDriver(had); if (pad && MSACM_FindFormatTagInCache(pad->obj.pACMDriverID, paftd->dwFormatTag, NULL)) mmr = MSACM_Message(had, ACMDM_FORMATTAG_DETAILS, (LPARAM)paftd, fdwDetails); } break; case ACM_FORMATTAGDETAILSF_INDEX: if (had != NULL) { PWINE_ACMDRIVER pad = MSACM_GetDriver(had); if (pad && paftd->dwFormatTagIndex < pad->obj.pACMDriverID->cFormatTags) mmr = MSACM_Message(had, ACMDM_FORMATTAG_DETAILS, (LPARAM)paftd, fdwDetails); } break; case ACM_FORMATTAGDETAILSF_LARGESTSIZE: if (had == NULL) { ACMFORMATTAGDETAILSW tmp; DWORD ft = paftd->dwFormatTag; for (padid = MSACM_pFirstACMDriverID; padid; padid = padid->pNextACMDriverID) { /* should check for codec only */ if (!(padid->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED) && acmDriverOpen(&had, (HACMDRIVERID)padid, 0) == 0) { memset(&tmp, 0, sizeof(tmp)); tmp.cbStruct = sizeof(tmp); tmp.dwFormatTag = ft; if (MSACM_Message(had, ACMDM_FORMATTAG_DETAILS, (LPARAM)&tmp, fdwDetails) == MMSYSERR_NOERROR) { if (mmr == ACMERR_NOTPOSSIBLE || paftd->cbFormatSize < tmp.cbFormatSize) { *paftd = tmp; mmr = MMSYSERR_NOERROR; } } acmDriverClose(had, 0); } } } else { mmr = MSACM_Message(had, ACMDM_FORMATTAG_DETAILS, (LPARAM)paftd, fdwDetails); } break; default: WARN("Unsupported fdwDetails=%08x\n", fdwDetails); mmr = MMSYSERR_ERROR; } if (mmr == MMSYSERR_NOERROR && paftd->dwFormatTag == WAVE_FORMAT_PCM && paftd->szFormatTag[0] == 0) MultiByteToWideChar( CP_ACP, 0, "PCM", -1, paftd->szFormatTag, sizeof(paftd->szFormatTag)/sizeof(WCHAR) ); return mmr; }
/*********************************************************************** * acmStreamPrepareHeader (MSACM32.@) */ MMRESULT WINAPI acmStreamPrepareHeader(HACMSTREAM has, PACMSTREAMHEADER pash, DWORD fdwPrepare) { PWINE_ACMSTREAM was; MMRESULT ret = MMSYSERR_NOERROR; PACMDRVSTREAMHEADER padsh; TRACE("(%p, %p, %d)\n", has, pash, fdwPrepare); if ((was = ACM_GetStream(has)) == NULL) { WARN("invalid handle\n"); return MMSYSERR_INVALHANDLE; } if (!pash || pash->cbStruct < sizeof(ACMSTREAMHEADER)) { WARN("invalid parameter\n"); return MMSYSERR_INVALPARAM; } if (fdwPrepare) ret = MMSYSERR_INVALFLAG; if (pash->fdwStatus & ACMSTREAMHEADER_STATUSF_DONE) return MMSYSERR_NOERROR; /* Note: the ACMSTREAMHEADER and ACMDRVSTREAMHEADER structs are of same * size. some fields are private to msacm internals, and are exposed * in ACMSTREAMHEADER in the dwReservedDriver array */ padsh = (PACMDRVSTREAMHEADER)pash; padsh->fdwConvert = fdwPrepare; padsh->padshNext = NULL; padsh->fdwDriver = padsh->dwDriver = 0L; padsh->fdwPrepared = 0; padsh->dwPrepared = 0; padsh->pbPreparedSrc = 0; padsh->cbPreparedSrcLength = 0; padsh->pbPreparedDst = 0; padsh->cbPreparedDstLength = 0; ret = MSACM_Message((HACMDRIVER)was->pDrv, ACMDM_STREAM_PREPARE, (LPARAM)&was->drvInst, (LPARAM)padsh); if (ret == MMSYSERR_NOERROR || ret == MMSYSERR_NOTSUPPORTED) { ret = MMSYSERR_NOERROR; padsh->fdwStatus &= ~(ACMSTREAMHEADER_STATUSF_DONE|ACMSTREAMHEADER_STATUSF_INQUEUE); padsh->fdwStatus |= ACMSTREAMHEADER_STATUSF_PREPARED; padsh->fdwPrepared = padsh->fdwStatus; padsh->dwPrepared = 0; padsh->pbPreparedSrc = padsh->pbSrc; padsh->cbPreparedSrcLength = padsh->cbSrcLength; padsh->pbPreparedDst = padsh->pbDst; padsh->cbPreparedDstLength = padsh->cbDstLength; } else { padsh->fdwPrepared = 0; padsh->dwPrepared = 0; padsh->pbPreparedSrc = 0; padsh->cbPreparedSrcLength = 0; padsh->pbPreparedDst = 0; padsh->cbPreparedDstLength = 0; } TRACE("=> (%d)\n", ret); return ret; }
/*********************************************************************** * acmStreamOpen (MSACM32.@) */ MMRESULT WINAPI acmStreamOpen(PHACMSTREAM phas, HACMDRIVER had, PWAVEFORMATEX pwfxSrc, PWAVEFORMATEX pwfxDst, PWAVEFILTER pwfltr, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen) { PWINE_ACMSTREAM was; PWINE_ACMDRIVER wad; MMRESULT ret; int wfxSrcSize; int wfxDstSize; WAVEFORMATEX wfxSrc, wfxDst; TRACE("(%p, %p, %p, %p, %p, %ld, %ld, %d)\n", phas, had, pwfxSrc, pwfxDst, pwfltr, dwCallback, dwInstance, fdwOpen); /* NOTE: pwfxSrc and/or pwfxDst can point to a structure smaller than * WAVEFORMATEX so don't use them directly when not sure */ if (pwfxSrc->wFormatTag == WAVE_FORMAT_PCM) { memcpy(&wfxSrc, pwfxSrc, sizeof(PCMWAVEFORMAT)); wfxSrc.wBitsPerSample = pwfxSrc->wBitsPerSample; wfxSrc.cbSize = 0; pwfxSrc = &wfxSrc; } if (pwfxDst->wFormatTag == WAVE_FORMAT_PCM) { memcpy(&wfxDst, pwfxDst, sizeof(PCMWAVEFORMAT)); wfxDst.wBitsPerSample = pwfxDst->wBitsPerSample; wfxDst.cbSize = 0; pwfxDst = &wfxDst; } TRACE("src [wFormatTag=%u, nChannels=%u, nSamplesPerSec=%u, nAvgBytesPerSec=%u, nBlockAlign=%u, wBitsPerSample=%u, cbSize=%u]\n", pwfxSrc->wFormatTag, pwfxSrc->nChannels, pwfxSrc->nSamplesPerSec, pwfxSrc->nAvgBytesPerSec, pwfxSrc->nBlockAlign, pwfxSrc->wBitsPerSample, pwfxSrc->cbSize); TRACE("dst [wFormatTag=%u, nChannels=%u, nSamplesPerSec=%u, nAvgBytesPerSec=%u, nBlockAlign=%u, wBitsPerSample=%u, cbSize=%u]\n", pwfxDst->wFormatTag, pwfxDst->nChannels, pwfxDst->nSamplesPerSec, pwfxDst->nAvgBytesPerSec, pwfxDst->nBlockAlign, pwfxDst->wBitsPerSample, pwfxDst->cbSize); /* (WS) In query mode, phas should be NULL. If it is not, then instead * of returning an error we are making sure it is NULL, preventing some * applications that pass garbage for phas from crashing. */ if (fdwOpen & ACM_STREAMOPENF_QUERY) phas = NULL; if (pwfltr && (pwfxSrc->wFormatTag != pwfxDst->wFormatTag)) { WARN("invalid parameter\n"); return MMSYSERR_INVALPARAM; } wfxSrcSize = wfxDstSize = sizeof(WAVEFORMATEX); if (pwfxSrc->wFormatTag != WAVE_FORMAT_PCM) wfxSrcSize += pwfxSrc->cbSize; if (pwfxDst->wFormatTag != WAVE_FORMAT_PCM) wfxDstSize += pwfxDst->cbSize; was = HeapAlloc(MSACM_hHeap, 0, sizeof(*was) + wfxSrcSize + wfxDstSize + ((pwfltr) ? sizeof(WAVEFILTER) : 0)); if (was == NULL) { WARN("no memory\n"); return MMSYSERR_NOMEM; } was->drvInst.cbStruct = sizeof(was->drvInst); was->drvInst.pwfxSrc = (PWAVEFORMATEX)((LPSTR)was + sizeof(*was)); memcpy(was->drvInst.pwfxSrc, pwfxSrc, wfxSrcSize); was->drvInst.pwfxDst = (PWAVEFORMATEX)((LPSTR)was + sizeof(*was) + wfxSrcSize); memcpy(was->drvInst.pwfxDst, pwfxDst, wfxDstSize); if (pwfltr) { was->drvInst.pwfltr = (PWAVEFILTER)((LPSTR)was + sizeof(*was) + wfxSrcSize + wfxDstSize); memcpy(was->drvInst.pwfltr, pwfltr, sizeof(WAVEFILTER)); } else { was->drvInst.pwfltr = NULL; } was->drvInst.dwCallback = dwCallback; was->drvInst.dwInstance = dwInstance; was->drvInst.fdwOpen = fdwOpen; was->drvInst.fdwDriver = 0L; was->drvInst.dwDriver = 0L; /* real value will be stored once ACMDM_STREAM_OPEN succeeds */ was->drvInst.has = 0L; if (had) { if (!(wad = MSACM_GetDriver(had))) { ret = MMSYSERR_INVALPARAM; goto errCleanUp; } was->obj.dwType = WINE_ACMOBJ_STREAM; was->obj.pACMDriverID = wad->obj.pACMDriverID; was->pDrv = wad; was->hAcmDriver = 0; /* not to close it in acmStreamClose */ ret = MSACM_Message((HACMDRIVER)wad, ACMDM_STREAM_OPEN, (LPARAM)&was->drvInst, 0L); if (ret != MMSYSERR_NOERROR) goto errCleanUp; } else { PWINE_ACMDRIVERID wadi; ret = ACMERR_NOTPOSSIBLE; for (wadi = MSACM_pFirstACMDriverID; wadi; wadi = wadi->pNextACMDriverID) { if ((wadi->fdwSupport & ACMDRIVERDETAILS_SUPPORTF_DISABLED) || !MSACM_FindFormatTagInCache(wadi, pwfxSrc->wFormatTag, NULL) || !MSACM_FindFormatTagInCache(wadi, pwfxDst->wFormatTag, NULL)) continue; ret = acmDriverOpen(&had, (HACMDRIVERID)wadi, 0L); if (ret != MMSYSERR_NOERROR) continue; if ((wad = MSACM_GetDriver(had)) != 0) { was->obj.dwType = WINE_ACMOBJ_STREAM; was->obj.pACMDriverID = wad->obj.pACMDriverID; was->pDrv = wad; was->hAcmDriver = had; ret = MSACM_Message((HACMDRIVER)wad, ACMDM_STREAM_OPEN, (LPARAM)&was->drvInst, 0L); TRACE("%s => %08x\n", debugstr_w(wadi->pszDriverAlias), ret); if (ret == MMSYSERR_NOERROR) { if (fdwOpen & ACM_STREAMOPENF_QUERY) { MSACM_Message((HACMDRIVER)wad, ACMDM_STREAM_CLOSE, (LPARAM)&was->drvInst, 0); acmDriverClose(had, 0L); } break; } } /* no match, close this acm driver and try next one */ acmDriverClose(had, 0L); } if (ret != MMSYSERR_NOERROR) { ret = ACMERR_NOTPOSSIBLE; goto errCleanUp; } } ret = MMSYSERR_NOERROR; was->drvInst.has = (HACMSTREAM)was; if (!(fdwOpen & ACM_STREAMOPENF_QUERY)) { if (phas) *phas = (HACMSTREAM)was; TRACE("=> (%d)\n", ret); return ret; } errCleanUp: if (phas) *phas = NULL; HeapFree(MSACM_hHeap, 0, was); TRACE("=> (%d)\n", ret); return ret; }
/*********************************************************************** * acmDriverMessage (MSACM32.@) * * Note: MSDN documentation (July 2001) is incomplete. This function * accepts sending messages to an HACMDRIVERID in addition to the * documented HACMDRIVER. In fact, for DRV_QUERYCONFIGURE and DRV_CONFIGURE, * this might actually be the required mode of operation. * * Note: For DRV_CONFIGURE, msacm supplies its own DRVCONFIGINFO structure * when the application fails to supply one. Some native drivers depend on * this and refuse to display unless a valid DRVCONFIGINFO structure is * built and supplied. */ LRESULT WINAPI acmDriverMessage(HACMDRIVER had, UINT uMsg, LPARAM lParam1, LPARAM lParam2) { TRACE("(%p, %04x, %08lx, %08lx\n", had, uMsg, lParam1, lParam2); if ((uMsg >= ACMDM_USER && uMsg < ACMDM_RESERVED_LOW) || uMsg == ACMDM_DRIVER_ABOUT || uMsg == DRV_QUERYCONFIGURE || uMsg == DRV_CONFIGURE) { PWINE_ACMDRIVERID padid; LRESULT lResult; LPDRVCONFIGINFO pConfigInfo = NULL; LPWSTR section_name = NULL; LPWSTR alias_name = NULL; /* Check whether handle is an HACMDRIVERID */ padid = MSACM_GetDriverID((HACMDRIVERID)had); /* If the message is DRV_CONFIGURE, and the application provides no DRVCONFIGINFO structure, msacm must supply its own. */ if (uMsg == DRV_CONFIGURE && lParam2 == 0) { LPWSTR pAlias; /* Get the alias from the HACMDRIVERID */ if (padid) { pAlias = padid->pszDriverAlias; if (pAlias == NULL) { WARN("DRV_CONFIGURE: no alias for this driver, cannot self-supply alias\n"); } } else { FIXME("DRV_CONFIGURE: reverse lookup HACMDRIVER -> HACMDRIVERID not implemented\n"); pAlias = NULL; } if (pAlias != NULL) { /* DRVCONFIGINFO is only 12 bytes long, but native msacm * reports a 16-byte structure to codecs, so allocate 16 bytes, * just to be on the safe side. */ const unsigned int iStructSize = 16; pConfigInfo = HeapAlloc(MSACM_hHeap, 0, iStructSize); if (!pConfigInfo) { ERR("OOM while supplying DRVCONFIGINFO for DRV_CONFIGURE, using NULL\n"); } else { static const WCHAR drivers32[] = {'D','r','i','v','e','r','s','3','2','\0'}; pConfigInfo->dwDCISize = iStructSize; section_name = HeapAlloc(MSACM_hHeap, 0, (strlenW(drivers32) + 1) * sizeof(WCHAR)); if (section_name) strcpyW(section_name, drivers32); pConfigInfo->lpszDCISectionName = section_name; alias_name = HeapAlloc(MSACM_hHeap, 0, (strlenW(pAlias) + 1) * sizeof(WCHAR)); if (alias_name) strcpyW(alias_name, pAlias); pConfigInfo->lpszDCIAliasName = alias_name; if (pConfigInfo->lpszDCISectionName == NULL || pConfigInfo->lpszDCIAliasName == NULL) { HeapFree(MSACM_hHeap, 0, alias_name); HeapFree(MSACM_hHeap, 0, section_name); HeapFree(MSACM_hHeap, 0, pConfigInfo); pConfigInfo = NULL; ERR("OOM while supplying DRVCONFIGINFO for DRV_CONFIGURE, using NULL\n"); } } } lParam2 = (LPARAM)pConfigInfo; } if (padid) { /* Handle is really an HACMDRIVERID, must have an open session to get an HACMDRIVER */ if (padid->pACMDriverList != NULL) { lResult = MSACM_Message((HACMDRIVER)padid->pACMDriverList, uMsg, lParam1, lParam2); } else { MMRESULT mmr = acmDriverOpen(&had, (HACMDRIVERID)padid, 0); if (mmr != MMSYSERR_NOERROR) { lResult = MMSYSERR_INVALPARAM; } else { lResult = acmDriverMessage(had, uMsg, lParam1, lParam2); acmDriverClose(had, 0); } } } else { lResult = MSACM_Message(had, uMsg, lParam1, lParam2); } if (pConfigInfo) { HeapFree(MSACM_hHeap, 0, alias_name); HeapFree(MSACM_hHeap, 0, section_name); HeapFree(MSACM_hHeap, 0, pConfigInfo); } return lResult; } WARN("invalid parameter\n"); return MMSYSERR_INVALPARAM; }
/*********************************************************************** * acmStreamPrepareHeader (MSACM32.@) */ MMRESULT WINAPI acmStreamPrepareHeader(HACMSTREAM has, PACMSTREAMHEADER pash, DWORD fdwPrepare) { PWINE_ACMSTREAM was; MMRESULT ret = MMSYSERR_NOERROR; PACMDRVSTREAMHEADER padsh; TRACE("(%p, %p, %d)\n", has, pash, fdwPrepare); if ((was = ACM_GetStream(has)) == NULL) { WARN("invalid handle\n"); return MMSYSERR_INVALHANDLE; } if (!pash || pash->cbStruct < sizeof(ACMSTREAMHEADER)) { WARN("invalid parameter\n"); return MMSYSERR_INVALPARAM; } if (fdwPrepare) { WARN("invalid use of reserved parameter\n"); return MMSYSERR_INVALFLAG; } if ((was->drvInst.pwfxSrc->wFormatTag == WAVE_FORMAT_ADPCM || was->drvInst.pwfxSrc->wFormatTag == WAVE_FORMAT_PCM) && pash->cbSrcLength < was->drvInst.pwfxSrc->nBlockAlign) { WARN("source smaller than block align (%d < %d)\n", pash->cbSrcLength, was->drvInst.pwfxSrc->nBlockAlign); return pash->cbSrcLength ? ACMERR_NOTPOSSIBLE : MMSYSERR_INVALPARAM; } /* Note: the ACMSTREAMHEADER and ACMDRVSTREAMHEADER structs are of same * size. some fields are private to msacm internals, and are exposed * in ACMSTREAMHEADER in the dwReservedDriver array */ padsh = (PACMDRVSTREAMHEADER)pash; padsh->fdwConvert = fdwPrepare; padsh->padshNext = NULL; padsh->fdwDriver = padsh->dwDriver = 0L; padsh->fdwPrepared = 0; padsh->dwPrepared = 0; padsh->pbPreparedSrc = 0; padsh->cbPreparedSrcLength = 0; padsh->pbPreparedDst = 0; padsh->cbPreparedDstLength = 0; ret = MSACM_Message((HACMDRIVER)was->pDrv, ACMDM_STREAM_PREPARE, (LPARAM)&was->drvInst, (LPARAM)padsh); if (ret == MMSYSERR_NOERROR || ret == MMSYSERR_NOTSUPPORTED) { ret = MMSYSERR_NOERROR; padsh->fdwStatus &= ~ACMSTREAMHEADER_STATUSF_INQUEUE; padsh->fdwStatus |= ACMSTREAMHEADER_STATUSF_PREPARED; padsh->fdwPrepared = padsh->fdwStatus; padsh->dwPrepared = 0; padsh->pbPreparedSrc = padsh->pbSrc; padsh->cbPreparedSrcLength = padsh->cbSrcLength; padsh->pbPreparedDst = padsh->pbDst; padsh->cbPreparedDstLength = padsh->cbDstLength; } else { padsh->fdwPrepared = 0; padsh->dwPrepared = 0; padsh->pbPreparedSrc = 0; padsh->cbPreparedSrcLength = 0; padsh->pbPreparedDst = 0; padsh->cbPreparedDstLength = 0; } TRACE("=> (%d)\n", ret); return ret; }