mirror of
https://github.com/badaix/snapcast.git
synced 2025-06-15 09:11:42 +02:00
Fix tidy issue
This commit is contained in:
parent
ea091483fb
commit
7d7ef5bf10
2 changed files with 49 additions and 6 deletions
|
@ -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;
|
std::ignore = encoder;
|
||||||
// LOG(TRACE, LOG_TAG) << "onChunkEncoded: " << getName() << ", duration: " << duration
|
// LOG(TRACE, LOG_TAG) << "onChunkEncoded: " << getName() << ", duration: " << duration
|
||||||
|
|
|
@ -104,24 +104,28 @@ class PcmStream : public std::enable_shared_from_this<PcmStream>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// Callback interface for users of PcmStream
|
/// 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
|
class Listener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/// Properties of @p pcmStream changed to @p properties
|
||||||
virtual void onPropertiesChanged(const PcmStream* pcmStream, const Properties& properties) = 0;
|
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;
|
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;
|
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;
|
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;
|
virtual void onResync(const PcmStream* pcmStream, double ms) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
using ResultHandler = std::function<void(const snapcast::ErrorCode& ec)>;
|
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);
|
PcmStream(PcmStream::Listener* pcmListener, boost::asio::io_context& ioc, const ServerSettings& server_settings, const StreamUri& uri);
|
||||||
|
/// d'tor
|
||||||
virtual ~PcmStream();
|
virtual ~PcmStream();
|
||||||
|
|
||||||
/// Start the stream reader, init the encoder and optionally the stream control
|
/// Start the stream reader, init the encoder and optionally the stream control
|
||||||
|
@ -143,43 +147,67 @@ public:
|
||||||
/// @return the codec of the stream
|
/// @return the codec of the stream
|
||||||
virtual std::string getCodec() const;
|
virtual std::string getCodec() const;
|
||||||
|
|
||||||
|
/// @return stream properties
|
||||||
const Properties& getProperties() const;
|
const Properties& getProperties() const;
|
||||||
|
|
||||||
// Setter for properties
|
// Setter for properties
|
||||||
|
/// Set shuffle property
|
||||||
virtual void setShuffle(bool shuffle, ResultHandler handler);
|
virtual void setShuffle(bool shuffle, ResultHandler handler);
|
||||||
|
/// Set loop property
|
||||||
virtual void setLoopStatus(LoopStatus status, ResultHandler handler);
|
virtual void setLoopStatus(LoopStatus status, ResultHandler handler);
|
||||||
|
/// Set volume property
|
||||||
virtual void setVolume(uint16_t volume, ResultHandler handler);
|
virtual void setVolume(uint16_t volume, ResultHandler handler);
|
||||||
|
/// Set mute property
|
||||||
virtual void setMute(bool mute, ResultHandler handler);
|
virtual void setMute(bool mute, ResultHandler handler);
|
||||||
|
/// Set playback rate property
|
||||||
virtual void setRate(float rate, ResultHandler handler);
|
virtual void setRate(float rate, ResultHandler handler);
|
||||||
|
|
||||||
// Control commands
|
// Control commands
|
||||||
|
/// Set position
|
||||||
virtual void setPosition(std::chrono::milliseconds position, ResultHandler handler);
|
virtual void setPosition(std::chrono::milliseconds position, ResultHandler handler);
|
||||||
|
/// Seek
|
||||||
virtual void seek(std::chrono::milliseconds offset, ResultHandler handler);
|
virtual void seek(std::chrono::milliseconds offset, ResultHandler handler);
|
||||||
|
/// Play next
|
||||||
virtual void next(ResultHandler handler);
|
virtual void next(ResultHandler handler);
|
||||||
|
/// Play previous
|
||||||
virtual void previous(ResultHandler handler);
|
virtual void previous(ResultHandler handler);
|
||||||
|
/// Pause
|
||||||
virtual void pause(ResultHandler handler);
|
virtual void pause(ResultHandler handler);
|
||||||
|
/// Toggle play/pause
|
||||||
virtual void playPause(ResultHandler handler);
|
virtual void playPause(ResultHandler handler);
|
||||||
|
/// Stop
|
||||||
virtual void stop(ResultHandler handler);
|
virtual void stop(ResultHandler handler);
|
||||||
|
/// Play
|
||||||
virtual void play(ResultHandler handler);
|
virtual void play(ResultHandler handler);
|
||||||
|
|
||||||
|
/// Get stream reader state (idle/playing)
|
||||||
virtual ReaderState getState() const;
|
virtual ReaderState getState() const;
|
||||||
|
/// Stream description to json
|
||||||
virtual json toJson() const;
|
virtual json toJson() const;
|
||||||
|
|
||||||
|
/// Add a pcm listener
|
||||||
void addListener(PcmStream::Listener* pcmListener);
|
void addListener(PcmStream::Listener* pcmListener);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/// Stream is active (started?
|
||||||
std::atomic<bool> active_;
|
std::atomic<bool> active_;
|
||||||
|
|
||||||
/// check if the volume of the \p chunk is below the silence threshold
|
/// check if the volume of the \p chunk is below the silence threshold
|
||||||
bool isSilent(const msg::PcmChunk& chunk) const;
|
bool isSilent(const msg::PcmChunk& chunk) const;
|
||||||
|
|
||||||
|
/// Set reader state
|
||||||
void setState(ReaderState newState);
|
void setState(ReaderState newState);
|
||||||
|
/// A @p chunk has been read
|
||||||
void chunkRead(const msg::PcmChunk& chunk);
|
void chunkRead(const msg::PcmChunk& chunk);
|
||||||
|
/// Announce resync
|
||||||
void resync(const std::chrono::nanoseconds& duration);
|
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);
|
void setProperties(const Properties& properties);
|
||||||
|
|
||||||
|
/// Poll stream properties
|
||||||
void pollProperties();
|
void pollProperties();
|
||||||
|
|
||||||
// script callbacks
|
// script callbacks
|
||||||
|
@ -192,20 +220,35 @@ protected:
|
||||||
/// Send request to stream control script
|
/// Send request to stream control script
|
||||||
void sendRequest(const std::string& method, const jsonrpcpp::Parameter& params, ResultHandler handler);
|
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_;
|
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_;
|
std::chrono::time_point<std::chrono::steady_clock> tvEncodedChunk_;
|
||||||
|
/// Listeners for PCM events
|
||||||
std::vector<PcmStream::Listener*> pcmListeners_;
|
std::vector<PcmStream::Listener*> pcmListeners_;
|
||||||
|
/// URI of this stream
|
||||||
StreamUri uri_;
|
StreamUri uri_;
|
||||||
|
/// Sampleformat of this stream
|
||||||
SampleFormat sampleFormat_;
|
SampleFormat sampleFormat_;
|
||||||
|
/// Chunk read duration
|
||||||
size_t chunk_ms_;
|
size_t chunk_ms_;
|
||||||
|
/// Encoder (PCM, flac, vorbus, opus)
|
||||||
std::unique_ptr<encoder::Encoder> encoder_;
|
std::unique_ptr<encoder::Encoder> encoder_;
|
||||||
|
/// Name of this stream
|
||||||
std::string name_;
|
std::string name_;
|
||||||
|
/// Stream state
|
||||||
std::atomic<ReaderState> state_;
|
std::atomic<ReaderState> state_;
|
||||||
|
/// Stream properies
|
||||||
Properties properties_;
|
Properties properties_;
|
||||||
|
/// Server settings
|
||||||
ServerSettings server_settings_;
|
ServerSettings server_settings_;
|
||||||
|
/// Stream controller (play, pause, next, ...)
|
||||||
std::unique_ptr<StreamControl> stream_ctrl_;
|
std::unique_ptr<StreamControl> stream_ctrl_;
|
||||||
|
/// Id of the last request sent to the stream controller
|
||||||
std::atomic<int> req_id_;
|
std::atomic<int> req_id_;
|
||||||
|
/// Property poll timer
|
||||||
boost::asio::steady_timer property_timer_;
|
boost::asio::steady_timer property_timer_;
|
||||||
|
/// Protect properties
|
||||||
mutable std::recursive_mutex mutex_;
|
mutable std::recursive_mutex mutex_;
|
||||||
/// If a chunk's max amplitude is below the threshold, it is considered silent
|
/// If a chunk's max amplitude is below the threshold, it is considered silent
|
||||||
int32_t silence_threshold_ = 0;
|
int32_t silence_threshold_ = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue