From e0798f4ab34b72f4c439932f9c43361b5a898301 Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Mon, 13 Jun 2011 15:25:44 +0000 Subject: [PATCH] neutrino: fix playback position display in flacdec.cpp git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@1541 e54a6e83-5905-42d5-8d5c-058d10e6a962 Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/545ff5456a26fcc52a203369782516260f0a97db Author: Stefan Seyfried Date: 2011-06-13 (Mon, 13 Jun 2011) --- src/driver/audiodec/flacdec.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/driver/audiodec/flacdec.cpp b/src/driver/audiodec/flacdec.cpp index 39ac27562..ece7b09f4 100644 --- a/src/driver/audiodec/flacdec.cpp +++ b/src/driver/audiodec/flacdec.cpp @@ -423,6 +423,8 @@ CBaseDec::RetCode CFlacDec::Decoder(FILE *in, const int /*OutputFd*/, State* con mTimePlayed = time_played; mFrameCount = 0; mSamplesProcessed = 0; + struct stat s; + FLAC__uint64 filesize = 0; mFlacDec = FLAC__stream_decoder_new(); @@ -432,6 +434,14 @@ CBaseDec::RetCode CFlacDec::Decoder(FILE *in, const int /*OutputFd*/, State* con return Status; } + if (fstat(fileno(in), &s)) + { + perror("CFlacDec::Decoder fstat"); + *time_played = 0; + } + else + filesize = (FLAC__uint64)s.st_size; + /* up and away ... */ mSlotSize = MAX_OUTPUT_SAMPLES * 2 * FLAC__stream_decoder_get_channels(mFlacDec); // State oldstate=*state; @@ -440,7 +450,7 @@ CBaseDec::RetCode CFlacDec::Decoder(FILE *in, const int /*OutputFd*/, State* con int bytes_to_skip = (int) (1.0 * actSecsToSkip * meta_data->bitrate / 8); int bytes_to_play = (int) (1.0 * MSECS_TO_PLAY / 1000 * meta_data->bitrate / 8); unsigned int oldSecsToSkip = *secondsToSkip; -// FLAC__uint64 position; + FLAC__uint64 position; do { @@ -490,8 +500,10 @@ CBaseDec::RetCode CFlacDec::Decoder(FILE *in, const int /*OutputFd*/, State* con } rval = FLAC__stream_decoder_process_single(mFlacDec); - // TODO: calculate time_played from the actual file position so that REW/FF actions will be included - *time_played = (mSamplesProcessed * (mLengthInMsec/1000)) / mTotalSamples; + + /* update playback position */ + if (filesize > 0 && FLAC__stream_decoder_get_decode_position(mFlacDec, &position)) + *time_played = position / 1000ULL * mLengthInMsec / filesize; } while (rval && *state != STOP_REQ && Status == OK);