From 1c0870ee29719b7ef30656df3abb994b26cb3696 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Thu, 27 Aug 2015 21:00:18 -0300 Subject: [PATCH] Pre-emptively work around an issue in libvorbis 1.3.4 and older when rewinding some Ogg Theora videos. May (or may not) also fix crash issues when rewinding Ogg files on some systems... --- src/modules/sound/lullaby/VorbisDecoder.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/modules/sound/lullaby/VorbisDecoder.cpp b/src/modules/sound/lullaby/VorbisDecoder.cpp index 4c2ee13cf..76f053681 100644 --- a/src/modules/sound/lullaby/VorbisDecoder.cpp +++ b/src/modules/sound/lullaby/VorbisDecoder.cpp @@ -210,7 +210,14 @@ int VorbisDecoder::decode() bool VorbisDecoder::seek(float s) { - int result = ov_time_seek(&handle, s); + int result = 0; + + // Avoid ov_time_seek (which calls ov_pcm_seek) when seeking to 0, to avoid + // a bug in libvorbis <= 1.3.4 when seeking to PCM 0 in multiplexed streams. + if (s <= 0.000001) + result = ov_raw_seek(&handle, 0); + else + result = ov_time_seek(&handle, s); if (result == 0) { @@ -223,7 +230,9 @@ bool VorbisDecoder::seek(float s) bool VorbisDecoder::rewind() { - int result = ov_pcm_seek(&handle, 0); + // Avoid ov_time_seek to avoid a bug in libvorbis <= 1.3.4 when seeking to + // PCM 0 in multiplexed streams. + int result = ov_raw_seek(&handle, 0); if (result == 0) {