[PSDK]
authorJohannes Anderwald <johannes.anderwald@reactos.org>
Fri, 13 Nov 2009 14:22:11 +0000 (14:22 +0000)
committerJohannes Anderwald <johannes.anderwald@reactos.org>
Fri, 13 Nov 2009 14:22:11 +0000 (14:22 +0000)
- Fix MIXEROPENDESC struct(x64 compability issue)
[MMEBUDDY]
- Fix usage of MIXEROPENDESC
[WDMAUD.DRV]
- Implement a listening thread which waits for volume level / mute control changes

svn path=/trunk/; revision=44133

reactos/dll/win32/wdmaud.drv/wdmaud.c
reactos/include/psdk/mmddk.h
reactos/include/reactos/libs/sound/mmebuddy.h
reactos/lib/drivers/sound/mmebuddy/deviceinstance.c

index 48d0b68..325df20 100644 (file)
@@ -260,6 +260,13 @@ CloseWdmSoundDevice(
                                       NULL);
     }
 
+    if (DeviceType == MIXER_DEVICE_TYPE)
+    {
+        SetEvent(SoundDeviceInstance->hStopEvent);
+        CloseHandle(SoundDeviceInstance->hStopEvent);
+        CloseHandle(SoundDeviceInstance->hNotifyEvent);
+    }
+
     --OpenCount;
 
     if ( OpenCount < 1 )
@@ -283,6 +290,62 @@ QueryWdmWaveDeviceFormatSupport(
 }
 
 
+DWORD
+WINAPI
+MixerEventThreadRoutine(
+    LPVOID Parameter)
+{
+    HANDLE WaitObjects[2];
+    DWORD dwResult;
+    MMRESULT Result;
+    WDMAUD_DEVICE_INFO DeviceInfo;
+    PSOUND_DEVICE_INSTANCE Instance = (PSOUND_DEVICE_INSTANCE)Parameter;
+
+    /* setup wait objects */
+    WaitObjects[0] = Instance->hNotifyEvent;
+    WaitObjects[1] = Instance->hStopEvent;
+
+    /* zero device info */
+    ZeroMemory(&DeviceInfo, sizeof(WDMAUD_DEVICE_INFO));
+
+    DeviceInfo.hDevice = Instance->Handle;
+    DeviceInfo.DeviceType = MIXER_DEVICE_TYPE;
+
+    do
+    {
+        dwResult = WaitForMultipleObjects(2, WaitObjects, FALSE, INFINITE);
+
+        if (dwResult == WAIT_OBJECT_0 + 1)
+        {
+            /* stop event was signalled */
+            break;
+        }
+
+        Result = SyncOverlappedDeviceIoControl(KernelHandle,
+                                               IOCTL_GET_MIXER_EVENT,
+                                               (LPVOID) &DeviceInfo,
+                                               sizeof(WDMAUD_DEVICE_INFO),
+                                               (LPVOID) &DeviceInfo,
+                                               sizeof(WDMAUD_DEVICE_INFO),
+                                               NULL);
+
+        if (Result == MMSYSERR_NOERROR)
+        {
+            DriverCallback(Instance->WinMM.ClientCallback,
+                           HIWORD(Instance->WinMM.Flags),
+                           Instance->WinMM.Handle,
+                           DeviceInfo.u.MixerEvent.NotificationType,
+                           Instance->WinMM.ClientCallbackInstanceData,
+                           (DWORD_PTR)DeviceInfo.u.MixerEvent.Value,
+                           0);
+        }
+    }while(TRUE);
+
+    /* done */
+    return 0;
+}
+
+
 MMRESULT
 SetWdmMixerDeviceFormat(
     IN  PSOUND_DEVICE_INSTANCE Instance,
@@ -292,6 +355,7 @@ SetWdmMixerDeviceFormat(
 {
     MMRESULT Result;
     WDMAUD_DEVICE_INFO DeviceInfo;
+    HANDLE hThread;
 
     if (Instance->Handle != KernelHandle)
     {
@@ -299,10 +363,18 @@ SetWdmMixerDeviceFormat(
         return MMSYSERR_NOERROR;
     }
 
+    Instance->hNotifyEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
+    if ( ! Instance->hNotifyEvent )
+        return MMSYSERR_NOMEM;
+
+    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,
@@ -314,9 +386,17 @@ SetWdmMixerDeviceFormat(
 
     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;
 
index fa9512a..18ea88d 100644 (file)
@@ -416,9 +416,10 @@ typedef struct {
 typedef struct tMIXEROPENDESC
 {
        HMIXEROBJ               hmx;
-        LPVOID                 pReserved0;
-       DWORD                   dwCallback;
-       DWORD                   dwInstance;
+       LPVOID                  pReserved0;
+       DWORD_PTR                       dwCallback;
+       DWORD_PTR                       dwInstance;
+       DWORD_PTR                       dnDevNode;
 } MIXEROPENDESC, *LPMIXEROPENDESC;
 
 typedef struct {
index b145c16..9f2ce0f 100644 (file)
@@ -334,8 +334,8 @@ typedef struct _SOUND_DEVICE_INSTANCE
     {
         HDRVR Handle;
         DWORD Flags;
-        DWORD ClientCallback;
-        DWORD ClientCallbackInstanceData;
+        DWORD_PTR ClientCallback;
+        DWORD_PTR ClientCallbackInstanceData;
     } WinMM;
 
     /* DO NOT TOUCH THESE OUTSIDE OF THE SOUND THREAD */
@@ -357,6 +357,8 @@ typedef struct _SOUND_DEVICE_INSTANCE
     DWORD FrameSize;
     DWORD BufferCount;
     WAVEFORMATEX WaveFormatEx;
+    HANDLE hNotifyEvent;
+    HANDLE hStopEvent;
 } SOUND_DEVICE_INSTANCE, *PSOUND_DEVICE_INSTANCE;
 
 /* This lives in WAVEHDR.reserved */
@@ -561,8 +563,8 @@ MMRESULT
 SetSoundDeviceInstanceMmeData(
     IN  PSOUND_DEVICE_INSTANCE SoundDeviceInstance,
     IN  HDRVR MmeHandle,
-    IN  DWORD ClientCallback,
-    IN  DWORD ClientCallbackData,
+    IN  DWORD_PTR ClientCallback,
+    IN  DWORD_PTR ClientCallbackData,
     IN  DWORD Flags);
 
 
index 790429e..0558b2b 100644 (file)
@@ -353,8 +353,8 @@ MMRESULT
 SetSoundDeviceInstanceMmeData(
     IN  PSOUND_DEVICE_INSTANCE SoundDeviceInstance,
     IN  HDRVR MmeHandle,
-    IN  DWORD ClientCallback,
-    IN  DWORD ClientCallbackData,
+    IN  DWORD_PTR ClientCallback,
+    IN  DWORD_PTR ClientCallbackData,
     IN  DWORD Flags)
 {
     VALIDATE_MMSYS_PARAMETER( IsValidSoundDeviceInstance(SoundDeviceInstance) );