mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-01 11:17:36 +02:00
Reformat code with clang 10
This commit is contained in:
parent
59763f03c1
commit
3ac9245d00
24 changed files with 174 additions and 155 deletions
|
@ -281,6 +281,8 @@ IF(CLANG_FORMAT)
|
||||||
server/*.[ch]pp
|
server/*.[ch]pp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
list(REMOVE_ITEM CHECK_CXX_SOURCE_FILES "${CMAKE_SOURCE_DIR}/common/json.hpp")
|
||||||
|
|
||||||
ADD_CUSTOM_TARGET(
|
ADD_CUSTOM_TARGET(
|
||||||
reformat
|
reformat
|
||||||
COMMAND
|
COMMAND
|
||||||
|
|
|
@ -176,9 +176,10 @@ bool BrowseBonjour::browse(const string& serviceName, mDNSResult& result, int /*
|
||||||
deque<mDNSReply> replyCollection;
|
deque<mDNSReply> replyCollection;
|
||||||
{
|
{
|
||||||
DNSServiceHandle service(new DNSServiceRef(NULL));
|
DNSServiceHandle service(new DNSServiceRef(NULL));
|
||||||
CHECKED(DNSServiceBrowse(service.get(), 0, 0, serviceName.c_str(), "local.",
|
CHECKED(DNSServiceBrowse(
|
||||||
[](DNSServiceRef /*service*/, DNSServiceFlags /*flags*/, uint32_t /*interfaceIndex*/, DNSServiceErrorType errorCode,
|
service.get(), 0, 0, serviceName.c_str(), "local.",
|
||||||
const char* serviceName, const char* regtype, const char* replyDomain, void* context) {
|
[](DNSServiceRef /*service*/, DNSServiceFlags /*flags*/, uint32_t /*interfaceIndex*/, DNSServiceErrorType errorCode, const char* serviceName,
|
||||||
|
const char* regtype, const char* replyDomain, void* context) {
|
||||||
auto replyCollection = static_cast<deque<mDNSReply>*>(context);
|
auto replyCollection = static_cast<deque<mDNSReply>*>(context);
|
||||||
|
|
||||||
CHECKED(errorCode);
|
CHECKED(errorCode);
|
||||||
|
@ -194,10 +195,10 @@ bool BrowseBonjour::browse(const string& serviceName, mDNSResult& result, int /*
|
||||||
{
|
{
|
||||||
DNSServiceHandle service(new DNSServiceRef(NULL));
|
DNSServiceHandle service(new DNSServiceRef(NULL));
|
||||||
for (auto& reply : replyCollection)
|
for (auto& reply : replyCollection)
|
||||||
CHECKED(DNSServiceResolve(service.get(), 0, 0, reply.name.c_str(), reply.regtype.c_str(), reply.domain.c_str(),
|
CHECKED(DNSServiceResolve(
|
||||||
[](DNSServiceRef /*service*/, DNSServiceFlags /*flags*/, uint32_t /*interfaceIndex*/, DNSServiceErrorType errorCode,
|
service.get(), 0, 0, reply.name.c_str(), reply.regtype.c_str(), reply.domain.c_str(),
|
||||||
const char* /*fullName*/, const char* hosttarget, uint16_t port, uint16_t /*txtLen*/,
|
[](DNSServiceRef /*service*/, DNSServiceFlags /*flags*/, uint32_t /*interfaceIndex*/, DNSServiceErrorType errorCode, const char* /*fullName*/,
|
||||||
const unsigned char* /*txtRecord*/, void* context) {
|
const char* hosttarget, uint16_t port, uint16_t /*txtLen*/, const unsigned char* /*txtRecord*/, void* context) {
|
||||||
auto resultCollection = static_cast<deque<mDNSResolve>*>(context);
|
auto resultCollection = static_cast<deque<mDNSResolve>*>(context);
|
||||||
|
|
||||||
CHECKED(errorCode);
|
CHECKED(errorCode);
|
||||||
|
@ -216,9 +217,10 @@ bool BrowseBonjour::browse(const string& serviceName, mDNSResult& result, int /*
|
||||||
for (auto& resolve : resolveCollection)
|
for (auto& resolve : resolveCollection)
|
||||||
{
|
{
|
||||||
resultCollection[i].port = resolve.port;
|
resultCollection[i].port = resolve.port;
|
||||||
CHECKED(DNSServiceGetAddrInfo(service.get(), kDNSServiceFlagsLongLivedQuery, 0, kDNSServiceProtocol_IPv4, resolve.fullName.c_str(),
|
CHECKED(DNSServiceGetAddrInfo(
|
||||||
[](DNSServiceRef /*service*/, DNSServiceFlags /*flags*/, uint32_t interfaceIndex, DNSServiceErrorType /*errorCode*/,
|
service.get(), kDNSServiceFlagsLongLivedQuery, 0, kDNSServiceProtocol_IPv4, resolve.fullName.c_str(),
|
||||||
const char* hostname, const sockaddr* address, uint32_t /*ttl*/, void* context) {
|
[](DNSServiceRef /*service*/, DNSServiceFlags /*flags*/, uint32_t interfaceIndex, DNSServiceErrorType /*errorCode*/, const char* hostname,
|
||||||
|
const sockaddr* address, uint32_t /*ttl*/, void* context) {
|
||||||
auto result = static_cast<mDNSResult*>(context);
|
auto result = static_cast<mDNSResult*>(context);
|
||||||
|
|
||||||
result->host = string(hostname);
|
result->host = string(hostname);
|
||||||
|
@ -227,8 +229,7 @@ bool BrowseBonjour::browse(const string& serviceName, mDNSResult& result, int /*
|
||||||
|
|
||||||
char hostIP[NI_MAXHOST];
|
char hostIP[NI_MAXHOST];
|
||||||
char hostService[NI_MAXSERV];
|
char hostService[NI_MAXSERV];
|
||||||
if (getnameinfo(address, sizeof(*address), hostIP, sizeof(hostIP), hostService, sizeof(hostService),
|
if (getnameinfo(address, sizeof(*address), hostIP, sizeof(hostIP), hostService, sizeof(hostService), NI_NUMERICHOST | NI_NUMERICSERV) == 0)
|
||||||
NI_NUMERICHOST | NI_NUMERICSERV) == 0)
|
|
||||||
result->ip = string(hostIP);
|
result->ip = string(hostIP);
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -260,8 +260,8 @@ void Controller::getNextMessage()
|
||||||
void Controller::sendTimeSyncMessage(int quick_syncs)
|
void Controller::sendTimeSyncMessage(int quick_syncs)
|
||||||
{
|
{
|
||||||
auto timeReq = std::make_shared<msg::Time>();
|
auto timeReq = std::make_shared<msg::Time>();
|
||||||
clientConnection_->sendRequest<msg::Time>(timeReq, 2s, [this, quick_syncs](const boost::system::error_code& ec,
|
clientConnection_->sendRequest<msg::Time>(
|
||||||
const std::unique_ptr<msg::Time>& response) mutable {
|
timeReq, 2s, [this, quick_syncs](const boost::system::error_code& ec, const std::unique_ptr<msg::Time>& response) mutable {
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
LOG(ERROR, LOG_TAG) << "Time sync request failed: " << ec.message() << "\n";
|
LOG(ERROR, LOG_TAG) << "Time sync request failed: " << ec.message() << "\n";
|
||||||
|
@ -277,7 +277,8 @@ void Controller::sendTimeSyncMessage(int quick_syncs)
|
||||||
if (quick_syncs > 0)
|
if (quick_syncs > 0)
|
||||||
{
|
{
|
||||||
if (--quick_syncs == 0)
|
if (--quick_syncs == 0)
|
||||||
LOG(INFO, LOG_TAG) << "diff to server [ms]: " << (float)TimeProvider::getInstance().getDiffToServer<chronos::usec>().count() / 1000.f << "\n";
|
LOG(INFO, LOG_TAG) << "diff to server [ms]: " << (float)TimeProvider::getInstance().getDiffToServer<chronos::usec>().count() / 1000.f
|
||||||
|
<< "\n";
|
||||||
next = 100us;
|
next = 100us;
|
||||||
}
|
}
|
||||||
timer_.expires_after(next);
|
timer_.expires_after(next);
|
||||||
|
|
|
@ -368,7 +368,8 @@ void AlsaPlayer::initAlsa()
|
||||||
unsigned int period_time;
|
unsigned int period_time;
|
||||||
snd_pcm_hw_params_get_period_time(params, &period_time, nullptr);
|
snd_pcm_hw_params_get_period_time(params, &period_time, nullptr);
|
||||||
snd_pcm_hw_params_get_period_size(params, &frames_, nullptr);
|
snd_pcm_hw_params_get_period_size(params, &frames_, nullptr);
|
||||||
LOG(INFO, LOG_TAG) << "rate: " << rate << ", channels: " << channels << ", buffer time: " << buffer_time << " us, periods: " << periods << ", period time: " << period_time << " us, period frames: " << frames_ << "\n";
|
LOG(INFO, LOG_TAG) << "rate: " << rate << ", channels: " << channels << ", buffer time: " << buffer_time << " us, periods: " << periods
|
||||||
|
<< ", period time: " << period_time << " us, period frames: " << frames_ << "\n";
|
||||||
|
|
||||||
// Allocate buffer to hold single period
|
// Allocate buffer to hold single period
|
||||||
snd_pcm_sw_params_t* swparams;
|
snd_pcm_sw_params_t* swparams;
|
||||||
|
|
|
@ -93,7 +93,8 @@ bool PulsePlayer::getHardwareVolume(double& volume, bool& muted)
|
||||||
|
|
||||||
void PulsePlayer::triggerVolumeUpdate()
|
void PulsePlayer::triggerVolumeUpdate()
|
||||||
{
|
{
|
||||||
pa_context_get_sink_input_info(pa_ctx_, pa_stream_get_index(playstream_),
|
pa_context_get_sink_input_info(
|
||||||
|
pa_ctx_, pa_stream_get_index(playstream_),
|
||||||
[](pa_context* ctx, const pa_sink_input_info* info, int eol, void* userdata) {
|
[](pa_context* ctx, const pa_sink_input_info* info, int eol, void* userdata) {
|
||||||
std::ignore = ctx;
|
std::ignore = ctx;
|
||||||
LOG(DEBUG, LOG_TAG) << "pa_context_get_sink_info_by_index info: " << (info != nullptr) << ", eol: " << eol << "\n";
|
LOG(DEBUG, LOG_TAG) << "pa_context_get_sink_info_by_index info: " << (info != nullptr) << ", eol: " << eol << "\n";
|
||||||
|
@ -247,7 +248,8 @@ void PulsePlayer::start()
|
||||||
// modify the variable to 1 so we know when we have a connection and it's
|
// modify the variable to 1 so we know when we have a connection and it's
|
||||||
// ready.
|
// ready.
|
||||||
// If there's an error, the callback will set pa_ready to 2
|
// If there's an error, the callback will set pa_ready to 2
|
||||||
pa_context_set_state_callback(pa_ctx_,
|
pa_context_set_state_callback(
|
||||||
|
pa_ctx_,
|
||||||
[](pa_context* c, void* userdata) {
|
[](pa_context* c, void* userdata) {
|
||||||
auto self = static_cast<PulsePlayer*>(userdata);
|
auto self = static_cast<PulsePlayer*>(userdata);
|
||||||
self->stateCallback(c);
|
self->stateCallback(c);
|
||||||
|
@ -276,7 +278,8 @@ void PulsePlayer::start()
|
||||||
|
|
||||||
if (settings_.mixer.mode == ClientSettings::Mixer::Mode::hardware)
|
if (settings_.mixer.mode == ClientSettings::Mixer::Mode::hardware)
|
||||||
{
|
{
|
||||||
pa_context_set_subscribe_callback(pa_ctx_,
|
pa_context_set_subscribe_callback(
|
||||||
|
pa_ctx_,
|
||||||
[](pa_context* ctx, pa_subscription_event_type_t event_type, uint32_t idx, void* userdata) {
|
[](pa_context* ctx, pa_subscription_event_type_t event_type, uint32_t idx, void* userdata) {
|
||||||
auto self = static_cast<PulsePlayer*>(userdata);
|
auto self = static_cast<PulsePlayer*>(userdata);
|
||||||
self->subscribeCallback(ctx, event_type, idx);
|
self->subscribeCallback(ctx, event_type, idx);
|
||||||
|
@ -284,7 +287,8 @@ void PulsePlayer::start()
|
||||||
this);
|
this);
|
||||||
const pa_subscription_mask_t mask = static_cast<pa_subscription_mask_t>(PA_SUBSCRIPTION_MASK_SINK_INPUT);
|
const pa_subscription_mask_t mask = static_cast<pa_subscription_mask_t>(PA_SUBSCRIPTION_MASK_SINK_INPUT);
|
||||||
|
|
||||||
pa_context_subscribe(pa_ctx_, mask,
|
pa_context_subscribe(
|
||||||
|
pa_ctx_, mask,
|
||||||
[](pa_context* ctx, int success, void* userdata) {
|
[](pa_context* ctx, int success, void* userdata) {
|
||||||
std::ignore = ctx;
|
std::ignore = ctx;
|
||||||
if (success)
|
if (success)
|
||||||
|
@ -296,14 +300,16 @@ void PulsePlayer::start()
|
||||||
this);
|
this);
|
||||||
}
|
}
|
||||||
|
|
||||||
pa_stream_set_write_callback(playstream_,
|
pa_stream_set_write_callback(
|
||||||
|
playstream_,
|
||||||
[](pa_stream* stream, size_t length, void* userdata) {
|
[](pa_stream* stream, size_t length, void* userdata) {
|
||||||
auto self = static_cast<PulsePlayer*>(userdata);
|
auto self = static_cast<PulsePlayer*>(userdata);
|
||||||
self->writeCallback(stream, length);
|
self->writeCallback(stream, length);
|
||||||
},
|
},
|
||||||
this);
|
this);
|
||||||
|
|
||||||
pa_stream_set_underflow_callback(playstream_,
|
pa_stream_set_underflow_callback(
|
||||||
|
playstream_,
|
||||||
[](pa_stream* stream, void* userdata) {
|
[](pa_stream* stream, void* userdata) {
|
||||||
auto self = static_cast<PulsePlayer*>(userdata);
|
auto self = static_cast<PulsePlayer*>(userdata);
|
||||||
self->underflowCallback(stream);
|
self->underflowCallback(stream);
|
||||||
|
|
|
@ -42,6 +42,6 @@ inline int64_t swap(const int64_t& val)
|
||||||
{
|
{
|
||||||
return SWAP_64(val);
|
return SWAP_64(val);
|
||||||
}
|
}
|
||||||
}
|
} // namespace endian
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -58,7 +58,7 @@ public:
|
||||||
msg["muted"] = muted;
|
msg["muted"] = muted;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace msg
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -106,7 +106,7 @@ public:
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace msg
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -80,7 +80,7 @@ public:
|
||||||
msg["muted"] = muted;
|
msg["muted"] = muted;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace msg
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -67,7 +67,7 @@ public:
|
||||||
|
|
||||||
~StreamTags() override = default;
|
~StreamTags() override = default;
|
||||||
};
|
};
|
||||||
}
|
} // namespace msg
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -53,7 +53,7 @@ protected:
|
||||||
writeVal(stream, latency.usec);
|
writeVal(stream, latency.usec);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace msg
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -111,7 +111,7 @@ static float strtof(const char* str, char** endptr)
|
||||||
return std::strtof(str, endptr);
|
return std::strtof(str, endptr);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
} // namespace cpt
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -152,8 +152,9 @@ ControlSessionHttp::~ControlSessionHttp()
|
||||||
|
|
||||||
void ControlSessionHttp::start()
|
void ControlSessionHttp::start()
|
||||||
{
|
{
|
||||||
http::async_read(socket_, buffer_, req_, boost::asio::bind_executor(strand_, [ this, self = shared_from_this() ](
|
http::async_read(
|
||||||
boost::system::error_code ec, std::size_t bytes) { on_read(ec, bytes); }));
|
socket_, buffer_, req_,
|
||||||
|
boost::asio::bind_executor(strand_, [this, self = shared_from_this()](boost::system::error_code ec, std::size_t bytes) { on_read(ec, bytes); }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -803,7 +803,8 @@ inline void Error::parse_json(const Json& json)
|
||||||
inline Json Error::to_json() const
|
inline Json Error::to_json() const
|
||||||
{
|
{
|
||||||
Json j = {
|
Json j = {
|
||||||
{"code", code_}, {"message", message_},
|
{"code", code_},
|
||||||
|
{"message", message_},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!data_.is_null())
|
if (!data_.is_null())
|
||||||
|
@ -1065,7 +1066,8 @@ inline void Response::parse_json(const Json& json)
|
||||||
inline Json Response::to_json() const
|
inline Json Response::to_json() const
|
||||||
{
|
{
|
||||||
Json j = {
|
Json j = {
|
||||||
{"jsonrpc", "2.0"}, {"id", id_.to_json()},
|
{"jsonrpc", "2.0"},
|
||||||
|
{"id", id_.to_json()},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (error_)
|
if (error_)
|
||||||
|
@ -1129,7 +1131,8 @@ inline void Notification::parse_json(const Json& json)
|
||||||
inline Json Notification::to_json() const
|
inline Json Notification::to_json() const
|
||||||
{
|
{
|
||||||
Json json = {
|
Json json = {
|
||||||
{"jsonrpc", "2.0"}, {"method", method_},
|
{"jsonrpc", "2.0"},
|
||||||
|
{"method", method_},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (params_)
|
if (params_)
|
||||||
|
|
|
@ -24,7 +24,8 @@
|
||||||
|
|
||||||
static constexpr auto LOG_TAG = "Bonjour";
|
static constexpr auto LOG_TAG = "Bonjour";
|
||||||
|
|
||||||
typedef union {
|
typedef union
|
||||||
|
{
|
||||||
unsigned char b[2];
|
unsigned char b[2];
|
||||||
unsigned short NotAnInteger;
|
unsigned short NotAnInteger;
|
||||||
} Opaque16;
|
} Opaque16;
|
||||||
|
|
|
@ -77,8 +77,9 @@ std::string StreamSessionWebsocket::getIP()
|
||||||
void StreamSessionWebsocket::sendAsync(const shared_const_buffer& buffer, const WriteHandler& handler)
|
void StreamSessionWebsocket::sendAsync(const shared_const_buffer& buffer, const WriteHandler& handler)
|
||||||
{
|
{
|
||||||
LOG(TRACE, LOG_TAG) << "sendAsync: " << buffer.message().type << "\n";
|
LOG(TRACE, LOG_TAG) << "sendAsync: " << buffer.message().type << "\n";
|
||||||
ws_.async_write(buffer, boost::asio::bind_executor(strand_, [ self = shared_from_this(), buffer, handler ](boost::system::error_code ec,
|
ws_.async_write(buffer, boost::asio::bind_executor(strand_, [self = shared_from_this(), buffer, handler](boost::system::error_code ec, std::size_t length) {
|
||||||
std::size_t length) { handler(ec, length); }));
|
handler(ec, length);
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -192,7 +192,9 @@ json PcmStream::toJson() const
|
||||||
state = "disabled";
|
state = "disabled";
|
||||||
|
|
||||||
json j = {
|
json j = {
|
||||||
{"uri", uri_.toJson()}, {"id", getId()}, {"status", state},
|
{"uri", uri_.toJson()},
|
||||||
|
{"id", getId()},
|
||||||
|
{"status", state},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (meta_)
|
if (meta_)
|
||||||
|
|
|
@ -147,4 +147,4 @@ std::string StreamUri::getQuery(const std::string& key, const std::string& def)
|
||||||
return iter->second;
|
return iter->second;
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
}
|
} // namespace streamreader
|
||||||
|
|
Loading…
Add table
Reference in a new issue