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>
33 #include <vlc_window.h>
35 static int OpenXID (vlc_object_t *);
36 static int OpenHWND (vlc_object_t *);
37 static void Close (vlc_object_t *);
39 #define XID_TEXT N_("ID of the video output X window")
40 #define XID_LONGTEXT N_( \
41 "VLC can embed its video output in an existing X11 window. " \
42 "This is the X identifier of that window (0 means none).")
48 set_shortname (N_("Drawable"))
49 set_description (N_("Embedded X window video"))
50 set_category (CAT_VIDEO)
51 set_subcategory (SUBCAT_VIDEO_VOUT)
52 set_capability ("xwindow", 70)
53 set_callbacks (OpenXID, Close)
54 add_integer ("drawable-xid", 0, NULL, XID_TEXT, XID_LONGTEXT, true)
56 /*change_integer_range (0, 0xffffffff)*/
59 set_description (N_("Embedded Windows video"))
60 set_capability ("hwnd", 70)
61 set_callbacks (OpenHWND, Close)
65 static int Control (vout_window_t *, int, va_list);
67 /* TODO: move to vlc_variables.h */
68 static inline void *var_GetAddress (vlc_object_t *o, const char *name)
71 return var_Get (o, name, &val) ? NULL : val.p_address;
74 static vlc_mutex_t serializer = VLC_STATIC_MUTEX;
77 * Find the drawable set by libvlc application.
79 static int Open (vlc_object_t *obj, const char *varname, bool ptr)
81 vout_window_t *wnd = (vout_window_t *)obj;
85 if (var_Create (obj->p_libvlc, "drawables-in-use", VLC_VAR_ADDRESS)
86 || var_Create (obj, varname, VLC_VAR_DOINHERIT
87 | (ptr ? VLC_VAR_ADDRESS : VLC_VAR_INTEGER)))
91 val = var_GetAddress (obj, varname);
93 val = (void *)(uintptr_t)var_GetInteger (obj, varname);
94 var_Destroy (obj, varname);
96 /* Keep a list of busy drawables, so we don't overlap videos if there are
97 * more than one video track in the stream. */
98 vlc_mutex_lock (&serializer);
99 /* TODO: per-type list of busy drawables */
100 used = var_GetAddress (VLC_OBJECT (obj->p_libvlc), "drawables-in-use");
103 while (used[n] != NULL)
111 used = realloc (used, sizeof (*used) * (n + 2));
116 var_SetAddress (obj->p_libvlc, "drawables-in-use", used);
121 msg_Warn (wnd, "drawable %p is busy", val);
124 vlc_mutex_unlock (&serializer);
130 wnd->handle.hwnd = val;
132 wnd->handle.xid = (uintptr_t)val;
134 /* FIXME: check that X server matches --x11-display (if specified) */
135 /* FIXME: get window size (in platform-dependent ways) */
137 wnd->control = Control;
142 static int OpenXID (vlc_object_t *obj)
144 return Open (obj, "drawable-xid", false);
147 static int OpenHWND (vlc_object_t *obj)
149 return Open (obj, "drawable-hwnd", true);
154 * Release the drawable.
156 static void Close (vlc_object_t *obj)
158 vout_window_t *wnd = (vout_window_t *)obj;
159 void **used, *val = wnd->p_sys;
162 /* Remove this drawable from the list of busy ones */
163 vlc_mutex_lock (&serializer);
164 used = var_GetAddress (VLC_OBJECT (obj->p_libvlc), "drawables-in-use");
166 while (used[n] != val)
172 used[n] = used[n + 1];
173 while (used[++n] != NULL);
176 /* should not be needed (var_Destroy...) but better safe than sorry: */
177 var_SetAddress (obj->p_libvlc, "drawables-in-use", NULL);
178 vlc_mutex_unlock (&serializer);
182 /* Variables are reference-counted... */
183 var_Destroy (obj->p_libvlc, "drawables-in-use");
187 static int Control (vout_window_t *wnd, int query, va_list ap)
191 case VOUT_SET_SIZE: /* not allowed */
192 case VOUT_SET_STAY_ON_TOP: /* not allowed either, would be ugly */
196 msg_Warn (wnd, "unsupported control query %d", query);