diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-03-10 11:28:33 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-04-19 10:27:59 +1000 |
| commit | a9531c86a433c8b7ae1f77ff0266c27c39eca7f4 (patch) | |
| tree | 11835552aa2ecb400537781d8eb3851118c47e61 /src/audio/include/stream_info.hpp | |
| parent | 2a46eecdc6334c31cee2b40427d2536b48cbb6be (diff) | |
| download | tangara-fw-a9531c86a433c8b7ae1f77ff0266c27c39eca7f4.tar.gz | |
mostly single task pipeline
Diffstat (limited to 'src/audio/include/stream_info.hpp')
| -rw-r--r-- | src/audio/include/stream_info.hpp | 63 |
1 files changed, 56 insertions, 7 deletions
diff --git a/src/audio/include/stream_info.hpp b/src/audio/include/stream_info.hpp index bf67364f..47f65649 100644 --- a/src/audio/include/stream_info.hpp +++ b/src/audio/include/stream_info.hpp @@ -4,19 +4,68 @@ #include <optional> #include <string> #include <string_view> +#include <variant> -#include "cbor.h" #include "result.hpp" -#include "sys/_stdint.h" +#include "span.hpp" +#include "types.hpp" namespace audio { struct StreamInfo { - std::optional<std::string> path; - std::optional<uint8_t> channels; - std::optional<uint8_t> bits_per_sample; - std::optional<uint16_t> sample_rate; - std::optional<size_t> chunk_size; + // The number of bytes that are available for consumption within this + // stream's buffer. + std::size_t bytes_in_stream; + + // The total length of this stream, in case its source is finite (e.g. a + // file on disk). May be absent for endless streams (internet streams, + // generated audio, etc.) + std::optional<std::size_t> length_bytes; + + struct Encoded { + // The codec that this stream is associated with. + codecs::StreamType type; + + bool operator==(const Encoded&) const = default; + }; + + struct Pcm { + // Number of channels in this stream. + uint8_t channels; + // Number of bits per sample. + uint8_t bits_per_sample; + // The sample rate. + uint16_t sample_rate; + + bool operator==(const Pcm&) const = default; + }; + + std::variant<Encoded, Pcm> data; + + bool operator==(const StreamInfo&) const = default; +}; + +class MutableStream { + public: + StreamInfo* info; + cpp::span<std::byte> data; + + MutableStream(StreamInfo* i, cpp::span<std::byte> d) + : info(i), data(d) {} +}; + +/* + * A byte buffer + associated metadata, which is not allowed to modify any of + * the underlying data. + */ +class Stream { + public: + explicit Stream(const MutableStream& s) : info(*s.info), data(s.data) {} + + const StreamInfo& info; + // `data` itself left mutable for signalling how much of the stream was + // consumed + cpp::span<const std::byte> data; }; } // namespace audio |
