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

List:       kde-commits
Subject:    KDE/kdemultimedia/kmix/backends
From:       Christian Esken <esken () kde ! org>
Date:       2011-08-09 20:22:52
Message-ID: 20110809202252.48060AC871 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1246044 by esken:

Adaptive polling (500ms normally. 50ms during changes)

 M  +33 -3     mixer_backend.cpp  
 M  +3 -0      mixer_backend.h  


--- trunk/KDE/kdemultimedia/kmix/backends/mixer_backend.cpp #1246043:1246044
@@ -54,7 +54,7 @@
         // but we want a somehow usable fallback just in case.
     
         if ( needsPolling() ) {
-            _pollingTimer->start(50);
+            _pollingTimer->start(500);
         }
         else {
             // The initial state must be read manually
@@ -107,15 +107,17 @@
         kDebug(67100) << "Mixer::readSetFromHW(): smart-update-tick";
         return;
     }
+
+    //kDebug() << "---tick---" << QTime::currentTime();
     _readSetFromHWforceUpdate = false;
 
-	int ret = Mixer::OK;
+	int ret = Mixer::OK_UNCHANGED;
 
     int mdCount = m_mixDevices.count();
     for(int i=0; i<mdCount  ; ++i )
     {
         MixDevice *md = m_mixDevices[i];
-        ret = readVolumeFromHW( md->id(), md );
+        int retLoop = readVolumeFromHW( md->id(), md );
         if (md->isEnum() ) {
             /*
              * This could be reworked:
@@ -124,14 +126,42 @@
              */
             md->setEnumId( enumIdHW(md->id()) ); 
         }
+	if ( retLoop == Mixer::OK && ret == Mixer::OK_UNCHANGED )
+	{
+		ret = Mixer::OK;
     }
+	else if ( retLoop != Mixer::OK && retLoop != Mixer::OK_UNCHANGED )
+	{
+		ret = retLoop;
+	}
+    }
     
     if ( ret == Mixer::OK )
 	{
 		// We explicitely exclude Mixer::OK_UNCHANGED and Mixer::ERROR_READ
+		_pollingTimer->setInterval(50);
+		QTime fastPollingEndsAt = QTime::currentTime ();
+		fastPollingEndsAt = fastPollingEndsAt.addSecs(5);
+		_fastPollingEndsAt = fastPollingEndsAt;
+		//_fastPollingEndsAt = fastPollingEndsAt;
+		kDebug() << "Start fast polling from " << QTime::currentTime() <<"until " << _fastPollingEndsAt;
 		emit controlChanged();
 	}
+
+    else
+    {
+    	// This code path is entered on Mixer::OK_UNCHANGED and ERROR
+	    if ( !_fastPollingEndsAt.isNull() )
+	    {
+		if( _fastPollingEndsAt < QTime::currentTime () )
+	    	{
+		    kDebug() << "End fast polling";
+		    _fastPollingEndsAt = QTime();
+		    _pollingTimer->setInterval(500);
 }
+	    }
+    }
+}
 
 /**
  * Return the MixDevice, that would qualify best as MasterDevice. The default is to return the
--- trunk/KDE/kdemultimedia/kmix/backends/mixer_backend.h #1246043:1246044
@@ -22,6 +22,7 @@
 #ifndef MIXER_BACKEND_H
 #define MIXER_BACKEND_H
 
+#include <QTime>
 //#include "core/mixer.h"
 #include "core/mixdevice.h"
 #include "core/mixset.h"
@@ -147,6 +148,8 @@
 
 protected slots:
   virtual void readSetFromHW();
+private:
+  QTime _fastPollingEndsAt;
 };
 
 #endif
[prev in list] [next in list] [prev in thread] [next in thread] 

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