1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix(video): usage of invalid file descriptors on error

Fixes code for getDeviceModes() under vfl2 namespace where error
numbers were being treated as valid file descriptors
This commit is contained in:
initramfs 2016-04-03 14:16:45 -04:00
parent dde56c99ec
commit 556a8750a1
No known key found for this signature in database
GPG Key ID: 78B8BDF87E9EF0AF

View File

@ -56,28 +56,29 @@ static std::map<uint32_t,QString> createPixFmtToName()
} }
const std::map<uint32_t,QString> pixFmtToName = createPixFmtToName(); const std::map<uint32_t,QString> pixFmtToName = createPixFmtToName();
static int deviceOpen(QString devName) static int deviceOpen(QString devName, int* error)
{ {
struct v4l2_capability cap; struct v4l2_capability cap;
int fd; int fd;
int err;
fd = open(devName.toStdString().c_str(), O_RDWR, 0); fd = open(devName.toStdString().c_str(), O_RDWR, 0);
if (fd < 0) if (fd < 0) {
return errno; *error = errno;
return fd;
}
if (ioctl(fd, VIDIOC_QUERYCAP, &cap) < 0) { if (ioctl(fd, VIDIOC_QUERYCAP, &cap) < 0) {
err = errno; *error = errno;
goto fail; goto fail;
} }
if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) { if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
err = ENODEV; *error = ENODEV;
goto fail; goto fail;
} }
if (!(cap.capabilities & V4L2_CAP_STREAMING)) { if (!(cap.capabilities & V4L2_CAP_STREAMING)) {
err = ENOSYS; *error = ENOSYS;
goto fail; goto fail;
} }
@ -85,7 +86,7 @@ static int deviceOpen(QString devName)
fail: fail:
close(fd); close(fd);
return err; return -1;
} }
static QVector<unsigned short> getDeviceModeFramerates(int fd, unsigned w, unsigned h, uint32_t pixelFormat) static QVector<unsigned short> getDeviceModeFramerates(int fd, unsigned w, unsigned h, uint32_t pixelFormat)
@ -120,8 +121,9 @@ QVector<VideoMode> v4l2::getDeviceModes(QString devName)
{ {
QVector<VideoMode> modes; QVector<VideoMode> modes;
int fd = deviceOpen(devName); int error = 0;
if (fd < 0) int fd = deviceOpen(devName, &error);
if (fd < 0 || error != 0)
return modes; return modes;
v4l2_fmtdesc vfd{}; v4l2_fmtdesc vfd{};
vfd.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; vfd.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;