Diffstat (limited to 'core/multimedia/opieplayer/loopcontrol_threaded.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/loopcontrol_threaded.cpp | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/core/multimedia/opieplayer/loopcontrol_threaded.cpp b/core/multimedia/opieplayer/loopcontrol_threaded.cpp index 364e77b..3796549 100644 --- a/core/multimedia/opieplayer/loopcontrol_threaded.cpp +++ b/core/multimedia/opieplayer/loopcontrol_threaded.cpp | |||
@@ -15,38 +15,37 @@ | |||
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #define _REENTRANT | 20 | #define _REENTRANT |
21 | 21 | ||
22 | #include <qpe/qpeapplication.h> | 22 | #include <qpe/qpeapplication.h> |
23 | #include <qpe/custom.h> | ||
23 | #include <qimage.h> | 24 | #include <qimage.h> |
24 | #include <qpainter.h> | 25 | #include <qpainter.h> |
25 | #ifdef Q_WS_QWS | 26 | #if !defined(QT_NO_COP) |
26 | #include <qpe/qcopenvelope_qws.h> | 27 | #include <qpe/qcopenvelope_qws.h> |
27 | #endif | 28 | #endif |
28 | #include "mediaplayerplugininterface.h" | 29 | #include "mediaplayerplugininterface.h" |
29 | #include <stdio.h> | 30 | #include <stdio.h> |
30 | #include <stdlib.h> | 31 | #include <stdlib.h> |
31 | #include <string.h> | 32 | #include <string.h> |
32 | #include <time.h> | 33 | #include <time.h> |
33 | #include <unistd.h> | 34 | #include <unistd.h> |
34 | #include <pthread.h> | 35 | #include <pthread.h> |
35 | #include "loopcontrol.h" | 36 | #include "loopcontrol.h" |
36 | #include "audiodevice.h" | 37 | #include "audiodevice.h" |
37 | #include "videowidget.h" | 38 | #include "videowidget.h" |
38 | #include "audiowidget.h" | 39 | #include "audiowidget.h" |
39 | #include "mediaplayerstate.h" | 40 | #include "mediaplayerstate.h" |
40 | 41 | ||
41 | 42 | ||
42 | #if defined(QT_QWS_SL5XXX) || defined(QT_QWS_IPAQ) || defined(QT_QWS_RAMSES) | 43 | |
43 | #define USE_REALTIME_AUDIO_THREAD | ||
44 | #endif | ||
45 | 44 | ||
46 | 45 | ||
47 | extern VideoWidget *videoUI; // now only needed to tell it to play a frame | 46 | extern VideoWidget *videoUI; // now only needed to tell it to play a frame |
48 | extern MediaPlayerState *mediaPlayerState; | 47 | extern MediaPlayerState *mediaPlayerState; |
49 | 48 | ||
50 | 49 | ||
51 | #define DecodeLoopDebug(x) qDebug x | 50 | #define DecodeLoopDebug(x) qDebug x |
52 | //#define DecodeLoopDebug(x) | 51 | //#define DecodeLoopDebug(x) |
@@ -251,17 +250,17 @@ void LoopControl::startVideo() { | |||
251 | 250 | ||
252 | do { | 251 | do { |
253 | 252 | ||
254 | 253 | ||
255 | /* | 254 | /* |
256 | videoMutex->lock(); | 255 | videoMutex->lock(); |
257 | current_frame = int( (double)playtime.elapsed() * (double)framerate / 1000.0 ); | 256 | current_frame = int( (double)playtime.elapsed() * (double)framerate / 1000.0 ); |
258 | //current_frame = ( clock() - begin ) * (double)framerate / CLOCKS_PER_SEC; | 257 | //current_frame = ( clock() - begin ) * (double)framerate / CLOCKS_PER_SEC; |
259 | 258 | ||
260 | // Sync to Audio | 259 | // Sync to Audio |
261 | // current_frame = (long)((double)(audioSampleCounter - 1000) * framerate / (double)freq); | 260 | // current_frame = (long)((double)(audioSampleCounter - 1000) * framerate / (double)freq); |
262 | 261 | ||
263 | long mSecsToNextFrame = 0; | 262 | long mSecsToNextFrame = 0; |
264 | 263 | ||
265 | if ( current_frame == prev_frame ) { | 264 | if ( current_frame == prev_frame ) { |
266 | int nf = current_frame + 1; | 265 | int nf = current_frame + 1; |
267 | if ( nf > 0 && nf != total_video_frames ) | 266 | if ( nf > 0 && nf != total_video_frames ) |
@@ -307,35 +306,35 @@ void LoopControl::startVideo() { | |||
307 | 306 | ||
308 | if ( check ) { | 307 | if ( check ) { |
309 | videoMutex->lock(); | 308 | videoMutex->lock(); |
310 | if ( current_frame > prev_frame + 1 ) { | 309 | if ( current_frame > prev_frame + 1 ) { |
311 | // qDebug("skipped a frame"); | 310 | // qDebug("skipped a frame"); |
312 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); | 311 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); |
313 | } | 312 | } |
314 | prev_frame = current_frame; | 313 | prev_frame = current_frame; |
315 | if ( moreVideo = videoUI->playVideo() ) | 314 | if ( moreVideo = videoUI->playVideo() ) |
316 | emitChangePos = TRUE; | 315 | emitChangePos = TRUE; |
317 | videoMutex->unlock(); | 316 | videoMutex->unlock(); |
318 | } | 317 | } |
319 | 318 | ||
320 | } else | 319 | } else |
321 | moreVideo = FALSE; | 320 | moreVideo = FALSE; |
322 | 321 | ||
323 | } | 322 | } |
324 | 323 | ||
325 | if ( !moreVideo && !moreAudio ) | 324 | if ( !moreVideo && !moreAudio ) |
326 | emitPlayFinished = TRUE; | 325 | emitPlayFinished = TRUE; |
327 | 326 | ||
328 | pthread_exit(NULL); | 327 | pthread_exit(NULL); |
329 | } | 328 | } |
330 | 329 | ||
331 | void LoopControl::startAudio() { | 330 | void LoopControl::startAudio() { |
332 | moreAudio = TRUE; | 331 | moreAudio = TRUE; |
333 | 332 | ||
334 | while ( moreAudio ) { | 333 | while ( moreAudio ) { |
335 | 334 | ||
336 | if ( !isMuted && mediaPlayerState->curDecoder() && hasAudioChannel ) { | 335 | if ( !isMuted && mediaPlayerState->curDecoder() && hasAudioChannel ) { |
337 | 336 | ||
338 | audioMutex->lock(); | 337 | audioMutex->lock(); |
339 | currentSample = mediaPlayerState->curDecoder()->audioGetSample( stream ); | 338 | currentSample = mediaPlayerState->curDecoder()->audioGetSample( stream ); |
340 | 339 | ||
341 | if ( currentSample == 0 ) | 340 | if ( currentSample == 0 ) |
@@ -399,17 +398,17 @@ void LoopControl::startAudio() { | |||
399 | else | 398 | else |
400 | moreAudio = FALSE; | 399 | moreAudio = FALSE; |
401 | 400 | ||
402 | } | 401 | } |
403 | } | 402 | } |
404 | 403 | ||
405 | // qDebug( "End of file" ); | 404 | // qDebug( "End of file" ); |
406 | 405 | ||
407 | if ( !moreVideo && !moreAudio ) | 406 | if ( !moreVideo && !moreAudio ) |
408 | emitPlayFinished = TRUE; | 407 | emitPlayFinished = TRUE; |
409 | 408 | ||
410 | pthread_exit(NULL); | 409 | pthread_exit(NULL); |
411 | } | 410 | } |
412 | 411 | ||
413 | void LoopControl::killTimers() { | 412 | void LoopControl::killTimers() { |
414 | if ( hasVideoChannel ) { | 413 | if ( hasVideoChannel ) { |
415 | if ( pthread_self() != video_tid ) { | 414 | if ( pthread_self() != video_tid ) { |
@@ -479,17 +478,17 @@ void LoopControl::setPaused( bool pause ) { | |||
479 | } | 478 | } |
480 | } | 479 | } |
481 | 480 | ||
482 | 481 | ||
483 | void LoopControl::stop( bool willPlayAgainShortly ) { | 482 | void LoopControl::stop( bool willPlayAgainShortly ) { |
484 | 483 | ||
485 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 484 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
486 | if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) { | 485 | if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) { |
487 | disabledSuspendScreenSaver = FALSE; | 486 | disabledSuspendScreenSaver = FALSE; |
488 | // Re-enable the suspend mode | 487 | // Re-enable the suspend mode |
489 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; | 488 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; |
490 | } | 489 | } |
491 | #endif | 490 | #endif |
492 | 491 | ||
493 | if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) { | 492 | if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) { |
494 | 493 | ||
495 | killTimers(); | 494 | killTimers(); |
@@ -507,19 +506,19 @@ void LoopControl::stop( bool willPlayAgainShortly ) { | |||
507 | } | 506 | } |
508 | 507 | ||
509 | 508 | ||
510 | bool LoopControl::init( const QString& filename ) { | 509 | bool LoopControl::init( const QString& filename ) { |
511 | stop(); | 510 | stop(); |
512 | fileName = filename; | 511 | fileName = filename; |
513 | stream = 0; // only play stream 0 for now | 512 | stream = 0; // only play stream 0 for now |
514 | current_frame = total_video_frames = total_audio_samples = 0; | 513 | current_frame = total_video_frames = total_audio_samples = 0; |
515 | 514 | ||
516 | // qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); | 515 | // qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); |
517 | 516 | ||
518 | // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin | 517 | // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin |
519 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { | 518 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { |
520 | if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) { | 519 | if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) { |
521 | total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); | 520 | total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); |
522 | mediaPlayerState->libMpeg3Decoder()->close(); | 521 | mediaPlayerState->libMpeg3Decoder()->close(); |
523 | } | 522 | } |
524 | } | 523 | } |
525 | 524 | ||
@@ -529,22 +528,22 @@ bool LoopControl::init( const QString& filename ) { | |||
529 | hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0; | 528 | hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0; |
530 | hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0; | 529 | hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0; |
531 | 530 | ||
532 | if ( hasAudioChannel ) { | 531 | if ( hasAudioChannel ) { |
533 | int astream = 0; | 532 | int astream = 0; |
534 | 533 | ||
535 | channels = mediaPlayerState->curDecoder()->audioChannels( astream ); | 534 | channels = mediaPlayerState->curDecoder()->audioChannels( astream ); |
536 | DecodeLoopDebug(( "channels = %d\n", channels )); | 535 | DecodeLoopDebug(( "channels = %d\n", channels )); |
537 | 536 | ||
538 | if ( !total_audio_samples ) | 537 | if ( !total_audio_samples ) |
539 | total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); | 538 | total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); |
540 | 539 | ||
541 | mediaPlayerState->setLength( total_audio_samples ); | 540 | mediaPlayerState->setLength( total_audio_samples ); |
542 | 541 | ||
543 | freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); | 542 | freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); |
544 | DecodeLoopDebug(( "frequency = %d\n", freq )); | 543 | DecodeLoopDebug(( "frequency = %d\n", freq )); |
545 | 544 | ||
546 | audioSampleCounter = 0; | 545 | audioSampleCounter = 0; |
547 | 546 | ||
548 | static const int bytes_per_sample = 2; //16 bit | 547 | static const int bytes_per_sample = 2; //16 bit |
549 | 548 | ||
550 | audioDevice = new AudioDevice( freq, channels, bytes_per_sample ); | 549 | audioDevice = new AudioDevice( freq, channels, bytes_per_sample ); |
@@ -589,19 +588,19 @@ bool LoopControl::init( const QString& filename ) { | |||
589 | return TRUE; | 588 | return TRUE; |
590 | } | 589 | } |
591 | 590 | ||
592 | 591 | ||
593 | void LoopControl::play() { | 592 | void LoopControl::play() { |
594 | 593 | ||
595 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 594 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
596 | if ( !disabledSuspendScreenSaver ) { | 595 | if ( !disabledSuspendScreenSaver ) { |
597 | disabledSuspendScreenSaver = TRUE; | 596 | disabledSuspendScreenSaver = TRUE; |
598 | // Stop the screen from blanking and power saving state | 597 | // Stop the screen from blanking and power saving state |
599 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) | 598 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) |
600 | << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend ); | 599 | << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend ); |
601 | } | 600 | } |
602 | #endif | 601 | #endif |
603 | 602 | ||
604 | //begin = clock(); | 603 | //begin = clock(); |
605 | playtime.start(); | 604 | playtime.start(); |
606 | startTimers(); | 605 | startTimers(); |
607 | //updateGeometry(); | 606 | //updateGeometry(); |