From b4b411b8a3152667858b3eedca28a39bbca304ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Fri, 18 Aug 2023 21:08:59 +0200 Subject: [PATCH] LibAudio: Add a sample count hinting mechanism to audio encoding --- Userland/Libraries/LibAudio/Encoder.h | 4 ++++ Userland/Utilities/aconv.cpp | 3 +++ 2 files changed, 7 insertions(+) diff --git a/Userland/Libraries/LibAudio/Encoder.h b/Userland/Libraries/LibAudio/Encoder.h index 2612316dd8..9eb3fd7ecb 100644 --- a/Userland/Libraries/LibAudio/Encoder.h +++ b/Userland/Libraries/LibAudio/Encoder.h @@ -24,6 +24,10 @@ public: // This method makes sure that all samples are encoded and written out. // This method is called in the destructor, but since this can error, you should call this function yourself before disposing of the decoder. virtual ErrorOr finalize() = 0; + + // Provides a hint about the total number of samples to the encoder, improving some encoder's performance in various aspects. + // Note that the hint does not have to be fully correct; wrong hints never cause errors, not even indirectly. + virtual void sample_count_hint([[maybe_unused]] size_t sample_count) { } }; } diff --git a/Userland/Utilities/aconv.cpp b/Userland/Utilities/aconv.cpp index 4bdb60437e..1e6b59603f 100644 --- a/Userland/Utilities/aconv.cpp +++ b/Userland/Utilities/aconv.cpp @@ -141,6 +141,9 @@ ErrorOr serenity_main(Main::Arguments arguments) return 1; } + if (writer.has_value()) + (*writer)->sample_count_hint(input_loader->total_samples()); + if (output != "-"sv) out("Writing: \033[s");