]> git.sesse.net Git - vlc/commitdiff
vout_window: use custom entry callback
authorRémi Denis-Courmont <remi@remlab.net>
Tue, 11 Jan 2011 20:31:33 +0000 (22:31 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Tue, 11 Jan 2011 20:31:33 +0000 (22:31 +0200)
include/vlc_vout_window.h
modules/gui/hildon/maemo.c
modules/gui/qt4/qt4.cpp
modules/gui/skins2/src/skin_main.cpp
modules/video_output/drawable.c
modules/video_output/xcb/window.c
src/video_output/window.c

index f4dddeae35c7d66c1f8b106f426430121cd3ed1c..a3df6d56b3267f6fb2d88c548ee2f11312518f38 100644 (file)
@@ -79,11 +79,6 @@ typedef struct {
 struct vout_window_t {
     VLC_COMMON_MEMBERS
 
-    /* Initial state (reserved).
-     * Once the open function is called, it will be set to NULL
-     */
-    const vout_window_cfg_t *cfg;
-
     /* window handle (mandatory)
      *
      * It must be filled in the open function.
index 401860f8453a743410b7da4b16031e53c9ef9797..9fa98097bfdf8123d5e69326451ee34b11e7efb6 100644 (file)
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static int      Open               ( vlc_object_t * );
-static void     Close              ( vlc_object_t * );
-static void     *Thread            ( void * );
-static int      OpenWindow         ( vlc_object_t * );
-static void     CloseWindow        ( vlc_object_t * );
-static int      ControlWindow      ( vout_window_t *, int, va_list );
-static gboolean interface_ready    ( gpointer );
+static int      Open            ( vlc_object_t * );
+static void     Close           ( vlc_object_t * );
+static void     *Thread         ( void * );
+static int      OpenWindow      ( vout_window_t *, const vout_window_cfg_t * );
+static void     CloseWindow     ( vout_window_t * );
+static int      ControlWindow   ( vout_window_t *, int, va_list );
+static gboolean interface_ready ( gpointer );
 
 /*****************************************************************************
 * Module descriptor
@@ -283,13 +283,12 @@ static void *Thread( void *obj )
 /**
 * Video output window provider
 */
-static int OpenWindow (vlc_object_t *p_obj)
+static int OpenWindow (vout_window_t *p_wnd, const vout_window_cfg_t *cfg)
 {
-    vout_window_t *p_wnd = (vout_window_t *)p_obj;
     intf_thread_t *p_intf;
     vlc_value_t val;
 
-    if (p_wnd->cfg->is_standalone)
+    if (cfg->is_standalone)
         return VLC_EGENERIC;
 
     if( var_Get( p_obj->p_libvlc, "hildon-iface", &val ) )
@@ -343,9 +342,8 @@ static int ControlWindow (vout_window_t *p_wnd, int query, va_list args)
     }
 }
 
-static void CloseWindow (vlc_object_t *p_obj)
+static void CloseWindow (vout_window_t *p_wnd)
 {
-    vout_window_t *p_wnd = (vout_window_t *)p_obj;
     intf_thread_t *p_intf = (intf_thread_t *)p_wnd->sys;
 
     if( p_intf->p_sys->b_fullscreen )
index 9caadf7d23b6c87b68f79153635e26108935c095..69880b5c43367f3851e06d37b45b8e1b56bc909d 100644 (file)
@@ -46,6 +46,7 @@
 #include "../../../share/icons/32x32/vlc.xpm"
 #include "../../../share/icons/32x32/vlc-xmas.xpm"
 #include <vlc_plugin.h>
+#include <vlc_vout_window.h>
 
 #ifdef WIN32 /* For static builds */
  #include <QtPlugin>
@@ -60,8 +61,8 @@ static int  OpenIntf     ( vlc_object_t * );
 static int  OpenDialogs  ( vlc_object_t * );
 static int  Open         ( vlc_object_t *, bool );
 static void Close        ( vlc_object_t * );
-static int  WindowOpen   ( vlc_object_t * );
-static void WindowClose  ( vlc_object_t * );
+static int  WindowOpen   ( vout_window_t *, const vout_window_cfg_t * );
+static void WindowClose  ( vout_window_t * );
 static void *Thread      ( void * );
 static void ShowDialog   ( intf_thread_t *, int, int, intf_dialog_args_t * );
 
@@ -607,31 +608,23 @@ static void ShowDialog( intf_thread_t *p_intf, int i_dialog_event, int i_arg,
  *
  * TODO move it out of here ?
  */
-#include <vlc_vout_window.h>
-
 static int WindowControl( vout_window_t *, int i_query, va_list );
 
-static int WindowOpen( vlc_object_t *p_obj )
+static int WindowOpen( vout_window_t *p_wnd, const vout_window_cfg_t *cfg )
 {
-    vout_window_t *p_wnd = (vout_window_t*)p_obj;
-
     /* */
-    if( p_wnd->cfg->is_standalone )
+    if( cfg->is_standalone )
         return VLC_EGENERIC;
 #if defined (Q_WS_X11)
-    if( var_InheritBool( p_obj, "video-wallpaper" ) )
+    if( var_InheritBool( p_wnd, "video-wallpaper" ) )
         return VLC_EGENERIC;
 #endif
 
-    vlc_value_t val;
-    if( var_Inherit( p_obj, "qt4-iface", VLC_VAR_ADDRESS, &val ) )
-        val.p_address = NULL;
-
-    intf_thread_t *p_intf = (intf_thread_t *)val.p_address;
-
+    intf_thread_t *p_intf =
+        (intf_thread_t *)var_InheritAddress( p_wnd, "qt4-iface" );
     if( !p_intf )
     {   /* If another interface is used, this plugin cannot work */
-        msg_Dbg( p_obj, "Qt4 interface not found" );
+        msg_Dbg( p_wnd, "Qt4 interface not found" );
         return VLC_EGENERIC;
     }
 
@@ -640,12 +633,12 @@ static int WindowOpen( vlc_object_t *p_obj )
         return VLC_EGENERIC;
 
     MainInterface *p_mi = p_intf->p_sys->p_mi;
-    msg_Dbg( p_obj, "requesting video..." );
+    msg_Dbg( p_wnd, "requesting video..." );
 
-    int i_x = p_wnd->cfg->x;
-    int i_y = p_wnd->cfg->y;
-    unsigned i_width = p_wnd->cfg->width;
-    unsigned i_height = p_wnd->cfg->height;
+    int i_x = cfg->x;
+    int i_y = cfg->y;
+    unsigned i_width = cfg->width;
+    unsigned i_height = cfg->height;
 
 #if defined (Q_WS_X11)
     p_wnd->handle.xid = p_mi->getVideo( &i_x, &i_y, &i_width, &i_height );
@@ -684,9 +677,8 @@ static int WindowControl( vout_window_t *p_wnd, int i_query, va_list args )
     return p_mi->controlVideo( i_query, args );
 }
 
-static void WindowClose( vlc_object_t *p_obj )
+static void WindowClose( vout_window_t *p_wnd )
 {
-    vout_window_t *p_wnd = (vout_window_t*)p_obj;
     MainInterface *p_mi = (MainInterface *)p_wnd->sys;
     QMutexLocker locker (&lock);
 
@@ -701,9 +693,9 @@ static void WindowClose( vlc_object_t *p_obj )
      * XCB and Xlib-XCB are fine with that. Plain Xlib wouldn't, */
     if (unlikely(!active))
     {
-        msg_Warn (p_obj, "video already released");
+        msg_Warn (p_wnd, "video already released");
         return;
     }
-    msg_Dbg (p_obj, "releasing video...");
+    msg_Dbg (p_wnd, "releasing video...");
     p_mi->releaseVideo();
 }
index 1fa1289f0ec2734e291de5e07f70f3e325d5d771..7e54841f08ec651b626e59ba30f509109e8e07f8 100644 (file)
@@ -316,10 +316,8 @@ end:
 static vlc_mutex_t serializer = VLC_STATIC_MUTEX;
 
 // Callbacks for vout requests
-static int WindowOpen( vlc_object_t *p_this )
+static int WindowOpen( vout_window_t *pWnd, const vout_window_cfg_t *cfg )
 {
-    vout_window_t *pWnd = (vout_window_t *)p_this;
-
     vlc_mutex_lock( &skin_load.mutex );
     intf_thread_t *pIntf = skin_load.intf;
     if( pIntf )
@@ -331,7 +329,7 @@ static int WindowOpen( vlc_object_t *p_this )
 
     if( !vlc_object_alive( pIntf ) ||
         !var_InheritBool( pIntf, "skinned-video") ||
-        pWnd->cfg->is_standalone )
+        cfg->is_standalone )
     {
         vlc_object_release( pIntf );
         return VLC_EGENERIC;
@@ -357,9 +355,8 @@ static int WindowOpen( vlc_object_t *p_this )
     }
 }
 
-static void WindowClose( vlc_object_t *p_this )
+static void WindowClose( vout_window_t *pWnd )
 {
-    vout_window_t *pWnd = (vout_window_t *)p_this;
     intf_thread_t *pIntf = (intf_thread_t *)pWnd->sys;
 
     vlc_mutex_lock( &serializer );
index 1a887fc6d3e2328a097ace79c71cd803c0851afe..961ae8b0672e1806e1eb29d75e6063c27084bf81 100644 (file)
@@ -31,8 +31,8 @@
 #include <vlc_plugin.h>
 #include <vlc_vout_window.h>
 
-static int  Open (vlc_object_t *);
-static void Close(vlc_object_t *);
+static int  Open (vout_window_t *, const vout_window_cfg_t *);
+static void Close(vout_window_t *);
 
 /*
  * Module descriptor
@@ -54,23 +54,22 @@ static vlc_mutex_t serializer = VLC_STATIC_MUTEX;
 /**
  * Find the drawable set by libvlc application.
  */
-static int Open (vlc_object_t *obj)
+static int Open (vout_window_t *wnd)
 {
-    vout_window_t *wnd = (vout_window_t *)obj;
     void **used, *val;
     size_t n = 0;
 
-    if (var_Create (obj->p_libvlc, "hwnd-in-use", VLC_VAR_ADDRESS)
-     || var_Create (obj, "drawable-hwnd", VLC_VAR_DOINHERIT | VLC_VAR_ADDRESS))
+    if (var_Create (wnd->p_libvlc, "hwnd-in-use", VLC_VAR_ADDRESS)
+     || var_Create (wnd, "drawable-hwnd", VLC_VAR_DOINHERIT | VLC_VAR_ADDRESS))
         return VLC_ENOMEM;
 
-    val = var_GetAddress (obj, "drawable-hwnd");
-    var_Destroy (obj, "drawable-hwnd");
+    val = var_GetAddress (wnd, "drawable-hwnd");
+    var_Destroy (wnd, "drawable-hwnd");
 
     /* Keep a list of busy drawables, so we don't overlap videos if there are
      * more than one video track in the stream. */
     vlc_mutex_lock (&serializer);
-    used = var_GetAddress (obj->p_libvlc, "hwnd-in-use");
+    used = var_GetAddress (wnd->p_libvlc, "hwnd-in-use");
     if (used != NULL)
     {
         while (used[n] != NULL)
@@ -86,7 +85,7 @@ static int Open (vlc_object_t *obj)
     {
         used[n] = val;
         used[n + 1] = NULL;
-        var_SetAddress (obj->p_libvlc, "hwnd-in-use", used);
+        var_SetAddress (wnd->p_libvlc, "hwnd-in-use", used);
     }
     else
     {
@@ -108,15 +107,14 @@ skip:
 /**
  * Release the drawable.
  */
-static void Close (vlc_object_t *obj)
+static void Close (vout_window_t *wnd)
 {
-    vout_window_t *wnd = (vout_window_t *)obj;
     void **used, *val = wnd->sys;
     size_t n = 0;
 
     /* Remove this drawable from the list of busy ones */
     vlc_mutex_lock (&serializer);
-    used = var_GetAddress (obj->p_libvlc, "hwnd-in-use");
+    used = var_GetAddress (wnd->p_libvlc, "hwnd-in-use");
     assert (used);
     while (used[n] != val)
     {
@@ -128,13 +126,13 @@ static void Close (vlc_object_t *obj)
     while (used[++n] != NULL);
 
     if (n == 0)
-         var_SetAddress (obj->p_libvlc, "hwnd-in-use", NULL);
+         var_SetAddress (wnd->p_libvlc, "hwnd-in-use", NULL);
     vlc_mutex_unlock (&serializer);
 
     if (n == 0)
         free (used);
     /* Variables are reference-counted... */
-    var_Destroy (obj->p_libvlc, "hwnd-in-use");
+    var_Destroy (wnd->p_libvlc, "hwnd-in-use");
 }
 
 
index 08f70f32f6a2351d3ca178af61006da120117293..2c5b24858c43d507a16baead03dce2dda80de7b0 100644 (file)
@@ -45,10 +45,10 @@ typedef xcb_atom_t Atom;
     "VLC can embed its video output in an existing X11 window. " \
     "This is the X identifier of that window (0 means none).")
 
-static int  Open (vlc_object_t *);
-static void Close (vlc_object_t *);
-static int  EmOpen (vlc_object_t *);
-static void EmClose (vlc_object_t *);
+static int  Open (vout_window_t *, const vout_window_cfg_t *);
+static void Close (vout_window_t *);
+static int  EmOpen (vout_window_t *, const vout_window_cfg_t *);
+static void EmClose (vout_window_t *);
 
 /*
  * Module descriptor
@@ -208,9 +208,8 @@ static void CacheAtoms (vout_window_sys_t *p_sys)
 /**
  * Create an X11 window.
  */
-static int Open (vlc_object_t *obj)
+static int Open (vout_window_t *wnd, const vout_window_cfg_t *cfg)
 {
-    vout_window_t *wnd = (vout_window_t *)obj;
     xcb_generic_error_t *err;
     xcb_void_cookie_t ck;
 
@@ -257,8 +256,7 @@ static int Open (vlc_object_t *obj)
 
     xcb_window_t window = xcb_generate_id (conn);
     ck = xcb_create_window_checked (conn, scr->root_depth, window, scr->root,
-                                    wnd->cfg->x, wnd->cfg->y,
-                                    wnd->cfg->width, wnd->cfg->height, 0,
+                                    cfg->x, cfg->y, cfg->width, cfg->height, 0,
                                     XCB_WINDOW_CLASS_INPUT_OUTPUT,
                                     scr->root_visual, mask, values);
     err = xcb_request_check (conn, ck);
@@ -275,8 +273,8 @@ static int Open (vlc_object_t *obj)
     wnd->sys = p_sys;
 
     p_sys->conn = conn;
-    if (var_InheritBool (obj, "keyboard-events"))
-        p_sys->keys = CreateKeyHandler (obj, conn);
+    if (var_InheritBool (wnd, "keyboard-events"))
+        p_sys->keys = CreateKeyHandler (VLC_OBJECT(wnd), conn);
     else
         p_sys->keys = NULL;
     p_sys->root = scr->root;
@@ -342,7 +340,7 @@ static int Open (vlc_object_t *obj)
     /* Make the window visible */
     xcb_map_window (conn, window);
 
-    if (var_InheritBool (obj, "video-wallpaper"))
+    if (var_InheritBool (wnd, "video-wallpaper"))
     {
         vout_window_SetState (wnd, VOUT_WINDOW_STATE_BELOW);
         vout_window_SetFullScreen (wnd, true);
@@ -373,9 +371,8 @@ error:
 /**
  * Destroys the X11 window.
  */
-static void Close (vlc_object_t *obj)
+static void Close (vout_window_t *wnd)
 {
-    vout_window_t *wnd = (vout_window_t *)obj;
     vout_window_sys_t *p_sys = wnd->sys;
     xcb_connection_t *conn = p_sys->conn;
 
@@ -607,15 +604,13 @@ static void ReleaseDrawable (vlc_object_t *obj, xcb_window_t window)
 /**
  * Wrap an existing X11 window to embed the video.
  */
-static int EmOpen (vlc_object_t *obj)
+static int EmOpen (vout_window_t *wnd, const vout_window_cfg_t *cfg)
 {
-    vout_window_t *wnd = (vout_window_t *)obj;
-
-    xcb_window_t window = var_InheritInteger (obj, "drawable-xid");
+    xcb_window_t window = var_InheritInteger (wnd, "drawable-xid");
     if (window == 0)
         return VLC_EGENERIC;
 
-    if (AcquireDrawable (obj, window))
+    if (AcquireDrawable (VLC_OBJECT(wnd), window))
         return VLC_EGENERIC;
 
     vout_window_sys_t *p_sys = malloc (sizeof (*p_sys));
@@ -635,15 +630,15 @@ static int EmOpen (vlc_object_t *obj)
         xcb_get_geometry_reply (conn, xcb_get_geometry (conn, window), NULL);
     if (geo == NULL)
     {
-        msg_Err (obj, "bad X11 window 0x%08"PRIx8, window);
+        msg_Err (wnd, "bad X11 window 0x%08"PRIx8, window);
         goto error;
     }
     p_sys->root = geo->root;
     free (geo);
 
-    if (var_InheritBool (obj, "keyboard-events"))
+    if (var_InheritBool (wnd, "keyboard-events"))
     {
-        p_sys->keys = CreateKeyHandler (obj, conn);
+        p_sys->keys = CreateKeyHandler (VLC_OBJECT(wnd), conn);
         if (p_sys->keys != NULL)
         {
             const uint32_t mask = XCB_CW_EVENT_MASK;
@@ -660,21 +655,20 @@ static int EmOpen (vlc_object_t *obj)
         DestroyKeyHandler (p_sys->keys);
 
     xcb_flush (conn);
-
+    (void) cfg;
     return VLC_SUCCESS;
 
 error:
     xcb_disconnect (conn);
     free (p_sys);
-    ReleaseDrawable (obj, window);
+    ReleaseDrawable (VLC_OBJECT(wnd), window);
     return VLC_EGENERIC;
 }
 
-static void EmClose (vlc_object_t *obj)
+static void EmClose (vout_window_t *wnd)
 {
-    vout_window_t *wnd = (vout_window_t *)obj;
     xcb_window_t window = wnd->handle.xid;
 
-    Close (obj);
-    ReleaseDrawable (obj, window);
+    Close (wnd);
+    ReleaseDrawable (VLC_OBJECT(wnd), window);
 }
index bcb08bcc87026c0f1c6e5d6edc60f7e44e8d6dba..fd21bec95ac2b9254cec3e8b4b8f1578a1c0c4b6 100644 (file)
@@ -42,6 +42,15 @@ typedef struct
     vlc_inhibit_t *inhibit;
 } window_t;
 
+static int vout_window_start(void *func, va_list ap)
+{
+    int (*activate)(vout_window_t *, const vout_window_cfg_t *) = func;
+    vout_window_t *wnd = va_arg(ap, vout_window_t *);
+    const vout_window_cfg_t *cfg = va_arg(ap, const vout_window_cfg_t *);
+
+    return activate(wnd, cfg);
+}
+
 vout_window_t *vout_window_New(vlc_object_t *obj,
                                const char *module,
                                const vout_window_cfg_t *cfg)
@@ -50,7 +59,6 @@ vout_window_t *vout_window_New(vlc_object_t *obj,
     window_t *w = vlc_custom_create(obj, sizeof(*w), VLC_OBJECT_GENERIC, name);
     vout_window_t *window = &w->wnd;
 
-    window->cfg = cfg;
     memset(&window->handle, 0, sizeof(window->handle));
     window->control = NULL;
     window->sys = NULL;
@@ -80,7 +88,8 @@ vout_window_t *vout_window_New(vlc_object_t *obj,
         assert(0);
     }
 
-    w->module = module_need(window, type, module, module && *module != '\0');
+    w->module = vlc_module_load(window, type, module, module && *module,
+                                vout_window_start, window, cfg);
     if (!w->module) {
         vlc_object_release(window);
         return NULL;
@@ -100,6 +109,14 @@ vout_window_t *vout_window_New(vlc_object_t *obj,
     return window;
 }
 
+static void vout_window_stop(void *func, va_list ap)
+{
+    int (*deactivate)(vout_window_t *) = func;
+    vout_window_t *wnd = va_arg(ap, vout_window_t *);
+
+    deactivate(wnd);
+}
+
 void vout_window_Delete(vout_window_t *window)
 {
     if (!window)
@@ -112,8 +129,7 @@ void vout_window_Delete(vout_window_t *window)
         vlc_inhibit_Destroy (w->inhibit);
     }
 
-    module_unneed(window, w->module);
-
+    vlc_module_unload(w->module, vout_window_stop, window);
     vlc_object_release(window);
 }