From 440480f1cbc2f9aa11b1a5ae3dd8be5f2f185be6 Mon Sep 17 00:00:00 2001 From: Greg White Date: Tue, 9 Jan 2024 17:39:30 +1300 Subject: [PATCH] Reverse min/max definitions to fix framerate comparison --- FlashCap.Core/Devices/V4L2Devices.cs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/FlashCap.Core/Devices/V4L2Devices.cs b/FlashCap.Core/Devices/V4L2Devices.cs index 3701523..b29dc69 100644 --- a/FlashCap.Core/Devices/V4L2Devices.cs +++ b/FlashCap.Core/Devices/V4L2Devices.cs @@ -119,14 +119,19 @@ private static IEnumerable EnumerateFramesPerSecond( }). SelectMany(frmivalenum => { - // v4l2_fract is "interval", so makes fps to do reciprocal. - // (numerator <--> denominator) + static IEnumerable EnumerateStepWise( v4l2_frmival_stepwise stepwise) { - var min = new Fraction((int)stepwise.min.denominator, (int)stepwise.min.numerator); - var max = new Fraction((int)stepwise.max.denominator, (int)stepwise.max.numerator); + // v4l2_fract is "interval", so do reciprocal to make fps. + // (numerator <--> denominator) + + // Since we're inverting the interval to get the FPS, we also need to swap the meaning of min/max + var min = new Fraction((int)stepwise.max.denominator, (int)stepwise.max.numerator); + var max = new Fraction((int)stepwise.min.denominator, (int)stepwise.min.numerator); + var step = new Fraction((int)stepwise.step.denominator, (int)stepwise.step.numerator); + return NativeMethods.DefactoStandardFramesPerSecond. Where(fps => fps >= min && fps <= max && @@ -138,8 +143,13 @@ static IEnumerable EnumerateStepWise( static IEnumerable EnumerateContinuous( v4l2_frmival_stepwise stepwise) { - var min = new Fraction((int)stepwise.min.denominator, (int)stepwise.min.numerator); - var max = new Fraction((int)stepwise.max.denominator, (int)stepwise.max.numerator); + // v4l2_fract is "interval", so do reciprocal to make fps. + // (numerator <--> denominator) + + // Since we're inverting the interval to get the FPS, we also need to swap the meaning of min/max + var min = new Fraction((int)stepwise.max.denominator, (int)stepwise.max.numerator); + var max = new Fraction((int)stepwise.min.denominator, (int)stepwise.min.numerator); + return NativeMethods.DefactoStandardFramesPerSecond. Where(fps => fps >= min && fps <= max). OrderByDescending(fps => fps).