mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-22 13:36:18 +02:00
encoder header is shared ptr
This commit is contained in:
parent
bfdca3038d
commit
d44232114a
7 changed files with 12 additions and 15 deletions
|
@ -56,8 +56,6 @@ public:
|
||||||
|
|
||||||
virtual ~Encoder()
|
virtual ~Encoder()
|
||||||
{
|
{
|
||||||
if (headerChunk_ != NULL)
|
|
||||||
delete headerChunk_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The listener will receive the encoded stream
|
/// The listener will receive the encoded stream
|
||||||
|
@ -86,7 +84,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Header information needed to decode the data
|
/// Header information needed to decode the data
|
||||||
virtual msg::Header* getHeader() const
|
virtual std::shared_ptr<msg::Header> getHeader() const
|
||||||
{
|
{
|
||||||
return headerChunk_;
|
return headerChunk_;
|
||||||
}
|
}
|
||||||
|
@ -95,7 +93,7 @@ protected:
|
||||||
virtual void initEncoder() = 0;
|
virtual void initEncoder() = 0;
|
||||||
|
|
||||||
SampleFormat sampleFormat_;
|
SampleFormat sampleFormat_;
|
||||||
msg::Header* headerChunk_;
|
std::shared_ptr<msg::Header> headerChunk_;
|
||||||
EncoderListener* listener_;
|
EncoderListener* listener_;
|
||||||
std::string codecOptions_;
|
std::string codecOptions_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,7 +28,7 @@ using namespace std;
|
||||||
FlacEncoder::FlacEncoder(const std::string& codecOptions) : Encoder(codecOptions), encoder_(NULL), pcmBufferSize_(0), encodedSamples_(0)
|
FlacEncoder::FlacEncoder(const std::string& codecOptions) : Encoder(codecOptions), encoder_(NULL), pcmBufferSize_(0), encodedSamples_(0)
|
||||||
{
|
{
|
||||||
flacChunk_ = new msg::PcmChunk();
|
flacChunk_ = new msg::PcmChunk();
|
||||||
headerChunk_ = new msg::Header("flac");
|
headerChunk_.reset(new msg::Header("flac"));
|
||||||
pcmBuffer_ = (FLAC__int32*)malloc(pcmBufferSize_ * sizeof(FLAC__int32));
|
pcmBuffer_ = (FLAC__int32*)malloc(pcmBufferSize_ * sizeof(FLAC__int32));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -223,7 +223,7 @@ void OggEncoder::initEncoder()
|
||||||
* audio data will start on a new page, as per spec
|
* audio data will start on a new page, as per spec
|
||||||
*/
|
*/
|
||||||
size_t pos(0);
|
size_t pos(0);
|
||||||
headerChunk_ = new msg::Header("ogg");
|
headerChunk_.reset(new msg::Header("ogg"));
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
int result = ogg_stream_flush(&os,&og);
|
int result = ogg_stream_flush(&os,&og);
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
PcmEncoder::PcmEncoder(const std::string& codecOptions) : Encoder(codecOptions)
|
PcmEncoder::PcmEncoder(const std::string& codecOptions) : Encoder(codecOptions)
|
||||||
{
|
{
|
||||||
headerChunk_ = new msg::Header("pcm");
|
headerChunk_.reset(new msg::Header("pcm"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ PcmReader::~PcmReader()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
msg::Header* PcmReader::getHeader()
|
std::shared_ptr<msg::Header> PcmReader::getHeader()
|
||||||
{
|
{
|
||||||
return encoder_->getHeader();
|
return encoder_->getHeader();
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ public:
|
||||||
|
|
||||||
/// Implementation of EncoderListener::onChunkEncoded
|
/// 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);
|
||||||
virtual msg::Header* getHeader();
|
virtual std::shared_ptr<msg::Header> getHeader();
|
||||||
|
|
||||||
virtual const ReaderUri& getUri() const;
|
virtual const ReaderUri& getUri() const;
|
||||||
virtual const std::string& getName() const;
|
virtual const std::string& getName() const;
|
||||||
|
|
|
@ -217,8 +217,7 @@ void StreamServer::onMessageReceived(ControlSession* controlSession, const std::
|
||||||
StreamSession* session = getStreamSession(request.getParam("client").get<string>());
|
StreamSession* session = getStreamSession(request.getParam("client").get<string>());
|
||||||
if (session != NULL)
|
if (session != NULL)
|
||||||
{
|
{
|
||||||
msg::Header* headerChunk = stream->getHeader();
|
session->add(stream->getHeader());
|
||||||
session->send(headerChunk);
|
|
||||||
session->setPcmReader(stream);
|
session->setPcmReader(stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -287,9 +286,9 @@ void StreamServer::onMessageReceived(StreamSession* connection, const msg::BaseM
|
||||||
{
|
{
|
||||||
// std::lock_guard<std::mutex> mlock(mutex_);
|
// std::lock_guard<std::mutex> mlock(mutex_);
|
||||||
//TODO: use the correct stream
|
//TODO: use the correct stream
|
||||||
msg::Header* headerChunk = streamManager_->getDefaultStream()->getHeader();
|
auto headerChunk = streamManager_->getDefaultStream()->getHeader();
|
||||||
headerChunk->refersTo = requestMsg.id;
|
headerChunk->refersTo = requestMsg.id;
|
||||||
connection->send(headerChunk);
|
connection->send(headerChunk.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (baseMessage.type == message_type::kHello)
|
else if (baseMessage.type == message_type::kHello)
|
||||||
|
@ -319,8 +318,8 @@ void StreamServer::onMessageReceived(StreamSession* connection, const msg::BaseM
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: use the correct stream
|
//TODO: use the correct stream
|
||||||
msg::Header* headerChunk = streamManager_->getDefaultStream()->getHeader();
|
auto headerChunk = streamManager_->getDefaultStream()->getHeader();
|
||||||
connection->send(headerChunk);
|
connection->send(headerChunk.get());
|
||||||
|
|
||||||
|
|
||||||
ClientInfoPtr client = Config::instance().getClientInfo(connection->macAddress);
|
ClientInfoPtr client = Config::instance().getClientInfo(connection->macAddress);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue