[vlc-devel] [PATCH 06/10] vout: handle crop=0:0 case in parser

remi at remlab.net remi at remlab.net
Sat Feb 6 16:27:28 UTC 2021


From: RĂ©mi Denis-Courmont <remi at remlab.net>

...and simplify accordingly.
---
 src/video_output/video_output.c | 18 +++---------------
 src/video_output/vout_intf.c    |  8 +++++---
 2 files changed, 8 insertions(+), 18 deletions(-)

diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 5d9502fed9..d04d3f4d11 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -637,16 +637,6 @@ void vout_ChangeDisplayAspectRatio(vout_thread_t *vout,
     vlc_mutex_unlock(&sys->display_lock);
 }
 
-static void vout_SetCrop(vout_thread_sys_t *sys,
-                         const struct vout_crop *restrict crop)
-{
-    sys->source.crop = *crop;
-
-    if (crop->mode == VOUT_CROP_RATIO
-     && (crop->ratio.num == 0 || crop->ratio.den == 0))
-        sys->source.crop.mode = VOUT_CROP_NONE;
-}
-
 void vout_ChangeCrop(vout_thread_t *vout,
                      const struct vout_crop *restrict crop)
 {
@@ -654,7 +644,7 @@ void vout_ChangeCrop(vout_thread_t *vout,
     assert(!sys->dummy);
 
     vlc_mutex_lock(&sys->window_lock);
-    vout_SetCrop(sys, crop);
+    sys->source.crop = *crop;
     vout_UpdateWindowSizeLocked(sys);
 
     vlc_mutex_lock(&sys->display_lock);
@@ -2115,10 +2105,8 @@ static void vout_InitSource(vout_thread_sys_t *vout)
 
     char *psz_crop = var_InheritString(&vout->obj, "crop");
     if (psz_crop) {
-        struct vout_crop crop;
-
-        if (vout_ParseCrop(&crop, psz_crop))
-            vout_SetCrop(vout, &crop);
+        if (!vout_ParseCrop(&vout->source.crop, psz_crop))
+            vout->source.crop.mode = VOUT_CROP_NONE;
         free(psz_crop);
     }
 }
diff --git a/src/video_output/vout_intf.c b/src/video_output/vout_intf.c
index 1a20350527..0ed4f6bb87 100644
--- a/src/video_output/vout_intf.c
+++ b/src/video_output/vout_intf.c
@@ -452,7 +452,10 @@ exit:
 bool vout_ParseCrop(struct vout_crop *restrict cfg, const char *crop_str)
 {
     if (sscanf(crop_str, "%u:%u", &cfg->ratio.num, &cfg->ratio.den) == 2) {
-        cfg->mode = VOUT_CROP_RATIO;
+        if (cfg->ratio.num != 0 && cfg->ratio.den != 0)
+            cfg->mode = VOUT_CROP_RATIO;
+        else
+            cfg->mode = VOUT_CROP_NONE;
     } else if (sscanf(crop_str, "%ux%u+%u+%u",
                       &cfg->window.width, &cfg->window.height,
                       &cfg->window.x, &cfg->window.y) == 4) {
@@ -462,8 +465,7 @@ bool vout_ParseCrop(struct vout_crop *restrict cfg, const char *crop_str)
                       &cfg->border.right, &cfg->border.bottom) == 4) {
         cfg->mode = VOUT_CROP_BORDER;
     } else if (*crop_str == '\0') {
-        cfg->mode = VOUT_CROP_RATIO;
-        cfg->ratio.num = cfg->ratio.den = 0;
+        cfg->mode = VOUT_CROP_NONE;
     } else {
         return false;
     }
-- 
2.30.0



More information about the vlc-devel mailing list