diff --git a/src/platform/camera/v4l2.cpp b/src/platform/camera/v4l2.cpp index ec9790698..a52a9bde4 100644 --- a/src/platform/camera/v4l2.cpp +++ b/src/platform/camera/v4l2.cpp @@ -91,17 +91,17 @@ fail: return -1; } -static QVector getDeviceModeFramerates(int fd, unsigned w, unsigned h, +static QVector getDeviceModeFramerates(int fd, unsigned w, unsigned h, uint32_t pixelFormat) { - QVector rates; + QVector rates; v4l2_frmivalenum vfve{}; vfve.pixel_format = pixelFormat; vfve.height = h; vfve.width = w; while (!ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &vfve)) { - int rate; + float rate; switch (vfve.type) { case V4L2_FRMSIZE_TYPE_DISCRETE: rate = vfve.discrete.denominator / vfve.discrete.numerator; @@ -154,9 +154,9 @@ QVector v4l2::getDeviceModes(QString devName) continue; } - QVector rates = + QVector rates = getDeviceModeFramerates(fd, mode.width, mode.height, vfd.pixelformat); - for (unsigned short rate : rates) { + for (float rate : rates) { mode.FPS = rate; if (!modes.contains(mode)) modes.append(std::move(mode)); diff --git a/src/video/camerasource.cpp b/src/video/camerasource.cpp index b16d1d660..8bd7a2ce5 100644 --- a/src/video/camerasource.cpp +++ b/src/video/camerasource.cpp @@ -284,8 +284,9 @@ void CameraSource::openDevice() // We need to open the device as many time as we already have subscribers, // otherwise the device could get closed while we still have subscribers - for (int i = 0; i < subscriptions; ++i) + for (int i = 0; i < subscriptions; ++i) { device->open(); + } // Find the first video stream, if any for (unsigned i = 0; i < device->context->nb_streams; ++i) { diff --git a/src/video/videomode.cpp b/src/video/videomode.cpp index e5fa50c71..3b9603a1a 100644 --- a/src/video/videomode.cpp +++ b/src/video/videomode.cpp @@ -31,15 +31,15 @@ * * @var float VideoMode::FPS * @brief Frames per second supported by the device at this resolution + * @note a value < 0 indicates an invalid value */ -VideoMode::VideoMode(int width, int height, int x, int y, float FPS, int format) +VideoMode::VideoMode(int width, int height, int x, int y, float FPS) : width(width) , height(height) , x(x) , y(y) , FPS(FPS) - , pixel_format(format) { } @@ -48,8 +48,6 @@ VideoMode::VideoMode(QRect rect) , height(rect.height()) , x(rect.x()) , y(rect.y()) - , FPS(0) - , pixel_format(0) { } @@ -74,5 +72,5 @@ uint32_t VideoMode::norm(const VideoMode& other) const */ VideoMode::operator bool() const { - return width || height || FPS; + return width || height || (FPS < 0); } diff --git a/src/video/videomode.h b/src/video/videomode.h index c16747950..4af8c089e 100644 --- a/src/video/videomode.h +++ b/src/video/videomode.h @@ -27,10 +27,10 @@ struct VideoMode { int width, height; int x, y; - float FPS; - uint32_t pixel_format; + float FPS = -1.0f; + uint32_t pixel_format = 0; - VideoMode(int width = 0, int height = 0, int x = 0, int y = 0, float FPS = 0.0f, int format = 0); + VideoMode(int width = 0, int height = 0, int x = 0, int y = 0, float FPS = -1.0f); explicit VideoMode(QRect rect); diff --git a/src/widget/form/settings/avform.cpp b/src/widget/form/settings/avform.cpp index 092de6e9b..243683df5 100644 --- a/src/widget/form/settings/avform.cpp +++ b/src/widget/form/settings/avform.cpp @@ -319,13 +319,14 @@ void AVForm::fillCameraModesComboBox() int AVForm::searchPreferredIndex() { QRect prefRes = videoSettings->getCamVideoRes(); - quint16 prefFPS = videoSettings->getCamVideoFPS(); + float prefFPS = videoSettings->getCamVideoFPS(); for (int i = 0; i < videoModes.size(); ++i) { VideoMode mode = videoModes[i]; if (mode.width == prefRes.width() && mode.height == prefRes.height() - && static_cast(mode.FPS) == prefFPS) + && (qAbs(mode.FPS - prefFPS) < 0.0001f)) { return i; + } } return -1;