[vlc-devel] [PATCH 1/3] player: add "vout window" context getter/setter

Thomas Guillem thomas at gllm.fr
Mon Apr 1 13:21:42 CEST 2019


This will be used by the libvlc media_player (when we switch from
input_thread_t to vlc_player_t).

This will be used by the following libvlc calls:
 - libvlc_media_player_set_nsobject
 - libvlc_media_player_set_xwindow
 - libvlc_media_player_set_hwnd
 - libvlc_media_player_set_android_context

The getter will be also usable from "vout window" module. We will switch these
modules to the new getter when libvlc is finally ported to vlc_player_t.
---
 include/vlc_player.h | 40 +++++++++++++++++++++++
 src/input/player.c   | 78 ++++++++++++++++++++++++++++++++++++++++++++
 src/libvlccore.sym   |  2 ++
 3 files changed, 120 insertions(+)

diff --git a/include/vlc_player.h b/include/vlc_player.h
index ad170f3306..7eddd8ef88 100644
--- a/include/vlc_player.h
+++ b/include/vlc_player.h
@@ -54,6 +54,9 @@ digraph player_states {
  * VLC Player API
  */
 
+/* Needed by vlc_vout_window_GetPlayerContext() */
+typedef struct vout_window_t vout_window_t;
+
 /**
  * Player opaque structure.
  */
@@ -337,6 +340,21 @@ enum vlc_vout_filter_type
     VLC_VOUT_FILTER_SUB_FILTER,
 };
 
+/**
+ * "vout window" context type
+ */
+enum vlc_player_window_context
+{
+    /** The context is a X11 window ID (uint32_t) */
+    VLC_PLAYER_WINDOW_CONTEXT_XWINDOW,
+    /** The context is a pointer to a android window handler */
+    VLC_PLAYER_WINDOW_CONTEXT_ANDROID,
+    /** The context is a pointer to a Window handle */
+    VLC_PLAYER_WINDOW_CONTEXT_HWND,
+    /** The context is a pointer to a NSView */
+    VLC_PLAYER_WINDOW_CONTEXT_NSOBJECT,
+};
+
 /** Player capability: can seek */
 #define VLC_PLAYER_CAP_SEEK (1<<0)
 /** Player capability: can pause */
@@ -2464,6 +2482,28 @@ vlc_player_GetV4l2Object(vlc_player_t *player) VLC_DEPRECATED;
 VLC_API void
 vlc_player_SetVideoSplitter(vlc_player_t *player, const char *splitter);
 
+/**
+ * Setup a "vout window" context
+ *
+ * @param player player instance
+ * @param type type of window context
+ * @param context pointer to the window context
+ */
+VLC_API void
+vlc_player_SetWindowContext(vlc_player_t *player,
+                            enum vlc_player_window_context type, void *context);
+
+/**
+ * Get the window context set by the player
+ *
+ * @param window window instance
+ * @param type type of window context
+ * @return the context set by vlc_player_SetWindowContext() for the same type
+ */
+VLC_API void*
+vlc_vout_window_GetPlayerContext(vout_window_t *window,
+                                 enum vlc_player_window_context type);
+
 /**
  * Get the audio output
  *
diff --git a/src/input/player.c b/src/input/player.c
index 22284418e4..010beea468 100644
--- a/src/input/player.c
+++ b/src/input/player.c
@@ -31,6 +31,7 @@
 #include <vlc_vector.h>
 #include <vlc_atomic.h>
 #include <vlc_tick.h>
+#include <vlc_modules.h>
 
 #include "libvlc.h"
 #include "input_internal.h"
@@ -3356,6 +3357,69 @@ vlc_player_SetVideoSplitter(vlc_player_t *player, const char *splitter)
         }
 }
 
+
+void
+vlc_player_SetWindowContext(vlc_player_t *player,
+                            enum vlc_player_window_context type, void *context)
+{
+    assert(player);
+    switch (type)
+    {
+        case VLC_PLAYER_WINDOW_CONTEXT_XWINDOW:
+            var_SetAddress(player, "drawable-xid", context);
+            var_SetString(player, "vout", "");
+            var_SetString(player, "window", context ? "embed-xid,any" : "");
+            break;
+#ifdef __ANDROID__
+        case VLC_PLAYER_WINDOW_CONTEXT_ANDROID:
+            var_SetAddress(player, "drawable-androidwindow", context);
+            break;
+#endif
+#if defined (_WIN32) || defined (__OS2__)
+        case VLC_PLAYER_WINDOW_CONTEXT_HWND:
+            var_SetAddress(player, "drawable-hwnd", context);
+            var_SetString(player, "vout", "");
+            var_SetString(player, "window", context ? "embed-hwnd,any" : "");
+            break;
+#endif
+#ifdef __APPLE__
+        case VLC_PLAYER_WINDOW_CONTEXT_NSOBJECT:
+            var_SetAddress (p_mi, "drawable-nsobject", context);
+            var_SetString (p_mi, "vout", "");
+            var_SetString (p_mi, "window", "");
+            break;
+#endif
+        default:
+            vlc_assert_unreachable();
+    }
+}
+
+void*
+vlc_vout_window_GetPlayerContext(vout_window_t *window,
+                                 enum vlc_player_window_context type)
+{
+    assert(window);
+    switch (type)
+    {
+        case VLC_PLAYER_WINDOW_CONTEXT_XWINDOW:
+            return var_InheritAddress(window, "drawable-xid");
+#ifdef __ANDROID__
+        case VLC_PLAYER_WINDOW_CONTEXT_ANDROID:
+            return var_InheritAddress(window, "drawable-androidwindow");
+#endif
+#if defined (_WIN32) || defined (__OS2__)
+        case VLC_PLAYER_WINDOW_CONTEXT_HWND:
+            return var_InheritAddress(window, "drawable-hwnd");
+#endif
+#ifdef __APPLE__
+        case VLC_PLAYER_WINDOW_CONTEXT_NSOBJECT:
+            return var_InheritAddress(window, "drawable-nsobject");
+#endif
+        default:
+            vlc_assert_unreachable();
+    }
+}
+
 void
 vlc_player_vout_SetFullscreen(vlc_player_t *player, bool enabled)
 {
@@ -3547,6 +3611,20 @@ vlc_player_New(vlc_object_t *parent,
     VAR_CREATE("spu", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
     VAR_CREATE("sout-spu", VLC_VAR_BOOL | VLC_VAR_DOINHERIT);
 
+    /* Context variables */
+    VAR_CREATE("vout", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
+    VAR_CREATE("window", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
+    VAR_CREATE("drawable-xid", VLC_VAR_ADDRESS);
+#if defined (_WIN32) || defined (__OS2__)
+    VAR_CREATE("drawable-hwnd", VLC_VAR_ADDRESS);
+#endif
+#ifdef __APPLE__
+    VAR_CREATE("drawable-nsobject", VLC_VAR_ADDRESS);
+#endif
+#ifdef __ANDROID__
+    VAR_CREATE("drawable-androidwindow", VLC_VAR_ADDRESS);
+#endif
+
     /* TODO: Override these variables since the player handle media ended
      * action itself. */
     VAR_CREATE("start-paused", VLC_VAR_BOOL);
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 086bbc4ffa..feb6c200c8 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -935,6 +935,8 @@ vlc_player_vout_SetFilter
 vlc_player_vout_SetFullscreen
 vlc_player_vout_SetWallpaperModeEnabled
 vlc_player_vout_Snapshot
+vlc_player_SetWindowContext
+vlc_vout_window_GetPlayerContext
 vlc_playlist_item_Hold
 vlc_playlist_item_Release
 vlc_playlist_item_GetMedia
-- 
2.20.1



More information about the vlc-devel mailing list