From: <man...@us...> - 2014-10-10 13:26:16
|
Revision: 4409 http://sourceforge.net/p/modplug/code/4409 Author: manxorist Date: 2014-10-10 13:26:08 +0000 (Fri, 10 Oct 2014) Log Message: ----------- [Ref] Debug: Add MPT_TRACE() to all sound device related functions in CMainFrame and to all functions in CASIODevice in order to better understand ASIO-related threading bugs. Modified Paths: -------------- trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2014-10-10 13:23:10 UTC (rev 4408) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2014-10-10 13:26:08 UTC (rev 4409) @@ -458,6 +458,7 @@ void CMainFrame::OnClose() //------------------------ { + MPT_TRACE(); if(!(TrackerSettings::Instance().m_dwPatternSetup & PATTERN_NOCLOSEDIALOG)) { // Show modified documents window @@ -618,6 +619,7 @@ void CMainFrame::OnTimerNotify() //------------------------------ { + MPT_TRACE(); ASSERT(InGuiThread()); ASSERT(!InNotifyHandler()); m_InNotifyHandler = true; @@ -664,6 +666,7 @@ void CMainFrame::AudioMessage(const std::string &str) //--------------------------------------------------- { + MPT_TRACE(); Reporting::Notification(str.c_str()); } @@ -671,6 +674,7 @@ void CMainFrame::FillAudioBufferLocked(SoundDevice::IFillAudioBuffer &callback) //----------------------------------------------------------------------------- { + MPT_TRACE(); CriticalSection cs; ALWAYS_ASSERT(m_pSndFile != nullptr); m_AudioThreadId = GetCurrentThreadId(); @@ -755,6 +759,7 @@ void CMainFrame::AudioRead(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()); OPENMPT_PROFILE_FUNCTION(Profiler::Audio); TimingInfo timingInfo; @@ -787,6 +792,7 @@ void CMainFrame::AudioDone(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); MPT_UNREFERENCED_PARAMETER(flags); MPT_UNREFERENCED_PARAMETER(bufferAttributes); @@ -801,6 +807,7 @@ bool CMainFrame::IsAudioDeviceOpen() const //---------------------------------------- { + MPT_TRACE(); return gpSoundDevice && gpSoundDevice->IsOpen(); } @@ -808,6 +815,7 @@ bool CMainFrame::audioOpenDevice() //-------------------------------- { + MPT_TRACE(); if(!TrackerSettings::Instance().GetMixerSettings().IsValid()) { Reporting::Error("Unable to open sound device: Invalid mixer settings."); @@ -864,6 +872,7 @@ void CMainFrame::audioCloseDevice() //--------------------------------- { + MPT_TRACE(); if(gpSoundDevice) { gpSoundDevice->Close(); @@ -913,6 +922,7 @@ bool CMainFrame::DoNotification(DWORD dwSamplesRead, int64 streamPosition) //------------------------------------------------------------------------ { + MPT_TRACE(); ASSERT(InAudioThread()); if(!m_pSndFile) return false; @@ -1195,6 +1205,7 @@ void CMainFrame::ResetNotificationBuffer() //---------------------------------------- { + MPT_TRACE(); Util::lock_guard<Util::mutex> lock(m_NotificationBufferMutex); m_NotifyBuffer.clear(); } @@ -1203,6 +1214,7 @@ bool CMainFrame::PreparePlayback() //-------------------------------- { + MPT_TRACE(); // open the audio device to update needed TrackerSettings mixer parameters if(!audioOpenDevice()) return false; return true; @@ -1212,6 +1224,7 @@ bool CMainFrame::StartPlayback() //------------------------------ { + MPT_TRACE(); if(!m_pSndFile) return false; // nothing to play if(!IsAudioDeviceOpen()) return false; if(!gpSoundDevice->Start()) return false; @@ -1232,6 +1245,7 @@ void CMainFrame::StopPlayback() //----------------------------- { + MPT_TRACE(); if(!IsAudioDeviceOpen()) return; gpSoundDevice->Stop(); if(m_NotifyTimer) @@ -1250,6 +1264,7 @@ bool CMainFrame::RestartPlayback() //-------------------------------- { + MPT_TRACE(); if(!m_pSndFile) return false; // nothing to play if(!IsAudioDeviceOpen()) return false; if(!gpSoundDevice->IsPlaying()) return false; @@ -1267,6 +1282,7 @@ bool CMainFrame::PausePlayback() //------------------------------ { + MPT_TRACE(); if(!IsAudioDeviceOpen()) return false; gpSoundDevice->Stop(); if(m_NotifyTimer) @@ -1658,6 +1674,7 @@ void CMainFrame::IdleHandlerSounddevice() //--------------------------------------- { + MPT_TRACE(); if(gpSoundDevice) { const LONG requestFlags = gpSoundDevice->GetRequestFlags(); @@ -1682,6 +1699,7 @@ BOOL CMainFrame::ResetSoundCard() //------------------------------- { + MPT_TRACE(); return CMainFrame::SetupSoundCard(TrackerSettings::Instance().GetSoundDeviceSettings(TrackerSettings::Instance().GetSoundDeviceIdentifier()), TrackerSettings::Instance().GetSoundDeviceIdentifier(), TrackerSettings::Instance().m_SoundSettingsStopMode, true); } @@ -1689,6 +1707,7 @@ BOOL CMainFrame::SetupSoundCard(SoundDevice::Settings deviceSettings, SoundDevice::Identifier deviceIdentifier, SoundDevice::StopMode stoppedMode, bool forceReset) //----------------------------------------------------------------------------------------------------------------------------------------------------------------- { + MPT_TRACE(); if(forceReset || (TrackerSettings::Instance().GetSoundDeviceIdentifier() != deviceIdentifier) || (TrackerSettings::Instance().GetSoundDeviceSettings(deviceIdentifier) != deviceSettings) Modified: trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2014-10-10 13:23:10 UTC (rev 4408) +++ trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2014-10-10 13:26:08 UTC (rev 4409) @@ -111,6 +111,7 @@ std::vector<SoundDevice::Info> CASIODevice::EnumerateDevices() //---------------------------------------------------------- { + MPT_TRACE(); std::vector<SoundDevice::Info> devices; LONG cr; @@ -184,6 +185,7 @@ //---------------------------------------------- : SoundDevice::Base(info) { + MPT_TRACE(); InitMembers(); m_QueriedFeatures.reset(); m_UsedFeatures.reset(); @@ -193,6 +195,7 @@ void CASIODevice::InitMembers() //----------------------------- { + MPT_TRACE(); m_pAsioDrv = nullptr; m_nAsioBufferLen = 0; @@ -219,6 +222,7 @@ bool CASIODevice::HandleRequests() //-------------------------------- { + MPT_TRACE(); bool result = false; LONG flags = InterlockedExchange(&m_AsioRequestFlags, 0); if(flags & AsioRequestFlagLatenciesChanged) @@ -233,6 +237,7 @@ CASIODevice::~CASIODevice() //------------------------- { + MPT_TRACE(); Close(); } @@ -240,6 +245,7 @@ bool CASIODevice::InternalOpen() //------------------------------ { + MPT_TRACE(); ASSERT(!IsDriverOpen()); @@ -468,6 +474,7 @@ void CASIODevice::UpdateLatency() //------------------------------- { + MPT_TRACE(); SoundDevice::BufferAttributes bufferAttributes; long inputLatency = 0; long outputLatency = 0; @@ -497,6 +504,7 @@ void CASIODevice::SetRenderSilence(bool silence, bool wait) //--------------------------------------------------------- { + MPT_TRACE(); InterlockedExchange(&m_RenderSilence, silence?1:0); if(!wait) { @@ -536,6 +544,7 @@ bool CASIODevice::InternalStart() //------------------------------- { + MPT_TRACE(); ALWAYS_ASSERT_WARN_MESSAGE(!CriticalSection::IsLocked(), "AudioCriticalSection locked while starting ASIO"); if(m_Settings.KeepDeviceRunning) @@ -565,18 +574,21 @@ void CASIODevice::InternalStopForce() //----------------------------------- { + MPT_TRACE(); InternalStopImpl(true); } void CASIODevice::InternalStop() //------------------------------ { + MPT_TRACE(); InternalStopImpl(false); } void CASIODevice::InternalStopImpl(bool force) //-------------------------------------------- { + MPT_TRACE(); ALWAYS_ASSERT_WARN_MESSAGE(!CriticalSection::IsLocked(), "AudioCriticalSection locked while stopping ASIO"); if(m_Settings.KeepDeviceRunning && !force) @@ -602,6 +614,7 @@ bool CASIODevice::InternalClose() //------------------------------- { + MPT_TRACE(); if(m_DeviceRunning) { m_DeviceRunning = false; @@ -651,6 +664,7 @@ void CASIODevice::OpenDriver() //---------------------------- { + MPT_TRACE(); if(IsDriverOpen()) { return; @@ -690,6 +704,7 @@ void CASIODevice::CloseDriver() //----------------------------- { + MPT_TRACE(); if(!IsDriverOpen()) { return; @@ -834,6 +849,7 @@ void CASIODevice::InternalFillAudioBuffer() //----------------------------------------- { + MPT_TRACE(); const bool rendersilence = (InterlockedExchangeAdd(&m_RenderSilence, 0) == 1); const int channels = m_Settings.Channels; const std::size_t countChunk = m_nAsioBufferLen; @@ -994,6 +1010,7 @@ bool CASIODevice::InternalHasTimeInfo() const //------------------------------------------- { + MPT_TRACE(); return m_Settings.UseHardwareTiming; } @@ -1001,6 +1018,7 @@ bool CASIODevice::InternalHasGetStreamPosition() const //---------------------------------------------------- { + MPT_TRACE(); return m_Settings.UseHardwareTiming; } @@ -1008,6 +1026,7 @@ int64 CASIODevice::InternalGetStreamPositionFrames() const //-------------------------------------------------------- { + MPT_TRACE(); if(m_Settings.UseHardwareTiming) { const uint64 asioNow = Clock().NowNanoseconds(); @@ -1028,6 +1047,7 @@ void CASIODevice::UpdateTimeInfo(AsioTimeInfo asioTimeInfo) //--------------------------------------------------------- { + MPT_TRACE(); if(m_Settings.UseHardwareTiming) { if((asioTimeInfo.flags & kSamplePositionValid) && (asioTimeInfo.flags & kSystemTimeValid)) @@ -1061,6 +1081,7 @@ void CASIODevice::BufferSwitch(long doubleBufferIndex, ASIOBool directProcess) //---------------------------------------------------------------------------- { + MPT_TRACE(); BufferSwitchTimeInfo(nullptr, doubleBufferIndex, directProcess); // delegate } @@ -1068,6 +1089,7 @@ ASIOTime* CASIODevice::BufferSwitchTimeInfo(ASIOTime* params, long doubleBufferIndex, ASIOBool directProcess) //----------------------------------------------------------------------------------------------------------- { + MPT_TRACE(); ASSERT(directProcess); // !directProcess is not handled correctly in OpenMPT, would require a separate thread and potentially additional buffering if(!directProcess) { @@ -1135,6 +1157,7 @@ void CASIODevice::SampleRateDidChange(ASIOSampleRate sRate) //--------------------------------------------------------- { + MPT_TRACE(); if(Util::Round<uint32>(sRate) == m_Settings.Samplerate) { // not different, ignore it @@ -1170,6 +1193,7 @@ std::string CASIODevice::GetStatistics() const //-------------------------------------------- { + MPT_TRACE(); const FlagSet<AsioFeatures> unsupported((AsioFeatures)(AsioFeatureNoDirectProcess | AsioFeatureOverload | AsioFeatureBufferSizeChange | AsioFeatureSampleRateChange)); FlagSet<AsioFeatures> unsupportedFeatues = m_UsedFeatures; unsupportedFeatues &= unsupported; @@ -1190,6 +1214,7 @@ long CASIODevice::AsioMessage(long selector, long value, void* message, double* opt) //---------------------------------------------------------------------------------- { + MPT_TRACE(); long result = 0; switch(selector) { @@ -1280,6 +1305,7 @@ long CASIODevice::CallbackAsioMessage(long selector, long value, void* message, double* opt) //------------------------------------------------------------------------------------------ { + MPT_TRACE(); ALWAYS_ASSERT(g_CallbacksInstance); if(!g_CallbacksInstance) return 0; return g_CallbacksInstance->AsioMessage(selector, value, message, opt); @@ -1289,6 +1315,7 @@ void CASIODevice::CallbackSampleRateDidChange(ASIOSampleRate sRate) //----------------------------------------------------------------- { + MPT_TRACE(); ALWAYS_ASSERT(g_CallbacksInstance); if(!g_CallbacksInstance) return; g_CallbacksInstance->SampleRateDidChange(sRate); @@ -1298,6 +1325,7 @@ void CASIODevice::CallbackBufferSwitch(long doubleBufferIndex, ASIOBool directProcess) //------------------------------------------------------------------------------------ { + MPT_TRACE(); ALWAYS_ASSERT(g_CallbacksInstance); if(!g_CallbacksInstance) return; g_CallbacksInstance->BufferSwitch(doubleBufferIndex, directProcess); @@ -1307,6 +1335,7 @@ ASIOTime* CASIODevice::CallbackBufferSwitchTimeInfo(ASIOTime* params, long doubleBufferIndex, ASIOBool directProcess) //------------------------------------------------------------------------------------------------------------------- { + MPT_TRACE(); ALWAYS_ASSERT(g_CallbacksInstance); if(!g_CallbacksInstance) return params; return g_CallbacksInstance->BufferSwitchTimeInfo(params, doubleBufferIndex, directProcess); @@ -1316,6 +1345,7 @@ void CASIODevice::ReportASIOException(const std::string &str) //----------------------------------------------------------- { + MPT_TRACE(); AudioSendMessage(str); Log("%s", str.c_str()); } @@ -1324,6 +1354,7 @@ SoundDevice::Caps CASIODevice::InternalGetDeviceCaps() //-------------------------------------------------- { + MPT_TRACE(); SoundDevice::Caps caps; caps.Available = true; @@ -1350,6 +1381,7 @@ SoundDevice::DynamicCaps CASIODevice::GetDeviceDynamicCaps(const std::vector<uint32> &baseSampleRates) //-------------------------------------------------------------------------------------------------- { + MPT_TRACE(); SoundDevice::DynamicCaps caps; TemporaryASIODriverOpener opener(*this); @@ -1425,6 +1457,7 @@ bool CASIODevice::OpenDriverSettings() //------------------------------------ { + MPT_TRACE(); TemporaryASIODriverOpener opener(*this); if(!IsDriverOpen()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |