From 222c810b07ffc635fc7908d121e97e4d65ccc5c8 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Fri, 2 Dec 2022 13:39:00 +1100 Subject: fix build errors --- src/codecs/include/codec.hpp | 70 ++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 31 deletions(-) (limited to 'src/codecs/include/codec.hpp') diff --git a/src/codecs/include/codec.hpp b/src/codecs/include/codec.hpp index 8e82bd71..764b63fc 100644 --- a/src/codecs/include/codec.hpp +++ b/src/codecs/include/codec.hpp @@ -1,18 +1,17 @@ #pragma once #include + #include #include +#include +#include +#include #include "result.hpp" namespace codecs { -enum CreateCodecError { UNKNOWN_EXTENSION }; - -auto CreateCodecForFile(const std::string& extension) - -> cpp::result, CreateCodecError>; - class ICodec { public: virtual ~ICodec() {} @@ -22,39 +21,48 @@ class ICodec { struct OutputFormat { uint8_t num_channels; uint8_t bits_per_sample; - int sample_rate_hz; + uint32_t sample_rate_hz; }; virtual auto GetOutputFormat() -> OutputFormat = 0; - enum ProcessingError {}; - - struct Result { - bool need_more_input; - /* - * For need_more_input, this is how far we got in the input buffer - * before we were unable to process more data. Any remaining data in the - * buffer should be moved to the start before the next call. - */ - std::size_t input_processed; - - bool flush_output; - /* - * For flush_output, this is how far we got in the output buffer before - * we ran out of space for samples. The caller should flush this many - * bytes downstream. - */ - std::size_t output_written; - }; + enum ProcessingError { MALFORMED_DATA }; virtual auto ResetForNewStream() -> void = 0; - virtual auto SetInput(uint8_t* buffer, std::size_t length) = 0; - virtual auto Process(uint8_t* output, std::size_t output_length) - -> cpp::result = 0; - - virtual auto GetOutputProcessed() -> std::size_t; - = 0; + virtual auto SetInput(uint8_t* buffer, std::size_t length) -> void = 0; + + /* + * Returns the codec's next read position within the input buffer. If the + * codec is out of usable data, but there is still some data left in the + * stream, that data should be prepended to the next input buffer. + */ + virtual auto GetInputPosition() -> std::size_t = 0; + + /* + * Read one frame (or equivalent discrete chunk) from the input, and + * synthesize output samples for it. + * + * Returns true if we are out of usable data from the input stream, or false + * otherwise. + */ + virtual auto ProcessNextFrame() -> cpp::result = 0; + + /* + * Writes PCM samples to the given output buffer. + * + * Returns the number of bytes that were written, and true if all of the + * samples synthesized from the last call to `ProcessNextFrame` have been + * written. If this returns false, then this method should be called again + * after flushing the output buffer. + */ + virtual auto WriteOutputSamples(uint8_t* output, std::size_t output_length) + -> std::pair = 0; }; +enum CreateCodecError { UNKNOWN_EXTENSION }; + +auto CreateCodecForFile(const std::string& extension) + -> cpp::result, CreateCodecError>; + } // namespace codecs -- cgit v1.2.3