From 3746bd13bc345c7785ed3e06ac8f02e364a57ce3 Mon Sep 17 00:00:00 2001 From: sudden6 Date: Fri, 28 Sep 2018 20:54:12 +0200 Subject: [PATCH] fix(video): workaround for webcams that provide no fps value fixes #5082 --- src/platform/camera/v4l2.cpp | 14 ++++++++++++-- src/widget/form/settings/avform.cpp | 5 +++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/platform/camera/v4l2.cpp b/src/platform/camera/v4l2.cpp index b7e031c27..7741dd54d 100644 --- a/src/platform/camera/v4l2.cpp +++ b/src/platform/camera/v4l2.cpp @@ -126,8 +126,10 @@ QVector v4l2::getDeviceModes(QString devName) int error = 0; int fd = deviceOpen(devName, &error); - if (fd < 0 || error != 0) + if (fd < 0 || error != 0) { return modes; + } + v4l2_fmtdesc vfd{}; vfd.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; @@ -156,10 +158,18 @@ QVector v4l2::getDeviceModes(QString devName) QVector rates = getDeviceModeFramerates(fd, mode.width, mode.height, vfd.pixelformat); + + // insert dummy FPS value to have the mode in the list even if we don't know the FPS + // this fixes support for some webcams, see #5082 + if (rates.isEmpty()) { + rates.append(0.0f); + } + for (float rate : rates) { mode.FPS = rate; - if (!modes.contains(mode)) + if (!modes.contains(mode)) { modes.append(std::move(mode)); + } } vfse.index++; } diff --git a/src/widget/form/settings/avform.cpp b/src/widget/form/settings/avform.cpp index 00f90c4a6..4c8f947a9 100644 --- a/src/widget/form/settings/avform.cpp +++ b/src/widget/form/settings/avform.cpp @@ -222,6 +222,11 @@ void AVForm::on_videoModescomboBox_currentIndexChanged(int index) void AVForm::selectBestModes(QVector& allVideoModes) { + if (allVideoModes.isEmpty()) { + qCritical() << "Trying to select best mode from empty modes list"; + return; + } + // Identify the best resolutions available for the supposed XXXXp resolutions. std::map idealModes; idealModes[120] = VideoMode(160, 120);