summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/loopcontrol.cpp
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/loopcontrol.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/loopcontrol.cpp68
1 files changed, 38 insertions, 30 deletions
diff --git a/core/multimedia/opieplayer/loopcontrol.cpp b/core/multimedia/opieplayer/loopcontrol.cpp
index 4ed5921..91153fd 100644
--- a/core/multimedia/opieplayer/loopcontrol.cpp
+++ b/core/multimedia/opieplayer/loopcontrol.cpp
@@ -19,22 +19,30 @@
19 **********************************************************************/ 19 **********************************************************************/
20// L.J.Potter added changes Fri 02-15-2002 20// L.J.Potter added changes Fri 02-15-2002
21 21
22
23#include "mediaplayerstate.h"
24#include "loopcontrol.h"
25#include "videowidget.h"
26#include "audiodevice.h"
27
28/* OPIE */
22#include <qpe/qpeapplication.h> 29#include <qpe/qpeapplication.h>
30#include <qpe/mediaplayerplugininterface.h>
31#include <opie2/odebug.h>
23 32
24#ifdef Q_WS_QWS 33#ifdef Q_WS_QWS
25#include <qpe/qcopenvelope_qws.h> 34#include <qpe/qcopenvelope_qws.h>
26#endif 35#endif
36
37/* QT */
38
39/* STD */
27#include <stdio.h> 40#include <stdio.h>
28#include <stdlib.h> 41#include <stdlib.h>
29#include <string.h> 42#include <string.h>
30#include <pthread.h> 43#include <pthread.h>
31#include <errno.h> 44#include <errno.h>
32#include <unistd.h> 45#include <unistd.h>
33#include "loopcontrol.h"
34#include "videowidget.h"
35#include "audiodevice.h"
36#include <qpe/mediaplayerplugininterface.h>
37#include "mediaplayerstate.h"
38 46
39 47
40extern VideoWidget *videoUI; // now only needed to tell it to play a frame 48extern VideoWidget *videoUI; // now only needed to tell it to play a frame
@@ -100,7 +108,7 @@ LoopControl::LoopControl( QObject *parent, const char *name )
100 : QObject( parent, name ) { 108 : QObject( parent, name ) {
101 isMuted = FALSE; 109 isMuted = FALSE;
102 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) ); 110 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) );
103 //qDebug("starting loopcontrol"); 111 //odebug << "starting loopcontrol" << oendl;
104 audioMutex = new Mutex; 112 audioMutex = new Mutex;
105 113
106 pthread_attr_init(&audio_attr); 114 pthread_attr_init(&audio_attr);
@@ -112,12 +120,12 @@ LoopControl::LoopControl( QObject *parent, const char *name )
112 params.sched_priority = 50; 120 params.sched_priority = 50;
113 pthread_attr_setschedparam(&audio_attr,&params); 121 pthread_attr_setschedparam(&audio_attr,&params);
114 } else { 122 } else {
115 // qDebug( "Error setting up a realtime thread, reverting to using a normal thread." ); 123 // odebug << "Error setting up a realtime thread, reverting to using a normal thread." << oendl;
116 pthread_attr_destroy(&audio_attr); 124 pthread_attr_destroy(&audio_attr);
117 pthread_attr_init(&audio_attr); 125 pthread_attr_init(&audio_attr);
118 } 126 }
119#endif 127#endif
120 //qDebug("create audio thread"); 128 //odebug << "create audio thread" << oendl;
121 pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); 129 pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this);
122} 130}
123 131
@@ -144,7 +152,7 @@ void LoopControl::timerEvent( QTimerEvent *te ) {
144 } 152 }
145 } 153 }
146 154
147 if ( !moreVideo && !moreAudio ) { 155 if ( !moreVideo && !moreAudio ) {
148 mediaPlayerState->setPlaying( FALSE ); 156 mediaPlayerState->setPlaying( FALSE );
149 mediaPlayerState->setNext(); 157 mediaPlayerState->setNext();
150 } 158 }
@@ -153,7 +161,7 @@ void LoopControl::timerEvent( QTimerEvent *te ) {
153 161
154void LoopControl::setPosition( long pos ) { 162void LoopControl::setPosition( long pos ) {
155 audioMutex->lock(); 163 audioMutex->lock();
156// qDebug("Loop control %d", pos); 164// odebug << "Loop control " << pos << "" << oendl;
157 if ( hasVideoChannel && hasAudioChannel ) { 165 if ( hasVideoChannel && hasAudioChannel ) {
158 playtime.restart(); 166 playtime.restart();
159 playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); 167 playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) );
@@ -219,7 +227,7 @@ void LoopControl::startVideo() {
219 227
220 228
221void LoopControl::startAudio() { 229void LoopControl::startAudio() {
222 230
223 audioMutex->lock(); 231 audioMutex->lock();
224 if ( moreAudio ) { 232 if ( moreAudio ) {
225 233
@@ -228,7 +236,7 @@ void LoopControl::startAudio() {
228 currentSample = audioSampleCounter + 1; 236 currentSample = audioSampleCounter + 1;
229 237
230// if ( currentSample != audioSampleCounter + 1 ) 238// if ( currentSample != audioSampleCounter + 1 )
231// qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); 239// odebug << "out of sync with decoder " << currentSample << " " << audioSampleCounter << "" << oendl;
232 240
233 long samplesRead = 0; 241 long samplesRead = 0;
234 bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); 242 bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream );
@@ -241,7 +249,7 @@ void LoopControl::startAudio() {
241 usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); 249 usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) );
242 } 250 }
243 else if ( sampleWaitTime <= -5000 ) { 251 else if ( sampleWaitTime <= -5000 ) {
244 // qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); 252 // odebug << "need to catch up by: " << -sampleWaitTime << " (" << currentSample << "," << sampleWeShouldBeAt << ")" << oendl;
245 // //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); 253 // //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream );
246 currentSample = sampleWeShouldBeAt; 254 currentSample = sampleWeShouldBeAt;
247 } 255 }
@@ -270,7 +278,7 @@ void LoopControl::killTimers() {
270 278
271 audioMutex->lock(); 279 audioMutex->lock();
272 280
273 if ( hasVideoChannel ) 281 if ( hasVideoChannel )
274 killTimer( videoId ); 282 killTimer( videoId );
275 killTimer( sliderId ); 283 killTimer( sliderId );
276 threadOkToGo = FALSE; 284 threadOkToGo = FALSE;
@@ -324,7 +332,7 @@ void LoopControl::stop( bool willPlayAgainShortly ) {
324 332
325#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 333#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
326 if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) { 334 if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) {
327 disabledSuspendScreenSaver = FALSE; 335 disabledSuspendScreenSaver = FALSE;
328 // Re-enable the suspend mode 336 // Re-enable the suspend mode
329 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 337 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
330 } 338 }
@@ -349,7 +357,7 @@ void LoopControl::stop( bool willPlayAgainShortly ) {
349 } 357 }
350 audioSampleCounter=0; 358 audioSampleCounter=0;
351 current_frame=0; 359 current_frame=0;
352 total_audio_samples=0; 360 total_audio_samples=0;
353} 361}
354 362
355 363
@@ -360,9 +368,9 @@ bool LoopControl::init( const QString& filename ) {
360 fileName = filename; 368 fileName = filename;
361 stream = 0; // only play stream 0 for now 369 stream = 0; // only play stream 0 for now
362 current_frame = total_video_frames = total_audio_samples = 0; 370 current_frame = total_video_frames = total_audio_samples = 0;
363 371
364 // qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); 372 // odebug << "Using the " << mediaPlayerState->curDecoder()->pluginName() << " decoder" << oendl;
365 373
366 // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin 374 // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin
367// if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { 375// if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) {
368// if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename )) { 376// if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename )) {
@@ -370,7 +378,7 @@ bool LoopControl::init( const QString& filename ) {
370// mediaPlayerState->libMpeg3Decoder()->close(); 378// mediaPlayerState->libMpeg3Decoder()->close();
371// } 379// }
372// } 380// }
373 381
374 if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) { 382 if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) {
375 audioMutex->unlock(); 383 audioMutex->unlock();
376 return FALSE; 384 return FALSE;
@@ -387,23 +395,23 @@ bool LoopControl::init( const QString& filename ) {
387 else 395 else
388 channels = mediaPlayerState->curDecoder()->audioChannels( astream ); 396 channels = mediaPlayerState->curDecoder()->audioChannels( astream );
389 397
390 // qDebug( "LC- channels = %d", channels ); 398 // odebug << "LC- channels = " << channels << "" << oendl;
391 399
392// if ( !total_audio_samples ) 400// if ( !total_audio_samples )
393 total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); 401 total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream );
394 402
395 total_audio_samples += 1000; 403 total_audio_samples += 1000;
396 // qDebug("total samples %d", total_audio_samples); 404 // odebug << "total samples " << total_audio_samples << "" << oendl;
397 mediaPlayerState->setLength( total_audio_samples ); 405 mediaPlayerState->setLength( total_audio_samples );
398 406
399 freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); 407 freq = mediaPlayerState->curDecoder()->audioFrequency( astream );
400 // qDebug( "LC- frequency = %d", freq ); 408 // odebug << "LC- frequency = " << freq << "" << oendl;
401 409
402 audioSampleCounter = 0; 410 audioSampleCounter = 0;
403 int bits_per_sample; 411 int bits_per_sample;
404 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibWavPlugin") ) { 412 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibWavPlugin") ) {
405 bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime(); 413 bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime();
406 // qDebug("using stupid hack"); 414 // odebug << "using stupid hack" << oendl;
407 } else { 415 } else {
408 bits_per_sample=0; 416 bits_per_sample=0;
409 } 417 }
@@ -451,15 +459,15 @@ bool LoopControl::init( const QString& filename ) {
451 459
452 460
453void LoopControl::play() { 461void LoopControl::play() {
454 // qDebug("LC- play"); 462 // odebug << "LC- play" << oendl;
455 mediaPlayerState->setPosition( 0); //uglyhack 463 mediaPlayerState->setPosition( 0); //uglyhack
456 464
457#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 465#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
458 if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) { 466 if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) {
459 disabledSuspendScreenSaver = TRUE; 467 disabledSuspendScreenSaver = TRUE;
460 previousSuspendMode = hasVideoChannel; 468 previousSuspendMode = hasVideoChannel;
461 // Stop the screen from blanking and power saving state 469 // Stop the screen from blanking and power saving state
462 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) 470 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" )
463 << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend ); 471 << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend );
464 } 472 }
465#endif 473#endif