[vlc-devel] [PATCH 2/4] vgl: expose opengl callbacks through libvlc

Pierre Lamot pierre at videolabs.io
Tue Jul 3 14:38:35 CEST 2018


---
 include/vlc/libvlc_media_player.h | 75 +++++++++++++++++++++++++++++++
 lib/libvlc.sym                    |  1 +
 lib/media_player.c                | 37 +++++++++++++++
 3 files changed, 113 insertions(+)

diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
index 87d3368bf3..2f3b699fd0 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -421,6 +421,81 @@ void libvlc_video_set_callbacks( libvlc_media_player_t *mp,
                                  libvlc_video_display_cb display,
                                  void *opaque );
 
+/**
+ * Callback prototype to configure rendering,
+ *
+ * You can allocate ressources required for rendering here.
+ *
+ * \param opaque private pointer passed to the @a libvlc_video_set_opengl_callbacks() [IN]
+ * \param width video width in pixel [IN]
+ * \param height video height in pixel [IN]
+ * \version LibVLC 4.0.0 or later
+ */
+typedef void (*libvlc_gl_create_cb)(void* opaque, size_t width, size_t height);
+
+/**
+ * Callback prototype to release resources created by libvlc_gl_create_cb
+ *
+ * \param opaque private pointer passed to the @a libvlc_video_set_opengl_callbacks() [IN]
+ * \version LibVLC 4.0.0 or later
+ */
+typedef void (*libvlc_gl_destroy_cb)(void* opaque);
+
+/**
+ * Callback prototype called before/after performing drawing calls.
+ * This funvtion will be called every time VLC renders a video frame,
+ * first before rendering with @a enter = true then after the rendering with
+ * @a enter = false
+ *
+ * \param opaque private pointer passed to the @a libvlc_video_set_opengl_callbacks() [IN]
+ * \param enter true before performing the rendering, false after [IN]
+ * \version LibVLC 4.0.0 or later
+ */
+typedef void (*libvlc_gl_render_cb)(void* opaque, bool enter);
+
+/**
+ * \param opaque private pointer passed to the @a libvlc_video_set_opengl_callbacks() [IN]
+ * \param enter true to set the context as current, false to unset it [IN]
+ * \version LibVLC 4.0.0 or later
+ */
+typedef bool (*libvlc_gl_makeCurrent_cb)(void* opaque, bool enter);
+
+/**
+ * Callback prototype to load opengl functions
+ *
+ * \param opaque private pointer passed to the @a libvlc_video_set_opengl_callbacks() [IN]
+ * \param enter true before performing the rendering, false after [IN]
+ * \param fct_name name of the opengl function to load
+ * \version LibVLC 4.0.0 or later
+ */
+typedef void* (*libvlc_gl_getProcAddress_cb)(void* opaque, const char* fct_name);
+
+/**
+ * Set callbacks and data to render decoded video to a custom OpenGL texture
+ *
+ * \warning VLC will perform video rendering in its own thread and at its own rate,
+ * You need to provide your own synchronisation mechanism.
+ *
+ * OpenGL context need to be created before playing a media.
+ *
+ * \param mp the media player
+ * \param create_cb resource creation callback (cannot be NULL)
+ * \param destroy_cb resource release callback (cannot be NULL)
+ * \param makeCurrent_cb callback called to enter/leave the opengl context (cannot be NULL)
+ * \param getProcAddress_cb opengl function loading callback (cannot be NULL)
+ * \param render_cb callback callback called before/after rendering a video frame (cannot be NULL)
+ * \param opaque private pointer passed to callbacks
+ * \version LibVLC 4.0.0 or later
+ */
+LIBVLC_API
+void libvlc_video_set_opengl_callbacks( libvlc_media_player_t *mp,
+                                        libvlc_gl_create_cb create_cb,
+                                        libvlc_gl_destroy_cb destroy_cb,
+                                        libvlc_gl_makeCurrent_cb makeCurrent_cb,
+                                        libvlc_gl_getProcAddress_cb getProcAddress_cb,
+                                        libvlc_gl_render_cb render_cb,
+                                        void* opaque );
+
 /**
  * Set decoded video chroma and dimensions.
  * This only works in combination with libvlc_video_set_callbacks(),
diff --git a/lib/libvlc.sym b/lib/libvlc.sym
index cdbcec9dc9..1787fbdc2f 100644
--- a/lib/libvlc.sym
+++ b/lib/libvlc.sym
@@ -248,6 +248,7 @@ libvlc_video_set_crop_geometry
 libvlc_video_set_deinterlace
 libvlc_video_set_format
 libvlc_video_set_format_callbacks
+libvlc_video_set_opengl_callbacks
 libvlc_video_set_key_input
 libvlc_video_set_logo_int
 libvlc_video_set_logo_string
diff --git a/lib/media_player.c b/lib/media_player.c
index 2755048162..8d411ecd5e 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -625,6 +625,8 @@ libvlc_media_player_new( libvlc_instance_t *instance )
     /* Video */
     var_Create (mp, "vout", VLC_VAR_STRING|VLC_VAR_DOINHERIT);
     var_Create (mp, "window", VLC_VAR_STRING);
+    var_Create (mp, "gl", VLC_VAR_STRING);
+    var_Create (mp, "gles2", VLC_VAR_STRING);
     var_Create (mp, "vmem-lock", VLC_VAR_ADDRESS);
     var_Create (mp, "vmem-unlock", VLC_VAR_ADDRESS);
     var_Create (mp, "vmem-display", VLC_VAR_ADDRESS);
@@ -635,6 +637,14 @@ libvlc_media_player_new( libvlc_instance_t *instance )
     var_Create (mp, "vmem-width", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
     var_Create (mp, "vmem-height", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
     var_Create (mp, "vmem-pitch", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
+
+    var_Create( mp, "vgl-create-cb", VLC_VAR_ADDRESS );
+    var_Create( mp, "vgl-destroy-cb", VLC_VAR_ADDRESS );
+    var_Create( mp, "vgl-render-cb", VLC_VAR_ADDRESS );
+    var_Create( mp, "vgl-get-proc-address-cb", VLC_VAR_ADDRESS );
+    var_Create( mp, "vgl-make-current-cb", VLC_VAR_ADDRESS );
+    var_Create( mp, "vgl-opaque", VLC_VAR_ADDRESS );
+
     var_Create (mp, "avcodec-hw", VLC_VAR_STRING);
     var_Create (mp, "drawable-xid", VLC_VAR_INTEGER);
 #if defined (_WIN32) || defined (__OS2__)
@@ -1133,6 +1143,33 @@ void libvlc_video_set_format( libvlc_media_player_t *mp, const char *chroma,
     var_SetInteger( mp, "vmem-pitch", pitch );
 }
 
+void libvlc_video_set_opengl_callbacks( libvlc_media_player_t *mp,
+                                        libvlc_gl_create_cb create_cb,
+                                        libvlc_gl_destroy_cb destroy_cb,
+                                        libvlc_gl_makeCurrent_cb makeCurrent_cb,
+                                        libvlc_gl_getProcAddress_cb getProcAddress_cb,
+                                        libvlc_gl_render_cb render_cb,
+                                        void* opaque)
+{
+#ifdef __ANDROID__
+    var_SetString ( mp, "vout", "gles2");
+    //use the default android window
+    var_SetString( mp, "window", "");
+#else
+    var_SetString ( mp, "vout", "gl");
+    var_SetString( mp, "window", "wdummy");
+#endif
+    var_SetString ( mp, "gl", "vgl");
+    var_SetString ( mp, "gles2", "vgl");
+    var_SetAddress( mp, "vgl-create-cb", create_cb );
+    var_SetAddress( mp, "vgl-destroy-cb", destroy_cb );
+    var_SetAddress( mp, "vgl-render-cb", render_cb );
+    var_SetAddress( mp, "vgl-get-proc-address-cb", getProcAddress_cb );
+    var_SetAddress( mp, "vgl-make-current-cb", makeCurrent_cb );
+    var_SetAddress( mp, "vgl-opaque", opaque );
+}
+
+
 /**************************************************************************
  * set_nsobject
  **************************************************************************/
-- 
2.17.1



More information about the vlc-devel mailing list