[WDMAUD.DRV]
authorJohannes Anderwald <johannes.anderwald@reactos.org>
Fri, 25 Feb 2011 16:00:26 +0000 (16:00 +0000)
committerJohannes Anderwald <johannes.anderwald@reactos.org>
Fri, 25 Feb 2011 16:00:26 +0000 (16:00 +0000)
- Check if the provided waveformat is at least size of WAVEFORMAT
- Compute extra details such as the size or wBitsPerSample from the provided members
- Backup i/o completion handle before commiting the audio buffer as the struct might have already been released
- Fixes playback of mmsys cpl
- Found by DPH!

svn path=/trunk/; revision=50900

reactos/dll/win32/wdmaud.drv/legacy.c

index f1d01e7..5518917 100644 (file)
@@ -476,7 +476,7 @@ WdmAudSetWaveDeviceFormatByLegacy(
     DeviceInfo.u.WaveFormatEx.nSamplesPerSec = WaveFormat->nSamplesPerSec;
     DeviceInfo.u.WaveFormatEx.nBlockAlign = WaveFormat->nBlockAlign;
     DeviceInfo.u.WaveFormatEx.nAvgBytesPerSec = WaveFormat->nAvgBytesPerSec;
-    DeviceInfo.u.WaveFormatEx.wBitsPerSample = WaveFormat->wBitsPerSample;
+    DeviceInfo.u.WaveFormatEx.wBitsPerSample = (DeviceInfo.u.WaveFormatEx.nAvgBytesPerSec * 8) / (DeviceInfo.u.WaveFormatEx.nSamplesPerSec * DeviceInfo.u.WaveFormatEx.nChannels);
 #endif
 
     Result = SyncOverlappedDeviceIoControl(KernelHandle,
@@ -492,14 +492,19 @@ WdmAudSetWaveDeviceFormatByLegacy(
         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;
+    if (WaveFormatSize >= sizeof(WAVEFORMAT))
+    {
+        /* Store format */
+        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;
+    }
+
+    /* store details */
+    Instance->WaveFormatEx.cbSize = sizeof(WAVEFORMATEX);
+    Instance->WaveFormatEx.wBitsPerSample = (DeviceInfo.u.WaveFormatEx.nAvgBytesPerSec * 8) / (DeviceInfo.u.WaveFormatEx.nSamplesPerSec * DeviceInfo.u.WaveFormatEx.nChannels);
 
     /* Store sound device handle instance handle */
     Instance->Handle = (PVOID)DeviceInfo.hDevice;
@@ -617,7 +622,7 @@ WdmAudCommitWaveBufferByLegacy(
 
 
     // create completion event
-    Overlap->Standard.hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
+    Overlap->Standard.hEvent = Handle = CreateEventW(NULL, FALSE, FALSE, NULL);
     if (Overlap->Standard.hEvent == NULL)
     {
         // no memory
@@ -641,13 +646,11 @@ WdmAudCommitWaveBufferByLegacy(
     }
 
     // close event handle
-    CloseHandle(Overlap->Standard.hEvent);
+    CloseHandle(Handle);
 
     return MMSYSERR_NOERROR;
 }
 
-
-
 MMRESULT
 WdmAudSetWaveStateByLegacy(
     IN  struct _SOUND_DEVICE_INSTANCE* SoundDeviceInstance,