[vlc-commits] commit: Prepared for a better vout reuse. (Laurent Aimar )

git at videolan.org git at videolan.org
Tue May 18 23:10:46 CEST 2010


vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Tue May 18 21:48:48 2010 +0200| [acbdb684610fea1a392b7780b529706a52eb7238] | committer: Laurent Aimar 

Prepared for a better vout reuse.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=acbdb684610fea1a392b7780b529706a52eb7238
---

 src/video_output/control.h      |    4 ++
 src/video_output/video_output.c |   87 ++++++++++++++++++---------------------
 2 files changed, 44 insertions(+), 47 deletions(-)

diff --git a/src/video_output/control.h b/src/video_output/control.h
index 9198a7b..59202e1 100644
--- a/src/video_output/control.h
+++ b/src/video_output/control.h
@@ -32,6 +32,7 @@
 enum {
     VOUT_CONTROL_INIT,
     VOUT_CONTROL_CLEAN,
+    VOUT_CONTROL_REINIT,                /* reinit */
 
 #if 0
     /* */
@@ -89,6 +90,9 @@ typedef struct {
             unsigned width;
             unsigned height;
         } window;
+        struct {
+            const video_format_t *fmt;
+        } reinit;
     } u;
 } vout_control_cmd_t;
 
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index b32872c..b4f48f7 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -98,63 +98,38 @@ static int VoutValidateFormat(video_format_t *dst,
  * This function looks for a video output thread matching the current
  * properties. If not found, it spawns a new one.
  *****************************************************************************/
-vout_thread_t *(vout_Request)( vlc_object_t *p_this, vout_thread_t *p_vout,
-                               const video_format_t *p_fmt )
+vout_thread_t *(vout_Request)( vlc_object_t *object, vout_thread_t *vout,
+                               const video_format_t *fmt )
 {
-    if( !p_fmt )
-    {
-        /* Video output is no longer used.
-         * TODO: support for reusing video outputs with proper _thread-safe_
-         * reference handling. */
-        if( p_vout )
-            vout_CloseAndRelease( p_vout );
+    if (!fmt) {
+        if (vout)
+            vout_CloseAndRelease(vout);
         return NULL;
     }
 
-    /* If a video output was provided, lock it, otherwise look for one. */
-    if( p_vout )
-    {
-        vlc_object_hold( p_vout );
-    }
-
-    /* TODO: find a suitable unused video output */
-
-    /* If we now have a video output, check it has the right properties */
-    if( p_vout )
-    {
-        if( !video_format_IsSimilar( &p_vout->p->original, p_fmt ) )
-        {
-            /* We are not interested in this format, close this vout */
-            vout_CloseAndRelease( p_vout );
-            vlc_object_release( p_vout );
-            p_vout = NULL;
-        }
-        else
-        {
-            /* This video output is cool! Hijack it. */
-            vlc_object_release( p_vout );
-        }
+    /* If a vout is provided, try reusing it */
+    if (vout) {
+        spu_Attach(vout->p->p_spu, VLC_OBJECT(vout), false);
+        vlc_object_detach(vout);
 
-        if( p_vout )
-        {
-            msg_Dbg( p_this, "reusing provided vout" );
+        vout_control_cmd_t cmd;
+        vout_control_cmd_Init(&cmd, VOUT_CONTROL_REINIT);
+        cmd.u.reinit.fmt = fmt;
 
-            spu_Attach( p_vout->p->p_spu, VLC_OBJECT(p_vout), false );
-            vlc_object_detach( p_vout );
+        vout_control_Push(&vout->p->control, &cmd);
+        vout_control_WaitEmpty(&vout->p->control);
+        if (!vout->p->dead) {
+            vlc_object_attach(vout, object);
+            spu_Attach(vout->p->p_spu, VLC_OBJECT(vout), true);
 
-            vlc_object_attach( p_vout, p_this );
-            spu_Attach( p_vout->p->p_spu, VLC_OBJECT(p_vout), true );
+            msg_Dbg(object, "reusing provided vout");
+            return vout;
         }
-    }
-
-    if( !p_vout )
-    {
-        msg_Dbg( p_this, "no usable vout present, spawning one" );
+        vout_CloseAndRelease(vout);
 
-        p_vout = vout_Create( p_this, p_fmt );
+        msg_Warn(object, "cannot reuse provided vout");
     }
-
-    return p_vout;
+    return vout_Create(object, fmt);
 }
 
 /*****************************************************************************
@@ -958,6 +933,18 @@ static void ThreadClean(vout_thread_t *vout)
     vout->p->dead = true;
     vout_control_Dead(&vout->p->control);
 }
+static int ThreadReinit(vout_thread_t *vout,
+                        const video_format_t *fmt)
+{
+    video_format_t original;
+    if (VoutValidateFormat(&original, fmt))
+        return VLC_EGENERIC;
+    if (video_format_IsSimilar(&original, &vout->p->original))
+        return VLC_SUCCESS;
+
+    /* TODO */
+    return VLC_EGENERIC;
+}
 
 /*****************************************************************************
  * Thread: video output thread
@@ -995,6 +982,12 @@ static void *Thread(void *object)
             case VOUT_CONTROL_CLEAN:
                 ThreadClean(vout);
                 return NULL;
+            case VOUT_CONTROL_REINIT:
+                if (ThreadReinit(vout, cmd.u.reinit.fmt)) {
+                    ThreadClean(vout);
+                    return NULL;
+                }
+                break;
             case VOUT_CONTROL_OSD_TITLE:
                 ThreadDisplayOsdTitle(vout, cmd.u.string);
                 break;



More information about the vlc-commits mailing list