[vlc-devel] [PATCH 6/7] video_output: move the aspect-ratio string parsing in a separate function

Steve Lhomme robux4 at ycbcr.xyz
Tue Sep 1 12:06:37 CEST 2020


We need to evaluate it on startup.
---
 src/video_output/vout_intf.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/video_output/vout_intf.c b/src/video_output/vout_intf.c
index 630961125b7..12e830d29d5 100644
--- a/src/video_output/vout_intf.c
+++ b/src/video_output/vout_intf.c
@@ -523,6 +523,16 @@ static int CropBorderCallback(vlc_object_t *object, char const *cmd,
     return VLC_SUCCESS;
 }
 
+static bool GetAspectRatio(const char *ar_str, unsigned *num, unsigned *den)
+{
+    if (sscanf(ar_str, "%u:%u", num, den) == 2 &&
+        (num != 0) == (den != 0))
+        return true;
+    else if (*ar_str == '\0')
+        *num = *den = 0;
+    return false;
+}
+
 static int AspectCallback( vlc_object_t *object, char const *cmd,
                          vlc_value_t oldval, vlc_value_t newval, void *data )
 {
@@ -530,11 +540,8 @@ static int AspectCallback( vlc_object_t *object, char const *cmd,
     VLC_UNUSED(cmd); VLC_UNUSED(oldval); VLC_UNUSED(data);
     unsigned num, den;
 
-    if (sscanf(newval.psz_string, "%u:%u", &num, &den) == 2 &&
-        (num != 0) == (den != 0))
+    if (GetAspectRatio(newval.psz_string, &num, &den))
         vout_ChangeDisplayAspectRatio(vout, num, den);
-    else if (*newval.psz_string == '\0')
-        vout_ChangeDisplayAspectRatio(vout, 0, 0);
     return VLC_SUCCESS;
 }
 
-- 
2.26.2



More information about the vlc-devel mailing list