From 513e000e86141ee9cd6a07d2f9046137998659bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Fri, 30 Jun 2023 20:01:11 +0200 Subject: [PATCH] LibAudio: Generalize an encoder interface This interface is very simple for the time being and can be used to provide encoding functionality in a generalized way. Initialization and parameter setting are intentionally not abstracted for now, since this is usually very format-specific. We just need a general interface for writing samples and errorable finalization. --- Userland/Libraries/LibAudio/Encoder.h | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Userland/Libraries/LibAudio/Encoder.h diff --git a/Userland/Libraries/LibAudio/Encoder.h b/Userland/Libraries/LibAudio/Encoder.h new file mode 100644 index 0000000000..2612316dd8 --- /dev/null +++ b/Userland/Libraries/LibAudio/Encoder.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023, kleines Filmröllchen + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include + +namespace Audio { + +class Encoder { +public: + virtual ~Encoder() = default; + + // Encodes the given samples and writes them to the output stream. + // Note that due to format restrictions, not all samples might be written immediately, this is only guaranteed after a call to finalize(). + virtual ErrorOr write_samples(ReadonlySpan samples) = 0; + + // Finalizes the stream, future calls to write_samples() will cause an error. + // 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; +}; + +}