[vlc-devel] [PATCH 2/2] libvlc: handle the report size callback in the wextern window module

Steve Lhomme robux4 at ycbcr.xyz
Fri Jun 14 16:26:23 CEST 2019


This way it can work for all modules that render externally. And the code is
generic. It also makes more sense to handle the window size in the window
module.
---
 modules/video_output/wextern.c          | 66 +++++++++++++++++++++----
 modules/video_output/win32/direct3d11.c | 18 -------
 modules/video_output/win32/direct3d9.c  | 15 ------
 3 files changed, 56 insertions(+), 43 deletions(-)

diff --git a/modules/video_output/wextern.c b/modules/video_output/wextern.c
index eab44854cd..eacfd44fe0 100644
--- a/modules/video_output/wextern.c
+++ b/modules/video_output/wextern.c
@@ -30,24 +30,70 @@
 #include <vlc_plugin.h>
 #include <vlc_vout_window.h>
 
+#include <vlc/libvlc.h>
+#include <vlc/libvlc_picture.h>
+#include <vlc/libvlc_media.h>
+#include <vlc/libvlc_renderer_discoverer.h>
+#include <vlc/libvlc_media_player.h>
+
+static int Open(vout_window_t *);
+
+vlc_module_begin()
+    set_shortname(N_("Callback window"))
+    set_description(N_("External callback window"))
+    set_category(CAT_VIDEO)
+    set_subcategory(SUBCAT_VIDEO_VOUT)
+    set_capability("vout window", 0)
+    set_callbacks(Open, NULL)
+vlc_module_end()
+
+typedef struct {
+    void                                     *opaque;
+    libvlc_video_direct3d_set_resize_cb      setResizeCb;
+} wextern_t;
+
+static void WindowResize(void *opaque, unsigned width, unsigned height)
+{
+    vout_window_t *window = opaque;
+    vout_window_ReportSize(window, width, height);
+}
+
+static int Enable(struct vout_window_t *wnd, const vout_window_cfg_t *wcfg)
+{
+    wextern_t *sys = wnd->sys;
+
+    if ( sys->setResizeCb != NULL )
+        /* bypass the size handling as the window doesn't handle the size */
+        sys->setResizeCb( sys->opaque, WindowResize, wnd );
+
+    return VLC_SUCCESS;
+}
+
+static void Disable(struct vout_window_t *wnd)
+{
+    wextern_t *sys = wnd->sys;
+
+    if ( sys->setResizeCb != NULL )
+        sys->setResizeCb( sys->opaque, NULL, NULL );
+}
+
 static const struct vout_window_operations ops = {
+    .enable  = Enable,
+    .disable = Disable,
     // .resize: don't let the core resize us on zoom/crop/ar changes
     //          the display module should do the ReportSize for us
 };
 
 static int Open(vout_window_t *wnd)
 {
+    wextern_t *sys = vlc_obj_malloc(VLC_OBJECT(wnd), sizeof(*sys));
+    if (unlikely(sys==NULL))
+        return VLC_ENOMEM;
+    sys->opaque          = var_InheritAddress( wnd, "vout-cb-opaque" );
+    sys->setResizeCb     = var_InheritAddress( wnd, "vout-cb-resize-cb" );
+
+    wnd->sys = sys;
     wnd->type = VOUT_WINDOW_TYPE_DUMMY;
     wnd->ops = &ops;
     return VLC_SUCCESS;
 }
-
-vlc_module_begin()
-    set_shortname(N_("Callback window"))
-    set_description(N_("External callback window"))
-    set_category(CAT_VIDEO)
-    set_subcategory(SUBCAT_VIDEO_VOUT)
-    set_capability("vout window", 0)
-    set_callbacks(Open, NULL)
-    add_shortcut("dummy")
-vlc_module_end()
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index b5cd32ad9c..ec50ef824c 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -125,7 +125,6 @@ struct vout_display_sys_t
     void *outside_opaque;
     libvlc_video_direct3d_device_setup_cb    setupDeviceCb;
     libvlc_video_direct3d_device_cleanup_cb  cleanupDeviceCb;
-    libvlc_video_direct3d_set_resize_cb      setResizeCb;
     libvlc_video_direct3d_update_output_cb   updateOutputCb;
     libvlc_video_swap_cb                     swapCb;
     libvlc_video_direct3d_start_end_rendering_cb startEndRenderingCb;
@@ -326,7 +325,6 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
     sys->outside_opaque = var_InheritAddress( vd, "vout-cb-opaque" );
     sys->setupDeviceCb       = var_InheritAddress( vd, "vout-cb-setup" );
     sys->cleanupDeviceCb     = var_InheritAddress( vd, "vout-cb-cleanup" );
-    sys->setResizeCb         = var_InheritAddress( vd, "vout-cb-resize-cb" );
     sys->updateOutputCb      = var_InheritAddress( vd, "vout-cb-update-output" );
     sys->swapCb              = var_InheritAddress( vd, "vout-cb-swap" );
     sys->startEndRenderingCb = var_InheritAddress( vd, "vout-cb-make-current" );
@@ -353,7 +351,6 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
             goto error;
         sys->setupDeviceCb       = LocalSwapchainSetupDevice;
         sys->cleanupDeviceCb     = LocalSwapchainCleanupDevice;
-        sys->setResizeCb         = NULL;
         sys->updateOutputCb      = LocalSwapchainUpdateOutput;
         sys->swapCb              = LocalSwapchainSwap;
         sys->startEndRenderingCb = LocalSwapchainStartEndRendering;
@@ -852,12 +849,6 @@ static const d3d_format_t *GetBlendableFormat(vout_display_t *vd, vlc_fourcc_t i
     return FindD3D11Format( vd, &vd->sys->d3d_dev, i_src_chroma, false, 0, 0, 0, false, supportFlags );
 }
 
-static void WindowResize(void *opaque, unsigned width, unsigned height)
-{
-    vout_window_t *window = opaque;
-    vout_window_ReportSize(window, width, height);
-}
-
 static int Direct3D11Open(vout_display_t *vd, video_format_t *fmtp)
 {
     vout_display_sys_t *sys = vd->sys;
@@ -916,9 +907,6 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmtp)
         }
     }
 
-    if (sys->setResizeCb && !vd->cfg->window->ops->resize)
-        sys->setResizeCb( sys->outside_opaque, WindowResize, vd->cfg->window );
-
     /* adjust the decoder sizes to have proper padding */
     sys->picQuad.i_width  = fmt.i_width;
     sys->picQuad.i_height = fmt.i_height;
@@ -948,9 +936,6 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmtp)
 
     if (Direct3D11CreateGenericResources(vd)) {
         msg_Err(vd, "Failed to allocate resources");
-        if (sys->setResizeCb && !vd->cfg->window->ops->resize)
-            sys->setResizeCb( sys->outside_opaque, NULL, NULL );
-
         if ( sys->cleanupDeviceCb )
             sys->cleanupDeviceCb( sys->outside_opaque );
         return VLC_EGENERIC;
@@ -1063,9 +1048,6 @@ static void Direct3D11Close(vout_display_t *vd)
 
     D3D11_ReleaseDevice( &sys->d3d_dev );
 
-    if (sys->setResizeCb && !vd->cfg->window->ops->resize)
-        sys->setResizeCb( sys->outside_opaque, NULL, NULL );
-
     if ( sys->cleanupDeviceCb )
         sys->cleanupDeviceCb( sys->outside_opaque );
 
diff --git a/modules/video_output/win32/direct3d9.c b/modules/video_output/win32/direct3d9.c
index d832f59a90..4ea1f178e6 100644
--- a/modules/video_output/win32/direct3d9.c
+++ b/modules/video_output/win32/direct3d9.c
@@ -176,7 +176,6 @@ struct vout_display_sys_t
     void *outside_opaque;
     libvlc_video_direct3d_device_setup_cb    setupDeviceCb;
     libvlc_video_direct3d_device_cleanup_cb  cleanupDeviceCb;
-    libvlc_video_direct3d_set_resize_cb      setResizeCb;
     libvlc_video_direct3d_update_output_cb   updateOutputCb;
     libvlc_video_swap_cb                     swapCb;
     libvlc_video_direct3d_start_end_rendering_cb startEndRenderingCb;
@@ -1413,9 +1412,6 @@ static void Direct3D9Destroy(vout_display_sys_t *sys)
         sys->hxdll = NULL;
     }
 
-    if (sys->setResizeCb && !vd->cfg->window->ops->resize)
-        sys->setResizeCb( sys->outside_opaque, NULL, NULL );
-
     if ( sys->cleanupDeviceCb )
         sys->cleanupDeviceCb( sys->outside_opaque );
 }
@@ -1671,12 +1667,6 @@ static bool LocalSwapchainStartEndRendering( void *opaque, bool enter, const lib
     return true;
 }
 
-static void WindowResize(void *opaque, unsigned width, unsigned height)
-{
-    vout_window_t *window = opaque;
-    vout_window_ReportSize(window, width, height);
-}
-
 /**
  * It creates a Direct3D vout display.
  */
@@ -1712,7 +1702,6 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
     sys->outside_opaque = var_InheritAddress( vd, "vout-cb-opaque" );
     sys->setupDeviceCb       = var_InheritAddress( vd, "vout-cb-setup" );
     sys->cleanupDeviceCb     = var_InheritAddress( vd, "vout-cb-cleanup" );
-    sys->setResizeCb         = var_InheritAddress( vd, "vout-cb-resize-cb" );
     sys->updateOutputCb      = var_InheritAddress( vd, "vout-cb-update-output" );
     sys->swapCb              = var_InheritAddress( vd, "vout-cb-swap" );
     sys->startEndRenderingCb = var_InheritAddress( vd, "vout-cb-make-current" );
@@ -1726,7 +1715,6 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
         sys->outside_opaque = vd;
         sys->setupDeviceCb       = LocalSwapchainSetupDevice;
         sys->cleanupDeviceCb     = NULL;
-        sys->setResizeCb         = NULL;
         sys->updateOutputCb      = LocalSwapchainUpdateOutput;
         sys->swapCb              = LocalSwapchainSwap;
         sys->startEndRenderingCb = LocalSwapchainStartEndRendering;
@@ -1762,9 +1750,6 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
         return VLC_EGENERIC;
     }
 
-    if (sys->setResizeCb && !vd->cfg->window->ops->resize)
-        sys->setResizeCb( sys->outside_opaque, WindowResize, vd->cfg->window );
-
     if (sys->setupDeviceCb != LocalSwapchainSetupDevice)
         CommonPlacePicture(VLC_OBJECT(vd), &sys->area, &sys->sys);
 
-- 
2.17.1



More information about the vlc-devel mailing list