mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-21 04:56:13 +02:00
server buffer
git-svn-id: svn://elaine/murooma/trunk@296 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
parent
35fead6ac0
commit
6354d55f78
5 changed files with 17 additions and 16 deletions
|
@ -47,12 +47,10 @@ void Controller::onMessageReceived(ClientConnection* connection, const BaseMessa
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Controller::start(const std::string& _ip, size_t _port, int _bufferMs)
|
void Controller::start(const std::string& _ip, size_t _port)
|
||||||
{
|
{
|
||||||
bufferMs = _bufferMs;
|
|
||||||
ip = _ip;
|
ip = _ip;
|
||||||
clientConnection = new ClientConnection(this, ip, _port);
|
clientConnection = new ClientConnection(this, ip, _port);
|
||||||
|
|
||||||
controllerThread = new thread(&Controller::worker, this);
|
controllerThread = new thread(&Controller::worker, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +75,7 @@ void Controller::worker()
|
||||||
RequestMsg requestMsg("serverSettings");
|
RequestMsg requestMsg("serverSettings");
|
||||||
shared_ptr<ServerSettings> serverSettings(NULL);
|
shared_ptr<ServerSettings> serverSettings(NULL);
|
||||||
while (!(serverSettings = clientConnection->sendReq<ServerSettings>(&requestMsg, 1000)));
|
while (!(serverSettings = clientConnection->sendReq<ServerSettings>(&requestMsg, 1000)));
|
||||||
cout << "ServerSettings port: " << serverSettings->port << "\n";
|
cout << "ServerSettings buffer: " << serverSettings->bufferMs << "\n";
|
||||||
|
|
||||||
requestMsg.request = "sampleFormat";
|
requestMsg.request = "sampleFormat";
|
||||||
while (!(sampleFormat = clientConnection->sendReq<SampleFormat>(&requestMsg, 1000)));
|
while (!(sampleFormat = clientConnection->sendReq<SampleFormat>(&requestMsg, 1000)));
|
||||||
|
@ -110,7 +108,7 @@ cout << "Received: " << TimeProvider::sinceEpoche<chronos::msec>(TimeProvider::t
|
||||||
}
|
}
|
||||||
|
|
||||||
stream = new Stream(*sampleFormat);
|
stream = new Stream(*sampleFormat);
|
||||||
stream->setBufferLen(bufferMs);
|
stream->setBufferLen(serverSettings->bufferMs);
|
||||||
|
|
||||||
Player player(stream);
|
Player player(stream);
|
||||||
player.start();
|
player.start();
|
||||||
|
|
|
@ -13,7 +13,7 @@ class Controller : public MessageReceiver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Controller();
|
Controller();
|
||||||
void start(const std::string& _ip, size_t _port, int _bufferMs);
|
void start(const std::string& _ip, size_t _port);
|
||||||
void stop();
|
void stop();
|
||||||
virtual void onMessageReceived(ClientConnection* connection, const BaseMessage& baseMessage, char* buffer);
|
virtual void onMessageReceived(ClientConnection* connection, const BaseMessage& baseMessage, char* buffer);
|
||||||
virtual void onException(ClientConnection* connection, const std::exception& exception);
|
virtual void onException(ClientConnection* connection, const std::exception& exception);
|
||||||
|
@ -24,7 +24,6 @@ private:
|
||||||
std::thread* controllerThread;
|
std::thread* controllerThread;
|
||||||
ClientConnection* clientConnection;
|
ClientConnection* clientConnection;
|
||||||
Stream* stream;
|
Stream* stream;
|
||||||
int bufferMs;
|
|
||||||
std::string ip;
|
std::string ip;
|
||||||
std::shared_ptr<SampleFormat> sampleFormat;
|
std::shared_ptr<SampleFormat> sampleFormat;
|
||||||
Decoder* decoder;
|
Decoder* decoder;
|
||||||
|
|
|
@ -24,7 +24,7 @@ int main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int deviceIdx;
|
int deviceIdx;
|
||||||
string ip;
|
string ip;
|
||||||
int bufferMs;
|
// int bufferMs;
|
||||||
size_t port;
|
size_t port;
|
||||||
bool runAsDaemon;
|
bool runAsDaemon;
|
||||||
// string sampleFormat;
|
// string sampleFormat;
|
||||||
|
@ -35,7 +35,7 @@ int main (int argc, char *argv[])
|
||||||
("ip,i", po::value<string>(&ip)->default_value("192.168.0.2"), "server IP")
|
("ip,i", po::value<string>(&ip)->default_value("192.168.0.2"), "server IP")
|
||||||
("soundcard,s", po::value<int>(&deviceIdx)->default_value(-1), "index of the soundcard")
|
("soundcard,s", po::value<int>(&deviceIdx)->default_value(-1), "index of the soundcard")
|
||||||
// ("sampleformat,f", po::value<string>(&sampleFormat)->default_value("48000:16:2"), "sample format")
|
// ("sampleformat,f", po::value<string>(&sampleFormat)->default_value("48000:16:2"), "sample format")
|
||||||
("buffer,b", po::value<int>(&bufferMs)->default_value(300), "buffer size [ms]")
|
// ("buffer,b", po::value<int>(&bufferMs)->default_value(300), "buffer size [ms]")
|
||||||
("daemon,d", po::bool_switch(&runAsDaemon)->default_value(false), "daemonize")
|
("daemon,d", po::bool_switch(&runAsDaemon)->default_value(false), "daemonize")
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ int main (int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
Controller controller;
|
Controller controller;
|
||||||
controller.start(ip, port, bufferMs);
|
controller.start(ip, port);
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
class ServerSettings : public BaseMessage
|
class ServerSettings : public BaseMessage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ServerSettings(size_t _port = 0) : BaseMessage(message_type::serversettings), port(_port)
|
ServerSettings() : BaseMessage(message_type::serversettings)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ public:
|
||||||
|
|
||||||
virtual void read(std::istream& stream)
|
virtual void read(std::istream& stream)
|
||||||
{
|
{
|
||||||
stream.read(reinterpret_cast<char *>(&port), sizeof(int32_t));
|
stream.read(reinterpret_cast<char *>(&bufferMs), sizeof(int32_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual uint32_t getSize()
|
virtual uint32_t getSize()
|
||||||
|
@ -26,12 +26,12 @@ public:
|
||||||
return sizeof(int32_t);
|
return sizeof(int32_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t port;
|
int32_t bufferMs;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void doserialize(std::ostream& stream)
|
virtual void doserialize(std::ostream& stream)
|
||||||
{
|
{
|
||||||
stream.write(reinterpret_cast<char *>(&port), sizeof(int32_t));
|
stream.write(reinterpret_cast<char *>(&bufferMs), sizeof(int32_t));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ int main(int argc, char* argv[])
|
||||||
string fifoName;
|
string fifoName;
|
||||||
string codec;
|
string codec;
|
||||||
bool runAsDaemon;
|
bool runAsDaemon;
|
||||||
|
int32_t bufferMs;
|
||||||
|
|
||||||
po::options_description desc("Allowed options");
|
po::options_description desc("Allowed options");
|
||||||
desc.add_options()
|
desc.add_options()
|
||||||
|
@ -38,6 +39,7 @@ int main(int argc, char* argv[])
|
||||||
("codec,c", po::value<string>(&codec)->default_value("ogg"), "transport codec [ogg|pcm]")
|
("codec,c", po::value<string>(&codec)->default_value("ogg"), "transport codec [ogg|pcm]")
|
||||||
("fifo,f", po::value<string>(&fifoName)->default_value("/tmp/snapfifo"), "name of fifo file")
|
("fifo,f", po::value<string>(&fifoName)->default_value("/tmp/snapfifo"), "name of fifo file")
|
||||||
("daemon,d", po::bool_switch(&runAsDaemon)->default_value(false), "daemonize")
|
("daemon,d", po::bool_switch(&runAsDaemon)->default_value(false), "daemonize")
|
||||||
|
("buffer,b", po::value<int32_t>(&bufferMs)->default_value(500), "buffer [ms]")
|
||||||
;
|
;
|
||||||
|
|
||||||
po::variables_map vm;
|
po::variables_map vm;
|
||||||
|
@ -80,9 +82,11 @@ int main(int argc, char* argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::auto_ptr<ServerSettings> serverSettings(new ServerSettings(port + 1));
|
ServerSettings serverSettings;
|
||||||
|
serverSettings.bufferMs = bufferMs;
|
||||||
|
|
||||||
ControlServer* controlServer = new ControlServer(port);
|
ControlServer* controlServer = new ControlServer(port);
|
||||||
controlServer->setServerSettings(serverSettings.get());
|
controlServer->setServerSettings(&serverSettings);
|
||||||
controlServer->setFormat(&format);
|
controlServer->setFormat(&format);
|
||||||
controlServer->setHeader(encoder->getHeader());
|
controlServer->setHeader(encoder->getHeader());
|
||||||
controlServer->start();
|
controlServer->start();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue