|
From: Lasse Kärkkäi. <tr...@us...> - 2011-07-06 23:35:20
|
Author: Lasse Karkkainen <tro...@tr...>
Date: Wed May 18 18:52:13 2011 +0300
More precise timecode handling and more tolerance before seeking (workaround for infinite seekloops).
---
game/ffmpeg.cc | 5 +++--
game/ffmpeg.hh | 2 +-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/game/ffmpeg.cc b/game/ffmpeg.cc
index 1be7d7f..e565a04 100644
--- a/game/ffmpeg.cc
+++ b/game/ffmpeg.cc
@@ -280,11 +280,12 @@ void FFmpeg::decodeNextFrame() {
std::vector<int16_t> resampled(AVCODEC_MAX_AUDIO_FRAME_SIZE);
int frames = audio_resample(pResampleCtx, &resampled[0], audioFrames, outsize);
resampled.resize(frames * AUDIO_CHANNELS);
- // Calculate new positions
+ // Use timecode from packet if available
if (packet.time() == packet.time()) m_position = packet.time();
- else m_position += double(resampled.size())/double(audioQueue.getSamplesPerSecond());
// Push to output queue (may block)
audioQueue.push(resampled, m_position);
+ // Increment current time
+ m_position += double(resampled.size())/double(audioQueue.getSamplesPerSecond());
}
// Audio frames are always finished
frameFinished = 1;
diff --git a/game/ffmpeg.hh b/game/ffmpeg.hh
index 8006df8..a94a8b0 100644
--- a/game/ffmpeg.hh
+++ b/game/ffmpeg.hh
@@ -162,7 +162,7 @@ class AudioBuffer {
void setDuration(double seconds) { m_duration = seconds; }
bool wantSeek() {
size_t oldest = m_pos - m_data.size();
- return oldest > 0 && m_posReq < int64_t(oldest);
+ return m_posReq + int64_t(m_sps) * 2.0 /* seconds tolerance */ < int64_t(oldest);
}
private:
bool wantMore() { return int64_t(m_pos) - int64_t(m_data.capacity() / 2) < m_posReq; }
|