Commit 4f6f08dd authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

drawable: use static variable rather than LibVLC variable

HWND are process-wide so there is not much point in a dedicated list
per LibVLC instance.
parent fe187eff
...@@ -49,7 +49,10 @@ vlc_module_end () ...@@ -49,7 +49,10 @@ vlc_module_end ()
static int Control (vout_window_t *, int, va_list); static int Control (vout_window_t *, int, va_list);
/* Keep a list of busy drawables, so we don't overlap videos if there are
* more than one video track in the stream. */
static vlc_mutex_t serializer = VLC_STATIC_MUTEX; static vlc_mutex_t serializer = VLC_STATIC_MUTEX;
static void **used = NULL;
/** /**
* Find the drawable set by libvlc application. * Find the drawable set by libvlc application.
...@@ -61,39 +64,29 @@ static int Open (vout_window_t *wnd, const vout_window_cfg_t *cfg) ...@@ -61,39 +64,29 @@ static int Open (vout_window_t *wnd, const vout_window_cfg_t *cfg)
if (val == NULL) if (val == NULL)
return VLC_EGENERIC; return VLC_EGENERIC;
if (var_Create (wnd->p_libvlc, "hwnd-in-use", VLC_VAR_ADDRESS)) void **tab;
return VLC_ENOMEM;
/* Keep a list of busy drawables, so we don't overlap videos if there are
* more than one video track in the stream. */
void **used;
size_t n = 0; size_t n = 0;
vlc_mutex_lock (&serializer); vlc_mutex_lock (&serializer);
used = var_GetAddress (wnd->p_libvlc, "hwnd-in-use");
if (used != NULL) if (used != NULL)
{ for (/*n = 0*/; used[n] != NULL; n++)
while (used[n] != NULL)
{
if (used[n] == val) if (used[n] == val)
{
msg_Warn (wnd, "HWND %p is busy", val);
val = NULL;
goto skip; goto skip;
n++;
}
} }
used = realloc (used, sizeof (*used) * (n + 2)); tab = realloc (used, sizeof (*used) * (n + 2));
if (used != NULL) if (likely(tab != NULL))
{ {
used = tab;
used[n] = val; used[n] = val;
used[n + 1] = NULL; used[n + 1] = NULL;
var_SetAddress (wnd->p_libvlc, "hwnd-in-use", used);
} }
else else
{
skip:
msg_Warn (wnd, "HWND %p is busy", val);
val = NULL; val = NULL;
} skip:
vlc_mutex_unlock (&serializer); vlc_mutex_unlock (&serializer);
if (val == NULL) if (val == NULL)
...@@ -110,16 +103,15 @@ skip: ...@@ -110,16 +103,15 @@ skip:
*/ */
static void Close (vout_window_t *wnd) static void Close (vout_window_t *wnd)
{ {
void **used, *val = wnd->sys; void *val = wnd->sys;
size_t n = 0; size_t n = 0;
/* Remove this drawable from the list of busy ones */ /* Remove this drawable from the list of busy ones */
vlc_mutex_lock (&serializer); vlc_mutex_lock (&serializer);
used = var_GetAddress (wnd->p_libvlc, "hwnd-in-use"); assert (used != NULL);
assert (used);
while (used[n] != val) while (used[n] != val)
{ {
assert (used[n]); assert (used[n] != NULL);
n++; n++;
} }
do do
...@@ -127,13 +119,11 @@ static void Close (vout_window_t *wnd) ...@@ -127,13 +119,11 @@ static void Close (vout_window_t *wnd)
while (used[++n] != NULL); while (used[++n] != NULL);
if (n == 0) if (n == 0)
var_SetAddress (wnd->p_libvlc, "hwnd-in-use", NULL); {
vlc_mutex_unlock (&serializer);
if (n == 0)
free (used); free (used);
/* Variables are reference-counted... */ used = NULL;
var_Destroy (wnd->p_libvlc, "hwnd-in-use"); }
vlc_mutex_unlock (&serializer);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment