-rw-r--r-- | core/multimedia/opieplayer/libmad/libmadplugin.cpp | 8 | ||||
-rw-r--r-- | core/multimedia/opieplayer/loopcontrol.cpp | 4 | ||||
-rw-r--r-- | core/multimedia/opieplayer/wavplugin/wavplugin.cpp | 2 |
3 files changed, 7 insertions, 7 deletions
diff --git a/core/multimedia/opieplayer/libmad/libmadplugin.cpp b/core/multimedia/opieplayer/libmad/libmadplugin.cpp index b2b876f..9d04f7e 100644 --- a/core/multimedia/opieplayer/libmad/libmadplugin.cpp +++ b/core/multimedia/opieplayer/libmad/libmadplugin.cpp | |||
@@ -304,275 +304,275 @@ long LibMadPlugin::audioGetSample( int ) { | |||
304 | debugMsg( "LibMadPlugin::audioGetSample" ); | 304 | debugMsg( "LibMadPlugin::audioGetSample" ); |
305 | return 0; | 305 | return 0; |
306 | } | 306 | } |
307 | 307 | ||
308 | /* | 308 | /* |
309 | bool LibMadPlugin::audioReadSamples( short *, int, long, int ) { | 309 | bool LibMadPlugin::audioReadSamples( short *, int, long, int ) { |
310 | debugMsg( "LibMadPlugin::audioReadSamples" ); | 310 | debugMsg( "LibMadPlugin::audioReadSamples" ); |
311 | return FALSE; | 311 | return FALSE; |
312 | } | 312 | } |
313 | 313 | ||
314 | 314 | ||
315 | bool LibMadPlugin::audioReReadSamples( short *, int, long, int ) { | 315 | bool LibMadPlugin::audioReReadSamples( short *, int, long, int ) { |
316 | debugMsg( "LibMadPlugin::audioReReadSamples" ); | 316 | debugMsg( "LibMadPlugin::audioReReadSamples" ); |
317 | return FALSE; | 317 | return FALSE; |
318 | } | 318 | } |
319 | */ | 319 | */ |
320 | 320 | ||
321 | bool LibMadPlugin::read() { | 321 | bool LibMadPlugin::read() { |
322 | debugMsg( "LibMadPlugin::read" ); | 322 | debugMsg( "LibMadPlugin::read" ); |
323 | int len; | 323 | int len; |
324 | 324 | ||
325 | if (d->input.eof) | 325 | if (d->input.eof) |
326 | return FALSE; | 326 | return FALSE; |
327 | 327 | ||
328 | #if defined(HAVE_MMAP) | 328 | #if defined(HAVE_MMAP) |
329 | if (d->input.fdm) { | 329 | if (d->input.fdm) { |
330 | unsigned long skip = 0; | 330 | unsigned long skip = 0; |
331 | 331 | ||
332 | if (d->stream.next_frame) { | 332 | if (d->stream.next_frame) { |
333 | struct stat stat; | 333 | struct stat stat; |
334 | 334 | ||
335 | if (fstat(d->input.fd, &stat) == -1) | 335 | if (fstat(d->input.fd, &stat) == -1) |
336 | return FALSE; | 336 | return FALSE; |
337 | 337 | ||
338 | if (stat.st_size + MAD_BUFFER_GUARD <= (signed)d->input.length) | 338 | if (stat.st_size + MAD_BUFFER_GUARD <= (signed)d->input.length) |
339 | return FALSE; | 339 | return FALSE; |
340 | 340 | ||
341 | // file size changed; update memory map | 341 | // file size changed; update memory map |
342 | skip = d->stream.next_frame - d->input.data; | 342 | skip = d->stream.next_frame - d->input.data; |
343 | 343 | ||
344 | if (unmap_file(d->input.fdm, d->input.length) == -1) { | 344 | if (unmap_file(d->input.fdm, d->input.length) == -1) { |
345 | d->input.fdm = 0; | 345 | d->input.fdm = 0; |
346 | d->input.data = 0; | 346 | d->input.data = 0; |
347 | return FALSE; | 347 | return FALSE; |
348 | } | 348 | } |
349 | 349 | ||
350 | d->input.length = stat.st_size; | 350 | d->input.length = stat.st_size; |
351 | 351 | ||
352 | d->input.fdm = map_file(d->input.fd, &d->input.length); | 352 | d->input.fdm = map_file(d->input.fd, &d->input.length); |
353 | if (d->input.fdm == 0) { | 353 | if (d->input.fdm == 0) { |
354 | d->input.data = 0; | 354 | d->input.data = 0; |
355 | return FALSE; | 355 | return FALSE; |
356 | } | 356 | } |
357 | 357 | ||
358 | d->input.data = (unsigned char *)d->input.fdm; | 358 | d->input.data = (unsigned char *)d->input.fdm; |
359 | } | 359 | } |
360 | 360 | ||
361 | mad_stream_buffer(&d->stream, d->input.data + skip, d->input.length - skip); | 361 | mad_stream_buffer(&d->stream, d->input.data + skip, d->input.length - skip); |
362 | 362 | ||
363 | } else | 363 | } else |
364 | #endif | 364 | #endif |
365 | { | 365 | { |
366 | if (d->stream.next_frame) { | 366 | if (d->stream.next_frame) { |
367 | memmove(d->input.data, d->stream.next_frame, | 367 | memmove(d->input.data, d->stream.next_frame, |
368 | d->input.length = &d->input.data[d->input.length] - d->stream.next_frame); | 368 | d->input.length = &d->input.data[d->input.length] - d->stream.next_frame); |
369 | } | 369 | } |
370 | 370 | ||
371 | do { | 371 | do { |
372 | len = ::read(d->input.fd, d->input.data + d->input.length, MPEG_BUFFER_SIZE - d->input.length); | 372 | len = ::read(d->input.fd, d->input.data + d->input.length, MPEG_BUFFER_SIZE - d->input.length); |
373 | } | 373 | } |
374 | while (len == -1 && errno == EINTR); | 374 | while (len == -1 && errno == EINTR); |
375 | 375 | ||
376 | if (len == -1) { | 376 | if (len == -1) { |
377 | qDebug("error reading audio"); | 377 | qDebug("error reading audio"); |
378 | return FALSE; | 378 | return FALSE; |
379 | } | 379 | } |
380 | else if (len == 0) { | 380 | else if (len == 0) { |
381 | d->input.eof = 1; | 381 | d->input.eof = 1; |
382 | 382 | ||
383 | assert(MPEG_BUFFER_SIZE - d->input.length >= MAD_BUFFER_GUARD); | 383 | assert(MPEG_BUFFER_SIZE - d->input.length >= MAD_BUFFER_GUARD); |
384 | 384 | ||
385 | while (len < MAD_BUFFER_GUARD) | 385 | while (len < MAD_BUFFER_GUARD) |
386 | d->input.data[d->input.length + len++] = 0; | 386 | d->input.data[d->input.length + len++] = 0; |
387 | } | 387 | } |
388 | 388 | ||
389 | mad_stream_buffer(&d->stream, d->input.data, d->input.length += len); | 389 | mad_stream_buffer(&d->stream, d->input.data, d->input.length += len); |
390 | } | 390 | } |
391 | 391 | ||
392 | return TRUE; | 392 | return TRUE; |
393 | } | 393 | } |
394 | 394 | ||
395 | 395 | ||
396 | static mad_fixed_t left_err, right_err; | 396 | static mad_fixed_t left_err, right_err; |
397 | static const int bits = 16; | 397 | static const int bits = 16; |
398 | static const int shift = MAD_F_FRACBITS + 1 - bits; | 398 | static const int shift = MAD_F_FRACBITS + 1 - bits; |
399 | 399 | ||
400 | 400 | ||
401 | inline long audio_linear_dither( mad_fixed_t sample, mad_fixed_t& error ) | 401 | inline long audio_linear_dither( mad_fixed_t sample, mad_fixed_t& error ) |
402 | { | 402 | { |
403 | sample += error; | 403 | sample += error; |
404 | mad_fixed_t quantized = (sample >= MAD_F_ONE) ? MAD_F_ONE - 1 : ( (sample < -MAD_F_ONE) ? -MAD_F_ONE : sample ); | 404 | mad_fixed_t quantized = (sample >= MAD_F_ONE) ? MAD_F_ONE - 1 : ( (sample < -MAD_F_ONE) ? -MAD_F_ONE : sample ); |
405 | quantized &= ~((1L << shift) - 1); | 405 | quantized &= ~((1L << shift) - 1); |
406 | error = sample - quantized; | 406 | error = sample - quantized; |
407 | return quantized >> shift; | 407 | return quantized >> shift; |
408 | } | 408 | } |
409 | 409 | ||
410 | 410 | ||
411 | inline void audio_pcm( short *data, unsigned int nsamples, mad_fixed_t *left, mad_fixed_t *right ) | 411 | inline void audio_pcm( short *data, unsigned int nsamples, mad_fixed_t *left, mad_fixed_t *right ) |
412 | { | 412 | { |
413 | if ( right ) { | 413 | if ( right ) { |
414 | while (nsamples--) { | 414 | while (nsamples--) { |
415 | data[0] = audio_linear_dither( *left++, left_err ); | 415 | data[0] = audio_linear_dither( *left++, left_err ); |
416 | data[1] = audio_linear_dither( *right++, right_err ); | 416 | data[1] = audio_linear_dither( *right++, right_err ); |
417 | data += 2; | 417 | data += 2; |
418 | } | 418 | } |
419 | } else { | 419 | } else { |
420 | while (nsamples--) { | 420 | while (nsamples--) { |
421 | data[0] = data[1] = audio_linear_dither( *left++, left_err ); | 421 | data[0] = data[1] = audio_linear_dither( *left++, left_err ); |
422 | data += 2; | 422 | data += 2; |
423 | } | 423 | } |
424 | } | 424 | } |
425 | } | 425 | } |
426 | 426 | ||
427 | 427 | ||
428 | bool LibMadPlugin::decode( short *output, long samples, long& samplesMade ) { | 428 | bool LibMadPlugin::decode( short *output, long samples, long& samplesMade ) { |
429 | debugMsg( "LibMadPlugin::decode" ); | 429 | debugMsg( "LibMadPlugin::decode" ); |
430 | 430 | ||
431 | static int buffered = 0; | 431 | static int buffered = 0; |
432 | static mad_fixed_t buffer[2][65536 * 2]; | 432 | static mad_fixed_t buffer[2][65536 * 2]; |
433 | int offset = buffered; | 433 | int offset = buffered; |
434 | samplesMade = 0; | 434 | samplesMade = 0; |
435 | 435 | ||
436 | static int maxBuffered = 8000; // 65536; | 436 | static int maxBuffered = 8000; // 65536; |
437 | 437 | ||
438 | if ( samples > maxBuffered ) | 438 | if ( samples > maxBuffered ) |
439 | samples = maxBuffered; | 439 | samples = maxBuffered; |
440 | 440 | ||
441 | if ( d->flush ) { | 441 | if ( d->flush ) { |
442 | buffered = 0; | 442 | buffered = 0; |
443 | offset = 0; | 443 | offset = 0; |
444 | d->flush = FALSE; | 444 | d->flush = FALSE; |
445 | } | 445 | } |
446 | 446 | ||
447 | while ( buffered < maxBuffered ) { | 447 | while ( buffered < maxBuffered ) { |
448 | 448 | ||
449 | while (mad_frame_decode(&d->frame, &d->stream) == -1) { | 449 | while (mad_frame_decode(&d->frame, &d->stream) == -1) { |
450 | if (!MAD_RECOVERABLE(d->stream.error)) { | 450 | if (!MAD_RECOVERABLE(d->stream.error)) { |
451 | debugMsg( "feed me" ); | 451 | debugMsg( "feed me" ); |
452 | return FALSE; // Feed me | 452 | return FALSE; // Feed me |
453 | } | 453 | } |
454 | if ( d->stream.error == MAD_ERROR_BADCRC ) { | 454 | if ( d->stream.error == MAD_ERROR_BADCRC ) { |
455 | mad_frame_mute(&d->frame); | 455 | mad_frame_mute(&d->frame); |
456 | qDebug( "error decoding, bad crc" ); | 456 | qDebug( "error decoding, bad crc" ); |
457 | } | 457 | } |
458 | } | 458 | } |
459 | 459 | ||
460 | mad_synth_frame(&d->synth, &d->frame); | 460 | mad_synth_frame(&d->synth, &d->frame); |
461 | int decodedSamples = d->synth.pcm.length; | 461 | int decodedSamples = d->synth.pcm.length; |
462 | memcpy( &(buffer[0][offset]), d->synth.pcm.samples[0], decodedSamples * sizeof(mad_fixed_t) ); | 462 | memcpy( &(buffer[0][offset]), d->synth.pcm.samples[0], decodedSamples * sizeof(mad_fixed_t) ); |
463 | if ( d->synth.pcm.channels == 2 ) | 463 | if ( d->synth.pcm.channels == 2 ) |
464 | memcpy( &(buffer[1][offset]), d->synth.pcm.samples[1], decodedSamples * sizeof(mad_fixed_t) ); | 464 | memcpy( &(buffer[1][offset]), d->synth.pcm.samples[1], decodedSamples * sizeof(mad_fixed_t) ); |
465 | offset += decodedSamples; | 465 | offset += decodedSamples; |
466 | buffered += decodedSamples; | 466 | buffered += decodedSamples; |
467 | } | 467 | } |
468 | 468 | ||
469 | audio_pcm( output, samples, buffer[0], (d->synth.pcm.channels == 2) ? buffer[1] : 0 ); | 469 | audio_pcm( output, samples, buffer[0], (d->synth.pcm.channels == 2) ? buffer[1] : 0 ); |
470 | // audio_pcm( output, samples, buffer[1], buffer[0] ); | 470 | // audio_pcm( output, samples, buffer[1], buffer[0] ); |
471 | // audio_pcm( output, samples, buffer[0], buffer[1] ); | 471 | // audio_pcm( output, samples, buffer[0], buffer[1] ); |
472 | samplesMade = samples; | 472 | samplesMade = samples; |
473 | memmove( buffer[0], &(buffer[0][samples]), (buffered - samples) * sizeof(mad_fixed_t) ); | 473 | memmove( buffer[0], &(buffer[0][samples]), (buffered - samples) * sizeof(mad_fixed_t) ); |
474 | if ( d->synth.pcm.channels == 2 ) | 474 | if ( d->synth.pcm.channels == 2 ) |
475 | memmove( buffer[1], &(buffer[1][samples]), (buffered - samples) * sizeof(mad_fixed_t) ); | 475 | memmove( buffer[1], &(buffer[1][samples]), (buffered - samples) * sizeof(mad_fixed_t) ); |
476 | buffered -= samples; | 476 | buffered -= samples; |
477 | 477 | ||
478 | return TRUE; | 478 | return TRUE; |
479 | } | 479 | } |
480 | 480 | ||
481 | /* | 481 | /* |
482 | bool LibMadPlugin::audioReadMonoSamples( short *, long, long&, int ) { | 482 | bool LibMadPlugin::audioReadMonoSamples( short *, long, long&, int ) { |
483 | debugMsg( "LibMadPlugin::audioReadMonoSamples" ); | 483 | debugMsg( "LibMadPlugin::audioReadMonoSamples" ); |
484 | return FALSE; | 484 | return FALSE; |
485 | } | 485 | } |
486 | 486 | ||
487 | 487 | ||
488 | bool LibMadPlugin::audioReadStereoSamples( short *output, long samples, long& samplesMade, int ) { | 488 | bool LibMadPlugin::audioReadStereoSamples( short *output, long samples, long& samplesMade, int ) { |
489 | */ | 489 | */ |
490 | bool LibMadPlugin::audioReadSamples( short *output, int /*channels*/, long samples, long& samplesMade, int ) { | 490 | bool LibMadPlugin::audioReadSamples( short *output, int /*channels*/, long samples, long& samplesMade, int ) { |
491 | debugMsg( "LibMadPlugin::audioReadStereoSamples" ); | 491 | debugMsg( "LibMadPlugin::audioReadStereoSamples" ); |
492 | 492 | ||
493 | static bool needInput = TRUE; | 493 | static bool needInput = TRUE; |
494 | 494 | ||
495 | if ( samples == 0 ) | 495 | if ( samples == 0 ) |
496 | return TRUE; | 496 | return FALSE; |
497 | 497 | ||
498 | do { | 498 | do { |
499 | if ( needInput ) | 499 | if ( needInput ) |
500 | if ( !read() ) { | 500 | if ( !read() ) { |
501 | // if ( d->input.eof ) | 501 | // if ( d->input.eof ) |
502 | // needInput = FALSE; | 502 | // needInput = FALSE; |
503 | // else | 503 | // else |
504 | return TRUE; | 504 | return FALSE; |
505 | } | 505 | } |
506 | 506 | ||
507 | needInput = FALSE; | 507 | needInput = FALSE; |
508 | 508 | ||
509 | if ( decode( output, samples, samplesMade ) ) | 509 | if ( decode( output, samples, samplesMade ) ) |
510 | return FALSE; | 510 | return TRUE; |
511 | else | 511 | else |
512 | needInput = TRUE; | 512 | needInput = TRUE; |
513 | } | 513 | } |
514 | while ( ( samplesMade < samples ) && ( !d->input.eof ) ); | 514 | while ( ( samplesMade < samples ) && ( !d->input.eof ) ); |
515 | /* | 515 | /* |
516 | static bool firstTimeThru = TRUE; | 516 | static bool firstTimeThru = TRUE; |
517 | 517 | ||
518 | if ( firstTimeThru ) { | 518 | if ( firstTimeThru ) { |
519 | firstTimeThru = FALSE; | 519 | firstTimeThru = FALSE; |
520 | decode( output, samples, samplesMade ); | 520 | decode( output, samples, samplesMade ); |
521 | return FALSE; | 521 | return FALSE; |
522 | } else | 522 | } else |
523 | */ | 523 | */ |
524 | return TRUE; | 524 | return FALSE; |
525 | } | 525 | } |
526 | 526 | ||
527 | 527 | ||
528 | double LibMadPlugin::getTime() { | 528 | double LibMadPlugin::getTime() { |
529 | debugMsg( "LibMadPlugin::getTime" ); | 529 | debugMsg( "LibMadPlugin::getTime" ); |
530 | return 0.0; | 530 | return 0.0; |
531 | } | 531 | } |
532 | 532 | ||
533 | 533 | ||
534 | void LibMadPlugin::printID3Tags() { | 534 | void LibMadPlugin::printID3Tags() { |
535 | debugMsg( "LibMadPlugin::printID3Tags" ); | 535 | debugMsg( "LibMadPlugin::printID3Tags" ); |
536 | 536 | ||
537 | char id3v1[128 + 1]; | 537 | char id3v1[128 + 1]; |
538 | 538 | ||
539 | if ( ::lseek( d->input.fd, -128, SEEK_END ) == -1 ) { | 539 | if ( ::lseek( d->input.fd, -128, SEEK_END ) == -1 ) { |
540 | qDebug( "error seeking to id3 tags" ); | 540 | qDebug( "error seeking to id3 tags" ); |
541 | return; | 541 | return; |
542 | } | 542 | } |
543 | 543 | ||
544 | if ( ::read( d->input.fd, id3v1, 128 ) != 128 ) { | 544 | if ( ::read( d->input.fd, id3v1, 128 ) != 128 ) { |
545 | qDebug( "error reading in id3 tags" ); | 545 | qDebug( "error reading in id3 tags" ); |
546 | return; | 546 | return; |
547 | } | 547 | } |
548 | 548 | ||
549 | if ( ::strncmp( (const char *)id3v1, "TAG", 3 ) != 0 ) { | 549 | if ( ::strncmp( (const char *)id3v1, "TAG", 3 ) != 0 ) { |
550 | debugMsg( "sorry, no id3 tags" ); | 550 | debugMsg( "sorry, no id3 tags" ); |
551 | } else { | 551 | } else { |
552 | int len[5] = { 30, 30, 30, 4, 30 }; | 552 | int len[5] = { 30, 30, 30, 4, 30 }; |
553 | QString label[5] = { tr( "Title" ), tr( "Artist" ), tr( "Album" ), tr( "Year" ), tr( "Comment" ) }; | 553 | QString label[5] = { tr( "Title" ), tr( "Artist" ), tr( "Album" ), tr( "Year" ), tr( "Comment" ) }; |
554 | char *ptr = id3v1 + 3, *ptr2 = ptr + len[0]; | 554 | char *ptr = id3v1 + 3, *ptr2 = ptr + len[0]; |
555 | qDebug( "ID3 tags in file:" ); | 555 | qDebug( "ID3 tags in file:" ); |
556 | info = ""; | 556 | info = ""; |
557 | for ( int i = 0; i < 5; ptr += len[i], i++, ptr2 += len[i] ) { | 557 | for ( int i = 0; i < 5; ptr += len[i], i++, ptr2 += len[i] ) { |
558 | char push = *ptr2; | 558 | char push = *ptr2; |
559 | *ptr2 = '\0'; | 559 | *ptr2 = '\0'; |
560 | char *ptr3 = ptr2; | 560 | char *ptr3 = ptr2; |
561 | while ( ptr3-1 >= ptr && isspace(ptr3[-1]) ) ptr3--; | 561 | while ( ptr3-1 >= ptr && isspace(ptr3[-1]) ) ptr3--; |
562 | char push2 = *ptr3; *ptr3 = '\0'; | 562 | char push2 = *ptr3; *ptr3 = '\0'; |
563 | if ( strcmp( ptr, "" ) ) | 563 | if ( strcmp( ptr, "" ) ) |
564 | info += ( i != 0 ? ", " : "" ) + label[i] + ": " + ptr; | 564 | info += ( i != 0 ? ", " : "" ) + label[i] + ": " + ptr; |
565 | //qDebug( info.latin1() ); | 565 | //qDebug( info.latin1() ); |
566 | *ptr3 = push2; | 566 | *ptr3 = push2; |
567 | *ptr2 = push; | 567 | *ptr2 = push; |
568 | } | 568 | } |
569 | if (id3v1[126] == 0 && id3v1[127] != 0) | 569 | if (id3v1[126] == 0 && id3v1[127] != 0) |
570 | info += tr( ", Track: " ) + id3v1[127]; | 570 | info += tr( ", Track: " ) + id3v1[127]; |
571 | } | 571 | } |
572 | 572 | ||
573 | if ( ::lseek(d->input.fd, 0, SEEK_SET) == -1 ) { | 573 | if ( ::lseek(d->input.fd, 0, SEEK_SET) == -1 ) { |
574 | qDebug( "error seeking back to beginning" ); | 574 | qDebug( "error seeking back to beginning" ); |
575 | return; | 575 | return; |
576 | } | 576 | } |
577 | } | 577 | } |
578 | 578 | ||
diff --git a/core/multimedia/opieplayer/loopcontrol.cpp b/core/multimedia/opieplayer/loopcontrol.cpp index 93a6e3f..6dfd057 100644 --- a/core/multimedia/opieplayer/loopcontrol.cpp +++ b/core/multimedia/opieplayer/loopcontrol.cpp | |||
@@ -39,400 +39,400 @@ extern MediaPlayerState *mediaPlayerState; | |||
39 | 39 | ||
40 | 40 | ||
41 | //#define DecodeLoopDebug(x) qDebug x | 41 | //#define DecodeLoopDebug(x) qDebug x |
42 | #define DecodeLoopDebug(x) | 42 | #define DecodeLoopDebug(x) |
43 | 43 | ||
44 | 44 | ||
45 | static char *audioBuffer = NULL; | 45 | static char *audioBuffer = NULL; |
46 | static AudioDevice *audioDevice = NULL; | 46 | static AudioDevice *audioDevice = NULL; |
47 | static bool disabledSuspendScreenSaver = FALSE; | 47 | static bool disabledSuspendScreenSaver = FALSE; |
48 | static bool previousSuspendMode = FALSE; | 48 | static bool previousSuspendMode = FALSE; |
49 | 49 | ||
50 | 50 | ||
51 | pthread_taudio_tid; | 51 | pthread_taudio_tid; |
52 | pthread_attr_t audio_attr; | 52 | pthread_attr_t audio_attr; |
53 | bool threadOkToGo = FALSE; | 53 | bool threadOkToGo = FALSE; |
54 | 54 | ||
55 | 55 | ||
56 | class Mutex { | 56 | class Mutex { |
57 | public: | 57 | public: |
58 | Mutex() { | 58 | Mutex() { |
59 | pthread_mutexattr_t attr; | 59 | pthread_mutexattr_t attr; |
60 | pthread_mutexattr_init( &attr ); | 60 | pthread_mutexattr_init( &attr ); |
61 | pthread_mutex_init( &mutex, &attr ); | 61 | pthread_mutex_init( &mutex, &attr ); |
62 | pthread_mutexattr_destroy( &attr ); | 62 | pthread_mutexattr_destroy( &attr ); |
63 | } | 63 | } |
64 | 64 | ||
65 | ~Mutex() { | 65 | ~Mutex() { |
66 | pthread_mutex_destroy( &mutex ); | 66 | pthread_mutex_destroy( &mutex ); |
67 | } | 67 | } |
68 | 68 | ||
69 | void lock() { | 69 | void lock() { |
70 | pthread_mutex_lock( &mutex ); | 70 | pthread_mutex_lock( &mutex ); |
71 | } | 71 | } |
72 | 72 | ||
73 | void unlock() { | 73 | void unlock() { |
74 | pthread_mutex_unlock( &mutex ); | 74 | pthread_mutex_unlock( &mutex ); |
75 | } | 75 | } |
76 | private: | 76 | private: |
77 | pthread_mutex_t mutex; | 77 | pthread_mutex_t mutex; |
78 | }; | 78 | }; |
79 | 79 | ||
80 | 80 | ||
81 | void *startAudioThread( void *ptr ) { | 81 | void *startAudioThread( void *ptr ) { |
82 | LoopControl *mpegView = (LoopControl *)ptr; | 82 | LoopControl *mpegView = (LoopControl *)ptr; |
83 | while ( TRUE ) { | 83 | while ( TRUE ) { |
84 | if ( threadOkToGo && mpegView->moreAudio ) | 84 | if ( threadOkToGo && mpegView->moreAudio ) |
85 | mpegView->startAudio(); | 85 | mpegView->startAudio(); |
86 | else | 86 | else |
87 | usleep( 10000 ); // Semi-buzy-wait till we are playing again | 87 | usleep( 10000 ); // Semi-buzy-wait till we are playing again |
88 | } | 88 | } |
89 | return 0; | 89 | return 0; |
90 | } | 90 | } |
91 | 91 | ||
92 | 92 | ||
93 | Mutex *audioMutex; | 93 | Mutex *audioMutex; |
94 | 94 | ||
95 | 95 | ||
96 | LoopControl::LoopControl( QObject *parent, const char *name ) | 96 | LoopControl::LoopControl( QObject *parent, const char *name ) |
97 | : QObject( parent, name ) { | 97 | : QObject( parent, name ) { |
98 | isMuted = FALSE; | 98 | isMuted = FALSE; |
99 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) ); | 99 | connect( qApp, SIGNAL( volumeChanged(bool) ), this, SLOT( setMute(bool) ) ); |
100 | 100 | ||
101 | audioMutex = new Mutex; | 101 | audioMutex = new Mutex; |
102 | 102 | ||
103 | pthread_attr_init(&audio_attr); | 103 | pthread_attr_init(&audio_attr); |
104 | #define USE_REALTIME_AUDIO_THREAD | 104 | #define USE_REALTIME_AUDIO_THREAD |
105 | #ifdef USE_REALTIME_AUDIO_THREAD | 105 | #ifdef USE_REALTIME_AUDIO_THREAD |
106 | // Attempt to set it to real-time round robin | 106 | // Attempt to set it to real-time round robin |
107 | if ( pthread_attr_setschedpolicy( &audio_attr, SCHED_RR ) == 0 ) { | 107 | if ( pthread_attr_setschedpolicy( &audio_attr, SCHED_RR ) == 0 ) { |
108 | sched_param params; | 108 | sched_param params; |
109 | params.sched_priority = 50; | 109 | params.sched_priority = 50; |
110 | pthread_attr_setschedparam(&audio_attr,¶ms); | 110 | pthread_attr_setschedparam(&audio_attr,¶ms); |
111 | } else { | 111 | } else { |
112 | qDebug( "Error setting up a realtime thread, reverting to using a normal thread." ); | 112 | qDebug( "Error setting up a realtime thread, reverting to using a normal thread." ); |
113 | pthread_attr_destroy(&audio_attr); | 113 | pthread_attr_destroy(&audio_attr); |
114 | pthread_attr_init(&audio_attr); | 114 | pthread_attr_init(&audio_attr); |
115 | } | 115 | } |
116 | #endif | 116 | #endif |
117 | pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); | 117 | pthread_create(&audio_tid, &audio_attr, (void * (*)(void *))startAudioThread, this); |
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||
121 | LoopControl::~LoopControl() { | 121 | LoopControl::~LoopControl() { |
122 | stop(); | 122 | stop(); |
123 | } | 123 | } |
124 | 124 | ||
125 | 125 | ||
126 | static long prev_frame = 0; | 126 | static long prev_frame = 0; |
127 | static int currentSample = 0; | 127 | static int currentSample = 0; |
128 | 128 | ||
129 | 129 | ||
130 | void LoopControl::timerEvent( QTimerEvent *te ) { | 130 | void LoopControl::timerEvent( QTimerEvent *te ) { |
131 | 131 | ||
132 | if ( te->timerId() == videoId ) | 132 | if ( te->timerId() == videoId ) |
133 | startVideo(); | 133 | startVideo(); |
134 | 134 | ||
135 | if ( te->timerId() == sliderId ) { | 135 | if ( te->timerId() == sliderId ) { |
136 | if ( hasAudioChannel && !hasVideoChannel && moreAudio ) { | 136 | if ( hasAudioChannel && !hasVideoChannel && moreAudio ) { |
137 | mediaPlayerState->updatePosition( audioSampleCounter ); | 137 | mediaPlayerState->updatePosition( audioSampleCounter ); |
138 | } else if ( hasVideoChannel && moreVideo ) { | 138 | } else if ( hasVideoChannel && moreVideo ) { |
139 | mediaPlayerState->updatePosition( current_frame ); | 139 | mediaPlayerState->updatePosition( current_frame ); |
140 | } | 140 | } |
141 | } | 141 | } |
142 | 142 | ||
143 | if ( !moreVideo && !moreAudio ) { | 143 | if ( !moreVideo && !moreAudio ) { |
144 | mediaPlayerState->setPlaying( FALSE ); | 144 | mediaPlayerState->setPlaying( FALSE ); |
145 | mediaPlayerState->setNext(); | 145 | mediaPlayerState->setNext(); |
146 | } | 146 | } |
147 | } | 147 | } |
148 | 148 | ||
149 | 149 | ||
150 | void LoopControl::setPosition( long pos ) { | 150 | void LoopControl::setPosition( long pos ) { |
151 | audioMutex->lock(); | 151 | audioMutex->lock(); |
152 | 152 | ||
153 | if ( hasVideoChannel && hasAudioChannel ) { | 153 | if ( hasVideoChannel && hasAudioChannel ) { |
154 | playtime.restart(); | 154 | playtime.restart(); |
155 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); | 155 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); |
156 | current_frame = pos + 1; | 156 | current_frame = pos + 1; |
157 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); | 157 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); |
158 | prev_frame = current_frame - 1; | 158 | prev_frame = current_frame - 1; |
159 | currentSample = (int)( (double)current_frame * freq / framerate ); | 159 | currentSample = (int)( (double)current_frame * freq / framerate ); |
160 | mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); | 160 | mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); |
161 | audioSampleCounter = currentSample - 1; | 161 | audioSampleCounter = currentSample - 1; |
162 | } else if ( hasVideoChannel ) { | 162 | } else if ( hasVideoChannel ) { |
163 | playtime.restart(); | 163 | playtime.restart(); |
164 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); | 164 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); |
165 | current_frame = pos + 1; | 165 | current_frame = pos + 1; |
166 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); | 166 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); |
167 | prev_frame = current_frame - 1; | 167 | prev_frame = current_frame - 1; |
168 | } else if ( hasAudioChannel ) { | 168 | } else if ( hasAudioChannel ) { |
169 | playtime.restart(); | 169 | playtime.restart(); |
170 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / freq) ); | 170 | playtime = playtime.addMSecs( long((double)-pos * 1000.0 / freq) ); |
171 | currentSample = pos + 1; | 171 | currentSample = pos + 1; |
172 | mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); | 172 | mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); |
173 | audioSampleCounter = currentSample - 1; | 173 | audioSampleCounter = currentSample - 1; |
174 | } | 174 | } |
175 | 175 | ||
176 | audioMutex->unlock(); | 176 | audioMutex->unlock(); |
177 | } | 177 | } |
178 | 178 | ||
179 | 179 | ||
180 | void LoopControl::startVideo() { | 180 | void LoopControl::startVideo() { |
181 | 181 | ||
182 | if ( moreVideo ) { | 182 | if ( moreVideo ) { |
183 | 183 | ||
184 | if ( mediaPlayerState->curDecoder() ) { | 184 | if ( mediaPlayerState->curDecoder() ) { |
185 | 185 | ||
186 | if ( hasAudioChannel && !isMuted ) { | 186 | if ( hasAudioChannel && !isMuted ) { |
187 | 187 | ||
188 | current_frame = long( playtime.elapsed() * framerate / 1000 ); | 188 | current_frame = long( playtime.elapsed() * framerate / 1000 ); |
189 | 189 | ||
190 | if ( prev_frame != -1 && current_frame <= prev_frame ) | 190 | if ( prev_frame != -1 && current_frame <= prev_frame ) |
191 | return; | 191 | return; |
192 | 192 | ||
193 | } else { | 193 | } else { |
194 | // Don't skip | 194 | // Don't skip |
195 | current_frame++; | 195 | current_frame++; |
196 | } | 196 | } |
197 | 197 | ||
198 | if ( prev_frame == -1 || current_frame > prev_frame ) { | 198 | if ( prev_frame == -1 || current_frame > prev_frame ) { |
199 | if ( current_frame > prev_frame + 1 ) { | 199 | if ( current_frame > prev_frame + 1 ) { |
200 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); | 200 | mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); |
201 | } | 201 | } |
202 | moreVideo = videoUI->playVideo(); | 202 | moreVideo = videoUI->playVideo(); |
203 | prev_frame = current_frame; | 203 | prev_frame = current_frame; |
204 | } | 204 | } |
205 | 205 | ||
206 | } else { | 206 | } else { |
207 | 207 | ||
208 | moreVideo = FALSE; | 208 | moreVideo = FALSE; |
209 | killTimer( videoId ); | 209 | killTimer( videoId ); |
210 | 210 | ||
211 | } | 211 | } |
212 | 212 | ||
213 | } | 213 | } |
214 | } | 214 | } |
215 | 215 | ||
216 | 216 | ||
217 | void LoopControl::startAudio() { | 217 | void LoopControl::startAudio() { |
218 | 218 | ||
219 | audioMutex->lock(); | 219 | audioMutex->lock(); |
220 | 220 | ||
221 | if ( moreAudio ) { | 221 | if ( moreAudio ) { |
222 | 222 | ||
223 | if ( !isMuted && mediaPlayerState->curDecoder() ) { | 223 | if ( !isMuted && mediaPlayerState->curDecoder() ) { |
224 | 224 | ||
225 | currentSample = audioSampleCounter + 1; | 225 | currentSample = audioSampleCounter + 1; |
226 | 226 | ||
227 | if ( currentSample != audioSampleCounter + 1 ) | 227 | if ( currentSample != audioSampleCounter + 1 ) |
228 | qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); | 228 | qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); |
229 | 229 | ||
230 | long samplesRead = 0; | 230 | long samplesRead = 0; |
231 | mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); | 231 | bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); |
232 | long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; | 232 | long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; |
233 | long sampleWaitTime = currentSample - sampleWeShouldBeAt; | 233 | long sampleWaitTime = currentSample - sampleWeShouldBeAt; |
234 | 234 | ||
235 | if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) { | 235 | if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) { |
236 | usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); | 236 | usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); |
237 | } else if ( sampleWaitTime <= -5000 ) { | 237 | } else if ( sampleWaitTime <= -5000 ) { |
238 | qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); | 238 | qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); |
239 | //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); | 239 | //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); |
240 | currentSample = sampleWeShouldBeAt; | 240 | currentSample = sampleWeShouldBeAt; |
241 | } | 241 | } |
242 | 242 | ||
243 | audioDevice->write( audioBuffer, samplesRead * 2 * channels ); | 243 | audioDevice->write( audioBuffer, samplesRead * 2 * channels ); |
244 | audioSampleCounter = currentSample + samplesRead - 1; | 244 | audioSampleCounter = currentSample + samplesRead - 1; |
245 | 245 | ||
246 | moreAudio = audioSampleCounter <= total_audio_samples; | 246 | moreAudio = readOk && (audioSampleCounter <= total_audio_samples); |
247 | 247 | ||
248 | } else { | 248 | } else { |
249 | 249 | ||
250 | moreAudio = FALSE; | 250 | moreAudio = FALSE; |
251 | 251 | ||
252 | } | 252 | } |
253 | 253 | ||
254 | } | 254 | } |
255 | 255 | ||
256 | audioMutex->unlock(); | 256 | audioMutex->unlock(); |
257 | } | 257 | } |
258 | 258 | ||
259 | 259 | ||
260 | void LoopControl::killTimers() { | 260 | void LoopControl::killTimers() { |
261 | 261 | ||
262 | audioMutex->lock(); | 262 | audioMutex->lock(); |
263 | 263 | ||
264 | if ( hasVideoChannel ) | 264 | if ( hasVideoChannel ) |
265 | killTimer( videoId ); | 265 | killTimer( videoId ); |
266 | killTimer( sliderId ); | 266 | killTimer( sliderId ); |
267 | threadOkToGo = FALSE; | 267 | threadOkToGo = FALSE; |
268 | 268 | ||
269 | audioMutex->unlock(); | 269 | audioMutex->unlock(); |
270 | } | 270 | } |
271 | 271 | ||
272 | 272 | ||
273 | void LoopControl::startTimers() { | 273 | void LoopControl::startTimers() { |
274 | 274 | ||
275 | audioMutex->lock(); | 275 | audioMutex->lock(); |
276 | 276 | ||
277 | moreVideo = FALSE; | 277 | moreVideo = FALSE; |
278 | moreAudio = FALSE; | 278 | moreAudio = FALSE; |
279 | 279 | ||
280 | if ( hasVideoChannel ) { | 280 | if ( hasVideoChannel ) { |
281 | moreVideo = TRUE; | 281 | moreVideo = TRUE; |
282 | int mSecsBetweenFrames = (int)(100 / framerate); // 10% of the real value | 282 | int mSecsBetweenFrames = (int)(100 / framerate); // 10% of the real value |
283 | videoId = startTimer( mSecsBetweenFrames ); | 283 | videoId = startTimer( mSecsBetweenFrames ); |
284 | } | 284 | } |
285 | 285 | ||
286 | if ( hasAudioChannel ) { | 286 | if ( hasAudioChannel ) { |
287 | moreAudio = TRUE; | 287 | moreAudio = TRUE; |
288 | threadOkToGo = TRUE; | 288 | threadOkToGo = TRUE; |
289 | } | 289 | } |
290 | 290 | ||
291 | sliderId = startTimer( 300 ); // update slider every 1/3 second | 291 | sliderId = startTimer( 300 ); // update slider every 1/3 second |
292 | 292 | ||
293 | audioMutex->unlock(); | 293 | audioMutex->unlock(); |
294 | } | 294 | } |
295 | 295 | ||
296 | 296 | ||
297 | void LoopControl::setPaused( bool pause ) { | 297 | void LoopControl::setPaused( bool pause ) { |
298 | 298 | ||
299 | if ( !mediaPlayerState->curDecoder() || !mediaPlayerState->curDecoder()->isOpen() ) | 299 | if ( !mediaPlayerState->curDecoder() || !mediaPlayerState->curDecoder()->isOpen() ) |
300 | return; | 300 | return; |
301 | 301 | ||
302 | if ( pause ) { | 302 | if ( pause ) { |
303 | killTimers(); | 303 | killTimers(); |
304 | } else { | 304 | } else { |
305 | // Force an update of the position | 305 | // Force an update of the position |
306 | mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); | 306 | mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); |
307 | mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); | 307 | mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); |
308 | // Just like we never stopped | 308 | // Just like we never stopped |
309 | startTimers(); | 309 | startTimers(); |
310 | } | 310 | } |
311 | } | 311 | } |
312 | 312 | ||
313 | 313 | ||
314 | void LoopControl::stop( bool willPlayAgainShortly ) { | 314 | void LoopControl::stop( bool willPlayAgainShortly ) { |
315 | 315 | ||
316 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 316 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
317 | if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) { | 317 | if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) { |
318 | disabledSuspendScreenSaver = FALSE; | 318 | disabledSuspendScreenSaver = FALSE; |
319 | // Re-enable the suspend mode | 319 | // Re-enable the suspend mode |
320 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; | 320 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; |
321 | } | 321 | } |
322 | #endif | 322 | #endif |
323 | 323 | ||
324 | if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) { | 324 | if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) { |
325 | 325 | ||
326 | killTimers(); | 326 | killTimers(); |
327 | 327 | ||
328 | audioMutex->lock(); | 328 | audioMutex->lock(); |
329 | 329 | ||
330 | mediaPlayerState->curDecoder()->close(); | 330 | mediaPlayerState->curDecoder()->close(); |
331 | 331 | ||
332 | if ( audioDevice ) { | 332 | if ( audioDevice ) { |
333 | delete audioDevice; | 333 | delete audioDevice; |
334 | delete audioBuffer; | 334 | delete audioBuffer; |
335 | audioDevice = 0; | 335 | audioDevice = 0; |
336 | audioBuffer = 0; | 336 | audioBuffer = 0; |
337 | } | 337 | } |
338 | 338 | ||
339 | audioMutex->unlock(); | 339 | audioMutex->unlock(); |
340 | 340 | ||
341 | } | 341 | } |
342 | } | 342 | } |
343 | 343 | ||
344 | 344 | ||
345 | bool LoopControl::init( const QString& filename ) { | 345 | bool LoopControl::init( const QString& filename ) { |
346 | stop(); | 346 | stop(); |
347 | 347 | ||
348 | audioMutex->lock(); | 348 | audioMutex->lock(); |
349 | 349 | ||
350 | fileName = filename; | 350 | fileName = filename; |
351 | stream = 0; // only play stream 0 for now | 351 | stream = 0; // only play stream 0 for now |
352 | current_frame = total_video_frames = total_audio_samples = 0; | 352 | current_frame = total_video_frames = total_audio_samples = 0; |
353 | 353 | ||
354 | qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); | 354 | qDebug( "Using the %s decoder", mediaPlayerState->curDecoder()->pluginName() ); |
355 | 355 | ||
356 | // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin | 356 | // ### Hack to use libmpeg3plugin to get the number of audio samples if we are using the libmad plugin |
357 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { | 357 | if ( mediaPlayerState->curDecoder()->pluginName() == QString("LibMadPlugin") ) { |
358 | if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) { | 358 | if ( mediaPlayerState->libMpeg3Decoder() && mediaPlayerState->libMpeg3Decoder()->open( filename ) ) { |
359 | total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); | 359 | total_audio_samples = mediaPlayerState->libMpeg3Decoder()->audioSamples( 0 ); |
360 | mediaPlayerState->libMpeg3Decoder()->close(); | 360 | mediaPlayerState->libMpeg3Decoder()->close(); |
361 | } | 361 | } |
362 | } | 362 | } |
363 | 363 | ||
364 | if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) { | 364 | if ( !mediaPlayerState->curDecoder()|| !mediaPlayerState->curDecoder()->open( filename ) ) { |
365 | audioMutex->unlock(); | 365 | audioMutex->unlock(); |
366 | return FALSE; | 366 | return FALSE; |
367 | } | 367 | } |
368 | 368 | ||
369 | hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0; | 369 | hasAudioChannel = mediaPlayerState->curDecoder()->audioStreams() > 0; |
370 | hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0; | 370 | hasVideoChannel = mediaPlayerState->curDecoder()->videoStreams() > 0; |
371 | 371 | ||
372 | if ( hasAudioChannel ) { | 372 | if ( hasAudioChannel ) { |
373 | int astream = 0; | 373 | int astream = 0; |
374 | 374 | ||
375 | channels = mediaPlayerState->curDecoder()->audioChannels( astream ); | 375 | channels = mediaPlayerState->curDecoder()->audioChannels( astream ); |
376 | DecodeLoopDebug(( "channels = %d\n", channels )); | 376 | DecodeLoopDebug(( "channels = %d\n", channels )); |
377 | 377 | ||
378 | if ( !total_audio_samples ) | 378 | if ( !total_audio_samples ) |
379 | total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); | 379 | total_audio_samples = mediaPlayerState->curDecoder()->audioSamples( astream ); |
380 | 380 | ||
381 | total_audio_samples += 1000; | 381 | total_audio_samples += 1000; |
382 | 382 | ||
383 | mediaPlayerState->setLength( total_audio_samples ); | 383 | mediaPlayerState->setLength( total_audio_samples ); |
384 | 384 | ||
385 | freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); | 385 | freq = mediaPlayerState->curDecoder()->audioFrequency( astream ); |
386 | DecodeLoopDebug(( "frequency = %d\n", freq )); | 386 | DecodeLoopDebug(( "frequency = %d\n", freq )); |
387 | 387 | ||
388 | audioSampleCounter = 0; | 388 | audioSampleCounter = 0; |
389 | 389 | ||
390 | static const int bytes_per_sample = 2; //16 bit | 390 | static const int bytes_per_sample = 2; //16 bit |
391 | 391 | ||
392 | audioDevice = new AudioDevice( freq, channels, bytes_per_sample ); | 392 | audioDevice = new AudioDevice( freq, channels, bytes_per_sample ); |
393 | audioBuffer = new char[ audioDevice->bufferSize() ]; | 393 | audioBuffer = new char[ audioDevice->bufferSize() ]; |
394 | channels = audioDevice->channels(); | 394 | channels = audioDevice->channels(); |
395 | 395 | ||
396 | //### must check which frequency is actually used. | 396 | //### must check which frequency is actually used. |
397 | static const int size = 1; | 397 | static const int size = 1; |
398 | short int buf[size]; | 398 | short int buf[size]; |
399 | long samplesRead = 0; | 399 | long samplesRead = 0; |
400 | mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); | 400 | mediaPlayerState->curDecoder()->audioReadSamples( buf, channels, size, samplesRead, stream ); |
401 | } | 401 | } |
402 | 402 | ||
403 | if ( hasVideoChannel ) { | 403 | if ( hasVideoChannel ) { |
404 | total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream ); | 404 | total_video_frames = mediaPlayerState->curDecoder()->videoFrames( stream ); |
405 | 405 | ||
406 | mediaPlayerState->setLength( total_video_frames ); | 406 | mediaPlayerState->setLength( total_video_frames ); |
407 | 407 | ||
408 | framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream ); | 408 | framerate = mediaPlayerState->curDecoder()->videoFrameRate( stream ); |
409 | DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames )); | 409 | DecodeLoopDebug(( "Frame rate %g total %ld", framerate, total_video_frames )); |
410 | 410 | ||
411 | if ( framerate <= 1.0 ) { | 411 | if ( framerate <= 1.0 ) { |
412 | DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" )); | 412 | DecodeLoopDebug(( "Crazy frame rate, resetting to sensible" )); |
413 | framerate = 25; | 413 | framerate = 25; |
414 | } | 414 | } |
415 | 415 | ||
416 | if ( total_video_frames == 1 ) { | 416 | if ( total_video_frames == 1 ) { |
417 | DecodeLoopDebug(( "Cannot seek to frame" )); | 417 | DecodeLoopDebug(( "Cannot seek to frame" )); |
418 | } | 418 | } |
419 | 419 | ||
420 | } | 420 | } |
421 | 421 | ||
422 | current_frame = 0; | 422 | current_frame = 0; |
423 | prev_frame = -1; | 423 | prev_frame = -1; |
424 | 424 | ||
425 | connect( mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( setPosition( long ) ) ); | 425 | connect( mediaPlayerState, SIGNAL( positionChanged( long ) ), this, SLOT( setPosition( long ) ) ); |
426 | connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( setPaused( bool ) ) ); | 426 | connect( mediaPlayerState, SIGNAL( pausedToggled( bool ) ), this, SLOT( setPaused( bool ) ) ); |
427 | 427 | ||
428 | audioMutex->unlock(); | 428 | audioMutex->unlock(); |
429 | 429 | ||
430 | return TRUE; | 430 | return TRUE; |
431 | } | 431 | } |
432 | 432 | ||
433 | 433 | ||
434 | void LoopControl::play() { | 434 | void LoopControl::play() { |
435 | 435 | ||
436 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | 436 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) |
437 | if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) { | 437 | if ( !disabledSuspendScreenSaver || previousSuspendMode != hasVideoChannel ) { |
438 | disabledSuspendScreenSaver = TRUE; | 438 | disabledSuspendScreenSaver = TRUE; |
diff --git a/core/multimedia/opieplayer/wavplugin/wavplugin.cpp b/core/multimedia/opieplayer/wavplugin/wavplugin.cpp index 60a0024..a6bd974 100644 --- a/core/multimedia/opieplayer/wavplugin/wavplugin.cpp +++ b/core/multimedia/opieplayer/wavplugin/wavplugin.cpp | |||
@@ -134,201 +134,201 @@ public: | |||
134 | #define WAVE_FORMAT_PCM 1 | 134 | #define WAVE_FORMAT_PCM 1 |
135 | if ( chunkdata.formatTag != WAVE_FORMAT_PCM ) { | 135 | if ( chunkdata.formatTag != WAVE_FORMAT_PCM ) { |
136 | qDebug("WAV file: UNSUPPORTED FORMAT %d",chunkdata.formatTag); | 136 | qDebug("WAV file: UNSUPPORTED FORMAT %d",chunkdata.formatTag); |
137 | return FALSE; | 137 | return FALSE; |
138 | } | 138 | } |
139 | } else { | 139 | } else { |
140 | // ignored chunk | 140 | // ignored chunk |
141 | if ( chunk.size > 1000000000 || !input->at(input->at()+chunk.size) ) { | 141 | if ( chunk.size > 1000000000 || !input->at(input->at()+chunk.size) ) { |
142 | return FALSE; | 142 | return FALSE; |
143 | } | 143 | } |
144 | } | 144 | } |
145 | } // while | 145 | } // while |
146 | 146 | ||
147 | return TRUE; | 147 | return TRUE; |
148 | } | 148 | } |
149 | 149 | ||
150 | 150 | ||
151 | // gets a sample from the file | 151 | // gets a sample from the file |
152 | bool getSample(int& l, int& r) | 152 | bool getSample(int& l, int& r) |
153 | { | 153 | { |
154 | l = r = 0; | 154 | l = r = 0; |
155 | 155 | ||
156 | if ( input == 0 ) | 156 | if ( input == 0 ) |
157 | return FALSE; | 157 | return FALSE; |
158 | 158 | ||
159 | if ( (wavedata_remaining < 0) || !max ) | 159 | if ( (wavedata_remaining < 0) || !max ) |
160 | return FALSE; | 160 | return FALSE; |
161 | 161 | ||
162 | if ( out >= max ) { | 162 | if ( out >= max ) { |
163 | max = input->readBlock( (char*)data, (uint)QMIN(sound_buffer_size,wavedata_remaining) ); | 163 | max = input->readBlock( (char*)data, (uint)QMIN(sound_buffer_size,wavedata_remaining) ); |
164 | 164 | ||
165 | wavedata_remaining -= max; | 165 | wavedata_remaining -= max; |
166 | 166 | ||
167 | out = 0; | 167 | out = 0; |
168 | if ( max <= 0 ) { | 168 | if ( max <= 0 ) { |
169 | max = 0; | 169 | max = 0; |
170 | return TRUE; | 170 | return TRUE; |
171 | } | 171 | } |
172 | } | 172 | } |
173 | if ( chunkdata.wBitsPerSample == 8 ) { | 173 | if ( chunkdata.wBitsPerSample == 8 ) { |
174 | l = (data[out++] - 128) * 128; | 174 | l = (data[out++] - 128) * 128; |
175 | } else { | 175 | } else { |
176 | l = ((short*)data)[out/2]; | 176 | l = ((short*)data)[out/2]; |
177 | out += 2; | 177 | out += 2; |
178 | } | 178 | } |
179 | if ( chunkdata.channels == 1 ) { | 179 | if ( chunkdata.channels == 1 ) { |
180 | r = l; | 180 | r = l; |
181 | } else { | 181 | } else { |
182 | if ( chunkdata.wBitsPerSample == 8 ) { | 182 | if ( chunkdata.wBitsPerSample == 8 ) { |
183 | r = (data[out++] - 128) * 128; | 183 | r = (data[out++] - 128) * 128; |
184 | } else { | 184 | } else { |
185 | r = ((short*)data)[out/2]; | 185 | r = ((short*)data)[out/2]; |
186 | out += 2; | 186 | out += 2; |
187 | } | 187 | } |
188 | } | 188 | } |
189 | return TRUE; | 189 | return TRUE; |
190 | } // getSample | 190 | } // getSample |
191 | 191 | ||
192 | }; | 192 | }; |
193 | 193 | ||
194 | 194 | ||
195 | WavPlugin::WavPlugin() { | 195 | WavPlugin::WavPlugin() { |
196 | d = new WavPluginData; | 196 | d = new WavPluginData; |
197 | d->input = 0; | 197 | d->input = 0; |
198 | } | 198 | } |
199 | 199 | ||
200 | 200 | ||
201 | WavPlugin::~WavPlugin() { | 201 | WavPlugin::~WavPlugin() { |
202 | close(); | 202 | close(); |
203 | delete d; | 203 | delete d; |
204 | } | 204 | } |
205 | 205 | ||
206 | 206 | ||
207 | bool WavPlugin::isFileSupported( const QString& path ) { | 207 | bool WavPlugin::isFileSupported( const QString& path ) { |
208 | debugMsg( "WavPlugin::isFileSupported" ); | 208 | debugMsg( "WavPlugin::isFileSupported" ); |
209 | 209 | ||
210 | char *ext = strrchr( path.latin1(), '.' ); | 210 | char *ext = strrchr( path.latin1(), '.' ); |
211 | 211 | ||
212 | // Test file extension | 212 | // Test file extension |
213 | if ( ext ) { | 213 | if ( ext ) { |
214 | if ( strncasecmp(ext, ".raw", 4) == 0 ) | 214 | if ( strncasecmp(ext, ".raw", 4) == 0 ) |
215 | return TRUE; | 215 | return TRUE; |
216 | if ( strncasecmp(ext, ".wav", 4) == 0 ) | 216 | if ( strncasecmp(ext, ".wav", 4) == 0 ) |
217 | return TRUE; | 217 | return TRUE; |
218 | if ( strncasecmp(ext, ".wave", 4) == 0 ) | 218 | if ( strncasecmp(ext, ".wave", 4) == 0 ) |
219 | return TRUE; | 219 | return TRUE; |
220 | } | 220 | } |
221 | 221 | ||
222 | return FALSE; | 222 | return FALSE; |
223 | } | 223 | } |
224 | 224 | ||
225 | 225 | ||
226 | bool WavPlugin::open( const QString& path ) { | 226 | bool WavPlugin::open( const QString& path ) { |
227 | debugMsg( "WavPlugin::open" ); | 227 | debugMsg( "WavPlugin::open" ); |
228 | 228 | ||
229 | d->max = d->out = sound_buffer_size; | 229 | d->max = d->out = sound_buffer_size; |
230 | d->wavedata_remaining = 0; | 230 | d->wavedata_remaining = 0; |
231 | d->samples_due = 0; | 231 | d->samples_due = 0; |
232 | 232 | ||
233 | d->input = new QFile( path ); | 233 | d->input = new QFile( path ); |
234 | if ( d->input->open(IO_ReadOnly) == FALSE ) { | 234 | if ( d->input->open(IO_ReadOnly) == FALSE ) { |
235 | qDebug("couldn't open file"); | 235 | qDebug("couldn't open file"); |
236 | delete d->input; | 236 | delete d->input; |
237 | d->input = 0; | 237 | d->input = 0; |
238 | return FALSE; | 238 | return FALSE; |
239 | } | 239 | } |
240 | 240 | ||
241 | d->initialise(); | 241 | d->initialise(); |
242 | 242 | ||
243 | return TRUE; | 243 | return TRUE; |
244 | } | 244 | } |
245 | 245 | ||
246 | 246 | ||
247 | bool WavPlugin::close() { | 247 | bool WavPlugin::close() { |
248 | debugMsg( "WavPlugin::close" ); | 248 | debugMsg( "WavPlugin::close" ); |
249 | 249 | ||
250 | d->input->close(); | 250 | d->input->close(); |
251 | delete d->input; | 251 | delete d->input; |
252 | d->input = 0; | 252 | d->input = 0; |
253 | return TRUE; | 253 | return TRUE; |
254 | } | 254 | } |
255 | 255 | ||
256 | 256 | ||
257 | bool WavPlugin::isOpen() { | 257 | bool WavPlugin::isOpen() { |
258 | debugMsg( "WavPlugin::isOpen" ); | 258 | debugMsg( "WavPlugin::isOpen" ); |
259 | return ( d->input != 0 ); | 259 | return ( d->input != 0 ); |
260 | } | 260 | } |
261 | 261 | ||
262 | 262 | ||
263 | int WavPlugin::audioStreams() { | 263 | int WavPlugin::audioStreams() { |
264 | debugMsg( "WavPlugin::audioStreams" ); | 264 | debugMsg( "WavPlugin::audioStreams" ); |
265 | return 1; | 265 | return 1; |
266 | } | 266 | } |
267 | 267 | ||
268 | 268 | ||
269 | int WavPlugin::audioChannels( int ) { | 269 | int WavPlugin::audioChannels( int ) { |
270 | debugMsg( "WavPlugin::audioChannels" ); | 270 | debugMsg( "WavPlugin::audioChannels" ); |
271 | return 2; // ### Always scale audio to stereo samples | 271 | return 2; // ### Always scale audio to stereo samples |
272 | } | 272 | } |
273 | 273 | ||
274 | 274 | ||
275 | int WavPlugin::audioFrequency( int ) { | 275 | int WavPlugin::audioFrequency( int ) { |
276 | debugMsg( "WavPlugin::audioFrequency" ); | 276 | debugMsg( "WavPlugin::audioFrequency" ); |
277 | return 44100; // ### Always scale to frequency of 44100 | 277 | return 44100; // ### Always scale to frequency of 44100 |
278 | } | 278 | } |
279 | 279 | ||
280 | 280 | ||
281 | int WavPlugin::audioSamples( int ) { | 281 | int WavPlugin::audioSamples( int ) { |
282 | debugMsg( "WavPlugin::audioSamples" ); | 282 | debugMsg( "WavPlugin::audioSamples" ); |
283 | return d->samples * 2 / d->chunkdata.channels; // ### Scaled samples will be made stereo, | 283 | return d->samples * 2 / d->chunkdata.channels; // ### Scaled samples will be made stereo, |
284 | // Therefore if source is mono we will double the number of samples | 284 | // Therefore if source is mono we will double the number of samples |
285 | } | 285 | } |
286 | 286 | ||
287 | 287 | ||
288 | bool WavPlugin::audioSetSample( long, int ) { | 288 | bool WavPlugin::audioSetSample( long, int ) { |
289 | debugMsg( "WavPlugin::audioSetSample" ); | 289 | debugMsg( "WavPlugin::audioSetSample" ); |
290 | return FALSE; | 290 | return FALSE; |
291 | } | 291 | } |
292 | 292 | ||
293 | 293 | ||
294 | long WavPlugin::audioGetSample( int ) { | 294 | long WavPlugin::audioGetSample( int ) { |
295 | debugMsg( "WavPlugin::audioGetSample" ); | 295 | debugMsg( "WavPlugin::audioGetSample" ); |
296 | return 0; | 296 | return 0; |
297 | } | 297 | } |
298 | 298 | ||
299 | /* | 299 | /* |
300 | bool WavPlugin::audioReadSamples( short *, int, long, int ) { | 300 | bool WavPlugin::audioReadSamples( short *, int, long, int ) { |
301 | debugMsg( "WavPlugin::audioReadSamples" ); | 301 | debugMsg( "WavPlugin::audioReadSamples" ); |
302 | return FALSE; | 302 | return FALSE; |
303 | } | 303 | } |
304 | 304 | ||
305 | 305 | ||
306 | bool WavPlugin::audioReReadSamples( short *, int, long, int ) { | 306 | bool WavPlugin::audioReReadSamples( short *, int, long, int ) { |
307 | debugMsg( "WavPlugin::audioReReadSamples" ); | 307 | debugMsg( "WavPlugin::audioReReadSamples" ); |
308 | return FALSE; | 308 | return FALSE; |
309 | } | 309 | } |
310 | 310 | ||
311 | 311 | ||
312 | bool WavPlugin::audioReadMonoSamples( short *output, long samples, long& samplesMade, int ) { | 312 | bool WavPlugin::audioReadMonoSamples( short *output, long samples, long& samplesMade, int ) { |
313 | debugMsg( "WavPlugin::audioReadMonoSamples" ); | 313 | debugMsg( "WavPlugin::audioReadMonoSamples" ); |
314 | return !d->add( output, samples, samplesMade, FALSE ); | 314 | return !d->add( output, samples, samplesMade, FALSE ); |
315 | } | 315 | } |
316 | 316 | ||
317 | 317 | ||
318 | bool WavPlugin::audioReadStereoSamples( short *output, long samples, long& samplesMade, int ) { | 318 | bool WavPlugin::audioReadStereoSamples( short *output, long samples, long& samplesMade, int ) { |
319 | debugMsg( "WavPlugin::audioReadStereoSamples" ); | 319 | debugMsg( "WavPlugin::audioReadStereoSamples" ); |
320 | return !d->add( output, samples, samplesMade, TRUE ); | 320 | return !d->add( output, samples, samplesMade, TRUE ); |
321 | } | 321 | } |
322 | */ | 322 | */ |
323 | 323 | ||
324 | bool WavPlugin::audioReadSamples( short *output, int channels, long samples, long& samplesMade, int ) { | 324 | bool WavPlugin::audioReadSamples( short *output, int channels, long samples, long& samplesMade, int ) { |
325 | debugMsg( "WavPlugin::audioReadSamples" ); | 325 | debugMsg( "WavPlugin::audioReadSamples" ); |
326 | return !d->add( output, samples, samplesMade, channels != 1 ); | 326 | return d->add( output, samples, samplesMade, channels != 1 ); |
327 | } | 327 | } |
328 | 328 | ||
329 | double WavPlugin::getTime() { | 329 | double WavPlugin::getTime() { |
330 | debugMsg( "WavPlugin::getTime" ); | 330 | debugMsg( "WavPlugin::getTime" ); |
331 | return 0.0; | 331 | return 0.0; |
332 | } | 332 | } |
333 | 333 | ||
334 | 334 | ||