summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/libmad/libmadplugin.cpp
Unidiff
Diffstat (limited to 'core/multimedia/opieplayer/libmad/libmadplugin.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/multimedia/opieplayer/libmad/libmadplugin.cpp72
1 files changed, 34 insertions, 38 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
@@ -19,18 +19,6 @@
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>
@@ -46,6 +34,12 @@
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>
@@ -60,6 +54,7 @@
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
65extern "C" { 60extern "C" {
@@ -387,7 +382,7 @@ int LibMadPlugin::http_open(const QString& path ) {
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
@@ -401,7 +396,7 @@ int LibMadPlugin::http_open(const QString& path ) {
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-") {
@@ -422,7 +417,7 @@ int LibMadPlugin::http_open(const QString& path ) {
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}
@@ -434,12 +429,12 @@ bool LibMadPlugin::open( const QString& path ) {
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
@@ -455,13 +450,13 @@ bool LibMadPlugin::open( const QString& path ) {
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;
@@ -473,7 +468,7 @@ bool LibMadPlugin::open( const QString& path ) {
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 }
@@ -482,7 +477,7 @@ bool LibMadPlugin::open( const QString& path ) {
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;
@@ -510,7 +505,7 @@ bool LibMadPlugin::close() {
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;
@@ -524,7 +519,7 @@ bool LibMadPlugin::close() {
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
@@ -550,7 +545,7 @@ 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;
@@ -560,7 +555,7 @@ int LibMadPlugin::audioChannels( int ) {
560int LibMadPlugin::audioFrequency( int ) { 555int 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
@@ -571,16 +566,17 @@ int LibMadPlugin::audioSamples( int ) {
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
@@ -596,7 +592,7 @@ bool LibMadPlugin::audioSetSample( long, int ) {
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
@@ -684,7 +680,7 @@ bool LibMadPlugin::read() {
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) {
@@ -762,7 +758,7 @@ bool LibMadPlugin::decode( short *output, long samples, long& samplesMade ) {
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
@@ -825,17 +821,17 @@ double LibMadPlugin::getTime() {
825 821
826 822
827void LibMadPlugin::printID3Tags() { 823void 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
@@ -845,7 +841,7 @@ void LibMadPlugin::printID3Tags() {
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;
@@ -857,7 +853,7 @@ void LibMadPlugin::printID3Tags() {
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 }
@@ -866,7 +862,7 @@ void LibMadPlugin::printID3Tags() {
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}