[vlc-commits] demux: merge access and location parameters as URL

Rémi Denis-Courmont git at videolan.org
Mon Apr 16 17:18:11 CEST 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Apr 16 17:49:01 2018 +0300| [169c6aee1c0930dc2290549b5a9856ae7ce4e318] | committer: Rémi Denis-Courmont

demux: merge access and location parameters as URL

(like is being done for access for a while)

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

 src/input/demux.c | 21 +++++++++------------
 src/input/demux.h |  4 ++--
 src/input/input.c | 37 +++++++++++++++++--------------------
 3 files changed, 28 insertions(+), 34 deletions(-)

diff --git a/src/input/demux.c b/src/input/demux.c
index 8700f729a7..8d3d33c02e 100644
--- a/src/input/demux.c
+++ b/src/input/demux.c
@@ -142,7 +142,7 @@ demux_t *demux_New( vlc_object_t *p_obj, const char *psz_name,
                     stream_t *s, es_out_t *out )
 {
     assert(s != NULL );
-    return demux_NewAdvanced( p_obj, NULL, "", psz_name, "", s, out, false );
+    return demux_NewAdvanced( p_obj, NULL, psz_name, "", s, out, false );
 }
 
 struct vlc_demux_private
@@ -179,8 +179,7 @@ static int demux_Probe(void *func, va_list ap)
 }
 
 demux_t *demux_NewAdvanced( vlc_object_t *p_obj, input_thread_t *p_parent_input,
-                            const char *psz_access, const char *psz_demux,
-                            const char *psz_location,
+                            const char *psz_demux, const char *url,
                             stream_t *s, es_out_t *out, bool b_preparsing )
 {
     struct vlc_demux_private *priv;
@@ -203,24 +202,22 @@ demux_t *demux_NewAdvanced( vlc_object_t *p_obj, input_thread_t *p_parent_input,
         }
     }
 
-    size_t schemelen = strlen(psz_access);
-
     p_demux->p_input = p_parent_input;
     p_demux->psz_name = strdup( psz_demux );
     if (unlikely(p_demux->psz_name == NULL))
         goto error;
 
-    if (unlikely(asprintf(&p_demux->psz_url, "%s://%s", psz_access,
-                          psz_location) == -1))
+    p_demux->psz_url = strdup(url);
+    if (unlikely(p_demux->psz_url == NULL))
         goto error;
 
-    p_demux->psz_location = p_demux->psz_url + schemelen + 3;
-    p_demux->psz_filepath = get_path( psz_location ); /* parse URL */
+    const char *p = strstr(p_demux->psz_url, "://");
+    p_demux->psz_location = (p != NULL) ? (p + 3) : "";
+    p_demux->psz_filepath = get_path(p_demux->psz_location); /* parse URL */
 
     if( !b_preparsing )
-        msg_Dbg( p_obj, "creating demux: access='%s' demux='%s' "
-                 "location='%s' file='%s'", psz_access, psz_demux,
-                 p_demux->psz_location, p_demux->psz_filepath );
+        msg_Dbg( p_obj, "creating demux \"%s\", URL: %s, path: %s",
+                 psz_demux, url, p_demux->psz_filepath );
 
     p_demux->s              = s;
     p_demux->out            = out;
diff --git a/src/input/demux.h b/src/input/demux.h
index a972482592..ca4da6efc5 100644
--- a/src/input/demux.h
+++ b/src/input/demux.h
@@ -32,8 +32,8 @@
 
 /* stream_t *s could be null and then it mean a access+demux in one */
 demux_t *demux_NewAdvanced( vlc_object_t *p_obj, input_thread_t *p_parent_input,
-                            const char *psz_access, const char *psz_demux,
-                            const char *psz_path, stream_t *s, es_out_t *out, bool );
+                            const char *psz_demux, const char *url,
+                            stream_t *s, es_out_t *out, bool );
 
 unsigned demux_TestAndClearFlags( demux_t *, unsigned );
 int demux_GetTitle( demux_t * );
diff --git a/src/input/input.c b/src/input/input.c
index e597c10113..c9e19504d2 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -2403,24 +2403,16 @@ InputStreamHandleAnchor( input_source_t *source, stream_t **stream,
     return VLC_SUCCESS;
 }
 
-static demux_t *InputDemuxNew( input_thread_t *p_input, input_source_t *p_source,
-                               const char *psz_access, const char *psz_demux,
-                               const char *psz_path, const char *psz_anchor )
+static demux_t *InputDemuxNew( input_thread_t *p_input,
+                               input_source_t *p_source, const char *url,
+                               const char *psz_demux, const char *psz_anchor )
 {
     input_thread_private_t *priv = input_priv(p_input );
     vlc_object_t *obj = VLC_OBJECT(p_source);
-    demux_t *p_demux = NULL;
-
-    /* not an access-demux: create the underlying access stream */
-    char *psz_base_mrl;
-
-    if( asprintf( &psz_base_mrl, "%s://%s", psz_access, psz_path ) < 0 )
-        return NULL;
 
+    /* create the underlying access stream */
     stream_t *p_stream = stream_AccessNew( obj, p_input, priv->p_es_out,
-                                           priv->b_preparsing, psz_base_mrl );
-    free( psz_base_mrl );
-
+                                           priv->b_preparsing, url );
     if( p_stream == NULL )
         return NULL;
 
@@ -2450,11 +2442,10 @@ static demux_t *InputDemuxNew( input_thread_t *p_input, input_source_t *p_source
         p_stream = stream_FilterChainNew( p_stream, "record" );
 
     /* create a regular demux with the access stream created */
-    p_demux = demux_NewAdvanced( obj, p_input, psz_access, psz_demux, psz_path,
-                                 p_stream, priv->p_es_out,
-                                 priv->b_preparsing );
-    if( p_demux )
-        return p_demux;
+    demux_t *demux = demux_NewAdvanced( obj, p_input, psz_demux, url, p_stream,
+                                        priv->p_es_out, priv->b_preparsing );
+    if( demux != NULL )
+        return demux;
 
 error:
     vlc_stream_Delete( p_stream );
@@ -2557,8 +2548,14 @@ static input_source_t *InputSourceNew( input_thread_t *p_input,
         TAB_CLEAN( count, tab );
     }
 
-    in->p_demux = InputDemuxNew( p_input, in, psz_access, psz_demux,
-                                 psz_path, psz_anchor );
+    char *url;
+    if( likely(asprintf( &url, "%s://%s", psz_access, psz_path ) >= 0) )
+    {
+        in->p_demux = InputDemuxNew( p_input, in, url, psz_demux, psz_anchor );
+        free( url );
+    }
+    else
+        in->p_demux = NULL;
 
     free( psz_demux_var );
     free( psz_dup );



More information about the vlc-commits mailing list