Author: silverblade Date: Sun Feb 15 09:19:58 2009 New Revision: 39608
URL: http://svn.reactos.org/svn/reactos?rev=39608&view=rev Log: WaveHdr prepare/unprepare/submit now gets handled within the context of the appropriate sound thread. This removes some responsibility of the sound threading from the actual usermode sound component implementations. Minor cleanup to CallSoundThread as we can deduce the thread handle from the sound device instance.
Modified: trunk/reactos/include/reactos/libs/sound/mmebuddy.h trunk/reactos/lib/drivers/sound/mmebuddy/deviceinstance.c trunk/reactos/lib/drivers/sound/mmebuddy/functiontable.c trunk/reactos/lib/drivers/sound/mmebuddy/thread.c trunk/reactos/lib/drivers/sound/mmebuddy/wave/header.c
Modified: trunk/reactos/include/reactos/libs/sound/mmebuddy.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/libs/sound/... ============================================================================== --- trunk/reactos/include/reactos/libs/sound/mmebuddy.h [iso-8859-1] (original) +++ trunk/reactos/include/reactos/libs/sound/mmebuddy.h [iso-8859-1] Sun Feb 15 09:19:58 2009 @@ -376,7 +376,7 @@ MMRESULT SetSoundDeviceFunctionTable( IN PSOUND_DEVICE SoundDevice, - IN PMMFUNCTION_TABLE FunctionTable OPTIONAL); + IN PMMFUNCTION_TABLE FunctionTable);
MMRESULT GetSoundDeviceFunctionTable( @@ -438,9 +438,8 @@
MMRESULT CallSoundThread( - IN PSOUND_THREAD Thread, + IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, IN SOUND_THREAD_REQUEST_HANDLER RequestHandler, - IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance OPTIONAL, IN PVOID Parameter OPTIONAL);
Modified: trunk/reactos/lib/drivers/sound/mmebuddy/deviceinstance.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/sound/mmebuddy/... ============================================================================== --- trunk/reactos/lib/drivers/sound/mmebuddy/deviceinstance.c [iso-8859-1] (original) +++ trunk/reactos/lib/drivers/sound/mmebuddy/deviceinstance.c [iso-8859-1] Sun Feb 15 09:19:58 2009 @@ -243,7 +243,7 @@ SND_ASSERT( FunctionTable->Close ); if ( FunctionTable->Close == NULL ) { - /* Bad practice, really! If you can open, why not close?! */ + /* This indicates bad practice, really! If you can open, why not close?! */ return MMSYSERR_NOTSUPPORTED; }
Modified: trunk/reactos/lib/drivers/sound/mmebuddy/functiontable.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/sound/mmebuddy/... ============================================================================== --- trunk/reactos/lib/drivers/sound/mmebuddy/functiontable.c [iso-8859-1] (original) +++ trunk/reactos/lib/drivers/sound/mmebuddy/functiontable.c [iso-8859-1] Sun Feb 15 09:19:58 2009 @@ -18,26 +18,26 @@ /* Attaches a function table to a sound device. Any NULL entries in this table are automatically set to point to a default routine to handle - the appropriate function. If NULL is passed as the function table itself, - the entire function table will use only the default routines. + the appropriate function. */ MMRESULT SetSoundDeviceFunctionTable( IN PSOUND_DEVICE SoundDevice, - IN PMMFUNCTION_TABLE FunctionTable OPTIONAL) + IN PMMFUNCTION_TABLE FunctionTable) { VALIDATE_MMSYS_PARAMETER( IsValidSoundDevice(SoundDevice) ); + VALIDATE_MMSYS_PARAMETER( FunctionTable );
/* Zero out the existing function table (if present) */ ZeroMemory(&SoundDevice->FunctionTable, sizeof(MMFUNCTION_TABLE));
- if ( FunctionTable ) - { - /* Fill in the client-supplied functions */ - CopyMemory(&SoundDevice->FunctionTable, - FunctionTable, - sizeof(MMFUNCTION_TABLE)); - } + if ( ! FunctionTable ) + return MMSYSERR_INVALPARAM; + + /* Fill in the client-supplied functions */ + CopyMemory(&SoundDevice->FunctionTable, + FunctionTable, + sizeof(MMFUNCTION_TABLE));
return MMSYSERR_NOERROR; }
Modified: trunk/reactos/lib/drivers/sound/mmebuddy/thread.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/sound/mmebuddy/... ============================================================================== --- trunk/reactos/lib/drivers/sound/mmebuddy/thread.c [iso-8859-1] (original) +++ trunk/reactos/lib/drivers/sound/mmebuddy/thread.c [iso-8859-1] Sun Feb 15 09:19:58 2009 @@ -175,6 +175,7 @@ /* Wake the thread up */ if ( ResumeThread(NewThread->Handle) == -1 ) { + SND_ERR(L"Failed to resume thread!\n"); CloseHandle(NewThread->Handle); DestroySoundThreadEvents(NewThread->Events.Ready, NewThread->Events.Request, @@ -199,13 +200,15 @@
MMRESULT CallSoundThread( - IN PSOUND_THREAD Thread, + IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance, IN SOUND_THREAD_REQUEST_HANDLER RequestHandler, - IN PSOUND_DEVICE_INSTANCE SoundDeviceInstance OPTIONAL, IN PVOID Parameter OPTIONAL) { - VALIDATE_MMSYS_PARAMETER( Thread ); + VALIDATE_MMSYS_PARAMETER( SoundDeviceInstance ); VALIDATE_MMSYS_PARAMETER( RequestHandler ); + + /* TODO: Don't call this directly? */ + PSOUND_THREAD Thread = SoundDeviceInstance->Thread;
SND_TRACE(L"Waiting for READY event\n"); WaitForSingleObject(Thread->Events.Ready, INFINITE);
Modified: trunk/reactos/lib/drivers/sound/mmebuddy/wave/header.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/sound/mmebuddy/... ============================================================================== --- trunk/reactos/lib/drivers/sound/mmebuddy/wave/header.c [iso-8859-1] (original) +++ trunk/reactos/lib/drivers/sound/mmebuddy/wave/header.c [iso-8859-1] Sun Feb 15 09:19:58 2009 @@ -13,6 +13,62 @@ #include <mmddk.h> #include <ntddsnd.h> #include <mmebuddy.h> + + +/* + This structure gets used locally within functions as a way to shuttle data + to the sound thread. It's safe to use locally since CallSoundThread will + not return until the operation has been carried out. +*/ + +typedef struct +{ + MMWAVEHEADER_FUNC Function; + PWAVEHDR Header; +} THREADED_WAVEHEADER_PARAMETERS; + + +/* + Helper routines to simplify the call to the sound thread for the header + functions. +*/ + +MMRESULT +WaveHeaderOperationInSoundThread( + PSOUND_DEVICE_INSTANCE SoundDeviceInstance, + IN PVOID Parameter) +{ + THREADED_WAVEHEADER_PARAMETERS* Parameters = (THREADED_WAVEHEADER_PARAMETERS*) Parameter; + return Parameters->Function(SoundDeviceInstance, Parameters->Header); +} + +MMRESULT +WaveHeaderOperation( + MMWAVEHEADER_FUNC Function, + PSOUND_DEVICE_INSTANCE SoundDeviceInstance, + PWAVEHDR Header) +{ + THREADED_WAVEHEADER_PARAMETERS Parameters; + + Parameters.Function = Function; + Parameters.Header = Header; + + return CallSoundThread(SoundDeviceInstance, + WaveHeaderOperationInSoundThread, + &Parameters); +} + + +/* + The following routines are basically handlers for: + - WODM_PREPARE + - WODM_UNPREPARE + - WODM_WRITE + + All of these calls are ultimately dealt with in the context of the + appropriate sound thread, so the implementation should expect itself to + be running in this other thread when any of these operations take place. +*/
MMRESULT PrepareWaveHeader( @@ -39,7 +95,9 @@ if ( ! FunctionTable->PrepareWaveHeader ) return MMSYSERR_NOTSUPPORTED;
- return FunctionTable->PrepareWaveHeader(SoundDeviceInstance, Header); + return WaveHeaderOperation(FunctionTable->PrepareWaveHeader, + SoundDeviceInstance, + Header); }
MMRESULT @@ -67,7 +125,9 @@ if ( ! FunctionTable->UnprepareWaveHeader ) return MMSYSERR_NOTSUPPORTED;
- return FunctionTable->UnprepareWaveHeader(SoundDeviceInstance, Header); + return WaveHeaderOperation(FunctionTable->UnprepareWaveHeader, + SoundDeviceInstance, + Header); }
MMRESULT @@ -95,6 +155,8 @@ if ( ! FunctionTable->SubmitWaveHeader ) return MMSYSERR_NOTSUPPORTED;
- return FunctionTable->SubmitWaveHeader(SoundDeviceInstance, Header); + return WaveHeaderOperation(FunctionTable->SubmitWaveHeader, + SoundDeviceInstance, + Header); }