mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-10 23:56:43 +02:00
clean
git-svn-id: svn://elaine/murooma/trunk@318 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
parent
83eed0be78
commit
bccffc7432
4 changed files with 37 additions and 11 deletions
|
@ -60,7 +60,10 @@ void Controller::start(const PcmDevice& pcmDevice, const std::string& _ip, size_
|
|||
|
||||
void Controller::stop()
|
||||
{
|
||||
cout << "Stopping\n";
|
||||
active_ = false;
|
||||
controllerThread->join();
|
||||
clientConnection->stop();
|
||||
}
|
||||
|
||||
|
||||
|
@ -77,16 +80,16 @@ void Controller::worker()
|
|||
clientConnection->start();
|
||||
RequestMsg requestMsg(serversettings);
|
||||
shared_ptr<ServerSettings> serverSettings(NULL);
|
||||
while (!(serverSettings = clientConnection->sendReq<ServerSettings>(&requestMsg)));
|
||||
while (active_ && !(serverSettings = clientConnection->sendReq<ServerSettings>(&requestMsg)));
|
||||
cout << "ServerSettings buffer: " << serverSettings->bufferMs << "\n";
|
||||
|
||||
requestMsg.request = sampleformat;
|
||||
while (!(sampleFormat = clientConnection->sendReq<SampleFormat>(&requestMsg)));
|
||||
while (active_ && !(sampleFormat = clientConnection->sendReq<SampleFormat>(&requestMsg)));
|
||||
cout << "SampleFormat rate: " << sampleFormat->rate << ", bits: " << sampleFormat->bits << ", channels: " << sampleFormat->channels << "\n";
|
||||
|
||||
requestMsg.request = header;
|
||||
shared_ptr<HeaderMessage> headerChunk(NULL);
|
||||
while (!(headerChunk = clientConnection->sendReq<HeaderMessage>(&requestMsg)));
|
||||
while (active_ && !(headerChunk = clientConnection->sendReq<HeaderMessage>(&requestMsg)));
|
||||
cout << "Codec: " << headerChunk->codec << "\n";
|
||||
if (headerChunk->codec == "ogg")
|
||||
decoder = new OggDecoder();
|
||||
|
@ -95,7 +98,7 @@ void Controller::worker()
|
|||
decoder->setHeader(headerChunk.get());
|
||||
|
||||
RequestMsg timeReq(timemsg);
|
||||
for (size_t n=0; n<50; ++n)
|
||||
for (size_t n=0; n<50 && active_; ++n)
|
||||
{
|
||||
shared_ptr<TimeMsg> reply = clientConnection->sendReq<TimeMsg>(&timeReq, chronos::msec(2000));
|
||||
if (reply)
|
||||
|
@ -115,7 +118,7 @@ void Controller::worker()
|
|||
|
||||
CommandMsg startStream("startStream");
|
||||
shared_ptr<AckMsg> ackMsg(NULL);
|
||||
while (!(ackMsg = clientConnection->sendReq<AckMsg>(&startStream)));
|
||||
while (active_ && !(ackMsg = clientConnection->sendReq<AckMsg>(&startStream)));
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -152,9 +155,11 @@ void Controller::worker()
|
|||
cout << "Stopping clientConnection\n";
|
||||
clientConnection->stop();
|
||||
cout << "done\n";
|
||||
if (active_)
|
||||
usleep(1000000);
|
||||
}
|
||||
}
|
||||
cout << "Thread stopped\n";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "common/utils.h"
|
||||
#include "common/log.h"
|
||||
#include "common/signalHandler.h"
|
||||
#include "controller.h"
|
||||
#include "alsaPlayer.h"
|
||||
|
||||
|
@ -18,6 +19,8 @@
|
|||
using namespace std;
|
||||
namespace po = boost::program_options;
|
||||
|
||||
//bool g_terminated = false;
|
||||
std::condition_variable terminateSignaled;
|
||||
|
||||
PcmDevice getPcmDevice(const std::string& soundcard)
|
||||
{
|
||||
|
@ -87,6 +90,10 @@ int main (int argc, char *argv[])
|
|||
return 1;
|
||||
}
|
||||
|
||||
signal(SIGHUP, signal_handler);
|
||||
signal(SIGTERM, signal_handler);
|
||||
signal(SIGINT, signal_handler);
|
||||
|
||||
std::clog.rdbuf(new Log("snapclient", LOG_DAEMON));
|
||||
if (runAsDaemon)
|
||||
{
|
||||
|
@ -105,8 +112,11 @@ int main (int argc, char *argv[])
|
|||
Controller controller;
|
||||
controller.start(pcmDevice, ip, port, latency);
|
||||
|
||||
while(true)
|
||||
usleep(10000);
|
||||
|
||||
std::mutex mtx;
|
||||
std::unique_lock<std::mutex> lck(mtx);
|
||||
terminateSignaled.wait(lck);
|
||||
controller.stop();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
|
||||
#include <signal.h>
|
||||
#include <syslog.h>
|
||||
#include <condition_variable>
|
||||
|
||||
extern bool g_terminated;
|
||||
extern std::condition_variable terminateSignaled;
|
||||
|
||||
void signal_handler(int sig)
|
||||
{
|
||||
|
@ -16,7 +17,11 @@ void signal_handler(int sig)
|
|||
break;
|
||||
case SIGTERM:
|
||||
syslog(LOG_WARNING, "Received SIGTERM signal.");
|
||||
g_terminated = true;
|
||||
terminateSignaled.notify_all();
|
||||
break;
|
||||
case SIGINT:
|
||||
syslog(LOG_WARNING, "Received SIGINT signal.");
|
||||
terminateSignaled.notify_all();
|
||||
break;
|
||||
default:
|
||||
syslog(LOG_WARNING, "Unhandled signal ");
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include "message/message.h"
|
||||
#include "pcmEncoder.h"
|
||||
#include "oggEncoder.h"
|
||||
#include "controlServer.h"
|
||||
c#include "controlServer.h"
|
||||
|
||||
|
||||
bool g_terminated = false;
|
||||
|
@ -18,6 +18,7 @@ namespace po = boost::program_options;
|
|||
using namespace std;
|
||||
|
||||
|
||||
std::condition_variable terminateSignaled;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
@ -76,6 +77,11 @@ int main(int argc, char* argv[])
|
|||
encoder.reset(new OggEncoder(sampleFormat));
|
||||
else if (codec == "pcm")
|
||||
encoder.reset(new PcmEncoder(sampleFormat));
|
||||
else if (codec == "flac")
|
||||
{
|
||||
cout << "Not yet supported\n";
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "unknown codec: " << codec << "\n";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue