switch to popl v0.7.0

This commit is contained in:
badaix 2017-09-19 23:17:12 +02:00
parent 4670927d67
commit 16286d122a
4 changed files with 53 additions and 82 deletions

View file

@ -78,38 +78,25 @@ int main (int argc, char **argv)
size_t port(1704); size_t port(1704);
int latency(0); int latency(0);
size_t instance(1); size_t instance(1);
int processPriority(-3);
Switch helpSwitch("", "help", "produce help message");
Switch debugSwitch("", "debug", "enable debug logging");
Switch versionSwitch("v", "version", "show version number");
Switch listSwitch("l", "list", "list pcm devices");
Value<string> hostValue("h", "host", "server hostname or ip address", "", &host);
Value<size_t> portValue("p", "port", "server port", 1704, &port);
Value<string> soundcardValue("s", "soundcard", "index or name of the soundcard", "default", &soundcard);
Implicit<int> daemonOption("d", "daemon", "daemonize, optional process priority [-20..19]", -3, &processPriority);
Value<int> latencyValue("", "latency", "latency of the soundcard", 0, &latency);
Value<size_t> instanceValue("i", "instance", "instance id", 1, &instance);
Value<string> hostIdValue("", "hostID", "unique host id", "");
Value<string> userValue("", "user", "the user[:group] to run snapclient as when daemonized");
OptionParser op("Allowed options"); OptionParser op("Allowed options");
op.add(helpSwitch) auto helpSwitch = op.add<Switch>("", "help", "produce help message");
.add(debugSwitch, hidden) auto debugSwitch = op.add<Switch, Attribute::hidden>("", "debug", "enable debug logging");
.add(versionSwitch) auto versionSwitch = op.add<Switch>("v", "version", "show version number");
.add(hostValue)
.add(portValue)
#if defined(HAS_ALSA) #if defined(HAS_ALSA)
.add(listSwitch) auto listSwitch = op.add<Switch>("l", "list", "list pcm devices");
.add(soundcardValue) auto soundcardValue = op.add<Value<string>>("s", "soundcard", "index or name of the soundcard", "default", &soundcard);
#endif #endif
auto hostValue = op.add<Value<string>>("h", "host", "server hostname or ip address", "", &host);
auto portValue = op.add<Value<size_t>>("p", "port", "server port", 1704, &port);
#ifdef HAS_DAEMON #ifdef HAS_DAEMON
.add(daemonOption) int processPriority(-3);
.add(userValue) auto daemonOption = op.add<Implicit<int>>("d", "daemon", "daemonize, optional process priority [-20..19]", -3, &processPriority);
auto userValue = op.add<Value<string>>("", "user", "the user[:group] to run snapclient as when daemonized");
#endif #endif
.add(latencyValue) auto latencyValue = op.add<Value<int>>("", "latency", "latency of the soundcard", 0, &latency);
.add(hostIdValue) auto instanceValue = op.add<Value<size_t>>("i", "instance", "instance id", 1, &instance);
.add(instanceValue); auto hostIdValue = op.add<Value<string>>("", "hostID", "unique host id", "");
try try
{ {
@ -122,7 +109,7 @@ int main (int argc, char **argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (versionSwitch.isSet()) if (versionSwitch->is_set())
{ {
cout << "snapclient v" << VERSION << "\n" cout << "snapclient v" << VERSION << "\n"
<< "Copyright (C) 2014-2017 BadAix (snapcast@badaix.de).\n" << "Copyright (C) 2014-2017 BadAix (snapcast@badaix.de).\n"
@ -133,20 +120,20 @@ int main (int argc, char **argv)
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
if (listSwitch.isSet())
{
#ifdef HAS_ALSA #ifdef HAS_ALSA
if (listSwitch->is_set())
{
vector<PcmDevice> pcmDevices = AlsaPlayer::pcm_list(); vector<PcmDevice> pcmDevices = AlsaPlayer::pcm_list();
for (auto dev: pcmDevices) for (auto dev: pcmDevices)
{ {
cout << dev.idx << ": " << dev.name << "\n" cout << dev.idx << ": " << dev.name << "\n"
<< dev.description << "\n\n"; << dev.description << "\n\n";
} }
#endif
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
#endif
if (helpSwitch.isSet()) if (helpSwitch->is_set())
{ {
cout << op << "\n"; cout << op << "\n";
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
@ -157,7 +144,7 @@ int main (int argc, char **argv)
AixLog::Log::init( AixLog::Log::init(
{ {
make_shared<AixLog::SinkCout>(debugSwitch.isSet()?(AixLog::Severity::trace):(AixLog::Severity::info), AixLog::Type::all, debugSwitch.isSet()?"%Y-%m-%d %H-%M-%S.#ms [#severity] (#function)":"%Y-%m-%d %H-%M-%S [#severity]"), make_shared<AixLog::SinkCout>(debugSwitch->is_set()?(AixLog::Severity::trace):(AixLog::Severity::info), AixLog::Type::all, debugSwitch->is_set()?"%Y-%m-%d %H-%M-%S.#ms [#severity] (#function)":"%Y-%m-%d %H-%M-%S [#severity]"),
make_shared<AixLog::SinkNative>("snapclient", AixLog::Severity::trace, AixLog::Type::special) make_shared<AixLog::SinkNative>("snapclient", AixLog::Severity::trace, AixLog::Type::special)
} }
); );
@ -168,7 +155,7 @@ int main (int argc, char **argv)
#ifdef HAS_DAEMON #ifdef HAS_DAEMON
std::unique_ptr<Daemon> daemon; std::unique_ptr<Daemon> daemon;
if (daemonOption.isSet()) if (daemonOption->is_set())
{ {
string pidFile = "/var/run/snapclient/pid"; string pidFile = "/var/run/snapclient/pid";
if (instance != 1) if (instance != 1)
@ -176,12 +163,12 @@ int main (int argc, char **argv)
string user = ""; string user = "";
string group = ""; string group = "";
if (userValue.isSet()) if (userValue->is_set())
{ {
if (userValue.getValue().empty()) if (userValue->value().empty())
std::invalid_argument("user must not be empty"); std::invalid_argument("user must not be empty");
vector<string> user_group = utils::string::split(userValue.getValue(), ':'); vector<string> user_group = utils::string::split(userValue->value(), ':');
user = user_group[0]; user = user_group[0];
if (user_group.size() > 1) if (user_group.size() > 1)
group = user_group[1]; group = user_group[1];
@ -233,7 +220,7 @@ int main (int argc, char **argv)
#endif #endif
} }
std::unique_ptr<Controller> controller(new Controller(hostIdValue.getValue(), instance)); std::unique_ptr<Controller> controller(new Controller(hostIdValue->value(), instance));
if (!g_terminated) if (!g_terminated)
{ {
LOG(INFO) << "Latency: " << latency << "\n"; LOG(INFO) << "Latency: " << latency << "\n";

2
externals/aixlog vendored

@ -1 +1 @@
Subproject commit 85903c3718900a2acac479db60679ae1e09aab28 Subproject commit 9c2c1419170dc07807724b8faa5bc73909aa7f57

2
externals/popl vendored

@ -1 +1 @@
Subproject commit 9504d8e36ca6b069ba40edced6ee9ba2dc41d5cb Subproject commit 5a4878df88238d7712fdf3240996f26a78e207c5

View file

@ -59,39 +59,23 @@ int main(int argc, char* argv[])
std::string pcmStream = "pipe:///tmp/snapfifo?name=default"; std::string pcmStream = "pipe:///tmp/snapfifo?name=default";
int processPriority(0); int processPriority(0);
Switch helpSwitch("h", "help", "Produce help message");
Switch debugSwitch("", "debug", "enable debug logging");
Switch versionSwitch("v", "version", "Show version number");
Value<size_t> portValue("p", "port", "Server port", settings.port, &settings.port);
Value<size_t> controlPortValue("", "controlPort", "Remote control port", settings.controlPort, &settings.controlPort);
Value<string> streamValue("s", "stream", "URI of the PCM input stream.\nFormat: TYPE://host/path?name=NAME\n[&codec=CODEC]\n[&sampleformat=SAMPLEFORMAT]", pcmStream, &pcmStream);
Value<string> sampleFormatValue("", "sampleformat", "Default sample format", settings.sampleFormat);
Value<string> codecValue("c", "codec", "Default transport codec\n(flac|ogg|pcm)[:options]\nType codec:? to get codec specific options", settings.codec, &settings.codec);
Value<size_t> streamBufferValue("", "streamBuffer", "Default stream read buffer [ms]", settings.streamReadMs, &settings.streamReadMs);
Value<int> bufferValue("b", "buffer", "Buffer [ms]", settings.bufferMs, &settings.bufferMs);
Switch muteSwitch("", "sendToMuted", "Send audio to muted clients", &settings.sendAudioToMutedClients);
Implicit<int> daemonOption("d", "daemon", "Daemonize\noptional process priority [-20..19]", 0, &processPriority);
Value<string> userValue("", "user", "the user[:group] to run snapserver as when daemonized", "");
OptionParser op("Allowed options"); OptionParser op("Allowed options");
op.add(helpSwitch) auto helpSwitch = op.add<Switch>("h", "help", "Produce help message");
.add(debugSwitch, hidden) auto debugSwitch = op.add<Switch, Attribute::hidden>("", "debug", "enable debug logging");
.add(versionSwitch) auto versionSwitch = op.add<Switch>("v", "version", "Show version number");
.add(portValue) auto portValue = op.add<Value<size_t>>("p", "port", "Server port", settings.port, &settings.port);
.add(controlPortValue) auto controlPortValue = op.add<Value<size_t>>("", "controlPort", "Remote control port", settings.controlPort, &settings.controlPort);
.add(streamValue) auto streamValue = op.add<Value<string>>("s", "stream", "URI of the PCM input stream.\nFormat: TYPE://host/path?name=NAME\n[&codec=CODEC]\n[&sampleformat=SAMPLEFORMAT]", pcmStream, &pcmStream);
.add(sampleFormatValue)
.add(codecValue) auto sampleFormatValue = op.add<Value<string>>("", "sampleformat", "Default sample format", settings.sampleFormat);
.add(streamBufferValue) auto codecValue = op.add<Value<string>>("c", "codec", "Default transport codec\n(flac|ogg|pcm)[:options]\nType codec:? to get codec specific options", settings.codec, &settings.codec);
.add(bufferValue) auto streamBufferValue = op.add<Value<size_t>>("", "streamBuffer", "Default stream read buffer [ms]", settings.streamReadMs, &settings.streamReadMs);
.add(muteSwitch) auto bufferValue = op.add<Value<int>>("b", "buffer", "Buffer [ms]", settings.bufferMs, &settings.bufferMs);
auto muteSwitch = op.add<Switch>("", "sendToMuted", "Send audio to muted clients", &settings.sendAudioToMutedClients);
#ifdef HAS_DAEMON #ifdef HAS_DAEMON
.add(daemonOption) auto daemonOption = op.add<Implicit<int>>("d", "daemon", "Daemonize\noptional process priority [-20..19]", 0, &processPriority);
.add(userValue) auto userValue = op.add<Value<string>>("", "user", "the user[:group] to run snapserver as when daemonized", "");
#endif #endif
;
try try
{ {
@ -104,7 +88,7 @@ int main(int argc, char* argv[])
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (versionSwitch.isSet()) if (versionSwitch->is_set())
{ {
cout << "snapserver v" << VERSION << "\n" cout << "snapserver v" << VERSION << "\n"
<< "Copyright (C) 2014-2017 BadAix (snapcast@badaix.de).\n" << "Copyright (C) 2014-2017 BadAix (snapcast@badaix.de).\n"
@ -115,19 +99,19 @@ int main(int argc, char* argv[])
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
if (helpSwitch.isSet()) if (helpSwitch->is_set())
{ {
cout << op << "\n"; cout << op << "\n";
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
if (!streamValue.isSet()) if (!streamValue->is_set())
settings.pcmStreams.push_back(streamValue.getValue()); settings.pcmStreams.push_back(streamValue->value());
for (size_t n=0; n<streamValue.count(); ++n) for (size_t n=0; n<streamValue->count(); ++n)
{ {
cout << streamValue.getValue(n) << "\n"; cout << streamValue->value(n) << "\n";
settings.pcmStreams.push_back(streamValue.getValue(n)); settings.pcmStreams.push_back(streamValue->value(n));
} }
if (settings.codec.find(":?") != string::npos) if (settings.codec.find(":?") != string::npos)
@ -145,7 +129,7 @@ int main(int argc, char* argv[])
AixLog::Log::init( AixLog::Log::init(
{ {
make_shared<AixLog::SinkCout>(debugSwitch.isSet()?(AixLog::Severity::trace):(AixLog::Severity::info), AixLog::Type::all, debugSwitch.isSet()?"%Y-%m-%d %H-%M-%S.#ms [#severity] (#tag)":"%Y-%m-%d %H-%M-%S [#severity]"), make_shared<AixLog::SinkCout>(debugSwitch->is_set()?(AixLog::Severity::trace):(AixLog::Severity::info), AixLog::Type::all, debugSwitch->is_set()?"%Y-%m-%d %H-%M-%S.#ms [#severity] (#tag)":"%Y-%m-%d %H-%M-%S [#severity]"),
make_shared<AixLog::SinkNative>("snapserver", AixLog::Severity::trace, AixLog::Type::special) make_shared<AixLog::SinkNative>("snapserver", AixLog::Severity::trace, AixLog::Type::special)
} }
); );
@ -156,17 +140,17 @@ int main(int argc, char* argv[])
#ifdef HAS_DAEMON #ifdef HAS_DAEMON
std::unique_ptr<Daemon> daemon; std::unique_ptr<Daemon> daemon;
if (daemonOption.isSet()) if (daemonOption->is_set())
{ {
string user = ""; string user = "";
string group = ""; string group = "";
if (userValue.isSet()) if (userValue->is_set())
{ {
if (userValue.getValue().empty()) if (userValue->value().empty())
std::invalid_argument("user must not be empty"); std::invalid_argument("user must not be empty");
vector<string> user_group = utils::string::split(userValue.getValue(), ':'); vector<string> user_group = utils::string::split(userValue->value(), ':');
user = user_group[0]; user = user_group[0];
if (user_group.size() > 1) if (user_group.size() > 1)
group = user_group[1]; group = user_group[1];
@ -193,7 +177,7 @@ int main(int argc, char* argv[])
if (settings.bufferMs < 400) if (settings.bufferMs < 400)
settings.bufferMs = 400; settings.bufferMs = 400;
settings.sampleFormat = sampleFormatValue.getValue(); settings.sampleFormat = sampleFormatValue->value();
asio::io_service io_service; asio::io_service io_service;
std::unique_ptr<StreamServer> streamServer(new StreamServer(&io_service, settings)); std::unique_ptr<StreamServer> streamServer(new StreamServer(&io_service, settings));