[vlc-devel] [PATCH 3/6] vlc_stream: add vlc_stream_NewMRL
Rémi Denis-Courmont
remi at remlab.net
Tue Mar 28 19:56:10 CEST 2017
Le perjantaina 17. maaliskuuta 2017, 3.22.33 EEST Filip Roséen a écrit :
> ---
> include/vlc_stream.h | 16 ++++++++++++++++
> src/input/stream.c | 27 +++++++++++++++++++++++++++
> src/input/stream_extractor.c | 6 ------
> src/libvlccore.sym | 1 +
> 4 files changed, 44 insertions(+), 6 deletions(-)
>
> diff --git a/include/vlc_stream.h b/include/vlc_stream.h
> index 3a6d6ccd0e..55350d6b30 100644
> --- a/include/vlc_stream.h
> +++ b/include/vlc_stream.h
> @@ -350,6 +350,22 @@ VLC_USED;
> #define vlc_stream_NewURL(a, b) vlc_stream_NewURL(VLC_OBJECT(a), b)
>
> /**
> + * Create a stream_t reading from a \ref MRL.
> + * You must delete it using vlc_stream_Delete.
> + *
> + * \warning This function shall only be used when MRL functionality is
> + * explicitly needed (such as when referring to items within an
> + * archive). \ref vlc_stream_NewURL shall be used where
> applicable.
Frankly, *I* did not understand what that distinction meant until I read the
code below. Now, I can see the logic, and I don´t think that my own
documentation is great either. But I find this text very unhelpful.
> + *
> + * \param obj the parent of the requested stream
> + * \param mrl the mrl for which the stream_t should be created
> + * \return NULL on error, pointer to 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)
And regardless of how much you manage to improve the documentation, if you
leave this function in vlc_stream.h, people will (mis)use it, because they
cultivate cargo instead of reading the documentation.
It´s not your fault, but I think you should put it in the extractor header.
> +
> +/**
> * \defgroup stream_fifo FIFO stream
> * In-memory anonymous pipe
> @{
> diff --git a/src/input/stream.c b/src/input/stream.c
> index f63ca1fe53..063daa4c95 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,31 @@ 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 )
> + anchor = "#";
> +
> + char const* extra;
> + if( stream_extractor_AttachParsed( &stream, anchor + 1, &extra ) )
> + {
> + msg_Err( parent, "unable to open %s", mrl );
> + 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/input/stream_extractor.c b/src/input/stream_extractor.c
> index 038912881c..9b53a5ac57 100644
> --- a/src/input/stream_extractor.c
> +++ b/src/input/stream_extractor.c
> @@ -366,12 +366,6 @@ stream_extractor_AttachParsed( stream_t** source, char
> const* data, free( vlc_array_item_at_index( &identifiers, i ) );
> vlc_array_clear( &identifiers );
>
> - if( remaining == 0 )
> - {
> - vlc_stream_extractor_Attach( source, NULL, NULL );
> - return VLC_SUCCESS;
> - }
> -
> return remaining == 0 ? VLC_SUCCESS : VLC_EGENERIC;
> }
>
> diff --git a/src/libvlccore.sym b/src/libvlccore.sym
> index 8c4d6cd2e7..79a034d153 100644
> --- a/src/libvlccore.sym
> +++ b/src/libvlccore.sym
> @@ -410,6 +410,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
--
雷米‧德尼-库尔蒙
https://www.remlab.net/
More information about the vlc-devel
mailing list