From 9b1b401dcb986a26d10bcc898be670653acc2d3f Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 26 Jul 2023 17:11:23 +1000 Subject: big cleanup of new encoder + stream buffer types --- src/audio/include/stream_info.hpp | 72 +++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 30 deletions(-) (limited to 'src/audio/include/stream_info.hpp') diff --git a/src/audio/include/stream_info.hpp b/src/audio/include/stream_info.hpp index 00aa1110..77789c24 100644 --- a/src/audio/include/stream_info.hpp +++ b/src/audio/include/stream_info.hpp @@ -7,6 +7,7 @@ #pragma once #include +#include #include #include #include @@ -25,25 +26,26 @@ namespace audio { -struct StreamInfo { +class StreamInfo { + public: + StreamInfo() : bytes_in_stream_(0), total_length_bytes_(), format_() {} + // The number of bytes that are available for consumption within this // stream's buffer. - std::size_t bytes_in_stream{0}; - - bool is_producer_finished = true; - - bool is_consumer_finished = true; - - std::optional duration_seconds; + auto bytes_in_stream() -> std::size_t& { return bytes_in_stream_; } + auto bytes_in_stream() const -> std::size_t { return bytes_in_stream_; } - std::optional seek_to_seconds{}; + auto total_length_bytes() -> std::optional& { + return total_length_bytes_; + } + auto total_length_bytes() const -> std::optional { + return total_length_bytes_; + } struct Encoded { // The codec that this stream is associated with. codecs::StreamType type; - std::optional duration_bytes; - bool operator==(const Encoded&) const = default; }; @@ -59,33 +61,48 @@ struct StreamInfo { }; typedef std::variant Format; - Format format{}; + auto format() const -> const Format& { return format_; } + auto set_format(Format f) -> void { format_ = f; } + + template + auto format_as() const -> std::optional { + if (std::holds_alternative(format_)) { + return std::get(format_); + } + return {}; + } bool operator==(const StreamInfo&) const = default; + + private: + std::size_t bytes_in_stream_; + std::optional total_length_bytes_; + Format format_{}; }; +class InputStream; +class OutputStream; + class RawStream { public: - StreamInfo* info; - cpp::span data; + explicit RawStream(std::size_t size); + ~RawStream(); - RawStream(StreamInfo* i, cpp::span d) : info(i), data(d) {} + auto info() -> StreamInfo& { return info_; } + auto data() -> cpp::span; + + private: + StreamInfo info_; + std::size_t buffer_size_; + std::byte* buffer_; }; -/* - * A byte buffer + associated metadata, which is not allowed to modify any of - * the underlying data. - */ class InputStream { public: explicit InputStream(RawStream* s) : raw_(s) {} void consume(std::size_t bytes) const; - bool is_producer_finished() const; - - void mark_consumer_finished() const; - const StreamInfo& info() const; cpp::span data() const; @@ -100,18 +117,13 @@ class OutputStream { void add(std::size_t bytes) const; - bool prepare(const StreamInfo::Format& new_format); - - void set_duration(std::size_t); + void prepare(const StreamInfo::Format& new_format, + std::optional length); const StreamInfo& info() const; cpp::span data() const; - bool is_consumer_finished() const; - - void mark_producer_finished() const; - private: RawStream* raw_; }; -- cgit v1.2.3