Diffstat (limited to 'core/multimedia/opieplayer/libmad') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/libmad/Makefile.in | 2 | ||||
-rw-r--r-- | core/multimedia/opieplayer/libmad/libmad.pro | 18 | ||||
-rw-r--r-- | core/multimedia/opieplayer/libmad/libmadplugin.cpp | 302 | ||||
-rw-r--r-- | core/multimedia/opieplayer/libmad/libmadplugin.h | 4 | ||||
-rw-r--r-- | core/multimedia/opieplayer/libmad/libmadpluginimpl.h | 4 |
5 files changed, 167 insertions, 163 deletions
diff --git a/core/multimedia/opieplayer/libmad/Makefile.in b/core/multimedia/opieplayer/libmad/Makefile.in index e9f74e7..552043c 100644 --- a/core/multimedia/opieplayer/libmad/Makefile.in +++ b/core/multimedia/opieplayer/libmad/Makefile.in @@ -213,11 +213,13 @@ huffman.o: huffman.c \ huffman.h libmadplugin.o: libmadplugin.cpp \ libmadplugin.h \ + ../mediaplayerplugininterface.h \ mad.h libmadpluginimpl.o: libmadpluginimpl.cpp \ libmadplugin.h \ + ../mediaplayerplugininterface.h \ libmadpluginimpl.h diff --git a/core/multimedia/opieplayer/libmad/libmad.pro b/core/multimedia/opieplayer/libmad/libmad.pro index 6c40a15..06e19e4 100644 --- a/core/multimedia/opieplayer/libmad/libmad.pro +++ b/core/multimedia/opieplayer/libmad/libmad.pro @@ -1,12 +1,12 @@ -TEMPLATE = lib -CONFIG += qt warn_on release -HEADERS = libmad_version.h fixed.h bit.h timer.h stream.h frame.h synth.h decoder.h \ - layer12.h layer3.h huffman.h libmad_global.h mad.h libmadplugin.h libmadpluginimpl.h -SOURCES = version.c fixed.c bit.c timer.c stream.c frame.c synth.c decoder.c \ - layer12.c layer3.c huffman.c libmadplugin.cpp libmadpluginimpl.cpp -TARGET = madplugin -DESTDIR = ../../plugins/codecs +TEMPLATE = lib +CONFIG += qt warn_on release +HEADERS = libmad_version.h fixed.h bit.h timer.h stream.h frame.h synth.h decoder.h \ + layer12.h layer3.h huffman.h libmad_global.h mad.h libmadplugin.h libmadpluginimpl.h +SOURCES = version.c fixed.c bit.c timer.c stream.c frame.c synth.c decoder.c \ + layer12.c layer3.c huffman.c libmadplugin.cpp libmadpluginimpl.cpp +TARGET = madplugin +DESTDIR = ../../plugins/codecs INCLUDEPATH += $(OPIEDIR)/include .. DEPENDPATH += ../$(OPIEDIR)/include .. LIBS += -lqpe -lm -VERSION = 1.0.0 +VERSION = 1.0.0 diff --git a/core/multimedia/opieplayer/libmad/libmadplugin.cpp b/core/multimedia/opieplayer/libmad/libmadplugin.cpp index 9d04f7e..9f8ba65 100644 --- a/core/multimedia/opieplayer/libmad/libmadplugin.cpp +++ b/core/multimedia/opieplayer/libmad/libmadplugin.cpp @@ -46,9 +46,9 @@ extern "C" { } #define MPEG_BUFFER_SIZE 65536 -//#define debugMsg(a) qDebug(a) +//#define debugMsg(a) qDebug(a) #define debugMsg(a) class Input { @@ -144,20 +144,20 @@ LibMadPlugin::~LibMadPlugin() { bool LibMadPlugin::isFileSupported( const QString& path ) { debugMsg( "LibMadPlugin::isFileSupported" ); // Mpeg file extensions - // "mp2","mp3","m1v","m2v","m2s","mpg","vob","mpeg","ac3" + // "mp2","mp3","m1v","m2v","m2s","mpg","vob","mpeg","ac3" // Other media extensions // "wav","mid","mod","s3m","ogg","avi","mov","sid" char *ext = strrchr( path.latin1(), '.' ); // Test file extension if ( ext ) { - if ( strncasecmp(ext, ".mp2", 4) == 0 ) - return TRUE; - if ( strncasecmp(ext, ".mp3", 4) == 0 ) - return TRUE; + if ( strncasecmp(ext, ".mp2", 4) == 0 ) + return TRUE; + if ( strncasecmp(ext, ".mp3", 4) == 0 ) + return TRUE; } return FALSE; } @@ -175,35 +175,35 @@ bool LibMadPlugin::open( const QString& path ) { d->input.path = path.latin1(); d->input.fd = ::open( d->input.path, O_RDONLY ); if (d->input.fd == -1) { qDebug("error opening %s", d->input.path ); - return FALSE; + return FALSE; } printID3Tags(); #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.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; + 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(MPEG_BUFFER_SIZE); - if (d->input.data == 0) { - qDebug("error allocating input buffer"); - return FALSE; - } - d->input.length = 0; + d->input.data = (unsigned char *)malloc(MPEG_BUFFER_SIZE); + if (d->input.data == 0) { + qDebug("error allocating input buffer"); + return FALSE; + } + d->input.length = 0; } d->input.eof = 0; @@ -225,25 +225,25 @@ bool LibMadPlugin::close() { mad_stream_finish(&d->stream); #if defined(HAVE_MMAP) if (d->input.fdm) { - if (unmap_file(d->input.fdm, d->input.length) == -1) { - qDebug("error munmapping file"); - result = FALSE; - } - d->input.fdm = 0; - d->input.data = 0; + if (unmap_file(d->input.fdm, d->input.length) == -1) { + qDebug("error munmapping file"); + result = FALSE; + } + d->input.fdm = 0; + d->input.data = 0; } #endif if (d->input.data) { free(d->input.data); - d->input.data = 0; + d->input.data = 0; } if (::close(d->input.fd) == -1) { qDebug("error closing file %s", d->input.path); - result = FALSE; + result = FALSE; } d->input.fd = 0; @@ -322,72 +322,72 @@ bool LibMadPlugin::read() { debugMsg( "LibMadPlugin::read" ); int len; if (d->input.eof) - return FALSE; + return FALSE; #if defined(HAVE_MMAP) if (d->input.fdm) { - unsigned long skip = 0; + unsigned long skip = 0; - if (d->stream.next_frame) { - struct stat stat; + if (d->stream.next_frame) { + struct stat stat; - if (fstat(d->input.fd, &stat) == -1) - return FALSE; + if (fstat(d->input.fd, &stat) == -1) + return FALSE; - if (stat.st_size + MAD_BUFFER_GUARD <= (signed)d->input.length) - return FALSE; + if (stat.st_size + MAD_BUFFER_GUARD <= (signed)d->input.length) + return FALSE; - // file size changed; update memory map - skip = d->stream.next_frame - d->input.data; + // file size changed; update memory map + skip = d->stream.next_frame - d->input.data; - if (unmap_file(d->input.fdm, d->input.length) == -1) { - d->input.fdm = 0; - d->input.data = 0; - return FALSE; - } + if (unmap_file(d->input.fdm, d->input.length) == -1) { + d->input.fdm = 0; + d->input.data = 0; + return FALSE; + } - d->input.length = stat.st_size; + d->input.length = stat.st_size; - d->input.fdm = map_file(d->input.fd, &d->input.length); - if (d->input.fdm == 0) { - d->input.data = 0; - return FALSE; - } + d->input.fdm = map_file(d->input.fd, &d->input.length); + if (d->input.fdm == 0) { + d->input.data = 0; + return FALSE; + } - d->input.data = (unsigned char *)d->input.fdm; - } + d->input.data = (unsigned char *)d->input.fdm; + } - mad_stream_buffer(&d->stream, d->input.data + skip, d->input.length - skip); + mad_stream_buffer(&d->stream, d->input.data + skip, d->input.length - skip); } else #endif { - if (d->stream.next_frame) { - memmove(d->input.data, d->stream.next_frame, - d->input.length = &d->input.data[d->input.length] - d->stream.next_frame); - } - - do { - len = ::read(d->input.fd, d->input.data + d->input.length, MPEG_BUFFER_SIZE - d->input.length); - } - while (len == -1 && errno == EINTR); - - if (len == -1) { - qDebug("error reading audio"); - return FALSE; - } - else if (len == 0) { - d->input.eof = 1; - - assert(MPEG_BUFFER_SIZE - d->input.length >= MAD_BUFFER_GUARD); - - while (len < MAD_BUFFER_GUARD) - d->input.data[d->input.length + len++] = 0; - } - - mad_stream_buffer(&d->stream, d->input.data, d->input.length += len); + if (d->stream.next_frame) { + memmove(d->input.data, d->stream.next_frame, + d->input.length = &d->input.data[d->input.length] - d->stream.next_frame); + } + + do { + len = ::read(d->input.fd, d->input.data + d->input.length, MPEG_BUFFER_SIZE - d->input.length); + } + while (len == -1 && errno == EINTR); + + if (len == -1) { + qDebug("error reading audio"); + return FALSE; + } + else if (len == 0) { + d->input.eof = 1; + + assert(MPEG_BUFFER_SIZE - d->input.length >= MAD_BUFFER_GUARD); + + while (len < MAD_BUFFER_GUARD) + d->input.data[d->input.length + len++] = 0; + } + + mad_stream_buffer(&d->stream, d->input.data, d->input.length += len); } return TRUE; } @@ -410,18 +410,18 @@ inline long audio_linear_dither( mad_fixed_t sample, mad_fixed_t& error ) inline void audio_pcm( short *data, unsigned int nsamples, mad_fixed_t *left, mad_fixed_t *right ) { if ( right ) { - while (nsamples--) { - data[0] = audio_linear_dither( *left++, left_err ); - data[1] = audio_linear_dither( *right++, right_err ); - data += 2; - } + while (nsamples--) { + data[0] = audio_linear_dither( *left++, left_err ); + data[1] = audio_linear_dither( *right++, right_err ); + data += 2; + } } else { - while (nsamples--) { - data[0] = data[1] = audio_linear_dither( *left++, left_err ); - data += 2; - } + while (nsamples--) { + data[0] = data[1] = audio_linear_dither( *left++, left_err ); + data += 2; + } } } @@ -435,38 +435,38 @@ bool LibMadPlugin::decode( short *output, long samples, long& samplesMade ) { static int maxBuffered = 8000; // 65536; if ( samples > maxBuffered ) - samples = maxBuffered; + samples = maxBuffered; if ( d->flush ) { - buffered = 0; - offset = 0; - d->flush = FALSE; + buffered = 0; + offset = 0; + d->flush = FALSE; } while ( buffered < maxBuffered ) { - while (mad_frame_decode(&d->frame, &d->stream) == -1) { - if (!MAD_RECOVERABLE(d->stream.error)) { - debugMsg( "feed me" ); - return FALSE; // Feed me - } - if ( d->stream.error == MAD_ERROR_BADCRC ) { - mad_frame_mute(&d->frame); - qDebug( "error decoding, bad crc" ); - } - } - - mad_synth_frame(&d->synth, &d->frame); - int decodedSamples = d->synth.pcm.length; - memcpy( &(buffer[0][offset]), d->synth.pcm.samples[0], decodedSamples * sizeof(mad_fixed_t) ); - if ( d->synth.pcm.channels == 2 ) - memcpy( &(buffer[1][offset]), d->synth.pcm.samples[1], decodedSamples * sizeof(mad_fixed_t) ); - offset += decodedSamples; - buffered += decodedSamples; + while (mad_frame_decode(&d->frame, &d->stream) == -1) { + if (!MAD_RECOVERABLE(d->stream.error)) { + debugMsg( "feed me" ); + return FALSE; // Feed me + } + if ( d->stream.error == MAD_ERROR_BADCRC ) { + mad_frame_mute(&d->frame); + qDebug( "error decoding, bad crc" ); + } + } + + mad_synth_frame(&d->synth, &d->frame); + int decodedSamples = d->synth.pcm.length; + memcpy( &(buffer[0][offset]), d->synth.pcm.samples[0], decodedSamples * sizeof(mad_fixed_t) ); + if ( d->synth.pcm.channels == 2 ) + memcpy( &(buffer[1][offset]), d->synth.pcm.samples[1], decodedSamples * sizeof(mad_fixed_t) ); + offset += decodedSamples; + buffered += decodedSamples; } - +//qApp->processEvents(); audio_pcm( output, samples, buffer[0], (d->synth.pcm.channels == 2) ? buffer[1] : 0 ); // audio_pcm( output, samples, buffer[1], buffer[0] ); // audio_pcm( output, samples, buffer[0], buffer[1] ); samplesMade = samples; @@ -492,34 +492,34 @@ bool LibMadPlugin::audioReadSamples( short *output, int /*channels*/, long sampl static bool needInput = TRUE; if ( samples == 0 ) - return FALSE; + return FALSE; do { - if ( needInput ) - if ( !read() ) { -// if ( d->input.eof ) -// needInput = FALSE; -// else - return FALSE; - } - - needInput = FALSE; - - if ( decode( output, samples, samplesMade ) ) - return TRUE; - else - needInput = TRUE; + if ( needInput ) + if ( !read() ) { +// if ( d->input.eof ) +// needInput = FALSE; +// else + return FALSE; + } + + needInput = FALSE; + + if ( decode( output, samples, samplesMade ) ) + return TRUE; + else + needInput = TRUE; } while ( ( samplesMade < samples ) && ( !d->input.eof ) ); /* static bool firstTimeThru = TRUE; if ( firstTimeThru ) { - firstTimeThru = FALSE; - decode( output, samples, samplesMade ); - return FALSE; + firstTimeThru = FALSE; + decode( output, samples, samplesMade ); + return FALSE; } else */ return FALSE; } @@ -536,43 +536,43 @@ void LibMadPlugin::printID3Tags() { char id3v1[128 + 1]; if ( ::lseek( d->input.fd, -128, SEEK_END ) == -1 ) { - qDebug( "error seeking to id3 tags" ); - return; + qDebug( "error seeking to id3 tags" ); + return; } if ( ::read( d->input.fd, id3v1, 128 ) != 128 ) { - qDebug( "error reading in id3 tags" ); - return; + qDebug( "error reading in id3 tags" ); + return; } if ( ::strncmp( (const char *)id3v1, "TAG", 3 ) != 0 ) { - debugMsg( "sorry, no id3 tags" ); + debugMsg( "sorry, no id3 tags" ); } else { - int len[5] = { 30, 30, 30, 4, 30 }; - QString label[5] = { tr( "Title" ), tr( "Artist" ), tr( "Album" ), tr( "Year" ), tr( "Comment" ) }; - char *ptr = id3v1 + 3, *ptr2 = ptr + len[0]; - qDebug( "ID3 tags in file:" ); - info = ""; - for ( int i = 0; i < 5; ptr += len[i], i++, ptr2 += len[i] ) { - char push = *ptr2; - *ptr2 = '\0'; - char *ptr3 = ptr2; - while ( ptr3-1 >= ptr && isspace(ptr3[-1]) ) ptr3--; - char push2 = *ptr3; *ptr3 = '\0'; - if ( strcmp( ptr, "" ) ) - info += ( i != 0 ? ", " : "" ) + label[i] + ": " + ptr; - //qDebug( info.latin1() ); - *ptr3 = push2; - *ptr2 = push; - } - if (id3v1[126] == 0 && id3v1[127] != 0) - info += tr( ", Track: " ) + id3v1[127]; + int len[5] = { 30, 30, 30, 4, 30 }; + QString label[5] = { tr( "Title" ), tr( "Artist" ), tr( "Album" ), tr( "Year" ), tr( "Comment" ) }; + char *ptr = id3v1 + 3, *ptr2 = ptr + len[0]; + qDebug( "ID3 tags in file:" ); + info = ""; + for ( int i = 0; i < 5; ptr += len[i], i++, ptr2 += len[i] ) { + char push = *ptr2; + *ptr2 = '\0'; + char *ptr3 = ptr2; + while ( ptr3-1 >= ptr && isspace(ptr3[-1]) ) ptr3--; + char push2 = *ptr3; *ptr3 = '\0'; + if ( strcmp( ptr, "" ) ) + info += ( i != 0 ? ", " : "" ) + label[i] + ": " + ptr; + //qDebug( info.latin1() ); + *ptr3 = push2; + *ptr2 = push; + } + if (id3v1[126] == 0 && id3v1[127] != 0) + info += tr( ", Track: " ) + id3v1[127]; } if ( ::lseek(d->input.fd, 0, SEEK_SET) == -1 ) { - qDebug( "error seeking back to beginning" ); + qDebug( "error seeking back to beginning" ); return; } } diff --git a/core/multimedia/opieplayer/libmad/libmadplugin.h b/core/multimedia/opieplayer/libmad/libmadplugin.h index d85e0d4..d163458 100644 --- a/core/multimedia/opieplayer/libmad/libmadplugin.h +++ b/core/multimedia/opieplayer/libmad/libmadplugin.h @@ -20,9 +20,10 @@ #ifndef LIBMAD_PLUGIN_H #define LIBMAD_PLUGIN_H #include <qstring.h> -#include <qpe/mediaplayerplugininterface.h> +//#include <qpe/mediaplayerplugininterface.h> +#include "../mediaplayerplugininterface.h" // #define OLD_MEDIAPLAYER_API @@ -51,8 +52,9 @@ public: int audioChannels( int stream ); int audioFrequency( int stream ); int audioSamples( int stream ); bool audioSetSample( long sample, int stream ); + int audioBitsPerSample(int) {return 0;} long audioGetSample( int stream ); #ifdef OLD_MEDIAPLAYER_API bool audioReadMonoSamples( short *output, long samples, long& samplesRead, int stream ); bool audioReadStereoSamples( short *output, long samples, long& samplesRead, int stream ); diff --git a/core/multimedia/opieplayer/libmad/libmadpluginimpl.h b/core/multimedia/opieplayer/libmad/libmadpluginimpl.h index 2c5ed3b..bc864ee 100644 --- a/core/multimedia/opieplayer/libmad/libmadpluginimpl.h +++ b/core/multimedia/opieplayer/libmad/libmadpluginimpl.h @@ -19,9 +19,10 @@ **********************************************************************/ #ifndef LIBMAD_PLUGIN_IMPL_H #define LIBMAD_PLUGIN_IMPL_H -#include <qpe/mediaplayerplugininterface.h> +//#include <qpe/mediaplayerplugininterface.h> +#include "../mediaplayerplugininterface.h" class LibMadPlugin; @@ -40,9 +41,8 @@ public: #endif virtual MediaPlayerDecoder *decoder(); virtual MediaPlayerEncoder *encoder(); - private: LibMadPlugin *libmadplugin; ulong ref; }; |