Author: silverblade
Date: Fri Jan 2 23:20:07 2009
New Revision: 38519
URL:
http://svn.reactos.org/svn/reactos?rev=38519&view=rev
Log:
Implemented device instance tracking list. Also fixed problem with NULL
initialisation of the function table.
Modified:
branches/silverblade-audio/include/reactos/libs/sound/mmebuddy.h
branches/silverblade-audio/lib/drivers/sound/mmebuddy/deviceinstance.c
branches/silverblade-audio/lib/drivers/sound/mmebuddy/devicelist.c
branches/silverblade-audio/lib/drivers/sound/mmebuddy/functiontable.c
Modified: branches/silverblade-audio/include/reactos/libs/sound/mmebuddy.h
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/include/react…
==============================================================================
--- branches/silverblade-audio/include/reactos/libs/sound/mmebuddy.h [iso-8859-1]
(original)
+++ branches/silverblade-audio/include/reactos/libs/sound/mmebuddy.h [iso-8859-1] Fri Jan
2 23:20:07 2009
@@ -60,6 +60,7 @@
ExitProcess(1); \
} \
}
+
#else
#define SND_ERR(...) while ( 0 ) do {}
#define SND_WARN(...) while ( 0 ) do {}
@@ -124,6 +125,9 @@
} \
}
+#define MMSUCCESS(result) \
+ ( result == MMSYSERR_NOERROR )
+
/*
Types and Structures
@@ -188,6 +192,8 @@
typedef struct _SOUND_DEVICE
{
struct _SOUND_DEVICE* Next;
+ struct _SOUND_DEVICE_INSTANCE* HeadInstance;
+ struct _SOUND_DEVICE_INSTANCE* TailInstance;
MMDEVICE_TYPE Type;
PVOID Identifier; /* Path for NT4 drivers */
/*PWSTR Path;*/
@@ -196,6 +202,7 @@
typedef struct _SOUND_DEVICE_INSTANCE
{
+ struct _SOUND_DEVICE_INSTANCE* Next;
struct _SOUND_DEVICE* Device;
PVOID Handle;
@@ -324,7 +331,7 @@
MMRESULT
SetSoundDeviceFunctionTable(
IN PSOUND_DEVICE SoundDevice,
- IN PMMFUNCTION_TABLE FunctionTable);
+ IN PMMFUNCTION_TABLE FunctionTable OPTIONAL);
MMRESULT
GetSoundDeviceFunctionTable(
Modified: branches/silverblade-audio/lib/drivers/sound/mmebuddy/deviceinstance.c
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/lib/drivers/s…
==============================================================================
--- branches/silverblade-audio/lib/drivers/sound/mmebuddy/deviceinstance.c [iso-8859-1]
(original)
+++ branches/silverblade-audio/lib/drivers/sound/mmebuddy/deviceinstance.c [iso-8859-1]
Fri Jan 2 23:20:07 2009
@@ -37,7 +37,9 @@
FreeSoundDeviceInstance(
IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance)
{
- SND_ASSERT( IsValidSoundDeviceInstance(SoundDeviceInstance) );
+ /* This won't work as the device is no longer valid by this point! */
+ /*SND_ASSERT( IsValidSoundDeviceInstance(SoundDeviceInstance) );*/
+ ZeroMemory(SoundDeviceInstance, sizeof(SOUND_DEVICE_INSTANCE));
FreeMemory(SoundDeviceInstance);
}
@@ -45,8 +47,27 @@
IsValidSoundDeviceInstance(
IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance)
{
- /* TODO - do this better */
- return ( SoundDeviceInstance != NULL );
+ PSOUND_DEVICE SoundDevice;
+ PSOUND_DEVICE_INSTANCE CurrentInstance;
+
+ if ( ! SoundDeviceInstance )
+ return FALSE;
+
+ /* GetSoundDeviceFromInstance would send us into a recursive loop... */
+ SoundDevice = SoundDeviceInstance->Device;
+ SND_ASSERT(SoundDevice);
+
+ CurrentInstance = SoundDevice->HeadInstance;
+
+ while ( CurrentInstance )
+ {
+ if ( CurrentInstance == SoundDeviceInstance )
+ return TRUE;
+
+ CurrentInstance = CurrentInstance->Next;
+ }
+
+ return FALSE;
}
MMRESULT
@@ -54,14 +75,72 @@
IN PSOUND_DEVICE SoundDevice,
IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance)
{
- return MMSYSERR_NOTSUPPORTED;
+ VALIDATE_MMSYS_PARAMETER( IsValidSoundDevice(SoundDevice) );
+ VALIDATE_MMSYS_PARAMETER( SoundDeviceInstance );
+
+ SND_TRACE(L"Listing sound device instance\n");
+
+ if ( ! SoundDevice->HeadInstance )
+ {
+ /* First entry - assign to head and tail */
+ SoundDevice->HeadInstance = SoundDeviceInstance;
+ SoundDevice->TailInstance = SoundDeviceInstance;
+ }
+ else
+ {
+ /* Attach to the end */
+ SoundDevice->TailInstance->Next = SoundDeviceInstance;
+ SoundDevice->TailInstance = SoundDeviceInstance;
+ }
+
+ return MMSYSERR_NOERROR;
}
MMRESULT
UnlistSoundDeviceInstance(
IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance)
{
- return MMSYSERR_NOTSUPPORTED;
+ MMRESULT Result;
+ PSOUND_DEVICE SoundDevice;
+ PSOUND_DEVICE_INSTANCE CurrentInstance, PreviousInstance;
+
+ VALIDATE_MMSYS_PARAMETER( IsValidSoundDeviceInstance(SoundDeviceInstance) );
+
+ SND_TRACE(L"Unlisting sound device instance\n");
+
+ Result = GetSoundDeviceFromInstance(SoundDeviceInstance, &SoundDevice);
+ SND_ASSERT( MMSUCCESS(Result) );
+
+ PreviousInstance = NULL;
+ CurrentInstance = SoundDevice->HeadInstance;
+
+ while ( CurrentInstance )
+ {
+ if ( CurrentInstance == SoundDeviceInstance )
+ {
+ if ( ! PreviousInstance )
+ {
+ /* This is the head node */
+ SoundDevice->HeadInstance = SoundDevice->HeadInstance->Next;
+ }
+ else
+ {
+ /* There are nodes before this one - cut ours out */
+ PreviousInstance->Next = CurrentInstance->Next;
+ }
+
+ if ( ! CurrentInstance->Next )
+ {
+ /* This is the tail node */
+ SoundDevice->TailInstance = PreviousInstance;
+ }
+ }
+
+ PreviousInstance = CurrentInstance;
+ CurrentInstance = CurrentInstance->Next;
+ }
+
+ return MMSYSERR_NOERROR;
}
MMRESULT
@@ -97,17 +176,31 @@
}
/* Set up the members of the structure */
+ (*SoundDeviceInstance)->Next = NULL;
(*SoundDeviceInstance)->Device = SoundDevice;
+ (*SoundDeviceInstance)->Handle = NULL;
+
+ (*SoundDeviceInstance)->WinMM.Handle = NULL;
+ (*SoundDeviceInstance)->WinMM.ClientCallback = 0;
+ (*SoundDeviceInstance)->WinMM.ClientCallbackInstanceData = 0;
+ (*SoundDeviceInstance)->WinMM.Flags = 0;
+
+ /* Add the instance to the list */
+ Result = ListSoundDeviceInstance(SoundDevice, *SoundDeviceInstance);
+ if ( ! MMSUCCESS(Result) )
+ {
+ FreeSoundDeviceInstance(*SoundDeviceInstance);
+ return TranslateInternalMmResult(Result);
+ }
/* Try and open the device */
Result = FunctionTable->Open(SoundDevice,
(&(*SoundDeviceInstance)->Handle));
- if ( Result != MMSYSERR_NOERROR )
- {
+ if ( ! MMSUCCESS(Result) )
+ {
+ UnlistSoundDeviceInstance(*SoundDeviceInstance);
FreeSoundDeviceInstance(*SoundDeviceInstance);
return TranslateInternalMmResult(Result);
}
-
- /* TODO: List device */
return MMSYSERR_NOERROR;
}
@@ -126,18 +219,16 @@
VALIDATE_MMSYS_PARAMETER( IsValidSoundDeviceInstance(SoundDeviceInstance) );
Result = GetSoundDeviceFromInstance(SoundDeviceInstance, &SoundDevice);
- if ( Result != MMSYSERR_NOERROR )
- return TranslateInternalMmResult(Result);
-
- /* TODO: Unlist */
+ if ( ! MMSUCCESS(Result) )
+ return TranslateInternalMmResult(Result);
Result = GetSoundDeviceInstanceHandle(SoundDeviceInstance, &Handle);
- if ( Result != MMSYSERR_NOERROR )
+ if ( ! MMSUCCESS(Result) )
return TranslateInternalMmResult(Result);
/* Get the "close" routine from the function table, and validate it */
Result = GetSoundDeviceFunctionTable(SoundDevice, &FunctionTable);
- if ( Result != MMSYSERR_NOERROR )
+ if ( ! MMSUCCESS(Result) )
return TranslateInternalMmResult(Result);
SND_ASSERT( FunctionTable->Close );
@@ -149,7 +240,12 @@
/* Try and close the device */
Result = FunctionTable->Close(SoundDeviceInstance, Handle);
- if ( Result != MMSYSERR_NOERROR )
+ if ( ! MMSUCCESS(Result) )
+ return TranslateInternalMmResult(Result);
+
+ /* Drop it from the list */
+ Result = UnlistSoundDeviceInstance(SoundDeviceInstance);
+ if ( ! MMSUCCESS(Result) )
return TranslateInternalMmResult(Result);
FreeSoundDeviceInstance(SoundDeviceInstance);
Modified: branches/silverblade-audio/lib/drivers/sound/mmebuddy/devicelist.c
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/lib/drivers/s…
==============================================================================
--- branches/silverblade-audio/lib/drivers/sound/mmebuddy/devicelist.c [iso-8859-1]
(original)
+++ branches/silverblade-audio/lib/drivers/sound/mmebuddy/devicelist.c [iso-8859-1] Fri
Jan 2 23:20:07 2009
@@ -172,6 +172,8 @@
/* Set up other members of the structure */
NewDevice->Identifier = Identifier;
+ NewDevice->HeadInstance = NULL;
+ NewDevice->TailInstance = NULL;
/* Fill in the caller's PSOUND_DEVICE */
if ( SoundDevice )
Modified: branches/silverblade-audio/lib/drivers/sound/mmebuddy/functiontable.c
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/lib/drivers/s…
==============================================================================
--- branches/silverblade-audio/lib/drivers/sound/mmebuddy/functiontable.c [iso-8859-1]
(original)
+++ branches/silverblade-audio/lib/drivers/sound/mmebuddy/functiontable.c [iso-8859-1] Fri
Jan 2 23:20:07 2009
@@ -24,18 +24,20 @@
MMRESULT
SetSoundDeviceFunctionTable(
IN PSOUND_DEVICE SoundDevice,
- IN PMMFUNCTION_TABLE FunctionTable)
+ IN PMMFUNCTION_TABLE FunctionTable OPTIONAL)
{
VALIDATE_MMSYS_PARAMETER( IsValidSoundDevice(SoundDevice) );
- VALIDATE_MMSYS_PARAMETER( FunctionTable );
/* Zero out the existing function table (if present) */
ZeroMemory(&SoundDevice->FunctionTable, sizeof(MMFUNCTION_TABLE));
- /* Fill in the client-supplied functions */
- CopyMemory(&SoundDevice->FunctionTable,
- FunctionTable,
- sizeof(MMFUNCTION_TABLE));
+ if ( FunctionTable )
+ {
+ /* Fill in the client-supplied functions */
+ CopyMemory(&SoundDevice->FunctionTable,
+ FunctionTable,
+ sizeof(MMFUNCTION_TABLE));
+ }
return MMSYSERR_NOERROR;
}