[vlc-commits] resource: inline RequestVout()

Rémi Denis-Courmont git at videolan.org
Fri Jan 18 22:12:45 CET 2019


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri Jan 18 19:56:39 2019 +0200| [298f43a3f86af4b3ea0f5aa914adb2382a66b6b4] | committer: Rémi Denis-Courmont

resource: inline RequestVout()

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

 src/input/resource.c | 163 +++++++++++++++++++++++----------------------------
 1 file changed, 74 insertions(+), 89 deletions(-)

diff --git a/src/input/resource.c b/src/input/resource.c
index fd7d855a76..8f4b39d30e 100644
--- a/src/input/resource.c
+++ b/src/input/resource.c
@@ -193,93 +193,7 @@ static void DisplayVoutTitle( input_resource_t *p_resource,
     }
     free( psz_nowplaying );
 }
-static vout_thread_t *RequestVout( input_resource_t *p_resource,
-                                   const vout_configuration_t *req_cfg,
-                                   bool b_recycle )
-{
-    vlc_mutex_assert( &p_resource->lock );
-
-    vout_configuration_t cfg = *req_cfg;
-
-    if( cfg.fmt )
-    {
-        /* */
-        if( !cfg.vout && p_resource->p_vout_free )
-        {
-            msg_Dbg( p_resource->p_parent, "trying to reuse free vout" );
-            cfg.vout = p_resource->p_vout_free;
-
-            p_resource->p_vout_free = NULL;
-        }
-        else if( cfg.vout )
-        {
-            assert( cfg.vout != p_resource->p_vout_free );
-
-            vlc_mutex_lock( &p_resource->lock_hold );
-            TAB_REMOVE( p_resource->i_vout, p_resource->pp_vout, cfg.vout );
-            vlc_mutex_unlock( &p_resource->lock_hold );
-        }
-
-        /* */
-        vout_thread_t *p_vout = vout_Request( p_resource->p_parent, &cfg,
-                                              p_resource->p_input );
-        if( !p_vout )
-            return NULL;
-
-        DisplayVoutTitle( p_resource, p_vout );
-
-        /* Send original viewpoint to the input in order to update other ESes */
-        if( p_resource->p_input != NULL )
-            input_Control( p_resource->p_input, INPUT_SET_INITIAL_VIEWPOINT,
-                           &cfg.fmt->pose );
-
-        vlc_mutex_lock( &p_resource->lock_hold );
-        TAB_APPEND( p_resource->i_vout, p_resource->pp_vout, p_vout );
-        vlc_mutex_unlock( &p_resource->lock_hold );
-
-        if( p_resource->p_input )
-            input_SendEventVout( p_resource->p_input,
-                &(struct vlc_input_event_vout) {
-                    .action = VLC_INPUT_EVENT_VOUT_ADDED,
-                    .vout = p_vout,
-                });
-
-        return p_vout;
-    }
-    else
-    {
-        assert( cfg.vout );
-
-        vlc_mutex_lock( &p_resource->lock_hold );
-        TAB_REMOVE( p_resource->i_vout, p_resource->pp_vout, cfg.vout );
-        const int i_vout_active = p_resource->i_vout;
-        vlc_mutex_unlock( &p_resource->lock_hold );
-
-        if( p_resource->p_input )
-            input_SendEventVout( p_resource->p_input,
-                &(struct vlc_input_event_vout) {
-                    .action = VLC_INPUT_EVENT_VOUT_DELETED,
-                    .vout = cfg.vout,
-                });
 
-        if( p_resource->p_vout_free || i_vout_active > 0 || !b_recycle )
-        {
-            if( b_recycle )
-                msg_Dbg( p_resource->p_parent, "destroying vout (already one saved or active)" );
-            vout_CloseAndRelease( cfg.vout );
-        }
-        else
-        {
-            msg_Dbg( p_resource->p_parent, "saving a free vout" );
-            vout_FlushAll( cfg.vout );
-            vout_FlushSubpictureChannel( cfg.vout, -1 );
-
-            p_resource->p_vout_free = vout_Request( p_resource->p_parent, &cfg,
-                                                    NULL );
-        }
-        return NULL;
-    }
-}
 static vout_thread_t *HoldVout( input_resource_t *p_resource )
 {
     /* TODO FIXME: p_resource->pp_vout order is NOT stable */
@@ -459,14 +373,85 @@ vout_thread_t *input_resource_RequestVout( input_resource_t *p_resource,
                                            const vout_configuration_t *cfg,
                                            bool b_recycle )
 {
-    assert(cfg != NULL);
+    vout_thread_t *vout;
 
+    assert(cfg != NULL);
     vlc_mutex_lock( &p_resource->lock );
-    vout_thread_t *p_ret = RequestVout( p_resource, cfg, b_recycle );
+
+    if (cfg->fmt != NULL) {
+        vout_configuration_t cfg_buf;
+
+        if (cfg->vout == NULL && p_resource->p_vout_free != NULL) {
+            msg_Dbg(p_resource->p_parent, "trying to reuse free vout");
+
+            cfg_buf = *cfg;
+            cfg_buf.vout = p_resource->p_vout_free;
+            p_resource->p_vout_free = NULL;
+            cfg = &cfg_buf;
+
+        }  else if (cfg->vout != NULL) {
+            assert(cfg->vout != p_resource->p_vout_free);
+
+            vlc_mutex_lock(&p_resource->lock_hold);
+            TAB_REMOVE(p_resource->i_vout, p_resource->pp_vout, cfg->vout);
+            vlc_mutex_unlock(&p_resource->lock_hold);
+        }
+
+        vout = vout_Request(p_resource->p_parent, cfg, p_resource->p_input);
+        if (vout != NULL) {
+            DisplayVoutTitle(p_resource, vout);
+
+            /* Send original viewpoint to the input in order to update other ESes */
+            if (p_resource->p_input != NULL)
+                input_Control(p_resource->p_input, INPUT_SET_INITIAL_VIEWPOINT,
+                              &cfg->fmt->pose);
+
+            vlc_mutex_lock(&p_resource->lock_hold);
+            TAB_APPEND(p_resource->i_vout, p_resource->pp_vout, vout);
+            vlc_mutex_unlock(&p_resource->lock_hold);
+
+            if (p_resource->p_input != NULL)
+                input_SendEventVout(p_resource->p_input,
+                    &(struct vlc_input_event_vout) {
+                        .action = VLC_INPUT_EVENT_VOUT_ADDED,
+                        .vout = vout,
+                    });
+        }
+    } else {
+        assert(cfg->vout != NULL);
+
+        vlc_mutex_lock(&p_resource->lock_hold);
+        TAB_REMOVE(p_resource->i_vout, p_resource->pp_vout, cfg->vout);
+
+        const int active_vouts = p_resource->i_vout;
+        vlc_mutex_unlock(&p_resource->lock_hold);
+
+        if (p_resource->p_input != NULL)
+            input_SendEventVout(p_resource->p_input,
+                &(struct vlc_input_event_vout) {
+                    .action = VLC_INPUT_EVENT_VOUT_DELETED,
+                    .vout = cfg->vout,
+                });
+
+        if (p_resource->p_vout_free != NULL || active_vouts > 0 || !b_recycle) {
+            if (b_recycle)
+                msg_Dbg(p_resource->p_parent, "destroying vout (already one saved or active)");
+            vout_CloseAndRelease(cfg->vout);
+        } else {
+            msg_Dbg(p_resource->p_parent, "saving a free vout");
+            vout_FlushAll(cfg->vout);
+            vout_FlushSubpictureChannel(cfg->vout, -1);
+
+            p_resource->p_vout_free = vout_Request(p_resource->p_parent, cfg,
+                                                   NULL);
+        }
+        vout = NULL;
+    }
     vlc_mutex_unlock( &p_resource->lock );
 
-    return p_ret;
+    return vout;
 }
+
 vout_thread_t *input_resource_HoldVout( input_resource_t *p_resource )
 {
     return HoldVout( p_resource );



More information about the vlc-commits mailing list