NEWS: update from 3.0.x branch
[vlc.git] / modules / video_output / drawable_os2.c
blob8d125fb5546e9c62e632adbbea02523d8ada6d9e
1 /**
2 * @file drawable_os2.c
3 * @brief Legacy monolithic LibVLC video window provider
4 */
5 /*****************************************************************************
6 * Copyright © 2009 Rémi Denis-Courmont
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program 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 Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 # include <config.h>
25 #endif
27 #include <stdarg.h>
28 #include <assert.h>
30 #include <vlc_common.h>
31 #include <vlc_plugin.h>
32 #include <vlc_vout_window.h>
34 #define HWND_TEXT N_("Window handle (HWND)")
35 #define HWND_LONGTEXT N_( \
36 "Video will be embedded in this pre-existing window. " \
37 "If zero, a new window will be created.")
39 static int Open(vout_window_t *);
40 static void Close(vout_window_t *);
43 * Module descriptor
45 vlc_module_begin ()
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_callback(Open)
52 add_shortcut ("embed-hwnd")
54 add_integer ("drawable-hwnd", 0, HWND_TEXT, HWND_LONGTEXT, true)
55 change_volatile ()
56 vlc_module_end ()
58 /* Keep a list of busy drawables, so we don't overlap videos if there are
59 * more than one video track in the stream. */
60 static vlc_mutex_t serializer = VLC_STATIC_MUTEX;
61 static uintptr_t *used = NULL;
63 static const struct vout_window_operations ops = {
64 .destroy = Close,
67 static void RemoveDrawable(uintptr_t val)
69 size_t n = 0;
71 /* Remove this drawable from the list of busy ones */
72 vlc_mutex_lock (&serializer);
73 assert (used != NULL);
74 while (used[n] != val)
76 assert (used[n]);
77 n++;
80 used[n] = used[n + 1];
81 while (used[++n] != 0);
83 if (n == 1)
85 free (used);
86 used = NULL;
88 vlc_mutex_unlock (&serializer);
91 /**
92 * Find the drawable set by libvlc application.
94 static int Open(vout_window_t *wnd)
96 uintptr_t val = var_InheritInteger (wnd, "drawable-hwnd");
97 if (val == 0)
98 return VLC_EGENERIC;
100 uintptr_t *tab;
101 size_t n = 0;
103 vlc_mutex_lock (&serializer);
104 if (used != NULL)
105 for (/*n = 0*/; used[n]; n++)
106 if (used[n] == val)
108 msg_Warn (wnd, "HWND 0x%" PRIXPTR " is busy", val);
109 val = 0;
110 goto skip;
113 tab = realloc (used, sizeof (*used) * (n + 2));
114 if (likely(tab != NULL))
116 used = tab;
117 used[n] = val;
118 used[n + 1] = 0;
120 else
121 val = 0;
122 skip:
123 vlc_mutex_unlock (&serializer);
125 if (val == 0)
126 return VLC_EGENERIC;
128 wnd->type = VOUT_WINDOW_TYPE_HWND;
129 wnd->handle.hwnd = (void *)val;
130 wnd->ops = &ops;
131 wnd->sys = (void *)val;
132 return VLC_SUCCESS;
136 * Release the drawable.
138 static void Close (vout_window_t *wnd)
140 uintptr_t val = (uintptr_t)wnd->sys;
142 RemoveDrawable(val);