From 8a8976c460616f3c2cab2c02293674ffb7cb0443 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 23 Dec 2006 11:31:10 +0000 Subject: [PATCH] merge RageSound::GetPositionSeconds and GetPositionSecondsInternal; fix lock order --- stepmania/src/RageSound.cpp | 54 +++++++++++++++++-------------------- stepmania/src/RageSound.h | 1 - 2 files changed, 24 insertions(+), 31 deletions(-) diff --git a/stepmania/src/RageSound.cpp b/stepmania/src/RageSound.cpp index aaf718564d..995391bb38 100644 --- a/stepmania/src/RageSound.cpp +++ b/stepmania/src/RageSound.cpp @@ -428,33 +428,6 @@ int RageSound::GetSourceFrameFromHardwareFrame( int64_t iHardwareFrame, bool *bA return (int) iSourceFrame; } -/* Get the position in frames. */ -int64_t RageSound::GetPositionSecondsInternal( bool *bApproximate, RageTimer *pTimer ) const -{ - LockMut( m_Mutex ); - - if( bApproximate ) - *bApproximate = false; - - /* If we're not playing, just report the static position. */ - if( !IsPlaying() ) - return m_iStoppedSourceFrame; - - /* If we don't yet have any position data, CommitPlayingPosition hasn't yet been called at all, - * so guess what we think the real time is. */ - if( m_HardwareToStreamMap.IsEmpty() || m_StreamToSourceMap.IsEmpty() ) - { - // LOG->Trace( "no data yet; %i", m_iStoppedSourceFrame ); - if( bApproximate ) - *bApproximate = true; - return m_iStoppedSourceFrame; - } - - /* Get our current hardware position. */ - int64_t iCurrentHardwareFrame = SOUNDMAN->GetPosition( pTimer ); - return GetSourceFrameFromHardwareFrame( iCurrentHardwareFrame, bApproximate ); -} - /* * If non-NULL, approximate is set to true if the returned time is approximated because of * underrun, the sound not having started (after Play()) or finished (after EOF) yet. @@ -463,13 +436,34 @@ int64_t RageSound::GetPositionSecondsInternal( bool *bApproximate, RageTimer *pT * position. We might take a variable amount of time before grabbing the timestamp (to * lock SOUNDMAN); we might lose the scheduler after grabbing it, when releasing SOUNDMAN. */ - float RageSound::GetPositionSeconds( bool *bApproximate, RageTimer *pTimestamp ) const { + /* Get our current hardware position. */ + int64_t iCurrentHardwareFrame = SOUNDMAN->GetPosition( pTimestamp ); + + /* Lock the mutex after calling SOUNDMAN->GetPosition(). We must not make driver + * calls with our mutex locked (driver mutex < sound mutex). */ LockMut( m_Mutex ); - const int64_t iPositionFrames = GetPositionSecondsInternal( bApproximate, pTimestamp ); - return iPositionFrames / float(samplerate()); + if( bApproximate ) + *bApproximate = false; + + /* If we're not playing, just report the static position. */ + if( !IsPlaying() ) + return m_iStoppedSourceFrame / float(samplerate()); + + /* If we don't yet have any position data, CommitPlayingPosition hasn't yet been called at all, + * so guess what we think the real time is. */ + if( m_HardwareToStreamMap.IsEmpty() || m_StreamToSourceMap.IsEmpty() ) + { + // LOG->Trace( "no data yet; %i", m_iStoppedSourceFrame ); + if( bApproximate ) + *bApproximate = true; + return m_iStoppedSourceFrame / float(samplerate()); + } + + int iSourceFrame = GetSourceFrameFromHardwareFrame( iCurrentHardwareFrame, bApproximate ); + return iSourceFrame / float(samplerate()); } diff --git a/stepmania/src/RageSound.h b/stepmania/src/RageSound.h index 22d91d15ac..d545910a39 100644 --- a/stepmania/src/RageSound.h +++ b/stepmania/src/RageSound.h @@ -173,7 +173,6 @@ private: RString m_sError; - int64_t GetPositionSecondsInternal( bool *bApproximate = NULL, RageTimer *pTimer = NULL ) const; int GetSourceFrameFromHardwareFrame( int64_t iHardwareFrame, bool *bApproximate = NULL ) const; bool SetPositionFrames( int frames = -1 );