summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/loopcontrol.cpp
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/loopcontrol.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/multimedia/opieplayer/loopcontrol.cpp14
1 files changed, 6 insertions, 8 deletions
diff --git a/core/multimedia/opieplayer/loopcontrol.cpp b/core/multimedia/opieplayer/loopcontrol.cpp
index 4b2827e..b9f96de 100644
--- a/core/multimedia/opieplayer/loopcontrol.cpp
+++ b/core/multimedia/opieplayer/loopcontrol.cpp
@@ -10,25 +10,24 @@
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20// L.J.Potter added changes Fri 02-15-2002 20// L.J.Potter added changes Fri 02-15-2002
21 21
22
23#include <qpe/qpeapplication.h> 22#include <qpe/qpeapplication.h>
24 23
25#ifdef Q_WS_QWS 24#ifdef Q_WS_QWS
26#include <qpe/qcopenvelope_qws.h> 25#include <qpe/qcopenvelope_qws.h>
27#endif 26#endif
28#include <stdio.h> 27#include <stdio.h>
29#include <stdlib.h> 28#include <stdlib.h>
30#include <string.h> 29#include <string.h>
31#include <pthread.h> 30#include <pthread.h>
32#include <errno.h> 31#include <errno.h>
33#include <unistd.h> 32#include <unistd.h>
34#include "loopcontrol.h" 33#include "loopcontrol.h"
@@ -212,44 +211,45 @@ void LoopControl::startVideo() {
212 211
213 moreVideo = FALSE; 212 moreVideo = FALSE;
214 killTimer( videoId ); 213 killTimer( videoId );
215 214
216 } 215 }
217 216
218 } 217 }
219} 218}
220 219
221 220
222void LoopControl::startAudio() { 221void LoopControl::startAudio() {
223 222
223//qDebug("start audio");
224 audioMutex->lock(); 224 audioMutex->lock();
225 if ( moreAudio ) { 225 if ( moreAudio ) {
226 226
227 if ( !isMuted && mediaPlayerState->curDecoder() ) { 227 if ( !isMuted && mediaPlayerState->curDecoder() ) {
228 228
229 currentSample = audioSampleCounter + 1; 229 currentSample = audioSampleCounter + 1;
230 230
231 if ( currentSample != audioSampleCounter + 1 ) 231 if ( currentSample != audioSampleCounter + 1 )
232 qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); 232 qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter);
233 233
234 long samplesRead = 0; 234 long samplesRead = 0;
235 bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); 235 bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream );
236 long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; 236 long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000;
237 long sampleWaitTime = currentSample - sampleWeShouldBeAt; 237 long sampleWaitTime = currentSample - sampleWeShouldBeAt;
238 238
239// if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) { 239// if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) {
240// usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); 240// usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) );
241// } 241// }
242// else if ( sampleWaitTime <= -5000 ) { 242// else if ( sampleWaitTime <= -5000 ) {
243// // qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); 243// qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt );
244// //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); 244// //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream );
245// currentSample = sampleWeShouldBeAt; 245// currentSample = sampleWeShouldBeAt;
246// } 246// }
247 247
248 audioDevice->write( audioBuffer, samplesRead * 2 * channels ); 248 audioDevice->write( audioBuffer, samplesRead * 2 * channels );
249 audioSampleCounter = currentSample + samplesRead - 1; 249 audioSampleCounter = currentSample + samplesRead - 1;
250 250
251 moreAudio = readOk && (audioSampleCounter <= total_audio_samples); 251 moreAudio = readOk && (audioSampleCounter <= total_audio_samples);
252 252
253 } else { 253 } else {
254 254
255 moreAudio = FALSE; 255 moreAudio = FALSE;
@@ -369,45 +369,43 @@ bool LoopControl::init( const QString& filename ) {
369 if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) { 369 if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) {
370 audioMutex->unlock(); 370 audioMutex->unlock();
371 return FALSE; 371 return FALSE;
372 } 372 }
373 373
374 hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0; 374 hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0;
375 hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0; 375 hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0;
376 376
377 if ( hasAudioChannel ) { 377 if ( hasAudioChannel ) {
378 int astream = 0; 378 int astream = 0;
379 379
380 channels = mediaPlayerState->curDecoder()->audioChannels( astream ); 380 channels = mediaPlayerState->curDecoder()->audioChannels( astream );
381// qDebug( "LC- channels = %d", channels ); 381 qDebug( "LC- channels = %d", channels );
382 382
383 if ( !total_audio_samples ) 383 if ( !total_audio_samples )
384 total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); 384 total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream );
385 385
386// total_audio_samples += 1000; 386// total_audio_samples += 1000;
387 387
388 mediaPlayerState->setLength( total_audio_samples ); 388 mediaPlayerState->setLength( total_audio_samples );
389 389
390 freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); 390 freq = mediaPlayerState->curDecoder()->audioFrequency( astream );
391// qDebug( "LC- frequency = %d", freq ); 391 qDebug( "LC- frequency = %d", freq );
392 392
393 audioSampleCounter = 0; 393 audioSampleCounter = 0;
394 int bits_per_sample; 394 int bits_per_sample;
395 if ( mediaPlayerState->curDecoder()->pluginName() == QString("WavPlugin") ) { 395 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibWavPlugin") ) {
396 bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime(); 396 bits_per_sample =(int) mediaPlayerState->curDecoder()->getTime();
397// qDebug("using stupid hack"); 397 qDebug("using stupid hack");
398 } else { 398 } else {
399 bits_per_sample=0; 399 bits_per_sample=0;
400// freq=44100;
401 channels=2;
402 } 400 }
403 401
404 audioDevice = new AudioDevice( freq, channels, bits_per_sample); 402 audioDevice = new AudioDevice( freq, channels, bits_per_sample);
405 audioBuffer = new char[ audioDevice->bufferSize() ]; 403 audioBuffer = new char[ audioDevice->bufferSize() ];
406 channels = audioDevice->channels(); 404 channels = audioDevice->channels();
407 405
408 //### must check which frequency is actually used. 406 //### must check which frequency is actually used.
409 static const int size = 1; 407 static const int size = 1;
410 short int buf[size]; 408 short int buf[size];
411 long samplesRead = 0; 409 long samplesRead = 0;
412 mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); 410 mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream );
413 } 411 }