Author: janderwald
Date: Thu Feb  3 09:34:59 2011
New Revision: 50600

URL: http://svn.reactos.org/svn/reactos?rev=50600&view=rev
Log:
[AUDIO]
- Add i/o completion routine, which delivers the number of bytes written / read
- Close event handle, after the overlapped request has been handled.
- Audio stack no longer leaks ~ 50 event handles per second

Modified:
    trunk/reactos/dll/win32/wdmaud.drv/legacy.c
    trunk/reactos/dll/win32/wdmaud.drv/mixer.c
    trunk/reactos/include/reactos/libs/sound/mmebuddy.h

Modified: trunk/reactos/dll/win32/wdmaud.drv/legacy.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/wdmaud.drv/legacy.c?rev=50600&r1=50599&r2=50600&view=diff
==============================================================================
--- trunk/reactos/dll/win32/wdmaud.drv/legacy.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/wdmaud.drv/legacy.c [iso-8859-1] Thu Feb  3 
09:34:59 2011
@@ -544,6 +544,25 @@
     return MMSYSERR_NOERROR;
 }
 
+VOID
+CALLBACK
+LegacyCompletionRoutine(
+    IN  DWORD dwErrorCode,
+    IN  DWORD dwNumberOfBytesTransferred,
+    IN  LPOVERLAPPED lpOverlapped)
+{
+    PSOUND_OVERLAPPED Overlap;
+    PWDMAUD_DEVICE_INFO DeviceInfo;
+
+    Overlap = (PSOUND_OVERLAPPED)lpOverlapped;
+    DeviceInfo = (PWDMAUD_DEVICE_INFO)Overlap->CompletionContext;
+
+    /* Call mmebuddy overlap routine */
+    Overlap->OriginalCompletionRoutine(dwErrorCode, 
DeviceInfo->Header.DataUsed, lpOverlapped);
+
+    HeapFree(GetProcessHeap(), 0, DeviceInfo);
+}
+
 MMRESULT
 WdmAudCommitWaveBufferByLegacy(
     IN  PSOUND_DEVICE_INSTANCE SoundDeviceInstance,
@@ -554,7 +573,7 @@
 {
     HANDLE Handle;
     MMRESULT Result;
-    WDMAUD_DEVICE_INFO DeviceInfo;
+    PWDMAUD_DEVICE_INFO DeviceInfo;
     PSOUND_DEVICE SoundDevice;
     MMDEVICE_TYPE DeviceType;
     BOOL Ret;
@@ -577,36 +596,52 @@
     Result = GetSoundDeviceType(SoundDevice, &DeviceType);
     SND_ASSERT( Result == MMSYSERR_NOERROR );
 
-    ZeroMemory(&DeviceInfo, sizeof(WDMAUD_DEVICE_INFO));
-
-    DeviceInfo.Header.FrameExtent = Length;
+    DeviceInfo = (PWDMAUD_DEVICE_INFO)HeapAlloc(GetProcessHeap(), 
HEAP_ZERO_MEMORY, sizeof(WDMAUD_DEVICE_INFO));
+    if (!DeviceInfo)
+    {
+        // no memory
+        return MMSYSERR_NOMEM;
+    }
+
+    DeviceInfo->Header.FrameExtent = Length;
     if (DeviceType == WAVE_OUT_DEVICE_TYPE)
     {
-        DeviceInfo.Header.DataUsed = Length;
-    }
-    DeviceInfo.Header.Data = OffsetPtr;
-    DeviceInfo.Header.Size = sizeof(WDMAUD_DEVICE_INFO);
-    DeviceInfo.Header.PresentationTime.Numerator = 1;
-    DeviceInfo.Header.PresentationTime.Denominator = 1;
-    DeviceInfo.hDevice = Handle;
-    DeviceInfo.DeviceType = DeviceType;
-
-
-
+        DeviceInfo->Header.DataUsed = Length;
+    }
+    DeviceInfo->Header.Data = OffsetPtr;
+    DeviceInfo->Header.Size = sizeof(WDMAUD_DEVICE_INFO);
+    DeviceInfo->Header.PresentationTime.Numerator = 1;
+    DeviceInfo->Header.PresentationTime.Denominator = 1;
+    DeviceInfo->hDevice = Handle;
+    DeviceInfo->DeviceType = DeviceType;
+
+
+    // create completion event
     Overlap->Standard.hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
+    if (Overlap->Standard.hEvent == NULL)
+    {
+        // no memory
+        return MMSYSERR_NOMEM;
+    }
+
+    Overlap->OriginalCompletionRoutine = CompletionRoutine;
+    Overlap->CompletionContext = (PVOID)DeviceInfo;
 
     if (DeviceType == WAVE_OUT_DEVICE_TYPE)
     {
-        Ret = WriteFileEx(KernelHandle, &DeviceInfo, 
sizeof(WDMAUD_DEVICE_INFO), (LPOVERLAPPED)Overlap, CompletionRoutine);
+        Ret = WriteFileEx(KernelHandle, DeviceInfo, 
sizeof(WDMAUD_DEVICE_INFO), (LPOVERLAPPED)Overlap, LegacyCompletionRoutine);
         if (Ret)
             WaitForSingleObjectEx (KernelHandle, INFINITE, TRUE);
     }
     else if (DeviceType == WAVE_IN_DEVICE_TYPE)
     {
-        Ret = ReadFileEx(KernelHandle, &DeviceInfo, 
sizeof(WDMAUD_DEVICE_INFO), (LPOVERLAPPED)Overlap, CompletionRoutine);
-        //if (Ret)
-        //    WaitForSingleObjectEx (KernelHandle, INFINITE, TRUE);
-    }
+        Ret = ReadFileEx(KernelHandle, DeviceInfo, sizeof(WDMAUD_DEVICE_INFO), 
(LPOVERLAPPED)Overlap, LegacyCompletionRoutine);
+        if (Ret)
+            WaitForSingleObjectEx (KernelHandle, INFINITE, TRUE);
+    }
+
+    // close event handle
+    CloseHandle(Overlap->Standard.hEvent);
 
     return MMSYSERR_NOERROR;
 }

Modified: trunk/reactos/dll/win32/wdmaud.drv/mixer.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/wdmaud.drv/mixer.c?rev=50600&r1=50599&r2=50600&view=diff
==============================================================================
--- trunk/reactos/dll/win32/wdmaud.drv/mixer.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/wdmaud.drv/mixer.c [iso-8859-1] Thu Feb  3 09:34:59 
2011
@@ -421,7 +421,7 @@
     PSOUND_OVERLAPPED Overlap = (PSOUND_OVERLAPPED)lpOverlapped;
 
     /* Call mmebuddy overlap routine */
-    Overlap->OriginalCompletionRoutine(dwErrorCode, 
Overlap->OriginalBufferSize, lpOverlapped);
+    Overlap->OriginalCompletionRoutine(dwErrorCode, 
PtrToUlong(Overlap->CompletionContext), lpOverlapped);
 }
 
 MMRESULT
@@ -527,7 +527,7 @@
     DeviceInfo.Header.PresentationTime.Numerator = 1;
     DeviceInfo.Header.PresentationTime.Denominator = 1;
 
-    Overlap->OriginalBufferSize = Length;
+    Overlap->CompletionContext = UlongToPtr(Length);
     Overlap->OriginalCompletionRoutine = CompletionRoutine;
 
     Overlap->Standard.hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);

Modified: trunk/reactos/include/reactos/libs/sound/mmebuddy.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/libs/sound/mmebuddy.h?rev=50600&r1=50599&r2=50600&view=diff
==============================================================================
--- trunk/reactos/include/reactos/libs/sound/mmebuddy.h [iso-8859-1] (original)
+++ trunk/reactos/include/reactos/libs/sound/mmebuddy.h [iso-8859-1] Thu Feb  3 
09:34:59 2011
@@ -185,8 +185,8 @@
     PWAVEHDR Header;
     BOOL PerformCompletion;
 
-    DWORD OriginalBufferSize;
     LPOVERLAPPED_COMPLETION_ROUTINE OriginalCompletionRoutine;
+    PVOID CompletionContext;
 
 } SOUND_OVERLAPPED, *PSOUND_OVERLAPPED;
 


Reply via email to