[MMEBUDDY]
authorJohannes Anderwald <johannes.anderwald@reactos.org>
Fri, 25 Feb 2011 14:10:31 +0000 (14:10 +0000)
committerJohannes Anderwald <johannes.anderwald@reactos.org>
Fri, 25 Feb 2011 14:10:31 +0000 (14:10 +0000)
- Store the internal state if an audio stream has been stopped
- Construct a thread when WODM_RESTART is received. This thread then triggers performs a callback to the wave thread, which finally restarts playback
- Only start the wave thread when playback is active (not paused by WODM_PAUSE)
- Fixes playback in Winamp 5.601 despite graphical issues
- Tested in Vbox 4.0 + 512MB RAM + Winamp 5.601

svn path=/trunk/; revision=50897

reactos/include/reactos/libs/sound/mmebuddy.h
reactos/lib/drivers/sound/mmebuddy/mmewrap.c
reactos/lib/drivers/sound/mmebuddy/wave/header.c
reactos/lib/drivers/sound/mmebuddy/wave/streaming.c

index 90b89ef..d1139c7 100644 (file)
@@ -366,6 +366,7 @@ typedef struct _SOUND_DEVICE_INSTANCE
     HANDLE hStopEvent;
     HANDLE hResetEvent;
     BOOL ResetInProgress;
+    BOOL bPaused;
 } SOUND_DEVICE_INSTANCE, *PSOUND_DEVICE_INSTANCE;
 
 /* This lives in WAVEHDR.reserved */
@@ -702,6 +703,9 @@ MMRESULT
 StopStreaming(
     IN  PSOUND_DEVICE_INSTANCE SoundDeviceInstance);
 
+VOID
+InitiateSoundStreaming(
+    IN  PSOUND_DEVICE_INSTANCE SoundDeviceInstance);
 
 /*
     kernel.c
index 9e03770..5b65154 100644 (file)
@@ -29,6 +29,7 @@ MmeSetState(
     PMMFUNCTION_TABLE FunctionTable;
     PSOUND_DEVICE SoundDevice;
     PSOUND_DEVICE_INSTANCE SoundDeviceInstance;
+    BOOL OldState;
 
     VALIDATE_MMSYS_PARAMETER( PrivateHandle );
     SoundDeviceInstance = (PSOUND_DEVICE_INSTANCE) PrivateHandle;
@@ -53,6 +54,20 @@ MmeSetState(
     /* Try change state */
     Result = FunctionTable->SetState(SoundDeviceInstance, bStart);
 
+    if ( MMSUCCESS(Result) )
+    {
+        /* Get old audio stream state */
+        OldState = SoundDeviceInstance->bPaused;
+
+        /* Store audio stream pause state */
+        SoundDeviceInstance->bPaused = !bStart;
+
+        if (SoundDeviceInstance->bPaused == FALSE && OldState == TRUE)
+        {
+            InitiateSoundStreaming(SoundDeviceInstance);
+        }
+    }
+
     return Result;
 }
 
index b4d7fdc..998edef 100644 (file)
@@ -242,7 +242,11 @@ EnqueueWaveHeader(
         SoundDeviceInstance->HeadWaveHeader = WaveHeader;
         SoundDeviceInstance->TailWaveHeader = WaveHeader;
 
-        DoWaveStreaming(SoundDeviceInstance);
+        /* Only do wave streaming when the stream has not been paused */
+        if (SoundDeviceInstance->bPaused == FALSE)
+        {
+            DoWaveStreaming(SoundDeviceInstance);
+        }
     }
     else
     {
@@ -258,7 +262,11 @@ EnqueueWaveHeader(
             SoundDeviceInstance->TailWaveHeader = WaveHeader;
             DUMP_WAVEHDR_QUEUE(SoundDeviceInstance);
 
-            DoWaveStreaming(SoundDeviceInstance);
+            /* Only do wave streaming when the stream has not been paused */
+            if ( SoundDeviceInstance->bPaused == FALSE )
+            {
+                DoWaveStreaming(SoundDeviceInstance);
+            }
         }
     }
 
index 320ac39..d892f2d 100644 (file)
@@ -361,3 +361,37 @@ StopStreaming(
                            StopStreamingInSoundThread,
                            NULL);
 }
+
+MMRESULT
+PerformWaveStreaming(
+    IN  PSOUND_DEVICE_INSTANCE SoundDeviceInstance,
+    IN  PVOID Parameter)
+{
+    DoWaveStreaming(SoundDeviceInstance);
+
+    return MMSYSERR_NOERROR;
+}
+
+DWORD
+WINAPI
+WaveActivateSoundStreaming(
+    IN PVOID lpParameter)
+{
+    CallSoundThread((PSOUND_DEVICE_INSTANCE)lpParameter,
+                    PerformWaveStreaming,
+                    NULL);
+
+    ExitThread(0);
+}
+
+VOID
+InitiateSoundStreaming(
+    IN  PSOUND_DEVICE_INSTANCE SoundDeviceInstance)
+{
+    HANDLE hThread;
+
+    hThread = CreateThread(NULL, 0, WaveActivateSoundStreaming, (PVOID)SoundDeviceInstance, 0, NULL);
+
+    if (hThread != NULL)
+        CloseHandle(hThread);
+}