Author: silverblade
Date: Sat Jul 19 23:20:29 2008
New Revision: 34599
URL:
http://svn.reactos.org/svn/reactos?rev=34599&view=rev
Log:
Re-implemented the device list. Separated allocation/init and cleanup/free
of sound device information from the insertion into/removal from the list.
Got debug output working in NT4 so this no longer plasters message boxes all
over the screen or outputs to command prompt window. "Multimedia" control
panel applet in NT4 happily loads and unloads this component, but since the
device count is reported but no device names, it doesn't do much more than
this.
Previously, debugging these components was quite awkward as the only debug
output I could get was via popup messages or spat out to the command prompt
window via printf, meaning if I had no console window (such is the case when
using a Windows program to interact with the sound device) I'd get less debug
info and would have to keep clicking OK to continue. Then it'd crash.
Now that NT4 is becoming friends with my sndblst.dll implementation (and the
support library I'm developing) and debug info is output to something I can
scroll through etc. things should be a bit easier.
Removed:
branches/silverblade-audio/lib/drivers/sound/mmebuddy/mmebuddy.rbuild~
Modified:
branches/silverblade-audio/dll/win32/sndblst/sndblst.c
branches/silverblade-audio/include/reactos/libs/sound/mmebuddy.h
branches/silverblade-audio/lib/drivers/sound/mmebuddy/devicelist.c
branches/silverblade-audio/lib/drivers/sound/mmebuddy/nt4.c
Modified: branches/silverblade-audio/dll/win32/sndblst/sndblst.c
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/dll/win32/snd…
==============================================================================
--- branches/silverblade-audio/dll/win32/sndblst/sndblst.c [iso-8859-1] (original)
+++ branches/silverblade-audio/dll/win32/sndblst/sndblst.c [iso-8859-1] Sat Jul 19
23:20:29 2008
@@ -29,7 +29,7 @@
MMRESULT Result;
PSOUND_DEVICE SoundDevice = NULL;
- POPUP(DevicePath);
+ SND_TRACE(L"Callback received: %wS\n", DevicePath);
/*
MMFUNCTION_TABLE FuncTable;
@@ -65,7 +65,7 @@
{
case DRV_LOAD :
{
- POPUP(L"DRV_LOAD");
+ SND_TRACE(L"DRV_LOAD\n");
Result = InitEntrypointMutexes();
@@ -80,8 +80,7 @@
{
CleanupEntrypointMutexes();
- Result = UnlistAllSoundDevices();
- SND_ASSERT( Result == MMSYSERR_NOERROR );
+ UnlistAllSoundDevices();
return 0L;
}
@@ -91,22 +90,32 @@
case DRV_FREE :
{
- POPUP(L"DRV_FREE");
+ SND_TRACE(L"DRV_FREE\n");
+
+ UnlistAllSoundDevices();
CleanupEntrypointMutexes();
- POPUP(L"Unfreed memory blocks: %d", GetMemoryAllocationCount());
+ SND_TRACE(L"Unfreed memory blocks: %d\n",
+ GetMemoryAllocationCount());
return 1L;
}
case DRV_QUERYCONFIGURE :
+ {
+ SND_TRACE(L"DRV_QUERYCONFIGURE");
return 0L;
+ }
case DRV_CONFIGURE :
return DRVCNF_OK;
default :
- return 1L;
+ return DefDriverProc(DriverId,
+ DriverHandle,
+ Message,
+ Parameter1,
+ Parameter2);
}
}
@@ -364,16 +373,16 @@
switch ( fdwReason )
{
case DLL_PROCESS_ATTACH :
- MessageBox(0, L"DLL_PROCESS_ATTACH", L"DllMain", MB_OK |
MB_TASKMODAL);
+ SND_TRACE(L"DLL_PROCESS_ATTACH\n");
break;
case DLL_PROCESS_DETACH :
- MessageBox(0, L"DLL_PROCESS_DETACH", L"DllMain", MB_OK |
MB_TASKMODAL);
+ SND_TRACE(L"DLL_PROCESS_DETACH\n");
break;
case DLL_THREAD_ATTACH :
- MessageBox(0, L"DLL_THREAD_ATTACH", L"DllMain", MB_OK |
MB_TASKMODAL);
+ SND_TRACE(L"DLL_THREAD_ATTACH\n");
break;
case DLL_THREAD_DETACH :
- MessageBox(0, L"DLL_THREAD_DETACH", L"DllMain", MB_OK |
MB_TASKMODAL);
+ SND_TRACE(L"DLL_THREAD_DETACH\n");
break;
}
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] Sat Jul
19 23:20:29 2008
@@ -54,7 +54,9 @@
{ \
if ( ! ( condition ) ) \
{ \
- SND_ERR(L"ASSERT FAILED: %wS\n", #condition); \
+ SND_ERR(L"ASSERT FAILED: %hS\n", #condition); \
+ POPUP(L"ASSERT FAILED: %hS\n", #condition); \
+ ExitProcess(1); \
} \
}
#else
@@ -113,7 +115,7 @@
{ \
if ( ! (parameter_condition) ) \
{ \
- SND_ERR(L"Parameter check: %s\n", #parameter_condition); \
+ SND_ERR(L"FAILED parameter check: %hS\n", #parameter_condition); \
return MMSYSERR_INVALPARAM; \
} \
}
@@ -127,6 +129,9 @@
typedef struct _SOUND_DEVICE
{
+ struct _SOUND_DEVICE* Next;
+ MMDEVICE_TYPE Type;
+ PWSTR Path;
} SOUND_DEVICE, *PSOUND_DEVICE;
typedef struct _SOUND_DEVICE_INSTANCE
@@ -169,7 +174,7 @@
MMRESULT
ListSoundDevice(
IN MMDEVICE_TYPE DeviceType,
- IN LPWSTR DevicePath,
+ IN LPWSTR DevicePath OPTIONAL,
OUT PSOUND_DEVICE* SoundDevice OPTIONAL);
MMRESULT
@@ -181,7 +186,7 @@
UnlistSoundDevices(
IN MMDEVICE_TYPE DeviceType);
-MMRESULT
+VOID
UnlistAllSoundDevices();
MMRESULT
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] Sat
Jul 19 23:20:29 2008
@@ -13,8 +13,79 @@
#include <mmebuddy.h>
ULONG SoundDeviceCounts[SOUND_DEVICE_TYPES];
-PSOUND_DEVICE SoundDeviceLists[SOUND_DEVICE_TYPES];
-
+PSOUND_DEVICE SoundDeviceListHeads[SOUND_DEVICE_TYPES];
+PSOUND_DEVICE SoundDeviceListTails[SOUND_DEVICE_TYPES];
+
+/*
+ Handles the allocation and initialisation of a SOUND_DEVICE structure.
+*/
+MMRESULT
+AllocateSoundDevice(
+ IN MMDEVICE_TYPE DeviceType,
+ IN PWSTR DevicePath OPTIONAL,
+ OUT PSOUND_DEVICE* SoundDevice)
+{
+ PSOUND_DEVICE NewDevice;
+
+ SND_ASSERT( IsValidSoundDeviceType(DeviceType) );
+ SND_ASSERT( SoundDevice );
+
+ SND_TRACE(L"Allocating SOUND_DEVICE for %wS\n", DevicePath);
+
+ NewDevice = AllocateStruct(SOUND_DEVICE);
+
+ if ( ! NewDevice )
+ return MMSYSERR_NOMEM;
+
+ NewDevice->Type = DeviceType;
+
+ /* Only copy the device path if one was actually passed in */
+ if ( DevicePath )
+ {
+ NewDevice->Path = AllocateWideString(wcslen(DevicePath));
+
+ if ( ! NewDevice->Path )
+ {
+ FreeMemory(NewDevice);
+ NewDevice = NULL;
+ return MMSYSERR_NOMEM;
+ }
+
+ CopyWideString(NewDevice->Path, DevicePath);
+ }
+
+ /* TODO: Initialise function table */
+
+ /* Return the new structure to the caller and report success */
+ *SoundDevice = NewDevice;
+
+ return MMSYSERR_NOERROR;
+}
+
+/*
+ Handles the cleanup and freeing of a SOUND_DEVICE structure.
+*/
+VOID
+FreeSoundDevice(
+ IN PSOUND_DEVICE SoundDevice)
+{
+ SND_ASSERT( SoundDevice );
+
+ SND_TRACE(L"Freeing SOUND_DEVICE for %wS\n", SoundDevice->Path);
+
+ if ( SoundDevice->Path )
+ {
+ FreeMemory(SoundDevice->Path);
+ }
+
+ FreeMemory(SoundDevice);
+}
+
+/*
+ Returns the number of devices of the specified type which have been added
+ to the device lists. If an invalid device type is specified, the function
+ returns zero.
+*/
ULONG
GetSoundDeviceCount(
IN MMDEVICE_TYPE DeviceType)
@@ -29,41 +100,173 @@
return SoundDeviceCounts[Index];
}
+/*
+ Determines if a sound device structure pointer is valid, firstly by
+ ensuring that it is not NULL, and then by checking that the device itself
+ exists in one of the device lists.
+*/
BOOLEAN
IsValidSoundDevice(
IN PSOUND_DEVICE SoundDevice)
{
+ if ( ! SoundDevice )
+ return FALSE;
+
+ /* TODO */
return TRUE;
}
+/*
+ Informs the MME-Buddy library that it should take ownership of a device.
+ The DevicePath is typically used for storing a device path (for subsequent
+ opening using CreateFile) but it can be a wide-string representing any
+ information that makes sense to your MME driver implementation.
+
+ MME components which operate solely in user-mode (for example, MIDI
+ loopback devices) won't need to communicate with a kernel-mode device,
+ so in these situations DevicePath is likely to be NULL.
+
+ Upon successful addition to the sound device list, the pointer to the new
+ device's SOUND_DEVICE structure is returned via SoundDevice.
+*/
MMRESULT
ListSoundDevice(
IN MMDEVICE_TYPE DeviceType,
- IN LPWSTR DevicePath,
- OUT PSOUND_DEVICE* SoundDevice)
-{
- return MMSYSERR_NOTSUPPORTED;
-}
-
+ IN LPWSTR DevicePath OPTIONAL,
+ OUT PSOUND_DEVICE* SoundDevice OPTIONAL)
+{
+ MMRESULT Result;
+ PSOUND_DEVICE NewDevice;
+ UCHAR TypeIndex = SOUND_DEVICE_TYPE_TO_INDEX(DeviceType);
+
+ VALIDATE_MMSYS_PARAMETER( IsValidSoundDeviceType(DeviceType) );
+
+ Result = AllocateSoundDevice(DeviceType, DevicePath, &NewDevice);
+
+ if ( Result != MMSYSERR_NOERROR )
+ {
+ SND_ERR(L"Failed to allocate SOUND_DEVICE structure\n");
+ return Result;
+ }
+
+ if ( ! SoundDeviceListHeads[TypeIndex] )
+ {
+ SND_TRACE(L"Putting first entry into device list %d\n", DeviceType);
+ SoundDeviceListHeads[TypeIndex] = NewDevice;
+ SoundDeviceListTails[TypeIndex] = NewDevice;
+ }
+ else
+ {
+ SND_TRACE(L"Putting another entry into device list %d\n", DeviceType);
+ SoundDeviceListTails[TypeIndex]->Next = NewDevice;
+ SoundDeviceListTails[TypeIndex] = NewDevice;
+ }
+
+ /* Add to the count */
+ ++ SoundDeviceCounts[TypeIndex];
+
+ /* Fill in the caller's PSOUND_DEVICE */
+ if ( SoundDevice )
+ {
+ *SoundDevice = NewDevice;
+ }
+
+ return MMSYSERR_NOERROR;
+}
+
+/*
+ Removes a sound device from the list, and frees the memory associated
+ with its description.
+*/
MMRESULT
UnlistSoundDevice(
IN MMDEVICE_TYPE DeviceType,
IN PSOUND_DEVICE SoundDevice)
{
- return MMSYSERR_NOTSUPPORTED;
+ PSOUND_DEVICE CurrentDevice, PreviousDevice;
+
+ UCHAR TypeIndex = SOUND_DEVICE_TYPE_TO_INDEX(DeviceType);
+
+ VALIDATE_MMSYS_PARAMETER( IsValidSoundDeviceType(DeviceType) );
+ VALIDATE_MMSYS_PARAMETER( IsValidSoundDevice(SoundDevice) );
+
+ PreviousDevice = NULL;
+ CurrentDevice = SoundDeviceListHeads[TypeIndex];
+
+ while ( CurrentDevice )
+ {
+ if ( CurrentDevice == SoundDevice )
+ {
+ if ( ! PreviousDevice )
+ {
+ /* This is the head node */
+ SND_TRACE(L"Removing head node from device list %d\n",
DeviceType);
+ SoundDeviceListHeads[TypeIndex] =
+ SoundDeviceListHeads[TypeIndex]->Next;
+ }
+ else
+ {
+ SND_TRACE(L"Removing node from device list %d\n", DeviceType);
+ /* There are nodes before this one - cut our device out */
+ PreviousDevice->Next = CurrentDevice->Next;
+ }
+
+ if ( ! CurrentDevice->Next )
+ {
+ /* This is the tail node */
+ SND_TRACE(L"Removing tail node from device list %d\n",
DeviceType);
+ SoundDeviceListTails[TypeIndex] = PreviousDevice;
+ }
+ }
+
+ PreviousDevice = CurrentDevice;
+ CurrentDevice = CurrentDevice->Next;
+ }
+
+ /* Subtract from the count */
+ -- SoundDeviceCounts[TypeIndex];
+
+ /* Finally, free up the deleted entry */
+ FreeSoundDevice(SoundDevice);
+
+ return MMSYSERR_NOERROR;
}
MMRESULT
UnlistSoundDevices(
IN MMDEVICE_TYPE DeviceType)
{
- return MMSYSERR_NOTSUPPORTED;
-}
-
-MMRESULT
+ UCHAR TypeIndex;
+ VALIDATE_MMSYS_PARAMETER( IsValidSoundDeviceType(DeviceType) );
+
+ SND_TRACE(L"Unlisting all sound devices of type %d\n", DeviceType);
+
+ TypeIndex = SOUND_DEVICE_TYPE_TO_INDEX(DeviceType);
+
+ /* Munch away at the head of the list until it's drained */
+ while ( SoundDeviceCounts[TypeIndex] > 0 )
+ {
+ MMRESULT Result;
+ Result = UnlistSoundDevice(DeviceType, SoundDeviceListHeads[TypeIndex]);
+ SND_ASSERT( Result == MMSYSERR_NOERROR );
+ }
+
+ return MMSYSERR_NOERROR;
+}
+
+VOID
UnlistAllSoundDevices()
{
- return MMSYSERR_NOTSUPPORTED;
+ MMDEVICE_TYPE Type;
+
+ SND_TRACE(L"Unlisting all sound devices\n");
+
+ for ( Type = MIN_SOUND_DEVICE_TYPE; Type <= MAX_SOUND_DEVICE_TYPE; ++ Type )
+ {
+ MMRESULT Result;
+ Result = UnlistSoundDevices(Type);
+ SND_ASSERT( Result == MMSYSERR_NOERROR );
+ }
}
MMRESULT
Removed: branches/silverblade-audio/lib/drivers/sound/mmebuddy/mmebuddy.rbuild~
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/lib/drivers/s…
==============================================================================
--- branches/silverblade-audio/lib/drivers/sound/mmebuddy/mmebuddy.rbuild~ [iso-8859-1]
(original)
+++ branches/silverblade-audio/lib/drivers/sound/mmebuddy/mmebuddy.rbuild~ (removed)
@@ -1,25 +1,0 @@
-<?xml version="1.0"?>
-<!DOCTYPE module SYSTEM "../../../../tools/rbuild/project.dtd">
-<module name="mmebuddy" type="staticlibrary"
allowwarnings="false" unicode="yes">
- <include base="ReactOS">include/reactos/libs/sound</include>
- <define name="DEBUG_NT4">1</define>
- <file>devicelist.c</file>
- <file>reentrancy.c</file>
- <file>utility.c</file>
- <file>nt4.c</file>
- <file>kernel.c</file>
- <directory name="wave">
- <file>widMessage.c</file>
- <file>wodMessage.c</file>
- </directory>
- <directory name="midi">
- <file>midMessage.c</file>
- <file>modMessage.c</file>
- </directory>
- <directory name="mixer">
- <file>mxdMessage.c</file>
- </directory>
- <directory name="auxiliary">
- <file>auxMessage.c</file>
- </directory>
-</module>
Modified: branches/silverblade-audio/lib/drivers/sound/mmebuddy/nt4.c
URL:
http://svn.reactos.org/svn/reactos/branches/silverblade-audio/lib/drivers/s…
==============================================================================
--- branches/silverblade-audio/lib/drivers/sound/mmebuddy/nt4.c [iso-8859-1] (original)
+++ branches/silverblade-audio/lib/drivers/sound/mmebuddy/nt4.c [iso-8859-1] Sat Jul 19
23:20:29 2008
@@ -50,6 +50,8 @@
ServiceName,
REG_PARAMETERS_KEY_NAME_U);
+ SND_TRACE(L"Opening reg key: %wS\n", ParametersKeyName);
+
/* Perform the open */
if ( RegOpenKeyEx(HKEY_LOCAL_MACHINE,
ParametersKeyName,
@@ -58,6 +60,7 @@
KeyHandle) != ERROR_SUCCESS )
{
/* Couldn't open the key */
+ SND_ERR(L"Failed to open reg key: %wS\n", ParametersKeyName);
FreeMemory(ParametersKeyName);
return MMSYSERR_ERROR;
}
@@ -114,6 +117,8 @@
REG_DEVICE_KEY_NAME_U,
DeviceIndex);
+ SND_TRACE(L"Opening reg key: %wS\n", RegPath);
+
/* Perform the open */
if ( RegOpenKeyEx(HKEY_LOCAL_MACHINE,
RegPath,
@@ -122,6 +127,7 @@
KeyHandle) != ERROR_SUCCESS )
{
/* Couldn't open the key */
+ SND_ERR(L"Failed to open reg key: %wS\n", RegPath);
FreeMemory(RegPath);
return MMSYSERR_ERROR;
}
@@ -173,6 +179,7 @@
&MaxNameLength,
NULL, NULL, NULL) != ERROR_SUCCESS )
{
+ SND_ERR(L"Failed to query registry key information\n");
RegCloseKey(DevicesKey);
RegCloseKey(Key);
@@ -217,6 +224,7 @@
if ( ( DeviceType == 0 ) ||
( DeviceType == ValueData ) )
{
+ SND_TRACE(L"Found device: %wS\n", DevicePath);
SoundDeviceDetectedProc(ValueData, DevicePath);
}
}
@@ -262,7 +270,7 @@
{
ULONG DeviceNameLength = 0;
PWSTR DeviceName = NULL;
- ULONG Index = 0, Count = 0;
+ ULONG Index = 0;
HANDLE DeviceHandle;
BOOLEAN DoSearch = TRUE;
@@ -290,10 +298,8 @@
&DeviceHandle) == MMSYSERR_NOERROR )
{
/* Notify the callback function */
- if ( SoundDeviceDetectedProc(DeviceType, DeviceName) )
- {
- ++ Count;
- }
+ SND_TRACE(L"Found device: %wS\n", DeviceName);
+ SoundDeviceDetectedProc(DeviceType, DeviceName);
CloseHandle(DeviceHandle);