[vlc-commits] input: Provide the potential renderer upon input thread creation

Hugo Beauzée-Luyssen git at videolan.org
Tue Sep 19 11:49:20 CEST 2017


vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Tue Jul  4 16:30:26 2017 +0200| [48f3be3af54888054dafdf9b47686c1a594a82a0] | committer: Hugo Beauzée-Luyssen

input: Provide the potential renderer upon input thread creation

refs #18605

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

 include/vlc_input.h          |  8 +++++---
 lib/media_player.c           |  2 +-
 modules/misc/fingerprinter.c |  2 +-
 src/input/input.c            | 28 +++++++++++++++++++++-------
 src/input/vlm.c              |  5 +++--
 src/playlist/thread.c        | 11 ++++++++++-
 6 files changed, 41 insertions(+), 15 deletions(-)

diff --git a/include/vlc_input.h b/include/vlc_input.h
index 3641f13295..13fe107fb6 100644
--- a/include/vlc_input.h
+++ b/include/vlc_input.h
@@ -494,8 +494,10 @@ enum input_query_e
  * Prototypes
  *****************************************************************************/
 
-VLC_API input_thread_t * input_Create( vlc_object_t *p_parent, input_item_t *, const char *psz_log, input_resource_t * ) VLC_USED;
-#define input_Create(a,b,c,d) input_Create(VLC_OBJECT(a),b,c,d)
+VLC_API input_thread_t * input_Create( vlc_object_t *p_parent, input_item_t *,
+                                       const char *psz_log, input_resource_t *,
+                                       vlc_renderer_item_t* p_renderer ) VLC_USED;
+#define input_Create(a,b,c,d,e) input_Create(VLC_OBJECT(a),b,c,d,e)
 
 VLC_API int input_Start( input_thread_t * );
 
@@ -521,7 +523,7 @@ static inline
 input_thread_t *input_CreateAndStart( vlc_object_t *parent,
                                       input_item_t *item, const char *log )
 {
-    input_thread_t *input = input_Create( parent, item, log, NULL );
+    input_thread_t *input = input_Create( parent, item, log, NULL, NULL );
     if( input != NULL && input_Start( input ) )
     {
         vlc_object_release( input );
diff --git a/lib/media_player.c b/lib/media_player.c
index f369b96755..b5677ae7ec 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -967,7 +967,7 @@ int libvlc_media_player_play( libvlc_media_player_t *p_mi )
     media_attach_preparsed_event( p_mi->p_md );
 
     p_input_thread = input_Create( p_mi, p_mi->p_md->p_input_item, NULL,
-                                   p_mi->input.p_resource );
+                                   p_mi->input.p_resource, NULL );
     unlock(p_mi);
     if( !p_input_thread )
     {
diff --git a/modules/misc/fingerprinter.c b/modules/misc/fingerprinter.c
index 6f09362747..593b2ff8cc 100644
--- a/modules/misc/fingerprinter.c
+++ b/modules/misc/fingerprinter.c
@@ -183,7 +183,7 @@ static void DoFingerprint( fingerprinter_thread_t *p_fingerprinter,
     }
     input_item_SetURI( p_item, psz_uri ) ;
 
-    input_thread_t *p_input = input_Create( p_fingerprinter, p_item, "fingerprinter", NULL );
+    input_thread_t *p_input = input_Create( p_fingerprinter, p_item, "fingerprinter", NULL, NULL );
     input_item_Release( p_item );
 
     if( p_input == NULL )
diff --git a/src/input/input.c b/src/input/input.c
index 39b7003b18..0de436b1c8 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -63,7 +63,8 @@ static  void *Run( void * );
 static  void *Preparse( void * );
 
 static input_thread_t * Create  ( vlc_object_t *, input_item_t *,
-                                  const char *, bool, input_resource_t * );
+                                  const char *, bool, input_resource_t *,
+                                  vlc_renderer_item_t * );
 static  int             Init    ( input_thread_t *p_input );
 static void             End     ( input_thread_t *p_input );
 static void             MainLoop( input_thread_t *p_input, bool b_interactive );
@@ -126,9 +127,10 @@ static void input_ChangeState( input_thread_t *p_input, int i_state ); /* TODO f
  */
 input_thread_t *input_Create( vlc_object_t *p_parent,
                               input_item_t *p_item,
-                              const char *psz_log, input_resource_t *p_resource )
+                              const char *psz_log, input_resource_t *p_resource,
+                              vlc_renderer_item_t *p_renderer )
 {
-    return Create( p_parent, p_item, psz_log, false, p_resource );
+    return Create( p_parent, p_item, psz_log, false, p_resource, p_renderer );
 }
 
 #undef input_Read
@@ -141,7 +143,7 @@ input_thread_t *input_Create( vlc_object_t *p_parent,
  */
 int input_Read( vlc_object_t *p_parent, input_item_t *p_item )
 {
-    input_thread_t *p_input = Create( p_parent, p_item, NULL, false, NULL );
+    input_thread_t *p_input = Create( p_parent, p_item, NULL, false, NULL, NULL );
     if( !p_input )
         return VLC_EGENERIC;
 
@@ -158,7 +160,7 @@ int input_Read( vlc_object_t *p_parent, input_item_t *p_item )
 input_thread_t *input_CreatePreparser( vlc_object_t *parent,
                                        input_item_t *item )
 {
-    return Create( parent, item, NULL, true, NULL );
+    return Create( parent, item, NULL, true, NULL, NULL );
 }
 
 /**
@@ -282,7 +284,8 @@ input_item_t *input_GetItem( input_thread_t *p_input )
  *****************************************************************************/
 static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
                                const char *psz_header, bool b_preparsing,
-                               input_resource_t *p_resource )
+                               input_resource_t *p_resource,
+                               vlc_renderer_item_t *p_renderer )
 {
     /* Allocate descriptor */
     input_thread_private_t *priv;
@@ -323,6 +326,9 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
     priv->attachment_demux = NULL;
     priv->p_sout   = NULL;
     priv->b_out_pace_control = false;
+    /* The renderer is passed after its refcount was incremented.
+     * The input thread is now responsible for releasing it */
+    priv->p_renderer = p_renderer;
 
     priv->viewpoint_changed = false;
     /* Fetch the viewpoint from the mediaplayer or the playlist if any */
@@ -840,7 +846,15 @@ static int InitSout( input_thread_t * p_input )
         return VLC_SUCCESS;
 
     /* Find a usable sout and attach it to p_input */
-    char *psz = var_GetNonEmptyString( p_input, "sout" );
+    char *psz = NULL;
+    if( priv->p_renderer )
+    {
+        const char *psz_renderer_sout = vlc_renderer_item_sout( priv->p_renderer );
+        if( asprintf( &psz, "#%s", psz_renderer_sout ) < 0 )
+            return VLC_ENOMEM;
+    }
+    if( !psz )
+        psz = var_GetNonEmptyString( p_input, "sout" );
     if( psz && strncasecmp( priv->p_item->psz_uri, "vlc:", 4 ) )
     {
         priv->p_sout  = input_resource_RequestSout( priv->p_resource, NULL, psz );
diff --git a/src/input/vlm.c b/src/input/vlm.c
index ccd5c36a65..99e0e5862b 100644
--- a/src/input/vlm.c
+++ b/src/input/vlm.c
@@ -624,7 +624,7 @@ static int vlm_OnMediaUpdate( vlm_t *p_vlm, vlm_media_sys_t *p_media )
             sout_description_data_t data;
             TAB_INIT(data.i_es, data.es);
 
-            p_input = input_Create( p_vlm->p_vod, p_media->vod.p_item, psz_header, NULL );
+            p_input = input_Create( p_vlm->p_vod, p_media->vod.p_item, psz_header, NULL, NULL );
             if( p_input )
             {
                 vlc_sem_t sem_preparse;
@@ -998,7 +998,8 @@ static int vlm_ControlMediaInstanceStart( vlm_t *p_vlm, int64_t id, const char *
     {
         p_instance->p_input = input_Create( p_instance->p_parent,
                                             p_instance->p_item, psz_log,
-                                            p_instance->p_input_resource );
+                                            p_instance->p_input_resource,
+                                            NULL );
         if( p_instance->p_input )
         {
             var_AddCallback( p_instance->p_input, "intf-event", InputEvent, p_media );
diff --git a/src/playlist/thread.c b/src/playlist/thread.c
index 5632babe4d..076260fb29 100644
--- a/src/playlist/thread.c
+++ b/src/playlist/thread.c
@@ -33,6 +33,7 @@
 #include <vlc_interface.h>
 #include <vlc_playlist.h>
 #include <vlc_rand.h>
+#include <vlc_renderer_discovery.h>
 #include "playlist_internal.h"
 
 /*****************************************************************************
@@ -195,6 +196,7 @@ static bool PlayItem( playlist_t *p_playlist, playlist_item_t *p_item )
 {
     playlist_private_t *p_sys = pl_priv(p_playlist);
     input_item_t *p_input = p_item->p_input;
+    vlc_renderer_item_t *p_renderer;
 
     PL_ASSERT_LOCKED;
 
@@ -202,13 +204,20 @@ static bool PlayItem( playlist_t *p_playlist, playlist_item_t *p_item )
 
     p_item->i_nb_played++;
     set_current_status_item( p_playlist, p_item );
+    p_renderer = p_sys->p_renderer;
+    /* Retain the renderer now to avoid it to be released by
+     * playlist_SetRenderer when we exit the locked scope. If the last reference
+     * was to be released, we would use a dangling pointer */
+    if( p_renderer )
+        vlc_renderer_item_hold( p_renderer );
     assert( p_sys->p_input == NULL );
     PL_UNLOCK;
 
     libvlc_MetadataCancel( p_playlist->obj.libvlc, p_item );
 
     input_thread_t *p_input_thread = input_Create( p_playlist, p_input, NULL,
-                                                   p_sys->p_input_resource );
+                                                   p_sys->p_input_resource,
+                                                   p_renderer );
     if( likely(p_input_thread != NULL) )
     {
         var_AddCallback( p_input_thread, "intf-event",



More information about the vlc-commits mailing list