[vlc-devel] [PATCH 4/7] video_output: move the crop string parsing in a separate function

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


We need to evaluate it on startup.
---
 src/video_output/vout_internal.h |  4 +++
 src/video_output/vout_intf.c     | 52 ++++++++++++++++++++++++--------
 src/video_output/vout_private.h  |  4 ---
 3 files changed, 44 insertions(+), 16 deletions(-)

diff --git a/src/video_output/vout_internal.h b/src/video_output/vout_internal.h
index 3f5a81c98eb..ef6625c1eea 100644
--- a/src/video_output/vout_internal.h
+++ b/src/video_output/vout_internal.h
@@ -101,6 +101,10 @@ void vout_StopDisplay(vout_thread_t *);
  */
 int vout_ChangeSource( vout_thread_t *p_vout, const video_format_t *fmt );
 
+enum vout_crop_mode {
+    VOUT_CROP_NONE, VOUT_CROP_RATIO, VOUT_CROP_WINDOW, VOUT_CROP_BORDER,
+};
+
 /* TODO to move them to vlc_vout.h */
 void vout_ChangeFullscreen(vout_thread_t *, const char *id);
 void vout_ChangeWindowed(vout_thread_t *);
diff --git a/src/video_output/vout_intf.c b/src/video_output/vout_intf.c
index 4fb207ff469..534f783a456 100644
--- a/src/video_output/vout_intf.c
+++ b/src/video_output/vout_intf.c
@@ -450,6 +450,28 @@ exit:
     free( psz_path );
 }
 
+static bool GetCropMode(const char *crop_str, enum vout_crop_mode *mode,
+                        unsigned *num, unsigned *den,
+                        unsigned *x, unsigned *y,
+                        unsigned *width, unsigned *height )
+{
+    if (sscanf(crop_str, "%u:%u", num, den) == 2) {
+        *mode = VOUT_CROP_RATIO;
+    } else if (sscanf(crop_str, "%ux%u+%u+%u",
+                      width, height, x, y) == 4) {
+        *mode = VOUT_CROP_WINDOW;
+    } else if (sscanf(crop_str, "%u+%u+%u+%u",
+                    x, y, width, height) == 4) {
+        *mode = VOUT_CROP_BORDER;
+    } else if (*crop_str == '\0') {
+        *mode = VOUT_CROP_RATIO;
+        *num = *den = 0;
+    } else {
+        return false;
+    }
+    return true;
+}
+
 /*****************************************************************************
  * Object variables callbacks
  *****************************************************************************/
@@ -461,18 +483,24 @@ static int CropCallback( vlc_object_t *object, char const *cmd,
     unsigned num, den;
     unsigned y, x;
     unsigned width, height;
-    unsigned left, top, right, bottom;
-
-    if (sscanf(newval.psz_string, "%u:%u", &num, &den) == 2) {
-        vout_ChangeCropRatio(vout, num, den);
-    } else if (sscanf(newval.psz_string, "%ux%u+%u+%u",
-                      &width, &height, &x, &y) == 4) {
-        vout_ChangeCropWindow(vout, x, y, width, height);
-    } else if (sscanf(newval.psz_string, "%u+%u+%u+%u",
-                    &left, &top, &right, &bottom) == 4) {
-        vout_ChangeCropBorder(vout, left, top, right, bottom);
-    } else if (*newval.psz_string == '\0') {
-        vout_ChangeCropRatio(vout, 0, 0);
+    enum vout_crop_mode mode;
+
+    if (GetCropMode(newval.psz_string, &mode, &num, &den,
+                    &x, &y, &width, &height)) {
+        switch (mode)
+        {
+            case VOUT_CROP_RATIO:
+                vout_ChangeCropRatio(vout, num, den);
+                break;
+            case VOUT_CROP_WINDOW:
+                vout_ChangeCropWindow(vout, x, y, width, height);
+                break;
+            case VOUT_CROP_BORDER:
+                vout_ChangeCropBorder(vout, x, y, width, height);
+                break;
+            case VOUT_CROP_NONE:
+                break;
+        }
     } else {
         msg_Err(object, "Unknown crop format (%s)", newval.psz_string);
     }
diff --git a/src/video_output/vout_private.h b/src/video_output/vout_private.h
index 261dcc30fe4..5e8c58dabe7 100644
--- a/src/video_output/vout_private.h
+++ b/src/video_output/vout_private.h
@@ -30,10 +30,6 @@
 
 typedef struct vout_thread_private_t vout_thread_private_t;
 
-enum vout_crop_mode {
-    VOUT_CROP_NONE, VOUT_CROP_RATIO, VOUT_CROP_WINDOW, VOUT_CROP_BORDER,
-};
-
 /* */
 struct vout_thread_private_t
 {
-- 
2.26.2



More information about the vlc-devel mailing list