summaryrefslogtreecommitdiff
path: root/core/multimedia/opieplayer/libmad/libmadplugin.cpp
Side-by-side diff
Diffstat (limited to 'core/multimedia/opieplayer/libmad/libmadplugin.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/multimedia/opieplayer/libmad/libmadplugin.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/core/multimedia/opieplayer/libmad/libmadplugin.cpp b/core/multimedia/opieplayer/libmad/libmadplugin.cpp
index 9f8ba65..8ede537 100644
--- a/core/multimedia/opieplayer/libmad/libmadplugin.cpp
+++ b/core/multimedia/opieplayer/libmad/libmadplugin.cpp
@@ -23,39 +23,41 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <time.h>
#include <locale.h>
#include <math.h>
#include <assert.h>
#include <qapplication.h>
+#include <qpe/config.h>
//#define HAVE_MMAP
#if defined(HAVE_MMAP)
# include <sys/mman.h>
#endif
#include "libmadplugin.h"
extern "C" {
#include "mad.h"
}
#define MPEG_BUFFER_SIZE 65536
+//#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 char *data;
@@ -156,25 +158,28 @@ bool LibMadPlugin::isFileSupported( const QString& path ) {
if ( strncasecmp(ext, ".mp2", 4) == 0 )
return TRUE;
if ( strncasecmp(ext, ".mp3", 4) == 0 )
return TRUE;
}
return FALSE;
}
bool LibMadPlugin::open( const QString& path ) {
debugMsg( "LibMadPlugin::open" );
-
+ Config cfg("MediaPlayer");
+ cfg.setGroup("Options");
+ bufferSize = cfg.readNumEntry("MPeg_BufferSize",MPEG_BUFFER_SIZE);
+ qDebug("buffer size is %d", bufferSize);
d->bad_last_frame = 0;
d->flush = TRUE;
info = QString( "" );
//qDebug( "Opening %s", path.latin1() );
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;
}
@@ -188,25 +193,25 @@ bool LibMadPlugin::open( const QString& path ) {
}
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(MPEG_BUFFER_SIZE);
+ d->input.data = (unsigned char *)malloc( bufferSize /*MPEG_BUFFER_SIZE*/);
if (d->input.data == 0) {
qDebug("error allocating input buffer");
return FALSE;
}
d->input.length = 0;
}
d->input.eof = 0;
mad_stream_init(&d->stream);
mad_frame_init(&d->frame);
mad_synth_init(&d->synth);
@@ -360,36 +365,36 @@ bool LibMadPlugin::read() {
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);
+ len = ::read(d->input.fd, d->input.data + d->input.length, bufferSize /* 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);
+ assert(bufferSize /*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;
}