mirror of
https://github.com/badaix/snapcast.git
synced 2025-04-29 18:27:12 +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
|
@ -280,7 +280,9 @@ IF(CLANG_FORMAT)
|
||||||
client/*.[ch]pp
|
client/*.[ch]pp
|
||||||
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,15 +176,16 @@ 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,
|
||||||
auto replyCollection = static_cast<deque<mDNSReply>*>(context);
|
const char* regtype, const char* replyDomain, void* context) {
|
||||||
|
auto replyCollection = static_cast<deque<mDNSReply>*>(context);
|
||||||
|
|
||||||
CHECKED(errorCode);
|
CHECKED(errorCode);
|
||||||
replyCollection->push_back(mDNSReply{string(serviceName), string(regtype), string(replyDomain)});
|
replyCollection->push_back(mDNSReply{string(serviceName), string(regtype), string(replyDomain)});
|
||||||
},
|
},
|
||||||
&replyCollection));
|
&replyCollection));
|
||||||
|
|
||||||
runService(service);
|
runService(service);
|
||||||
}
|
}
|
||||||
|
@ -194,16 +195,16 @@ 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);
|
||||||
resultCollection->push_back(mDNSResolve{string(hosttarget), ntohs(port)});
|
resultCollection->push_back(mDNSResolve{string(hosttarget), ntohs(port)});
|
||||||
},
|
},
|
||||||
&resolveCollection));
|
&resolveCollection));
|
||||||
|
|
||||||
runService(service);
|
runService(service);
|
||||||
}
|
}
|
||||||
|
@ -216,25 +217,25 @@ 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,
|
||||||
auto result = static_cast<mDNSResult*>(context);
|
const sockaddr* address, uint32_t /*ttl*/, void* context) {
|
||||||
|
auto result = static_cast<mDNSResult*>(context);
|
||||||
|
|
||||||
result->host = string(hostname);
|
result->host = string(hostname);
|
||||||
result->ip_version = (address->sa_family == AF_INET) ? (IPVersion::IPv4) : (IPVersion::IPv6);
|
result->ip_version = (address->sa_family == AF_INET) ? (IPVersion::IPv4) : (IPVersion::IPv6);
|
||||||
result->iface_idx = static_cast<int>(interfaceIndex);
|
result->iface_idx = static_cast<int>(interfaceIndex);
|
||||||
|
|
||||||
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;
|
result->valid = true;
|
||||||
result->valid = true;
|
},
|
||||||
},
|
&resultCollection[i++]));
|
||||||
&resultCollection[i++]));
|
|
||||||
}
|
}
|
||||||
runService(service);
|
runService(service);
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ public:
|
||||||
/// @param value the response message
|
/// @param value the response message
|
||||||
void setValue(std::unique_ptr<msg::BaseMessage> value)
|
void setValue(std::unique_ptr<msg::BaseMessage> value)
|
||||||
{
|
{
|
||||||
boost::asio::post(strand_, [ this, self = shared_from_this(), val = std::move(value) ]() mutable {
|
boost::asio::post(strand_, [this, self = shared_from_this(), val = std::move(value)]() mutable {
|
||||||
timer_.cancel();
|
timer_.cancel();
|
||||||
if (handler_)
|
if (handler_)
|
||||||
handler_({}, std::move(val));
|
handler_({}, std::move(val));
|
||||||
|
@ -79,7 +79,7 @@ public:
|
||||||
void startTimer(const chronos::usec& timeout)
|
void startTimer(const chronos::usec& timeout)
|
||||||
{
|
{
|
||||||
timer_.expires_after(timeout);
|
timer_.expires_after(timeout);
|
||||||
timer_.async_wait(boost::asio::bind_executor(strand_, [ this, self = shared_from_this() ](boost::system::error_code ec) {
|
timer_.async_wait(boost::asio::bind_executor(strand_, [this, self = shared_from_this()](boost::system::error_code ec) {
|
||||||
if (!handler_)
|
if (!handler_)
|
||||||
return;
|
return;
|
||||||
if (!ec)
|
if (!ec)
|
||||||
|
|
|
@ -260,34 +260,35 @@ 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";
|
|
||||||
reconnect();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
TimeProvider::getInstance().setDiff(response->latency, response->received - response->sent);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::chrono::microseconds next = TIME_SYNC_INTERVAL;
|
|
||||||
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";
|
|
||||||
next = 100us;
|
|
||||||
}
|
|
||||||
timer_.expires_after(next);
|
|
||||||
timer_.async_wait([this, quick_syncs](const boost::system::error_code& ec) {
|
|
||||||
if (!ec)
|
|
||||||
{
|
{
|
||||||
sendTimeSyncMessage(quick_syncs);
|
LOG(ERROR, LOG_TAG) << "Time sync request failed: " << ec.message() << "\n";
|
||||||
|
reconnect();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TimeProvider::getInstance().setDiff(response->latency, response->received - response->sent);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::chrono::microseconds next = TIME_SYNC_INTERVAL;
|
||||||
|
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";
|
||||||
|
next = 100us;
|
||||||
|
}
|
||||||
|
timer_.expires_after(next);
|
||||||
|
timer_.async_wait([this, quick_syncs](const boost::system::error_code& ec) {
|
||||||
|
if (!ec)
|
||||||
|
{
|
||||||
|
sendTimeSyncMessage(quick_syncs);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::browseMdns(const MdnsHandler& handler)
|
void Controller::browseMdns(const MdnsHandler& handler)
|
||||||
|
|
|
@ -288,7 +288,7 @@ void AlsaPlayer::initAlsa()
|
||||||
// if ((pcm = snd_pcm_playback_info( pcm_handle, &pinfo)) < 0)
|
// if ((pcm = snd_pcm_playback_info( pcm_handle, &pinfo)) < 0)
|
||||||
// fprintf(stderr, "Error: playback info error: %s\n", snd_strerror(err));
|
// fprintf(stderr, "Error: playback info error: %s\n", snd_strerror(err));
|
||||||
// printf("buffer: '%d'\n", pinfo.buffer_size);
|
// printf("buffer: '%d'\n", pinfo.buffer_size);
|
||||||
|
|
||||||
// Allocate parameters object and fill it with default values
|
// Allocate parameters object and fill it with default values
|
||||||
snd_pcm_hw_params_t* params;
|
snd_pcm_hw_params_t* params;
|
||||||
snd_pcm_hw_params_alloca(¶ms);
|
snd_pcm_hw_params_alloca(¶ms);
|
||||||
|
@ -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,29 +93,30 @@ 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_context* ctx, const pa_sink_input_info* info, int eol, void* userdata) {
|
pa_ctx_, pa_stream_get_index(playstream_),
|
||||||
std::ignore = ctx;
|
[](pa_context* ctx, const pa_sink_input_info* info, int eol, void* userdata) {
|
||||||
LOG(DEBUG, LOG_TAG) << "pa_context_get_sink_info_by_index info: " << (info != nullptr) << ", eol: " << eol << "\n";
|
std::ignore = ctx;
|
||||||
if (info)
|
LOG(DEBUG, LOG_TAG) << "pa_context_get_sink_info_by_index info: " << (info != nullptr) << ", eol: " << eol << "\n";
|
||||||
{
|
if (info)
|
||||||
auto self = static_cast<PulsePlayer*>(userdata);
|
{
|
||||||
auto volume = (double)pa_cvolume_avg(&(info->volume)) / (double)PA_VOLUME_NORM;
|
auto self = static_cast<PulsePlayer*>(userdata);
|
||||||
bool muted = (info->mute != 0);
|
auto volume = (double)pa_cvolume_avg(&(info->volume)) / (double)PA_VOLUME_NORM;
|
||||||
LOG(DEBUG, LOG_TAG) << "volume changed: " << volume << ", muted: " << muted << "\n";
|
bool muted = (info->mute != 0);
|
||||||
|
LOG(DEBUG, LOG_TAG) << "volume changed: " << volume << ", muted: " << muted << "\n";
|
||||||
|
|
||||||
auto now = std::chrono::steady_clock::now();
|
auto now = std::chrono::steady_clock::now();
|
||||||
if (now - self->last_change_ < 1s)
|
if (now - self->last_change_ < 1s)
|
||||||
{
|
{
|
||||||
LOG(DEBUG, LOG_TAG) << "Last volume change by server: "
|
LOG(DEBUG, LOG_TAG) << "Last volume change by server: "
|
||||||
<< std::chrono::duration_cast<std::chrono::milliseconds>(now - self->last_change_).count()
|
<< std::chrono::duration_cast<std::chrono::milliseconds>(now - self->last_change_).count()
|
||||||
<< " ms => ignoring volume change\n";
|
<< " ms => ignoring volume change\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self->notifyVolumeChange(volume, muted);
|
self->notifyVolumeChange(volume, muted);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
this);
|
this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -247,12 +248,13 @@ 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_context* c, void* userdata) {
|
pa_ctx_,
|
||||||
auto self = static_cast<PulsePlayer*>(userdata);
|
[](pa_context* c, void* userdata) {
|
||||||
self->stateCallback(c);
|
auto self = static_cast<PulsePlayer*>(userdata);
|
||||||
},
|
self->stateCallback(c);
|
||||||
this);
|
},
|
||||||
|
this);
|
||||||
|
|
||||||
// We can't do anything until PA is ready, so just iterate the mainloop
|
// We can't do anything until PA is ready, so just iterate the mainloop
|
||||||
// and continue
|
// and continue
|
||||||
|
@ -276,39 +278,43 @@ 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_context* ctx, pa_subscription_event_type_t event_type, uint32_t idx, void* userdata) {
|
pa_ctx_,
|
||||||
auto self = static_cast<PulsePlayer*>(userdata);
|
[](pa_context* ctx, pa_subscription_event_type_t event_type, uint32_t idx, void* userdata) {
|
||||||
self->subscribeCallback(ctx, event_type, idx);
|
auto self = static_cast<PulsePlayer*>(userdata);
|
||||||
},
|
self->subscribeCallback(ctx, event_type, idx);
|
||||||
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_context* ctx, int success, void* userdata) {
|
pa_ctx_, mask,
|
||||||
std::ignore = ctx;
|
[](pa_context* ctx, int success, void* userdata) {
|
||||||
if (success)
|
std::ignore = ctx;
|
||||||
{
|
if (success)
|
||||||
auto self = static_cast<PulsePlayer*>(userdata);
|
{
|
||||||
self->triggerVolumeUpdate();
|
auto self = static_cast<PulsePlayer*>(userdata);
|
||||||
}
|
self->triggerVolumeUpdate();
|
||||||
},
|
}
|
||||||
this);
|
},
|
||||||
|
this);
|
||||||
}
|
}
|
||||||
|
|
||||||
pa_stream_set_write_callback(playstream_,
|
pa_stream_set_write_callback(
|
||||||
[](pa_stream* stream, size_t length, void* userdata) {
|
playstream_,
|
||||||
auto self = static_cast<PulsePlayer*>(userdata);
|
[](pa_stream* stream, size_t length, void* userdata) {
|
||||||
self->writeCallback(stream, length);
|
auto self = static_cast<PulsePlayer*>(userdata);
|
||||||
},
|
self->writeCallback(stream, length);
|
||||||
this);
|
},
|
||||||
|
this);
|
||||||
|
|
||||||
pa_stream_set_underflow_callback(playstream_,
|
pa_stream_set_underflow_callback(
|
||||||
[](pa_stream* stream, void* userdata) {
|
playstream_,
|
||||||
auto self = static_cast<PulsePlayer*>(userdata);
|
[](pa_stream* stream, void* userdata) {
|
||||||
self->underflowCallback(stream);
|
auto self = static_cast<PulsePlayer*>(userdata);
|
||||||
},
|
self->underflowCallback(stream);
|
||||||
this);
|
},
|
||||||
|
this);
|
||||||
|
|
||||||
bufattr_.fragsize = pa_usec_to_bytes(latency_.count(), &pa_ss_);
|
bufattr_.fragsize = pa_usec_to_bytes(latency_.count(), &pa_ss_);
|
||||||
bufattr_.maxlength = pa_usec_to_bytes(latency_.count(), &pa_ss_);
|
bufattr_.maxlength = pa_usec_to_bytes(latency_.count(), &pa_ss_);
|
||||||
|
|
|
@ -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); }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -313,7 +314,7 @@ void ControlSessionHttp::on_read(beast::error_code ec, std::size_t bytes_transfe
|
||||||
// Create a WebSocket session by transferring the socket
|
// Create a WebSocket session by transferring the socket
|
||||||
// std::make_shared<websocket_session>(std::move(socket_), state_)->run(std::move(req_));
|
// std::make_shared<websocket_session>(std::move(socket_), state_)->run(std::move(req_));
|
||||||
auto ws = std::make_shared<websocket::stream<beast::tcp_stream>>(std::move(socket_));
|
auto ws = std::make_shared<websocket::stream<beast::tcp_stream>>(std::move(socket_));
|
||||||
ws->async_accept(req_, [ this, ws, self = shared_from_this() ](beast::error_code ec) {
|
ws->async_accept(req_, [this, ws, self = shared_from_this()](beast::error_code ec) {
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
LOG(ERROR, LOG_TAG) << "Error during WebSocket handshake (control): " << ec.message() << "\n";
|
LOG(ERROR, LOG_TAG) << "Error during WebSocket handshake (control): " << ec.message() << "\n";
|
||||||
|
@ -330,7 +331,7 @@ void ControlSessionHttp::on_read(beast::error_code ec, std::size_t bytes_transfe
|
||||||
// Create a WebSocket session by transferring the socket
|
// Create a WebSocket session by transferring the socket
|
||||||
// std::make_shared<websocket_session>(std::move(socket_), state_)->run(std::move(req_));
|
// std::make_shared<websocket_session>(std::move(socket_), state_)->run(std::move(req_));
|
||||||
auto ws = std::make_shared<websocket::stream<beast::tcp_stream>>(std::move(socket_));
|
auto ws = std::make_shared<websocket::stream<beast::tcp_stream>>(std::move(socket_));
|
||||||
ws->async_accept(req_, [ this, ws, self = shared_from_this() ](beast::error_code ec) {
|
ws->async_accept(req_, [this, ws, self = shared_from_this()](beast::error_code ec) {
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
LOG(ERROR, LOG_TAG) << "Error during WebSocket handshake (stream): " << ec.message() << "\n";
|
LOG(ERROR, LOG_TAG) << "Error during WebSocket handshake (stream): " << ec.message() << "\n";
|
||||||
|
@ -355,7 +356,7 @@ void ControlSessionHttp::on_read(beast::error_code ec, std::size_t bytes_transfe
|
||||||
|
|
||||||
// Write the response
|
// Write the response
|
||||||
http::async_write(this->socket_, *sp,
|
http::async_write(this->socket_, *sp,
|
||||||
boost::asio::bind_executor(strand_, [ this, self = this->shared_from_this(), sp ](beast::error_code ec, std::size_t bytes) {
|
boost::asio::bind_executor(strand_, [this, self = this->shared_from_this(), sp](beast::error_code ec, std::size_t bytes) {
|
||||||
this->on_write(ec, bytes, sp->need_eof());
|
this->on_write(ec, bytes, sp->need_eof());
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
@ -385,7 +386,7 @@ void ControlSessionHttp::on_write(beast::error_code ec, std::size_t, bool close)
|
||||||
|
|
||||||
// Read another request
|
// Read another request
|
||||||
http::async_read(socket_, buffer_, req_,
|
http::async_read(socket_, buffer_, req_,
|
||||||
boost::asio::bind_executor(strand_, [ this, self = shared_from_this() ](beast::error_code ec, std::size_t bytes) { on_read(ec, bytes); }));
|
boost::asio::bind_executor(strand_, [this, self = shared_from_this()](beast::error_code ec, std::size_t bytes) { on_read(ec, bytes); }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ void ControlSessionTcp::do_read()
|
||||||
const std::string delimiter = "\n";
|
const std::string delimiter = "\n";
|
||||||
boost::asio::async_read_until(
|
boost::asio::async_read_until(
|
||||||
socket_, streambuf_, delimiter,
|
socket_, streambuf_, delimiter,
|
||||||
boost::asio::bind_executor(strand_, [ this, self = shared_from_this(), delimiter ](const std::error_code& ec, std::size_t bytes_transferred) {
|
boost::asio::bind_executor(strand_, [this, self = shared_from_this(), delimiter](const std::error_code& ec, std::size_t bytes_transferred) {
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
LOG(ERROR, LOG_TAG) << "Error while reading from control socket: " << ec.message() << "\n";
|
LOG(ERROR, LOG_TAG) << "Error while reading from control socket: " << ec.message() << "\n";
|
||||||
|
@ -94,7 +94,7 @@ void ControlSessionTcp::stop()
|
||||||
|
|
||||||
void ControlSessionTcp::sendAsync(const std::string& message)
|
void ControlSessionTcp::sendAsync(const std::string& message)
|
||||||
{
|
{
|
||||||
strand_.post([ this, self = shared_from_this(), message ]() {
|
strand_.post([this, self = shared_from_this(), message]() {
|
||||||
messages_.emplace_back(message + "\r\n");
|
messages_.emplace_back(message + "\r\n");
|
||||||
if (messages_.size() > 1)
|
if (messages_.size() > 1)
|
||||||
{
|
{
|
||||||
|
@ -108,7 +108,7 @@ void ControlSessionTcp::sendAsync(const std::string& message)
|
||||||
void ControlSessionTcp::send_next()
|
void ControlSessionTcp::send_next()
|
||||||
{
|
{
|
||||||
boost::asio::async_write(socket_, boost::asio::buffer(messages_.front()),
|
boost::asio::async_write(socket_, boost::asio::buffer(messages_.front()),
|
||||||
boost::asio::bind_executor(strand_, [ this, self = shared_from_this() ](std::error_code ec, std::size_t length) {
|
boost::asio::bind_executor(strand_, [this, self = shared_from_this()](std::error_code ec, std::size_t length) {
|
||||||
messages_.pop_front();
|
messages_.pop_front();
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
|
|
|
@ -61,7 +61,7 @@ void ControlSessionWebsocket::stop()
|
||||||
|
|
||||||
void ControlSessionWebsocket::sendAsync(const std::string& message)
|
void ControlSessionWebsocket::sendAsync(const std::string& message)
|
||||||
{
|
{
|
||||||
strand_.post([ this, self = shared_from_this(), msg = message ]() {
|
strand_.post([this, self = shared_from_this(), msg = message]() {
|
||||||
messages_.push_back(std::move(msg));
|
messages_.push_back(std::move(msg));
|
||||||
if (messages_.size() > 1)
|
if (messages_.size() > 1)
|
||||||
{
|
{
|
||||||
|
@ -77,7 +77,7 @@ void ControlSessionWebsocket::send_next()
|
||||||
{
|
{
|
||||||
const std::string& message = messages_.front();
|
const std::string& message = messages_.front();
|
||||||
ws_.async_write(boost::asio::buffer(message),
|
ws_.async_write(boost::asio::buffer(message),
|
||||||
boost::asio::bind_executor(strand_, [ this, self = shared_from_this() ](std::error_code ec, std::size_t length) {
|
boost::asio::bind_executor(strand_, [this, self = shared_from_this()](std::error_code ec, std::size_t length) {
|
||||||
messages_.pop_front();
|
messages_.pop_front();
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
|
@ -96,7 +96,7 @@ void ControlSessionWebsocket::send_next()
|
||||||
void ControlSessionWebsocket::do_read_ws()
|
void ControlSessionWebsocket::do_read_ws()
|
||||||
{
|
{
|
||||||
// Read a message into our buffer
|
// Read a message into our buffer
|
||||||
ws_.async_read(buffer_, boost::asio::bind_executor(strand_, [ this, self = shared_from_this() ](beast::error_code ec, std::size_t bytes_transferred) {
|
ws_.async_read(buffer_, boost::asio::bind_executor(strand_, [this, self = shared_from_this()](beast::error_code ec, std::size_t bytes_transferred) {
|
||||||
on_read_ws(ec, bytes_transferred);
|
on_read_ws(ec, bytes_transferred);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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_)
|
||||||
|
|
|
@ -222,8 +222,8 @@ void PublishAvahi::client_callback(AvahiClient* c, AvahiClientState state, AVAHI
|
||||||
|
|
||||||
case AVAHI_CLIENT_S_COLLISION:
|
case AVAHI_CLIENT_S_COLLISION:
|
||||||
|
|
||||||
/// Let's drop our registered services. When the server is back
|
/// Let's drop our registered services. When the server is back
|
||||||
/// in AVAHI_SERVER_RUNNING state we will register them again with the new host name.
|
/// in AVAHI_SERVER_RUNNING state we will register them again with the new host name.
|
||||||
|
|
||||||
case AVAHI_CLIENT_S_REGISTERING:
|
case AVAHI_CLIENT_S_REGISTERING:
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -52,7 +52,7 @@ void StreamSession::send_next()
|
||||||
{
|
{
|
||||||
auto& buffer = messages_.front();
|
auto& buffer = messages_.front();
|
||||||
buffer.on_air = true;
|
buffer.on_air = true;
|
||||||
strand_.post([ this, self = shared_from_this(), buffer ]() {
|
strand_.post([this, self = shared_from_this(), buffer]() {
|
||||||
sendAsync(buffer, [this](boost::system::error_code ec, std::size_t length) {
|
sendAsync(buffer, [this](boost::system::error_code ec, std::size_t length) {
|
||||||
messages_.pop_front();
|
messages_.pop_front();
|
||||||
if (ec)
|
if (ec)
|
||||||
|
@ -70,7 +70,7 @@ void StreamSession::send_next()
|
||||||
|
|
||||||
void StreamSession::send(shared_const_buffer const_buf)
|
void StreamSession::send(shared_const_buffer const_buf)
|
||||||
{
|
{
|
||||||
strand_.post([ this, self = shared_from_this(), const_buf ]() {
|
strand_.post([this, self = shared_from_this(), const_buf]() {
|
||||||
// delete PCM chunks that are older than the overall buffer duration
|
// delete PCM chunks that are older than the overall buffer duration
|
||||||
messages_.erase(std::remove_if(messages_.begin(), messages_.end(),
|
messages_.erase(std::remove_if(messages_.begin(), messages_.end(),
|
||||||
[this](const shared_const_buffer& buffer) {
|
[this](const shared_const_buffer& buffer) {
|
||||||
|
|
|
@ -81,7 +81,7 @@ std::string StreamSessionTcp::getIP()
|
||||||
void StreamSessionTcp::read_next()
|
void StreamSessionTcp::read_next()
|
||||||
{
|
{
|
||||||
boost::asio::async_read(socket_, boost::asio::buffer(buffer_, base_msg_size_),
|
boost::asio::async_read(socket_, boost::asio::buffer(buffer_, base_msg_size_),
|
||||||
boost::asio::bind_executor(strand_, [ this, self = shared_from_this() ](boost::system::error_code ec, std::size_t length) mutable {
|
boost::asio::bind_executor(strand_, [this, self = shared_from_this()](boost::system::error_code ec, std::size_t length) mutable {
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
LOG(ERROR, LOG_TAG) << "Error reading message header of length " << length << ": " << ec.message() << "\n";
|
LOG(ERROR, LOG_TAG) << "Error reading message header of length " << length << ": " << ec.message() << "\n";
|
||||||
|
@ -131,6 +131,6 @@ void StreamSessionTcp::read_next()
|
||||||
void StreamSessionTcp::sendAsync(const shared_const_buffer& buffer, const WriteHandler& handler)
|
void StreamSessionTcp::sendAsync(const shared_const_buffer& buffer, const WriteHandler& handler)
|
||||||
{
|
{
|
||||||
boost::asio::async_write(socket_, buffer,
|
boost::asio::async_write(socket_, buffer,
|
||||||
boost::asio::bind_executor(strand_, [ self = shared_from_this(), buffer, handler ](boost::system::error_code ec,
|
boost::asio::bind_executor(strand_, [self = shared_from_this(), buffer, handler](boost::system::error_code ec,
|
||||||
std::size_t length) { handler(ec, length); }));
|
std::size_t length) { handler(ec, length); }));
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,15 +77,16 @@ 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);
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void StreamSessionWebsocket::do_read_ws()
|
void StreamSessionWebsocket::do_read_ws()
|
||||||
{
|
{
|
||||||
// Read a message into our buffer
|
// Read a message into our buffer
|
||||||
ws_.async_read(buffer_, boost::asio::bind_executor(strand_, [ this, self = shared_from_this() ](beast::error_code ec, std::size_t bytes_transferred) {
|
ws_.async_read(buffer_, boost::asio::bind_executor(strand_, [this, self = shared_from_this()](beast::error_code ec, std::size_t bytes_transferred) {
|
||||||
on_read_ws(ec, bytes_transferred);
|
on_read_ws(ec, bytes_transferred);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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