[vlc-devel] [RFC PATCH 6/8] playlist: Add playlist_SetRenderer

Hugo Beauzée-Luyssen hugo at beauzee.fr
Thu Jul 6 19:14:29 CEST 2017


---
 include/vlc_input.h              |  3 +++
 include/vlc_playlist.h           |  8 +++++++
 src/Makefile.am                  |  1 +
 src/input/control.c              |  8 +++++++
 src/input/input.c                | 41 +++++++++++++++++++++++++++++++-
 src/input/input_internal.h       |  3 +++
 src/libvlccore.sym               |  1 +
 src/playlist/engine.c            |  3 +++
 src/playlist/playlist_internal.h |  1 +
 src/playlist/renderer.c          | 50 ++++++++++++++++++++++++++++++++++++++++
 10 files changed, 118 insertions(+), 1 deletion(-)
 create mode 100644 src/playlist/renderer.c

diff --git a/include/vlc_input.h b/include/vlc_input.h
index 8afefafe73..9672d8a75b 100644
--- a/include/vlc_input.h
+++ b/include/vlc_input.h
@@ -479,6 +479,9 @@ enum input_query_e
     INPUT_GET_VOUTS,        /* arg1=vout_thread_t ***, size_t *        res=can fail */
     INPUT_GET_ES_OBJECTS,   /* arg1=int id, vlc_object_t **dec, vout_thread_t **, audio_output_t ** */
 
+    /* Renderers */
+    INPUT_SET_RENDERER,     /* arg1=vlc_renderer_item_t* */
+
     /* External clock managments */
     INPUT_GET_PCR_SYSTEM,   /* arg1=mtime_t *, arg2=mtime_t *       res=can fail */
     INPUT_MODIFY_PCR_SYSTEM,/* arg1=int absolute, arg2=mtime_t      res=can fail */
diff --git a/include/vlc_playlist.h b/include/vlc_playlist.h
index 6774410433..36e69ea077 100644
--- a/include/vlc_playlist.h
+++ b/include/vlc_playlist.h
@@ -357,6 +357,14 @@ VLC_API bool playlist_IsServicesDiscoveryLoaded( playlist_t *,const char *) VLC_
 /** Query a services discovery */
 VLC_API int playlist_ServicesDiscoveryControl( playlist_t *, const char *, int, ... );
 
+/********************** Renderer ***********************/
+/**
+ * Sets a renderer or remove the current one
+ * @param p_item    The renderer item to be used, or NULL to disable the current
+ *                  one. If a renderer is provided, its reference count will be
+ *                  incremented.
+ */
+VLC_API int playlist_SetRenderer( playlist_t* p_pl, vlc_renderer_item_t* p_item );
 
 
 /********************************************************
diff --git a/src/Makefile.am b/src/Makefile.am
index c93a4021ee..f384c10328 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -225,6 +225,7 @@ libvlccore_la_SOURCES = \
 	playlist/item.c \
 	playlist/search.c \
 	playlist/services_discovery.c \
+	playlist/renderer.c \
 	input/item.c \
 	input/access.c \
 	input/clock.c \
diff --git a/src/input/control.c b/src/input/control.c
index 24fe630473..41877fb112 100644
--- a/src/input/control.c
+++ b/src/input/control.c
@@ -558,6 +558,14 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
             return es_out_ControlModifyPcrSystem( priv->p_es_out_display, b_absolute, i_system );
         }
 
+        case INPUT_SET_RENDERER:
+        {
+            vlc_renderer_item_t* p_item = va_arg( args, vlc_renderer_item_t* );
+            val.p_address = p_item;
+            input_ControlPush( p_input, INPUT_CONTROL_SET_RENDERER, &val );
+            break;
+        }
+
         default:
             msg_Err( p_input, "unknown query 0x%x in %s", i_query, __func__ );
             return VLC_EGENERIC;
diff --git a/src/input/input.c b/src/input/input.c
index 670afbebc0..e04a9c3a3b 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -54,6 +54,7 @@
 #include <vlc_modules.h>
 #include <vlc_stream.h>
 #include <vlc_stream_extractor.h>
+#include <vlc_renderer_discovery.h>
 
 /*****************************************************************************
  * Local prototypes
@@ -237,6 +238,8 @@ static void input_Destructor( vlc_object_t *obj )
     free( psz_name );
 #endif
 
+    if( priv->p_renderer )
+        vlc_renderer_item_release( priv->p_renderer );
     if( priv->p_es_out_display )
         es_out_Delete( priv->p_es_out_display );
 
@@ -2184,6 +2187,31 @@ static bool Control( input_thread_t *p_input,
             b_force_update = Control( p_input, INPUT_CONTROL_SET_TIME, val );
             break;
         }
+        case INPUT_CONTROL_SET_RENDERER:
+        {
+            vlc_renderer_item_t *p_item = val.p_address;
+            input_thread_private_t *p_priv = input_priv( p_input );
+            // We do not support switching from a renderer to another for now
+            if ( p_item == NULL && p_priv->p_renderer == NULL )
+                break;
+
+            if ( p_priv->p_renderer )
+            {
+                ControlUpdateSout( p_input, NULL );
+                p_priv->master->p_demux =
+                        demux_FilterRemoveFromChain( p_priv->master->p_demux,
+                                    vlc_renderer_item_demux_filter( p_priv->p_renderer ) );
+                vlc_renderer_item_release( p_priv->p_renderer );
+                p_priv->p_renderer = NULL;
+            }
+            if( p_item != NULL )
+            {
+                p_priv->p_renderer = vlc_renderer_item_hold( p_item );
+                ControlUpdateSout( p_input, vlc_renderer_item_sout( p_item ) );
+                ControlInsertDemuxFilter( p_input,
+                                    vlc_renderer_item_demux_filter( p_item ) );
+            }
+        }
 
         case INPUT_CONTROL_NAV_ACTIVATE:
         case INPUT_CONTROL_NAV_UP:
@@ -2395,6 +2423,7 @@ static input_source_t *InputSourceNew( input_thread_t *p_input,
                                        const char *psz_forced_demux,
                                        bool b_in_can_fail )
 {
+    input_thread_private_t *priv = input_priv(p_input);
     input_source_t *in = vlc_custom_create( p_input, sizeof( *in ),
                                             "input source" );
     if( unlikely(in == NULL) )
@@ -2495,7 +2524,16 @@ static input_source_t *InputSourceNew( input_thread_t *p_input,
         return NULL;
     }
 
-    char *psz_demux_chain = var_GetNonEmptyString(p_input, "demux-filter");
+    char *psz_demux_chain = NULL;
+    if( priv->p_renderer )
+    {
+        const char* psz_renderer_demux = vlc_renderer_item_demux_filter(
+                    priv->p_renderer );
+        if( psz_renderer_demux )
+            psz_demux_chain = strdup( psz_renderer_demux );
+    }
+    if( !psz_demux_chain )
+        psz_demux_chain = var_GetNonEmptyString(p_input, "demux-filter");
     /* add the chain of demux filters */
     demux_t *p_filtered_demux = demux_FilterChainNew( in->p_demux, psz_demux_chain );
     if ( p_filtered_demux != NULL )
@@ -3290,3 +3328,4 @@ char *input_CreateFilename(input_thread_t *input, const char *dir,
     free(filename);
     return path;
 }
+
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index 87da2a634f..439c69ad31 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -111,6 +111,7 @@ typedef struct input_thread_private_t
     es_out_t        *p_es_out;
     es_out_t        *p_es_out_display;
     vlc_viewpoint_t viewpoint;
+    vlc_renderer_item_t *p_renderer;
 
     /* Title infos FIXME multi-input (not easy) ? */
     int          i_title;
@@ -230,6 +231,8 @@ enum input_control_e
     INPUT_CONTROL_SET_RECORD_STATE,
 
     INPUT_CONTROL_SET_FRAME_NEXT,
+
+    INPUT_CONTROL_SET_RENDERER,
 };
 
 /* Internal helpers */
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 93c56d3749..b27b831815 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -360,6 +360,7 @@ playlist_VolumeSet
 playlist_VolumeUp
 playlist_MuteSet
 playlist_MuteGet
+playlist_SetRenderer
 sdp_AddAttribute
 sdp_AddMedia
 secstotimestr
diff --git a/src/playlist/engine.c b/src/playlist/engine.c
index 0b0c82ee92..680366cd09 100644
--- a/src/playlist/engine.c
+++ b/src/playlist/engine.c
@@ -34,6 +34,7 @@
 #include <vlc_playlist.h>
 #include <vlc_interface.h>
 #include <vlc_http.h>
+#include <vlc_renderer_discovery.h>
 #include "playlist_internal.h"
 #include "input/resource.h"
 
@@ -310,6 +311,8 @@ void playlist_Destroy( playlist_t *p_playlist )
     /* Release input resources */
     assert( p_sys->p_input == NULL );
     input_resource_Release( p_sys->p_input_resource );
+    if( p_sys->p_renderer )
+        vlc_renderer_item_release( p_sys->p_renderer );
 
     if( p_playlist->p_media_library != NULL )
         playlist_MLDump( p_playlist );
diff --git a/src/playlist/playlist_internal.h b/src/playlist/playlist_internal.h
index ed40679f8f..3515a898bd 100644
--- a/src/playlist/playlist_internal.h
+++ b/src/playlist/playlist_internal.h
@@ -58,6 +58,7 @@ typedef struct playlist_private_t
     input_thread_t *      p_input;  /**< the input thread associated
                                      * with the current item */
     input_resource_t *   p_input_resource; /**< input resources */
+    vlc_renderer_item_t *p_renderer;
     struct {
         /* Current status. These fields are readonly, only the playlist
          * main loop can touch it*/
diff --git a/src/playlist/renderer.c b/src/playlist/renderer.c
new file mode 100644
index 0000000000..eb1da914a7
--- /dev/null
+++ b/src/playlist/renderer.c
@@ -0,0 +1,50 @@
+/*****************************************************************************
+ * renderer.c : Manage renderer modules
+ *****************************************************************************
+ * Copyright (C) 1999-2017 VLC authors, VideoLAN and VideoLabs
+ *
+ * Authors: Hugo Beauzée-Luyssen <hugo at beauzee.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_playlist.h>
+#include <vlc_renderer_discovery.h>
+
+#include "playlist/playlist_internal.h"
+
+int playlist_SetRenderer( playlist_t* p_playlist, vlc_renderer_item_t* p_item )
+{
+    PL_LOCK;
+
+    playlist_private_t* p_priv = pl_priv( p_playlist );
+    if( p_priv->p_renderer )
+        vlc_renderer_item_release( p_priv->p_renderer );
+    p_priv->p_renderer = p_item;
+    if( p_item )
+        vlc_renderer_item_hold( p_item );
+    if( p_priv->p_input )
+    {
+        input_Control( p_priv->p_input, INPUT_SET_RENDERER, p_item );
+    }
+
+    PL_UNLOCK;
+    return VLC_SUCCESS;
+}
-- 
2.11.0



More information about the vlc-devel mailing list