Skip to content
Snippets Groups Projects
Commit 3eede614 authored by Sébastien Blin's avatar Sébastien Blin Committed by Adrien Béraud
Browse files

video_device_monitor: avoid infinite loop

Change-Id: I22362d3335a07f00f3e09598a4902ee8042c50ed
GitLab: #379
parent a6d5ad32
No related branches found
No related tags found
Loading
......@@ -148,12 +148,12 @@ VideoDeviceMonitorImpl::VideoDeviceMonitorImpl(VideoDeviceMonitor* monitor)
try {
auto unique_name = getDeviceString(dev);
JAMI_DBG("udev: adding device with id %s", unique_name.c_str());
monitor_->addDevice(unique_name, {{{"devPath", path}}});
currentPathToId_.emplace(path, unique_name);
if (monitor_->addDevice(unique_name, {{{"devPath", path}}}))
currentPathToId_.emplace(path, unique_name);
} catch (const std::exception& e) {
JAMI_WARN("udev: %s, fallback on path (your camera may be a fake camera)", e.what());
monitor_->addDevice(path, {{{"devPath", path}}});
currentPathToId_.emplace(path, path);
if (monitor_->addDevice(path, {{{"devPath", path}}}))
currentPathToId_.emplace(path, path);
}
}
udev_device_unref(dev);
......@@ -175,10 +175,9 @@ udev_failed:
/* fallback : go through /dev/video* */
for (int idx = 0;; ++idx) {
std::stringstream ss;
ss << "/dev/video" << idx;
try {
monitor_->addDevice(ss.str());
if (!monitor_->addDevice("/dev/video" + std::to_string(idx)))
break;
} catch (const std::runtime_error& e) {
JAMI_ERR("%s", e.what());
return;
......@@ -237,8 +236,8 @@ VideoDeviceMonitorImpl::run()
const char* action = udev_device_get_action(dev);
if (!strcmp(action, "add")) {
JAMI_DBG("udev: adding device with id %s", unique_name.c_str());
monitor_->addDevice(unique_name, {{{"devPath", path}}});
currentPathToId_.emplace(path, unique_name);
if (monitor_->addDevice(unique_name, {{{"devPath", path}}}))
currentPathToId_.emplace(path, unique_name);
} else if (!strcmp(action, "remove")) {
auto it = currentPathToId_.find(path);
if (it != currentPathToId_.end()) {
......
......@@ -187,20 +187,20 @@ notify()
}
}
void
bool
VideoDeviceMonitor::addDevice(const string& id,
const std::vector<std::map<std::string, std::string>>& devInfo)
{
try {
std::lock_guard<std::mutex> l(lock_);
if (findDeviceById(id) != devices_.end())
return;
return false;
// instantiate a new unique device
VideoDevice dev {id, devInfo};
if (dev.getChannelList().empty())
return;
return false;
giveUniqueName(dev, devices_);
......@@ -220,9 +220,10 @@ VideoDeviceMonitor::addDevice(const string& id,
devices_.emplace_back(std::move(dev));
} catch (const std::exception& e) {
JAMI_ERR("Failed to add device %s: %s", id.c_str(), e.what());
return;
return false;
}
notify();
return true;
}
void
......
......@@ -59,7 +59,7 @@ public:
bool setDefaultDevice(const std::string& name);
void setDeviceOrientation(const std::string& id, int angle);
void addDevice(const std::string& node,
bool addDevice(const std::string& node,
const std::vector<std::map<std::string, std::string>>& devInfo = {});
void removeDevice(const std::string& node);
void removeDeviceViaInput(const std::string& path);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment