diff options
Diffstat (limited to 'vdr_decoder_flac.c')
-rw-r--r-- | vdr_decoder_flac.c | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/vdr_decoder_flac.c b/vdr_decoder_flac.c index fd1ca53..e4b7cbb 100644 --- a/vdr_decoder_flac.c +++ b/vdr_decoder_flac.c @@ -10,16 +10,12 @@ #ifdef HAVE_FLAC -#define DEBUG - #include <string> #include <stdlib.h> #include <stdio.h> #include "mg_tools.h" -#include "mg_content.h" -#include "vdr_setup.h" #include "vdr_decoder_flac.h" @@ -32,7 +28,7 @@ static const unsigned MAX_RES_SIZE = 16384; // --- mgFlacDecoder ------------------------------------------------------------- -mgFlacDecoder::mgFlacDecoder( mgContentItem *item ) +mgFlacDecoder::mgFlacDecoder( mgItemGd *item ) : mgDecoder( item ), FLAC::Decoder::File() { mgLog lg( "mgFlacDecoder::mgFlacDecoder" ); @@ -81,7 +77,7 @@ bool mgFlacDecoder::initialize() // init reservoir buffer; this should be according to the maximum // frame/sample size that we can probably obtain from metadata - m_reservoir = new (FLAC__int32*)[2]; + m_reservoir = new FLAC__int32*[2]; m_reservoir[0] = new FLAC__int32[MAX_RES_SIZE]; m_reservoir[1] = new FLAC__int32[MAX_RES_SIZE]; @@ -262,7 +258,6 @@ mgFlacDecoder::write_callback(const ::FLAC__Frame *frame, m_current_samples += m_len_decoded; m_current_time_ms += (m_len_decoded*1000) / m_pcm->samplerate; // in milliseconds - // cout << "Samples decoded: " << m_len_decoded << ", current time: " << m_current_time_ms << ", bits per sample: "<< m_nBitsPerSample << endl << flush; // append buffer to m_reservoir if( m_len_decoded > 0 ) @@ -291,20 +286,20 @@ void mgFlacDecoder::metadata_callback( const ::FLAC__StreamMetadata *metadata ) if(metadata->type == FLAC__METADATA_TYPE_STREAMINFO) { - m_nTotalSamples = (unsigned)(metadata->data.stream_info.total_samples & 0xfffffffful); + m_nTotalSamples = (long)(metadata->data.stream_info.total_samples & 0xfffffffful); m_nBitsPerSample = metadata->data.stream_info.bits_per_sample; m_nCurrentChannels = metadata->data.stream_info.channels; m_nCurrentSampleRate = metadata->data.stream_info.sample_rate; m_nFrameSize = metadata->data.stream_info.max_framesize; m_nBlockSize = metadata->data.stream_info.max_blocksize; - m_nCurrentSampleRate = (int)get_sample_rate(); + // m_nCurrentSampleRate = (int)get_sample_rate(); m_nCurrentChannels = (int)get_channels(); m_nCurrentBitsPerSample = (int)get_bits_per_sample(); - - // m_nLengthMS = m_nTotalSamples * 10 / (m_nCurrentSampleRate / 100); m_nBlockAlign = (m_nBitsPerSample / 8) * m_nCurrentChannels; - + m_nLengthMS = m_nTotalSamples / m_nCurrentSampleRate; + m_nLengthMS *= 1000; + // m_nAverageBitRate = ((m_pReader->GetLength() * 8) / (m_nLengthMS / 1000) / 1000); // m_nCurrentBitrate = m_nAverageBitRate; } @@ -346,16 +341,27 @@ bool mgFlacDecoder::skip(int seconds, int avail, int rate) if( m_playing ) { - const long target_time_ms = ((seconds-avail)*rate / 1000) + m_current_time_ms; + float bufsecs = (float) avail / (float) (rate * (16 / 8 * 2)); + + const long target_time_ms = ( ( seconds - (int)bufsecs ) * 1000) + m_current_time_ms; const double distance = target_time_ms / (double)m_nLengthMS; - const unsigned target_sample = (unsigned)(distance * (double)m_nTotalSamples); - - if( seek_absolute( (FLAC__uint64)target_sample) ) + const long target_sample = (unsigned)(distance * (double)m_nTotalSamples); + + if( target_sample > 0 ) { - m_current_time_ms = target_time_ms; + if( seek_absolute( (FLAC__uint64)target_sample) ) + { + m_current_time_ms = target_time_ms; + } + else + { + seek_absolute( 0 ); + m_current_time_ms = 0; + } res = true; } } + unlock(); return res; } |