summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2003-02-25 23:36:47 (UTC)
committer llornkcor <llornkcor>2003-02-25 23:36:47 (UTC)
commitbde9ed97c92b6f7eefa8a66d9f58aa4c78127733 (patch) (unidiff)
tree4a74c6083acd5d89e191aaa3629040fb4449ff71
parent689847f2dcaabdfca266efd3c99c81b833bf6e9f (diff)
downloadopie-bde9ed97c92b6f7eefa8a66d9f58aa4c78127733.zip
opie-bde9ed97c92b6f7eefa8a66d9f58aa4c78127733.tar.gz
opie-bde9ed97c92b6f7eefa8a66d9f58aa4c78127733.tar.bz2
add proper number of samples reporting
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/libmad/libmadplugin.cpp52
1 files changed, 43 insertions, 9 deletions
diff --git a/core/multimedia/opieplayer/libmad/libmadplugin.cpp b/core/multimedia/opieplayer/libmad/libmadplugin.cpp
index 9a1ab2a..9d1ff8c 100644
--- a/core/multimedia/opieplayer/libmad/libmadplugin.cpp
+++ b/core/multimedia/opieplayer/libmad/libmadplugin.cpp
@@ -66,25 +66,26 @@ extern "C" {
66//#define MPEG_BUFFER_SIZE 32768 //16384 // 8192 66//#define MPEG_BUFFER_SIZE 32768 //16384 // 8192
67//#define debugMsg(a) qDebug(a) 67//#define debugMsg(a) qDebug(a)
68#define debugMsg(a) 68#define debugMsg(a)
69 69
70 70
71class Input { 71class Input {
72public: 72public:
73 char const *path; 73 char const *path;
74 int fd; 74 int fd;
75#if defined(HAVE_MMAP) 75#if defined(HAVE_MMAP)
76 void *fdm; 76 void *fdm;
77#endif 77#endif
78 unsigned char *data; 78 unsigned long fileLength;
79 unsigned char *data;
79 unsigned long length; 80 unsigned long length;
80 int eof; 81 int eof;
81}; 82};
82 83
83 84
84class Output { 85class Output {
85public: 86public:
86 mad_fixed_t attenuate; 87 mad_fixed_t attenuate;
87 struct filter *filters; 88 struct filter *filters;
88 unsigned int channels_in; 89 unsigned int channels_in;
89 unsigned int channels_out; 90 unsigned int channels_out;
90 unsigned int speed_in; 91 unsigned int speed_in;
@@ -444,29 +445,34 @@ bool LibMadPlugin::open( const QString& path ) {
444 } 445 }
445 } else { 446 } else {
446 d->input.path = path.latin1(); 447 d->input.path = path.latin1();
447 d->input.fd = ::open( d->input.path, O_RDONLY ); 448 d->input.fd = ::open( d->input.path, O_RDONLY );
448 // 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
449 printID3Tags(); 450 printID3Tags();
450 } 451 }
451 if (d->input.fd == -1) { 452 if (d->input.fd == -1) {
452 qDebug("error opening %s", d->input.path ); 453 qDebug("error opening %s", d->input.path );
453 return FALSE; 454 return FALSE;
454 } 455 }
455 456
456#if defined(HAVE_MMAP)
457 struct stat stat; 457 struct stat stat;
458 if (fstat(d->input.fd, &stat) == -1) { 458 if (fstat(d->input.fd, &stat) == -1) {
459 //qDebug("error calling fstat"); return FALSE; 459 qDebug("error calling fstat"); return FALSE;
460 } 460 }
461 if (S_ISREG(stat.st_mode) && stat.st_size > 0)
462 d->input.fileLength = stat.st_size;
463 else
464 d->input.fileLength = 0;
465
466#if defined(HAVE_MMAP)
461 if (S_ISREG(stat.st_mode) && stat.st_size > 0) { 467 if (S_ISREG(stat.st_mode) && stat.st_size > 0) {
462 d->input.length = stat.st_size; 468 d->input.length = stat.st_size;
463 d->input.fdm = map_file(d->input.fd, &d->input.length); 469 d->input.fdm = map_file(d->input.fd, &d->input.length);
464 if (d->input.fdm == 0) { 470 if (d->input.fdm == 0) {
465 qDebug("error mmapping file"); return FALSE; 471 qDebug("error mmapping file"); return FALSE;
466 } 472 }
467 d->input.data = (unsigned char *)d->input.fdm; 473 d->input.data = (unsigned char *)d->input.fdm;
468 } 474 }
469#endif 475#endif
470 476
471 if (d->input.data == 0) { 477 if (d->input.data == 0) {
472 d->input.data = (unsigned char *)malloc( bufferSize /*MPEG_BUFFER_SIZE*/); 478 d->input.data = (unsigned char *)malloc( bufferSize /*MPEG_BUFFER_SIZE*/);
@@ -546,37 +552,65 @@ int LibMadPlugin::audioChannels( int ) {
546} 552}
547 553
548 554
549int LibMadPlugin::audioFrequency( int ) { 555int LibMadPlugin::audioFrequency( int ) {
550 debugMsg( "LibMadPlugin::audioFrequency" ); 556 debugMsg( "LibMadPlugin::audioFrequency" );
551 long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); 557 long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 );
552 qDebug( "LibMadPlugin::audioFrequency: %i", d->frame.header.samplerate ); 558 qDebug( "LibMadPlugin::audioFrequency: %i", d->frame.header.samplerate );
553 return d->frame.header.samplerate; 559 return d->frame.header.samplerate;
554} 560}
555 561
556 562
557int LibMadPlugin::audioSamples( int ) { 563int LibMadPlugin::audioSamples( int ) {
558 debugMsg( "LibMadPlugin::audioSamples" ); 564 debugMsg( "LibMadPlugin::audioSamples" );
565
566 long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 );
567 mad_header_decode( (struct mad_header *)&d->frame.header, &d->stream );
568/*
569 qDebug( "LibMadPlugin::audioSamples: %i*%i", d->frame.header.duration.seconds,
570 d->frame.header.samplerate );
571 return d->frame.header.duration.seconds * d->frame.header.samplerate;
572*/
573 if ( d->frame.header.bitrate == 0 )
574 return 0;
575 int samples = (d->input.fileLength / (d->frame.header.bitrate/8)) * d->frame.header.samplerate;
576
577 qDebug( "LibMadPlugin::audioSamples: %i * %i * 8 / %i", (int)d->input.fileLength,
578 (int)d->frame.header.samplerate, (int)d->frame.header.bitrate );
579 qDebug( "LibMadPlugin::audioSamples: %i", samples );
559 580
560 // long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); 581 return samples;
561// mad_header_decode( (struct mad_header *)&d->frame.header, &d->stream );
562// qDebug( "LibMadPlugin::audioSamples: %i*%i", d->frame.header.duration.seconds, d->frame.header.samplerate );
563// return d->frame.header.duration.seconds * d->frame.header.samplerate;
564 582
565 return 10000000; 583// return 10000000;
566} 584}
567 585
568 586
569bool LibMadPlugin::audioSetSample( long, int ) { 587bool LibMadPlugin::audioSetSample( long, int ) {
570 debugMsg( "LibMadPlugin::audioSetSample" ); 588 debugMsg( "LibMadPlugin::audioSetSample" );
589
590// long totalSamples = audioSamples(0);
591// if ( totalSamples <= 1 )
592// return FALSE;
593
594// // Seek to requested position
595// qDebug( "seek pos: %i", (int)((double)pos * d->input.fileLength / totalSamples) );
596// ::lseek( d->input.fd, (long)((double)pos * d->input.fileLength / totalSamples), SEEK_SET );
597// mad_stream_sync(&d->stream);
598
599// mad_stream_init(&d->stream);
600// mad_frame_init(&d->frame);
601// mad_synth_init(&d->synth);
602
603// return TRUE;
604 debugMsg( "LibMadPlugin::audioSetSample" );
571 return FALSE; 605 return FALSE;
572} 606}
573 607
574 608
575long LibMadPlugin::audioGetSample( int ) { 609long LibMadPlugin::audioGetSample( int ) {
576 debugMsg( "LibMadPlugin::audioGetSample" ); 610 debugMsg( "LibMadPlugin::audioGetSample" );
577 return 0; 611 return 0;
578} 612}
579 613
580/* 614/*
581bool LibMadPlugin::audioReadSamples( short *, int, long, int ) { 615bool LibMadPlugin::audioReadSamples( short *, int, long, int ) {
582debugMsg( "LibMadPlugin::audioReadSamples" ); 616debugMsg( "LibMadPlugin::audioReadSamples" );