[vlc-devel] [PATCH 05/10] vout: use struct vout_crop for vout_SetDisplayCrop()

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


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

No functional changes.
---
 src/video_output/display.c      | 27 ++++++++++++++++--
 src/video_output/video_output.c | 50 +++------------------------------
 src/video_output/vout_wrapper.h |  4 +--
 3 files changed, 31 insertions(+), 50 deletions(-)

diff --git a/src/video_output/display.c b/src/video_output/display.c
index b66fe39c55..3dd0faa574 100644
--- a/src/video_output/display.c
+++ b/src/video_output/display.c
@@ -42,6 +42,7 @@
 
 #include "display.h"
 #include "window.h"
+#include "vout_internal.h"
 
 /*****************************************************************************
  * FIXME/TODO see how to have direct rendering here (interact with vout.c)
@@ -628,10 +629,32 @@ void vout_SetDisplayAspect(vout_display_t *vd, unsigned dar_num, unsigned dar_de
 }
 
 void vout_SetDisplayCrop(vout_display_t *vd,
-                         unsigned crop_num, unsigned crop_den,
-                         unsigned left, unsigned top, int right, int bottom)
+                         const struct vout_crop *restrict crop)
 {
     vout_display_priv_t *osys = container_of(vd, vout_display_priv_t, display);
+    unsigned crop_num = 0, crop_den = 0, left = 0, top = 0;
+    int right = 0, bottom = 0;
+
+    switch (crop->mode) {
+        case VOUT_CROP_NONE:
+            break;
+        case VOUT_CROP_RATIO:
+            crop_num = crop->ratio.num;
+            crop_den = crop->ratio.den;
+            break;
+        case VOUT_CROP_WINDOW:
+            left = crop->window.x;
+            top = crop->window.y;
+            right = crop->window.width;
+            bottom = crop->window.height;
+            break;
+        case VOUT_CROP_BORDER:
+            left = crop->border.left;
+            top = crop->border.top;
+            right = -(int)crop->border.right;
+            bottom = -(int)crop->border.bottom;
+            break;
+    }
 
     if (osys->crop.left  != (int)left  || osys->crop.top != (int)top ||
         osys->crop.right != right || osys->crop.bottom != bottom ||
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 4a76e9f595..5d9502fed9 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -661,27 +661,7 @@ void vout_ChangeCrop(vout_thread_t *vout,
     vlc_mutex_unlock(&sys->window_lock);
 
     if (sys->display != NULL)
-        switch (crop->mode) {
-            case VOUT_CROP_NONE:
-                vout_SetDisplayCrop(sys->display, 0, 0, 0, 0, 0, 0);
-                break;
-            case VOUT_CROP_RATIO:
-                vout_SetDisplayCrop(sys->display, crop->ratio.num,
-                                    crop->ratio.den, 0, 0, 0, 0);
-                break;
-            case VOUT_CROP_WINDOW:
-                vout_SetDisplayCrop(sys->display, 0, 0,
-                                    crop->window.x, crop->window.y,
-                                    crop->window.width, crop->window.height);
-                break;
-            case VOUT_CROP_BORDER:
-                vout_SetDisplayCrop(sys->display, 0, 0,
-                                    crop->border.left, crop->border.top,
-                                    -(int)crop->border.right,
-                                    -(int)crop->border.bottom);
-                break;
-        }
-
+        vout_SetDisplayCrop(sys->display, crop);
     vlc_mutex_unlock(&sys->display_lock);
 }
 
@@ -1699,8 +1679,7 @@ static int vout_Start(vout_thread_sys_t *vout, vlc_video_context *vctx, const vo
     sys->filter.chain_interactive = filter_chain_NewVideo(&vout->obj, true, &owner);
 
     vout_display_cfg_t dcfg;
-    int x = 0, y = 0, w = 0, h = 0;
-    unsigned crop_num = 0, crop_den = 0;
+    struct vout_crop crop;
     unsigned num, den;
 
     vlc_mutex_lock(&sys->window_lock);
@@ -1715,28 +1694,7 @@ static int vout_Start(vout_thread_sys_t *vout, vlc_video_context *vctx, const vo
 #endif
 
     dcfg = sys->display_cfg;
-
-    switch (sys->source.crop.mode) {
-        case VOUT_CROP_NONE:
-            break;
-        case VOUT_CROP_RATIO:
-            crop_num = sys->source.crop.ratio.num;
-            crop_den = sys->source.crop.ratio.den;
-            break;
-        case VOUT_CROP_WINDOW:
-            x = sys->source.crop.window.x;
-            y = sys->source.crop.window.y;
-            w = sys->source.crop.window.width;
-            h = sys->source.crop.window.height;
-            break;
-        case VOUT_CROP_BORDER:
-            x = sys->source.crop.border.left;
-            y = sys->source.crop.border.top;
-            w = -(int)sys->source.crop.border.right;
-            h = -(int)sys->source.crop.border.bottom;
-            break;
-    }
-
+    crop = sys->source.crop;
     num = sys->source.dar.num;
     den = sys->source.dar.den;
     vlc_mutex_lock(&sys->display_lock);
@@ -1753,7 +1711,7 @@ static int vout_Start(vout_thread_sys_t *vout, vlc_video_context *vctx, const vo
         goto error;
     }
 
-    vout_SetDisplayCrop(sys->display, crop_num, crop_den, x, y, w, h);
+    vout_SetDisplayCrop(sys->display, &crop);
 
     if (num != 0 && den != 0)
         vout_SetDisplayAspect(sys->display, num, den);
diff --git a/src/video_output/vout_wrapper.h b/src/video_output/vout_wrapper.h
index 0f3a018279..0aae83be9b 100644
--- a/src/video_output/vout_wrapper.h
+++ b/src/video_output/vout_wrapper.h
@@ -26,6 +26,7 @@
 #include <vlc_vout_display.h>
 
 /* XXX DO NOT use it outside the vout module wrapper XXX */
+struct vout_crop;
 
 picture_pool_t *vout_GetPool(vout_display_t *vd, unsigned count);
 
@@ -36,8 +37,7 @@ void vout_FilterFlush(vout_display_t *);
 void vout_SetDisplayFilled(vout_display_t *, bool is_filled);
 void vout_SetDisplayZoom(vout_display_t *, unsigned num, unsigned den);
 void vout_SetDisplayAspect(vout_display_t *, unsigned num, unsigned den);
-void vout_SetDisplayCrop(vout_display_t *, unsigned num, unsigned den,
-                         unsigned left, unsigned top, int right, int bottom);
+void vout_SetDisplayCrop(vout_display_t *, const struct vout_crop *);
 void vout_SetDisplayViewpoint(vout_display_t *, const vlc_viewpoint_t *);
 
 #endif /* LIBVLC_VOUT_WRAPPER_H */
-- 
2.30.0



More information about the vlc-devel mailing list