From ac95d1a691332934fae7ea5ee3a17be35228d480 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Wed, 11 Mar 2020 09:56:36 +0200 Subject: videodevice: use exception to catch bad fd --- kms++util/src/videodevice.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/kms++util/src/videodevice.cpp b/kms++util/src/videodevice.cpp index 23f45d4..89a7286 100644 --- a/kms++util/src/videodevice.cpp +++ b/kms++util/src/videodevice.cpp @@ -248,7 +248,8 @@ VideoDevice::VideoDevice(const string& dev) VideoDevice::VideoDevice(int fd) : m_fd(fd), m_has_capture(false), m_has_output(false), m_has_m2m(false), m_capture_streamer(0), m_output_streamer(0) { - FAIL_IF(fd < 0, "Bad fd"); + if (fd < 0) + throw runtime_error("bad fd"); struct v4l2_capability cap = { }; int r = ioctl(fd, VIDIOC_QUERYCAP, &cap); @@ -370,10 +371,13 @@ vector VideoDevice::get_capture_devices() if (stat(name.c_str(), &buffer) != 0) continue; - VideoDevice vid(name); + try { + VideoDevice vid(name); - if (vid.has_capture() && !vid.has_m2m()) - v.push_back(name); + if (vid.has_capture() && !vid.has_m2m()) + v.push_back(name); + } catch (...) { + } } return v; @@ -390,10 +394,13 @@ vector VideoDevice::get_m2m_devices() if (stat(name.c_str(), &buffer) != 0) continue; - VideoDevice vid(name); + try { + VideoDevice vid(name); - if (vid.has_m2m()) - v.push_back(name); + if (vid.has_m2m()) + v.push_back(name); + } catch (...) { + } } return v; -- cgit v1.2.3