From f2d9280342edccc8b79ae352d2815d55ca535d2e Mon Sep 17 00:00:00 2001 From: Zaggy1024 Date: Wed, 5 Jul 2023 02:23:07 -0500 Subject: [PATCH] LibAudio: Skip FLAC samples even if already close to seek target Previously, the FLAC loader would not skip samples to reach its seek target if it saw that the current sample in the loader is closer to the target than the seek point it finds. This prevents seeking forward when there are no seek points past the current position. --- Userland/Libraries/LibAudio/FlacLoader.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibAudio/FlacLoader.cpp b/Userland/Libraries/LibAudio/FlacLoader.cpp index e37f1b297c..6306d35d37 100644 --- a/Userland/Libraries/LibAudio/FlacLoader.cpp +++ b/Userland/Libraries/LibAudio/FlacLoader.cpp @@ -300,15 +300,14 @@ MaybeLoaderError FlacLoaderPlugin::seek(int int_sample_index) // When a small seek happens, we may already be closer to the target than the seekpoint. if (sample_index - target_seekpoint.sample_index > sample_index - m_loaded_samples) { - dbgln_if(AFLACLOADER_DEBUG, "Close enough to target ({} samples): not seeking", sample_index - m_loaded_samples); - return {}; + dbgln_if(AFLACLOADER_DEBUG, "Close enough to target ({} samples): ignoring seek point", sample_index - m_loaded_samples); + } else { + dbgln_if(AFLACLOADER_DEBUG, "Seeking to seektable: sample index {}, byte offset {}", target_seekpoint.sample_index, target_seekpoint.byte_offset); + auto position = target_seekpoint.byte_offset + m_data_start_location; + if (m_stream->seek(static_cast(position), SeekMode::SetPosition).is_error()) + return LoaderError { LoaderError::Category::IO, m_loaded_samples, DeprecatedString::formatted("Invalid seek position {}", position) }; + m_loaded_samples = target_seekpoint.sample_index; } - - dbgln_if(AFLACLOADER_DEBUG, "Seeking to seektable: sample index {}, byte offset {}", target_seekpoint.sample_index, target_seekpoint.byte_offset); - auto position = target_seekpoint.byte_offset + m_data_start_location; - if (m_stream->seek(static_cast(position), SeekMode::SetPosition).is_error()) - return LoaderError { LoaderError::Category::IO, m_loaded_samples, DeprecatedString::formatted("Invalid seek position {}", position) }; - m_loaded_samples = target_seekpoint.sample_index; } // Skip frames until we're within the seek tolerance.