From 16d5d29049c08e21f57f7928ceedf40586a2d294 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Sat, 3 Dec 2022 11:10:06 +1100 Subject: Use std::span (backported) and std::byte to make our buffers safer --- src/codecs/include/codec.hpp | 5 +++-- src/codecs/include/mad.hpp | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src/codecs/include') diff --git a/src/codecs/include/codec.hpp b/src/codecs/include/codec.hpp index 764b63fc..bbb621f5 100644 --- a/src/codecs/include/codec.hpp +++ b/src/codecs/include/codec.hpp @@ -9,6 +9,7 @@ #include #include "result.hpp" +#include "span.hpp" namespace codecs { @@ -30,7 +31,7 @@ class ICodec { virtual auto ResetForNewStream() -> void = 0; - virtual auto SetInput(uint8_t* buffer, std::size_t length) -> void = 0; + virtual auto SetInput(cpp::span input) -> void = 0; /* * Returns the codec's next read position within the input buffer. If the @@ -56,7 +57,7 @@ class ICodec { * 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) + virtual auto WriteOutputSamples(cpp::span output) -> std::pair = 0; }; diff --git a/src/codecs/include/mad.hpp b/src/codecs/include/mad.hpp index aa24f3c9..6077314c 100644 --- a/src/codecs/include/mad.hpp +++ b/src/codecs/include/mad.hpp @@ -5,6 +5,7 @@ #include #include "mad.h" +#include "span.hpp" #include "codec.hpp" @@ -18,10 +19,10 @@ class MadMp3Decoder : public ICodec { auto CanHandleFile(const std::string& path) -> bool override; auto GetOutputFormat() -> OutputFormat override; auto ResetForNewStream() -> void override; - auto SetInput(uint8_t* buffer, std::size_t length) -> void override; + auto SetInput(cpp::span input) -> void override; auto GetInputPosition() -> std::size_t override; auto ProcessNextFrame() -> cpp::result override; - auto WriteOutputSamples(uint8_t* output, std::size_t output_length) + auto WriteOutputSamples(cpp::span output) -> std::pair override; private: -- cgit v1.2.3