Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(video): workaround for webcams that provide no fps value
Browse files Browse the repository at this point in the history
fixes #5082
  • Loading branch information
sudden6 committed Sep 29, 2018
1 parent 39dc6da commit 3746bd1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/platform/camera/v4l2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ QVector<VideoMode> 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;

Expand Down Expand Up @@ -156,10 +158,18 @@ QVector<VideoMode> v4l2::getDeviceModes(QString devName)

QVector<float> 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++;
}
Expand Down
5 changes: 5 additions & 0 deletions src/widget/form/settings/avform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ void AVForm::on_videoModescomboBox_currentIndexChanged(int index)

void AVForm::selectBestModes(QVector<VideoMode>& 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<int, VideoMode> idealModes;
idealModes[120] = VideoMode(160, 120);
Expand Down

0 comments on commit 3746bd1

Please sign in to comment.