From: <man...@us...> - 2013-10-25 13:26:51
|
Revision: 3016 http://sourceforge.net/p/modplug/code/3016 Author: manxorist Date: 2013-10-25 13:26:42 +0000 (Fri, 25 Oct 2013) Log Message: ----------- [Ref] sounddev: ISoundDevice::Reset() is only ever called directly before Close() and Close() does a superset of Reset() for all device types. The implementation for DirectSound called IDirectSoundBuffer::stop() from the wrong thread. And generelly, the intendet semantics for ISoundDevice::Reset() are totally unclear and the implemented semantics differ depending on the actual device type. Just remove it, it is just not needed. [Fix] sounddev: Ensure InternalClose() is only ever called if the output has been Stop()ed before. Modified Paths: -------------- trunk/OpenMPT/mptrack/ExceptionHandler.cpp trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/sounddev/SoundDevice.cpp trunk/OpenMPT/sounddev/SoundDevice.h trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp trunk/OpenMPT/sounddev/SoundDeviceASIO.h trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp trunk/OpenMPT/sounddev/SoundDevicePortAudio.h trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp trunk/OpenMPT/sounddev/SoundDeviceWaveout.h trunk/OpenMPT/sounddev/SoundDevices.h Modified: trunk/OpenMPT/mptrack/ExceptionHandler.cpp =================================================================== --- trunk/OpenMPT/mptrack/ExceptionHandler.cpp 2013-10-25 11:06:48 UTC (rev 3015) +++ trunk/OpenMPT/mptrack/ExceptionHandler.cpp 2013-10-25 13:26:42 UTC (rev 3016) @@ -148,7 +148,6 @@ { if(pMainFrame->gpSoundDevice) { - pMainFrame->gpSoundDevice->Reset(); pMainFrame->gpSoundDevice->Close(); } if(pMainFrame->m_NotifyTimer) Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2013-10-25 11:06:48 UTC (rev 3015) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2013-10-25 13:26:42 UTC (rev 3016) @@ -873,7 +873,6 @@ { if(gpSoundDevice) { - gpSoundDevice->Reset(); gpSoundDevice->Close(); } Modified: trunk/OpenMPT/sounddev/SoundDevice.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-10-25 11:06:48 UTC (rev 3015) +++ trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-10-25 13:26:42 UTC (rev 3016) @@ -100,6 +100,7 @@ bool ISoundDevice::Open(const SoundDeviceSettings &settings) //---------------------------------------------------------- { + if(IsOpen()) return false; m_Settings = settings; if(m_Settings.LatencyMS < SNDDEV_MINLATENCY_MS) m_Settings.LatencyMS = SNDDEV_MINLATENCY_MS; if(m_Settings.LatencyMS > SNDDEV_MAXLATENCY_MS) m_Settings.LatencyMS = SNDDEV_MAXLATENCY_MS; @@ -114,6 +115,8 @@ bool ISoundDevice::Close() //------------------------ { + if(!IsOpen()) return true; + Stop(); return InternalClose(); } @@ -204,15 +207,6 @@ } -void ISoundDevice::Reset() -//------------------------ -{ - if(!IsOpen()) return; - Stop(); - InternalReset(); -} - - int64 ISoundDevice::GetStreamPositionSamples() const //-------------------------------------------------- { @@ -612,14 +606,7 @@ } -void CSoundDeviceWithThread::InternalReset() -//------------------------------------------ -{ - ResetFromOutsideSoundThread(); -} - - /////////////////////////////////////////////////////////////////////////////////////// // // Global Functions Modified: trunk/OpenMPT/sounddev/SoundDevice.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.h 2013-10-25 11:06:48 UTC (rev 3015) +++ trunk/OpenMPT/sounddev/SoundDevice.h 2013-10-25 13:26:42 UTC (rev 3016) @@ -262,17 +262,15 @@ virtual bool InternalOpen() = 0; virtual void InternalStart() = 0; virtual void InternalStop() = 0; - virtual void InternalReset() = 0; virtual bool InternalClose() = 0; virtual bool InternalHasGetStreamPosition() const { return false; } virtual int64 InternalGetStreamPositionSamples() const { return 0; } public: - bool Open(const SoundDeviceSettings &settings); // Open a device - bool Close(); // Close the currently open device + bool Open(const SoundDeviceSettings &settings); + bool Close(); void Start(); void Stop(); - void Reset(); int64 GetStreamPositionSamples() const; SampleFormat GetActualSampleFormat() { return IsOpen() ? m_Settings.sampleFormat : SampleFormatInvalid; } virtual bool IsOpen() const = 0; Modified: trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2013-10-25 11:06:48 UTC (rev 3015) +++ trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2013-10-25 13:26:42 UTC (rev 3016) @@ -176,7 +176,6 @@ CASIODevice::~CASIODevice() //------------------------- { - Reset(); Close(); } @@ -459,30 +458,6 @@ } -void CASIODevice::InternalReset() -//------------------------------- -{ - if(IsOpen()) - { - Stop(); - if(m_bMixRunning) - { - m_bMixRunning = FALSE; - ALWAYS_ASSERT(g_asio_startcount==0); - try - { - m_pAsioDrv->stop(); - } catch(...) - { - CASIODevice::ReportASIOException("ASIO crash in stop()\n"); - } - g_asio_startcount = 0; - SetRenderSilence(false); - } - } -} - - void CASIODevice::OpenDevice() //---------------------------- { Modified: trunk/OpenMPT/sounddev/SoundDeviceASIO.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceASIO.h 2013-10-25 11:06:48 UTC (rev 3015) +++ trunk/OpenMPT/sounddev/SoundDeviceASIO.h 2013-10-25 13:26:42 UTC (rev 3016) @@ -59,7 +59,6 @@ bool InternalOpen(); bool InternalClose(); void FillAudioBuffer(); - void InternalReset(); void InternalStart(); void InternalStop(); bool IsOpen() const { return (m_pAsioDrv != NULL); } Modified: trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp 2013-10-25 11:06:48 UTC (rev 3015) +++ trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp 2013-10-25 13:26:42 UTC (rev 3016) @@ -108,7 +108,6 @@ CDSoundDevice::~CDSoundDevice() //----------------------------- { - Reset(); Close(); } @@ -305,17 +304,6 @@ } -void CDSoundDevice::ResetFromOutsideSoundThread() -//----------------------------------------------- -{ - if(m_pMixBuffer) - { - m_pMixBuffer->Stop(); - } - m_bMixRunning = FALSE; -} - - DWORD CDSoundDevice::LockBuffer(DWORD dwBytes, LPVOID *lpBuf1, LPDWORD lpSize1, LPVOID *lpBuf2, LPDWORD lpSize2) //-------------------------------------------------------------------------------------------------------------- { Modified: trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h 2013-10-25 11:06:48 UTC (rev 3015) +++ trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h 2013-10-25 13:26:42 UTC (rev 3016) @@ -45,7 +45,6 @@ bool InternalOpen(); bool InternalClose(); void FillAudioBuffer(); - void ResetFromOutsideSoundThread(); void StartFromSoundThread(); void StopFromSoundThread(); bool IsOpen() const { return (m_pMixBuffer != NULL); } Modified: trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp 2013-10-25 11:06:48 UTC (rev 3015) +++ trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp 2013-10-25 13:26:42 UTC (rev 3016) @@ -41,7 +41,6 @@ CPortaudioDevice::~CPortaudioDevice() //----------------------------------- { - Reset(); Close(); } @@ -113,13 +112,6 @@ } -void CPortaudioDevice::InternalReset() -//------------------------------------ -{ - Pa_AbortStream(m_Stream); -} - - void CPortaudioDevice::InternalStart() //------------------------------------ { Modified: trunk/OpenMPT/sounddev/SoundDevicePortAudio.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevicePortAudio.h 2013-10-25 11:06:48 UTC (rev 3015) +++ trunk/OpenMPT/sounddev/SoundDevicePortAudio.h 2013-10-25 13:26:42 UTC (rev 3016) @@ -46,7 +46,6 @@ bool InternalOpen(); bool InternalClose(); void FillAudioBuffer(); - void InternalReset(); void InternalStart(); void InternalStop(); bool IsOpen() const { return m_Stream ? true : false; } Modified: trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp 2013-10-25 11:06:48 UTC (rev 3015) +++ trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp 2013-10-25 13:26:42 UTC (rev 3016) @@ -46,7 +46,6 @@ CWaveDevice::~CWaveDevice() //------------------------- { - Reset(); Close(); } @@ -108,10 +107,12 @@ bool CWaveDevice::InternalClose() //------------------------------- { - Reset(); - if (m_hWaveOut) + if(m_hWaveOut) { - ResetFromOutsideSoundThread(); // always reset so that waveOutClose does not fail if we did only P->Stop() (meaning waveOutPause()) before + waveOutReset(m_hWaveOut); + m_JustStarted = false; + InterlockedExchange(&m_nBuffersPending, 0); + m_nWriteBuffer = 0; while (m_nPreparedHeaders > 0) { m_nPreparedHeaders--; @@ -147,19 +148,6 @@ } -void CWaveDevice::ResetFromOutsideSoundThread() -//--------------------------------------------- -{ - if(m_hWaveOut) - { - waveOutReset(m_hWaveOut); - m_JustStarted = false; - } - InterlockedExchange(&m_nBuffersPending, 0); - m_nWriteBuffer = 0; -} - - void CWaveDevice::FillAudioBuffer() //--------------------------------- { Modified: trunk/OpenMPT/sounddev/SoundDeviceWaveout.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceWaveout.h 2013-10-25 11:06:48 UTC (rev 3015) +++ trunk/OpenMPT/sounddev/SoundDeviceWaveout.h 2013-10-25 13:26:42 UTC (rev 3016) @@ -44,7 +44,6 @@ bool InternalOpen(); bool InternalClose(); void FillAudioBuffer(); - void ResetFromOutsideSoundThread(); void StartFromSoundThread(); void StopFromSoundThread(); bool IsOpen() const { return (m_hWaveOut != NULL); } Modified: trunk/OpenMPT/sounddev/SoundDevices.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevices.h 2013-10-25 11:06:48 UTC (rev 3015) +++ trunk/OpenMPT/sounddev/SoundDevices.h 2013-10-25 13:26:42 UTC (rev 3016) @@ -67,9 +67,7 @@ virtual ~CSoundDeviceWithThread() {} void InternalStart(); void InternalStop(); - void InternalReset(); virtual void StartFromSoundThread() = 0; virtual void StopFromSoundThread() = 0; - virtual void ResetFromOutsideSoundThread() = 0; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |