3 * @brief Legacy monolithic LibVLC video window provider
5 /*****************************************************************************
6 * Copyright © 2009 Rémi Denis-Courmont
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2.0
11 * of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 ****************************************************************************/
30 #include <vlc_common.h>
31 #include <vlc_plugin.h>
32 #include <vlc_vout_window.h>
34 static int Open (vlc_object_t *);
35 static void Close(vlc_object_t *);
37 #define XID_TEXT N_("ID of the video output X window")
38 #define XID_LONGTEXT N_( \
39 "VLC can embed its video output in an existing X11 window. " \
40 "This is the X identifier of that window (0 means none).")
46 set_shortname (N_("Drawable"))
47 set_description (N_("Embedded window video"))
48 set_category (CAT_VIDEO)
49 set_subcategory (SUBCAT_VIDEO_VOUT)
50 set_capability ("vout window", 70)
51 set_callbacks (Open, Close)
52 add_integer ("drawable-xid", 0, NULL, XID_TEXT, XID_LONGTEXT, true)
54 //add_integer ("drawable-hwnd", 0, NULL, HWN_TEXT, HWND_LONGTEXT, true) /* How to ? */
55 // change_unsaveable ()
58 static int Control (vout_window_t *, int, va_list);
60 /* TODO: move to vlc_variables.h */
61 static inline void *var_GetAddress (vlc_object_t *o, const char *name)
64 return var_Get (o, name, &val) ? NULL : val.p_address;
67 static vlc_mutex_t serializer = VLC_STATIC_MUTEX;
70 * Find the drawable set by libvlc application.
72 static int Open (vlc_object_t *obj)
74 vout_window_t *wnd = (vout_window_t *)obj;
78 switch (wnd->cfg->type)
80 case VOUT_WINDOW_TYPE_XWINDOW:
81 varname = "drawable-xid";
84 case VOUT_WINDOW_TYPE_HWND:
85 varname = "drawable-hwnd";
95 if (var_Create (obj->p_libvlc, "drawables-in-use", VLC_VAR_ADDRESS)
96 || var_Create (obj, varname, VLC_VAR_DOINHERIT
97 | (ptr ? VLC_VAR_ADDRESS : VLC_VAR_INTEGER)))
101 val = var_GetAddress (obj, varname);
103 val = (void *)(uintptr_t)var_GetInteger (obj, varname);
104 var_Destroy (obj, varname);
106 /* Keep a list of busy drawables, so we don't overlap videos if there are
107 * more than one video track in the stream. */
108 vlc_mutex_lock (&serializer);
109 /* TODO: per-type list of busy drawables */
110 used = var_GetAddress (VLC_OBJECT (obj->p_libvlc), "drawables-in-use");
113 while (used[n] != NULL)
121 used = realloc (used, sizeof (*used) * (n + 2));
126 var_SetAddress (obj->p_libvlc, "drawables-in-use", used);
131 msg_Warn (wnd, "drawable %p is busy", val);
134 vlc_mutex_unlock (&serializer);
140 wnd->handle.hwnd = val;
142 wnd->handle.xid = (uintptr_t)val;
144 /* FIXME: check that X server matches --x11-display (if specified) */
145 /* FIXME: get window size (in platform-dependent ways) */
147 wnd->control = Control;
153 * Release the drawable.
155 static void Close (vlc_object_t *obj)
157 vout_window_t *wnd = (vout_window_t *)obj;
158 void **used, *val = wnd->sys;
161 /* Remove this drawable from the list of busy ones */
162 vlc_mutex_lock (&serializer);
163 used = var_GetAddress (VLC_OBJECT (obj->p_libvlc), "drawables-in-use");
165 while (used[n] != val)
171 used[n] = used[n + 1];
172 while (used[++n] != NULL);
175 /* should not be needed (var_Destroy...) but better safe than sorry: */
176 var_SetAddress (obj->p_libvlc, "drawables-in-use", NULL);
177 vlc_mutex_unlock (&serializer);
181 /* Variables are reference-counted... */
182 var_Destroy (obj->p_libvlc, "drawables-in-use");
186 static int Control (vout_window_t *wnd, int query, va_list ap)
190 case VOUT_WINDOW_SET_SIZE: /* not allowed */
191 case VOUT_WINDOW_SET_ON_TOP: /* not allowed either, would be ugly */
194 msg_Warn (wnd, "unsupported control query %d", query);