[vlc-devel] [PATCH 07/21] input/stream: stream-fragments: add vlc_stream_PeekFragment

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


As documented, the function this commit introduces implements
functionality so that one can peek into the next unhandled fragment
(if any).

An implementation will as such be able to see whether there is an
unhandled fragment, as well as decide whether it can handle it or not,
without modifying the internal fragment state.
---
 include/vlc_stream.h | 16 ++++++++++++++++
 src/input/stream.c   | 14 ++++++++++++++
 src/libvlccore.sym   |  1 +
 3 files changed, 31 insertions(+)

diff --git a/include/vlc_stream.h b/include/vlc_stream.h
index 0771b76..71e7b16 100644
--- a/include/vlc_stream.h
+++ b/include/vlc_stream.h
@@ -549,6 +549,22 @@ do { \
 VLC_API char* vlc_stream_CreateFragmentedMRL( stream_t * s, char const * resource );
 
 /**
+ * \ingroup stream
+ * \ingroup stream_fragments
+ *
+ * The function shall be used to peek the next unhandled fragment.
+ *
+ * The returned value is guaranteed to be the same across invocations until a
+ * corresponding call to ::vlc_stream_PopFragment has been made.
+ *
+ * \note The returned pointer is owned by the stream, and shall not be modified.
+ *
+ * \param s the stream
+ * \return a pointer to the next fragment, or NULL.
+ **/
+VLC_API char const* vlc_stream_PeekFragment( stream_t * s );
+
+/**
  * @}
  */
 
diff --git a/src/input/stream.c b/src/input/stream.c
index 8b7b9a3..0e48126 100644
--- a/src/input/stream.c
+++ b/src/input/stream.c
@@ -772,6 +772,20 @@ char* vlc_stream_CreateFragmentedMRL( stream_t* s, char const * fragment )
     return ret != -1 ? result : NULL;
 }
 
+char const* vlc_stream_PeekFragment( stream_t * s )
+{
+    stream_priv_t *priv = (stream_priv_t*)s;
+
+    size_t offset = priv->fragments.offset;
+    size_t tokens = priv->fragments.tokens;
+    char**   data = priv->fragments.data;
+
+    if( offset >= tokens )
+        return NULL;
+
+    return data[ offset ];
+}
+
 static int EscapeFragment( char** out, char const* data )
 {
     size_t out_len = 0;
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 463efd1..d298cc8 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -404,6 +404,7 @@ spu_ClearChannel
 vlc_stream_Block
 vlc_stream_CommonNew
 vlc_stream_CreateFragmentedMRL
+vlc_stream_PeekFragment
 vlc_stream_Delete
 vlc_stream_Eof
 vlc_stream_FilterNew
-- 
2.9.2



More information about the vlc-devel mailing list