/* * Copyright 2023 jacqueline * * SPDX-License-Identifier: GPL-3.0-only */ #pragma once #include #include #include "audio/audio_events.hpp" #include "audio/audio_sink.hpp" #include "audio/audio_source.hpp" #include "audio/processor.hpp" #include "codec.hpp" #include "database/track.hpp" #include "sample.hpp" #include "types.hpp" namespace audio { /* * Handle to a persistent task that takes encoded bytes from arbitrary sources, * decodes them into sample::Sample (normalised to 16 bit signed PCM), and then * streams them onward to the sample processor. */ class Decoder { public: static auto Start(std::shared_ptr) -> Decoder*; auto open(std::shared_ptr) -> void; Decoder(const Decoder&) = delete; Decoder& operator=(const Decoder&) = delete; private: Decoder(std::shared_ptr); auto Main() -> void; auto prepareDecode(std::shared_ptr) -> void; auto continueDecode() -> bool; auto finishDecode(bool cancel) -> void; std::shared_ptr processor_; // Struct used with the next_stream_ queue. struct NextStream { std::shared_ptr stream; }; QueueHandle_t next_stream_; std::shared_ptr stream_; std::unique_ptr codec_; std::shared_ptr track_; std::span codec_buffer_; std::span leftover_samples_; }; } // namespace audio