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 *);
43 set_shortname (N_("Drawable"))
44 set_description (N_("Embedded X window video"))
45 set_category (CAT_VIDEO)
46 set_subcategory (SUBCAT_VIDEO_VOUT)
47 set_capability ("xwindow", 70)
48 set_callbacks (OpenXID, Close)
51 set_description (N_("Embedded Windows video"))
52 set_capability ("hwnd", 70)
53 set_callbacks (OpenHWND, Close)
57 static int Control (vout_window_t *, int, va_list);
60 * Find the drawable set by libvlc application.
62 static int Open (vlc_object_t *obj, const char *varname, bool ptr)
64 static vlc_mutex_t serializer = VLC_STATIC_MUTEX;
65 vout_window_t *wnd = (vout_window_t *)obj;
66 vlc_value_t val, globval;
68 if (var_Create (obj->p_libvlc, "drawable-busy", VLC_VAR_BOOL)
69 || var_Create (obj, varname, VLC_VAR_DOINHERIT
70 | (ptr ? VLC_VAR_ADDRESS : VLC_VAR_INTEGER)))
72 var_Get (obj, varname, &val);
74 vlc_mutex_lock (&serializer);
75 /* Note: We cannot simply clear the drawable variable.
76 * It would break libvlc_video_get_parent(). */
77 var_Get (obj->p_libvlc, varname, &globval);
78 if (ptr ? (val.p_address == globval.p_address)
79 : (val.i_int == globval.i_int))
81 if (var_GetBool (obj->p_libvlc, "drawable-busy"))
82 { /* LibVLC-wide drawable already in use */
89 var_SetBool (obj->p_libvlc, "drawable-busy", true);
91 /* If we got a drawable _not_ from the root object (from the input?),
92 * We assume it is not busy. This is a bug. */
93 vlc_mutex_unlock (&serializer);
95 var_Destroy (obj, varname);
97 if (ptr ? (val.p_address == NULL) : (val.i_int == 0))
99 var_Destroy (obj->p_libvlc, "drawable-busy");
104 wnd->handle.hwnd = val.p_address;
106 wnd->handle.xid = val.i_int;
108 /* FIXME: check that X server matches --x11-display (if specified) */
109 /* FIXME: get window size (in platform-dependent ways) */
111 wnd->control = Control;
115 static int OpenXID (vlc_object_t *obj)
117 return Open (obj, "drawable-xid", false);
120 static int OpenHWND (vlc_object_t *obj)
122 return Open (obj, "drawable-hwnd", true);
127 * Release the drawable.
129 static void Close (vlc_object_t *obj)
131 /* This is atomic with regards to var_GetBool() in Open(): */
132 var_SetBool (obj->p_libvlc, "drawable-busy", false);
134 /* Variables are reference-counted... */
135 var_Destroy (obj->p_libvlc, "drawable-busy");
139 static int Control (vout_window_t *wnd, int query, va_list ap)
143 case VOUT_SET_SIZE: /* not allowed */
144 case VOUT_SET_STAY_ON_TOP: /* not allowed either, would be ugly */
148 msg_Warn (wnd, "unsupported control query %d", query);