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