mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-22 05:26:17 +02:00
configurable process priority
This commit is contained in:
parent
389bc92b2f
commit
83d7ca8856
2 changed files with 107 additions and 88 deletions
|
@ -61,104 +61,116 @@ PcmDevice getPcmDevice(const std::string& soundcard)
|
|||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
string soundcard;
|
||||
string ip;
|
||||
// int bufferMs;
|
||||
size_t port;
|
||||
size_t latency;
|
||||
bool runAsDaemon;
|
||||
bool listPcmDevices;
|
||||
|
||||
po::options_description desc("Allowed options");
|
||||
desc.add_options()
|
||||
("help,h", "produce help message")
|
||||
("version,v", "show version number")
|
||||
("list,l", po::bool_switch(&listPcmDevices)->default_value(false), "list pcm devices")
|
||||
("ip,i", po::value<string>(&ip), "server IP")
|
||||
("port,p", po::value<size_t>(&port)->default_value(98765), "server port")
|
||||
("soundcard,s", po::value<string>(&soundcard)->default_value("default"), "index or name of the soundcard")
|
||||
("daemon,d", po::bool_switch(&runAsDaemon)->default_value(false), "daemonize")
|
||||
("latency", po::value<size_t>(&latency)->default_value(0), "latency")
|
||||
;
|
||||
|
||||
po::variables_map vm;
|
||||
po::store(po::parse_command_line(argc, argv, desc), vm);
|
||||
po::notify(vm);
|
||||
|
||||
std::clog.rdbuf(new Log("snapclient", LOG_DAEMON));
|
||||
|
||||
if (vm.count("help"))
|
||||
try
|
||||
{
|
||||
cout << desc << "\n";
|
||||
return 1;
|
||||
}
|
||||
string soundcard;
|
||||
string ip;
|
||||
// int bufferMs;
|
||||
size_t port;
|
||||
size_t latency;
|
||||
int runAsDaemon;
|
||||
bool listPcmDevices;
|
||||
|
||||
if (vm.count("version"))
|
||||
{
|
||||
cout << "snapclient v" << VERSION << "\n"
|
||||
<< "Copyright (C) 2014 BadAix (snapcast@badaix.de).\n"
|
||||
<< "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n"
|
||||
<< "This is free software: you are free to change and redistribute it.\n"
|
||||
<< "There is NO WARRANTY, to the extent permitted by law.\n\n"
|
||||
<< "Written by Johannes M. Pohl.\n";
|
||||
return 1;
|
||||
}
|
||||
po::options_description desc("Allowed options");
|
||||
desc.add_options()
|
||||
("help,h", "produce help message")
|
||||
("version,v", "show version number")
|
||||
("list,l", po::bool_switch(&listPcmDevices)->default_value(false), "list pcm devices")
|
||||
("ip,i", po::value<string>(&ip), "server IP")
|
||||
("port,p", po::value<size_t>(&port)->default_value(98765), "server port")
|
||||
("soundcard,s", po::value<string>(&soundcard)->default_value("default"), "index or name of the soundcard")
|
||||
("daemon,d", po::value<int>(&runAsDaemon)->implicit_value(-5), "daemonize, optional process priority [-20..19]")
|
||||
("latency", po::value<size_t>(&latency)->default_value(0), "latency of the soundcard")
|
||||
;
|
||||
|
||||
if (listPcmDevices)
|
||||
{
|
||||
vector<PcmDevice> pcmDevices = Player::pcm_list();
|
||||
for (auto dev: pcmDevices)
|
||||
po::variables_map vm;
|
||||
po::store(po::parse_command_line(argc, argv, desc), vm);
|
||||
po::notify(vm);
|
||||
|
||||
std::clog.rdbuf(new Log("snapclient", LOG_DAEMON));
|
||||
|
||||
if (vm.count("help"))
|
||||
{
|
||||
cout << dev.idx << ": " << dev.name << "\n"
|
||||
<< dev.description << "\n\n";
|
||||
cout << desc << "\n";
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
signal(SIGHUP, signal_handler);
|
||||
signal(SIGTERM, signal_handler);
|
||||
signal(SIGINT, signal_handler);
|
||||
|
||||
if (runAsDaemon)
|
||||
{
|
||||
daemonize("/var/run/snapclient.pid");
|
||||
setpriority(PRIO_PROCESS, 0, -5);
|
||||
logS(kLogNotice) << "daemon started" << std::endl;
|
||||
}
|
||||
|
||||
PcmDevice pcmDevice = getPcmDevice(soundcard);
|
||||
if (pcmDevice.idx == -1)
|
||||
{
|
||||
cout << "soundcard \"" << soundcard << "\" not found\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!vm.count("ip"))
|
||||
{
|
||||
BrowseAvahi browseAvahi;
|
||||
AvahiResult avahiResult;
|
||||
while (!g_terminated)
|
||||
if (vm.count("version"))
|
||||
{
|
||||
if (browseAvahi.browse("_snapcast._tcp", AVAHI_PROTO_INET, avahiResult, 5000))
|
||||
cout << "snapclient v" << VERSION << "\n"
|
||||
<< "Copyright (C) 2014 BadAix (snapcast@badaix.de).\n"
|
||||
<< "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n"
|
||||
<< "This is free software: you are free to change and redistribute it.\n"
|
||||
<< "There is NO WARRANTY, to the extent permitted by law.\n\n"
|
||||
<< "Written by Johannes M. Pohl.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (listPcmDevices)
|
||||
{
|
||||
vector<PcmDevice> pcmDevices = Player::pcm_list();
|
||||
for (auto dev: pcmDevices)
|
||||
{
|
||||
ip = avahiResult.ip_;
|
||||
port = avahiResult.port_;
|
||||
std::cout << ip << ":" << port << "\n";
|
||||
break;
|
||||
cout << dev.idx << ": " << dev.name << "\n"
|
||||
<< dev.description << "\n\n";
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
signal(SIGHUP, signal_handler);
|
||||
signal(SIGTERM, signal_handler);
|
||||
signal(SIGINT, signal_handler);
|
||||
|
||||
if (vm.count("daemon"))
|
||||
{
|
||||
daemonize("/var/run/snapclient.pid");
|
||||
if (runAsDaemon < -20)
|
||||
runAsDaemon = -20;
|
||||
else if (runAsDaemon > 19)
|
||||
runAsDaemon = 10;
|
||||
setpriority(PRIO_PROCESS, 0, runAsDaemon);
|
||||
logS(kLogNotice) << "daemon started" << std::endl;
|
||||
}
|
||||
|
||||
PcmDevice pcmDevice = getPcmDevice(soundcard);
|
||||
if (pcmDevice.idx == -1)
|
||||
{
|
||||
cout << "soundcard \"" << soundcard << "\" not found\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!vm.count("ip"))
|
||||
{
|
||||
BrowseAvahi browseAvahi;
|
||||
AvahiResult avahiResult;
|
||||
while (!g_terminated)
|
||||
{
|
||||
if (browseAvahi.browse("_snapcast._tcp", AVAHI_PROTO_INET, avahiResult, 5000))
|
||||
{
|
||||
ip = avahiResult.ip_;
|
||||
port = avahiResult.port_;
|
||||
std::cout << ip << ":" << port << "\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Controller controller;
|
||||
if (!g_terminated)
|
||||
Controller controller;
|
||||
if (!g_terminated)
|
||||
{
|
||||
controller.start(pcmDevice, ip, port, latency);
|
||||
while(!g_terminated)
|
||||
usleep(100*1000);
|
||||
controller.stop();
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
controller.start(pcmDevice, ip, port, latency);
|
||||
while(!g_terminated)
|
||||
usleep(100*1000);
|
||||
controller.stop();
|
||||
logS(kLogErr) << "Exception: " << e.what() << std::endl;
|
||||
}
|
||||
daemonShutdown();
|
||||
|
||||
logS(kLogNotice) << "daemon terminated." << endl;
|
||||
daemonShutdown();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ int main(int argc, char* argv[])
|
|||
try
|
||||
{
|
||||
ControlServerSettings settings;
|
||||
bool runAsDaemon;
|
||||
int runAsDaemon;
|
||||
string sampleFormat;
|
||||
|
||||
po::options_description desc("Allowed options");
|
||||
|
@ -58,7 +58,7 @@ int main(int argc, char* argv[])
|
|||
("sampleformat,s", po::value<string>(&sampleFormat)->default_value("44100:16:2"), "sample format")
|
||||
("codec,c", po::value<string>(&settings.codec)->default_value("flac"), "transport codec [flac|ogg|pcm][:options]. Type codec:? to get codec specific options")
|
||||
("fifo,f", po::value<string>(&settings.fifoName)->default_value("/tmp/snapfifo"), "name of the input fifo file")
|
||||
("daemon,d", po::bool_switch(&runAsDaemon)->default_value(false), "daemonize")
|
||||
("daemon,d", po::value<int>(&runAsDaemon)->implicit_value(-5), "daemonize, optional process priority [-20..19]")
|
||||
("buffer,b", po::value<int32_t>(&settings.bufferMs)->default_value(1000), "buffer [ms]")
|
||||
;
|
||||
|
||||
|
@ -102,10 +102,14 @@ int main(int argc, char* argv[])
|
|||
signal(SIGTERM, signal_handler);
|
||||
signal(SIGINT, signal_handler);
|
||||
|
||||
if (runAsDaemon)
|
||||
if (vm.count("daemon"))
|
||||
{
|
||||
daemonize("/var/run/snapserver.pid");
|
||||
setpriority(PRIO_PROCESS, 0, -5);
|
||||
if (runAsDaemon < -20)
|
||||
runAsDaemon = -20;
|
||||
else if (runAsDaemon > 19)
|
||||
runAsDaemon = 10;
|
||||
setpriority(PRIO_PROCESS, 0, runAsDaemon);
|
||||
logS(kLogNotice) << "daemon started." << endl;
|
||||
}
|
||||
|
||||
|
@ -114,6 +118,8 @@ int main(int argc, char* argv[])
|
|||
services.push_back(AvahiService("_snapcast._tcp", settings.port));
|
||||
publishAvahi.publish(services);
|
||||
|
||||
if (settings.bufferMs < 400)
|
||||
settings.bufferMs = 400;
|
||||
settings.sampleFormat = sampleFormat;
|
||||
ControlServer* controlServer = new ControlServer(settings);
|
||||
controlServer->start();
|
||||
|
@ -128,6 +134,7 @@ int main(int argc, char* argv[])
|
|||
|
||||
logS(kLogNotice) << "daemon terminated." << endl;
|
||||
daemonShutdown();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue