mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-16 22:42:18 +00:00
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.
This commit is contained in:
parent
ee1903e641
commit
f2d9280342
Notes:
sideshowbarker
2024-07-16 19:17:47 +09:00
Author: https://github.com/Zaggy1024
Commit: f2d9280342
Pull-request: https://github.com/SerenityOS/serenity/pull/19802
Reviewed-by: https://github.com/kleinesfilmroellchen ✅
1 changed files with 7 additions and 8 deletions
|
@ -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<i64>(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<i64>(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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue