diff --git a/daemon/src/video/v4l2/video_device_monitor.cpp b/daemon/src/video/v4l2/video_device_monitor.cpp index f38a980e260351046efa5d32b1e43676d77db379..4e3524cd14abfbc10c967895a8094e820b90d3d8 100644 --- a/daemon/src/video/v4l2/video_device_monitor.cpp +++ b/daemon/src/video/v4l2/video_device_monitor.cpp @@ -84,7 +84,7 @@ class VideoDeviceMonitorImpl { std::vector<VideoV4l2Device>::const_iterator findDevice(const std::string &name) const; NON_COPYABLE(VideoDeviceMonitorImpl); void delDevice(const std::string &node); - bool addDevice(const std::string &dev); + void addDevice(const std::string &dev); std::vector<VideoV4l2Device> devices_; std::thread thread_; mutable std::mutex mutex_; @@ -170,8 +170,7 @@ udev_failed: std::stringstream ss; ss << "/dev/video" << idx; try { - if (!addDevice(ss.str())) - return; + addDevice(ss.str()); } catch (const std::runtime_error &e) { ERROR("%s", e.what()); return; @@ -277,9 +276,8 @@ void VideoDeviceMonitorImpl::run() if (!strcmp(action, "add")) { DEBUG("udev: adding %s", node); try { - if (addDevice(node)) { - Manager::instance().getVideoManager()->deviceEvent(); - } + addDevice(node); + Manager::instance().getVideoManager()->deviceEvent(); } catch (const std::runtime_error &e) { ERROR("%s", e.what()); } @@ -319,24 +317,13 @@ void VideoDeviceMonitorImpl::delDevice(const string &node) } } -bool VideoDeviceMonitorImpl::addDevice(const string &dev) +void VideoDeviceMonitorImpl::addDevice(const string &dev) { std::lock_guard<std::mutex> lock(mutex_); - int fd = open(dev.c_str(), O_RDWR); - if (fd == -1) { - ERROR("Problem opening device"); - strErr(); - return false; - } - - const string s(dev); - VideoV4l2Device v(fd, s); + VideoV4l2Device v(dev); giveUniqueName(v, devices_); devices_.push_back(v); - - ::close(fd); - return true; } vector<string> diff --git a/daemon/src/video/v4l2/video_v4l2.cpp b/daemon/src/video/v4l2/video_v4l2.cpp index 3385c6816ec9a60e159b13859cbe306bc875272f..55d474a44e5345bdc8515cec733198fef7feb610 100644 --- a/daemon/src/video/v4l2/video_v4l2.cpp +++ b/daemon/src/video/v4l2/video_v4l2.cpp @@ -328,9 +328,13 @@ VideoV4l2Size VideoV4l2Channel::getSize(const string &name) const } -VideoV4l2Device::VideoV4l2Device(int fd, const string &device) : +VideoV4l2Device::VideoV4l2Device(const string &device) : device(device), name(), channels_() { + int fd = open(device.c_str(), O_RDWR); + if (fd == -1) + throw std::runtime_error("could not open device"); + v4l2_capability cap; if (ioctl(fd, VIDIOC_QUERYCAP, &cap)) throw std::runtime_error("could not query capabilities"); @@ -356,6 +360,8 @@ VideoV4l2Device::VideoV4l2Device(int fd, const string &device) : input.index = ++idx; } + + ::close(fd); } vector<string> VideoV4l2Device::getChannelList() const diff --git a/daemon/src/video/v4l2/video_v4l2.h b/daemon/src/video/v4l2/video_v4l2.h index 0e1d46b9e32c254b8b2353ae4221202c56db27a9..15af31cc327937c7d15cb37a4389ed7d5392ee4b 100644 --- a/daemon/src/video/v4l2/video_v4l2.h +++ b/daemon/src/video/v4l2/video_v4l2.h @@ -94,7 +94,7 @@ class VideoV4l2Device { /** * @throw std::runtime_error */ - VideoV4l2Device(int fd, const std::string &device); + VideoV4l2Device(const std::string &device); std::string device; std::string name;