[vlc-commits] vlc_stream: add vlc_stream_NewMRL

Filip Roséen git at videolan.org
Tue May 16 18:44:45 CEST 2017


vlc | branch: master | Filip Roséen <filip at atch.se> | Fri Mar 17 11:55:40 2017 +0100| [a1ae9f4b46167cd8d9f727c55525c011f7d586d7] | committer: Hugo Beauzée-Luyssen

vlc_stream: add vlc_stream_NewMRL

Signed-off-by: Hugo Beauzée-Luyssen <hugo at beauzee.fr>

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

 include/vlc_stream_extractor.h | 23 +++++++++++++++++++++++
 src/input/stream.c             | 28 ++++++++++++++++++++++++++++
 src/libvlccore.sym             |  1 +
 3 files changed, 52 insertions(+)

diff --git a/include/vlc_stream_extractor.h b/include/vlc_stream_extractor.h
index bc90879016..45c46d566d 100644
--- a/include/vlc_stream_extractor.h
+++ b/include/vlc_stream_extractor.h
@@ -90,6 +90,29 @@ typedef struct stream_directory_t {
 } stream_directory_t;
 
 /**
+ * Create a stream for the data referred to by a \ref mrl
+ *
+ * This function will create a \ref stream that reads from the specified \ref
+ * mrl, potentially making use of \ref stream_extractor%s to access named
+ * entities within the data read from the original source.
+ *
+ *  - See the \ref mrl specification for further information.
+ *  - The returned resource shall be deleted through \ref vlc_stream_Delete.
+ *
+ * \warning This function is only be used when \ref mrl functionality is
+ *          explicitly needed, \ref vlc_stream_NewURL shall be used where
+ *          applicable (and functionality associated with \ref MRL is not
+ *          wanted nor needed).
+ *
+ * \param obj the owner of the requested stream
+ * \param mrl the mrl for which the stream_t should be created
+ * \return `NULL` on error, a pointer to \ref stream_t on success.
+ **/
+VLC_API stream_t * vlc_stream_NewMRL(vlc_object_t *obj, const char *mrl)
+VLC_USED;
+#define vlc_stream_NewMRL(a, b) vlc_stream_NewMRL(VLC_OBJECT(a), b)
+
+/**
  * Create a relative MRL for the associated entity
  *
  * This function shall be used by stream_directory_t's in order to
diff --git a/src/input/stream.c b/src/input/stream.c
index f63ca1fe53..6045f53cee 100644
--- a/src/input/stream.c
+++ b/src/input/stream.c
@@ -37,9 +37,11 @@
 #include <vlc_access.h>
 #include <vlc_charset.h>
 #include <vlc_interrupt.h>
+#include <vlc_stream_extractor.h>
 
 #include <libvlc.h>
 #include "stream.h"
+#include "mrl_helpers.h"
 
 typedef struct stream_priv_t
 {
@@ -133,6 +135,32 @@ stream_t *(vlc_stream_NewURL)(vlc_object_t *p_parent, const char *psz_url)
     return s;
 }
 
+stream_t *(vlc_stream_NewMRL)(vlc_object_t* parent, const char* mrl )
+{
+    stream_t* stream = vlc_stream_NewURL( parent, mrl );
+
+    if( stream == NULL )
+        return NULL;
+
+    char const* anchor = strchr( mrl, '#' );
+
+    if( anchor == NULL )
+        return stream;
+
+    char const* extra;
+    if( stream_extractor_AttachParsed( &stream, anchor + 1, &extra ) )
+    {
+        msg_Err( parent, "unable to open %s", mrl );
+        vlc_stream_Delete( stream );
+        return NULL;
+    }
+
+    if( extra && *extra )
+        msg_Warn( parent, "ignoring extra fragment data: %s", extra );
+
+    return stream;
+}
+
 /**
  * Read from the stream until first newline.
  * \param s Stream handle to read from
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index 62f01fd06a..77c9a1aaf4 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -411,6 +411,7 @@ vlc_stream_ReadLine
 vlc_stream_ReadPartial
 vlc_stream_Seek
 vlc_stream_Tell
+vlc_stream_NewMRL
 vlc_stream_NewURL
 vlc_stream_vaControl
 vlc_stream_ReadDir



More information about the vlc-commits mailing list