Diffstat (limited to 'core/multimedia/opieplayer/loopcontrol.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/loopcontrol.cpp | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/core/multimedia/opieplayer/loopcontrol.cpp b/core/multimedia/opieplayer/loopcontrol.cpp index 90a7cc6..cb8de8a 100644 --- a/core/multimedia/opieplayer/loopcontrol.cpp +++ b/core/multimedia/opieplayer/loopcontrol.cpp | |||
@@ -33,9 +33,9 @@ | |||
33 | #include <unistd.h> | 33 | #include <unistd.h> |
34 | #include "loopcontrol.h" | 34 | #include "loopcontrol.h" |
35 | #include "videowidget.h" | 35 | #include "videowidget.h" |
36 | #include "audiodevice.h" | 36 | #include "audiodevice.h" |
37 | #include "mediaplayerplugininterface.h" | 37 | #include <qpe/mediaplayerplugininterface.h> |
38 | #include "mediaplayerstate.h" | 38 | #include "mediaplayerstate.h" |
39 | 39 | ||
40 | 40 | ||
41 | extern VideoWidget *videoUI; // now only needed to tell it to play a frame | 41 | extern VideoWidget *videoUI; // now only needed to tell it to play a frame |
@@ -100,9 +100,9 @@ Mutex *audioMutex; | |||
100 | LoopControl::LoopControl( QObject *parent, const char *name ) | 100 | LoopControl::LoopControl( QObject *parent, const char *name ) |
101 | : QObject( parent, name ) { | 101 | : QObject( parent, name ) { |
102 | isMuted = FALSE; | 102 | isMuted = FALSE; |
103 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) ); | 103 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) ); |
104 | 104 | //qDebug("starting loopcontrol"); | |
105 | audioMutex = new Mutex; | 105 | audioMutex = new Mutex; |
106 | 106 | ||
107 | pthread_attr_init(&audio_attr); | 107 | pthread_attr_init(&audio_attr); |
108 | #define USE_REALTIME_AUDIO_THREAD | 108 | #define USE_REALTIME_AUDIO_THREAD |
@@ -117,8 +117,9 @@ LoopControl::LoopControl( QObject *parent, const char *name ) | |||
117 | pthread_attr_destroy(&audio_attr); | 117 | pthread_attr_destroy(&audio_attr); |
118 | pthread_attr_init(&audio_attr); | 118 | pthread_attr_init(&audio_attr); |
119 | } | 119 | } |
120 | #endif | 120 | #endif |
121 | //qDebug("create audio thread"); | ||
121 | pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); | 122 | pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); |
122 | } | 123 | } |
123 | 124 | ||
124 | 125 | ||
@@ -219,10 +220,10 @@ void LoopControl::startVideo() { | |||
219 | 220 | ||
220 | 221 | ||
221 | void LoopControl::startAudio() { | 222 | void LoopControl::startAudio() { |
222 | 223 | ||
224 | //qDebug("start audio"); | ||
223 | audioMutex->lock(); | 225 | audioMutex->lock(); |
224 | |||
225 | if ( moreAudio ) { | 226 | if ( moreAudio ) { |
226 | 227 | ||
227 | if ( !isMuted && mediaPlayerState->curDecoder() ) { | 228 | if ( !isMuted && mediaPlayerState->curDecoder() ) { |
228 | 229 | ||
@@ -235,16 +236,16 @@ void LoopControl::startAudio() { | |||
235 | bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); | 236 | bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); |
236 | long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; | 237 | long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; |
237 | long sampleWaitTime = currentSample - sampleWeShouldBeAt; | 238 | long sampleWaitTime = currentSample - sampleWeShouldBeAt; |
238 | 239 | ||
239 | if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) { | 240 | // if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) { |
240 | usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); | 241 | // usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); |
241 | } | 242 | // } |
242 | else if ( sampleWaitTime <= -5000 ) { | 243 | // else if ( sampleWaitTime <= -5000 ) { |
243 | qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); | 244 | // qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); |
244 | //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); | 245 | // //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); |
245 | currentSample = sampleWeShouldBeAt; | 246 | // currentSample = sampleWeShouldBeAt; |
246 | } | 247 | // } |
247 | 248 | ||
248 | audioDevice->write( audioBuffer, samplesRead * 2 * channels ); | 249 | audioDevice->write( audioBuffer, samplesRead * 2 * channels ); |
249 | audioSampleCounter = currentSample + samplesRead - 1; | 250 | audioSampleCounter = currentSample + samplesRead - 1; |
250 | 251 | ||
@@ -390,10 +391,15 @@ bool LoopControl::init( const QString& filename ) { | |||
390 | freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); | 391 | freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); |
391 | qDebug( "LC- frequency = %d", freq ); | 392 | qDebug( "LC- frequency = %d", freq ); |
392 | 393 | ||
393 | audioSampleCounter = 0; | 394 | audioSampleCounter = 0; |
394 | 395 | int bits_per_sample; | |
395 | int bits_per_sample = mediaPlayerState->curDecoder()->audioBitsPerSample( astream); | 396 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibWavPlugin") ) { |
397 | bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime(); | ||
398 | qDebug("using stupid hack"); | ||
399 | } else { | ||
400 | bits_per_sample=0; | ||
401 | } | ||
396 | 402 | ||
397 | audioDevice = new AudioDevice( freq, channels, bits_per_sample); | 403 | audioDevice = new AudioDevice( freq, channels, bits_per_sample); |
398 | audioBuffer = new char[ audioDevice->bufferSize() ]; | 404 | audioBuffer = new char[ audioDevice->bufferSize() ]; |
399 | channels = audioDevice->channels(); | 405 | channels = audioDevice->channels(); |
@@ -436,9 +442,9 @@ bool LoopControl::init( const QString& filename ) { | |||
436 | } | 442 | } |
437 | 443 | ||
438 | 444 | ||
439 | void LoopControl::play() { | 445 | void LoopControl::play() { |
440 | 446 | qDebug("LC- play"); | |
441 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 447 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
442 | if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) { | 448 | if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) { |
443 | disabledSuspendScreenSaver = TRUE; | 449 | disabledSuspendScreenSaver = TRUE; |
444 | previousSuspendMode = hasVideoChannel; | 450 | previousSuspendMode = hasVideoChannel; |