From 713aeb20868d51a496ac55ecbbff8923a12908e6 Mon Sep 17 00:00:00 2001 From: liberuum Date: Thu, 5 Nov 2026 09:49:22 +0000 Subject: [PATCH] Default to the largest camera format that sustains 15 fps bestFormat ranked formats by pixel area alone, so cameras whose largest mode is uncompressed YUYV over USB 2.0 opened at 2 fps. On a Logitech C925e that is 2304x1536 YUYV, while the same camera offers 1920x1080 MJPEG at 30 fps. Formats below 15 fps now lose to any format that reaches it; among usable formats the largest still wins, so 4K at 15 fps is still preferred over 1080p at 30 fps as before. Co-Authored-By: Claude Opus 5.5 --- src/mediautils.cpp | 5 +++++ tests/backend_tests.cpp | 3 +++ 2 files changed, 8 insertions(+) diff --git a/src/mediautils.cpp b/src/mediautils.cpp index 190212f..33b882c 100644 --- a/src/mediautils.cpp +++ b/src/mediautils.cpp @@ -21,6 +21,11 @@ int media::bestFormat(const QList &formats) { const qint64 area = qint64(f.size.width()) * f.size.height(); const qint64 bestArea = qint64(b.size.width()) * b.size.height(); const double rate = targetFps(f.minFps, f.maxFps), bestRate = targetFps(b.minFps, b.maxFps); + // Largest resolution wins, but only among formats that sustain a usable + // frame rate: uncompressed modes at sensor maximum often run at 2 fps. + constexpr double usableFps = 15; + const double usable = std::min(rate, usableFps), bestUsable = std::min(bestRate, usableFps); + if (usable != bestUsable) { if (usable > bestUsable) best = i; continue; } if (area > bestArea || (area == bestArea && (std::abs(rate - 30) < std::abs(bestRate - 30) || (std::abs(rate - 30) == std::abs(bestRate - 30) && diff --git a/tests/backend_tests.cpp b/tests/backend_tests.cpp index 19745fe..e3cef2a 100644 --- a/tests/backend_tests.cpp +++ b/tests/backend_tests.cpp @@ -41,6 +41,9 @@ private slots: f.append({{3840,2160},30,30,0}); QCOMPARE(media::bestFormat(f),3); f.append({{3840,2160},30,60,0}); QCOMPARE(media::bestFormat(f),3); QCOMPARE(media::bestFormat({}),-1); + // Logitech C925e: YUYV at sensor maximum only manages 2 fps. + QList c{{{2304,1536},2,2,1}, {{1920,1080},5,30,2}, {{1920,1080},5,5,1}, {{640,480},5,30,1}}; + QCOMPARE(media::bestFormat(c),1); QCOMPARE(media::targetFps(15,15),15.0); } void clockExcludesPauses() {