Skip to content

Commit 3243c05

Browse files
refactor(sonar): fix sonar warnings (#217)
1 parent 0d22dc6 commit 3243c05

6 files changed

Lines changed: 238 additions & 91 deletions

File tree

src/network/host_discovery.cpp

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,20 @@ namespace {
182182
* @brief Thread-safe collector updated by the lwIP mDNS search callback.
183183
*/
184184
struct DiscoveryCollector {
185-
mutable std::mutex mutex; ///< Guards the partial discovery state shared with the callback.
186-
std::unordered_map<std::string, PendingDiscoveredService> servicesByInstance; ///< Partial records keyed by instance domain.
187-
std::unordered_map<std::string, std::string> ipv4ByDomain; ///< Resolved IPv4 addresses keyed by target host domain.
185+
/**
186+
* @brief Construct an empty discovery collector.
187+
*/
188+
DiscoveryCollector() = default;
189+
190+
private:
191+
friend void remember_ptr_service_instance(DiscoveryCollector *collector, std::string instanceDomain);
192+
friend void remember_srv_service_target(DiscoveryCollector *collector, std::string instanceDomain, std::string targetDomain, uint16_t port);
193+
friend void remember_a_record(DiscoveryCollector *collector, std::string domain, std::string ipv4Address);
194+
friend network::DiscoverHostsResult build_discover_hosts_result(const DiscoveryCollector &collector);
195+
196+
mutable std::mutex mutex_; ///< Guards the partial discovery state shared with the callback.
197+
std::unordered_map<std::string, PendingDiscoveredService> servicesByInstance_; ///< Partial records keyed by instance domain.
198+
std::unordered_map<std::string, std::string> ipv4ByDomain_; ///< Resolved IPv4 addresses keyed by target host domain.
188199
};
189200

190201
std::string encoded_domain_to_string(const char *encodedDomain, std::size_t encodedLength) {
@@ -235,8 +246,8 @@ namespace {
235246
return;
236247
}
237248

238-
const std::scoped_lock lock(collector->mutex);
239-
PendingDiscoveredService &service = collector->servicesByInstance[instanceDomain];
249+
const std::scoped_lock lock(collector->mutex_);
250+
PendingDiscoveredService &service = collector->servicesByInstance_[instanceDomain];
240251
service.instanceDomain = std::move(instanceDomain);
241252
if (service.displayName.empty()) {
242253
service.displayName = first_dns_label(service.instanceDomain);
@@ -248,8 +259,8 @@ namespace {
248259
return;
249260
}
250261

251-
const std::scoped_lock lock(collector->mutex);
252-
PendingDiscoveredService &service = collector->servicesByInstance[instanceDomain];
262+
const std::scoped_lock lock(collector->mutex_);
263+
PendingDiscoveredService &service = collector->servicesByInstance_[instanceDomain];
253264
service.instanceDomain = std::move(instanceDomain);
254265
if (service.displayName.empty()) {
255266
service.displayName = first_dns_label(service.instanceDomain);
@@ -263,8 +274,8 @@ namespace {
263274
return;
264275
}
265276

266-
const std::scoped_lock lock(collector->mutex);
267-
collector->ipv4ByDomain[std::move(domain)] = std::move(ipv4Address);
277+
const std::scoped_lock lock(collector->mutex_);
278+
collector->ipv4ByDomain_[std::move(domain)] = std::move(ipv4Address);
268279
}
269280

270281
/**
@@ -315,14 +326,14 @@ namespace {
315326
network::DiscoverHostsResult build_discover_hosts_result(const DiscoveryCollector &collector) {
316327
network::DiscoverHostsResult result {};
317328

318-
const std::scoped_lock lock(collector.mutex);
319-
for (const auto &[instanceDomain, service] : collector.servicesByInstance) {
329+
const std::scoped_lock lock(collector.mutex_);
330+
for (const auto &[instanceDomain, service] : collector.servicesByInstance_) {
320331
(void) instanceDomain;
321332
if (service.targetDomain.empty() || service.port == 0) {
322333
continue;
323334
}
324-
const auto addressIterator = collector.ipv4ByDomain.find(service.targetDomain);
325-
if (addressIterator == collector.ipv4ByDomain.end()) {
335+
const auto addressIterator = collector.ipv4ByDomain_.find(service.targetDomain);
336+
if (addressIterator == collector.ipv4ByDomain_.end()) {
326337
continue;
327338
}
328339

src/streaming/ffmpeg_stream_backend.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ namespace streaming {
457457

458458
bool textureNeedsUpload = false;
459459
if (const std::uint64_t publishedFrameVersion = video_.publishedFrameVersion.load(); publishedFrameVersion != video_.renderedFrameVersion) {
460-
std::scoped_lock lock(video_.frameMutex);
460+
std::scoped_lock lock(video_.frame_mutex());
461461
if (video_.latestFrameVersion != video_.renderedFrameVersion && video_.latestFrame.width > 0 && video_.latestFrame.height > 0) {
462462
std::swap(video_.renderFrame, video_.latestFrame);
463463
video_.renderedFrameVersion = video_.latestFrameVersion;
@@ -611,7 +611,7 @@ namespace streaming {
611611
video_.renderFrame = LatestVideoFrame {};
612612
video_.decodeFrame = LatestVideoFrame {};
613613
{
614-
std::scoped_lock lock(video_.frameMutex);
614+
std::scoped_lock lock(video_.frame_mutex());
615615
video_.latestFrame = LatestVideoFrame {};
616616
video_.latestFrameVersion = 0;
617617
}
@@ -742,7 +742,7 @@ namespace streaming {
742742
std::memcpy(nextFrame.vPlane.data(), frameToPresent->data[2], nextFrame.vPlane.size());
743743

744744
{
745-
std::scoped_lock lock(video_.frameMutex);
745+
std::scoped_lock lock(video_.frame_mutex());
746746
std::swap(video_.latestFrame, video_.decodeFrame);
747747
++video_.latestFrameVersion;
748748
video_.publishedFrameVersion.store(video_.latestFrameVersion);

src/streaming/ffmpeg_stream_backend.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,20 @@ namespace streaming {
277277
std::uint64_t renderedFrameVersion = 0;
278278
std::vector<std::uint8_t> convertedBuffer;
279279
std::vector<std::uint8_t> packetBuffer;
280-
mutable std::mutex frameMutex;
280+
281+
/**
282+
* @brief Return the mutex guarding decoded frame publication.
283+
*
284+
* @return Mutex used to exchange frames between decode and render threads.
285+
*/
286+
[[nodiscard]] std::mutex &frame_mutex() const {
287+
return frameMutex_;
288+
}
289+
290+
private:
291+
mutable std::mutex frameMutex_; ///< Guards latest decoded frame publication between worker and render threads.
292+
293+
public:
281294
SDL_Rect directFramebufferDestination {0, 0, 0, 0};
282295
LatestVideoFrame latestFrame;
283296
LatestVideoFrame decodeFrame;

0 commit comments

Comments
 (0)