[vlc-commits] access: add vlc_access_NewMRL() and vlc_access_Delete() helpers

Rémi Denis-Courmont git at videolan.org
Wed Jul 22 22:49:33 CEST 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Jul 22 21:30:55 2015 +0300| [3660164b72249dcca1763ec1edc2e4ee509b2501] | committer: Rémi Denis-Courmont

access: add vlc_access_NewMRL() and vlc_access_Delete() helpers

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

 include/vlc_access.h |   97 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/input/access.c   |   21 +++++++++++
 src/libvlccore.sym   |    2 ++
 3 files changed, 120 insertions(+)

diff --git a/include/vlc_access.h b/include/vlc_access.h
index fe5eacf..08726b1 100644
--- a/include/vlc_access.h
+++ b/include/vlc_access.h
@@ -124,6 +124,103 @@ struct access_t
     input_thread_t *p_input;
 };
 
+/**
+ * Opens a new read-only byte stream.
+ *
+ * This function might block.
+ * The initial offset is of course always zero.
+ *
+ * \param obj parent VLC object
+ * \param mrl media resource location to read
+ * \return a new access object on success, NULL on failure
+ */
+VLC_API access_t *vlc_access_NewMRL(vlc_object_t *obj, const char *mrl);
+
+/**
+ * Closes a byte stream.
+ * \param access byte stream to close
+ */
+VLC_API void vlc_access_Delete(access_t *access);
+
+/**
+ * Sets the read byte offset.
+ */
+static inline int vlc_access_Seek(access_t *access, uint64_t offset)
+{
+    if (access->pf_seek == NULL)
+        return VLC_EGENERIC;
+    return access->pf_seek(access, offset);
+}
+
+/**
+ * Gets the read byte offset.
+ */
+static inline uint64_t vlc_access_Tell(const access_t *access)
+{
+    return access->info.i_pos;
+}
+
+/**
+ * Checks if end-of-stream is reached.
+ */
+static inline bool vlc_access_Eof(const access_t *access)
+{
+    return access->info.b_eof;
+}
+
+/**
+ * Reads a byte stream.
+ *
+ * This function waits for some data to be available (if necessary) and returns
+ * available data (up to the requested size). Not all byte streams support
+ * this. Some streams must be read with vlc_access_Block() instead.
+ *
+ * \note
+ * A short read does <b>not</b> imply the end of the stream. It merely implies
+ * that enough data is not immediately available.
+ * To detect the end of the stream, either check if the function returns zero,
+ * or call vlc_access_Eof().
+ *
+ * \note
+ * The function may return a negative value spuriously. Negative error values
+ * should be ignored; they do not necessarily indicate a fatal error.
+ *
+ * \param buf buffer to read data into
+ * \param len size of the buffer in bytes
+ * \return the number of bytes read (possibly less than requested),
+ *         zero at end-of-stream, or -1 on <b>transient</b> errors
+  */
+static inline ssize_t vlc_access_Read(access_t *access, void *buf, size_t len)
+{
+    if (access->pf_read == NULL)
+        return -1;
+    return access->pf_read(access, (unsigned char *)buf, len);
+}
+
+/**
+ * Dequeues one block of data.
+ *
+ * This function waits for a block of data to be available (if necessary) and
+ * returns a reference to it. Not all byte streams support this. Some streams
+ * must be read with vlc_access_Read() instead.
+ *
+ * \note
+ * The returned block may be of any size. The size is dependent on the
+ * underlying implementation of the byte stream.
+ *
+ * \note
+ * The function may return NULL spuriously. A NULL return is not indicative of
+ * a fatal error.
+ *
+ * \return a data block (free with block_Release()) or NULL
+ */
+static inline block_t *vlc_access_Block(access_t *access)
+{
+    if (access->pf_block == NULL)
+        return NULL;
+    return access->pf_block(access);
+}
+
 static inline int access_vaControl( access_t *p_access, int i_query, va_list args )
 {
     if( !p_access ) return VLC_EGENERIC;
diff --git a/src/input/access.c b/src/input/access.c
index fcab560..e21e282 100644
--- a/src/input/access.c
+++ b/src/input/access.c
@@ -28,6 +28,7 @@
 #include <assert.h>
 
 #include "access.h"
+#include "input_internal.h"
 #include <libvlc.h>
 #include <vlc_url.h>
 #include <vlc_modules.h>
@@ -119,6 +120,26 @@ void access_Delete( access_t *p_access )
     vlc_object_release( p_access );
 }
 
+access_t *vlc_access_NewMRL(vlc_object_t *parent, const char *mrl)
+{
+    char *buf = strdup(mrl);
+    if (unlikely(buf == NULL))
+        return NULL;
+
+    const char *access, *demux, *location, *anchor;
+    input_SplitMRL(&access, &demux, &location, &anchor, buf);
+
+    /* Both demux and anchor are ignored, since they are of no use here. */
+    access_t *obj = access_New(parent, NULL, access, "", location);
+
+    free(buf);
+    return obj;
+}
+
+void vlc_access_Delete(access_t *access)
+{
+    access_Delete(access);
+}
 
 /*****************************************************************************
  * access_GetParentInput:
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index a145079..82b09e0 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -1,5 +1,7 @@
 access_GetParentInput
 access_vaDirectoryControlHelper
+vlc_access_NewMRL
+vlc_access_Delete
 AddMD5
 aout_BitsPerSample
 aout_ChannelExtract



More information about the vlc-commits mailing list