]> git.sesse.net Git - vlc/blob - modules/video_output/drawable.c
Fix spelling.
[vlc] / modules / video_output / drawable.c
1 /**
2  * @file drawable.c
3  * @brief Legacy monolithic LibVLC video window provider
4  */
5 /*****************************************************************************
6  * Copyright © 2009 Rémi Denis-Courmont
7  *
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
11  * of the License, or (at your option) any later version.
12  *
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.
17  *
18  * You should have received a copy of the GNU 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  ****************************************************************************/
22
23 #ifdef HAVE_CONFIG_H
24 # include <config.h>
25 #endif
26
27 #include <stdarg.h>
28 #include <assert.h>
29
30 #include <vlc_common.h>
31 #include <vlc_plugin.h>
32 #include <vlc_vout_window.h>
33
34 static int  Open (vlc_object_t *);
35 static void Close(vlc_object_t *);
36
37 /*
38  * Module descriptor
39  */
40 vlc_module_begin ()
41     set_shortname (N_("Drawable"))
42     set_description (N_("Embedded window video"))
43     set_category (CAT_VIDEO)
44     set_subcategory (SUBCAT_VIDEO_VOUT)
45     set_capability ("vout window hwnd", 70)
46     set_callbacks (Open, Close)
47 vlc_module_end ()
48
49 static int Control (vout_window_t *, int, va_list);
50
51 static vlc_mutex_t serializer = VLC_STATIC_MUTEX;
52
53 /**
54  * Find the drawable set by libvlc application.
55  */
56 static int Open (vlc_object_t *obj)
57 {
58     vout_window_t *wnd = (vout_window_t *)obj;
59     void **used, *val;
60     size_t n = 0;
61
62     if (var_Create (obj->p_libvlc, "hwnd-in-use", VLC_VAR_ADDRESS)
63      || var_Create (obj, "drawable-hwnd", VLC_VAR_DOINHERIT | VLC_VAR_ADDRESS))
64         return VLC_ENOMEM;
65
66     val = var_GetAddress (obj, "drawable-hwnd");
67     var_Destroy (obj, "drawable-hwnd");
68
69     /* Keep a list of busy drawables, so we don't overlap videos if there are
70      * more than one video track in the stream. */
71     vlc_mutex_lock (&serializer);
72     used = var_GetAddress (obj->p_libvlc, "hwnd-in-use");
73     if (used != NULL)
74     {
75         while (used[n] != NULL)
76         {
77             if (used[n] == val)
78                 goto skip;
79             n++;
80         }
81     }
82
83     used = realloc (used, sizeof (*used) * (n + 2));
84     if (used != NULL)
85     {
86         used[n] = val;
87         used[n + 1] = NULL;
88         var_SetAddress (obj->p_libvlc, "hwnd-in-use", used);
89     }
90     else
91     {
92 skip:
93         msg_Warn (wnd, "HWND %p is busy", val);
94         val = NULL;
95     }
96     vlc_mutex_unlock (&serializer);
97
98     if (val == NULL)
99         return VLC_EGENERIC;
100
101     wnd->handle.hwnd = val;
102     wnd->control = Control;
103     wnd->sys = val;
104     return VLC_SUCCESS;
105 }
106
107 /**
108  * Release the drawable.
109  */
110 static void Close (vlc_object_t *obj)
111 {
112     vout_window_t *wnd = (vout_window_t *)obj;
113     void **used, *val = wnd->sys;
114     size_t n = 0;
115
116     /* Remove this drawable from the list of busy ones */
117     vlc_mutex_lock (&serializer);
118     used = var_GetAddress (obj->p_libvlc, "hwnd-in-use");
119     assert (used);
120     while (used[n] != val)
121     {
122         assert (used[n]);
123         n++;
124     }
125     do
126         used[n] = used[n + 1];
127     while (used[++n] != NULL);
128
129     if (n == 0)
130          var_SetAddress (obj->p_libvlc, "hwnd-in-use", NULL);
131     vlc_mutex_unlock (&serializer);
132
133     if (n == 0)
134         free (used);
135     /* Variables are reference-counted... */
136     var_Destroy (obj->p_libvlc, "hwnd-in-use");
137 }
138
139
140 static int Control (vout_window_t *wnd, int query, va_list ap)
141 {
142     VLC_UNUSED( ap );
143
144     switch (query)
145     {
146         case VOUT_WINDOW_SET_SIZE:   /* not allowed */
147         case VOUT_WINDOW_SET_STATE: /* not allowed either, would be ugly */
148             return VLC_EGENERIC;
149         default:
150             msg_Warn (wnd, "unsupported control query %d", query);
151             return VLC_EGENERIC;
152     }
153 }
154