[vlc-devel] [PATCH 14/18] libvlc: let the OpenGL host app tell libvlc its rendering area changed

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


VLC adjusts the text rendering based on the rendering area size, so we should
be able to adapt to changes in the host app.

This is using the wextern dummy window, like it's done with D3D callbacks. The
callback is given to the host app when the window is enabled and reset when the
window is disabled.

Not sure how it's supposed to be done with Android but given it uses a
regular window, it probably reports size changes already.
---
 include/vlc/libvlc_media_player.h | 37 +++++++++++++++++--------------
 lib/media_player.c                |  4 +++-
 2 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
index e8dc66c9740..10cf6583b10 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -663,6 +663,24 @@ typedef enum libvlc_video_engine_t {
     libvlc_video_engine_gles2,
 } libvlc_video_engine_t;
 
+/**
+ * Set the callback to call when the host app resizes the rendering area.
+ *
+ * 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_output_setup_cb callback.
+ *
+ * \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.
+ * \param report_opaque private pointer to pass to the \ref report_size_change callback. [IN]
+ */
+typedef void( *libvlc_video_direct3d_set_resize_cb )( void *opaque,
+                                                      void (*report_size_change)(void *report_opaque, unsigned width, unsigned height),
+                                                      void *report_opaque );
+
 /**
  * Set callbacks and data to render decoded video to a custom texture
  *
@@ -675,6 +693,7 @@ typedef enum libvlc_video_engine_t {
  * \param engine the GPU engine to use
  * \param setup_cb callback called to initialize user data
  * \param cleanup_cb callback called to clean up user data
+ * \param resize_cb callback to set the resize callback
  * \param update_output_cb callback to get the rendering format of the host (cannot be NULL)
  * \param swap_cb callback called after rendering a video frame (cannot be NULL)
  * \param makeCurrent_cb callback called to enter/leave the opengl context (cannot be NULL for \ref libvlc_video_engine_opengl and for \ref libvlc_video_engine_gles2)
@@ -690,6 +709,7 @@ bool libvlc_video_set_output_callbacks( libvlc_media_player_t *mp,
                                         libvlc_video_engine_t engine,
                                         libvlc_video_output_setup_cb setup_cb,
                                         libvlc_video_output_cleanup_cb cleanup_cb,
+                                        libvlc_video_direct3d_set_resize_cb resize_cb,
                                         libvlc_video_update_output_cb update_output_cb,
                                         libvlc_video_swap_cb swap_cb,
                                         libvlc_video_makeCurrent_cb makeCurrent_cb,
@@ -708,23 +728,6 @@ typedef enum libvlc_video_direct3d_engine_t {
     libvlc_video_direct3d_engine_d3d9,
 } libvlc_video_direct3d_engine_t;
 
-/** Set the callback to call when the host app resizes the rendering area.
- *
- * 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_output_setup_cb callback.
- *
- * \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.
- * \param report_opaque private pointer to pass to the \ref report_size_change callback. [IN]
- */
-typedef void( *libvlc_video_direct3d_set_resize_cb )( void *opaque,
-                                                      void (*report_size_change)(void *report_opaque, unsigned width, unsigned height),
-                                                      void *report_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_output_setup_cb() [IN]
diff --git a/lib/media_player.c b/lib/media_player.c
index 3186ba03c62..978d5317a50 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -1035,6 +1035,7 @@ bool libvlc_video_set_output_callbacks(libvlc_media_player_t *mp,
                                        libvlc_video_engine_t engine,
                                        libvlc_video_output_setup_cb setup_cb,
                                        libvlc_video_output_cleanup_cb cleanup_cb,
+                                       libvlc_video_direct3d_set_resize_cb resize_cb,
                                        libvlc_video_update_output_cb update_output_cb,
                                        libvlc_video_swap_cb swap_cb,
                                        libvlc_video_makeCurrent_cb makeCurrent_cb,
@@ -1045,7 +1046,7 @@ bool libvlc_video_set_output_callbacks(libvlc_media_player_t *mp,
     //use the default android window
     var_SetString( mp, "window", "");
 #else
-    var_SetString( mp, "window", "wdummy");
+    var_SetString( mp, "window", "wextern");
 #endif
 
     if( engine == libvlc_video_engine_gles2 )
@@ -1064,6 +1065,7 @@ bool libvlc_video_set_output_callbacks(libvlc_media_player_t *mp,
     var_SetAddress( mp, "vout-cb-opaque", opaque );
     var_SetAddress( mp, "vout-cb-setup", setup_cb );
     var_SetAddress( mp, "vout-cb-cleanup", cleanup_cb );
+    var_SetAddress( mp, "vout-cb-resize-cb", resize_cb );
     var_SetAddress( mp, "vout-cb-update-output", update_output_cb );
     var_SetAddress( mp, "vout-cb-swap", swap_cb );
     var_SetAddress( mp, "vout-cb-get-proc-address", getProcAddress_cb );
-- 
2.17.1



More information about the vlc-devel mailing list