-rw-r--r-- | core/multimedia/opieplayer/libmad/libmadplugin.cpp | 8 | ||||
-rw-r--r-- | core/multimedia/opieplayer/loopcontrol.cpp | 4 | ||||
-rw-r--r-- | core/multimedia/opieplayer/wavplugin/wavplugin.cpp | 2 |
3 files changed, 7 insertions, 7 deletions
diff --git a/core/multimedia/opieplayer/libmad/libmadplugin.cpp b/core/multimedia/opieplayer/libmad/libmadplugin.cpp index b2b876f..9d04f7e 100644 --- a/core/multimedia/opieplayer/libmad/libmadplugin.cpp +++ b/core/multimedia/opieplayer/libmad/libmadplugin.cpp @@ -400,179 +400,179 @@ static const int shift = MAD_F_FRACBITS + 1 - bits; inline long audio_linear_dither( mad_fixed_t sample, mad_fixed_t& error ) { sample += error; mad_fixed_t quantized = (sample >= MAD_F_ONE) ? MAD_F_ONE - 1 : ( (sample < -MAD_F_ONE) ? -MAD_F_ONE : sample ); quantized &= ~((1L << shift) - 1); error = sample - quantized; return quantized >> shift; } 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; } } else { while (nsamples--) { data[0] = data[1] = audio_linear_dither( *left++, left_err ); data += 2; } } } bool LibMadPlugin::decode( short *output, long samples, long& samplesMade ) { debugMsg( "LibMadPlugin::decode" ); static int buffered = 0; static mad_fixed_t buffer[2][65536 * 2]; int offset = buffered; samplesMade = 0; static int maxBuffered = 8000; // 65536; if ( samples > maxBuffered ) samples = maxBuffered; if ( d->flush ) { 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; } 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; memmove( buffer[0], &(buffer[0][samples]), (buffered - samples) * sizeof(mad_fixed_t) ); if ( d->synth.pcm.channels == 2 ) memmove( buffer[1], &(buffer[1][samples]), (buffered - samples) * sizeof(mad_fixed_t) ); buffered -= samples; return TRUE; } /* bool LibMadPlugin::audioReadMonoSamples( short *, long, long&, int ) { debugMsg( "LibMadPlugin::audioReadMonoSamples" ); return FALSE; } bool LibMadPlugin::audioReadStereoSamples( short *output, long samples, long& samplesMade, int ) { */ bool LibMadPlugin::audioReadSamples( short *output, int /*channels*/, long samples, long& samplesMade, int ) { debugMsg( "LibMadPlugin::audioReadStereoSamples" ); static bool needInput = TRUE; if ( samples == 0 ) - return TRUE; + return FALSE; do { if ( needInput ) if ( !read() ) { // 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; } while ( ( samplesMade < samples ) && ( !d->input.eof ) ); /* static bool firstTimeThru = TRUE; if ( firstTimeThru ) { firstTimeThru = FALSE; decode( output, samples, samplesMade ); return FALSE; } else */ - return TRUE; + return FALSE; } double LibMadPlugin::getTime() { debugMsg( "LibMadPlugin::getTime" ); return 0.0; } void LibMadPlugin::printID3Tags() { debugMsg( "LibMadPlugin::printID3Tags" ); char id3v1[128 + 1]; if ( ::lseek( d->input.fd, -128, SEEK_END ) == -1 ) { qDebug( "error seeking to id3 tags" ); return; } if ( ::read( d->input.fd, id3v1, 128 ) != 128 ) { qDebug( "error reading in id3 tags" ); return; } if ( ::strncmp( (const char *)id3v1, "TAG", 3 ) != 0 ) { 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]; } if ( ::lseek(d->input.fd, 0, SEEK_SET) == -1 ) { qDebug( "error seeking back to beginning" ); return; } } diff --git a/core/multimedia/opieplayer/loopcontrol.cpp b/core/multimedia/opieplayer/loopcontrol.cpp index 93a6e3f..6dfd057 100644 --- a/core/multimedia/opieplayer/loopcontrol.cpp +++ b/core/multimedia/opieplayer/loopcontrol.cpp @@ -135,208 +135,208 @@ void LoopControl::timerEvent( QTimerEvent *te ) { if ( te->timerId() == sliderId ) { if ( hasAudioChannel && !hasVideoChannel && moreAudio ) { mediaPlayerState->updatePosition( audioSampleCounter ); } else if ( hasVideoChannel && moreVideo ) { mediaPlayerState->updatePosition( current_frame ); } } if ( !moreVideo && !moreAudio ) { mediaPlayerState->setPlaying( FALSE ); mediaPlayerState->setNext(); } } void LoopControl::setPosition( long pos ) { audioMutex->lock(); if ( hasVideoChannel && hasAudioChannel ) { playtime.restart(); playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); current_frame = pos + 1; mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); prev_frame = current_frame - 1; currentSample = (int)( (double)current_frame * freq / framerate ); mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); audioSampleCounter = currentSample - 1; } else if ( hasVideoChannel ) { playtime.restart(); playtime = playtime.addMSecs( long((double)-pos * 1000.0 / framerate) ); current_frame = pos + 1; mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); prev_frame = current_frame - 1; } else if ( hasAudioChannel ) { playtime.restart(); playtime = playtime.addMSecs( long((double)-pos * 1000.0 / freq) ); currentSample = pos + 1; mediaPlayerState->curDecoder()->audioSetSample( currentSample, stream ); audioSampleCounter = currentSample - 1; } audioMutex->unlock(); } void LoopControl::startVideo() { if ( moreVideo ) { if ( mediaPlayerState->curDecoder() ) { if ( hasAudioChannel && !isMuted ) { current_frame = long( playtime.elapsed() * framerate / 1000 ); if ( prev_frame != -1 && current_frame <= prev_frame ) return; } else { // Don't skip current_frame++; } if ( prev_frame == -1 || current_frame > prev_frame ) { if ( current_frame > prev_frame + 1 ) { mediaPlayerState->curDecoder()->videoSetFrame( current_frame, stream ); } moreVideo = videoUI->playVideo(); prev_frame = current_frame; } } else { moreVideo = FALSE; killTimer( videoId ); } } } void LoopControl::startAudio() { audioMutex->lock(); if ( moreAudio ) { if ( !isMuted && mediaPlayerState->curDecoder() ) { currentSample = audioSampleCounter + 1; if ( currentSample != audioSampleCounter + 1 ) qDebug("out of sync with decoder %i %i", currentSample, audioSampleCounter); long samplesRead = 0; - mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); + bool readOk=mediaPlayerState->curDecoder()->audioReadSamples( (short*)audioBuffer, channels, 1024, samplesRead, stream ); long sampleWeShouldBeAt = long( playtime.elapsed() ) * freq / 1000; long sampleWaitTime = currentSample - sampleWeShouldBeAt; if ( ( sampleWaitTime > 2000 ) && ( sampleWaitTime < 20000 ) ) { usleep( (long)((double)sampleWaitTime * 1000000.0 / freq) ); } else if ( sampleWaitTime <= -5000 ) { qDebug("need to catch up by: %li (%i,%li)", -sampleWaitTime, currentSample, sampleWeShouldBeAt ); //mediaPlayerState->curDecoder()->audioSetSample( sampleWeShouldBeAt, stream ); currentSample = sampleWeShouldBeAt; } audioDevice->write( audioBuffer, samplesRead * 2 * channels ); audioSampleCounter = currentSample + samplesRead - 1; - moreAudio = audioSampleCounter <= total_audio_samples; + moreAudio = readOk && (audioSampleCounter <= total_audio_samples); } else { moreAudio = FALSE; } } audioMutex->unlock(); } void LoopControl::killTimers() { audioMutex->lock(); if ( hasVideoChannel ) killTimer( videoId ); killTimer( sliderId ); threadOkToGo = FALSE; audioMutex->unlock(); } void LoopControl::startTimers() { audioMutex->lock(); moreVideo = FALSE; moreAudio = FALSE; if ( hasVideoChannel ) { moreVideo = TRUE; int mSecsBetweenFrames = (int)(100 / framerate); // 10% of the real value videoId = startTimer( mSecsBetweenFrames ); } if ( hasAudioChannel ) { moreAudio = TRUE; threadOkToGo = TRUE; } sliderId = startTimer( 300 ); // update slider every 1/3 second audioMutex->unlock(); } void LoopControl::setPaused( bool pause ) { if ( !mediaPlayerState->curDecoder() || !mediaPlayerState->curDecoder()->isOpen() ) return; if ( pause ) { killTimers(); } else { // Force an update of the position mediaPlayerState->setPosition( mediaPlayerState->position() + 1 ); mediaPlayerState->setPosition( mediaPlayerState->position() - 1 ); // Just like we never stopped startTimers(); } } void LoopControl::stop( bool willPlayAgainShortly ) { #if defined(Q_WS_QWS) && !defined(QT_NO_COP) if ( !willPlayAgainShortly && disabledSuspendScreenSaver ) { disabledSuspendScreenSaver = FALSE; // Re-enable the suspend mode QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; } #endif if ( mediaPlayerState->curDecoder() && mediaPlayerState->curDecoder()->isOpen() ) { killTimers(); audioMutex->lock(); mediaPlayerState->curDecoder()->close(); if ( audioDevice ) { delete audioDevice; delete audioBuffer; audioDevice = 0; audioBuffer = 0; } audioMutex->unlock(); } } diff --git a/core/multimedia/opieplayer/wavplugin/wavplugin.cpp b/core/multimedia/opieplayer/wavplugin/wavplugin.cpp index 60a0024..a6bd974 100644 --- a/core/multimedia/opieplayer/wavplugin/wavplugin.cpp +++ b/core/multimedia/opieplayer/wavplugin/wavplugin.cpp @@ -230,105 +230,105 @@ bool WavPlugin::open( const QString& path ) { d->wavedata_remaining = 0; d->samples_due = 0; d->input = new QFile( path ); if ( d->input->open(IO_ReadOnly) == FALSE ) { qDebug("couldn't open file"); delete d->input; d->input = 0; return FALSE; } d->initialise(); return TRUE; } bool WavPlugin::close() { debugMsg( "WavPlugin::close" ); d->input->close(); delete d->input; d->input = 0; return TRUE; } bool WavPlugin::isOpen() { debugMsg( "WavPlugin::isOpen" ); return ( d->input != 0 ); } int WavPlugin::audioStreams() { debugMsg( "WavPlugin::audioStreams" ); return 1; } int WavPlugin::audioChannels( int ) { debugMsg( "WavPlugin::audioChannels" ); return 2; // ### Always scale audio to stereo samples } int WavPlugin::audioFrequency( int ) { debugMsg( "WavPlugin::audioFrequency" ); return 44100; // ### Always scale to frequency of 44100 } int WavPlugin::audioSamples( int ) { debugMsg( "WavPlugin::audioSamples" ); return d->samples * 2 / d->chunkdata.channels; // ### Scaled samples will be made stereo, // Therefore if source is mono we will double the number of samples } bool WavPlugin::audioSetSample( long, int ) { debugMsg( "WavPlugin::audioSetSample" ); return FALSE; } long WavPlugin::audioGetSample( int ) { debugMsg( "WavPlugin::audioGetSample" ); return 0; } /* bool WavPlugin::audioReadSamples( short *, int, long, int ) { debugMsg( "WavPlugin::audioReadSamples" ); return FALSE; } bool WavPlugin::audioReReadSamples( short *, int, long, int ) { debugMsg( "WavPlugin::audioReReadSamples" ); return FALSE; } bool WavPlugin::audioReadMonoSamples( short *output, long samples, long& samplesMade, int ) { debugMsg( "WavPlugin::audioReadMonoSamples" ); return !d->add( output, samples, samplesMade, FALSE ); } bool WavPlugin::audioReadStereoSamples( short *output, long samples, long& samplesMade, int ) { debugMsg( "WavPlugin::audioReadStereoSamples" ); return !d->add( output, samples, samplesMade, TRUE ); } */ bool WavPlugin::audioReadSamples( short *output, int channels, long samples, long& samplesMade, int ) { debugMsg( "WavPlugin::audioReadSamples" ); - return !d->add( output, samples, samplesMade, channels != 1 ); + return d->add( output, samples, samplesMade, channels != 1 ); } double WavPlugin::getTime() { debugMsg( "WavPlugin::getTime" ); return 0.0; } |