summaryrefslogtreecommitdiffstats
path: root/multimedia/kdemultimedia4/files/patch-svn1250843
blob: 25b83e8b2d027ccf5c20fd766d472f891ad0a83b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
--- ./kmix/backends/mixer_backend.cpp.orig	2011-08-30 10:51:10.757627695 +0200
+++ ./kmix/backends/mixer_backend.cpp	2011-08-30 11:02:19.000000000 +0200
@@ -25,50 +25,54 @@
 #include "core/mixer.h"
 #include <QTimer>
 
+#define POLL_OSS_RATE_SLOW 1500
+#define POLL_OSS_RATE_FAST 50
+
+
 #include "mixer_backend_i18n.cpp"
 
 Mixer_Backend::Mixer_Backend(Mixer *mixer, int device) :
-        m_devnum (device) , m_isOpen(false), m_recommendedMaster(0), _mixer(mixer), _pollingTimer(0)
+m_devnum (device) , m_isOpen(false), m_recommendedMaster(0), _mixer(mixer), _pollingTimer(0)
 
 {
-   // In all cases create a QTimer. We will use it once as a singleShot(), even if something smart
-   // like ::select() is possible (as in ALSA).
-   _pollingTimer = new QTimer(); // will be started on open() and stopped on close()
-   connect( _pollingTimer, SIGNAL(timeout()), this, SLOT(readSetFromHW()), Qt::QueuedConnection);
+	// In all cases create a QTimer. We will use it once as a singleShot(), even if something smart
+	// like ::select() is possible (as in ALSA).
+	_pollingTimer = new QTimer(); // will be started on open() and stopped on close()
+	connect( _pollingTimer, SIGNAL(timeout()), this, SLOT(readSetFromHW()), Qt::QueuedConnection);
 }
 
 Mixer_Backend::~Mixer_Backend()
 {
-    delete _pollingTimer;
-    qDeleteAll(m_mixDevices);
-    m_mixDevices.clear();
+	delete _pollingTimer;
+	qDeleteAll(m_mixDevices);
+	m_mixDevices.clear();
 }
 
 
 bool Mixer_Backend::openIfValid() {
-    bool valid = false;
-    int ret = open();
-    if ( ret == 0  && (m_mixDevices.count() > 0 || _mixer->isDynamic())) {
-        valid = true;
-        // A better ID is now calculated in mixertoolbox.cpp, and set via setID(),
-        // but we want a somehow usable fallback just in case.
-    
-        if ( needsPolling() ) {
-            _pollingTimer->start(50);
-        }
-        else {
-            // The initial state must be read manually
-            QTimer::singleShot( 50, this, SLOT( readSetFromHW() ) );
-        }
-    } // cold be opened
-    else {
-        close();
-    }
-    return valid;
+	bool valid = false;
+	int ret = open();
+	if ( ret == 0  && (m_mixDevices.count() > 0 || _mixer->isDynamic())) {
+		valid = true;
+		// A better ID is now calculated in mixertoolbox.cpp, and set via setID(),
+		// but we want a somehow usable fallback just in case.
+
+		if ( needsPolling() ) {
+			_pollingTimer->start(POLL_OSS_RATE_FAST);
+		}
+		else {
+			// The initial state must be read manually
+			QTimer::singleShot( POLL_OSS_RATE_FAST, this, SLOT(readSetFromHW()) );
+		}
+	} // cold be opened
+	else {
+		close();
+	}
+	return valid;
 }
 
 bool Mixer_Backend::isOpen() {
-  return m_isOpen;
+	return m_isOpen;
 }
 
 /**
@@ -77,7 +81,7 @@
  * @return true, if there are changes. Otherwise false is returned.
  */
 bool Mixer_Backend::prepareUpdateFromHW() {
-  return true;
+	return true;
 }
 
 
@@ -90,47 +94,81 @@
  * 2) When reconstructing any MixerWidget (e.g. DockIcon after applying preferences)
  */
 void Mixer_Backend::readSetFromHWforceUpdate() const {
-   _readSetFromHWforceUpdate = true;
+	_readSetFromHWforceUpdate = true;
 }
 
 
 /**
    You can call this to retrieve the freshest information from the mixer HW.
    This method is also called regulary by the mixer timer.
-*/
+ */
 void Mixer_Backend::readSetFromHW()
 {
-    bool updated = prepareUpdateFromHW();
-    if ( (! updated) && (! _readSetFromHWforceUpdate) ) {
-        // Some drivers (ALSA) are smart. We don't need to run the following
-        // time-consuming update loop if there was no change
-        kDebug(67100) << "Mixer::readSetFromHW(): smart-update-tick";
-        return;
-    }
-    _readSetFromHWforceUpdate = false;
+	bool updated = prepareUpdateFromHW();
+	if ( (! updated) && (! _readSetFromHWforceUpdate) ) {
+		// Some drivers (ALSA) are smart. We don't need to run the following
+		// time-consuming update loop if there was no change
+		kDebug(67100) << "Mixer::readSetFromHW(): smart-update-tick";
+		return;
+	}
 
-	int ret = Mixer::OK;
+	//kDebug() << "---tick---" << QTime::currentTime();
+	_readSetFromHWforceUpdate = false;
 
-    int mdCount = m_mixDevices.count();
-    for(int i=0; i<mdCount  ; ++i )
-    {
-        MixDevice *md = m_mixDevices[i];
-        ret = readVolumeFromHW( md->id(), md );
-        if (md->isEnum() ) {
-            /*
-             * This could be reworked:
-             * Plan: Read everything (incuding enum's) in readVolumeFromHW().
-             * readVolumeFromHW() should then be renamed to readHW().
-             */
-            md->setEnumId( enumIdHW(md->id()) ); 
-        }
-    }
-    
-    if ( 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];
+		int retLoop = readVolumeFromHW( md->id(), md );
+		if (md->isEnum() ) {
+			/*
+			 * This could be reworked:
+			 * Plan: Read everything (incuding enum's) in readVolumeFromHW().
+			 * readVolumeFromHW() should then be renamed to readHW().
+			 */
+			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
+		if ( needsPolling() )
+		{
+			_pollingTimer->setInterval(POLL_OSS_RATE_FAST);
+			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();
+				if ( needsPolling() )
+					_pollingTimer->setInterval(POLL_OSS_RATE_SLOW);
+			}
+		}
+	}
 }
 
 /**
@@ -139,19 +177,19 @@
  * The users preference is NOT returned by this method - see the Mixer class for that.
  */
 MixDevice* Mixer_Backend::recommendedMaster() {
-   if ( m_recommendedMaster != 0 ) {
-      return m_recommendedMaster;   // Backend has set a recommended master. Thats fine.
-   } // recommendation from Backend
-   else if ( m_mixDevices.count() > 0 ) {
-      return m_mixDevices.at(0);  // Backend has NOT set a recommended master. Evil backend => lets help out.
-   } //first device (if exists)
-   else {
-      if ( !_mixer->isDynamic()) {
-         // This should never ever happen, as KMix doe NOT accept soundcards without controls
-         kError(67100) << "Mixer_Backend::recommendedMaster(): returning invalid master. This is a bug in KMix. Please file a bug report stating how you produced this." << endl;
-      }
-      return (MixDevice*)0;
-   }
+	if ( m_recommendedMaster != 0 ) {
+		return m_recommendedMaster;   // Backend has set a recommended master. Thats fine.
+	} // recommendation from Backend
+	else if ( m_mixDevices.count() > 0 ) {
+		return m_mixDevices.at(0);  // Backend has NOT set a recommended master. Evil backend => lets help out.
+	} //first device (if exists)
+	else {
+		if ( !_mixer->isDynamic()) {
+			// This should never ever happen, as KMix doe NOT accept soundcards without controls
+			kError(67100) << "Mixer_Backend::recommendedMaster(): returning invalid master. This is a bug in KMix. Please file a bug report stating how you produced this." << endl;
+		}
+		return (MixDevice*)0;
+	}
 }
 
 /**
@@ -161,7 +199,7 @@
  * code in its subclass (see Mixer_ALSA.cpp for an example).
  */
 void Mixer_Backend::setEnumIdHW(const QString& , unsigned int) {
-  return;
+	return;
 }
 
 /**
@@ -171,55 +209,55 @@
  * code in its subclass (see Mixer_ALSA.cpp for an example).
  */
 unsigned int Mixer_Backend::enumIdHW(const QString& ) {
-  return 0;
+	return 0;
 }
 
 /**
  * Move the stream to a new destination
  */
 bool Mixer_Backend::moveStream( const QString& id, const QString& destId ) {
-  Q_UNUSED(id);
-  Q_UNUSED(destId);
-  return false;
+	Q_UNUSED(id);
+	Q_UNUSED(destId);
+	return false;
 }
 
 void Mixer_Backend::errormsg(int mixer_error)
 {
-  QString l_s_errText;
-  l_s_errText = errorText(mixer_error);
-  kError() << l_s_errText << "\n";
+	QString l_s_errText;
+	l_s_errText = errorText(mixer_error);
+	kError() << l_s_errText << "\n";
 }
 
 int Mixer_Backend::id2num(const QString& id)
 {
-   return id.toInt();
+	return id.toInt();
 }
 
 QString Mixer_Backend::errorText(int mixer_error)
 {
-  QString l_s_errmsg;
-  switch (mixer_error)
-  {
-    case Mixer::ERR_PERM:
-      l_s_errmsg = i18n("kmix:You do not have permission to access the mixer device.\n" \
-	  "Please check your operating systems manual to allow the access.");
-      break;
-    case Mixer::ERR_WRITE:
-      l_s_errmsg = i18n("kmix: Could not write to mixer.");
-      break;
-    case Mixer::ERR_READ:
-      l_s_errmsg = i18n("kmix: Could not read from mixer.");
-      break;
-    case Mixer::ERR_OPEN:
-      l_s_errmsg = i18n("kmix: Mixer cannot be found.\n" \
-	  "Please check that the soundcard is installed and that\n" \
-	  "the soundcard driver is loaded.\n");
-      break;
-    default:
-      l_s_errmsg = i18n("kmix: Unknown error. Please report how you produced this error.");
-      break;
-  }
-  return l_s_errmsg;
+	QString l_s_errmsg;
+	switch (mixer_error)
+	{
+	case Mixer::ERR_PERM:
+		l_s_errmsg = i18n("kmix:You do not have permission to access the mixer device.\n" \
+				"Please check your operating systems manual to allow the access.");
+		break;
+	case Mixer::ERR_WRITE:
+		l_s_errmsg = i18n("kmix: Could not write to mixer.");
+		break;
+	case Mixer::ERR_READ:
+		l_s_errmsg = i18n("kmix: Could not read from mixer.");
+		break;
+	case Mixer::ERR_OPEN:
+		l_s_errmsg = i18n("kmix: Mixer cannot be found.\n" \
+				"Please check that the soundcard is installed and that\n" \
+				"the soundcard driver is loaded.\n");
+		break;
+	default:
+		l_s_errmsg = i18n("kmix: Unknown error. Please report how you produced this error.");
+		break;
+	}
+	return l_s_errmsg;
 }
 
 
--- ./kmix/backends/mixer_backend.h.orig	2011-08-31 14:40:43.854565142 +0200
+++ ./kmix/backends/mixer_backend.h	2011-08-31 14:45:05.104683569 +0200
@@ -22,6 +22,8 @@
 #ifndef MIXER_BACKEND_H
 #define MIXER_BACKEND_H
 
+#include <QTime>
+
 #include "core/mixer.h"
 
 class Mixer_Backend : public QObject
@@ -140,6 +142,9 @@
 
 protected slots:
   virtual void readSetFromHW();
+
+private:
+  QTime _fastPollingEndsAt;
 };
 
 #endif
--- ./kmix/core/mixer.h.orig	2011-08-30 10:43:44.917744648 +0200
+++ ./kmix/core/mixer.h	2011-08-30 10:48:24.467617529 +0200
@@ -56,7 +56,7 @@
 	 * 
 	 */
     enum MixerError { OK=0, ERR_PERM=1, ERR_WRITE, ERR_READ,
-        ERR_OPEN, ERR_LASTERR, OK_UNCHANGED };
+        ERR_OPEN, OK_UNCHANGED };
 
 
     Mixer( QString& ref_driverName, int device );
OpenPOWER on IntegriCloud