]> git.sesse.net Git - vlc/blobdiff - modules/video_output/drawable.c
sftp: change item b_net
[vlc] / modules / video_output / drawable.c
index 664873806c972d0d4b51903dcb575eb17bfe7400..9703f975105f63176a30b7e0831aac9fe6932544 100644 (file)
@@ -5,20 +5,20 @@
 /*****************************************************************************
  * Copyright © 2009 Rémi Denis-Courmont
  *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
  *
- * This library is distributed in the hope that it will be useful,
+ * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- ****************************************************************************/
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #include <vlc_plugin.h>
 #include <vlc_vout_window.h>
 
+#define HWND_TEXT N_("Window handle (HWND)")
+#define HWND_LONGTEXT N_( \
+    "Video will be embedded in this pre-existing window. " \
+    "If zero, a new window will be created.")
+
 static int  Open (vout_window_t *, const vout_window_cfg_t *);
 static void Close(vout_window_t *);
 
@@ -42,66 +47,66 @@ vlc_module_begin ()
     set_description (N_("Embedded window video"))
     set_category (CAT_VIDEO)
     set_subcategory (SUBCAT_VIDEO_VOUT)
-    set_capability ("vout window hwnd", 0)
+    set_capability ("vout window", 70)
     set_callbacks (Open, Close)
     add_shortcut ("embed-hwnd")
+
+    add_integer ("drawable-hwnd", 0, HWND_TEXT, HWND_LONGTEXT, true)
+        change_volatile ()
 vlc_module_end ()
 
 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 uintptr_t *used = NULL;
 
 /**
  * Find the drawable set by libvlc application.
  */
 static int Open (vout_window_t *wnd, const vout_window_cfg_t *cfg)
 {
-    VLC_UNUSED (cfg);
-    void *val = var_InheritAddress (wnd, "drawable-hwnd");
-    if (val == NULL)
+    if (cfg->type != VOUT_WINDOW_TYPE_INVALID
+     && cfg->type != VOUT_WINDOW_TYPE_HWND)
         return VLC_EGENERIC;
 
-    if (var_Create (wnd->p_libvlc, "hwnd-in-use", VLC_VAR_ADDRESS))
-        return VLC_ENOMEM;
+    uintptr_t val = var_InheritInteger (wnd, "drawable-hwnd");
+    if (val == 0)
+        return VLC_EGENERIC;
 
-    /* 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;
+    uintptr_t *tab;
     size_t n = 0;
 
     vlc_mutex_lock (&serializer);
-    used = var_GetAddress (wnd->p_libvlc, "hwnd-in-use");
     if (used != NULL)
-    {
-        while (used[n] != NULL)
-        {
+        for (/*n = 0*/; used[n]; n++)
             if (used[n] == val)
+            {
+                msg_Warn (wnd, "HWND 0x%zX is busy", val);
+                val = 0;
                 goto skip;
-            n++;
-        }
-    }
+            }
 
-    used = realloc (used, sizeof (*used) * (n + 2));
-    if (used != NULL)
+    tab = realloc (used, sizeof (*used) * (n + 2));
+    if (likely(tab != NULL))
     {
+        used = tab;
         used[n] = val;
-        used[n + 1] = NULL;
-        var_SetAddress (wnd->p_libvlc, "hwnd-in-use", used);
+        used[n + 1] = 0;
     }
     else
-    {
+        val = 0;
 skip:
-        msg_Warn (wnd, "HWND %p is busy", val);
-        val = NULL;
-    }
     vlc_mutex_unlock (&serializer);
 
-    if (val == NULL)
+    if (val == 0)
         return VLC_EGENERIC;
 
-    wnd->handle.hwnd = val;
+    wnd->type = VOUT_WINDOW_TYPE_HWND;
+    wnd->handle.hwnd = (void *)val;
     wnd->control = Control;
-    wnd->sys = val;
+    wnd->sys = (void *)val;
     return VLC_SUCCESS;
 }
 
@@ -110,13 +115,12 @@ skip:
  */
 static void Close (vout_window_t *wnd)
 {
-    void **used, *val = wnd->sys;
+    uintptr_t val = (uintptr_t)wnd->sys;
     size_t n = 0;
 
     /* Remove this drawable from the list of busy ones */
     vlc_mutex_lock (&serializer);
-    used = var_GetAddress (wnd->p_libvlc, "hwnd-in-use");
-    assert (used);
+    assert (used != NULL);
     while (used[n] != val)
     {
         assert (used[n]);
@@ -124,16 +128,14 @@ static void Close (vout_window_t *wnd)
     }
     do
         used[n] = used[n + 1];
-    while (used[++n] != NULL);
+    while (used[++n] != 0);
 
     if (n == 0)
-         var_SetAddress (wnd->p_libvlc, "hwnd-in-use", NULL);
+    {
+         free (used);
+         used = NULL;
+    }
     vlc_mutex_unlock (&serializer);
-
-    if (n == 0)
-        free (used);
-    /* Variables are reference-counted... */
-    var_Destroy (wnd->p_libvlc, "hwnd-in-use");
 }
 
 
@@ -151,4 +153,3 @@ static int Control (vout_window_t *wnd, int query, va_list ap)
             return VLC_EGENERIC;
     }
 }
-