[vlc-commits] input: source: add input_source_GetStrId()

Thomas Guillem git at videolan.org
Fri Feb 28 20:46:07 CET 2020


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed Feb 26 13:09:26 2020 +0100| [693d8b34e371bd7d386ef3cf4594bee5ce6b2eaa] | committer: Thomas Guillem

input: source: add input_source_GetStrId()

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

 src/input/input.c          | 33 +++++++++++++++++++++++++++++----
 src/input/input_internal.h |  8 ++++++++
 2 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/src/input/input.c b/src/input/input.c
index ff83b6caec..f467ceb2a3 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -54,6 +54,7 @@
 #include <vlc_stream.h>
 #include <vlc_stream_extractor.h>
 #include <vlc_renderer_discovery.h>
+#include <vlc_md5.h>
 
 /*****************************************************************************
  * Local prototypes
@@ -87,7 +88,7 @@ static void UpdateTitleListfromDemux( input_thread_t * );
 
 static void MRLSections( const char *, int *, int *, int *, int *);
 
-static input_source_t *InputSourceNew( void );
+static input_source_t *InputSourceNew( const char *psz_mrl );
 static int InputSourceInit( input_source_t *in, input_thread_t *p_input,
                             const char *psz_mrl,
                             const char *psz_forced_demux, bool b_in_can_fail );
@@ -270,7 +271,7 @@ static input_thread_t *Create( vlc_object_t *p_parent,
     if( unlikely(priv == NULL) )
         return NULL;
 
-    priv->master = InputSourceNew();
+    priv->master = InputSourceNew( NULL );
     if( !priv->master )
     {
         free( priv );
@@ -2479,13 +2480,29 @@ error:
 static void input_SplitMRL( const char **, const char **, const char **,
                             const char **, char * );
 
-static input_source_t *InputSourceNew( void )
+static input_source_t *InputSourceNew( const char *psz_mrl )
 {
     input_source_t *in = calloc(1, sizeof(*in) );
     if( unlikely(in == NULL) )
         return NULL;
 
     vlc_atomic_rc_init( &in->rc );
+
+    if( psz_mrl )
+    {
+        /* Use the MD5 sum of the complete source URL as an identifier. */
+        struct md5_s md5;
+        InitMD5( &md5 );
+        AddMD5( &md5, psz_mrl, strlen( psz_mrl ) );
+        EndMD5( &md5 );
+        in->str_id = psz_md5_hash( &md5 );
+        if( !in->str_id )
+        {
+            free( in );
+            return NULL;
+        }
+    }
+
     return in;
 }
 
@@ -2719,7 +2736,15 @@ input_source_t *input_source_Hold( input_source_t *in )
 void input_source_Release( input_source_t *in )
 {
     if( vlc_atomic_rc_dec( &in->rc ) )
+    {
+        free( in->str_id );
         free( in );
+    }
+}
+
+const char *input_source_GetStrId( input_source_t *in )
+{
+    return in->str_id;
 }
 
 /*****************************************************************************
@@ -3274,7 +3299,7 @@ static int input_SlaveSourceAdd( input_thread_t *p_input,
 
     priv->i_last_es_cat = UNKNOWN_ES;
 
-    input_source_t *p_source = InputSourceNew();
+    input_source_t *p_source = InputSourceNew( psz_uri );
     if( !p_source )
         return VLC_EGENERIC;
 
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index 3b46771a3d..0590d5bfe7 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -370,6 +370,7 @@ struct input_source_t
     vlc_atomic_rc_t rc;
 
     demux_t  *p_demux; /**< Demux object (most downstream) */
+    char *str_id;
 
     /* Title infos for that input */
     bool         b_title_demux; /* Titles/Seekpoints provided by demux */
@@ -648,6 +649,13 @@ input_source_t *input_source_Hold( input_source_t *in );
  */
 void input_source_Release( input_source_t *in );
 
+/**
+ * Returns the string identifying this input source
+ *
+ * @return a string id or NULL if the source is the master
+ */
+const char *input_source_GetStrId( input_source_t *in );
+
 /* Bound pts_delay */
 #define INPUT_PTS_DELAY_MAX VLC_TICK_FROM_SEC(60)
 



More information about the vlc-commits mailing list