-
-
-
-
-MMRESULT
-SetWdmMixerDeviceFormat(
- IN PSOUND_DEVICE_INSTANCE Instance,
- IN DWORD DeviceId,
- IN PWAVEFORMATEX WaveFormat,
- IN DWORD WaveFormatSize)
-{
- MMRESULT Result;
- WDMAUD_DEVICE_INFO DeviceInfo;
- HANDLE hThread;
-
-
- Instance->hNotifyEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
- if ( ! Instance->hNotifyEvent )
- return MMSYSERR_NOMEM;
-
-#ifdef USE_MMIXER_LIB
- return WdmAudOpenMixer(&Instance->Handle, DeviceId, Instance->hNotifyEvent);
-#endif
-
- if (Instance->Handle != KernelHandle)
- {
- /* device is already open */
- return MMSYSERR_NOERROR;
- }
-
- Instance->hStopEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
- if ( ! Instance->hStopEvent )
- return MMSYSERR_NOMEM;
-
- ZeroMemory(&DeviceInfo, sizeof(WDMAUD_DEVICE_INFO));
- DeviceInfo.DeviceType = MIXER_DEVICE_TYPE;
- DeviceInfo.DeviceIndex = DeviceId;
- DeviceInfo.u.hNotifyEvent = Instance->hNotifyEvent;
-
- Result = SyncOverlappedDeviceIoControl(KernelHandle,
- IOCTL_OPEN_WDMAUD,
- (LPVOID) &DeviceInfo,
- sizeof(WDMAUD_DEVICE_INFO),
- (LPVOID) &DeviceInfo,
- sizeof(WDMAUD_DEVICE_INFO),
- NULL);
-
- if ( ! MMSUCCESS(Result) )
- {
- CloseHandle(Instance->hNotifyEvent);
- CloseHandle(Instance->hStopEvent);
- return TranslateInternalMmResult(Result);
- }
-
- hThread = CreateThread(NULL, 0, MixerEventThreadRoutine, (LPVOID)Instance, 0, NULL);
- if ( hThread )
- {
- CloseHandle(hThread);
- }
-
- /* Store sound device handle instance handle */
- Instance->Handle = (PVOID)DeviceInfo.hDevice;
-
- return MMSYSERR_NOERROR;
-}
-
-MMRESULT
-SetWdmWaveDeviceFormat(
- IN PSOUND_DEVICE_INSTANCE Instance,
- IN DWORD DeviceId,
- IN PWAVEFORMATEX WaveFormat,
- IN DWORD WaveFormatSize)
-{
- MMRESULT Result;
- PSOUND_DEVICE SoundDevice;
- PVOID Identifier;
- WDMAUD_DEVICE_INFO DeviceInfo;
- MMDEVICE_TYPE DeviceType;
-
- Result = GetSoundDeviceFromInstance(Instance, &SoundDevice);
-
- if ( ! MMSUCCESS(Result) )
- {
- return TranslateInternalMmResult(Result);
- }
-
- Result = GetSoundDeviceIdentifier(SoundDevice, &Identifier);
-
- if ( ! MMSUCCESS(Result) )
- {
- return TranslateInternalMmResult(Result);
- }
-
- if (Instance->Handle != KernelHandle)
- {
- /* device is already open */
- return MMSYSERR_NOERROR;
- }
-
- Result = GetSoundDeviceType(SoundDevice, &DeviceType);
-
-#ifdef USE_MMIXER_LIB
- return WdmAudOpenWavePin(Instance, DeviceId, WaveFormat, DeviceType);
-#endif
-
-
- SND_ASSERT( Result == MMSYSERR_NOERROR );
-
- ZeroMemory(&DeviceInfo, sizeof(WDMAUD_DEVICE_INFO));
- DeviceInfo.DeviceType = DeviceType;
- DeviceInfo.DeviceIndex = DeviceId;
- DeviceInfo.u.WaveFormatEx.cbSize = sizeof(WAVEFORMATEX); //WaveFormat->cbSize;
- DeviceInfo.u.WaveFormatEx.wFormatTag = WaveFormat->wFormatTag;
-#ifdef USERMODE_MIXER
- DeviceInfo.u.WaveFormatEx.nChannels = 2;
- DeviceInfo.u.WaveFormatEx.nSamplesPerSec = 44100;
- DeviceInfo.u.WaveFormatEx.nBlockAlign = 4;
- DeviceInfo.u.WaveFormatEx.nAvgBytesPerSec = 176400;
- DeviceInfo.u.WaveFormatEx.wBitsPerSample = 16;
-#else
- DeviceInfo.u.WaveFormatEx.nChannels = WaveFormat->nChannels;
- DeviceInfo.u.WaveFormatEx.nSamplesPerSec = WaveFormat->nSamplesPerSec;
- DeviceInfo.u.WaveFormatEx.nBlockAlign = WaveFormat->nBlockAlign;
- DeviceInfo.u.WaveFormatEx.nAvgBytesPerSec = WaveFormat->nAvgBytesPerSec;
- DeviceInfo.u.WaveFormatEx.wBitsPerSample = WaveFormat->wBitsPerSample;
-#endif
-
- Result = SyncOverlappedDeviceIoControl(KernelHandle,
- IOCTL_OPEN_WDMAUD,
- (LPVOID) &DeviceInfo,
- sizeof(WDMAUD_DEVICE_INFO),
- (LPVOID) &DeviceInfo,
- sizeof(WDMAUD_DEVICE_INFO),
- NULL);
-
- if ( ! MMSUCCESS(Result) )
- {
- return TranslateInternalMmResult(Result);
- }
-
- /* Store format */
- Instance->WaveFormatEx.cbSize = WaveFormat->cbSize;
- Instance->WaveFormatEx.wFormatTag = WaveFormat->wFormatTag;
- Instance->WaveFormatEx.nChannels = WaveFormat->nChannels;
- Instance->WaveFormatEx.nSamplesPerSec = WaveFormat->nSamplesPerSec;
- Instance->WaveFormatEx.nBlockAlign = WaveFormat->nBlockAlign;
- Instance->WaveFormatEx.nAvgBytesPerSec = WaveFormat->nAvgBytesPerSec;
- Instance->WaveFormatEx.wBitsPerSample = WaveFormat->wBitsPerSample;
-
- /* Store sound device handle instance handle */
- Instance->Handle = (PVOID)DeviceInfo.hDevice;
-
- /* Now determine framing requirements */
- Result = SyncOverlappedDeviceIoControl(KernelHandle,
- IOCTL_GETFRAMESIZE,
- (LPVOID) &DeviceInfo,
- sizeof(WDMAUD_DEVICE_INFO),
- (LPVOID) &DeviceInfo,
- sizeof(WDMAUD_DEVICE_INFO),
- NULL);
-
- if ( MMSUCCESS(Result) )
- {
- if (DeviceInfo.u.FrameSize)
- {
- Instance->FrameSize = DeviceInfo.u.FrameSize * 2;
- Instance->BufferCount = WaveFormat->nAvgBytesPerSec / Instance->FrameSize;
- SND_TRACE(L"FrameSize %u BufferCount %u\n", Instance->FrameSize, Instance->BufferCount);
- }
- }
- else
- {
- // use a default of 100 buffers
- Instance->BufferCount = 100;
- }
-
- if (DeviceType == WAVE_OUT_DEVICE_TYPE)
- {
- /* Now start the stream */
- DeviceInfo.u.State = KSSTATE_RUN;
- SyncOverlappedDeviceIoControl(KernelHandle,
- IOCTL_SETDEVICE_STATE,
- (LPVOID) &DeviceInfo,
- sizeof(WDMAUD_DEVICE_INFO),
- (LPVOID) &DeviceInfo,
- sizeof(WDMAUD_DEVICE_INFO),
- NULL);
- }
-
- return MMSYSERR_NOERROR;
-}
-
-
-MMRESULT
-SetWdmWaveState(
- IN struct _SOUND_DEVICE_INSTANCE* SoundDeviceInstance,
- IN BOOL bStart)
-{
- MMRESULT Result;
- PSOUND_DEVICE SoundDevice;
- WDMAUD_DEVICE_INFO DeviceInfo;
- MMDEVICE_TYPE DeviceType;
- HANDLE Handle;
-
- Result = GetSoundDeviceFromInstance(SoundDeviceInstance, &SoundDevice);
-
- if ( ! MMSUCCESS(Result) )
- {
- return TranslateInternalMmResult(Result);
- }
-
- Result = GetSoundDeviceType(SoundDevice, &DeviceType);
- SND_ASSERT( Result == MMSYSERR_NOERROR );
-
- Result = GetSoundDeviceInstanceHandle(SoundDeviceInstance, &Handle);
- SND_ASSERT( Result == MMSYSERR_NOERROR );
-
- ZeroMemory(&DeviceInfo, sizeof(WDMAUD_DEVICE_INFO));
- DeviceInfo.hDevice = Handle;
- DeviceInfo.DeviceType = DeviceType;
-
- if (bStart)
- DeviceInfo.u.State = KSSTATE_RUN;
- else
- DeviceInfo.u.State = KSSTATE_PAUSE;
- Result = SyncOverlappedDeviceIoControl(KernelHandle,
- IOCTL_SETDEVICE_STATE,
- (LPVOID) &DeviceInfo,
- sizeof(WDMAUD_DEVICE_INFO),
- (LPVOID) &DeviceInfo,
- sizeof(WDMAUD_DEVICE_INFO),
- NULL);
-
- return Result;
-}
-
-MMRESULT
-GetDeviceInterfaceString(
- IN MMDEVICE_TYPE DeviceType,
- IN DWORD DeviceId,
- IN LPWSTR Interface,
- IN DWORD InterfaceLength,
- OUT DWORD * InterfaceSize)
-{
- WDMAUD_DEVICE_INFO DeviceInfo;
- MMRESULT Result;
-
- ZeroMemory(&DeviceInfo, sizeof(WDMAUD_DEVICE_INFO));
- DeviceInfo.DeviceType = DeviceType;
- DeviceInfo.DeviceIndex = DeviceId;
-
-
- Result = SyncOverlappedDeviceIoControl(KernelHandle,
- IOCTL_QUERYDEVICEINTERFACESTRING,
- (LPVOID) &DeviceInfo,
- sizeof(WDMAUD_DEVICE_INFO),
- (LPVOID) &DeviceInfo,
- sizeof(WDMAUD_DEVICE_INFO),
- NULL);
-
-
- if ( ! MMSUCCESS(Result) )
- {
- return TranslateInternalMmResult(Result);
- }
-
-
- if (!Interface)
- {
- SND_ASSERT(InterfaceSize);
-
- *InterfaceSize = DeviceInfo.u.Interface.DeviceInterfaceStringSize;
- return MMSYSERR_NOERROR;
- }
-
- if (InterfaceLength < DeviceInfo.u.Interface.DeviceInterfaceStringSize)
- {
- /* buffer is too small */
- return MMSYSERR_MOREDATA;
- }
-
- DeviceInfo.u.Interface.DeviceInterfaceStringSize = InterfaceLength;
- DeviceInfo.u.Interface.DeviceInterfaceString = Interface;
-
- Result = SyncOverlappedDeviceIoControl(KernelHandle,
- IOCTL_QUERYDEVICEINTERFACESTRING,
- (LPVOID) &DeviceInfo,
- sizeof(WDMAUD_DEVICE_INFO),
- (LPVOID) &DeviceInfo,
- sizeof(WDMAUD_DEVICE_INFO),
- NULL);
-
- if ( MMSUCCESS(Result) && InterfaceLength > 2)
- {
- Interface[1] = L'\\';
- Interface[InterfaceLength-1] = L'\0';
- }
-
- return Result;
-}
-
-MMRESULT
-GetWdmPosition(
- IN struct _SOUND_DEVICE_INSTANCE* SoundDeviceInstance,
- IN MMTIME* Time)
-{
- MMRESULT Result;
- PSOUND_DEVICE SoundDevice;
- WDMAUD_DEVICE_INFO DeviceInfo;
- MMDEVICE_TYPE DeviceType;
- HANDLE Handle;
-
- Result = GetSoundDeviceFromInstance(SoundDeviceInstance, &SoundDevice);
-
- if ( ! MMSUCCESS(Result) )
- {
- return TranslateInternalMmResult(Result);
- }
-
- Result = GetSoundDeviceType(SoundDevice, &DeviceType);
- SND_ASSERT( Result == MMSYSERR_NOERROR );
-
- Result = GetSoundDeviceInstanceHandle(SoundDeviceInstance, &Handle);
- SND_ASSERT( Result == MMSYSERR_NOERROR );
-
- ZeroMemory(&DeviceInfo, sizeof(WDMAUD_DEVICE_INFO));
- DeviceInfo.hDevice = Handle;
- DeviceInfo.DeviceType = DeviceType;
-
- Result = SyncOverlappedDeviceIoControl(KernelHandle,
- IOCTL_OPEN_WDMAUD,
- (LPVOID) &DeviceInfo,
- sizeof(WDMAUD_DEVICE_INFO),
- (LPVOID) &DeviceInfo,
- sizeof(WDMAUD_DEVICE_INFO),
- NULL);
-
- if ( ! MMSUCCESS(Result) )
- {
- return TranslateInternalMmResult(Result);
- }
-
- Time->wType = TIME_BYTES;
- Time->u.cb = (DWORD)DeviceInfo.u.Position;
-
- return MMSYSERR_NOERROR;
-}
-
-MMRESULT
-ResetStream(
- IN struct _SOUND_DEVICE_INSTANCE* SoundDeviceInstance,
- IN MMDEVICE_TYPE DeviceType,
- IN BOOLEAN bStartReset)
-{
- MMRESULT Result;
- HANDLE Handle;
- WDMAUD_DEVICE_INFO DeviceInfo;
-
- Result = GetSoundDeviceInstanceHandle(SoundDeviceInstance, &Handle);
- SND_ASSERT( Result == MMSYSERR_NOERROR );
-
- ZeroMemory(&DeviceInfo, sizeof(WDMAUD_DEVICE_INFO));
- DeviceInfo.hDevice = Handle;
- DeviceInfo.DeviceType = DeviceType;
- DeviceInfo.u.ResetStream = (bStartReset ? KSRESET_BEGIN : KSRESET_END);
-
- Result = SyncOverlappedDeviceIoControl(KernelHandle,
- IOCTL_RESET_STREAM,
- (LPVOID) &DeviceInfo,
- sizeof(WDMAUD_DEVICE_INFO),
- (LPVOID) &DeviceInfo,
- sizeof(WDMAUD_DEVICE_INFO),
- NULL);
- return Result;
-}
-
-
-MMRESULT
-QueryMixerInfo(
- IN struct _SOUND_DEVICE_INSTANCE* SoundDeviceInstance,
- IN UINT uMsg,
- IN LPVOID Parameter,
- IN DWORD Flags)
-{
- MMRESULT Result;
- WDMAUD_DEVICE_INFO DeviceInfo;
- HANDLE Handle;
- DWORD IoControlCode;
- LPMIXERLINEW MixLine;
- LPMIXERLINECONTROLSW MixControls;
- LPMIXERCONTROLDETAILS MixDetails;
-
- SND_TRACE(L"uMsg %x Flags %x\n", uMsg, Flags);
-
- Result = GetSoundDeviceInstanceHandle(SoundDeviceInstance, &Handle);
- SND_ASSERT( Result == MMSYSERR_NOERROR );
-
- ZeroMemory(&DeviceInfo, sizeof(WDMAUD_DEVICE_INFO));
- DeviceInfo.hDevice = Handle;
- DeviceInfo.DeviceType = MIXER_DEVICE_TYPE;
- DeviceInfo.Flags = Flags;
-
- MixLine = (LPMIXERLINEW)Parameter;
- MixControls = (LPMIXERLINECONTROLSW)Parameter;
- MixDetails = (LPMIXERCONTROLDETAILS)Parameter;
-
-#ifdef USE_MMIXER_LIB
- switch(uMsg)
- {
- case MXDM_GETLINEINFO:
- return WdmAudGetLineInfo(SoundDeviceInstance->Handle, MixLine, Flags);
- case MXDM_GETLINECONTROLS:
- return WdmAudGetLineControls(SoundDeviceInstance->Handle, MixControls, Flags);
- case MXDM_SETCONTROLDETAILS:
- return WdmAudSetControlDetails(SoundDeviceInstance->Handle, MixDetails, Flags);
- break;
- case MXDM_GETCONTROLDETAILS:
- return WdmAudGetControlDetails(SoundDeviceInstance->Handle, MixDetails, Flags);
- break;
- default:
- SND_ASSERT(0);
- return MMSYSERR_NOTSUPPORTED;
- }
-#endif
-
-
- switch(uMsg)
- {
- case MXDM_GETLINEINFO:
- RtlCopyMemory(&DeviceInfo.u.MixLine, MixLine, sizeof(MIXERLINEW));
- IoControlCode = IOCTL_GETLINEINFO;
- break;
- case MXDM_GETLINECONTROLS:
- RtlCopyMemory(&DeviceInfo.u.MixControls, MixControls, sizeof(MIXERLINECONTROLSW));
- IoControlCode = IOCTL_GETLINECONTROLS;
- break;
- case MXDM_SETCONTROLDETAILS:
- RtlCopyMemory(&DeviceInfo.u.MixDetails, MixDetails, sizeof(MIXERCONTROLDETAILS));
- IoControlCode = IOCTL_SETCONTROLDETAILS;
- break;
- case MXDM_GETCONTROLDETAILS:
- RtlCopyMemory(&DeviceInfo.u.MixDetails, MixDetails, sizeof(MIXERCONTROLDETAILS));
- IoControlCode = IOCTL_GETCONTROLDETAILS;
- break;
- default:
- SND_ASSERT(0);
- return MMSYSERR_NOTSUPPORTED;
- }
-
- Result = SyncOverlappedDeviceIoControl(KernelHandle,
- IoControlCode,
- (LPVOID) &DeviceInfo,
- sizeof(WDMAUD_DEVICE_INFO),
- (LPVOID) &DeviceInfo,
- sizeof(WDMAUD_DEVICE_INFO),
- NULL);
-
- if ( ! MMSUCCESS(Result) )
- {
- return Result;
- }
-
- switch(uMsg)
- {
- case MXDM_GETLINEINFO:
- {
- RtlCopyMemory(MixLine, &DeviceInfo.u.MixLine, sizeof(MIXERLINEW));
- break;
- }
- }
-
- return Result;
-}
-
-