mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-31 18:06:15 +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;
|
||||
|
||||
|
||||
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();
|
||||
|
||||
msg::Hello hello(clientConnection_->getMacAddress());
|
||||
msg::Hello hello(clientConnection_->getMacAddress(), instance_);
|
||||
clientConnection_->send(&hello);
|
||||
|
||||
msg::Time timeReq;
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
class Controller : public MessageReceiver
|
||||
{
|
||||
public:
|
||||
Controller();
|
||||
Controller(size_t instance);
|
||||
void start(const PcmDevice& pcmDevice, const std::string& host, size_t port, int latency);
|
||||
void stop();
|
||||
|
||||
|
@ -60,6 +60,7 @@ public:
|
|||
private:
|
||||
void worker();
|
||||
bool sendTimeSyncMessage(long after = 1000);
|
||||
size_t instance_;
|
||||
std::atomic<bool> active_;
|
||||
std::thread controllerThread_;
|
||||
SampleFormat sampleFormat_;
|
||||
|
|
|
@ -76,6 +76,7 @@ int main (int argc, char **argv)
|
|||
string host("");
|
||||
size_t port(1704);
|
||||
int latency(0);
|
||||
size_t instance(1);
|
||||
int processPriority(-3);
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
OptionParser op("Allowed options");
|
||||
op.add(helpSwitch)
|
||||
|
@ -99,7 +101,8 @@ int main (int argc, char **argv)
|
|||
#ifdef HAS_DAEMON
|
||||
.add(daemonOption)
|
||||
#endif
|
||||
.add(latencyValue);
|
||||
.add(latencyValue)
|
||||
.add(instanceValue);
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -151,7 +154,7 @@ int main (int argc, char **argv)
|
|||
if (daemonOption.isSet())
|
||||
{
|
||||
#ifdef HAS_DAEMON
|
||||
daemonize("snapcast", "audio", "/var/run/snapclient/pid");
|
||||
daemonize("snapcast", "audio", "/var/run/snapclient/pid." + cpt::to_string(instance));
|
||||
if (processPriority < -20)
|
||||
processPriority = -20;
|
||||
else if (processPriority > 19)
|
||||
|
@ -197,7 +200,7 @@ int main (int argc, char **argv)
|
|||
#endif
|
||||
}
|
||||
|
||||
std::unique_ptr<Controller> controller(new Controller());
|
||||
std::unique_ptr<Controller> controller(new Controller(instance));
|
||||
if (!g_terminated)
|
||||
{
|
||||
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)
|
||||
throw SnapException("Failed to set group " + cpt::to_string((int)user_gid));
|
||||
|
||||
#ifdef FREEBSD
|
||||
//#if defined(FREEBSD) && !defined(MACOS)
|
||||
//#ifdef FREEBSD
|
||||
/// init supplementary groups
|
||||
/// (must be done before we change our uid)
|
||||
/// 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)
|
||||
throw SnapException("Failed to set supplementary groups of user \"" + user + "\"");
|
||||
#endif
|
||||
// if (!had_group && user_uid != getuid() && initgroups(user_name, user_gid) == -1)
|
||||
// throw SnapException("Failed to set supplementary groups of user \"" + user + "\"");
|
||||
//#endif
|
||||
/// set uid
|
||||
if (user_uid != (uid_t)-1 && user_uid != getuid() && setuid(user_uid) == -1)
|
||||
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["HostName"] = ::getHostName();
|
||||
|
@ -42,6 +42,7 @@ public:
|
|||
msg["ClientName"] = "Snapclient";
|
||||
msg["OS"] = ::getOS();
|
||||
msg["Arch"] = ::getArch();
|
||||
msg["Instance"] = instance;
|
||||
msg["SnapStreamProtocolVersion"] = 2;
|
||||
}
|
||||
|
||||
|
@ -79,6 +80,11 @@ public:
|
|||
return msg["Arch"];
|
||||
}
|
||||
|
||||
int getInstance()
|
||||
{
|
||||
return get("Instance", 1);
|
||||
}
|
||||
|
||||
int getProtocolVersion()
|
||||
{
|
||||
return get("SnapStreamProtocolVersion", 1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue