socket stuff

git-svn-id: svn://elaine/murooma/trunk@274 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
(no author) 2014-09-20 16:24:28 +00:00
parent 3116ec0257
commit 3dbbf8e3e5
2 changed files with 3 additions and 11 deletions

View file

@ -14,7 +14,7 @@
using namespace std; using namespace std;
Controller::Controller() : MessageReceiver(), active_(false), streamClient(NULL), sampleFormat(NULL), decoder(NULL) Controller::Controller() : MessageReceiver(), active_(false), sampleFormat(NULL), decoder(NULL)
{ {
} }
@ -27,11 +27,11 @@ void Controller::onMessageReceived(SocketConnection* connection, const BaseMessa
{ {
PcmChunk* pcmChunk = new PcmChunk(*sampleFormat, 0); PcmChunk* pcmChunk = new PcmChunk(*sampleFormat, 0);
pcmChunk->deserialize(baseMessage, buffer); pcmChunk->deserialize(baseMessage, buffer);
//cout << "chunk: " << pcmChunk->payloadSize; cout << "chunk: " << pcmChunk->payloadSize;
if (decoder->decode(pcmChunk)) if (decoder->decode(pcmChunk))
{ {
stream->addChunk(pcmChunk); stream->addChunk(pcmChunk);
//cout << ", decoded: " << pcmChunk->payloadSize << ", Duration: " << pcmChunk->getDuration() << ", sec: " << pcmChunk->timestamp.sec << ", usec: " << pcmChunk->timestamp.usec/1000 << ", type: " << pcmChunk->type << "\n"; cout << ", decoded: " << pcmChunk->payloadSize << ", Duration: " << pcmChunk->getDuration() << ", sec: " << pcmChunk->timestamp.sec << ", usec: " << pcmChunk->timestamp.usec/1000 << ", type: " << pcmChunk->type << "\n";
} }
else else
delete pcmChunk; delete pcmChunk;
@ -72,7 +72,6 @@ void Controller::worker()
shared_ptr<ServerSettings> serverSettings(NULL); shared_ptr<ServerSettings> serverSettings(NULL);
while (!(serverSettings = controlConnection->sendReq<ServerSettings>(&requestMsg, 1000))); while (!(serverSettings = controlConnection->sendReq<ServerSettings>(&requestMsg, 1000)));
cout << "ServerSettings port: " << serverSettings->port << "\n"; cout << "ServerSettings port: " << serverSettings->port << "\n";
streamClient = new StreamClient(this, ip, serverSettings->port);
requestMsg.request = "sampleFormat"; requestMsg.request = "sampleFormat";
while (!(sampleFormat = controlConnection->sendReq<SampleFormat>(&requestMsg, 1000))); while (!(sampleFormat = controlConnection->sendReq<SampleFormat>(&requestMsg, 1000)));
@ -99,7 +98,6 @@ void Controller::worker()
} }
} }
streamClient->start();
stream = new Stream(*sampleFormat); stream = new Stream(*sampleFormat);
stream->setBufferLen(bufferMs); stream->setBufferLen(bufferMs);
@ -115,7 +113,6 @@ void Controller::worker()
if (reply) if (reply)
{ {
double latency = (reply->received.sec - reply->sent.sec) + (reply->received.usec - reply->sent.usec) / 1000000.; double latency = (reply->received.sec - reply->sent.sec) + (reply->received.usec - reply->sent.usec) / 1000000.;
// cout << "C2S: " << timeMsg.latency << ", S2C: " << latency << ", diff: " << (timeMsg.latency - latency) / 2 << endl;
TimeProvider::getInstance().setDiffToServer((reply->latency - latency) * 1000 / 2); TimeProvider::getInstance().setDiffToServer((reply->latency - latency) * 1000 / 2);
cout << TimeProvider::getInstance().getDiffToServer() << "\n"; cout << TimeProvider::getInstance().getDiffToServer() << "\n";
} }
@ -125,10 +122,6 @@ void Controller::worker()
{ {
cout << "Stopping player\n"; cout << "Stopping player\n";
player.stop(); player.stop();
cout << "Stopping streamClient\n";
streamClient->stop();
delete streamClient;
streamClient = NULL;
cout << "Deleting stream\n"; cout << "Deleting stream\n";
delete stream; delete stream;
stream = NULL; stream = NULL;

View file

@ -22,7 +22,6 @@ private:
void worker(); void worker();
std::atomic<bool> active_; std::atomic<bool> active_;
std::thread* controllerThread; std::thread* controllerThread;
StreamClient* streamClient;
ClientConnection* controlConnection; ClientConnection* controlConnection;
Stream* stream; Stream* stream;
int bufferMs; int bufferMs;