mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-24 14:36:15 +02:00
Code comments
This commit is contained in:
parent
4db8696889
commit
c1cb395eb0
6 changed files with 37 additions and 3 deletions
|
@ -1,4 +1,4 @@
|
||||||
VERSION = 0.2.94
|
VERSION = 0.2.95
|
||||||
TARGET = snapclient
|
TARGET = snapclient
|
||||||
SHELL = /bin/bash
|
SHELL = /bin/bash
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
VERSION = 0.2.94
|
VERSION = 0.2.95
|
||||||
TARGET = snapserver
|
TARGET = snapserver
|
||||||
SHELL = /bin/bash
|
SHELL = /bin/bash
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ struct ControlServerSettings
|
||||||
|
|
||||||
/// Forwars PCM data to the connected clients
|
/// Forwars PCM data to the connected clients
|
||||||
/**
|
/**
|
||||||
* Reads PCM data with pipereader, implements PipeListener to get the (encoded) PCM stream.
|
* Reads PCM data using PipeReader, implements PipeListener to get the (encoded) PCM stream.
|
||||||
* Accepts and holds client connections (ServerSession)
|
* Accepts and holds client connections (ServerSession)
|
||||||
* Receives (via the MessageReceiver interface) and answers messages from the clients
|
* Receives (via the MessageReceiver interface) and answers messages from the clients
|
||||||
* Forwards PCM data to the clients
|
* Forwards PCM data to the clients
|
||||||
|
@ -65,8 +65,14 @@ public:
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
|
/// Send a message to all connceted clients
|
||||||
void send(const msg::BaseMessage* message);
|
void send(const msg::BaseMessage* message);
|
||||||
|
|
||||||
|
/// Clients call this when they receive a message. Implementation of MessageReceiver::onMessageReceived
|
||||||
virtual void onMessageReceived(ServerSession* connection, const msg::BaseMessage& baseMessage, char* buffer);
|
virtual void onMessageReceived(ServerSession* connection, const msg::BaseMessage& baseMessage, char* buffer);
|
||||||
|
|
||||||
|
/// Implementation of PipeListener
|
||||||
virtual void onChunkRead(const PipeReader* pipeReader, const msg::PcmChunk* chunk);
|
virtual void onChunkRead(const PipeReader* pipeReader, const msg::PcmChunk* chunk);
|
||||||
virtual void onResync(const PipeReader* pipeReader, double ms);
|
virtual void onResync(const PipeReader* pipeReader, double ms);
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,10 @@
|
||||||
|
|
||||||
class Encoder;
|
class Encoder;
|
||||||
|
|
||||||
|
/// Callback interface for users of Encoder
|
||||||
|
/**
|
||||||
|
* Users of Encoder should implement this to get the encoded PCM data
|
||||||
|
*/
|
||||||
class EncoderListener
|
class EncoderListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -37,9 +41,15 @@ public:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// Abstract Encoder class
|
||||||
|
/**
|
||||||
|
* Stream encoder. PCM chunks are fed into the encoder.
|
||||||
|
* As soon as a frame is encoded, the encoded data is passed to the EncoderListener
|
||||||
|
*/
|
||||||
class Encoder
|
class Encoder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/// ctor. Codec options (E.g. compression level) are passed as string and are codec dependend
|
||||||
Encoder(const std::string& codecOptions = "") : headerChunk_(NULL), codecOptions_(codecOptions)
|
Encoder(const std::string& codecOptions = "") : headerChunk_(NULL), codecOptions_(codecOptions)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -50,6 +60,7 @@ public:
|
||||||
delete headerChunk_;
|
delete headerChunk_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The listener will receive the encoded stream
|
||||||
virtual void init(EncoderListener* listener, const msg::SampleFormat& format)
|
virtual void init(EncoderListener* listener, const msg::SampleFormat& format)
|
||||||
{
|
{
|
||||||
if (codecOptions_ == "")
|
if (codecOptions_ == "")
|
||||||
|
@ -59,6 +70,7 @@ public:
|
||||||
initEncoder();
|
initEncoder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Here the work is done. Encoded data is passed to the EncoderListener.
|
||||||
virtual void encode(const msg::PcmChunk* chunk) = 0;
|
virtual void encode(const msg::PcmChunk* chunk) = 0;
|
||||||
|
|
||||||
virtual std::string name() const = 0;
|
virtual std::string name() const = 0;
|
||||||
|
@ -73,6 +85,7 @@ public:
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Header information needed to decode the data
|
||||||
virtual msg::Header* getHeader() const
|
virtual msg::Header* getHeader() const
|
||||||
{
|
{
|
||||||
return headerChunk_;
|
return headerChunk_;
|
||||||
|
|
|
@ -29,6 +29,11 @@
|
||||||
|
|
||||||
class PipeReader;
|
class PipeReader;
|
||||||
|
|
||||||
|
|
||||||
|
/// Callback interface for users of PipeReader
|
||||||
|
/**
|
||||||
|
* Users of PipeReader should implement this to get the data
|
||||||
|
*/
|
||||||
class PipeListener
|
class PipeListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -47,12 +52,14 @@ public:
|
||||||
class PipeReader : public EncoderListener
|
class PipeReader : public EncoderListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/// ctor. Encoded PCM data is passed to the PipeListener
|
||||||
PipeReader(PipeListener* pipeListener, const msg::SampleFormat& sampleFormat, const std::string& codec, const std::string& fifoName);
|
PipeReader(PipeListener* pipeListener, const msg::SampleFormat& sampleFormat, const std::string& codec, const std::string& fifoName);
|
||||||
virtual ~PipeReader();
|
virtual ~PipeReader();
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
|
/// Implementation of EncoderListener::onChunkEncoded
|
||||||
virtual void onChunkEncoded(const Encoder* encoder, msg::PcmChunk* chunk, double duration);
|
virtual void onChunkEncoded(const Encoder* encoder, msg::PcmChunk* chunk, double duration);
|
||||||
msg::Header* getHeader();
|
msg::Header* getHeader();
|
||||||
|
|
||||||
|
|
|
@ -54,11 +54,16 @@ public:
|
||||||
class ServerSession
|
class ServerSession
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/// ctor. Received message from the client are passed to MessageReceiver
|
||||||
ServerSession(MessageReceiver* receiver, std::shared_ptr<tcp::socket> socket);
|
ServerSession(MessageReceiver* receiver, std::shared_ptr<tcp::socket> socket);
|
||||||
~ServerSession();
|
~ServerSession();
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
|
/// Sends a message to the client (synchronous)
|
||||||
bool send(const msg::BaseMessage* message) const;
|
bool send(const msg::BaseMessage* message) const;
|
||||||
|
|
||||||
|
/// Sends a message to the client (asynchronous)
|
||||||
void add(const std::shared_ptr<const msg::BaseMessage>& message);
|
void add(const std::shared_ptr<const msg::BaseMessage>& message);
|
||||||
|
|
||||||
bool active() const
|
bool active() const
|
||||||
|
@ -66,11 +71,14 @@ public:
|
||||||
return active_;
|
return active_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Client subscribed for the PCM stream, by sending the "startStream" command
|
||||||
|
/// TODO: Currently there is only one stream ("zone")
|
||||||
void setStreamActive(bool active)
|
void setStreamActive(bool active)
|
||||||
{
|
{
|
||||||
streamActive_ = active;
|
streamActive_ = active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Max playout latency. No need to send PCM data that is older than bufferMs
|
||||||
void setBufferMs(size_t bufferMs)
|
void setBufferMs(size_t bufferMs)
|
||||||
{
|
{
|
||||||
bufferMs_ = bufferMs;
|
bufferMs_ = bufferMs;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue