|
From: Lasse Kärkkäi. <tr...@us...> - 2012-07-03 23:40:31
|
Author: Lasse Karkkainen <tro...@tr...>
Date: Wed Mar 21 05:24:47 2012 +0200
Fix handling of odd audio timestamps. Should finally fix all the wrong song playing issues.
---
game/ffmpeg.hh | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/game/ffmpeg.hh b/game/ffmpeg.hh
index 25f15e8..4b0ecf5 100644
--- a/game/ffmpeg.hh
+++ b/game/ffmpeg.hh
@@ -133,9 +133,14 @@ class AudioBuffer {
mutex::scoped_lock l(m_mutex);
while (!condition()) m_cond.wait(l);
if (m_quit) return;
- if (m_pos == 0 && timestamp != 0.0) {
- std::clog << "ffmpeg/info: The first audio frame begins at " << timestamp << " seconds instead of zero." << std::endl;
+ if (timestamp < 0.0) {
+ std::clog << "ffmpeg/warn: Negative audio timestamp " << timestamp << " seconds, frame ignored." << std::endl;
+ return;
+ }
+ // Insert silence at the beginning if the stream starts later than 0.0
+ if (m_pos == 0 && timestamp > 0.0) {
m_pos = timestamp * m_sps;
+ m_data.resize(m_pos, 0);
}
m_data.insert(m_data.end(), data.begin(), data.end());
m_pos += data.size();
|