[vlc-devel] [PATCH 08/21] input/stream: stream-fragments: add vlc_stream_PopFragment

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


When an implementation has decided to take responsibility for a
fragment, it shall call vlc_stream_PopFragment in order to modify the
internal fragment state.

The documentation included in this commit should provide deeper
insight.
---
 include/vlc_stream.h | 23 +++++++++++++++++++++++
 src/input/stream.c   | 19 +++++++++++++++++++
 src/libvlccore.sym   |  1 +
 3 files changed, 43 insertions(+)

diff --git a/include/vlc_stream.h b/include/vlc_stream.h
index 71e7b16..58487c9 100644
--- a/include/vlc_stream.h
+++ b/include/vlc_stream.h
@@ -565,6 +565,29 @@ VLC_API char* vlc_stream_CreateFragmentedMRL( stream_t * s, char const * resourc
 VLC_API char const* vlc_stream_PeekFragment( stream_t * s );
 
 /**
+ * \ingroup stream_fragments
+ *
+ * The function shall pop the next unhandled fragment from the stream,
+ * effectively stating that the caller takes full responsibility in terms of
+ * handling it.
+ *
+ * When a fragment has been popped, the internal state of the stream is updated
+ * so that the entity it refers to includes the popped fragment; effectively
+ * changing future invocations of ::vlc_stream_CreateFragmentedMRL for the
+ * stream in question.
+ *
+ * \note The memory referred to by the returned pointer needs to be freed by the
+ * caller.
+ *
+ * \pre It is \em undefined-behavior to invoke ::vlc_stream_PopFragment unless a
+ * previous call to ::vlc_stream_PeekFragment has returned a non-NULL value
+ * in-between a call to ::vlc_stream_PopFragment (if any).
+ *
+ * \return a pointer to the popped fragment
+ **/
+VLC_API char* vlc_stream_PopFragment( stream_t * s );
+
+/**
  * @}
  */
 
diff --git a/src/input/stream.c b/src/input/stream.c
index 0e48126..c363f2f 100644
--- a/src/input/stream.c
+++ b/src/input/stream.c
@@ -786,6 +786,25 @@ char const* vlc_stream_PeekFragment( stream_t * s )
     return data[ offset ];
 }
 
+char* vlc_stream_PopFragment( stream_t * s )
+{
+    stream_priv_t *priv = (stream_priv_t*)s;
+
+    size_t offset = priv->fragments.offset;
+    char**   data = priv->fragments.data;
+
+    char*  fragment = data[offset];
+    char* mrl_cache = vlc_stream_CreateFragmentedMRL( s, fragment );
+
+    if( unlikely( !mrl_cache ) )
+        return NULL;
+
+    data[offset] = mrl_cache;
+    ++priv->fragments.offset;
+
+    return fragment;
+}
+
 static int EscapeFragment( char** out, char const* data )
 {
     size_t out_len = 0;
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index d298cc8..6bced5b 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -405,6 +405,7 @@ vlc_stream_Block
 vlc_stream_CommonNew
 vlc_stream_CreateFragmentedMRL
 vlc_stream_PeekFragment
+vlc_stream_PopFragment
 vlc_stream_Delete
 vlc_stream_Eof
 vlc_stream_FilterNew
-- 
2.9.2



More information about the vlc-devel mailing list