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.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/core/multimedia/opieplayer/loopcontrol_threaded.cpp b/core/multimedia/opieplayer/loopcontrol_threaded.cpp
index 3796549..0a1fc17 100644
--- a/core/multimedia/opieplayer/loopcontrol_threaded.cpp
+++ b/core/multimedia/opieplayer/loopcontrol_threaded.cpp
@@ -392,233 +392,233 @@ void LoopControl::startAudio() {
392 moreAudio = audioSampleCounter <= total_audio_samples; 392 moreAudio = audioSampleCounter <= total_audio_samples;
393 393
394 } else { 394 } else {
395 395
396 if ( mediaPlayerState->curDecoder() && hasAudioChannel ) 396 if ( mediaPlayerState->curDecoder() && hasAudioChannel )
397 usleep( 100000 ); // Check every 1/10 sec to see if mute is off 397 usleep( 100000 ); // Check every 1/10 sec to see if mute is off
398 else 398 else
399 moreAudio = FALSE; 399 moreAudio = FALSE;
400 400
401 } 401 }
402 } 402 }
403 403
404 // qDebug( "End of file" ); 404 // qDebug( "End of file" );
405 405
406 if ( !moreVideo && !moreAudio ) 406 if ( !moreVideo && !moreAudio )
407 emitPlayFinished = TRUE; 407 emitPlayFinished = TRUE;
408 408
409 pthread_exit(NULL); 409 pthread_exit(NULL);
410} 410}
411 411
412void LoopControl::killTimers() { 412void LoopControl::killTimers() {
413 if ( hasVideoChannel ) { 413 if ( hasVideoChannel ) {
414 if ( pthread_self() != video_tid ) { 414 if ( pthread_self() != video_tid ) {
415 if ( pthread_cancel(video_tid) == 0 ) { 415 if ( pthread_cancel(video_tid) == 0 ) {
416 void *thread_result = 0; 416 void *thread_result = 0;
417 if ( pthread_join(video_tid,&thread_result) != 0 ) 417 if ( pthread_join(video_tid,&thread_result) != 0 )
418 // qDebug("thread join error 1"); 418 // qDebug("thread join error 1");
419 pthread_attr_destroy(&video_attr); 419 pthread_attr_destroy(&video_attr);
420 } 420 }
421 } 421 }
422 } 422 }
423 if ( hasAudioChannel ) { 423 if ( hasAudioChannel ) {
424 if ( pthread_self() != audio_tid ) { 424 if ( pthread_self() != audio_tid ) {
425 if ( pthread_cancel(audio_tid) == 0 ) { 425 if ( pthread_cancel(audio_tid) == 0 ) {
426 void *thread_result = 0; 426 void *thread_result = 0;
427 if ( pthread_join(audio_tid,&thread_result) != 0 ) 427 if ( pthread_join(audio_tid,&thread_result) != 0 )
428 // qDebug("thread join error 2"); 428 // qDebug("thread join error 2");
429 pthread_attr_destroy(&audio_attr); 429 pthread_attr_destroy(&audio_attr);
430 } 430 }
431 } 431 }
432 } 432 }
433} 433}
434 434
435void LoopControl::startTimers() { 435void LoopControl::startTimers() {
436 moreVideo = FALSE; 436 moreVideo = FALSE;
437 moreAudio = FALSE; 437 moreAudio = FALSE;
438 438
439 if ( hasVideoChannel ) { 439 if ( hasVideoChannel ) {
440 moreVideo = TRUE; 440 moreVideo = TRUE;
441 pthread_attr_init(&video_attr); 441 pthread_attr_init(&video_attr);
442 pthread_create(&video_tid, &video_attr, (void * (*)(void *))startVideoThread, this); 442 pthread_create(&video_tid, &video_attr, (void * (*)(void *))startVideoThread, this);
443 } 443 }
444 444
445 if ( hasAudioChannel ) { 445 if ( hasAudioChannel ) {
446 moreAudio = TRUE; 446 moreAudio = TRUE;
447 pthread_attr_init(&audio_attr); 447 pthread_attr_init(&audio_attr);
448#ifdef USE_REALTIME_AUDIO_THREAD 448#ifdef USE_REALTIME_AUDIO_THREAD
449 pthread_attr_setschedpolicy(&audio_attr,SCHED_RR); // Real-time round robin 449 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 ) ); 450 //qDebug("min: %i, max: %i", sched_get_priority_min( SCHED_RR ), sched_get_priority_max( SCHED_RR ) );
451 sched_param params; 451 sched_param params;
452 params.sched_priority = 50; 452 params.sched_priority = 50;
453 pthread_attr_setschedparam(&audio_attr,&params); 453 pthread_attr_setschedparam(&audio_attr,&params);
454#endif 454#endif
455 pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); 455 pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this);
456 } 456 }
457} 457}
458 458
459 459
460 460
461 461
462void LoopControl::setPaused( bool pause ) { 462void LoopControl::setPaused( bool pause ) {
463 static int whenPaused = 0; 463 static int whenPaused = 0;
464 464
465 if ( !mediaPlayerState->curDecoder() || !mediaPlayerState->curDecoder()->isOpen() ) 465 if ( !mediaPlayerState->curDecoder() || !mediaPlayerState->curDecoder()->isOpen() )
466 return; 466 return;
467 467
468 if ( pause ) { 468 if ( pause ) {
469 // Remember where we are 469 // Remember where we are
470 whenPaused = playtime.elapsed(); 470 whenPaused = playtime.elapsed();
471 killTimers(); 471 killTimers();
472 } else { 472 } else {
473 // Just like we never stopped 473 // Just like we never stopped
474 playtime.restart(); 474 playtime.restart();
475 playtime = playtime.addMSecs( -whenPaused ); 475 playtime = playtime.addMSecs( -whenPaused );
476 whenPaused = 0; 476 whenPaused = 0;
477 startTimers(); 477 startTimers();
478 } 478 }
479} 479}
480 480
481 481
482void LoopControl::stop( bool willPlayAgainShortly ) { 482void LoopControl::stop( bool willPlayAgainShortly ) {
483 483
484#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 484#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
485 if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) { 485 if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) {
486 disabledSuspendScreenSaver = FALSE; 486 disabledSuspendScreenSaver = FALSE;
487 // Re-enable the suspend mode 487 // Re-enable the suspend mode
488 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 488 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
489 } 489 }
490#endif 490#endif
491 491
492 if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) { 492 if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) {
493 493
494 killTimers(); 494 killTimers();
495 495
496 mediaPlayerState->curDecoder()->close(); 496 mediaPlayerState->curDecoder()->close();
497 497
498 if ( audioDevice ) { 498 if ( audioDevice ) {
499 delete audioDevice; 499 delete audioDevice;
500 delete audioBuffer; 500 delete audioBuffer;
501 audioDevice = 0; 501 audioDevice = 0;
502 audioBuffer = 0; 502 audioBuffer = 0;
503 } 503 }
504 504
505 } 505 }
506} 506}
507 507
508 508
509bool LoopControl::init( const QString& filename ) { 509bool LoopControl::init( const QString& filename ) {
510 stop(); 510 stop();
511 fileName = filename; 511 fileName = filename;
512 stream = 0; // only play stream 0 for now 512 stream = 0; // only play stream 0 for now
513 current_frame = total_video_frames = total_audio_samples = 0; 513 current_frame = total_video_frames = total_audio_samples = 0;
514 514
515 // qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); 515 // qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() );
516 516
517 // ### 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
518 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { 518 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) {
519 if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) { 519 if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) {
520 total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); 520 total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 );
521 mediaPlayerState->libMpeg3Decoder()->close(); 521 mediaPlayerState->libMpeg3Decoder()->close();
522 } 522 }
523 } 523 }
524 524
525 if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) 525 if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) )
526 return FALSE; 526 return FALSE;
527 527
528 hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0; 528 hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0;
529 hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0; 529 hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0;
530 530
531 if ( hasAudioChannel ) { 531 if ( hasAudioChannel ) {
532 int astream = 0; 532 int astream = 0;
533 533
534 channels = mediaPlayerState->curDecoder()->audioChannels( astream ); 534 channels = mediaPlayerState->curDecoder()->audioChannels( astream );
535 DecodeLoopDebug(( "channels = %d\n", channels )); 535 DecodeLoopDebug(( "channels = %d\n", channels ));
536 536
537 if ( !total_audio_samples ) 537 if ( !total_audio_samples )
538 total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); 538 total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream );
539 539
540 mediaPlayerState->setLength( total_audio_samples ); 540 mediaPlayerState->setLength( total_audio_samples );
541 541
542 freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); 542 freq = mediaPlayerState->curDecoder()->audioFrequency( astream );
543 DecodeLoopDebug(( "frequency = %d\n", freq )); 543 DecodeLoopDebug(( "frequency = %d\n", freq ));
544 544
545 audioSampleCounter = 0; 545 audioSampleCounter = 0;
546 546
547 static const int bytes_per_sample = 2; //16 bit 547 static const int bytes_per_sample = 2; //16 bit
548 548
549 audioDevice = new AudioDevice( freq, channels, bytes_per_sample ); 549 audioDevice = new AudioDevice( freq, channels, bytes_per_sample );
550 audioBuffer = new char[ audioDevice->bufferSize() ]; 550 audioBuffer = new char[ audioDevice->bufferSize() ];
551 channels = audioDevice->channels(); 551 channels = audioDevice->channels();
552 552
553 //### must check which frequency is actually used. 553 //### must check which frequency is actually used.
554 static const int size = 1; 554 static const int size = 1;
555 short int buf[size]; 555 short int buf[size];
556 long samplesRead = 0; 556 long samplesRead = 0;
557 mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); 557 mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream );
558 } 558 }
559 559
560 if ( hasVideoChannel ) { 560 if ( hasVideoChannel ) {
561 total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream ); 561 total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream );
562 562
563 mediaPlayerState->setLength( total_video_frames ); 563 mediaPlayerState->setLength( total_video_frames );
564 564
565 framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream ); 565 framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream );
566 DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames )); 566 DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames ));
567 567
568 if ( framerate <= 1.0 ) { 568 if ( framerate <= 1.0 ) {
569 DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" )); 569 DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" ));
570 framerate = 25; 570 framerate = 25;
571 } 571 }
572 572
573 if ( total_video_frames == 1 ) { 573 if ( total_video_frames == 1 ) {
574 DecodeLoopDebug(( "Cannot seek to frame" )); 574 DecodeLoopDebug(( "Cannot seek to frame" ));
575 } 575 }
576 576
577 } 577 }
578 578
579 videoMutex->lock(); 579 videoMutex->lock();
580 current_frame = 0; 580 current_frame = 0;
581 prev_frame = -1; 581 prev_frame = -1;
582 videoMutex->unlock(); 582 videoMutex->unlock();
583 583
584 connect( mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( setPosition( long ) ) ); 584 connect( mediaPlayerState, SIGNAL( positionChanged(long) ), this, SLOT( setPosition(long) ) );
585 connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( setPaused( bool ) ) ); 585 connect( mediaPlayerState, SIGNAL( pausedToggled(bool) ), this, SLOT( setPaused(bool) ) );
586 586
587 //setBackgroundColor( black ); 587 //setBackgroundColor( black );
588 return TRUE; 588 return TRUE;
589} 589}
590 590
591 591
592void LoopControl::play() { 592void LoopControl::play() {
593 593
594#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 594#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
595 if ( !disabledSuspendScreenSaver ) { 595 if ( !disabledSuspendScreenSaver ) {
596 disabledSuspendScreenSaver = TRUE; 596 disabledSuspendScreenSaver = TRUE;
597 // Stop the screen from blanking and power saving state 597 // Stop the screen from blanking and power saving state
598 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) 598 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" )
599 << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend ); 599 << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend );
600 } 600 }
601#endif 601#endif
602 602
603 //begin = clock(); 603 //begin = clock();
604 playtime.start(); 604 playtime.start();
605 startTimers(); 605 startTimers();
606 //updateGeometry(); 606 //updateGeometry();
607} 607}
608 608
609 609
610void LoopControl::setMute( bool on ) { 610void LoopControl::setMute( bool on ) {
611 if ( isMuted != on ) { 611 if ( isMuted != on ) {
612 isMuted = on; 612 isMuted = on;
613 if ( isMuted ) { 613 if ( isMuted ) {
614 } else { 614 } else {
615 int frame = current_frame; // mediaPlayerState->curDecoder()->videoGetFrame( stream ); 615 int frame = current_frame; // mediaPlayerState->curDecoder()->videoGetFrame( stream );
616 playtime.restart(); 616 playtime.restart();
617 playtime = playtime.addMSecs( -frame * 1000 / framerate ); 617 playtime = playtime.addMSecs( -frame * 1000 / framerate );
618 //begin = clock() - (double)frame * CLOCKS_PER_SEC / framerate; 618 //begin = clock() - (double)frame * CLOCKS_PER_SEC / framerate;
619 mediaPlayerState->curDecoder()->audioSetSample( frame*freq/framerate, stream ); 619 mediaPlayerState->curDecoder()->audioSetSample( frame*freq/framerate, stream );
620 } 620 }
621 } 621 }
622} 622}
623 623
624 624