From 659ffe080c86859ea196885d0f3275aab3d72270 Mon Sep 17 00:00:00 2001 From: badaix Date: Sun, 9 Feb 2025 19:56:46 +0100 Subject: [PATCH] Fix tidy issue --- server/streamreader/pcm_stream.cpp | 2 +- server/streamreader/pcm_stream.hpp | 53 +++++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/server/streamreader/pcm_stream.cpp b/server/streamreader/pcm_stream.cpp index 02b4ea8d..c2126ea3 100644 --- a/server/streamreader/pcm_stream.cpp +++ b/server/streamreader/pcm_stream.cpp @@ -306,7 +306,7 @@ void PcmStream::setState(ReaderState newState) } -void PcmStream::chunkEncoded(const encoder::Encoder& encoder, std::shared_ptr chunk, double duration) +void PcmStream::chunkEncoded(const encoder::Encoder& encoder, const std::shared_ptr& chunk, double duration) { std::ignore = encoder; // LOG(TRACE, LOG_TAG) << "onChunkEncoded: " << getName() << ", duration: " << duration diff --git a/server/streamreader/pcm_stream.hpp b/server/streamreader/pcm_stream.hpp index 5148c5ac..5827dd53 100644 --- a/server/streamreader/pcm_stream.hpp +++ b/server/streamreader/pcm_stream.hpp @@ -104,24 +104,28 @@ class PcmStream : public std::enable_shared_from_this { public: /// Callback interface for users of PcmStream - /** - * Users of PcmStream should implement this to get the data - */ + /// Users of PcmStream should implement this to get the data class Listener { public: + /// Properties of @p pcmStream changed to @p properties virtual void onPropertiesChanged(const PcmStream* pcmStream, const Properties& properties) = 0; + /// State of @p pcmStream changed to @p state virtual void onStateChanged(const PcmStream* pcmStream, ReaderState state) = 0; + /// Chunk @p chunk of @p pcmStream has read virtual void onChunkRead(const PcmStream* pcmStream, const msg::PcmChunk& chunk) = 0; + /// Chunk @p chunk with duration @p duration of stream @pcmStream has been encoded virtual void onChunkEncoded(const PcmStream* pcmStream, std::shared_ptr chunk, double duration) = 0; + /// Stream @p pcmStream muissed to read audio with duration @p ms virtual void onResync(const PcmStream* pcmStream, double ms) = 0; }; using ResultHandler = std::function; - /// ctor. Encoded PCM data is passed to the PcmStream::Listener + /// c'tor. Encoded PCM data is passed to the PcmStream::Listener PcmStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri); + /// d'tor virtual ~PcmStream(); /// Start the stream reader, init the encoder and optionally the stream control @@ -143,43 +147,67 @@ class PcmStream : public std::enable_shared_from_this /// @return the codec of the stream virtual std::string getCodec() const; + /// @return stream properties const Properties& getProperties() const; // Setter for properties + /// Set shuffle property virtual void setShuffle(bool shuffle, ResultHandler handler); + /// Set loop property virtual void setLoopStatus(LoopStatus status, ResultHandler handler); + /// Set volume property virtual void setVolume(uint16_t volume, ResultHandler handler); + /// Set mute property virtual void setMute(bool mute, ResultHandler handler); + /// Set playback rate property virtual void setRate(float rate, ResultHandler handler); // Control commands + /// Set position virtual void setPosition(std::chrono::milliseconds position, ResultHandler handler); + /// Seek virtual void seek(std::chrono::milliseconds offset, ResultHandler handler); + /// Play next virtual void next(ResultHandler handler); + /// Play previous virtual void previous(ResultHandler handler); + /// Pause virtual void pause(ResultHandler handler); + /// Toggle play/pause virtual void playPause(ResultHandler handler); + /// Stop virtual void stop(ResultHandler handler); + /// Play virtual void play(ResultHandler handler); + /// Get stream reader state (idle/playing) virtual ReaderState getState() const; + /// Stream description to json virtual json toJson() const; + /// Add a pcm listener void addListener(PcmStream::Listener* pcmListener); protected: + /// Stream is active (started? std::atomic active_; /// check if the volume of the \p chunk is below the silence threshold bool isSilent(const msg::PcmChunk& chunk) const; + /// Set reader state void setState(ReaderState newState); + /// A @p chunk has been read void chunkRead(const msg::PcmChunk& chunk); + /// Announce resync void resync(const std::chrono::nanoseconds& duration); - void chunkEncoded(const encoder::Encoder& encoder, std::shared_ptr chunk, double duration); + /// Called by @p encoder when a @p chunk of @p duration ms has been encoded + void chunkEncoded(const encoder::Encoder& encoder, const std::shared_ptr& chunk, double duration); + /// Set stream properties void setProperties(const Properties& properties); + /// Poll stream properties void pollProperties(); // script callbacks @@ -192,20 +220,35 @@ class PcmStream : public std::enable_shared_from_this /// Send request to stream control script void sendRequest(const std::string& method, const jsonrpcpp::Parameter& params, ResultHandler handler); + /// Executor for synchronous IO boost::asio::strand strand_; + /// Current abolute time of the last encoded chunk std::chrono::time_point tvEncodedChunk_; + /// Listeners for PCM events std::vector pcmListeners_; + /// URI of this stream StreamUri uri_; + /// Sampleformat of this stream SampleFormat sampleFormat_; + /// Chunk read duration size_t chunk_ms_; + /// Encoder (PCM, flac, vorbus, opus) std::unique_ptr encoder_; + /// Name of this stream std::string name_; + /// Stream state std::atomic state_; + /// Stream properies Properties properties_; + /// Server settings ServerSettings server_settings_; + /// Stream controller (play, pause, next, ...) std::unique_ptr stream_ctrl_; + /// Id of the last request sent to the stream controller std::atomic req_id_; + /// Property poll timer boost::asio::steady_timer property_timer_; + /// Protect properties mutable std::recursive_mutex mutex_; /// If a chunk's max amplitude is below the threshold, it is considered silent int32_t silence_threshold_ = 0;