summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/loopcontrol_threaded.cpp
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/loopcontrol_threaded.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/loopcontrol_threaded.cpp54
1 files changed, 30 insertions, 24 deletions
diff --git a/core/multimedia/opieplayer/loopcontrol_threaded.cpp b/core/multimedia/opieplayer/loopcontrol_threaded.cpp
index 0a1fc17..9a162c2 100644
--- a/core/multimedia/opieplayer/loopcontrol_threaded.cpp
+++ b/core/multimedia/opieplayer/loopcontrol_threaded.cpp
@@ -19,28 +19,34 @@
19**********************************************************************/ 19**********************************************************************/
20#define _REENTRANT 20#define _REENTRANT
21 21
22#include "mediaplayerplugininterface.h"
23#include "loopcontrol.h"
24#include "audiodevice.h"
25#include "videowidget.h"
26#include "audiowidget.h"
27#include "mediaplayerstate.h"
28
29/* OPIE */
22#include <qpe/qpeapplication.h> 30#include <qpe/qpeapplication.h>
23#include <qpe/custom.h> 31#include <qpe/custom.h>
24#include <qimage.h> 32
25#include <qpainter.h>
26#if !defined(QT_NO_COP) 33#if !defined(QT_NO_COP)
27#include <qpe/qcopenvelope_qws.h> 34#include <qpe/qcopenvelope_qws.h>
28#endif 35#endif
29#include "mediaplayerplugininterface.h" 36
37#include <opie2/odebug.h>
38
39/* QT */
40#include <qimage.h>
41#include <qpainter.h>
42
43/* STD */
30#include <stdio.h> 44#include <stdio.h>
31#include <stdlib.h> 45#include <stdlib.h>
32#include <string.h> 46#include <string.h>
33#include <time.h> 47#include <time.h>
34#include <unistd.h> 48#include <unistd.h>
35#include <pthread.h> 49#include <pthread.h>
36#include "loopcontrol.h"
37#include "audiodevice.h"
38#include "videowidget.h"
39#include "audiowidget.h"
40#include "mediaplayerstate.h"
41
42
43
44 50
45 51
46extern VideoWidget *videoUI; // now only needed to tell it to play a frame 52extern VideoWidget *videoUI; // now only needed to tell it to play a frame
@@ -191,7 +197,7 @@ void LoopControl::setPosition( long pos ) {
191 if ( hasVideoChannel && hasAudioChannel ) { 197 if ( hasVideoChannel && hasAudioChannel ) {
192 videoMutex->lock(); 198 videoMutex->lock();
193 audioMutex->lock(); 199 audioMutex->lock();
194 //qDebug("setting position"); 200 //odebug << "setting position" << oendl;
195 playtime.restart(); 201 playtime.restart();
196 playtime = playtime.addMSecs( -pos * 1000 / framerate ); 202 playtime = playtime.addMSecs( -pos * 1000 / framerate );
197 //begin = clock() - (double)pos * CLOCKS_PER_SEC / framerate; 203 //begin = clock() - (double)pos * CLOCKS_PER_SEC / framerate;
@@ -292,7 +298,7 @@ void LoopControl::startVideo() {
292 298
293 } while ( !done ); 299 } while ( !done );
294 300
295// qDebug("elapsed: %i %i (%f)", int( playtime.elapsed() ), current_frame, framerate ); 301// odebug << "elapsed: " << int( playtime.elapsed() ) << " " << current_frame << " (" << framerate << ")" << oendl;
296 302
297 } else { 303 } else {
298 videoMutex->lock(); 304 videoMutex->lock();
@@ -307,7 +313,7 @@ void LoopControl::startVideo() {
307 if ( check ) { 313 if ( check ) {
308 videoMutex->lock(); 314 videoMutex->lock();
309 if ( current_frame > prev_frame + 1 ) { 315 if ( current_frame > prev_frame + 1 ) {
310 // qDebug("skipped a frame"); 316 // odebug << "skipped a frame" << oendl;
311 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); 317 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream );
312 } 318 }
313 prev_frame = current_frame; 319 prev_frame = current_frame;
@@ -341,7 +347,7 @@ void LoopControl::startAudio() {
341 currentSample = audioSampleCounter + 1; 347 currentSample = audioSampleCounter + 1;
342 348
343// if ( currentSample != audioSampleCounter + 1 ) 349// if ( currentSample != audioSampleCounter + 1 )
344// qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); 350// odebug << "out of sync with decoder " << currentSample << " " << audioSampleCounter << "" << oendl;
345 audioMutex->unlock(); 351 audioMutex->unlock();
346 352
347/* 353/*
@@ -365,12 +371,12 @@ void LoopControl::startAudio() {
365 audioMutex->unlock(); 371 audioMutex->unlock();
366 372
367 if ( sampleWaitTime >= 0 && sampleWaitTime <= 2000 ) { 373 if ( sampleWaitTime >= 0 && sampleWaitTime <= 2000 ) {
368 //qDebug("sampleWaitTime: %i", sampleWaitTime); 374 //odebug << "sampleWaitTime: " << sampleWaitTime << "" << oendl;
369 usleep( ( sampleWaitTime * 1000000 ) / ( freq ) ); 375 usleep( ( sampleWaitTime * 1000000 ) / ( freq ) );
370 } else { 376 } else {
371 audioMutex->lock(); 377 audioMutex->lock();
372 if ( sampleWaitTime <= -2000 ) { 378 if ( sampleWaitTime <= -2000 ) {
373 // qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); 379 // odebug << "need to catch up by: " << -sampleWaitTime << " (" << currentSample << "," << sampleWeShouldBeAt << ")" << oendl;
374 mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); 380 mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream );
375 currentSample = sampleWeShouldBeAt; 381 currentSample = sampleWeShouldBeAt;
376 } 382 }
@@ -387,8 +393,8 @@ void LoopControl::startAudio() {
387 if ( !hasVideoChannel ) 393 if ( !hasVideoChannel )
388 emitChangePos = TRUE; 394 emitChangePos = TRUE;
389 395
390 //qDebug("currentSample: %i audioSampleCounter: %i total_audio_samples: %i", currentSample, audioSampleCounter, total_audio_samples); 396 //odebug << "currentSample: " << currentSample << " audioSampleCounter: " << audioSampleCounter << " total_audio_samples: " << total_audio_samples << "" << oendl;
391// qDebug("current: %i counter: %i total: %i", currentSample, audioSampleCounter, (int)total_audio_samples); 397// odebug << "current: " << currentSample << " counter: " << audioSampleCounter << " total: " << (int)total_audio_samples << "" << oendl;
392 moreAudio = audioSampleCounter <= total_audio_samples; 398 moreAudio = audioSampleCounter <= total_audio_samples;
393 399
394 } else { 400 } else {
@@ -401,7 +407,7 @@ void LoopControl::startAudio() {
401 } 407 }
402 } 408 }
403 409
404 // qDebug( "End of file" ); 410 // odebug << "End of file" << oendl;
405 411
406 if ( !moreVideo && !moreAudio ) 412 if ( !moreVideo && !moreAudio )
407 emitPlayFinished = TRUE; 413 emitPlayFinished = TRUE;
@@ -415,7 +421,7 @@ void LoopControl::killTimers() {
415 if ( pthread_cancel(video_tid) == 0 ) { 421 if ( pthread_cancel(video_tid) == 0 ) {
416 void *thread_result = 0; 422 void *thread_result = 0;
417 if ( pthread_join(video_tid,&thread_result) != 0 ) 423 if ( pthread_join(video_tid,&thread_result) != 0 )
418 // qDebug("thread join error 1"); 424 // odebug << "thread join error 1" << oendl;
419 pthread_attr_destroy(&video_attr); 425 pthread_attr_destroy(&video_attr);
420 } 426 }
421 } 427 }
@@ -425,7 +431,7 @@ void LoopControl::killTimers() {
425 if ( pthread_cancel(audio_tid) == 0 ) { 431 if ( pthread_cancel(audio_tid) == 0 ) {
426 void *thread_result = 0; 432 void *thread_result = 0;
427 if ( pthread_join(audio_tid,&thread_result) != 0 ) 433 if ( pthread_join(audio_tid,&thread_result) != 0 )
428 // qDebug("thread join error 2"); 434 // odebug << "thread join error 2" << oendl;
429 pthread_attr_destroy(&audio_attr); 435 pthread_attr_destroy(&audio_attr);
430 } 436 }
431 } 437 }
@@ -447,7 +453,7 @@ void LoopControl::startTimers() {
447 pthread_attr_init(&audio_attr); 453 pthread_attr_init(&audio_attr);
448#ifdef USE_REALTIME_AUDIO_THREAD 454#ifdef USE_REALTIME_AUDIO_THREAD
449 pthread_attr_setschedpolicy(&audio_attr,SCHED_RR); // Real-time round robin 455 pthread_attr_setschedpolicy(&audio_attr,SCHED_RR); // Real-time round robin
450 //qDebug("min: %i, max: %i", sched_get_priority_min( SCHED_RR ), sched_get_priority_max( SCHED_RR ) ); 456 //odebug << "min: " << sched_get_priority_min( SCHED_RR ) << ", max: " << sched_get_priority_max( SCHED_RR ) << "" << oendl;
451 sched_param params; 457 sched_param params;
452 params.sched_priority = 50; 458 params.sched_priority = 50;
453 pthread_attr_setschedparam(&audio_attr,&params); 459 pthread_attr_setschedparam(&audio_attr,&params);
@@ -512,7 +518,7 @@ bool LoopControl::init( const QString& filename ) {
512 stream = 0; // only play stream 0 for now 518 stream = 0; // only play stream 0 for now
513 current_frame = total_video_frames = total_audio_samples = 0; 519 current_frame = total_video_frames = total_audio_samples = 0;
514 520
515 // qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); 521 // odebug << "Using the " << mediaPlayerState->curDecoder()->pluginName() << " decoder" << oendl;
516 522
517 // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin 523 // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin
518 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { 524 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) {