Diffstat (limited to 'core/multimedia/opieplayer/loopcontrol_threaded.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/loopcontrol_threaded.cpp | 54 |
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 | |||
@@ -18,30 +18,36 @@ | |||
18 | ** | 18 | ** |
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 | ||
46 | extern VideoWidget *videoUI; // now only needed to tell it to play a frame | 52 | extern VideoWidget *videoUI; // now only needed to tell it to play a frame |
47 | extern MediaPlayerState *mediaPlayerState; | 53 | extern MediaPlayerState *mediaPlayerState; |
@@ -190,9 +196,9 @@ void LoopControl::setPosition( long pos ) { | |||
190 | 196 | ||
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; |
198 | current_frame = pos + 1; | 204 | current_frame = pos + 1; |
@@ -291,9 +297,9 @@ void LoopControl::startVideo() { | |||
291 | usleep( 1000 ); // wait a bit | 297 | usleep( 1000 ); // wait a bit |
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(); |
299 | current_frame++; | 305 | current_frame++; |
@@ -306,9 +312,9 @@ void LoopControl::startVideo() { | |||
306 | 312 | ||
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; |
314 | if ( moreVideo = videoUI->playVideo() ) | 320 | if ( moreVideo = videoUI->playVideo() ) |
@@ -340,9 +346,9 @@ void LoopControl::startAudio() { | |||
340 | if ( currentSample == 0 ) | 346 | if ( currentSample == 0 ) |
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 | /* |
348 | int sampleWeShouldBeAt = int( playtime.elapsed() ) * freq / 1000; | 354 | int sampleWeShouldBeAt = int( playtime.elapsed() ) * freq / 1000; |
@@ -364,14 +370,14 @@ void LoopControl::startAudio() { | |||
364 | long sampleWaitTime = currentSample - sampleWeShouldBeAt; | 370 | long sampleWaitTime = currentSample - sampleWeShouldBeAt; |
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 | } |
377 | audioMutex->unlock(); | 383 | audioMutex->unlock(); |
@@ -386,10 +392,10 @@ void LoopControl::startAudio() { | |||
386 | 392 | ||
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 { |
395 | 401 | ||
@@ -400,9 +406,9 @@ void LoopControl::startAudio() { | |||
400 | 406 | ||
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; |
408 | 414 | ||
@@ -414,9 +420,9 @@ void LoopControl::killTimers() { | |||
414 | if ( pthread_self() != video_tid ) { | 420 | if ( pthread_self() != video_tid ) { |
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 | } |
422 | } | 428 | } |
@@ -424,9 +430,9 @@ void LoopControl::killTimers() { | |||
424 | if ( pthread_self() != audio_tid ) { | 430 | if ( pthread_self() != audio_tid ) { |
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 | } |
432 | } | 438 | } |
@@ -446,9 +452,9 @@ void LoopControl::startTimers() { | |||
446 | moreAudio = TRUE; | 452 | moreAudio = TRUE; |
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,¶ms); | 459 | pthread_attr_setschedparam(&audio_attr,¶ms); |
454 | #endif | 460 | #endif |
@@ -511,9 +517,9 @@ bool LoopControl::init( const QString& filename ) { | |||
511 | fileName = filename; | 517 | fileName = 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") ) { |
519 | if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) { | 525 | if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) { |