mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-10 07:36:41 +02:00
send sample format
git-svn-id: svn://elaine/murooma/trunk@238 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
parent
989f986962
commit
b61c6f0217
4 changed files with 22 additions and 5 deletions
|
@ -60,6 +60,8 @@ BaseMessage* ServerConnection::getNextMessage(tcp::socket* socket)
|
|||
message = new PcmChunk(stream_->format, 0);
|
||||
else if (baseMessage.type == message_type::header)
|
||||
message = new HeaderMessage();
|
||||
else if (baseMessage.type == message_type::sampleformat)
|
||||
message = new SampleFormat();
|
||||
if (message != NULL)
|
||||
message->readVec(buffer);
|
||||
return message;
|
||||
|
@ -80,6 +82,12 @@ void ServerConnection::onMessageReceived(BaseMessage* message)
|
|||
{
|
||||
decoder.setHeader((HeaderMessage*)message);
|
||||
}
|
||||
else if (message->type == message_type::sampleformat)
|
||||
{
|
||||
SampleFormat* sampleFormat = (SampleFormat*)message;
|
||||
cout << "SampleFormat rate: " << sampleFormat->rate << ", bits: " << sampleFormat->bits << ", channels: " << sampleFormat->channels << "\n";
|
||||
delete sampleFormat;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -21,7 +21,8 @@ public:
|
|||
enum message_type
|
||||
{
|
||||
header = 0,
|
||||
payload = 1
|
||||
payload = 1,
|
||||
sampleformat = 2
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -5,18 +5,18 @@
|
|||
#include <iostream>
|
||||
|
||||
|
||||
SampleFormat::SampleFormat() : BaseMessage(message_type::payload)
|
||||
SampleFormat::SampleFormat() : BaseMessage(message_type::sampleformat)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SampleFormat::SampleFormat(const std::string& format) : BaseMessage(message_type::payload)
|
||||
SampleFormat::SampleFormat(const std::string& format) : BaseMessage(message_type::sampleformat)
|
||||
{
|
||||
setFormat(format);
|
||||
}
|
||||
|
||||
|
||||
SampleFormat::SampleFormat(uint16_t sampleRate, uint16_t bitsPerSample, uint16_t channelCount) : BaseMessage(message_type::payload)
|
||||
SampleFormat::SampleFormat(uint16_t sampleRate, uint16_t bitsPerSample, uint16_t channelCount) : BaseMessage(message_type::sampleformat)
|
||||
{
|
||||
setFormat(sampleRate, bitsPerSample, channelCount);
|
||||
}
|
||||
|
|
|
@ -107,6 +107,7 @@ public:
|
|||
a.accept(*sock);
|
||||
cout << "New connection: " << sock->remote_endpoint().address().to_string() << "\n";
|
||||
Session* session = new Session(sock);
|
||||
session->send(sampleFormat);
|
||||
session->send(headerChunk);
|
||||
session->start();
|
||||
sessions.insert(shared_ptr<Session>(session));
|
||||
|
@ -116,7 +117,12 @@ public:
|
|||
void setHeader(shared_ptr<HeaderMessage> header)
|
||||
{
|
||||
if (header)
|
||||
headerChunk = shared_ptr<HeaderMessage>(header);
|
||||
headerChunk = header;
|
||||
}
|
||||
|
||||
void setFormat(SampleFormat& format)
|
||||
{
|
||||
sampleFormat = shared_ptr<SampleFormat>(new SampleFormat(format));
|
||||
}
|
||||
|
||||
void send(shared_ptr<BaseMessage> message)
|
||||
|
@ -151,6 +157,7 @@ private:
|
|||
boost::asio::io_service io_service_;
|
||||
unsigned short port_;
|
||||
shared_ptr<HeaderMessage> headerChunk;
|
||||
shared_ptr<SampleFormat> sampleFormat;
|
||||
thread* acceptThread;
|
||||
};
|
||||
|
||||
|
@ -239,6 +246,7 @@ size_t duration = 50;
|
|||
return 1;
|
||||
}
|
||||
|
||||
server->setFormat(format);
|
||||
shared_ptr<HeaderMessage> header(encoder->getHeader());
|
||||
server->setHeader(header);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue