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
@@ -25,25 +25,25 @@
25#ifdef Q_WS_QWS 25#ifdef Q_WS_QWS
26#include <qpe/qcopenvelope_qws.h> 26#include <qpe/qcopenvelope_qws.h>
27#endif 27#endif
28#include <stdio.h> 28#include <stdio.h>
29#include <stdlib.h> 29#include <stdlib.h>
30#include <string.h> 30#include <string.h>
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
44 44
45//#define DecodeLoopDebug(x) qDebug x 45//#define DecodeLoopDebug(x) qDebug x
46#define DecodeLoopDebug(x) 46#define DecodeLoopDebug(x)
47 47
48 48
49static char *audioBuffer = NULL; 49static char *audioBuffer = NULL;
@@ -92,41 +92,42 @@ void *startAudioThread( void *ptr ) {
92 } 92 }
93 return 0; 93 return 0;
94} 94}
95 95
96 96
97Mutex *audioMutex; 97Mutex *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
111 if ( pthread_attr_setschedpolicy( &audio_attr, SCHED_RR ) == 0 ) { 111 if ( pthread_attr_setschedpolicy( &audio_attr, SCHED_RR ) == 0 ) {
112 sched_param params; 112 sched_param params;
113 params.sched_priority = 50; 113 params.sched_priority = 50;
114 pthread_attr_setschedparam(&audio_attr,&params); 114 pthread_attr_setschedparam(&audio_attr,&params);
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();
127} 128}
128 129
129 130
130static long prev_frame = 0; 131static long prev_frame = 0;
131static int currentSample = 0; 132static int currentSample = 0;
132 133
@@ -211,48 +212,48 @@ void LoopControl::startVideo() {
211 212
212 moreVideo = FALSE; 213 moreVideo = FALSE;
213 killTimer( videoId ); 214 killTimer( videoId );
214 215
215 } 216 }
216 217
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
231 if ( currentSample != audioSampleCounter + 1 ) 232 if ( currentSample != audioSampleCounter + 1 )
232 qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); 233 qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter);
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
253 } else { 254 } else {
254 255
255 moreAudio = FALSE; 256 moreAudio = FALSE;
256 257
257 } 258 }
258 259
@@ -382,26 +383,31 @@ bool LoopControl::init( const QString& filename ) {
382 383
383 if ( !total_audio_samples ) 384 if ( !total_audio_samples )
384 total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); 385 total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream );
385 386
386// total_audio_samples += 1000; 387// total_audio_samples += 1000;
387 388
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.
402 static const int size = 1; 408 static const int size = 1;
403 short int buf[size]; 409 short int buf[size];
404 long samplesRead = 0; 410 long samplesRead = 0;
405 mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); 411 mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream );
406 } 412 }
407 413
@@ -428,25 +434,25 @@ bool LoopControl::init( const QString& filename ) {
428 prev_frame = -1; 434 prev_frame = -1;
429 435
430 connect( mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( setPosition( long ) ) ); 436 connect( mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( setPosition( long ) ) );
431 connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( setPaused( bool ) ) ); 437 connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( setPaused( bool ) ) );
432 438
433 audioMutex->unlock(); 439 audioMutex->unlock();
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)" )
447 << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend ); 453 << ( hasVideoChannel ? QPEApplication::Disable : QPEApplication::DisableSuspend );
448 } 454 }
449#endif 455#endif
450 456
451 playtime.start(); 457 playtime.start();
452 startTimers(); 458 startTimers();