[vlc-devel] [PATCH 09/21] input/stream: stream-fragments: add vlc_stream_CommonNewMRL

Filip Roséen filip at atch.se
Sun Jul 31 22:42:18 CEST 2016


This commit implements vlc_stream_CommonNewMRL which is a wrapper
around vlc_stream_CommonNew that will take fragment data into account
when creating a new stream.
---
 include/vlc_stream.h | 13 ++++++++++++
 src/input/stream.c   | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/libvlccore.sym   |  1 +
 3 files changed, 73 insertions(+)

diff --git a/include/vlc_stream.h b/include/vlc_stream.h
index 58487c9..6cb2ef2 100644
--- a/include/vlc_stream.h
+++ b/include/vlc_stream.h
@@ -297,6 +297,19 @@ VLC_API void vlc_stream_Delete(stream_t *s);
 VLC_API stream_t *vlc_stream_CommonNew(vlc_object_t *, void (*)(stream_t *));
 
 /**
+ * Function used to create a new stream with fragments extracted from the
+ * passed MRL. The MRL is parsed according to the specification of \ref
+ * stream_fragments.
+ *
+ * \param parent the parent of the object
+ * \param mrl the mrl to which the stream is associated
+ * \param pf_destroy if not NULL, the referred to function will be called
+ *                   upon stream destruction.
+ **/
+VLC_API stream_t *vlc_stream_CommonNewMRL(vlc_object_t * parent,
+  char const* mrl, void (*pf_destroy)(stream_t *));
+
+/**
  * Get the size of the stream.
  */
 VLC_USED static inline int vlc_stream_GetSize( stream_t *s, uint64_t *size )
diff --git a/src/input/stream.c b/src/input/stream.c
index c363f2f..0113863 100644
--- a/src/input/stream.c
+++ b/src/input/stream.c
@@ -164,6 +164,65 @@ stream_t *vlc_stream_CommonNew(vlc_object_t *parent,
     return s;
 }
 
+stream_t *vlc_stream_CommonNewMRL(vlc_object_t *parent,
+  char const* mrl, void(*destroy)(stream_t*))
+{
+    stream_t* s = vlc_stream_CommonNew( parent, destroy );
+    stream_priv_t* priv = (stream_priv_t*)s;
+
+    s->psz_url = strdup( mrl );
+
+    if( unlikely( !s->psz_url ) )
+        goto error;
+
+    char* token = strchr( s->psz_url, '#' );
+
+    if( token )
+        *token++ = '\0';
+
+    /* always store base MRL at offset 0 */
+
+    TAB_APPEND( priv->fragments.tokens,
+                priv->fragments.data,
+                strdup( s->psz_url ) );
+
+    if( unlikely( !priv->fragments.data[0] ) )
+        goto error;
+
+    /* extract remaining tokens */
+
+    for( char* end = token; token; token = end )
+    {
+        vlc_uri_decode( token );
+
+        /* collapse "##" into "#" */
+
+        for( char* p = token; ( p = strstr( p, "##" ) ); end = p+1 )
+            memmove( p, p+1, strlen( p ) );
+
+        if( ( end = strchr( end, '#' ) ) )
+            *end++ = '\0';
+
+        token = strdup( token );
+
+        if( unlikely( !token ) )
+            goto error;
+
+        TAB_APPEND( priv->fragments.tokens,
+                    priv->fragments.data,
+                    token );
+    }
+
+    /* first unhandled fragment, if any, is always at offset 1 */
+
+    priv->fragments.offset = 1;
+    return s;
+
+error:
+    stream_CommonDelete( s );
+    return NULL;
+}
+
 void stream_CommonDelete(stream_t *s)
 {
     stream_priv_t *priv = (stream_priv_t *)s;
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 6bced5b..0c7da60 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -403,6 +403,7 @@ spu_RegisterChannel
 spu_ClearChannel
 vlc_stream_Block
 vlc_stream_CommonNew
+vlc_stream_CommonNewMRL
 vlc_stream_CreateFragmentedMRL
 vlc_stream_PeekFragment
 vlc_stream_PopFragment
-- 
2.9.2



More information about the vlc-devel mailing list