From 38242931f129ec33287ec847117542b0319183bc Mon Sep 17 00:00:00 2001 From: Johannes Anderwald Date: Mon, 21 Feb 2011 04:22:45 +0000 Subject: [PATCH] [MMEBUDDY] - Check if there is a reset request in progress while the wave thread is active. In that case exit the wave buffer commiting activity - In the reset routine, perform an alertable wait in order to make the apc io completion complete [PORTCLS] - Only perform copying audio bytes to dma buffer while the adapter is reset state is KSREST_END - Set the reset state indicator before canceling the audio buffers - Should fix the audio hang experienced in Winamp when skipping audio bytes svn path=/trunk/; revision=50851 --- .../wdm/audio/backpln/portcls/pin_wavecyclic.cpp | 10 ++++++++-- .../lib/drivers/sound/mmebuddy/wave/streaming.c | 16 +++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/reactos/drivers/wdm/audio/backpln/portcls/pin_wavecyclic.cpp b/reactos/drivers/wdm/audio/backpln/portcls/pin_wavecyclic.cpp index 7733606c6a5..fd7fc9de6c7 100644 --- a/reactos/drivers/wdm/audio/backpln/portcls/pin_wavecyclic.cpp +++ b/reactos/drivers/wdm/audio/backpln/portcls/pin_wavecyclic.cpp @@ -823,7 +823,7 @@ CPortPinWaveCyclic::RequestService() PC_ASSERT_IRQL(DISPATCH_LEVEL); - if (m_State == KSSTATE_RUN) + if (m_State == KSSTATE_RUN && m_ResetState == KSRESET_END) { Status = m_Stream->GetPosition(&Position); @@ -904,13 +904,19 @@ CPortPinWaveCyclic::DeviceIoControl( /* check for success */ if (NT_SUCCESS(Status)) { + //determine state of reset request if (ResetValue == KSRESET_BEGIN) { - m_IrpQueue->CancelBuffers(); + // start reset procress + // incoming read/write requests will be rejected m_ResetState = KSRESET_BEGIN; + + // cancel existing buffers + m_IrpQueue->CancelBuffers(); } else if (ResetValue == KSRESET_END) { + // end of reset process m_ResetState = KSRESET_END; } } diff --git a/reactos/lib/drivers/sound/mmebuddy/wave/streaming.c b/reactos/lib/drivers/sound/mmebuddy/wave/streaming.c index 63ac5e0a89d..320ac398238 100644 --- a/reactos/lib/drivers/sound/mmebuddy/wave/streaming.c +++ b/reactos/lib/drivers/sound/mmebuddy/wave/streaming.c @@ -60,7 +60,7 @@ DoWaveStreaming( } while ( ( SoundDeviceInstance->OutstandingBuffers < SoundDeviceInstance->BufferCount ) && - ( Header ) ) + ( Header ) && SoundDeviceInstance->ResetInProgress == FALSE) { HeaderExtension = (PWAVEHDR_EXTENSION) Header->reserved; SND_ASSERT( HeaderExtension ); @@ -176,8 +176,6 @@ CompleteIO( WaveHdr = (PWAVEHDR) SoundOverlapped->Header; SND_ASSERT( WaveHdr ); - SND_ASSERT( ERROR_SUCCESS == dwErrorCode ); - HdrExtension = (PWAVEHDR_EXTENSION) WaveHdr->reserved; SND_ASSERT( HdrExtension ); @@ -305,6 +303,12 @@ StopStreamingInSoundThread( /* cancel all current audio buffers */ FunctionTable->ResetStream(SoundDeviceInstance, DeviceType, TRUE); } + while(SoundDeviceInstance->OutstandingBuffers) + { + SND_TRACE(L"StopStreamingInSoundThread OutStandingBufferCount %lu\n", SoundDeviceInstance->OutstandingBuffers); + /* wait until pending i/o has completed */ + SleepEx(10, TRUE); + } /* complete all current headers */ while( SoundDeviceInstance->HeadWaveHeader ) @@ -316,12 +320,6 @@ StopStreamingInSoundThread( /* there should be no oustanding buffers now */ SND_ASSERT(SoundDeviceInstance->OutstandingBuffers == 0); - while(SoundDeviceInstance->OutstandingBuffers) - { - SND_ERR("StopStreamingInSoundThread OutStandingBufferCount %lu\n", SoundDeviceInstance->OutstandingBuffers); - /* my hack of doom */ - Sleep(10); - } /* Check if reset function is supported */ if (FunctionTable->ResetStream)