server buffer

git-svn-id: svn://elaine/murooma/trunk@296 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
(no author) 2014-09-25 16:34:13 +00:00
parent 35fead6ac0
commit 6354d55f78
5 changed files with 17 additions and 16 deletions

View file

@ -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;
clientConnection = new ClientConnection(this, ip, _port);
controllerThread = new thread(&Controller::worker, this);
}
@ -77,7 +75,7 @@ void Controller::worker()
RequestMsg requestMsg("serverSettings");
shared_ptr<ServerSettings> serverSettings(NULL);
while (!(serverSettings = clientConnection->sendReq<ServerSettings>(&requestMsg, 1000)));
cout << "ServerSettings port: " << serverSettings->port << "\n";
cout << "ServerSettings buffer: " << serverSettings->bufferMs << "\n";
requestMsg.request = "sampleFormat";
while (!(sampleFormat = clientConnection->sendReq<SampleFormat>(&requestMsg, 1000)));
@ -110,7 +108,7 @@ cout << "Received: " << TimeProvider::sinceEpoche<chronos::msec>(TimeProvider::t
}
stream = new Stream(*sampleFormat);
stream->setBufferLen(bufferMs);
stream->setBufferLen(serverSettings->bufferMs);
Player player(stream);
player.start();

View file

@ -13,7 +13,7 @@ class Controller : public MessageReceiver
{
public:
Controller();
void start(const std::string& _ip, size_t _port, int _bufferMs);
void start(const std::string& _ip, size_t _port);
void stop();
virtual void onMessageReceived(ClientConnection* connection, const BaseMessage& baseMessage, char* buffer);
virtual void onException(ClientConnection* connection, const std::exception& exception);
@ -24,7 +24,6 @@ private:
std::thread* controllerThread;
ClientConnection* clientConnection;
Stream* stream;
int bufferMs;
std::string ip;
std::shared_ptr<SampleFormat> sampleFormat;
Decoder* decoder;

View file

@ -24,7 +24,7 @@ int main (int argc, char *argv[])
{
int deviceIdx;
string ip;
int bufferMs;
// int bufferMs;
size_t port;
bool runAsDaemon;
// 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")
("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")
("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")
;
@ -57,7 +57,7 @@ int main (int argc, char *argv[])
}
Controller controller;
controller.start(ip, port, bufferMs);
controller.start(ip, port);
while(true)
usleep(10000);

View file

@ -8,7 +8,7 @@
class ServerSettings : public BaseMessage
{
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)
{
stream.read(reinterpret_cast<char *>(&port), sizeof(int32_t));
stream.read(reinterpret_cast<char *>(&bufferMs), sizeof(int32_t));
}
virtual uint32_t getSize()
@ -26,12 +26,12 @@ public:
return sizeof(int32_t);
}
int32_t port;
int32_t bufferMs;
protected:
virtual void doserialize(std::ostream& stream)
{
stream.write(reinterpret_cast<char *>(&port), sizeof(int32_t));
stream.write(reinterpret_cast<char *>(&bufferMs), sizeof(int32_t));
}
};

View file

@ -29,6 +29,7 @@ int main(int argc, char* argv[])
string fifoName;
string codec;
bool runAsDaemon;
int32_t bufferMs;
po::options_description desc("Allowed 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]")
("fifo,f", po::value<string>(&fifoName)->default_value("/tmp/snapfifo"), "name of fifo file")
("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;
@ -80,9 +82,11 @@ int main(int argc, char* argv[])
return 1;
}
std::auto_ptr<ServerSettings> serverSettings(new ServerSettings(port + 1));
ServerSettings serverSettings;
serverSettings.bufferMs = bufferMs;
ControlServer* controlServer = new ControlServer(port);
controlServer->setServerSettings(serverSettings.get());
controlServer->setServerSettings(&serverSettings);
controlServer->setFormat(&format);
controlServer->setHeader(encoder->getHeader());
controlServer->start();