[MMEBUDDY]
authorJohannes Anderwald <johannes.anderwald@reactos.org>
Sun, 31 Oct 2010 13:20:11 +0000 (13:20 +0000)
committerJohannes Anderwald <johannes.anderwald@reactos.org>
Sun, 31 Oct 2010 13:20:11 +0000 (13:20 +0000)
- Getting device capabilities requires the unicode version of the structure
- Implement MIDM_OPEN, MIDM_CLOSE, MIDM_START, MIDM_STOP
- Implement MODM_OPEN, MODM_CLOSE
- Refactor MmeOpenWaveDevice into MmeOpenDevice add add support MIXER_DEVICE_TYPE, MIDI_IN_DEVICE_TYPE, MIDI_OUT_DEVICE_TYPE
- Refactor MmeCloseWaveDeivce into MmeCloseDevice and add support MIXER_DEVICE_TYPE, MIDI_IN_DEVICE_TYPE, MIDI_OUT_DEVICE_TYPE

svn path=/trunk/; revision=49374

reactos/include/reactos/libs/sound/mmebuddy.h
reactos/lib/drivers/sound/mmebuddy/capabilities.c
reactos/lib/drivers/sound/mmebuddy/midi/midMessage.c
reactos/lib/drivers/sound/mmebuddy/midi/modMessage.c
reactos/lib/drivers/sound/mmebuddy/mixer/mxdMessage.c
reactos/lib/drivers/sound/mmebuddy/mmewrap.c
reactos/lib/drivers/sound/mmebuddy/wave/widMessage.c
reactos/lib/drivers/sound/mmebuddy/wave/wodMessage.c

index cae6f3f..1a2a543 100644 (file)
@@ -68,7 +68,7 @@
             SND_TRACE(L"-- Current wave header list --\n"); \
             while ( CurrDumpHdr ) \
             { \
-                SND_TRACE(L"%x | %d bytes | flags: %x\n", CurrDumpHdr->lpData, \
+                SND_TRACE(L"%x | %d bytes | flags: %x\n", CurrDumpHdr, \
                           CurrDumpHdr->dwBufferLength, \
                           CurrDumpHdr->dwFlags); \
                 CurrDumpHdr = CurrDumpHdr->lpNext; \
@@ -364,6 +364,8 @@ typedef struct _SOUND_DEVICE_INSTANCE
     WAVEFORMATEX WaveFormatEx;
     HANDLE hNotifyEvent;
     HANDLE hStopEvent;
+    HANDLE hResetEvent;
+    BOOL ResetInProgress;
 } SOUND_DEVICE_INSTANCE, *PSOUND_DEVICE_INSTANCE;
 
 /* This lives in WAVEHDR.reserved */
@@ -411,7 +413,7 @@ MmeGetSoundDeviceCapabilities(
     IN  DWORD CapabilitiesSize);
 
 MMRESULT
-MmeOpenWaveDevice(
+MmeOpenDevice(
     IN  MMDEVICE_TYPE DeviceType,
     IN  UINT DeviceId,
     IN  LPWAVEOPENDESC OpenParameters,
index c8ff658..edf7599 100644 (file)
@@ -62,32 +62,32 @@ GetSoundDeviceCapabilities(
     {
         case WAVE_OUT_DEVICE_TYPE :
         {
-            GoodSize = CapabilitiesSize >= sizeof(WAVEOUTCAPS);
+            GoodSize = CapabilitiesSize >= sizeof(WAVEOUTCAPSW);
             break;
         }
         case WAVE_IN_DEVICE_TYPE :
         {
-            GoodSize = CapabilitiesSize >= sizeof(WAVEINCAPS);
+            GoodSize = CapabilitiesSize >= sizeof(WAVEINCAPSW);
             break;
         }
         case MIDI_OUT_DEVICE_TYPE :
         {
-            GoodSize = CapabilitiesSize >= sizeof(MIDIOUTCAPS);
+            GoodSize = CapabilitiesSize >= sizeof(MIDIOUTCAPSW);
             break;
         }
         case MIDI_IN_DEVICE_TYPE :
         {
-            GoodSize = CapabilitiesSize >= sizeof(MIDIINCAPS);
+            GoodSize = CapabilitiesSize >= sizeof(MIDIINCAPSW);
             break;
         }
         case AUX_DEVICE_TYPE :
         {
-            GoodSize = CapabilitiesSize >= sizeof(AUXCAPS);
+            GoodSize = CapabilitiesSize >= sizeof(AUXCAPSW);
             break;
         }
         case MIXER_DEVICE_TYPE :
         {
-            GoodSize = CapabilitiesSize >= sizeof(MIXERCAPS);
+            GoodSize = CapabilitiesSize >= sizeof(MIXERCAPSW);
             break;
         }
     };
index 9e1a0ec..95738d7 100644 (file)
@@ -65,6 +65,33 @@ midMessage(
             break;
         }
 
+        case MIDM_OPEN :
+        {
+            Result = MmeOpenDevice(MIDI_IN_DEVICE_TYPE,
+                                   DeviceId,
+                                   (LPWAVEOPENDESC) Parameter1,
+                                   Parameter2,
+                                   (DWORD_PTR*) PrivateHandle);
+            break;
+        }
+
+        case MIDM_CLOSE :
+        {
+            Result = MmeCloseDevice(PrivateHandle);
+            break;
+        }
+
+       case MIDM_START :
+        {
+            Result = MmeSetState(PrivateHandle, TRUE);
+            break;
+        }
+
+        case MIDM_STOP :
+        {
+            Result = MmeSetState(PrivateHandle, FALSE);
+            break;
+        }
     }
 
     SND_TRACE(L"midMessage returning MMRESULT %d\n", Result);
index febfca5..d189b03 100644 (file)
@@ -64,6 +64,24 @@ modMessage(
             Result = MmeGetDeviceInterfaceString(MIDI_OUT_DEVICE_TYPE, DeviceId, (LPWSTR)Parameter1, Parameter2, NULL); //FIXME DWORD_PTR
             break;
         }
+
+        case MODM_OPEN :
+        {
+            Result = MmeOpenDevice(MIDI_OUT_DEVICE_TYPE,
+                                   DeviceId,
+                                   (LPWAVEOPENDESC) Parameter1, /* unused */
+                                   Parameter2,
+                                   (DWORD_PTR*)PrivateHandle);
+            break;
+        }
+
+        case MODM_CLOSE :
+        {
+            Result = MmeCloseDevice(PrivateHandle);
+
+            break;
+        }
+
     }
 
     SND_TRACE(L"modMessage returning MMRESULT %d\n", Result);
index cf87054..08815ba 100644 (file)
@@ -52,99 +52,6 @@ MmeGetLineInfo(
 }
 
 
-MMRESULT
-MmeCloseMixerDevice(
-    IN  DWORD_PTR PrivateHandle)
-{
-    MMRESULT Result;
-    PSOUND_DEVICE_INSTANCE SoundDeviceInstance;
-    PSOUND_DEVICE SoundDevice;
-
-    SND_TRACE(L"Closing mixer device \n");
-
-    VALIDATE_MMSYS_PARAMETER( PrivateHandle );
-    SoundDeviceInstance = (PSOUND_DEVICE_INSTANCE) PrivateHandle;
-
-    if ( ! IsValidSoundDeviceInstance(SoundDeviceInstance) )
-        return MMSYSERR_INVALHANDLE;
-
-    Result = GetSoundDeviceFromInstance(SoundDeviceInstance, &SoundDevice);
-    if ( ! MMSUCCESS(Result) )
-        return TranslateInternalMmResult(Result);
-
-
-    Result = DestroySoundDeviceInstance(SoundDeviceInstance);
-
-    return Result;
-}
-
-MMRESULT
-MmeOpenMixerDevice(
-    IN  MMDEVICE_TYPE DeviceType,
-    IN  DWORD DeviceId,
-    IN  LPMIXEROPENDESC OpenParameters,
-    IN  DWORD Flags,
-    OUT DWORD* PrivateHandle)
-{
-    MMRESULT Result;
-    PMMFUNCTION_TABLE FunctionTable;
-    PSOUND_DEVICE SoundDevice;
-    PSOUND_DEVICE_INSTANCE SoundDeviceInstance;
-
-    SND_TRACE(L"Opening mixer device");
-
-    VALIDATE_MMSYS_PARAMETER( OpenParameters );
-
-    Result = GetSoundDevice(DeviceType, DeviceId, &SoundDevice);
-    if ( ! MMSUCCESS(Result) )
-        return TranslateInternalMmResult(Result);
-
-    /* Check that winmm gave us a private handle to fill */
-    VALIDATE_MMSYS_PARAMETER( PrivateHandle );
-
-    /* Create a sound device instance and open the sound device */
-    Result = CreateSoundDeviceInstance(SoundDevice, &SoundDeviceInstance);
-    if ( ! MMSUCCESS(Result) )
-        return TranslateInternalMmResult(Result);
-
-    Result = GetSoundDeviceFunctionTable(SoundDevice, &FunctionTable);
-    if ( ! MMSUCCESS(Result) )
-        return TranslateInternalMmResult(Result);
-
-    if ( ! FunctionTable->SetWaveFormat )
-        return MMSYSERR_NOTSUPPORTED;
-
-    Result = FunctionTable->SetWaveFormat(SoundDeviceInstance, DeviceId, NULL, 0);
-    if ( ! MMSUCCESS(Result) )
-    {
-        /* TODO: Destroy sound instance */
-        return TranslateInternalMmResult(Result);
-    }
-
-    /* Store the device instance pointer in the private handle - is DWORD safe here? */
-    *PrivateHandle = (DWORD_PTR) SoundDeviceInstance;
-
-    /* Store the additional information we were given - FIXME: Need flags! */
-    SetSoundDeviceInstanceMmeData(SoundDeviceInstance,
-                                  (HDRVR)OpenParameters->hmx,
-                                  OpenParameters->dwCallback,
-                                  OpenParameters->dwInstance,
-                                  Flags);
-
-    /* Let the application know the device is open */
-    ReleaseEntrypointMutex(DeviceType);
-#if 0
-    NotifyMmeClient(SoundDeviceInstance,
-                    DeviceType == WAVE_OUT_DEVICE_TYPE ? WOM_OPEN : WIM_OPEN,
-                    0);
-#endif
-    AcquireEntrypointMutex(DeviceType);
-
-    SND_TRACE(L"Mixer device now open\n");
-
-    return MMSYSERR_NOERROR;
-}
-
 /*
     Standard MME driver entry-point for messages relating to mixers.
 */
@@ -188,18 +95,18 @@ mxdMessage(
 
         case MXDM_OPEN :
         {
-            Result = MmeOpenMixerDevice(MIXER_DEVICE_TYPE,
-                                       DeviceId,
-                                       (LPMIXEROPENDESC) Parameter1,
-                                       Parameter2,
-                                       (DWORD*) PrivateHandle);
+            Result = MmeOpenDevice(MIXER_DEVICE_TYPE,
+                                   DeviceId,
+                                   (LPWAVEOPENDESC) Parameter1, /* unused */
+                                   Parameter2,
+                                   (DWORD*) PrivateHandle);
 
             break;
         }
 
         case MXDM_CLOSE :
         {
-            Result = MmeCloseMixerDevice(PrivateHandle);
+            Result = MmeCloseDevice(PrivateHandle);
 
             break;
         }
index 960c483..583d198 100644 (file)
@@ -119,7 +119,7 @@ MmeGetSoundDeviceCapabilities(
 }
 
 MMRESULT
-MmeOpenWaveDevice(
+MmeOpenDevice(
     IN  MMDEVICE_TYPE DeviceType,
     IN  UINT DeviceId,
     IN  LPWAVEOPENDESC OpenParameters,
@@ -127,34 +127,37 @@ MmeOpenWaveDevice(
     OUT DWORD_PTR* PrivateHandle)
 {
     MMRESULT Result;
-
+    UINT Message;
     PSOUND_DEVICE SoundDevice;
     PSOUND_DEVICE_INSTANCE SoundDeviceInstance;
     LPWAVEFORMATEX Format;
 
-    SND_TRACE(L"Opening wave device (WIDM_OPEN / WODM_OPEN)");
+    SND_TRACE(L"Opening device");
 
     VALIDATE_MMSYS_PARAMETER( IS_WAVE_DEVICE_TYPE(DeviceType) );    /* FIXME? wave in too? */
     VALIDATE_MMSYS_PARAMETER( OpenParameters );
 
-    Format = OpenParameters->lpFormat;
-
     Result = GetSoundDevice(DeviceType, DeviceId, &SoundDevice);
     if ( ! MMSUCCESS(Result) )
         return TranslateInternalMmResult(Result);
 
-    /* Does this device support the format? */
-    Result = QueryWaveDeviceFormatSupport(SoundDevice, Format, sizeof(WAVEFORMATEX));
-    if ( ! MMSUCCESS(Result) )
+    if (DeviceType == WAVE_IN_DEVICE_TYPE || DeviceType == WAVE_OUT_DEVICE_TYPE)
     {
-        SND_ERR(L"Format not supported\n");
-        return TranslateInternalMmResult(Result);
+        Format = OpenParameters->lpFormat;
+
+        /* Does this device support the format? */
+        Result = QueryWaveDeviceFormatSupport(SoundDevice, Format, sizeof(WAVEFORMATEX));
+        if ( ! MMSUCCESS(Result) )
+        {
+            SND_ERR(L"Format not supported\n");
+            return TranslateInternalMmResult(Result);
+        }
+
+        /* If the caller just wanted to know if a format is supported, end here */
+        if ( Flags & WAVE_FORMAT_QUERY )
+            return MMSYSERR_NOERROR;
     }
 
-    /* If the caller just wanted to know if a format is supported, end here */
-    if ( Flags & WAVE_FORMAT_QUERY )
-        return MMSYSERR_NOERROR;
-
     /* Check that winmm gave us a private handle to fill */
     VALIDATE_MMSYS_PARAMETER( PrivateHandle );
 
@@ -175,20 +178,35 @@ MmeOpenWaveDevice(
 
     /* Store the additional information we were given - FIXME: Need flags! */
     SetSoundDeviceInstanceMmeData(SoundDeviceInstance,
-                                  (HDRVR)OpenParameters->hWave,
+                                  (HDRVR)OpenParameters->hWave, /* works because LPMIXEROPENDESC/etc has also the handle as first member */
                                   OpenParameters->dwCallback,
                                   OpenParameters->dwInstance,
                                   Flags);
 
-    /* Let the application know the device is open */
-    ReleaseEntrypointMutex(DeviceType);
-    NotifyMmeClient(SoundDeviceInstance,
-                    DeviceType == WAVE_OUT_DEVICE_TYPE ? WOM_OPEN : WIM_OPEN,
-                    0);
+    if (DeviceType == WAVE_OUT_DEVICE_TYPE || DeviceType == WAVE_IN_DEVICE_TYPE ||
+        DeviceType == MIDI_OUT_DEVICE_TYPE || DeviceType == MIDI_IN_DEVICE_TYPE)
+    {
+        /* Let the application know the device is open */
+
+        if (DeviceType == WAVE_OUT_DEVICE_TYPE)
+            Message = WOM_OPEN;
+        else if (DeviceType == WAVE_IN_DEVICE_TYPE)
+            Message = WIM_OPEN;
+        else if (DeviceType == MIDI_IN_DEVICE_TYPE)
+            Message = MIM_OPEN;
+        else
+            Message = MOM_OPEN;
 
-    AcquireEntrypointMutex(DeviceType);
+        ReleaseEntrypointMutex(DeviceType);
 
-    SND_TRACE(L"Wave device now open\n");
+        NotifyMmeClient(SoundDeviceInstance,
+                        Message,
+                        0);
+
+        AcquireEntrypointMutex(DeviceType);
+    }
+
+    SND_TRACE(L"device now open\n");
 
     return MMSYSERR_NOERROR;
 }
@@ -201,6 +219,7 @@ MmeCloseDevice(
     PSOUND_DEVICE_INSTANCE SoundDeviceInstance;
     PSOUND_DEVICE SoundDevice;
     MMDEVICE_TYPE DeviceType;
+    UINT Message = 0;
 
     SND_TRACE(L"Closing wave device (WIDM_CLOSE / WODM_CLOSE)\n");
 
@@ -221,12 +240,26 @@ MmeCloseDevice(
 
     /* TODO: Check device is stopped! */
 
-    ReleaseEntrypointMutex(DeviceType);
-    /* TODO: Work with MIDI devices too */
-    NotifyMmeClient(SoundDeviceInstance,
-                    DeviceType == WAVE_OUT_DEVICE_TYPE ? WOM_CLOSE : WIM_CLOSE,
-                    0);
-    AcquireEntrypointMutex(DeviceType);
+
+    if (DeviceType != MIXER_DEVICE_TYPE)
+    {
+        ReleaseEntrypointMutex(DeviceType);
+
+        if (DeviceType == WAVE_OUT_DEVICE_TYPE)
+            Message = WOM_CLOSE;
+        else if (DeviceType == WAVE_IN_DEVICE_TYPE)
+            Message = WIM_CLOSE;
+        else if (DeviceType == MIDI_IN_DEVICE_TYPE)
+            Message = MIM_CLOSE;
+        else if (DeviceType == MIDI_OUT_DEVICE_TYPE)
+            Message = MOM_CLOSE;
+
+        /* TODO: Work with MIDI devices too */
+        NotifyMmeClient(SoundDeviceInstance,
+                        Message,
+                        0);
+        AcquireEntrypointMutex(DeviceType);
+    }
 
     Result = DestroySoundDeviceInstance(SoundDeviceInstance);
 
index 47825ae..6584d3d 100644 (file)
@@ -68,7 +68,7 @@ widMessage(
         }
         case WIDM_OPEN :
         {
-            Result = MmeOpenWaveDevice(WAVE_IN_DEVICE_TYPE,
+            Result = MmeOpenDevice(WAVE_IN_DEVICE_TYPE,
                                        DeviceId,
                                        (LPWAVEOPENDESC) Parameter1,
                                        Parameter2,
index 70bd6b7..330c5f2 100644 (file)
@@ -65,11 +65,11 @@ wodMessage(
 
         case WODM_OPEN :
         {
-            Result = MmeOpenWaveDevice(WAVE_OUT_DEVICE_TYPE,
-                                       DeviceId,
-                                       (LPWAVEOPENDESC) Parameter1,
-                                       Parameter2,
-                                       (DWORD_PTR*)PrivateHandle);
+            Result = MmeOpenDevice(WAVE_OUT_DEVICE_TYPE,
+                                   DeviceId,
+                                   (LPWAVEOPENDESC) Parameter1,
+                                   Parameter2,
+                                   (DWORD_PTR*)PrivateHandle);
             break;
         }