From 5df9251e2006b38d7fc69c4bb2be9e13650f2169 Mon Sep 17 00:00:00 2001
From: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com>
Date: Tue, 16 Aug 2022 15:08:31 -0300
Subject: [PATCH] video_encoder: fix fps in windows

Virtual camera with non conventional fps where not working
properly due to a mismatch between the framerate rational in
daemon and AVRational in ffmpeg.

GitLab: https://git.jami.net/savoirfairelinux/jami-client-qt/-/issues/478

Change-Id: Ida3a575be1dedae0e581257e38bf7469154a6ef5
---
 src/media/media_decoder.cpp | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/media/media_decoder.cpp b/src/media/media_decoder.cpp
index 1cac4b95e0..7cba58abe6 100644
--- a/src/media/media_decoder.cpp
+++ b/src/media/media_decoder.cpp
@@ -103,17 +103,16 @@ MediaDemuxer::openInput(const DeviceParams& params)
 
     if (params.framerate) {
 #ifdef _WIN32
-        // On windows, certain framerate settings don't reduce to avrational values
+        // On windows, framerate settings don't reduce to avrational values
         // that correspond to valid video device formats.
         // e.g. A the rational<double>(10000000, 333333) or 30.000030000
         //      will be reduced by av_reduce to 999991/33333 or 30.00003000003
         //      which cause the device opening routine to fail.
-        // So we treat special cases in which the reduction is imprecise and adjust
-        // the value, or let dshow choose the framerate, which is, unfortunately,
+        // So we treat this imprecise reduction and adjust the value,
+        // or let dshow choose the framerate, which is, unfortunately,
         // NOT the highest according to our experimentations.
         auto framerate {params.framerate.real()};
-        if (params.framerate.denominator() == 333333)
-            framerate = (int) (params.framerate.real());
+        framerate = params.framerate.numerator() / (params.framerate.denominator() + 0.5);
         if (params.framerate.denominator() != 4999998)
             av_dict_set(&options_, "framerate", jami::to_string(framerate).c_str(), 0);
 #else
-- 
GitLab