1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:37:34 +00:00

LibAudio: Improve FLAC seeking

"Improve" is an understatement, since this commit makes all FLAC files
seek without errors, mostly with high accuracy, and partially even fast:
- A new generic seek table type is introduced, which keeps an
  always-sorted list of seek points, which allows it to use binary
  search and fast insertion.
- Automatic seek points are inserted according to two heuristics
  (distance between seek points and minimum seek precision), which not
  only builds a seek table for already-played sections of the file, but
  improves seek precision even for files with an existing seek table.
- Manual seeking by skipping frames works properly now and is still used
  as a last resort.
This commit is contained in:
kleines Filmröllchen 2023-03-18 14:12:25 +01:00 committed by Linus Groh
parent c66f7f2e7c
commit 0cd0565abc
7 changed files with 164 additions and 25 deletions

View file

@ -32,6 +32,13 @@ static constexpr StringView no_plugin_error = "No loader plugin available"sv;
// There was no intensive fine-tuning done to determine this value, so improvements may definitely be possible.
constexpr size_t const loader_buffer_size = 8 * KiB;
// Two seek points should ideally not be farther apart than this.
// This variable is a heuristic for seek table-constructing loaders.
constexpr u64 const maximum_seekpoint_distance_ms = 1000;
// Seeking should be at least as precise as this.
// That means: The actual achieved seek position must not be more than this amount of time before the requested seek position.
constexpr u64 const seek_tolerance_ms = 5000;
using LoaderSamples = ErrorOr<FixedArray<Sample>, LoaderError>;
using MaybeLoaderError = ErrorOr<void, LoaderError>;