[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [Amarok] d0ecb16: EngineController: Add a position guesstimator for
From:       Kelvie Wong <kelvie () ieee ! org>
Date:       2010-04-09 6:48:05
Message-ID: 201004090648.o396m5T0014599 () kore ! kollide ! net
[Download RAW message or body]

commit d0ecb164cdebc25b7c34292609a83072b469191a
Author: Kelvie Wong <kelvie@ieee.org>
Date:   Fri Apr 2 00:34:30 2010 -0700

    EngineController: Add a position guesstimator for bounded playback.
    
    I've noticed that for some backends, the position doesn't update as often as the
    tickInterval.  To remedy this, we count the number of repeated ticks to
    calculate a better position.
    
    The motivation for this fix was for cue tracks that played a little bit over the
    end in certain formats.
    
    I would like to know if this is required, or perhaps the backend should handle
    this and this is just a dirty hack.

diff --git a/src/EngineController.cpp b/src/EngineController.cpp
index d69bd93..6986584 100644
--- a/src/EngineController.cpp
+++ b/src/EngineController.cpp
@@ -80,6 +80,9 @@ EngineController::EngineController()
     , m_currentIsAudioCd( false )
     , m_ignoreVolumeChangeAction ( false )
     , m_ignoreVolumeChangeObserve ( false )
+    , m_tickInterval( 0 )
+    , m_lastTickPosition( -1 )
+    , m_lastTickCount( 0 )
 {
     DEBUG_BLOCK
 
@@ -160,7 +163,8 @@ EngineController::initializePhonon()
     }
 
     m_media->setTickInterval( 100 );
-    debug() << "Tick Interval (actual): " << m_media->tickInterval();
+    m_tickInterval = m_media->tickInterval();
+    debug() << "Tick Interval (actual): " << m_tickInterval;
     PERF_LOG( "EngineController: loaded phonon objects" )
 
     // Get the next track when there is 2 seconds left on the current one.
@@ -880,10 +884,23 @@ EngineController::slotTick( qint64 position )
 {
     if ( m_boundedPlayback )
     {
+        qint64 newPosition = position;
         trackPositionChangedNotify( static_cast<long>( position - \
m_boundedPlayback->startPosition() ), false );  
+        // Calculate a better position.  Sometimes the position doesn't update
+        // with a good resolution (for example, 1 sec for TrueAudio files in the
+        // Xine-1.1.18 backend).  This tick function, in those cases, just gets
+        // called multiple times with the same position.  We count how many
+        // times this has been called prior, and adjust for it.
+        if ( position == m_lastTickPosition )
+            newPosition += ++m_lastTickCount * m_tickInterval;
+        else
+            m_lastTickCount = 0;
+
+        m_lastTickPosition = position;
+
         //don't go beyond the stop point
-        if ( position >= m_boundedPlayback->endPosition() )
+        if ( newPosition >= m_boundedPlayback->endPosition() )
         {
             slotAboutToFinish();
         }
diff --git a/src/EngineController.h b/src/EngineController.h
index 5701d31..4efdc14 100644
--- a/src/EngineController.h
+++ b/src/EngineController.h
@@ -378,6 +378,11 @@ private:
     bool m_ignoreVolumeChangeAction;
     bool m_ignoreVolumeChangeObserve;
 
+    // Used to get a more accurate estimate of the position for slotTick
+    int m_tickInterval;
+    qint64 m_lastTickPosition;
+    qint64 m_lastTickCount;
+
     QMutex m_mutex;
 };
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic