[vlc-devel] [PATCH 11/18] libvlc: merge libvlc_video_setup_cb and libvlc_video_direct3d_device_setup_cb

Steve Lhomme robux4 at ycbcr.xyz
Tue Feb 4 16:26:06 CET 2020


For now the OpenGL setup doesn't need to get any adapter or context from the
host app.
---
 doc/libvlc/QtGL/qtvlcwidget.cpp   |  3 +-
 doc/libvlc/sdl_opengl_player.cpp  |  3 +-
 include/vlc/libvlc_media_player.h | 81 ++++++++++++++-----------------
 lib/media_player.c                |  4 +-
 modules/hw/d3d11/d3d11_device.c   |  2 +-
 modules/hw/d3d9/d3d9_device.c     |  2 +-
 modules/video_output/vgl.c        |  8 ++-
 7 files changed, 51 insertions(+), 52 deletions(-)

diff --git a/doc/libvlc/QtGL/qtvlcwidget.cpp b/doc/libvlc/QtGL/qtvlcwidget.cpp
index 8c8cd1224e7..575eb418aeb 100644
--- a/doc/libvlc/QtGL/qtvlcwidget.cpp
+++ b/doc/libvlc/QtGL/qtvlcwidget.cpp
@@ -64,7 +64,8 @@ public:
     }
 
     // This callback is called during initialisation.
-    static bool setup(void** data)
+    static bool setup(void** data, const libvlc_video_direct3d_device_cfg_t *cfg,
+                      libvlc_video_direct3d_device_setup_t *out)
     {
         if (!QOpenGLContext::supportsThreadedOpenGL())
             return false;
diff --git a/doc/libvlc/sdl_opengl_player.cpp b/doc/libvlc/sdl_opengl_player.cpp
index c5558b7cd65..c84938041b6 100644
--- a/doc/libvlc/sdl_opengl_player.cpp
+++ b/doc/libvlc/sdl_opengl_player.cpp
@@ -160,7 +160,8 @@ public:
     }
 
     // This callback is called during initialisation.
-    static bool setup(void** data)
+    static bool setup(void** data, const libvlc_video_direct3d_device_cfg_t *cfg,
+                      libvlc_video_direct3d_device_setup_t *out)
     {
         VLCVideo** that = static_cast<VLCVideo**>(data);
         (*that)->m_width = 0;
diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
index 99530383832..6cdab23d59c 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -503,16 +503,42 @@ void libvlc_video_set_format_callbacks( libvlc_media_player_t *mp,
                                         libvlc_video_cleanup_cb cleanup );
 
 
+typedef struct
+{
+    bool hardware_decoding; /** set if D3D11_CREATE_DEVICE_VIDEO_SUPPORT is needed for D3D11 */
+} libvlc_video_direct3d_device_cfg_t;
+
+typedef struct
+{
+    void *device_context; /** ID3D11DeviceContext* for D3D11, IDirect3D9 * for D3D9 */
+    int  adapter;         /** Adapter to use with the IDirect3D9 for D3D9 */
+} libvlc_video_direct3d_device_setup_t;
+
 /**
  * Callback prototype called to initialize user data.
+ * Setup the rendering environment.
  *
  * \param opaque private pointer passed to the @a libvlc_video_set_output_callbacks()
+ *               or @a libvlc_video_direct3d_set_callbacks()
  *               on input. The callback can change this value on output to be
- *               passed to all the other callbacks set on @a libvlc_video_set_output_callbacks(). [IN/OUT]
+ *               passed to all the other callbacks set on @a libvlc_video_direct3d_set_callbacks()
+ *               or @a libvlc_video_set_output_callbacks(). [IN/OUT]
+ * \param cfg requested configuration of the video device [IN]
+ * \param out libvlc_video_direct3d_device_setup_t* to fill [OUT]
  * \return true on success
  * \version LibVLC 4.0.0 or later
+ *
+ * For \ref libvlc_video_direct3d_engine_d3d9 the output must be a IDirect3D9*.
+ * A reference to this object is held until the \ref LIBVLC_VIDEO_DEVICE_CLEANUP is called.
+ * the device must be created with D3DPRESENT_PARAMETERS.hDeviceWindow set to 0.
+ *
+ * For \ref libvlc_video_direct3d_engine_d3d11 the output must be a ID3D11DeviceContext*.
+ * A reference to this object is held until the \ref LIBVLC_VIDEO_DEVICE_CLEANUP is called.
+ * The ID3D11Device used to create ID3D11DeviceContext must have multithreading enabled.
  */
-typedef bool (*libvlc_video_setup_cb)(void** opaque);
+typedef bool( *libvlc_video_output_setup_cb )( void **opaque,
+                                        const libvlc_video_direct3d_device_cfg_t *cfg,
+                                        libvlc_video_direct3d_device_setup_t *out );
 
 
 /**
@@ -552,7 +578,7 @@ typedef struct
  * Update the rendering output setup.
  *
  * \param opaque private pointer passed to the @a libvlc_video_set_output_callbacks() or
- *         @a libvlc_video_direct3d_device_setup_cb() [IN]
+ *         @a libvlc_video_output_setup_cb() [IN]
  * \param cfg configuration of the video that will be rendered [IN]
  * \param output configuration describing with how the rendering is setup [OUT]
  * \version LibVLC 4.0.0 or later
@@ -595,7 +621,7 @@ typedef struct
  * Tell the host the rendering is about to start/has finished.
  *
  * \param opaque private pointer passed to the @a libvlc_video_set_output_callbacks() or
- *          @a libvlc_video_direct3d_device_setup_cb() [IN]
+ *          @a libvlc_video_output_setup_cb() [IN]
  * \param enter true to set the context as current, false to unset it [IN]
  * \param hdr10 libvlc_video_frame_hdr10_metadata_t* or NULL [IN]
  * \return true on success
@@ -662,7 +688,7 @@ typedef enum libvlc_video_engine_t {
 LIBVLC_API
 bool libvlc_video_set_output_callbacks( libvlc_media_player_t *mp,
                                         libvlc_video_engine_t engine,
-                                        libvlc_video_setup_cb setup_cb,
+                                        libvlc_video_output_setup_cb setup_cb,
                                         libvlc_video_output_cleanup_cb cleanup_cb,
                                         libvlc_video_update_output_cb update_output_cb,
                                         libvlc_video_swap_cb swap_cb,
@@ -682,42 +708,9 @@ typedef enum libvlc_video_direct3d_engine_t {
     libvlc_video_direct3d_engine_d3d9,
 } libvlc_video_direct3d_engine_t;
 
-typedef struct
-{
-    bool hardware_decoding; /** set if D3D11_CREATE_DEVICE_VIDEO_SUPPORT is needed for D3D11 */
-} libvlc_video_direct3d_device_cfg_t;
-
-typedef struct
-{
-    void *device_context; /** ID3D11DeviceContext* for D3D11, IDirect3D9 * for D3D9 */
-    int  adapter;         /** Adapter to use with the IDirect3D9 for D3D9 */
-} libvlc_video_direct3d_device_setup_t;
-
-/** Setup the rendering environment.
- *
- * \param opaque private pointer passed to the @a libvlc_video_direct3d_set_callbacks()
- *               on input. The callback can change this value on output to be
- *               passed to all the other callbacks set on @a libvlc_video_direct3d_set_callbacks(). [IN/OUT]
- * \param cfg requested configuration of the video device [IN]
- * \param out libvlc_video_direct3d_device_setup_t* to fill [OUT]
- * \return true on success
- * \version LibVLC 4.0.0 or later
- *
- * For \ref libvlc_video_direct3d_engine_d3d9 the output must be a IDirect3D9*.
- * A reference to this object is held until the \ref LIBVLC_VIDEO_DEVICE_CLEANUP is called.
- * the device must be created with D3DPRESENT_PARAMETERS.hDeviceWindow set to 0.
- *
- * For \ref libvlc_video_direct3d_engine_d3d11 the output must be a ID3D11DeviceContext*.
- * A reference to this object is held until the \ref LIBVLC_VIDEO_DEVICE_CLEANUP is called.
- * The ID3D11Device used to create ID3D11DeviceContext must have multithreading enabled.
- */
-typedef bool( *libvlc_video_direct3d_device_setup_cb )( void **opaque,
-                                                        const libvlc_video_direct3d_device_cfg_t *cfg,
-                                                        libvlc_video_direct3d_device_setup_t *out );
-
-/** Cleanup the rendering environment initialized during \ref libvlc_video_direct3d_device_setup_cb.
+/** Cleanup the rendering environment initialized during \ref libvlc_video_output_setup_cb.
  *
- * \param opaque private pointer set on the opaque parameter of @a libvlc_video_direct3d_device_setup_cb() [IN]
+ * \param opaque private pointer set on the opaque parameter of @a libvlc_video_output_setup_cb() [IN]
  * \version LibVLC 4.0.0 or later
  */
 typedef void( *libvlc_video_direct3d_device_cleanup_cb )( void *opaque );
@@ -727,9 +720,9 @@ typedef void( *libvlc_video_direct3d_device_cleanup_cb )( void *opaque );
  * This allows text rendering and aspect ratio to be handled properly when the host
  * rendering size changes.
  *
- * It may be called before the \ref libvlc_video_direct3d_device_setup_cb callback.
+ * It may be called before the \ref libvlc_video_output_setup_cb callback.
  *
- * \param opaque private pointer set on the opaque parameter of @a libvlc_video_direct3d_device_setup_cb() [IN]
+ * \param opaque private pointer set on the opaque parameter of @a libvlc_video_output_setup_cb() [IN]
  * \param report_size_change callback which must be called when the host size changes. [IN]
  *        The callback is valid until another call to \ref libvlc_video_direct3d_set_resize_cb
  *        is done. This may be called from any thread.
@@ -741,7 +734,7 @@ typedef void( *libvlc_video_direct3d_set_resize_cb )( void *opaque,
 
 /** Tell the host the rendering for the given plane is about to start
  *
- * \param opaque private pointer set on the opaque parameter of @a libvlc_video_direct3d_device_setup_cb() [IN]
+ * \param opaque private pointer set on the opaque parameter of @a libvlc_video_output_setup_cb() [IN]
  * \param plane number of the rendering plane to select
  * \return true on success
  * \version LibVLC 4.0.0 or later
@@ -784,7 +777,7 @@ typedef bool( *libvlc_video_direct3d_select_plane_cb )( void *opaque, size_t pla
 LIBVLC_API
 bool libvlc_video_direct3d_set_callbacks( libvlc_media_player_t *mp,
                                          libvlc_video_direct3d_engine_t engine,
-                                         libvlc_video_direct3d_device_setup_cb setup_cb,
+                                         libvlc_video_output_setup_cb setup_cb,
                                          libvlc_video_direct3d_device_cleanup_cb cleanup_cb,
                                          libvlc_video_direct3d_set_resize_cb resize_cb,
                                          libvlc_video_update_output_cb update_output_cb,
diff --git a/lib/media_player.c b/lib/media_player.c
index 8fb79a8e2f5..2e2061b234d 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -1033,7 +1033,7 @@ void libvlc_video_set_format( libvlc_media_player_t *mp, const char *chroma,
 
 bool libvlc_video_set_output_callbacks(libvlc_media_player_t *mp,
                                        libvlc_video_engine_t engine,
-                                       libvlc_video_setup_cb setup_cb,
+                                       libvlc_video_output_setup_cb setup_cb,
                                        libvlc_video_output_cleanup_cb cleanup_cb,
                                        libvlc_video_update_output_cb update_output_cb,
                                        libvlc_video_swap_cb swap_cb,
@@ -1074,7 +1074,7 @@ bool libvlc_video_set_output_callbacks(libvlc_media_player_t *mp,
 
 bool libvlc_video_direct3d_set_callbacks(libvlc_media_player_t *mp,
                                          libvlc_video_direct3d_engine_t engine,
-                                         libvlc_video_direct3d_device_setup_cb setup_cb,
+                                         libvlc_video_output_setup_cb setup_cb,
                                          libvlc_video_direct3d_device_cleanup_cb cleanup_cb,
                                          libvlc_video_direct3d_set_resize_cb resize_cb,
                                          libvlc_video_update_output_cb update_output_cb,
diff --git a/modules/hw/d3d11/d3d11_device.c b/modules/hw/d3d11/d3d11_device.c
index 23e0b1b534c..80674b19a35 100644
--- a/modules/hw/d3d11/d3d11_device.c
+++ b/modules/hw/d3d11/d3d11_device.c
@@ -93,7 +93,7 @@ static int D3D11OpenDecoderDevice(vlc_decoder_device *device, bool forced, vout_
     else
 #endif
     {
-        libvlc_video_direct3d_device_setup_cb setupDeviceCb = var_InheritAddress( device, "vout-cb-setup" );
+        libvlc_video_output_setup_cb setupDeviceCb = var_InheritAddress( device, "vout-cb-setup" );
         if ( setupDeviceCb )
         {
             /* decoder device coming from the external app */
diff --git a/modules/hw/d3d9/d3d9_device.c b/modules/hw/d3d9/d3d9_device.c
index fd205f3a281..b02a5aa6cb0 100644
--- a/modules/hw/d3d9/d3d9_device.c
+++ b/modules/hw/d3d9/d3d9_device.c
@@ -70,7 +70,7 @@ int D3D9OpenDecoderDevice(vlc_decoder_device *device, vout_window_t *wnd)
 
     int adapter;
     sys->cleanupDeviceCb = NULL;
-    libvlc_video_direct3d_device_setup_cb setupDeviceCb = var_InheritAddress( device, "vout-cb-setup" );
+    libvlc_video_output_setup_cb setupDeviceCb = var_InheritAddress( device, "vout-cb-setup" );
     if ( setupDeviceCb )
     {
         /* external rendering */
diff --git a/modules/video_output/vgl.c b/modules/video_output/vgl.c
index e2f3c23414e..5f61bf2963e 100644
--- a/modules/video_output/vgl.c
+++ b/modules/video_output/vgl.c
@@ -38,7 +38,7 @@
 struct vout_display_sys_t
 {
     libvlc_video_output_cleanup_cb cleanupCb;
-    libvlc_video_setup_cb setupCb;
+    libvlc_video_output_setup_cb setupCb;
     libvlc_video_update_output_cb resizeCb;
     libvlc_video_swap_cb swapCb;
     libvlc_video_makeCurrent_cb makeCurrentCb;
@@ -141,11 +141,15 @@ static int Open(vlc_gl_t *gl, unsigned width, unsigned height)
     gl->destroy = Close;
 
     if( sys->setupCb )
-        if( !sys->setupCb(&sys->opaque) )
+    {
+        libvlc_video_direct3d_device_cfg_t setup_cfg = {};
+        libvlc_video_direct3d_device_setup_t configured_cfg;
+        if( !sys->setupCb(&sys->opaque, &setup_cfg, &configured_cfg) )
         {
             msg_Err( gl, "user setup failed" );
             return VLC_EGENERIC;
         }
+    }
 
     Resize(gl, width, height);
     return VLC_SUCCESS;
-- 
2.17.1



More information about the vlc-devel mailing list