summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/loopcontrol_threaded.cpp
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/loopcontrol_threaded.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/multimedia/opieplayer/loopcontrol_threaded.cpp18
1 files changed, 9 insertions, 9 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
@@ -183,25 +183,25 @@ void LoopControl::timerEvent( QTimerEvent* ) {
183 183
184 184
185 185
186void LoopControl::setPosition( long pos ) { 186void LoopControl::setPosition( long pos ) {
187 if ( sendingNewPos ) { 187 if ( sendingNewPos ) {
188 sendingNewPos = FALSE; 188 sendingNewPos = FALSE;
189 return; 189 return;
190 } 190 }
191 191
192 if ( hasVideoChannel && hasAudioChannel ) { 192 if ( hasVideoChannel && hasAudioChannel ) {
193 videoMutex->lock(); 193 videoMutex->lock();
194 audioMutex->lock(); 194 audioMutex->lock();
195qDebug("setting position"); 195 //qDebug("setting position");
196 playtime.restart(); 196 playtime.restart();
197 playtime = playtime.addMSecs( -pos * 1000 / framerate ); 197 playtime = playtime.addMSecs( -pos * 1000 / framerate );
198 //begin = clock() - (double)pos * CLOCKS_PER_SEC / framerate; 198 //begin = clock() - (double)pos * CLOCKS_PER_SEC / framerate;
199 current_frame = pos + 1; 199 current_frame = pos + 1;
200 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); 200 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream );
201 prev_frame = current_frame - 1; 201 prev_frame = current_frame - 1;
202 currentSample = (int)( current_frame * freq / framerate ); 202 currentSample = (int)( current_frame * freq / framerate );
203 mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); 203 mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream );
204 audioSampleCounter = currentSample - 1; 204 audioSampleCounter = currentSample - 1;
205 audioMutex->unlock(); 205 audioMutex->unlock();
206 videoMutex->unlock(); 206 videoMutex->unlock();
207 } else if ( hasVideoChannel ) { 207 } else if ( hasVideoChannel ) {
@@ -299,25 +299,25 @@ void LoopControl::startVideo() {
299 videoMutex->lock(); 299 videoMutex->lock();
300 current_frame++; 300 current_frame++;
301 videoMutex->unlock(); 301 videoMutex->unlock();
302 } 302 }
303 303
304 videoMutex->lock(); 304 videoMutex->lock();
305 bool check = current_frame && current_frame > prev_frame; 305 bool check = current_frame && current_frame > prev_frame;
306 videoMutex->unlock(); 306 videoMutex->unlock();
307 307
308 if ( check ) { 308 if ( check ) {
309 videoMutex->lock(); 309 videoMutex->lock();
310 if ( current_frame > prev_frame + 1 ) { 310 if ( current_frame > prev_frame + 1 ) {
311 qDebug("skipped a frame"); 311 // qDebug("skipped a frame");
312 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); 312 mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream );
313 } 313 }
314 prev_frame = current_frame; 314 prev_frame = current_frame;
315 if ( moreVideo = videoUI->playVideo() ) 315 if ( moreVideo = videoUI->playVideo() )
316 emitChangePos = TRUE; 316 emitChangePos = TRUE;
317 videoMutex->unlock(); 317 videoMutex->unlock();
318 } 318 }
319 319
320 } else 320 } else
321 moreVideo = FALSE; 321 moreVideo = FALSE;
322 322
323 } 323 }
@@ -332,26 +332,26 @@ void LoopControl::startAudio() {
332 moreAudio = TRUE; 332 moreAudio = TRUE;
333 333
334 while ( moreAudio ) { 334 while ( moreAudio ) {
335 335
336 if ( !isMuted && mediaPlayerState->curDecoder() && hasAudioChannel ) { 336 if ( !isMuted && mediaPlayerState->curDecoder() && hasAudioChannel ) {
337 337
338 audioMutex->lock(); 338 audioMutex->lock();
339 currentSample = mediaPlayerState->curDecoder()->audioGetSample( stream ); 339 currentSample = mediaPlayerState->curDecoder()->audioGetSample( stream );
340 340
341 if ( currentSample == 0 ) 341 if ( currentSample == 0 )
342 currentSample = audioSampleCounter + 1; 342 currentSample = audioSampleCounter + 1;
343 343
344 if ( currentSample != audioSampleCounter + 1 ) 344// if ( currentSample != audioSampleCounter + 1 )
345 qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); 345// qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter);
346 audioMutex->unlock(); 346 audioMutex->unlock();
347 347
348/* 348/*
349 int sampleWeShouldBeAt = int( playtime.elapsed() ) * freq / 1000; 349 int sampleWeShouldBeAt = int( playtime.elapsed() ) * freq / 1000;
350 350
351 if ( sampleWeShouldBeAt - currentSample > 20000 ) { 351 if ( sampleWeShouldBeAt - currentSample > 20000 ) {
352 mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); 352 mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream );
353 currentSample = sampleWeShouldBeAt; 353 currentSample = sampleWeShouldBeAt;
354 } 354 }
355*/ 355*/
356 long samplesRead = 0; 356 long samplesRead = 0;
357 357
@@ -362,25 +362,25 @@ void LoopControl::startAudio() {
362 audioMutex->lock(); 362 audioMutex->lock();
363 long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; 363 long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000;
364 //long sampleWeShouldBeAt = long( clock() - begin ) * (double) freq / CLOCKS_PER_SEC; 364 //long sampleWeShouldBeAt = long( clock() - begin ) * (double) freq / CLOCKS_PER_SEC;
365 long sampleWaitTime = currentSample - sampleWeShouldBeAt; 365 long sampleWaitTime = currentSample - sampleWeShouldBeAt;
366 audioMutex->unlock(); 366 audioMutex->unlock();
367 367
368 if ( sampleWaitTime >= 0 && sampleWaitTime <= 2000 ) { 368 if ( sampleWaitTime >= 0 && sampleWaitTime <= 2000 ) {
369 //qDebug("sampleWaitTime: %i", sampleWaitTime); 369 //qDebug("sampleWaitTime: %i", sampleWaitTime);
370 usleep( ( sampleWaitTime * 1000000 ) / ( freq ) ); 370 usleep( ( sampleWaitTime * 1000000 ) / ( freq ) );
371 } else { 371 } else {
372 audioMutex->lock(); 372 audioMutex->lock();
373 if ( sampleWaitTime <= -2000 ) { 373 if ( sampleWaitTime <= -2000 ) {
374 qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); 374 // qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt );
375 mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); 375 mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream );
376 currentSample = sampleWeShouldBeAt; 376 currentSample = sampleWeShouldBeAt;
377 } 377 }
378 audioMutex->unlock(); 378 audioMutex->unlock();
379 } 379 }
380 380
381 audioDevice->write( audioBuffer, samplesRead * 2 * channels ); 381 audioDevice->write( audioBuffer, samplesRead * 2 * channels );
382 382
383 audioMutex->lock(); 383 audioMutex->lock();
384 // audioSampleCounter += samplesRead; 384 // audioSampleCounter += samplesRead;
385 audioSampleCounter = currentSample + samplesRead - 1; 385 audioSampleCounter = currentSample + samplesRead - 1;
386 audioMutex->unlock(); 386 audioMutex->unlock();
@@ -393,49 +393,49 @@ void LoopControl::startAudio() {
393 moreAudio = audioSampleCounter <= total_audio_samples; 393 moreAudio = audioSampleCounter <= total_audio_samples;
394 394
395 } else { 395 } else {
396 396
397 if ( mediaPlayerState->curDecoder() && hasAudioChannel ) 397 if ( mediaPlayerState->curDecoder() && hasAudioChannel )
398 usleep( 100000 ); // Check every 1/10 sec to see if mute is off 398 usleep( 100000 ); // Check every 1/10 sec to see if mute is off
399 else 399 else
400 moreAudio = FALSE; 400 moreAudio = FALSE;
401 401
402 } 402 }
403 } 403 }
404 404
405 qDebug( "End of file" ); 405 // qDebug( "End of file" );
406 406
407 if ( !moreVideo && !moreAudio ) 407 if ( !moreVideo && !moreAudio )
408 emitPlayFinished = TRUE; 408 emitPlayFinished = TRUE;
409 409
410 pthread_exit(NULL); 410 pthread_exit(NULL);
411} 411}
412 412
413void LoopControl::killTimers() { 413void LoopControl::killTimers() {
414 if ( hasVideoChannel ) { 414 if ( hasVideoChannel ) {
415 if ( pthread_self() != video_tid ) { 415 if ( pthread_self() != video_tid ) {
416 if ( pthread_cancel(video_tid) == 0 ) { 416 if ( pthread_cancel(video_tid) == 0 ) {
417 void *thread_result = 0; 417 void *thread_result = 0;
418 if ( pthread_join(video_tid,&thread_result) != 0 ) 418 if ( pthread_join(video_tid,&thread_result) != 0 )
419 qDebug("thread join error 1"); 419 // qDebug("thread join error 1");
420 pthread_attr_destroy(&video_attr); 420 pthread_attr_destroy(&video_attr);
421 } 421 }
422 } 422 }
423 } 423 }
424 if ( hasAudioChannel ) { 424 if ( hasAudioChannel ) {
425 if ( pthread_self() != audio_tid ) { 425 if ( pthread_self() != audio_tid ) {
426 if ( pthread_cancel(audio_tid) == 0 ) { 426 if ( pthread_cancel(audio_tid) == 0 ) {
427 void *thread_result = 0; 427 void *thread_result = 0;
428 if ( pthread_join(audio_tid,&thread_result) != 0 ) 428 if ( pthread_join(audio_tid,&thread_result) != 0 )
429 qDebug("thread join error 2"); 429 // qDebug("thread join error 2");
430 pthread_attr_destroy(&audio_attr); 430 pthread_attr_destroy(&audio_attr);
431 } 431 }
432 } 432 }
433 } 433 }
434} 434}
435 435
436void LoopControl::startTimers() { 436void LoopControl::startTimers() {
437 moreVideo = FALSE; 437 moreVideo = FALSE;
438 moreAudio = FALSE; 438 moreAudio = FALSE;
439 439
440 if ( hasVideoChannel ) { 440 if ( hasVideoChannel ) {
441 moreVideo = TRUE; 441 moreVideo = TRUE;
@@ -504,25 +504,25 @@ void LoopControl::stop( bool willPlayAgainShortly ) {
504 } 504 }
505 505
506 } 506 }
507} 507}
508 508
509 509
510bool LoopControl::init( const QString& filename ) { 510bool LoopControl::init( const QString& filename ) {
511 stop(); 511 stop();
512 fileName = filename; 512 fileName = filename;
513 stream = 0; // only play stream 0 for now 513 stream = 0; // only play stream 0 for now
514 current_frame = total_video_frames = total_audio_samples = 0; 514 current_frame = total_video_frames = total_audio_samples = 0;
515 515
516 qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); 516 // qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() );
517 517
518 // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin 518 // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin
519 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { 519 if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) {
520 if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) { 520 if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) {
521 total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); 521 total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 );
522 mediaPlayerState->libMpeg3Decoder()->close(); 522 mediaPlayerState->libMpeg3Decoder()->close();
523 } 523 }
524 } 524 }
525 525
526 if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) 526 if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) )
527 return FALSE; 527 return FALSE;
528 528