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.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/core/multimedia/opieplayer/loopcontrol.cpp b/core/multimedia/opieplayer/loopcontrol.cpp
index 8cf0a75..82242a3 100644
--- a/core/multimedia/opieplayer/loopcontrol.cpp
+++ b/core/multimedia/opieplayer/loopcontrol.cpp
@@ -97,30 +97,30 @@ Mutex *audioMutex;
97 97
98 98
99LoopControl::LoopControl( QObject *parent, const char *name ) 99LoopControl::LoopControl( QObject *parent, const char *name )
100 : QObject( parent, name ) { 100 : QObject( parent, name ) {
101 isMuted = FALSE; 101 isMuted = FALSE;
102 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) ); 102 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) );
103qDebug("starting loopcontrol"); 103 //qDebug("starting loopcontrol");
104 audioMutex = new Mutex; 104 audioMutex = new Mutex;
105 105
106 pthread_attr_init(&audio_attr); 106 pthread_attr_init(&audio_attr);
107#define USE_REALTIME_AUDIO_THREAD 107#define USE_REALTIME_AUDIO_THREAD
108#ifdef USE_REALTIME_AUDIO_THREAD 108#ifdef USE_REALTIME_AUDIO_THREAD
109 // Attempt to set it to real-time round robin 109 // Attempt to set it to real-time round robin
110 if ( pthread_attr_setschedpolicy( &audio_attr, SCHED_RR ) == 0 ) { 110 if ( pthread_attr_setschedpolicy( &audio_attr, SCHED_RR ) == 0 ) {
111 sched_param params; 111 sched_param params;
112 params.sched_priority = 50; 112 params.sched_priority = 50;
113 pthread_attr_setschedparam(&audio_attr,&params); 113 pthread_attr_setschedparam(&audio_attr,&params);
114 } else { 114 } else {
115 qDebug( "Error setting up a realtime thread, reverting to using a normal thread." ); 115 // qDebug( "Error setting up a realtime thread, reverting to using a normal thread." );
116 pthread_attr_destroy(&audio_attr); 116 pthread_attr_destroy(&audio_attr);
117 pthread_attr_init(&audio_attr); 117 pthread_attr_init(&audio_attr);
118 } 118 }
119#endif 119#endif
120qDebug("create audio thread"); 120 //qDebug("create audio thread");
121 pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); 121 pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this);
122} 122}
123 123
124 124
125LoopControl::~LoopControl() { 125LoopControl::~LoopControl() {
126 stop(); 126 stop();
@@ -224,27 +224,27 @@ void LoopControl::startAudio() {
224 if ( moreAudio ) { 224 if ( moreAudio ) {
225 225
226 if ( !isMuted && mediaPlayerState->curDecoder() ) { 226 if ( !isMuted && mediaPlayerState->curDecoder() ) {
227 227
228 currentSample = audioSampleCounter + 1; 228 currentSample = audioSampleCounter + 1;
229 229
230 if ( currentSample != audioSampleCounter + 1 ) 230// if ( currentSample != audioSampleCounter + 1 )
231 qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); 231// qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter);
232 232
233 long samplesRead = 0; 233 long samplesRead = 0;
234 bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); 234 bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream );
235 long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; 235 long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000;
236 long sampleWaitTime = currentSample - sampleWeShouldBeAt; 236 long sampleWaitTime = currentSample - sampleWeShouldBeAt;
237 237
238// this causes drop outs not sure why its even here 238// this causes drop outs not sure why its even here
239 if ( hasVideoChannel ) { 239 if ( hasVideoChannel ) {
240 if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) { 240 if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) {
241 usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); 241 usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) );
242 } 242 }
243 else if ( sampleWaitTime <= -5000 ) { 243 else if ( sampleWaitTime <= -5000 ) {
244 qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); 244 // qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt );
245 // //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); 245 // //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream );
246 currentSample = sampleWeShouldBeAt; 246 currentSample = sampleWeShouldBeAt;
247 } 247 }
248} 248}
249 249
250 audioDevice->write( audioBuffer, samplesRead * 2 * channels ); 250 audioDevice->write( audioBuffer, samplesRead * 2 * channels );
@@ -358,13 +358,13 @@ bool LoopControl::init( const QString& filename ) {
358 audioMutex->lock(); 358 audioMutex->lock();
359 359
360 fileName = filename; 360 fileName = filename;
361 stream = 0; // only play stream 0 for now 361 stream = 0; // only play stream 0 for now
362 current_frame = total_video_frames = total_audio_samples = 0; 362 current_frame = total_video_frames = total_audio_samples = 0;
363 363
364 qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); 364 // qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() );
365 365
366 // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin 366 // ### 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") ) { 367// if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) {
368// if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename )) { 368// if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename )) {
369// total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); 369// total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 );
370// mediaPlayerState->libMpeg3Decoder()->close(); 370// mediaPlayerState->libMpeg3Decoder()->close();
@@ -384,29 +384,29 @@ bool LoopControl::init( const QString& filename ) {
384 384
385 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMpeg3Plugin") ) 385 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMpeg3Plugin") )
386 channels = 2; //dont akx me why, but it needs this hack 386 channels = 2; //dont akx me why, but it needs this hack
387 else 387 else
388 channels = mediaPlayerState->curDecoder()->audioChannels( astream ); 388 channels = mediaPlayerState->curDecoder()->audioChannels( astream );
389 389
390 qDebug( "LC- channels = %d", channels ); 390 // qDebug( "LC- channels = %d", channels );
391 391
392// if ( !total_audio_samples ) 392// if ( !total_audio_samples )
393 total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); 393 total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream );
394 394
395 total_audio_samples += 1000; 395 total_audio_samples += 1000;
396 qDebug("total samples %d", total_audio_samples); 396 // qDebug("total samples %d", total_audio_samples);
397 mediaPlayerState->setLength( total_audio_samples ); 397 mediaPlayerState->setLength( total_audio_samples );
398 398
399 freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); 399 freq = mediaPlayerState->curDecoder()->audioFrequency( astream );
400 qDebug( "LC- frequency = %d", freq ); 400 // qDebug( "LC- frequency = %d", freq );
401 401
402 audioSampleCounter = 0; 402 audioSampleCounter = 0;
403 int bits_per_sample; 403 int bits_per_sample;
404 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibWavPlugin") ) { 404 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibWavPlugin") ) {
405 bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime(); 405 bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime();
406 qDebug("using stupid hack"); 406 // qDebug("using stupid hack");
407 } else { 407 } else {
408 bits_per_sample=0; 408 bits_per_sample=0;
409 } 409 }
410 410
411 audioDevice = new AudioDevice( freq, channels, bits_per_sample); 411 audioDevice = new AudioDevice( freq, channels, bits_per_sample);
412 audioBuffer = new char[ audioDevice->bufferSize() ]; 412 audioBuffer = new char[ audioDevice->bufferSize() ];
@@ -448,13 +448,13 @@ bool LoopControl::init( const QString& filename ) {
448 448
449 return TRUE; 449 return TRUE;
450} 450}
451 451
452 452
453void LoopControl::play() { 453void LoopControl::play() {
454 qDebug("LC- play"); 454 // qDebug("LC- play");
455 mediaPlayerState->setPosition( 0); //uglyhack 455 mediaPlayerState->setPosition( 0); //uglyhack
456 456
457#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 457#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
458 if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) { 458 if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) {
459 disabledSuspendScreenSaver = TRUE; 459 disabledSuspendScreenSaver = TRUE;
460 previousSuspendMode = hasVideoChannel; 460 previousSuspendMode = hasVideoChannel;