Skip to content

Commit

Permalink
Fix tidy issue
Browse files Browse the repository at this point in the history
  • Loading branch information
badaix committed Feb 9, 2025
1 parent c765dfa commit 659ffe0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
2 changes: 1 addition & 1 deletion server/streamreader/pcm_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ void PcmStream::setState(ReaderState newState)
}


void PcmStream::chunkEncoded(const encoder::Encoder& encoder, std::shared_ptr<msg::PcmChunk> chunk, double duration)
void PcmStream::chunkEncoded(const encoder::Encoder& encoder, const std::shared_ptr<msg::PcmChunk>& chunk, double duration)
{
std::ignore = encoder;
// LOG(TRACE, LOG_TAG) << "onChunkEncoded: " << getName() << ", duration: " << duration
Expand Down
53 changes: 48 additions & 5 deletions server/streamreader/pcm_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,28 @@ class PcmStream : public std::enable_shared_from_this<PcmStream>
{
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<msg::PcmChunk> 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<void(const snapcast::ErrorCode& ec)>;

/// 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
Expand All @@ -143,43 +147,67 @@ class PcmStream : public std::enable_shared_from_this<PcmStream>
/// @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<bool> 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<msg::PcmChunk> 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<msg::PcmChunk>& chunk, double duration);

/// Set stream properties
void setProperties(const Properties& properties);

/// Poll stream properties
void pollProperties();

// script callbacks
Expand All @@ -192,20 +220,35 @@ class PcmStream : public std::enable_shared_from_this<PcmStream>
/// 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<boost::asio::any_io_executor> strand_;
/// Current abolute time of the last encoded chunk
std::chrono::time_point<std::chrono::steady_clock> tvEncodedChunk_;
/// Listeners for PCM events
std::vector<PcmStream::Listener*> 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::Encoder> encoder_;
/// Name of this stream
std::string name_;
/// Stream state
std::atomic<ReaderState> state_;
/// Stream properies
Properties properties_;
/// Server settings
ServerSettings server_settings_;
/// Stream controller (play, pause, next, ...)
std::unique_ptr<StreamControl> stream_ctrl_;
/// Id of the last request sent to the stream controller
std::atomic<int> 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;
Expand Down

0 comments on commit 659ffe0

Please sign in to comment.