author | llornkcor <llornkcor> | 2003-02-25 23:36:47 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2003-02-25 23:36:47 (UTC) |
commit | bde9ed97c92b6f7eefa8a66d9f58aa4c78127733 (patch) (side-by-side diff) | |
tree | 4a74c6083acd5d89e191aaa3629040fb4449ff71 | |
parent | 689847f2dcaabdfca266efd3c99c81b833bf6e9f (diff) | |
download | opie-bde9ed97c92b6f7eefa8a66d9f58aa4c78127733.zip opie-bde9ed97c92b6f7eefa8a66d9f58aa4c78127733.tar.gz opie-bde9ed97c92b6f7eefa8a66d9f58aa4c78127733.tar.bz2 |
add proper number of samples reporting
-rw-r--r-- | core/multimedia/opieplayer/libmad/libmadplugin.cpp | 48 |
1 files changed, 41 insertions, 7 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,24 +66,25 @@ extern "C" { //#define MPEG_BUFFER_SIZE 32768 //16384 // 8192 //#define debugMsg(a) qDebug(a) #define debugMsg(a) class Input { public: char const *path; int fd; #if defined(HAVE_MMAP) void *fdm; #endif + unsigned long fileLength; unsigned char *data; unsigned long length; int eof; }; class Output { public: mad_fixed_t attenuate; struct filter *filters; unsigned int channels_in; unsigned int channels_out; @@ -444,29 +445,34 @@ bool LibMadPlugin::open( const QString& path ) { } } else { d->input.path = path.latin1(); d->input.fd = ::open( d->input.path, O_RDONLY ); // thats a better place, since it should only seek for ID3 tags on mp3 files, not streams printID3Tags(); } if (d->input.fd == -1) { qDebug("error opening %s", d->input.path ); return FALSE; } -#if defined(HAVE_MMAP) struct stat stat; if (fstat(d->input.fd, &stat) == -1) { - //qDebug("error calling fstat"); return FALSE; + qDebug("error calling fstat"); return FALSE; } + if (S_ISREG(stat.st_mode) && stat.st_size > 0) + d->input.fileLength = stat.st_size; + else + d->input.fileLength = 0; + +#if defined(HAVE_MMAP) if (S_ISREG(stat.st_mode) && stat.st_size > 0) { d->input.length = stat.st_size; d->input.fdm = map_file(d->input.fd, &d->input.length); if (d->input.fdm == 0) { qDebug("error mmapping file"); return FALSE; } d->input.data = (unsigned char *)d->input.fdm; } #endif if (d->input.data == 0) { d->input.data = (unsigned char *)malloc( bufferSize /*MPEG_BUFFER_SIZE*/); @@ -548,35 +554,63 @@ int LibMadPlugin::audioChannels( int ) { int LibMadPlugin::audioFrequency( int ) { debugMsg( "LibMadPlugin::audioFrequency" ); long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); qDebug( "LibMadPlugin::audioFrequency: %i", d->frame.header.samplerate ); return d->frame.header.samplerate; } int LibMadPlugin::audioSamples( int ) { debugMsg( "LibMadPlugin::audioSamples" ); - // long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); -// mad_header_decode( (struct mad_header *)&d->frame.header, &d->stream ); -// qDebug( "LibMadPlugin::audioSamples: %i*%i", d->frame.header.duration.seconds, d->frame.header.samplerate ); -// return d->frame.header.duration.seconds * d->frame.header.samplerate; + long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); + mad_header_decode( (struct mad_header *)&d->frame.header, &d->stream ); +/* + qDebug( "LibMadPlugin::audioSamples: %i*%i", d->frame.header.duration.seconds, + d->frame.header.samplerate ); + return d->frame.header.duration.seconds * d->frame.header.samplerate; +*/ + if ( d->frame.header.bitrate == 0 ) + return 0; + int samples = (d->input.fileLength / (d->frame.header.bitrate/8)) * d->frame.header.samplerate; - return 10000000; + qDebug( "LibMadPlugin::audioSamples: %i * %i * 8 / %i", (int)d->input.fileLength, + (int)d->frame.header.samplerate, (int)d->frame.header.bitrate ); + qDebug( "LibMadPlugin::audioSamples: %i", samples ); + + return samples; + +// return 10000000; } bool LibMadPlugin::audioSetSample( long, int ) { debugMsg( "LibMadPlugin::audioSetSample" ); + +// long totalSamples = audioSamples(0); +// if ( totalSamples <= 1 ) +// return FALSE; + +// // Seek to requested position +// qDebug( "seek pos: %i", (int)((double)pos * d->input.fileLength / totalSamples) ); +// ::lseek( d->input.fd, (long)((double)pos * d->input.fileLength / totalSamples), SEEK_SET ); +// mad_stream_sync(&d->stream); + +// mad_stream_init(&d->stream); +// mad_frame_init(&d->frame); +// mad_synth_init(&d->synth); + +// return TRUE; + debugMsg( "LibMadPlugin::audioSetSample" ); return FALSE; } long LibMadPlugin::audioGetSample( int ) { debugMsg( "LibMadPlugin::audioGetSample" ); return 0; } /* bool LibMadPlugin::audioReadSamples( short *, int, long, int ) { debugMsg( "LibMadPlugin::audioReadSamples" ); |