summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/libmad/libmadplugin.cpp
authorllornkcor <llornkcor>2002-02-25 05:10:32 (UTC)
committer llornkcor <llornkcor>2002-02-25 05:10:32 (UTC)
commit1bebd27631a6c9d1ab967cbb32dd4e796b3b0402 (patch) (side-by-side diff)
tree8ce49800cba26f6f2c33de74a71d4efe0338843f /core/multimedia/opieplayer/libmad/libmadplugin.cpp
parentd948361c1b475fab4660b28fbf5ec21fd34d923f (diff)
downloadopie-1bebd27631a6c9d1ab967cbb32dd4e796b3b0402.zip
opie-1bebd27631a6c9d1ab967cbb32dd4e796b3b0402.tar.gz
opie-1bebd27631a6c9d1ab967cbb32dd4e796b3b0402.tar.bz2
fixed 2
Diffstat (limited to 'core/multimedia/opieplayer/libmad/libmadplugin.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/libmad/libmadplugin.cpp302
1 files changed, 151 insertions, 151 deletions
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
@@ -47,7 +47,7 @@ extern "C" {
#define MPEG_BUFFER_SIZE 65536
-//#define debugMsg(a) qDebug(a)
+//#define debugMsg(a) qDebug(a)
#define debugMsg(a)
@@ -145,7 +145,7 @@ 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"
@@ -153,10 +153,10 @@ bool LibMadPlugin::isFileSupported( const QString& path ) {
// 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;
@@ -176,7 +176,7 @@ bool LibMadPlugin::open( const QString& path ) {
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();
@@ -184,25 +184,25 @@ bool LibMadPlugin::open( const QString& path ) {
#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;
@@ -226,23 +226,23 @@ bool LibMadPlugin::close() {
#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;
@@ -323,70 +323,70 @@ bool 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;
@@ -411,16 +411,16 @@ 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;
+ }
}
}
@@ -436,36 +436,36 @@ 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] );
@@ -493,32 +493,32 @@ 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;
@@ -537,41 +537,41 @@ 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;
}
}