Drawable: separate XIDs and HWNDs
authorRémi Denis-Courmont <rdenis@simphalempin.com>
Mon, 2 Feb 2009 19:39:07 +0000 (21:39 +0200)
committerRémi Denis-Courmont <rdenis@simphalempin.com>
Mon, 2 Feb 2009 19:39:07 +0000 (21:39 +0200)
Also partially (internally only) fix missing Win64 drawable bits

modules/video_output/drawable.c
src/control/libvlc_internal.h
src/control/media_player.c
src/control/video.c
src/libvlc.c

index bc64d43..113ddb1 100644 (file)
@@ -32,7 +32,8 @@
 #include <vlc_vout.h>
 #include <vlc_window.h>
 
-static int  Open (vlc_object_t *);
+static int  OpenXID (vlc_object_t *);
+static int  OpenHWND (vlc_object_t *);
 static void Close (vlc_object_t *);
 
 /*
@@ -40,15 +41,16 @@ static void Close (vlc_object_t *);
  */
 vlc_module_begin ()
     set_shortname (N_("Drawable"))
-    set_description (N_("External embedded video window"))
+    set_description (N_("Embedded X window video"))
     set_category (CAT_VIDEO)
     set_subcategory (SUBCAT_VIDEO_VOUT)
-#ifdef WIN32
-    set_capability ("hwnd", 70)
-#else
     set_capability ("xwindow", 70)
-#endif
-    set_callbacks (Open, Close)
+    set_callbacks (OpenXID, Close)
+
+    add_submodule ()
+        set_description (N_("Embedded Windows video"))
+        set_capability ("hwnd", 70)
+        set_callbacks (OpenHWND, Close)
 
 vlc_module_end ()
 
@@ -57,11 +59,11 @@ static int Control (vout_window_t *, int, va_list);
 /**
  * Find the drawable set by libvlc application.
  */
-static int Open (vlc_object_t *obj)
+static int Open (vlc_object_t *obj, const char *varname, bool ptr)
 {
     static vlc_mutex_t serializer = VLC_STATIC_MUTEX;
     vout_window_t *wnd = (vout_window_t *)obj;
-    int drawable = 0;
+    vlc_value_t val;
 
     if (var_Create (obj->p_libvlc, "drawable-busy", VLC_VAR_BOOL))
         return VLC_ENOMEM;
@@ -71,33 +73,40 @@ static int Open (vlc_object_t *obj)
      * It would break libvlc_video_get_parent(). */
     if (!var_GetBool (obj->p_libvlc, "drawable-busy"))
     {
-        /* TODO: implement separate variables for XIDs and HWNDs */
-        drawable = var_GetInteger (obj->p_libvlc, "drawable");
-        if (drawable != 0)
+        var_Get (obj->p_libvlc, varname, &val);
+        if (ptr ? (val.p_address != NULL): (val.i_int == 0))
             var_SetBool (obj->p_libvlc, "drawable-busy", true);
     }
     vlc_mutex_unlock (&serializer);
 
-    if (drawable == 0)
+    if (ptr ? (val.p_address == NULL) : (val.i_int == 0))
     {
         var_Destroy (obj->p_libvlc, "drawable-busy");
         return VLC_EGENERIC;
     }
 
-#ifdef WIN32
-    /* FIXME: don't loose critical bits on Win64 */
-    wnd->handle.hwnd = (void *)drawable;
-#else
+    if (ptr)
+        wnd->handle.hwnd = val.p_address;
+    else
+        wnd->handle.xid = val.i_int;
+
     /* FIXME: check that X server matches --x11-display (if specified) */
-    /* FIXME: get X drawable dimensions */
-    wnd->handle.xid = drawable;
-#endif
     /* FIXME: get window size (in platform-dependent ways) */
 
     wnd->control = Control;
     return VLC_SUCCESS;
 }
 
+static int  OpenXID (vlc_object_t *obj)
+{
+    return Open (obj, "drawable-xid", false);
+}
+
+static int  OpenHWND (vlc_object_t *obj)
+{
+    return Open (obj, "drawable-hwnd", true);
+}
+
 
 /**
  * Release the drawable.
index 2fcc51b..fb26449 100644 (file)
@@ -153,7 +153,11 @@ struct libvlc_media_player_t
     struct libvlc_instance_t *  p_libvlc_instance; /* Parent instance */
     libvlc_media_t * p_md; /* current media descriptor */
     libvlc_event_manager_t *    p_event_manager;
-    libvlc_drawable_t           drawable;
+    union
+    {
+        void *hwnd;
+        uint32_t xid;
+    } drawable;
 
     bool        b_own_its_input_thread;
 };
index 5d36c59..7be73ed 100644 (file)
@@ -89,7 +89,8 @@ static void release_input_thread( libvlc_media_player_t *p_mi )
         input_StopThread( p_input_thread );
         vlc_thread_join( p_input_thread );
 
-        var_Destroy( p_input_thread, "drawable" );
+        var_Destroy( p_input_thread, "drawable-hwnd" );
+        var_Destroy( p_input_thread, "drawable-xid" );
     }
 
     vlc_object_release( p_input_thread );
@@ -257,7 +258,11 @@ libvlc_media_player_new( libvlc_instance_t * p_libvlc_instance,
         return NULL;
     }
     p_mi->p_md = NULL;
-    p_mi->drawable = 0;
+#ifndef WIN32
+    p_mi->drawable.xid = 0;
+#else
+    p_mi->drawable.hwnd = NULL;
+#endif
     p_mi->p_libvlc_instance = p_libvlc_instance;
     p_mi->p_input_thread = NULL;
     /* refcount strategy:
@@ -592,13 +597,14 @@ void libvlc_media_player_play( libvlc_media_player_t *p_mi,
 
     p_input_thread = p_mi->p_input_thread;
 
-    if( p_mi->drawable )
-    {
-        vlc_value_t val;
-        val.i_int = p_mi->drawable;
-        var_Create( p_input_thread, "drawable", VLC_VAR_DOINHERIT );
-        var_Set( p_input_thread, "drawable", val );
-    }
+    var_Create( p_input_thread, "drawable-xid", VLC_VAR_INTEGER );
+    var_Create( p_input_thread, "drawable-hwnd", VLC_VAR_ADDRESS );
+
+#ifndef WIN32
+    var_SetInteger( p_input_thread, "drawable-xid", p_mi->drawable.xid );
+#else
+    var_SetInteger( p_input_thread, "drawable-hwnd", p_mi->drawable.hwnd );
+#endif
 
     var_AddCallback( p_input_thread, "can-seek", input_seekable_changed, p_mi );
     var_AddCallback( p_input_thread, "can-pause", input_pausable_changed, p_mi );
@@ -703,7 +709,7 @@ void libvlc_media_player_set_drawable( libvlc_media_player_t *p_mi,
     input_thread_t *p_input_thread;
     vout_thread_t *p_vout = NULL;
 
-    p_mi->drawable = drawable;
+    p_mi->drawable.xid = drawable;
 
     /* Allow on the fly drawable changing. This is tricky has this may
      * not be supported by every vout. We though can't disable it
@@ -732,7 +738,7 @@ libvlc_drawable_t
 libvlc_media_player_get_drawable ( libvlc_media_player_t *p_mi, libvlc_exception_t *p_e )
 {
     VLC_UNUSED(p_e);
-    return p_mi->drawable;
+    return p_mi->drawable.xid;
 }
 
 /**************************************************************************
index 7b952af..9e846ba 100644 (file)
@@ -236,7 +236,16 @@ void libvlc_video_set_parent( libvlc_instance_t *p_instance, libvlc_drawable_t d
                               libvlc_exception_t *p_e )
 {
     /* set as default for future vout instances */
-    var_SetInteger(p_instance->p_libvlc_int, "drawable", (int)d);
+#ifdef WIN32
+    vlc_value_t val;
+
+    if( sizeof(HWND) > sizeof(libvlc_drawable_t) )
+        return; /* BOOM! we told you not to use this function! */
+    val.p_address = (void *)(uintptr_t)d;
+    var_Set( p_instance->p_libvlc_int, "drawable-hwnd", val );
+#else
+    var_SetInteger( p_instance->p_libvlc_int, "drawable-xid", d );
+#endif
 
     libvlc_media_player_t *p_mi = libvlc_playlist_get_media_player(p_instance, p_e);
     if( p_mi )
@@ -251,11 +260,16 @@ libvlc_drawable_t libvlc_video_get_parent( libvlc_instance_t *p_instance, libvlc
 {
     VLC_UNUSED(p_e);
 
-    libvlc_drawable_t result;
-
-    result = var_GetInteger( p_instance->p_libvlc_int, "drawable" );
+#ifdef WIN32
+    vlc_value_t val;
 
-    return result;
+    if( sizeof(HWND) > sizeof(libvlc_drawable_t) )
+        return 0;
+    var_Get( p_instance->p_libvlc_int, "drawable-hwnd", &val );
+    return (uintptr_t)val.p_address;
+#else
+    return var_GetInteger( p_instance->p_libvlc_int, "drawable-xid" );
+#endif
 }
 
 
index f297420..95f10cb 100644 (file)
@@ -983,7 +983,8 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
     /*
      * FIXME: kludge to use a p_libvlc-local variable for the Mozilla plugin
      */
-    var_Create( p_libvlc, "drawable", VLC_VAR_INTEGER );
+    var_Create( p_libvlc, "drawable-xid", VLC_VAR_INTEGER );
+    var_Create( p_libvlc, "drawable-hwnd", VLC_VAR_ADDRESS );
     var_Create( p_libvlc, "drawable-view-top", VLC_VAR_INTEGER );
     var_Create( p_libvlc, "drawable-view-left", VLC_VAR_INTEGER );
     var_Create( p_libvlc, "drawable-view-bottom", VLC_VAR_INTEGER );