diff --git a/src/media/video/video_device_monitor.cpp b/src/media/video/video_device_monitor.cpp index c1f5173a00bee23054255557e4cd112f3c892ccb..f8640cbca1fed0cd54e423051661377782d5d817 100644 --- a/src/media/video/video_device_monitor.cpp +++ b/src/media/video/video_device_monitor.cpp @@ -194,12 +194,12 @@ notify() void VideoDeviceMonitor::addDevice(const string& node, const std::vector<std::map<std::string, std::string>>* devInfo) { - std::unique_lock<std::mutex> l(lock_); - if (findDeviceByNode(node) != devices_.end()) - return; - - // instantiate a new unique device try { + std::lock_guard<std::mutex> l(lock_); + if (findDeviceByNode(node) != devices_.end()) + return; + + // instantiate a new unique device VideoDevice dev {node, *devInfo}; if (dev.getChannelList().empty()) @@ -221,13 +221,11 @@ VideoDeviceMonitor::addDevice(const string& node, const std::vector<std::map<std defaultDevice_ = dev.name; devices_.emplace_back(std::move(dev)); - - l.unlock(); - notify(); } catch (const std::exception& e) { RING_ERR("Failed to add device %s: %s", node.c_str(), e.what()); return; } + notify(); } void diff --git a/src/media/video/video_device_monitor.h b/src/media/video/video_device_monitor.h index 73d05c7ad95ed43e5ab82da3e18a3cfac7e20111..63f14e3ac3900c4a1bbc660137949dee781711a3 100644 --- a/src/media/video/video_device_monitor.h +++ b/src/media/video/video_device_monitor.h @@ -74,6 +74,7 @@ class VideoDeviceMonitor : public Serializable private: NON_COPYABLE(VideoDeviceMonitor); + mutable std::mutex lock_; /* * User preferred settings for a device, * as loaded from (and stored to) the configuration file. @@ -95,7 +96,6 @@ class VideoDeviceMonitor : public Serializable std::vector<VideoDevice>::const_iterator findDeviceByNode(const std::string& node) const; std::unique_ptr<VideoDeviceMonitorImpl> monitorImpl_; - mutable std::mutex lock_; constexpr static const char *CONFIG_LABEL = "video"; };