summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/loopcontrol_threaded.cpp
Side-by-side diff
Diffstat (limited to 'core/multimedia/opieplayer/loopcontrol_threaded.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/loopcontrol_threaded.cpp578
1 files changed, 289 insertions, 289 deletions
diff --git a/core/multimedia/opieplayer/loopcontrol_threaded.cpp b/core/multimedia/opieplayer/loopcontrol_threaded.cpp
index e99c97b..364e77b 100644
--- a/core/multimedia/opieplayer/loopcontrol_threaded.cpp
+++ b/core/multimedia/opieplayer/loopcontrol_threaded.cpp
@@ -54,10 +54,10 @@ extern MediaPlayerState *mediaPlayerState;
-static char *audioBuffer = NULL;
+static char *audioBuffer = NULL;
static AudioDevice *audioDevice = NULL;
-static bool disabledSuspendScreenSaver = FALSE;
+static bool disabledSuspendScreenSaver = FALSE;
-pthread_t video_tid;
+pthread_t video_tid;
pthread_attr_t video_attr;
-pthread_t audio_tid;
+pthread_t audio_tid;
pthread_attr_t audio_attr;
@@ -72,6 +72,6 @@ public:
Mutex() {
- pthread_mutexattr_t attr;
- pthread_mutexattr_init( &attr );
- pthread_mutex_init( &mutex, &attr );
- pthread_mutexattr_destroy( &attr );
+ pthread_mutexattr_t attr;
+ pthread_mutexattr_init( &attr );
+ pthread_mutex_init( &mutex, &attr );
+ pthread_mutexattr_destroy( &attr );
}
@@ -79,3 +79,3 @@ public:
~Mutex() {
- pthread_mutex_destroy( &mutex );
+ pthread_mutex_destroy( &mutex );
}
@@ -83,3 +83,3 @@ public:
void lock() {
- pthread_mutex_lock( &mutex );
+ pthread_mutex_lock( &mutex );
}
@@ -87,3 +87,3 @@ public:
void unlock() {
- pthread_mutex_unlock( &mutex );
+ pthread_mutex_unlock( &mutex );
}
@@ -91,10 +91,10 @@ public:
bool locked() {
- switch ( pthread_mutex_trylock( &mutex ) ) {
- case EBUSY:
- return TRUE;
- case 0:
- pthread_mutex_unlock( &mutex );
- default:
- return FALSE;
- }
+ switch ( pthread_mutex_trylock( &mutex ) ) {
+ case EBUSY:
+ return TRUE;
+ case 0:
+ pthread_mutex_unlock( &mutex );
+ default:
+ return FALSE;
+ }
}
@@ -110,9 +110,9 @@ public:
void set( long f ) {
- mutex.lock();
- value = f;
- mediaPlayerState->curDecoder()->videoSetFrame( f, 0 );
- mutex.unlock();
+ mutex.lock();
+ value = f;
+ mediaPlayerState->curDecoder()->videoSetFrame( f, 0 );
+ mutex.unlock();
}
long get() {
- return value;
+ return value;
}
@@ -129,3 +129,3 @@ Mutex *globalMutex;
-clock_t begin;
+clock_t begin;
@@ -160,3 +160,3 @@ void LoopControl::timerEvent( QTimerEvent* ) {
if ( emitPlayFinished ) {
- emitPlayFinished = FALSE;
+ emitPlayFinished = FALSE;
mediaPlayerState->setPlaying( FALSE );
@@ -166,14 +166,14 @@ void LoopControl::timerEvent( QTimerEvent* ) {
- emitChangePos = FALSE;
+ emitChangePos = FALSE;
- if ( hasVideoChannel && hasAudioChannel ) {
- sendingNewPos = TRUE;
- mediaPlayerState->setPosition( current_frame );
- } else if ( hasVideoChannel ) {
- sendingNewPos = TRUE;
- mediaPlayerState->setPosition( current_frame );
- } else if ( hasAudioChannel ) {
- sendingNewPos = TRUE;
- mediaPlayerState->setPosition( audioSampleCounter );
- }
+ if ( hasVideoChannel && hasAudioChannel ) {
+ sendingNewPos = TRUE;
+ mediaPlayerState->setPosition( current_frame );
+ } else if ( hasVideoChannel ) {
+ sendingNewPos = TRUE;
+ mediaPlayerState->setPosition( current_frame );
+ } else if ( hasAudioChannel ) {
+ sendingNewPos = TRUE;
+ mediaPlayerState->setPosition( audioSampleCounter );
+ }
@@ -187,4 +187,4 @@ void LoopControl::setPosition( long pos ) {
if ( sendingNewPos ) {
- sendingNewPos = FALSE;
- return;
+ sendingNewPos = FALSE;
+ return;
}
@@ -192,34 +192,34 @@ void LoopControl::setPosition( long pos ) {
if ( hasVideoChannel && hasAudioChannel ) {
- videoMutex->lock();
- audioMutex->lock();
-qDebug("setting position");
- playtime.restart();
- playtime = playtime.addMSecs( -pos * 1000 / framerate );
- //begin = clock() - (double)pos * CLOCKS_PER_SEC / framerate;
- current_frame = pos + 1;
- mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream );
- prev_frame = current_frame - 1;
- currentSample = (int)( current_frame * freq / framerate );
- mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream );
- audioSampleCounter = currentSample - 1;
- audioMutex->unlock();
- videoMutex->unlock();
+ videoMutex->lock();
+ audioMutex->lock();
+ //qDebug("setting position");
+ playtime.restart();
+ playtime = playtime.addMSecs( -pos * 1000 / framerate );
+ //begin = clock() - (double)pos * CLOCKS_PER_SEC / framerate;
+ current_frame = pos + 1;
+ mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream );
+ prev_frame = current_frame - 1;
+ currentSample = (int)( current_frame * freq / framerate );
+ mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream );
+ audioSampleCounter = currentSample - 1;
+ audioMutex->unlock();
+ videoMutex->unlock();
} else if ( hasVideoChannel ) {
- videoMutex->lock();
- playtime.restart();
- playtime = playtime.addMSecs( -pos * 1000 / framerate );
- //begin = clock() - (double)pos * CLOCKS_PER_SEC / framerate;
- current_frame = pos + 1;
- mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream );
- videoMutex->unlock();
- prev_frame = current_frame - 1;
+ videoMutex->lock();
+ playtime.restart();
+ playtime = playtime.addMSecs( -pos * 1000 / framerate );
+ //begin = clock() - (double)pos * CLOCKS_PER_SEC / framerate;
+ current_frame = pos + 1;
+ mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream );
+ videoMutex->unlock();
+ prev_frame = current_frame - 1;
} else if ( hasAudioChannel ) {
- audioMutex->lock();
- playtime.restart();
- playtime = playtime.addMSecs( -pos * 1000 / freq );
- //begin = clock() - (double)pos * CLOCKS_PER_SEC / freq;
- currentSample = pos + 1; // (int)( current_frame * freq / framerate );
- mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream );
- audioSampleCounter = currentSample - 1;
- audioMutex->unlock();
+ audioMutex->lock();
+ playtime.restart();
+ playtime = playtime.addMSecs( -pos * 1000 / freq );
+ //begin = clock() - (double)pos * CLOCKS_PER_SEC / freq;
+ currentSample = pos + 1; // (int)( current_frame * freq / framerate );
+ mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream );
+ audioSampleCounter = currentSample - 1;
+ audioMutex->unlock();
}
@@ -247,7 +247,7 @@ void LoopControl::startVideo() {
- if ( hasAudioChannel && !isMuted ) {
+ if ( hasAudioChannel && !isMuted ) {
- bool done = FALSE;
+ bool done = FALSE;
- do {
+ do {
@@ -255,68 +255,68 @@ void LoopControl::startVideo() {
/*
- videoMutex->lock();
- current_frame = int( (double)playtime.elapsed() * (double)framerate / 1000.0 );
- //current_frame = ( clock() - begin ) * (double)framerate / CLOCKS_PER_SEC;
-
- // Sync to Audio
-// current_frame = (long)((double)(audioSampleCounter - 1000) * framerate / (double)freq);
-
- long mSecsToNextFrame = 0;
-
- if ( current_frame == prev_frame ) {
- int nf = current_frame + 1;
- if ( nf > 0 && nf != total_video_frames )
- // mSecsToNextFrame = long(double(nf * CLOCKS_PER_SEC) / framerate) - ( clock() - begin );
- mSecsToNextFrame = long(double(nf * 1000) / framerate) - ( playtime.elapsed() );
- }
- videoMutex->unlock();
-
- if ( mSecsToNextFrame ) {
- usleep( mSecsToNextFrame ); // wait a bit
-
- videoMutex->lock();
- // This should now be the next frame
- current_frame = int( (double)playtime.elapsed() * (double)framerate / 1000.0 );
- //current_frame = ( clock() - begin ) * (double)framerate / CLOCKS_PER_SEC;
- videoMutex->unlock();
- }
-
- videoMutex->lock();
- done = current_frame >= prev_frame;
- videoMutex->unlock();
+ videoMutex->lock();
+ current_frame = int( (double)playtime.elapsed() * (double)framerate / 1000.0 );
+ //current_frame = ( clock() - begin ) * (double)framerate / CLOCKS_PER_SEC;
+
+ // Sync to Audio
+// current_frame = (long)((double)(audioSampleCounter - 1000) * framerate / (double)freq);
+
+ long mSecsToNextFrame = 0;
+
+ if ( current_frame == prev_frame ) {
+ int nf = current_frame + 1;
+ if ( nf > 0 && nf != total_video_frames )
+ // mSecsToNextFrame = long(double(nf * CLOCKS_PER_SEC) / framerate) - ( clock() - begin );
+ mSecsToNextFrame = long(double(nf * 1000) / framerate) - ( playtime.elapsed() );
+ }
+ videoMutex->unlock();
+
+ if ( mSecsToNextFrame ) {
+ usleep( mSecsToNextFrame ); // wait a bit
+
+ videoMutex->lock();
+ // This should now be the next frame
+ current_frame = int( (double)playtime.elapsed() * (double)framerate / 1000.0 );
+ //current_frame = ( clock() - begin ) * (double)framerate / CLOCKS_PER_SEC;
+ videoMutex->unlock();
+ }
+
+ videoMutex->lock();
+ done = current_frame >= prev_frame;
+ videoMutex->unlock();
*/
- videoMutex->lock();
- current_frame = int( (double)playtime.elapsed() * (double)framerate / 1000.0 );
- done = current_frame >= prev_frame;
- videoMutex->unlock();
- if ( !done )
- usleep( 1000 ); // wait a bit
-
- } while ( !done );
-
-// qDebug("elapsed: %i %i (%f)", int( playtime.elapsed() ), current_frame, framerate );
-
- } else {
- videoMutex->lock();
- current_frame++;
- videoMutex->unlock();
- }
-
- videoMutex->lock();
- bool check = current_frame && current_frame > prev_frame;
- videoMutex->unlock();
-
- if ( check ) {
- videoMutex->lock();
- if ( current_frame > prev_frame + 1 ) {
- qDebug("skipped a frame");
- mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream );
- }
- prev_frame = current_frame;
- if ( moreVideo = videoUI->playVideo() )
- emitChangePos = TRUE;
- videoMutex->unlock();
- }
-
- } else
- moreVideo = FALSE;
+ videoMutex->lock();
+ current_frame = int( (double)playtime.elapsed() * (double)framerate / 1000.0 );
+ done = current_frame >= prev_frame;
+ videoMutex->unlock();
+ if ( !done )
+ usleep( 1000 ); // wait a bit
+
+ } while ( !done );
+
+// qDebug("elapsed: %i %i (%f)", int( playtime.elapsed() ), current_frame, framerate );
+
+ } else {
+ videoMutex->lock();
+ current_frame++;
+ videoMutex->unlock();
+ }
+
+ videoMutex->lock();
+ bool check = current_frame && current_frame > prev_frame;
+ videoMutex->unlock();
+
+ if ( check ) {
+ videoMutex->lock();
+ if ( current_frame > prev_frame + 1 ) {
+ // qDebug("skipped a frame");
+ mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream );
+ }
+ prev_frame = current_frame;
+ if ( moreVideo = videoUI->playVideo() )
+ emitChangePos = TRUE;
+ videoMutex->unlock();
+ }
+
+ } else
+ moreVideo = FALSE;
@@ -325,3 +325,3 @@ void LoopControl::startVideo() {
if ( !moreVideo && !moreAudio )
- emitPlayFinished = TRUE;
+ emitPlayFinished = TRUE;
@@ -335,75 +335,75 @@ void LoopControl::startAudio() {
- if ( !isMuted && mediaPlayerState->curDecoder() && hasAudioChannel ) {
+ if ( !isMuted && mediaPlayerState->curDecoder() && hasAudioChannel ) {
- audioMutex->lock();
- currentSample = mediaPlayerState->curDecoder()->audioGetSample( stream );
+ audioMutex->lock();
+ currentSample = mediaPlayerState->curDecoder()->audioGetSample( stream );
- if ( currentSample == 0 )
- currentSample = audioSampleCounter + 1;
+ if ( currentSample == 0 )
+ currentSample = audioSampleCounter + 1;
- if ( currentSample != audioSampleCounter + 1 )
- qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter);
- audioMutex->unlock();
+// if ( currentSample != audioSampleCounter + 1 )
+// qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter);
+ audioMutex->unlock();
/*
- int sampleWeShouldBeAt = int( playtime.elapsed() ) * freq / 1000;
+ int sampleWeShouldBeAt = int( playtime.elapsed() ) * freq / 1000;
- if ( sampleWeShouldBeAt - currentSample > 20000 ) {
- mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream );
- currentSample = sampleWeShouldBeAt;
- }
+ if ( sampleWeShouldBeAt - currentSample > 20000 ) {
+ mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream );
+ currentSample = sampleWeShouldBeAt;
+ }
*/
- long samplesRead = 0;
-
- const long samples = 1024;
-
- moreAudio = !mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, samples, samplesRead, stream );
-
- audioMutex->lock();
- long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000;
- //long sampleWeShouldBeAt = long( clock() - begin ) * (double) freq / CLOCKS_PER_SEC;
- long sampleWaitTime = currentSample - sampleWeShouldBeAt;
- audioMutex->unlock();
-
- if ( sampleWaitTime >= 0 && sampleWaitTime <= 2000 ) {
- //qDebug("sampleWaitTime: %i", sampleWaitTime);
- usleep( ( sampleWaitTime * 1000000 ) / ( freq ) );
- } else {
- audioMutex->lock();
- if ( sampleWaitTime <= -2000 ) {
- qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt );
- mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream );
- currentSample = sampleWeShouldBeAt;
- }
- audioMutex->unlock();
- }
+ long samplesRead = 0;
+
+ const long samples = 1024;
+
+ moreAudio = !mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, samples, samplesRead, stream );
+
+ audioMutex->lock();
+ long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000;
+ //long sampleWeShouldBeAt = long( clock() - begin ) * (double) freq / CLOCKS_PER_SEC;
+ long sampleWaitTime = currentSample - sampleWeShouldBeAt;
+ audioMutex->unlock();
+
+ if ( sampleWaitTime >= 0 && sampleWaitTime <= 2000 ) {
+ //qDebug("sampleWaitTime: %i", sampleWaitTime);
+ usleep( ( sampleWaitTime * 1000000 ) / ( freq ) );
+ } else {
+ audioMutex->lock();
+ if ( sampleWaitTime <= -2000 ) {
+ // qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt );
+ mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream );
+ currentSample = sampleWeShouldBeAt;
+ }
+ audioMutex->unlock();
+ }
- audioDevice->write( audioBuffer, samplesRead * 2 * channels );
+ audioDevice->write( audioBuffer, samplesRead * 2 * channels );
- audioMutex->lock();
-// audioSampleCounter += samplesRead;
- audioSampleCounter = currentSample + samplesRead - 1;
- audioMutex->unlock();
+ audioMutex->lock();
+// audioSampleCounter += samplesRead;
+ audioSampleCounter = currentSample + samplesRead - 1;
+ audioMutex->unlock();
- if ( !hasVideoChannel )
- emitChangePos = TRUE;
+ if ( !hasVideoChannel )
+ emitChangePos = TRUE;
- //qDebug("currentSample: %i audioSampleCounter: %i total_audio_samples: %i", currentSample, audioSampleCounter, total_audio_samples);
-// qDebug("current: %i counter: %i total: %i", currentSample, audioSampleCounter, (int)total_audio_samples);
- moreAudio = audioSampleCounter <= total_audio_samples;
+ //qDebug("currentSample: %i audioSampleCounter: %i total_audio_samples: %i", currentSample, audioSampleCounter, total_audio_samples);
+// qDebug("current: %i counter: %i total: %i", currentSample, audioSampleCounter, (int)total_audio_samples);
+ moreAudio = audioSampleCounter <= total_audio_samples;
- } else {
+ } else {
- if ( mediaPlayerState->curDecoder() && hasAudioChannel )
- usleep( 100000 ); // Check every 1/10 sec to see if mute is off
- else
- moreAudio = FALSE;
+ if ( mediaPlayerState->curDecoder() && hasAudioChannel )
+ usleep( 100000 ); // Check every 1/10 sec to see if mute is off
+ else
+ moreAudio = FALSE;
- }
+ }
}
- qDebug( "End of file" );
+ // qDebug( "End of file" );
if ( !moreVideo && !moreAudio )
- emitPlayFinished = TRUE;
+ emitPlayFinished = TRUE;
@@ -414,20 +414,20 @@ void LoopControl::killTimers() {
if ( hasVideoChannel ) {
- if ( pthread_self() != video_tid ) {
- if ( pthread_cancel(video_tid) == 0 ) {
- void *thread_result = 0;
- if ( pthread_join(video_tid,&thread_result) != 0 )
- qDebug("thread join error 1");
- pthread_attr_destroy(&video_attr);
- }
- }
+ if ( pthread_self() != video_tid ) {
+ if ( pthread_cancel(video_tid) == 0 ) {
+ void *thread_result = 0;
+ if ( pthread_join(video_tid,&thread_result) != 0 )
+ // qDebug("thread join error 1");
+ pthread_attr_destroy(&video_attr);
+ }
+ }
}
if ( hasAudioChannel ) {
- if ( pthread_self() != audio_tid ) {
- if ( pthread_cancel(audio_tid) == 0 ) {
- void *thread_result = 0;
- if ( pthread_join(audio_tid,&thread_result) != 0 )
- qDebug("thread join error 2");
- pthread_attr_destroy(&audio_attr);
- }
- }
+ if ( pthread_self() != audio_tid ) {
+ if ( pthread_cancel(audio_tid) == 0 ) {
+ void *thread_result = 0;
+ if ( pthread_join(audio_tid,&thread_result) != 0 )
+ // qDebug("thread join error 2");
+ pthread_attr_destroy(&audio_attr);
+ }
+ }
}
@@ -440,5 +440,5 @@ void LoopControl::startTimers() {
if ( hasVideoChannel ) {
- moreVideo = TRUE;
- pthread_attr_init(&video_attr);
- pthread_create(&video_tid, &video_attr, (void * (*)(void *))startVideoThread, this);
+ moreVideo = TRUE;
+ pthread_attr_init(&video_attr);
+ pthread_create(&video_tid, &video_attr, (void * (*)(void *))startVideoThread, this);
}
@@ -446,12 +446,12 @@ void LoopControl::startTimers() {
if ( hasAudioChannel ) {
- moreAudio = TRUE;
- pthread_attr_init(&audio_attr);
+ moreAudio = TRUE;
+ pthread_attr_init(&audio_attr);
#ifdef USE_REALTIME_AUDIO_THREAD
- pthread_attr_setschedpolicy(&audio_attr,SCHED_RR); // Real-time round robin
- //qDebug("min: %i, max: %i", sched_get_priority_min( SCHED_RR ), sched_get_priority_max( SCHED_RR ) );
- sched_param params;
- params.sched_priority = 50;
- pthread_attr_setschedparam(&audio_attr,&params);
+ pthread_attr_setschedpolicy(&audio_attr,SCHED_RR); // Real-time round robin
+ //qDebug("min: %i, max: %i", sched_get_priority_min( SCHED_RR ), sched_get_priority_max( SCHED_RR ) );
+ sched_param params;
+ params.sched_priority = 50;
+ pthread_attr_setschedparam(&audio_attr,&params);
#endif
- pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this);
+ pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this);
}
@@ -466,14 +466,14 @@ void LoopControl::setPaused( bool pause ) {
if ( !mediaPlayerState->curDecoder() || !mediaPlayerState->curDecoder()->isOpen() )
- return;
+ return;
if ( pause ) {
- // Remember where we are
- whenPaused = playtime.elapsed();
- killTimers();
+ // Remember where we are
+ whenPaused = playtime.elapsed();
+ killTimers();
} else {
- // Just like we never stopped
- playtime.restart();
- playtime = playtime.addMSecs( -whenPaused );
- whenPaused = 0;
- startTimers();
+ // Just like we never stopped
+ playtime.restart();
+ playtime = playtime.addMSecs( -whenPaused );
+ whenPaused = 0;
+ startTimers();
}
@@ -486,5 +486,5 @@ void LoopControl::stop( bool willPlayAgainShortly ) {
if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) {
- disabledSuspendScreenSaver = FALSE;
- // Re-enable the suspend mode
- QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
+ disabledSuspendScreenSaver = FALSE;
+ // Re-enable the suspend mode
+ QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
}
@@ -494,12 +494,12 @@ void LoopControl::stop( bool willPlayAgainShortly ) {
- killTimers();
+ killTimers();
- mediaPlayerState->curDecoder()->close();
+ mediaPlayerState->curDecoder()->close();
- if ( audioDevice ) {
- delete audioDevice;
- delete audioBuffer;
- audioDevice = 0;
- audioBuffer = 0;
- }
+ if ( audioDevice ) {
+ delete audioDevice;
+ delete audioBuffer;
+ audioDevice = 0;
+ audioBuffer = 0;
+ }
@@ -515,3 +515,3 @@ bool LoopControl::init( const QString& filename ) {
- qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() );
+ // qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() );
@@ -519,6 +519,6 @@ bool LoopControl::init( const QString& filename ) {
if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) {
- if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) {
- total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 );
- mediaPlayerState->libMpeg3Decoder()->close();
- }
+ if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) {
+ total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 );
+ mediaPlayerState->libMpeg3Decoder()->close();
+ }
}
@@ -526,3 +526,3 @@ bool LoopControl::init( const QString& filename ) {
if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) )
- return FALSE;
+ return FALSE;
@@ -532,28 +532,28 @@ bool LoopControl::init( const QString& filename ) {
if ( hasAudioChannel ) {
- int astream = 0;
+ int astream = 0;
- channels = mediaPlayerState->curDecoder()->audioChannels( astream );
- DecodeLoopDebug(( "channels = %d\n", channels ));
-
- if ( !total_audio_samples )
- total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream );
+ channels = mediaPlayerState->curDecoder()->audioChannels( astream );
+ DecodeLoopDebug(( "channels = %d\n", channels ));
+
+ if ( !total_audio_samples )
+ total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream );
- mediaPlayerState->setLength( total_audio_samples );
-
- freq = mediaPlayerState->curDecoder()->audioFrequency( astream );
- DecodeLoopDebug(( "frequency = %d\n", freq ));
+ mediaPlayerState->setLength( total_audio_samples );
+
+ freq = mediaPlayerState->curDecoder()->audioFrequency( astream );
+ DecodeLoopDebug(( "frequency = %d\n", freq ));
- audioSampleCounter = 0;
+ audioSampleCounter = 0;
- static const int bytes_per_sample = 2; //16 bit
+ static const int bytes_per_sample = 2; //16 bit
- audioDevice = new AudioDevice( freq, channels, bytes_per_sample );
- audioBuffer = new char[ audioDevice->bufferSize() ];
- channels = audioDevice->channels();
+ audioDevice = new AudioDevice( freq, channels, bytes_per_sample );
+ audioBuffer = new char[ audioDevice->bufferSize() ];
+ channels = audioDevice->channels();
- //### must check which frequency is actually used.
- static const int size = 1;
- short int buf[size];
- long samplesRead = 0;
- mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream );
+ //### must check which frequency is actually used.
+ static const int size = 1;
+ short int buf[size];
+ long samplesRead = 0;
+ mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream );
}
@@ -561,17 +561,17 @@ bool LoopControl::init( const QString& filename ) {
if ( hasVideoChannel ) {
- total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream );
+ total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream );
- mediaPlayerState->setLength( total_video_frames );
+ mediaPlayerState->setLength( total_video_frames );
- framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream );
- DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames ));
+ framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream );
+ DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames ));
- if ( framerate <= 1.0 ) {
- DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" ));
- framerate = 25;
- }
+ if ( framerate <= 1.0 ) {
+ DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" ));
+ framerate = 25;
+ }
- if ( total_video_frames == 1 ) {
- DecodeLoopDebug(( "Cannot seek to frame" ));
- }
+ if ( total_video_frames == 1 ) {
+ DecodeLoopDebug(( "Cannot seek to frame" ));
+ }
@@ -596,6 +596,6 @@ void LoopControl::play() {
if ( !disabledSuspendScreenSaver ) {
- disabledSuspendScreenSaver = TRUE;
+ disabledSuspendScreenSaver = TRUE;
// Stop the screen from blanking and power saving state
- QCopEnvelope("QPE/System", "setScreenSaverMode(int)" )
- << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend );
+ QCopEnvelope("QPE/System", "setScreenSaverMode(int)" )
+ << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend );
}
@@ -612,11 +612,11 @@ void LoopControl::setMute( bool on ) {
if ( isMuted != on ) {
- isMuted = on;
- if ( isMuted ) {
- } else {
- int frame = current_frame; // mediaPlayerState->curDecoder()->videoGetFrame( stream );
- playtime.restart();
- playtime = playtime.addMSecs( -frame * 1000 / framerate );
- //begin = clock() - (double)frame * CLOCKS_PER_SEC / framerate;
- mediaPlayerState->curDecoder()->audioSetSample( frame*freq/framerate, stream );
- }
+ isMuted = on;
+ if ( isMuted ) {
+ } else {
+ int frame = current_frame; // mediaPlayerState->curDecoder()->videoGetFrame( stream );
+ playtime.restart();
+ playtime = playtime.addMSecs( -frame * 1000 / framerate );
+ //begin = clock() - (double)frame * CLOCKS_PER_SEC / framerate;
+ mediaPlayerState->curDecoder()->audioSetSample( frame*freq/framerate, stream );
+ }
}