summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/loopcontrol.cpp
authorbipolar <bipolar>2002-03-03 17:13:17 (UTC)
committer bipolar <bipolar>2002-03-03 17:13:17 (UTC)
commita99347380a9006ec81a9dba2340d6aaab690a86e (patch) (unidiff)
tree73fdc2eff476fba2113172ed881dd64a4031def6 /core/multimedia/opieplayer/loopcontrol.cpp
parent0e245156b28b70be5cd98a58a9256fe5e2739562 (diff)
downloadopie-a99347380a9006ec81a9dba2340d6aaab690a86e.zip
opie-a99347380a9006ec81a9dba2340d6aaab690a86e.tar.gz
opie-a99347380a9006ec81a9dba2340d6aaab690a86e.tar.bz2
commited by ljp (llornkcor) reverted to qpe's interface for compatibility. Added playlist features:
save, remove, and have different ones. Uncommented code for background image and added opielogo.
Diffstat (limited to 'core/multimedia/opieplayer/loopcontrol.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/loopcontrol.cpp34
1 files changed, 20 insertions, 14 deletions
diff --git a/core/multimedia/opieplayer/loopcontrol.cpp b/core/multimedia/opieplayer/loopcontrol.cpp
index 90a7cc6..cb8de8a 100644
--- a/core/multimedia/opieplayer/loopcontrol.cpp
+++ b/core/multimedia/opieplayer/loopcontrol.cpp
@@ -31,13 +31,13 @@
31#include <pthread.h> 31#include <pthread.h>
32#include <errno.h> 32#include <errno.h>
33#include <unistd.h> 33#include <unistd.h>
34#include "loopcontrol.h" 34#include "loopcontrol.h"
35#include "videowidget.h" 35#include "videowidget.h"
36#include "audiodevice.h" 36#include "audiodevice.h"
37#include "mediaplayerplugininterface.h" 37#include <qpe/mediaplayerplugininterface.h>
38#include "mediaplayerstate.h" 38#include "mediaplayerstate.h"
39 39
40 40
41extern VideoWidget *videoUI; // now only needed to tell it to play a frame 41extern VideoWidget *videoUI; // now only needed to tell it to play a frame
42extern MediaPlayerState *mediaPlayerState; 42extern MediaPlayerState *mediaPlayerState;
43 43
@@ -98,13 +98,13 @@ Mutex *audioMutex;
98 98
99 99
100LoopControl::LoopControl( QObject *parent, const char *name ) 100LoopControl::LoopControl( QObject *parent, const char *name )
101 : QObject( parent, name ) { 101 : QObject( parent, name ) {
102 isMuted = FALSE; 102 isMuted = FALSE;
103 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) ); 103 connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) );
104 104//qDebug("starting loopcontrol");
105 audioMutex = new Mutex; 105 audioMutex = new Mutex;
106 106
107 pthread_attr_init(&audio_attr); 107 pthread_attr_init(&audio_attr);
108#define USE_REALTIME_AUDIO_THREAD 108#define USE_REALTIME_AUDIO_THREAD
109#ifdef USE_REALTIME_AUDIO_THREAD 109#ifdef USE_REALTIME_AUDIO_THREAD
110 // Attempt to set it to real-time round robin 110 // Attempt to set it to real-time round robin
@@ -115,12 +115,13 @@ LoopControl::LoopControl( QObject *parent, const char *name )
115 } else { 115 } else {
116 qDebug( "Error setting up a realtime thread, reverting to using a normal thread." ); 116 qDebug( "Error setting up a realtime thread, reverting to using a normal thread." );
117 pthread_attr_destroy(&audio_attr); 117 pthread_attr_destroy(&audio_attr);
118 pthread_attr_init(&audio_attr); 118 pthread_attr_init(&audio_attr);
119 } 119 }
120#endif 120#endif
121//qDebug("create audio thread");
121 pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); 122 pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this);
122} 123}
123 124
124 125
125LoopControl::~LoopControl() { 126LoopControl::~LoopControl() {
126 stop(); 127 stop();
@@ -217,14 +218,14 @@ void LoopControl::startVideo() {
217 } 218 }
218} 219}
219 220
220 221
221void LoopControl::startAudio() { 222void LoopControl::startAudio() {
222 223
224//qDebug("start audio");
223 audioMutex->lock(); 225 audioMutex->lock();
224
225 if ( moreAudio ) { 226 if ( moreAudio ) {
226 227
227 if ( !isMuted && mediaPlayerState->curDecoder() ) { 228 if ( !isMuted && mediaPlayerState->curDecoder() ) {
228 229
229 currentSample = audioSampleCounter + 1; 230 currentSample = audioSampleCounter + 1;
230 231
@@ -233,20 +234,20 @@ void LoopControl::startAudio() {
233 234
234 long samplesRead = 0; 235 long samplesRead = 0;
235 bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); 236 bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream );
236 long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; 237 long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000;
237 long sampleWaitTime = currentSample - sampleWeShouldBeAt; 238 long sampleWaitTime = currentSample - sampleWeShouldBeAt;
238 239
239 if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) { 240// if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) {
240 usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); 241// usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) );
241 } 242// }
242 else if ( sampleWaitTime <= -5000 ) { 243// else if ( sampleWaitTime <= -5000 ) {
243 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 );
244 //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); 245// //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream );
245 currentSample = sampleWeShouldBeAt; 246// currentSample = sampleWeShouldBeAt;
246 } 247// }
247 248
248 audioDevice->write( audioBuffer, samplesRead * 2 * channels ); 249 audioDevice->write( audioBuffer, samplesRead * 2 * channels );
249 audioSampleCounter = currentSample + samplesRead - 1; 250 audioSampleCounter = currentSample + samplesRead - 1;
250 251
251 moreAudio = readOk && (audioSampleCounter <= total_audio_samples); 252 moreAudio = readOk && (audioSampleCounter <= total_audio_samples);
252 253
@@ -388,14 +389,19 @@ bool LoopControl::init( const QString& filename ) {
388 mediaPlayerState->setLength( total_audio_samples ); 389 mediaPlayerState->setLength( total_audio_samples );
389 390
390 freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); 391 freq = mediaPlayerState->curDecoder()->audioFrequency( astream );
391 qDebug( "LC- frequency = %d", freq ); 392 qDebug( "LC- frequency = %d", freq );
392 393
393 audioSampleCounter = 0; 394 audioSampleCounter = 0;
394 395 int bits_per_sample;
395 int bits_per_sample = mediaPlayerState->curDecoder()->audioBitsPerSample( astream); 396 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibWavPlugin") ) {
397 bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime();
398 qDebug("using stupid hack");
399 } else {
400 bits_per_sample=0;
401 }
396 402
397 audioDevice = new AudioDevice( freq, channels, bits_per_sample); 403 audioDevice = new AudioDevice( freq, channels, bits_per_sample);
398 audioBuffer = new char[ audioDevice->bufferSize() ]; 404 audioBuffer = new char[ audioDevice->bufferSize() ];
399 channels = audioDevice->channels(); 405 channels = audioDevice->channels();
400 406
401 //### must check which frequency is actually used. 407 //### must check which frequency is actually used.
@@ -434,13 +440,13 @@ bool LoopControl::init( const QString& filename ) {
434 440
435 return TRUE; 441 return TRUE;
436} 442}
437 443
438 444
439void LoopControl::play() { 445void LoopControl::play() {
440 446 qDebug("LC- play");
441#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 447#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
442 if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) { 448 if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) {
443 disabledSuspendScreenSaver = TRUE; 449 disabledSuspendScreenSaver = TRUE;
444 previousSuspendMode = hasVideoChannel; 450 previousSuspendMode = hasVideoChannel;
445 // Stop the screen from blanking and power saving state 451 // Stop the screen from blanking and power saving state
446 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) 452 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" )