mirror of
https://github.com/badaix/snapcast.git
synced 2025-07-17 00:25:43 +02:00
instance id for snapclient
This commit is contained in:
parent
a54a7f9a37
commit
bb7bea1b6c
5 changed files with 30 additions and 11 deletions
|
@ -34,7 +34,15 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
Controller::Controller() : MessageReceiver(), active_(false), latency_(0), stream_(nullptr), decoder_(nullptr), player_(nullptr), serverSettings_(nullptr), asyncException_(false)
|
Controller::Controller(size_t instance) : MessageReceiver(),
|
||||||
|
instance_(instance),
|
||||||
|
active_(false),
|
||||||
|
latency_(0),
|
||||||
|
stream_(nullptr),
|
||||||
|
decoder_(nullptr),
|
||||||
|
player_(nullptr),
|
||||||
|
serverSettings_(nullptr),
|
||||||
|
asyncException_(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +182,7 @@ void Controller::worker()
|
||||||
{
|
{
|
||||||
clientConnection_->start();
|
clientConnection_->start();
|
||||||
|
|
||||||
msg::Hello hello(clientConnection_->getMacAddress());
|
msg::Hello hello(clientConnection_->getMacAddress(), instance_);
|
||||||
clientConnection_->send(&hello);
|
clientConnection_->send(&hello);
|
||||||
|
|
||||||
msg::Time timeReq;
|
msg::Time timeReq;
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
class Controller : public MessageReceiver
|
class Controller : public MessageReceiver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Controller();
|
Controller(size_t instance);
|
||||||
void start(const PcmDevice& pcmDevice, const std::string& host, size_t port, int latency);
|
void start(const PcmDevice& pcmDevice, const std::string& host, size_t port, int latency);
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
|
@ -60,6 +60,7 @@ public:
|
||||||
private:
|
private:
|
||||||
void worker();
|
void worker();
|
||||||
bool sendTimeSyncMessage(long after = 1000);
|
bool sendTimeSyncMessage(long after = 1000);
|
||||||
|
size_t instance_;
|
||||||
std::atomic<bool> active_;
|
std::atomic<bool> active_;
|
||||||
std::thread controllerThread_;
|
std::thread controllerThread_;
|
||||||
SampleFormat sampleFormat_;
|
SampleFormat sampleFormat_;
|
||||||
|
|
|
@ -76,6 +76,7 @@ int main (int argc, char **argv)
|
||||||
string host("");
|
string host("");
|
||||||
size_t port(1704);
|
size_t port(1704);
|
||||||
int latency(0);
|
int latency(0);
|
||||||
|
size_t instance(1);
|
||||||
int processPriority(-3);
|
int processPriority(-3);
|
||||||
|
|
||||||
Switch helpSwitch("", "help", "produce help message");
|
Switch helpSwitch("", "help", "produce help message");
|
||||||
|
@ -86,6 +87,7 @@ int main (int argc, char **argv)
|
||||||
Value<string> soundcardValue("s", "soundcard", "index or name of the soundcard", "default", &soundcard);
|
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);
|
Implicit<int> daemonOption("d", "daemon", "daemonize, optional process priority [-20..19]", -3, &processPriority);
|
||||||
Value<int> latencyValue("", "latency", "latency of the soundcard", 0, &latency);
|
Value<int> latencyValue("", "latency", "latency of the soundcard", 0, &latency);
|
||||||
|
Value<size_t> instanceValue("i", "instance", "instance id", 1, &instance);
|
||||||
|
|
||||||
OptionParser op("Allowed options");
|
OptionParser op("Allowed options");
|
||||||
op.add(helpSwitch)
|
op.add(helpSwitch)
|
||||||
|
@ -99,7 +101,8 @@ int main (int argc, char **argv)
|
||||||
#ifdef HAS_DAEMON
|
#ifdef HAS_DAEMON
|
||||||
.add(daemonOption)
|
.add(daemonOption)
|
||||||
#endif
|
#endif
|
||||||
.add(latencyValue);
|
.add(latencyValue)
|
||||||
|
.add(instanceValue);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -151,7 +154,7 @@ int main (int argc, char **argv)
|
||||||
if (daemonOption.isSet())
|
if (daemonOption.isSet())
|
||||||
{
|
{
|
||||||
#ifdef HAS_DAEMON
|
#ifdef HAS_DAEMON
|
||||||
daemonize("snapcast", "audio", "/var/run/snapclient/pid");
|
daemonize("snapcast", "audio", "/var/run/snapclient/pid." + cpt::to_string(instance));
|
||||||
if (processPriority < -20)
|
if (processPriority < -20)
|
||||||
processPriority = -20;
|
processPriority = -20;
|
||||||
else if (processPriority > 19)
|
else if (processPriority > 19)
|
||||||
|
@ -197,7 +200,7 @@ int main (int argc, char **argv)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Controller> controller(new Controller());
|
std::unique_ptr<Controller> controller(new Controller(instance));
|
||||||
if (!g_terminated)
|
if (!g_terminated)
|
||||||
{
|
{
|
||||||
logO << "Latency: " << latency << "\n";
|
logO << "Latency: " << latency << "\n";
|
||||||
|
|
|
@ -84,13 +84,14 @@ void daemonize(const std::string& user, const std::string& group, const std::str
|
||||||
if (user_gid != (gid_t)-1 && user_gid != getgid() && setgid(user_gid) == -1)
|
if (user_gid != (gid_t)-1 && user_gid != getgid() && setgid(user_gid) == -1)
|
||||||
throw SnapException("Failed to set group " + cpt::to_string((int)user_gid));
|
throw SnapException("Failed to set group " + cpt::to_string((int)user_gid));
|
||||||
|
|
||||||
#ifdef FREEBSD
|
//#if defined(FREEBSD) && !defined(MACOS)
|
||||||
|
//#ifdef FREEBSD
|
||||||
/// init supplementary groups
|
/// init supplementary groups
|
||||||
/// (must be done before we change our uid)
|
/// (must be done before we change our uid)
|
||||||
/// no need to set the new user's supplementary groups if we are already this user
|
/// no need to set the new user's supplementary groups if we are already this user
|
||||||
if (!had_group && user_uid != getuid() && initgroups(user_name, user_gid) == -1)
|
// if (!had_group && user_uid != getuid() && initgroups(user_name, user_gid) == -1)
|
||||||
throw SnapException("Failed to set supplementary groups of user \"" + user + "\"");
|
// throw SnapException("Failed to set supplementary groups of user \"" + user + "\"");
|
||||||
#endif
|
//#endif
|
||||||
/// set uid
|
/// set uid
|
||||||
if (user_uid != (uid_t)-1 && user_uid != getuid() && setuid(user_uid) == -1)
|
if (user_uid != (uid_t)-1 && user_uid != getuid() && setuid(user_uid) == -1)
|
||||||
throw SnapException("Failed to set user " + user);
|
throw SnapException("Failed to set user " + user);
|
||||||
|
|
|
@ -34,7 +34,7 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Hello(const std::string& macAddress) : JsonMessage(message_type::kHello)
|
Hello(const std::string& macAddress, size_t instance) : JsonMessage(message_type::kHello)
|
||||||
{
|
{
|
||||||
msg["MAC"] = macAddress;
|
msg["MAC"] = macAddress;
|
||||||
msg["HostName"] = ::getHostName();
|
msg["HostName"] = ::getHostName();
|
||||||
|
@ -42,6 +42,7 @@ public:
|
||||||
msg["ClientName"] = "Snapclient";
|
msg["ClientName"] = "Snapclient";
|
||||||
msg["OS"] = ::getOS();
|
msg["OS"] = ::getOS();
|
||||||
msg["Arch"] = ::getArch();
|
msg["Arch"] = ::getArch();
|
||||||
|
msg["Instance"] = instance;
|
||||||
msg["SnapStreamProtocolVersion"] = 2;
|
msg["SnapStreamProtocolVersion"] = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +80,11 @@ public:
|
||||||
return msg["Arch"];
|
return msg["Arch"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getInstance()
|
||||||
|
{
|
||||||
|
return get("Instance", 1);
|
||||||
|
}
|
||||||
|
|
||||||
int getProtocolVersion()
|
int getProtocolVersion()
|
||||||
{
|
{
|
||||||
return get("SnapStreamProtocolVersion", 1);
|
return get("SnapStreamProtocolVersion", 1);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue