Index: libmadplugin.cpp =================================================================== RCS file: /var/cvsroot/yamaken/devel/zaurus/libmad-ja/libmadplugin.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.5 diff -u -u -r1.1.1.1 -r1.5 --- libmadplugin.cpp 7 Aug 2002 15:26:17 -0000 1.1.1.1 +++ libmadplugin.cpp 16 Aug 2002 04:07:05 -0000 1.5 @@ -32,6 +32,7 @@ #include #include #include +#include //#define HAVE_MMAP @@ -51,6 +52,7 @@ //#define debugMsg(a) qDebug(a) #define debugMsg(a) +static QTextCodec *codec_for_str(const char *str); class Input { public: @@ -111,6 +113,29 @@ return qApp->translate( "MediaPlayer", str, "libmad strings for mp3 file info" ); } +static QTextCodec * +codec_for_str(const char *str) { + static const char *encodings[] = {"SJIS", "eucJP", "ISO 8859-1", ""}; + QTextCodec *codec = NULL, *candidate = NULL; + int i, score = 0, hiscore = 0; + + for (i = 0; *encodings[i]; i++) { + candidate = QTextCodec::codecForName(encodings[i]); + if (candidate) { + score = candidate->heuristicContentMatch(str, strlen(str)); + } + if (hiscore < score) { + hiscore = score; + codec = candidate; + } + } + if (!codec) { + codec = QTextCodec::codecForName("ISO 8859-1"); + } + + return codec; +} + class LibMadPluginData { public: @@ -288,14 +313,19 @@ int LibMadPlugin::audioSamples( int ) { + int seconds, samples; + unsigned int sample_rate; + 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; -*/ - return 10000000; + + sample_rate = d->frame.header.samplerate; + seconds = 99 * 60/*min*/ + 59/*sec*/; + samples = seconds * sample_rate; + qDebug( "LibMadPlugin::audioSamples: %i*%i", seconds, sample_rate ); + + return samples; } @@ -512,7 +542,7 @@ static bool needInput = TRUE; if ( samples == 0 ) - return TRUE; + return FALSE; do { if ( needInput ) @@ -520,13 +550,13 @@ // if ( d->input.eof ) // needInput = FALSE; // else - return TRUE; + return FALSE; } needInput = FALSE; if ( decode( output, samples, samplesMade ) ) - return FALSE; + return TRUE; else needInput = TRUE; } @@ -537,10 +567,10 @@ if ( firstTimeThru ) { firstTimeThru = FALSE; decode( output, samples, samplesMade ); - return FALSE; + return TRUE; } else */ - return TRUE; + return FALSE; } @@ -579,8 +609,14 @@ 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; + if ( strcmp( ptr, "" ) ) { + QTextCodec *codec; + QString unicode_str; + + codec = codec_for_str(ptr); + unicode_str = codec->toUnicode(ptr); + info += ( i != 0 ? ", " : "" ) + label[i] + ": " + unicode_str; + } //qDebug( info.latin1() ); *ptr3 = push2; *ptr2 = push;