[vlc-devel] [PATCH v3 20/20] mmal: vout: simplify the code to update the display resolution

Steve Lhomme robux4 at ycbcr.xyz
Wed Aug 26 13:55:47 CEST 2020


---
 modules/hw/mmal/vout.c | 83 ++++++++++++------------------------------
 1 file changed, 23 insertions(+), 60 deletions(-)

diff --git a/modules/hw/mmal/vout.c b/modules/hw/mmal/vout.c
index 4534a281012..b73cd13ddcd 100644
--- a/modules/hw/mmal/vout.c
+++ b/modules/hw/mmal/vout.c
@@ -105,8 +105,6 @@ struct vout_display_sys_t {
     unsigned num_buffers; /* number of buffers allocated at mmal port */
 
     int display_id;
-    unsigned display_width;
-    unsigned display_height;
 
     MMAL_RECT_T dest_rect;      // Output rectangle in display coords
 
@@ -474,39 +472,38 @@ static void vd_input_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buf)
     mmal_buffer_header_release(buf);
 }
 
-static int query_resolution(vout_display_t *vd, const int display_id, unsigned *width, unsigned *height)
+static void query_resolution(vout_display_t *vd, const int display_id)
 {
     TV_DISPLAY_STATE_T display_state = {0};
-    int ret = 0;
 
     if (vc_tv_get_display_state_id(display_id, &display_state) == 0) {
         msg_Dbg(vd, "State=%#x", display_state.state);
         if (display_state.state & 0xFF) {
             msg_Dbg(vd, "HDMI: %dx%d", display_state.display.hdmi.width, display_state.display.hdmi.height);
-            *width = display_state.display.hdmi.width;
-            *height = display_state.display.hdmi.height;
-            vout_display_SetSize(vd, *width, *height);
+            unsigned width = display_state.display.hdmi.width;
+            unsigned height = display_state.display.hdmi.height;
+            vout_display_SetSize(vd, width, height);
         } else if (display_state.state & 0xFF00) {
             msg_Dbg(vd, "SDTV: %dx%d", display_state.display.sdtv.width, display_state.display.sdtv.height);
-            *width = display_state.display.sdtv.width;
-            *height = display_state.display.sdtv.height;
-            vout_display_SetSize(vd, *width, *height);
+            unsigned width = display_state.display.sdtv.width;
+            unsigned height = display_state.display.sdtv.height;
+            vout_display_SetSize(vd, width, height);
         } else {
             msg_Warn(vd, "Invalid display state %"PRIx32, display_state.state);
-            ret = -1;
         }
     } else {
         msg_Warn(vd, "Failed to query display resolution");
-        ret = -1;
     }
-
-    return ret;
 }
 
-static MMAL_RECT_T
-place_to_mmal_rect(const vout_display_place_t place)
+static void
+place_dest(vout_display_sys_t * const sys, const video_format_t * fmt)
 {
-    return (MMAL_RECT_T){
+    // Ignore what VLC thinks might be going on with display size
+    vout_display_place_t place;
+    vout_display_PlacePicture(&place, fmt, vd->cfg);
+
+    sys->dest_rect = (MMAL_RECT_T){
         .x      = place.x,
         .y      = place.y,
         .width  = place.width,
@@ -514,36 +511,14 @@ place_to_mmal_rect(const vout_display_place_t place)
     };
 }
 
-static void
-place_dest(vout_display_sys_t * const sys,
-           const vout_display_cfg_t * const cfg, const video_format_t * fmt)
-{
-    // Ignore what VLC thinks might be going on with display size
-    vout_display_cfg_t tcfg = *cfg;
-    vout_display_place_t place;
-    tcfg.display.width = sys->display_width;
-    tcfg.display.height = sys->display_height;
-    tcfg.is_display_filled = true;
-    vout_display_PlacePicture(&place, fmt, &tcfg);
 
-    sys->dest_rect = place_to_mmal_rect(place);
-}
 
-
-
-static int configure_display(vout_display_t *vd, const vout_display_cfg_t *cfg,
-                const video_format_t *fmt)
+static int configure_display(vout_display_t *vd, const video_format_t *fmt)
 {
     vout_display_sys_t * const sys = vd->sys;
     MMAL_DISPLAYREGION_T display_region;
     MMAL_STATUS_T status;
 
-    if (!cfg && !fmt)
-    {
-        msg_Err(vd, "Missing cfg & fmt");
-        return -EINVAL;
-    }
-
     isp_check(vd, sys);
 
     if (fmt) {
@@ -557,13 +532,10 @@ static int configure_display(vout_display_t *vd, const vout_display_cfg_t *cfg,
             return -EINVAL;
         }
     } else {
-        fmt = &vd->source;
+        fmt = vd->source;
     }
 
-    if (!cfg)
-        cfg = vd->cfg;
-
-    place_dest(sys, cfg, fmt);
+    place_dest(sys, fmt);
 
     display_region.hdr.id = MMAL_PARAMETER_DISPLAYREGION;
     display_region.hdr.size = sizeof(MMAL_DISPLAYREGION_T);
@@ -702,14 +674,14 @@ static int vd_control(vout_display_t *vd, int query, va_list args)
     switch (query) {
         case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:
         {
-            if (configure_display(vd, vd->cfg, NULL) >= 0)
+            if (configure_display(vd, NULL) >= 0)
                 ret = VLC_SUCCESS;
             break;
         }
 
         case VOUT_DISPLAY_CHANGE_SOURCE_ASPECT:
         case VOUT_DISPLAY_CHANGE_SOURCE_CROP:
-            if (configure_display(vd, NULL, &vd->source) >= 0)
+            if (configure_display(vd, &vd->source) >= 0)
                 ret = VLC_SUCCESS;
             break;
 
@@ -740,16 +712,11 @@ static int vd_control(vout_display_t *vd, int query, va_list args)
 static void vd_manage(vout_display_t *vd)
 {
     vout_display_sys_t *sys = vd->sys;
-    unsigned width, height;
 
     vlc_mutex_lock(&sys->manage_mutex);
 
     if (sys->need_configure_display) {
-        if (query_resolution(vd, sys->display_id, &width, &height) >= 0) {
-            sys->display_width = width;
-            sys->display_height = height;
-//            vout_window_ReportSize(vd->cfg->window, width, height);
-        }
+        query_resolution(vd, sys->display_id);
 
         sys->need_configure_display = false;
     }
@@ -818,7 +785,7 @@ static void vd_prepare(vout_display_t *vd, picture_t *p_pic,
         sys->b_progressive = p_pic->b_progressive;
         sys->i_frame_rate = p_pic->format.i_frame_rate;
         sys->i_frame_rate_base = p_pic->format.i_frame_rate_base;
-        configure_display(vd, NULL, &p_pic->format);
+        configure_display(vd, &p_pic->format);
     }
 
     // Subpics can either turn up attached to the main pic or in the
@@ -1202,13 +1169,9 @@ static int OpenMmalVout(vout_display_t *vd, const vout_display_cfg_t *cfg,
         }
     }
 
-    if (query_resolution(vd, sys->display_id, &sys->display_width, &sys->display_height) < 0)
-    {
-        sys->display_width = vd->cfg->display.width;
-        sys->display_height = vd->cfg->display.height;
-    }
+    query_resolution(vd, sys->display_id);
 
-    place_dest(sys, vd->cfg, &vd->source);  // Sets sys->dest_rect
+    place_dest(sys, &vd->source);  // Sets sys->dest_rect
 
     display_region.hdr.id = MMAL_PARAMETER_DISPLAYREGION;
     display_region.hdr.size = sizeof(MMAL_DISPLAYREGION_T);
-- 
2.26.2



More information about the vlc-devel mailing list