Skip to content
Snippets Groups Projects
Commit ca1afb8f authored by Vivien Didelot's avatar Vivien Didelot
Browse files

VideoV4l2Device: open device in constructor

Refs #47657

Change-Id: I97d4907ef38fc74d52c4fa5c02f1b63889015dc4
parent cc1e88b7
No related branches found
No related tags found
No related merge requests found
......@@ -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)) {
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>
......
......@@ -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
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment