Diffstat (limited to 'core/multimedia/opieplayer/libmad/libmadplugin.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/libmad/libmadplugin.cpp | 74 |
1 files changed, 35 insertions, 39 deletions
diff --git a/core/multimedia/opieplayer/libmad/libmadplugin.cpp b/core/multimedia/opieplayer/libmad/libmadplugin.cpp index 7438a45..1989b4a 100644 --- a/core/multimedia/opieplayer/libmad/libmadplugin.cpp +++ b/core/multimedia/opieplayer/libmad/libmadplugin.cpp | |||
@@ -18,20 +18,8 @@ | |||
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | // largly modified by Maximilian Reiss <max.reiss@gmx.de> | 20 | // largly modified by Maximilian Reiss <max.reiss@gmx.de> |
21 | 21 | ||
22 | #include "libmadplugin.h" | ||
23 | |||
24 | /* OPIE */ | ||
25 | #include <qpe/config.h> | ||
26 | #include <opie2/odebug.h> | ||
27 | |||
28 | /* QT */ | ||
29 | #include <qapplication.h> | ||
30 | #include <qmessagebox.h> | ||
31 | #include <qregexp.h> | ||
32 | |||
33 | /* STD */ | ||
34 | #include <stdio.h> | 22 | #include <stdio.h> |
35 | #include <stdarg.h> | 23 | #include <stdarg.h> |
36 | #include <stdlib.h> | 24 | #include <stdlib.h> |
37 | #include <sys/types.h> | 25 | #include <sys/types.h> |
@@ -45,8 +33,14 @@ | |||
45 | #include <locale.h> | 33 | #include <locale.h> |
46 | #include <math.h> | 34 | #include <math.h> |
47 | #include <assert.h> | 35 | #include <assert.h> |
48 | 36 | ||
37 | #include <qapplication.h> | ||
38 | #include <qmessagebox.h> | ||
39 | #include <qregexp.h> | ||
40 | |||
41 | #include <qpe/config.h> | ||
42 | |||
49 | // for network handling | 43 | // for network handling |
50 | #include <netinet/in.h> | 44 | #include <netinet/in.h> |
51 | #include <netdb.h> | 45 | #include <netdb.h> |
52 | #include <linux/limits.h> | 46 | #include <linux/limits.h> |
@@ -59,8 +53,9 @@ | |||
59 | 53 | ||
60 | #if defined(HAVE_MMAP) | 54 | #if defined(HAVE_MMAP) |
61 | # include <sys/mman.h> | 55 | # include <sys/mman.h> |
62 | #endif | 56 | #endif |
57 | #include "libmadplugin.h" | ||
63 | 58 | ||
64 | 59 | ||
65 | extern "C" { | 60 | extern "C" { |
66 | #include "mad.h" | 61 | #include "mad.h" |
@@ -386,9 +381,9 @@ int LibMadPlugin::http_open(const QString& path ) { | |||
386 | 381 | ||
387 | len = http_read_line(tcp_sock, http_request, sizeof(http_request)); | 382 | len = http_read_line(tcp_sock, http_request, sizeof(http_request)); |
388 | 383 | ||
389 | if (len == -1) { | 384 | if (len == -1) { |
390 | // odebug << "http_open: "+ QString(strerror(errno)) +"\n" << oendl; | 385 | // qDebug( "http_open: "+ QString(strerror(errno)) +"\n"); |
391 | return 0; | 386 | return 0; |
392 | } | 387 | } |
393 | 388 | ||
394 | if (QString(http_request).left(9) == "Location:") { | 389 | if (QString(http_request).left(9) == "Location:") { |
@@ -400,9 +395,9 @@ int LibMadPlugin::http_open(const QString& path ) { | |||
400 | 395 | ||
401 | if (QString(http_request).left(4) == "ICY ") { | 396 | if (QString(http_request).left(4) == "ICY ") { |
402 | /* This is shoutcast/icecast streaming */ | 397 | /* This is shoutcast/icecast streaming */ |
403 | if (strncmp(http_request + 4, "200 ", 4)) { | 398 | if (strncmp(http_request + 4, "200 ", 4)) { |
404 | // odebug << "http_open: " + QString(http_request) + "\n" << oendl; | 399 | // qDebug("http_open: " + QString(http_request) + "\n"); |
405 | return 0; | 400 | return 0; |
406 | } | 401 | } |
407 | } else if (QString(http_request).left(4) == "icy-") { | 402 | } else if (QString(http_request).left(4) == "icy-") { |
408 | /* we can have: icy-noticeX, icy-name, icy-genre, icy-url, icy-pub, icy-metaint, icy-br */ | 403 | /* we can have: icy-noticeX, icy-name, icy-genre, icy-url, icy-pub, icy-metaint, icy-br */ |
@@ -421,9 +416,9 @@ int LibMadPlugin::http_open(const QString& path ) { | |||
421 | } while (strcmp(http_request, "\n") != 0); | 416 | } while (strcmp(http_request, "\n") != 0); |
422 | 417 | ||
423 | info = QString(name + genre + url + bitrate + message).replace( QRegExp("\n"), " : " ); | 418 | info = QString(name + genre + url + bitrate + message).replace( QRegExp("\n"), " : " ); |
424 | 419 | ||
425 | // odebug << "Stream info: " + info << oendl; | 420 | // qDebug("Stream info: " + info); |
426 | 421 | ||
427 | return (tcp_sock); | 422 | return (tcp_sock); |
428 | } | 423 | } |
429 | 424 | ||
@@ -433,14 +428,14 @@ bool LibMadPlugin::open( const QString& path ) { | |||
433 | debugMsg( "LibMadPlugin::open" ); | 428 | debugMsg( "LibMadPlugin::open" ); |
434 | Config cfg("OpiePlayer"); | 429 | Config cfg("OpiePlayer"); |
435 | cfg.setGroup("Options"); | 430 | cfg.setGroup("Options"); |
436 | bufferSize = cfg.readNumEntry("MPeg_BufferSize",MPEG_BUFFER_SIZE); | 431 | bufferSize = cfg.readNumEntry("MPeg_BufferSize",MPEG_BUFFER_SIZE); |
437 | // odebug << "buffer size is " << bufferSize << "" << oendl; | 432 | // qDebug("buffer size is %d", bufferSize); |
438 | d->bad_last_frame = 0; | 433 | d->bad_last_frame = 0; |
439 | d->flush = TRUE; | 434 | d->flush = TRUE; |
440 | info = QString( "" ); | 435 | info = QString( "" ); |
441 | 436 | ||
442 | //odebug << "Opening " << path << "" << oendl; | 437 | //qDebug( "Opening %s", path.latin1() ); |
443 | 438 | ||
444 | if (path.left( 4 ) == "http" ) { | 439 | if (path.left( 4 ) == "http" ) { |
445 | // in case of any error we get 0 here | 440 | // in case of any error we get 0 here |
446 | if ( !(http_open(path) == 0) ) { | 441 | if ( !(http_open(path) == 0) ) { |
@@ -454,36 +449,36 @@ bool LibMadPlugin::open( const QString& path ) { | |||
454 | // thats a better place, since it should only seek for ID3 tags on mp3 files, not streams | 449 | // thats a better place, since it should only seek for ID3 tags on mp3 files, not streams |
455 | printID3Tags(); | 450 | printID3Tags(); |
456 | } | 451 | } |
457 | if (d->input.fd == -1) { | 452 | if (d->input.fd == -1) { |
458 | // odebug << "error opening " << d->input.path << "" << oendl; | 453 | // qDebug("error opening %s", d->input.path ); |
459 | return FALSE; | 454 | return FALSE; |
460 | } | 455 | } |
461 | 456 | ||
462 | struct stat stat; | 457 | struct stat stat; |
463 | if (fstat(d->input.fd, &stat) == -1) { | 458 | if (fstat(d->input.fd, &stat) == -1) { |
464 | // odebug << "error calling fstat" << oendl; return FALSE; | 459 | // qDebug("error calling fstat"); return FALSE; |
465 | } | 460 | } |
466 | if (S_ISREG(stat.st_mode) && stat.st_size > 0) | 461 | if (S_ISREG(stat.st_mode) && stat.st_size > 0) |
467 | d->input.fileLength = stat.st_size; | 462 | d->input.fileLength = stat.st_size; |
468 | else | 463 | else |
469 | d->input.fileLength = 0; | 464 | d->input.fileLength = 0; |
470 | 465 | ||
471 | #if defined(HAVE_MMAP) | 466 | #if defined(HAVE_MMAP) |
472 | if (S_ISREG(stat.st_mode) && stat.st_size > 0) { | 467 | if (S_ISREG(stat.st_mode) && stat.st_size > 0) { |
473 | d->input.length = stat.st_size; | 468 | d->input.length = stat.st_size; |
474 | d->input.fdm = map_file(d->input.fd, &d->input.length); | 469 | d->input.fdm = map_file(d->input.fd, &d->input.length); |
475 | if (d->input.fdm == 0) { | 470 | if (d->input.fdm == 0) { |
476 | // odebug << "error mmapping file" << oendl; return FALSE; | 471 | // qDebug("error mmapping file"); return FALSE; |
477 | } | 472 | } |
478 | d->input.data = (unsigned char *)d->input.fdm; | 473 | d->input.data = (unsigned char *)d->input.fdm; |
479 | } | 474 | } |
480 | #endif | 475 | #endif |
481 | 476 | ||
482 | if (d->input.data == 0) { | 477 | if (d->input.data == 0) { |
483 | d->input.data = (unsigned char *)malloc( bufferSize /*MPEG_BUFFER_SIZE*/); | 478 | d->input.data = (unsigned char *)malloc( bufferSize /*MPEG_BUFFER_SIZE*/); |
484 | if (d->input.data == 0) { | 479 | if (d->input.data == 0) { |
485 | // odebug << "error allocating input buffer" << oendl; | 480 | // qDebug("error allocating input buffer"); |
486 | return FALSE; | 481 | return FALSE; |
487 | } | 482 | } |
488 | d->input.length = 0; | 483 | d->input.length = 0; |
489 | } | 484 | } |
@@ -509,9 +504,9 @@ bool LibMadPlugin::close() { | |||
509 | 504 | ||
510 | #if defined(HAVE_MMAP) | 505 | #if defined(HAVE_MMAP) |
511 | if (d->input.fdm) { | 506 | if (d->input.fdm) { |
512 | if (unmap_file(d->input.fdm, d->input.length) == -1) { | 507 | if (unmap_file(d->input.fdm, d->input.length) == -1) { |
513 | // odebug << "error munmapping file" << oendl; | 508 | // qDebug("error munmapping file"); |
514 | result = FALSE; | 509 | result = FALSE; |
515 | } | 510 | } |
516 | d->input.fdm = 0; | 511 | d->input.fdm = 0; |
517 | d->input.data = 0; | 512 | d->input.data = 0; |
@@ -523,9 +518,9 @@ bool LibMadPlugin::close() { | |||
523 | d->input.data = 0; | 518 | d->input.data = 0; |
524 | } | 519 | } |
525 | 520 | ||
526 | if (::close(d->input.fd) == -1) { | 521 | if (::close(d->input.fd) == -1) { |
527 | // odebug << "error closing file " << d->input.path << "" << oendl; | 522 | // qDebug("error closing file %s", d->input.path); |
528 | result = FALSE; | 523 | result = FALSE; |
529 | } | 524 | } |
530 | 525 | ||
531 | d->input.fd = 0; | 526 | d->input.fd = 0; |
@@ -549,9 +544,9 @@ int LibMadPlugin::audioStreams() { | |||
549 | int LibMadPlugin::audioChannels( int ) { | 544 | int LibMadPlugin::audioChannels( int ) { |
550 | debugMsg( "LibMadPlugin::audioChannels" ); | 545 | debugMsg( "LibMadPlugin::audioChannels" ); |
551 | /* | 546 | /* |
552 | long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); | 547 | long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); |
553 | odebug << "LibMadPlugin::audioChannels: " << d->frame.header.mode > 0 ? 2 : 1 << "" << oendl; | 548 | qDebug( "LibMadPlugin::audioChannels: %i", d->frame.header.mode > 0 ? 2 : 1 ); |
554 | return d->frame.header.mode > 0 ? 2 : 1; | 549 | return d->frame.header.mode > 0 ? 2 : 1; |
555 | */ | 550 | */ |
556 | return 2; | 551 | return 2; |
557 | } | 552 | } |
@@ -559,9 +554,9 @@ int LibMadPlugin::audioChannels( int ) { | |||
559 | 554 | ||
560 | int LibMadPlugin::audioFrequency( int ) { | 555 | int LibMadPlugin::audioFrequency( int ) { |
561 | debugMsg( "LibMadPlugin::audioFrequency" ); | 556 | debugMsg( "LibMadPlugin::audioFrequency" ); |
562 | long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); | 557 | long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); |
563 | // odebug << "LibMadPlugin::audioFrequency: " << d->frame.header.samplerate << "" << oendl; | 558 | // qDebug( "LibMadPlugin::audioFrequency: %i", d->frame.header.samplerate ); |
564 | return d->frame.header.samplerate; | 559 | return d->frame.header.samplerate; |
565 | } | 560 | } |
566 | 561 | ||
567 | 562 | ||
@@ -570,18 +565,19 @@ int LibMadPlugin::audioSamples( int ) { | |||
570 | 565 | ||
571 | long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); | 566 | long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); |
572 | mad_header_decode( (struct mad_header *)&d->frame.header, &d->stream ); | 567 | mad_header_decode( (struct mad_header *)&d->frame.header, &d->stream ); |
573 | /* | 568 | /* |
574 | odebug << "LibMadPlugin::audioSamples: " << d->frame.header.duration.seconds << "*" << d->frame.header.samplerate << oendl; | 569 | qDebug( "LibMadPlugin::audioSamples: %i*%i", d->frame.header.duration.seconds, |
570 | d->frame.header.samplerate ); | ||
575 | return d->frame.header.duration.seconds * d->frame.header.samplerate; | 571 | return d->frame.header.duration.seconds * d->frame.header.samplerate; |
576 | */ | 572 | */ |
577 | if ( d->frame.header.bitrate == 0 ) | 573 | if ( d->frame.header.bitrate == 0 ) |
578 | return 0; | 574 | return 0; |
579 | int samples = (d->input.fileLength / (d->frame.header.bitrate/8)) * d->frame.header.samplerate; | 575 | int samples = (d->input.fileLength / (d->frame.header.bitrate/8)) * d->frame.header.samplerate; |
580 | 576 | ||
581 | // odebug << "LibMadPlugin::audioSamples: " << (int)d->input.fileLength | 577 | // qDebug( "LibMadPlugin::audioSamples: %i * %i * 8 / %i", (int)d->input.fileLength, |
582 | // << " * " << (int)d->frame.header.samplerate << " * 8 / " << (int)d->frame.header.bitrate << oendl; | 578 | // (int)d->frame.header.samplerate, (int)d->frame.header.bitrate ); |
583 | // odebug << "LibMadPlugin::audioSamples: " << samples << "" << oendl; | 579 | // qDebug( "LibMadPlugin::audioSamples: %i", samples ); |
584 | 580 | ||
585 | return samples; | 581 | return samples; |
586 | 582 | ||
587 | // return 10000000; | 583 | // return 10000000; |
@@ -595,9 +591,9 @@ bool LibMadPlugin::audioSetSample( long, int ) { | |||
595 | // if ( totalSamples <= 1 ) | 591 | // if ( totalSamples <= 1 ) |
596 | // return FALSE; | 592 | // return FALSE; |
597 | 593 | ||
598 | // // Seek to requested position | 594 | // // Seek to requested position |
599 | // odebug << "seek pos: " << (int)((double)pos * d->input.fileLength / totalSamples) << "" << oendl; | 595 | // qDebug( "seek pos: %i", (int)((double)pos * d->input.fileLength / totalSamples) ); |
600 | // ::lseek( d->input.fd, (long)((double)pos * d->input.fileLength / totalSamples), SEEK_SET ); | 596 | // ::lseek( d->input.fd, (long)((double)pos * d->input.fileLength / totalSamples), SEEK_SET ); |
601 | // mad_stream_sync(&d->stream); | 597 | // mad_stream_sync(&d->stream); |
602 | 598 | ||
603 | // mad_stream_init(&d->stream); | 599 | // mad_stream_init(&d->stream); |
@@ -683,9 +679,9 @@ bool LibMadPlugin::read() { | |||
683 | } | 679 | } |
684 | while (len == -1 && errno == EINTR); | 680 | while (len == -1 && errno == EINTR); |
685 | 681 | ||
686 | if (len == -1) { | 682 | if (len == -1) { |
687 | // odebug << "error reading audio" << oendl; | 683 | // qDebug("error reading audio"); |
688 | return FALSE; | 684 | return FALSE; |
689 | } | 685 | } |
690 | else if (len == 0) { | 686 | else if (len == 0) { |
691 | d->input.eof = 1; | 687 | d->input.eof = 1; |
@@ -761,9 +757,9 @@ bool LibMadPlugin::decode( short *output, long samples, long& samplesMade ) { | |||
761 | return FALSE; // Feed me | 757 | return FALSE; // Feed me |
762 | } | 758 | } |
763 | if ( d->stream.error == MAD_ERROR_BADCRC ) { | 759 | if ( d->stream.error == MAD_ERROR_BADCRC ) { |
764 | mad_frame_mute(&d->frame); | 760 | mad_frame_mute(&d->frame); |
765 | // odebug << "error decoding, bad crc" << oendl; | 761 | // qDebug( "error decoding, bad crc" ); |
766 | } | 762 | } |
767 | } | 763 | } |
768 | 764 | ||
769 | mad_synth_frame(&d->synth, &d->frame); | 765 | mad_synth_frame(&d->synth, &d->frame); |
@@ -824,19 +820,19 @@ double LibMadPlugin::getTime() { | |||
824 | } | 820 | } |
825 | 821 | ||
826 | 822 | ||
827 | void LibMadPlugin::printID3Tags() { | 823 | void LibMadPlugin::printID3Tags() { |
828 | // odebug << "LibMadPlugin::printID3Tags" << oendl; | 824 | // qDebug( "LibMadPlugin::printID3Tags" ); |
829 | 825 | ||
830 | char id3v1[128 + 1]; | 826 | char id3v1[128 + 1]; |
831 | 827 | ||
832 | if ( ::lseek( d->input.fd, -128, SEEK_END ) == -1 ) { | 828 | if ( ::lseek( d->input.fd, -128, SEEK_END ) == -1 ) { |
833 | // odebug << "error seeking to id3 tags" << oendl; | 829 | // qDebug( "error seeking to id3 tags" ); |
834 | return; | 830 | return; |
835 | } | 831 | } |
836 | 832 | ||
837 | if ( ::read( d->input.fd, id3v1, 128 ) != 128 ) { | 833 | if ( ::read( d->input.fd, id3v1, 128 ) != 128 ) { |
838 | // odebug << "error reading in id3 tags" << oendl; | 834 | // qDebug( "error reading in id3 tags" ); |
839 | return; | 835 | return; |
840 | } | 836 | } |
841 | 837 | ||
842 | if ( ::strncmp( (const char *)id3v1, "TAG", 3 ) != 0 ) { | 838 | if ( ::strncmp( (const char *)id3v1, "TAG", 3 ) != 0 ) { |
@@ -844,9 +840,9 @@ void LibMadPlugin::printID3Tags() { | |||
844 | } else { | 840 | } else { |
845 | int len[5] = { 30, 30, 30, 4, 30 }; | 841 | int len[5] = { 30, 30, 30, 4, 30 }; |
846 | QString label[5] = { tr( "Title" ), tr( "Artist" ), tr( "Album" ), tr( "Year" ), tr( "Comment" ) }; | 842 | QString label[5] = { tr( "Title" ), tr( "Artist" ), tr( "Album" ), tr( "Year" ), tr( "Comment" ) }; |
847 | char *ptr = id3v1 + 3, *ptr2 = ptr + len[0]; | 843 | char *ptr = id3v1 + 3, *ptr2 = ptr + len[0]; |
848 | // odebug << "ID3 tags in file:" << oendl; | 844 | // qDebug( "ID3 tags in file:" ); |
849 | info = ""; | 845 | info = ""; |
850 | for ( int i = 0; i < 5; ptr += len[i], i++, ptr2 += len[i] ) { | 846 | for ( int i = 0; i < 5; ptr += len[i], i++, ptr2 += len[i] ) { |
851 | char push = *ptr2; | 847 | char push = *ptr2; |
852 | *ptr2 = '\0'; | 848 | *ptr2 = '\0'; |
@@ -856,18 +852,18 @@ void LibMadPlugin::printID3Tags() { | |||
856 | if ( strcmp( ptr, "" ) ) { | 852 | if ( strcmp( ptr, "" ) ) { |
857 | if( ((QString)ptr).find(" ") == -1) // don't add anything that has blanks | 853 | if( ((QString)ptr).find(" ") == -1) // don't add anything that has blanks |
858 | info += ( i != 0 ? ", " : "" ) + label[i] + ": " + ptr; | 854 | info += ( i != 0 ? ", " : "" ) + label[i] + ": " + ptr; |
859 | } | 855 | } |
860 | // odebug << info.latin1() << oendl; | 856 | // qDebug( info.latin1() ); |
861 | *ptr3 = push2; | 857 | *ptr3 = push2; |
862 | *ptr2 = push; | 858 | *ptr2 = push; |
863 | } | 859 | } |
864 | if (id3v1[126] == 0 && id3v1[127] != 0) | 860 | if (id3v1[126] == 0 && id3v1[127] != 0) |
865 | info += tr( ", Track: " ) + id3v1[127]; | 861 | info += tr( ", Track: " ) + id3v1[127]; |
866 | } | 862 | } |
867 | 863 | ||
868 | if ( ::lseek(d->input.fd, 0, SEEK_SET) == -1 ) { | 864 | if ( ::lseek(d->input.fd, 0, SEEK_SET) == -1 ) { |
869 | // odebug << "error seeking back to beginning" << oendl; | 865 | // qDebug( "error seeking back to beginning" ); |
870 | return; | 866 | return; |
871 | } | 867 | } |
872 | } | 868 | } |
873 | 869 | ||