From: <man...@us...> - 2015-04-23 13:03:15
|
Revision: 4974 http://sourceforge.net/p/modplug/code/4974 Author: manxorist Date: 2015-04-23 13:03:08 +0000 (Thu, 23 Apr 2015) Log Message: ----------- [Ref] sounddev: Kill IFillAudioBuffer and move the responsibility of locking and unlocking the sound source to the sound device code itself instead of relying on ping-pong callback hierarchies. This simplifies the sound device interface by flattening the callback stack. Modified Paths: -------------- trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Mainfrm.h trunk/OpenMPT/sounddev/SoundDevice.cpp trunk/OpenMPT/sounddev/SoundDevice.h Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2015-04-23 12:58:08 UTC (rev 4973) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2015-04-23 13:03:08 UTC (rev 4974) @@ -177,6 +177,7 @@ // CMainFrame construction/destruction CMainFrame::CMainFrame() //---------------------- + : m_SoundDeviceFillBufferCriticalSection(CriticalSection::InitialUnlocked) { m_NotifyTimer = 0; gpSoundDevice = NULL; @@ -670,16 +671,24 @@ } -void CMainFrame::FillAudioBufferLocked(SoundDevice::IFillAudioBuffer &callback) -//----------------------------------------------------------------------------- +void CMainFrame::SoundSourceLock() +//-------------------------------- { MPT_TRACE(); - CriticalSection cs; + m_SoundDeviceFillBufferCriticalSection.Enter(); MPT_ASSERT_ALWAYS(m_pSndFile != nullptr); m_AudioThreadId = GetCurrentThreadId(); mpt::log::Trace::SetThreadId(mpt::log::Trace::ThreadKindAudio, m_AudioThreadId); - callback.FillAudioBuffer(); +} + + +void CMainFrame::SoundSourceUnlock() +//---------------------------------- +{ + MPT_TRACE(); + MPT_ASSERT_ALWAYS(m_pSndFile != nullptr); m_AudioThreadId = 0; + m_SoundDeviceFillBufferCriticalSection.Leave(); } @@ -705,8 +714,8 @@ }; -void CMainFrame::AudioRead(const SoundDevice::Settings &settings, const SoundDevice::Flags &flags, const SoundDevice::BufferAttributes &bufferAttributes, SoundDevice::TimeInfo timeInfo, std::size_t numFrames, void *buffer) -//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +void CMainFrame::SoundSourceRead(const SoundDevice::Settings &settings, const SoundDevice::Flags &flags, const SoundDevice::BufferAttributes &bufferAttributes, SoundDevice::TimeInfo timeInfo, std::size_t numFrames, void *buffer) +//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- { MPT_TRACE(); ASSERT(InAudioThread()); @@ -738,8 +747,8 @@ } -void CMainFrame::AudioDone(const SoundDevice::Settings &settings, const SoundDevice::Flags &flags, const SoundDevice::BufferAttributes &bufferAttributes, SoundDevice::TimeInfo timeInfo, std::size_t numFrames, int64 streamPosition) -//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ +void CMainFrame::SoundSourceDone(const SoundDevice::Settings &settings, const SoundDevice::Flags &flags, const SoundDevice::BufferAttributes &bufferAttributes, SoundDevice::TimeInfo timeInfo, std::size_t numFrames, int64 streamPosition) +//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ { MPT_TRACE(); MPT_UNREFERENCED_PARAMETER(settings); Modified: trunk/OpenMPT/mptrack/Mainfrm.h =================================================================== --- trunk/OpenMPT/mptrack/Mainfrm.h 2015-04-23 12:58:08 UTC (rev 4973) +++ trunk/OpenMPT/mptrack/Mainfrm.h 2015-04-23 13:03:08 UTC (rev 4974) @@ -349,6 +349,7 @@ public: // Low-Level Audio + CriticalSection m_SoundDeviceFillBufferCriticalSection; Util::MultimediaClock m_SoundDeviceClock; SoundDevice::IBase *gpSoundDevice; UINT_PTR m_NotifyTimer; @@ -408,10 +409,11 @@ void SoundSourcePreStartCallback(); void SoundSourcePostStopCallback(); bool SoundSourceIsLockedByCurrentThread() const; - void FillAudioBufferLocked(SoundDevice::IFillAudioBuffer &callback); - void AudioRead(const SoundDevice::Settings &settings, const SoundDevice::Flags &flags, const SoundDevice::BufferAttributes &bufferAttributes, SoundDevice::TimeInfo timeInfo, std::size_t numFrames, void *buffer); - void AudioDone(const SoundDevice::Settings &settings, const SoundDevice::Flags &flags, const SoundDevice::BufferAttributes &bufferAttributes, SoundDevice::TimeInfo timeInfo, std::size_t numFrames, int64 streamPosition); - + void SoundSourceLock(); + void SoundSourceRead(const SoundDevice::Settings &settings, const SoundDevice::Flags &flags, const SoundDevice::BufferAttributes &bufferAttributes, SoundDevice::TimeInfo timeInfo, std::size_t numFrames, void *buffer); + void SoundSourceDone(const SoundDevice::Settings &settings, const SoundDevice::Flags &flags, const SoundDevice::BufferAttributes &bufferAttributes, SoundDevice::TimeInfo timeInfo, std::size_t numFrames, int64 streamPosition); + void SoundSourceUnlock(); + // from SoundDevice::IMessageReceiver void SoundDeviceMessage(LogLevel level, const mpt::ustring &str); Modified: trunk/OpenMPT/sounddev/SoundDevice.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.cpp 2015-04-23 12:58:08 UTC (rev 4973) +++ trunk/OpenMPT/sounddev/SoundDevice.cpp 2015-04-23 13:03:08 UTC (rev 4974) @@ -237,14 +237,6 @@ } -void Base::FillAudioBuffer() -//-------------------------- -{ - MPT_TRACE(); - InternalFillAudioBuffer(); -} - - uint64 Base::SourceGetReferenceClockNowNanoseconds() const //-------------------------------------------------------- { @@ -297,7 +289,8 @@ MPT_TRACE(); if(m_Source) { - m_Source->FillAudioBufferLocked(*this); + ISource::Guard lock(*m_Source); + InternalFillAudioBuffer(); } } @@ -337,7 +330,7 @@ { return; } - m_Source->AudioRead(m_Settings, m_Flags, GetEffectiveBufferAttributes(), m_TimeInfo, numFrames, buffer); + m_Source->SoundSourceRead(m_Settings, m_Flags, GetEffectiveBufferAttributes(), m_TimeInfo, numFrames, buffer); } @@ -357,7 +350,7 @@ m_StreamPositionOutputFrames = m_StreamPositionRenderFrames - framesLatency; framesRendered = m_StreamPositionRenderFrames; } - m_Source->AudioDone(m_Settings, m_Flags, GetEffectiveBufferAttributes(), m_TimeInfo, numFrames, framesRendered); + m_Source->SoundSourceDone(m_Settings, m_Flags, GetEffectiveBufferAttributes(), m_TimeInfo, numFrames, framesRendered); } Modified: trunk/OpenMPT/sounddev/SoundDevice.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.h 2015-04-23 12:58:08 UTC (rev 4973) +++ trunk/OpenMPT/sounddev/SoundDevice.h 2015-04-23 13:03:08 UTC (rev 4974) @@ -29,15 +29,6 @@ //==================== -class IFillAudioBuffer -//==================== -{ -public: - virtual void FillAudioBuffer() = 0; -}; - - -//==================== class IMessageReceiver //==================== { @@ -75,9 +66,26 @@ virtual void SoundSourcePreStartCallback() = 0; virtual void SoundSourcePostStopCallback() = 0; virtual bool SoundSourceIsLockedByCurrentThread() const = 0; - virtual void FillAudioBufferLocked(SoundDevice::IFillAudioBuffer &callback) = 0; // take any locks needed while rendering audio and then call FillAudioBuffer - virtual void AudioRead(const SoundDevice::Settings &settings, const SoundDevice::Flags &flags, const SoundDevice::BufferAttributes &bufferAttributes, SoundDevice::TimeInfo timeInfo, std::size_t numFrames, void *buffer) = 0; - virtual void AudioDone(const SoundDevice::Settings &settings, const SoundDevice::Flags &flags, const SoundDevice::BufferAttributes &bufferAttributes, SoundDevice::TimeInfo timeInfo, std::size_t numFrames, int64 streamPosition) = 0; // in sample frames + virtual void SoundSourceLock() = 0; + virtual void SoundSourceRead(const SoundDevice::Settings &settings, const SoundDevice::Flags &flags, const SoundDevice::BufferAttributes &bufferAttributes, SoundDevice::TimeInfo timeInfo, std::size_t numFrames, void *buffer) = 0; + virtual void SoundSourceDone(const SoundDevice::Settings &settings, const SoundDevice::Flags &flags, const SoundDevice::BufferAttributes &bufferAttributes, SoundDevice::TimeInfo timeInfo, std::size_t numFrames, int64 streamPosition) = 0; // in sample frames + virtual void SoundSourceUnlock() = 0; +public: + class Guard + { + private: + ISource &m_Source; + public: + Guard(ISource &source) + : m_Source(source) + { + m_Source.SoundSourceLock(); + } + ~Guard() + { + m_Source.SoundSourceUnlock(); + } + }; }; @@ -486,7 +494,6 @@ //========= class IBase //========= - : protected IFillAudioBuffer { protected: @@ -497,10 +504,6 @@ virtual ~IBase() { } -protected: - - virtual void FillAudioBuffer() = 0; - public: virtual void SetSource(SoundDevice::ISource *source) = 0; @@ -593,8 +596,6 @@ virtual void InternalFillAudioBuffer() = 0; - void FillAudioBuffer(); - uint64 SourceGetReferenceClockNowNanoseconds() const; void SourceNotifyPreStart(); void SourceNotifyPostStop(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |