Closing of wave output devices is functional and terminates the sound thread
[reactos.git] / reactos / lib / drivers / sound / mmebuddy / deviceinstance.c
index 922ed1d..8722a08 100644 (file)
@@ -37,8 +37,12 @@ VOID
 FreeSoundDeviceInstance(
     IN  PSOUND_DEVICE_INSTANCE SoundDeviceInstance)
 {
-    /* This won't work as the device is no longer valid by this point! */
-    /*SND_ASSERT( IsValidSoundDeviceInstance(SoundDeviceInstance) );*/
+    /*
+        Device is marked as invalid by now, but we can still do some sanity
+        checking.
+    */
+    SND_ASSERT( SoundDeviceInstance->Thread == NULL );
+
     ZeroMemory(SoundDeviceInstance, sizeof(SOUND_DEVICE_INSTANCE));
     FreeMemory(SoundDeviceInstance);
 }
@@ -190,9 +194,9 @@ CreateSoundDeviceInstance(
     (*SoundDeviceInstance)->HeadWaveHeader = NULL;
     (*SoundDeviceInstance)->TailWaveHeader = NULL;
 
-    (*SoundDeviceInstance)->CurrentWaveHeader = NULL;
     (*SoundDeviceInstance)->OutstandingBuffers = 0;
-    // TODO: Loop
+
+    (*SoundDeviceInstance)->LoopsRemaining = 0;
 
     /* Create the streaming thread (TODO - is this for wave only?) */
     Result = CreateSoundThread(&(*SoundDeviceInstance)->Thread);
@@ -255,13 +259,26 @@ DestroySoundDeviceInstance(
         return MMSYSERR_NOTSUPPORTED;
     }
 
+    /* Stop the streaming thread (TODO - is this for wave only?) */
+    Result = DestroySoundThread(SoundDeviceInstance->Thread);
+    SND_ASSERT( MMSUCCESS(Result) );    /* It should succeed! */
+    if ( ! MMSUCCESS(Result ) )
+    {
+        return TranslateInternalMmResult(Result);
+    }
+
+    /* Blank this out here */
+    SoundDeviceInstance->Thread = NULL;
+
     /* Try and close the device */
     Result = FunctionTable->Close(SoundDeviceInstance, Handle);
+    SND_ASSERT( MMSUCCESS(Result) );    /* It should succeed! */
     if ( ! MMSUCCESS(Result) )
         return TranslateInternalMmResult(Result);
 
     /* Drop it from the list */
     Result = UnlistSoundDeviceInstance(SoundDeviceInstance);
+    SND_ASSERT( MMSUCCESS(Result) );    /* It should succeed! */
     if ( ! MMSUCCESS(Result) )
         return TranslateInternalMmResult(Result);
 
@@ -274,7 +291,19 @@ MMRESULT
 DestroyAllSoundDeviceInstances(
     IN  PSOUND_DEVICE SoundDevice)
 {
-    return MMSYSERR_NOTSUPPORTED;
+    MMRESULT Result;
+    PSOUND_DEVICE_INSTANCE SoundDeviceInstance;
+
+    SoundDeviceInstance = SoundDevice->HeadInstance;
+
+    while ( SoundDeviceInstance )
+    {
+        Result = DestroySoundDeviceInstance(SoundDeviceInstance);
+        SND_ASSERT( MMSUCCESS(Result) );
+        SoundDeviceInstance = SoundDeviceInstance->Next;
+    }
+
+    return MMSYSERR_NOERROR;
 }
 
 MMRESULT