[vlc-devel] [PATCH 1/6] input/stream: add stream_extractor_AttachedParsed
Filip Roséen
filip at atch.se
Fri Mar 17 03:22:31 CET 2017
This function will be used by entities who would otherwise have to
manually attach stream-extractors to a stream through use of
mrl_FragmentSplit and repeated use of vlc_stream_extractor_Attach.
As this handles both, it will be prevent reimplementing the same
functionality for cases where this is required.
---
src/input/stream.h | 26 ++++++++++++++++++++++++++
src/input/stream_extractor.c | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+)
diff --git a/src/input/stream.h b/src/input/stream.h
index 5db5732f40..2f5ca8b9b7 100644
--- a/src/input/stream.h
+++ b/src/input/stream.h
@@ -53,6 +53,32 @@ stream_t *stream_FilterAutoNew( stream_t *source ) VLC_USED;
*/
stream_t *stream_FilterChainNew( stream_t *p_source, const char *psz_chain );
+/**
+ * This function will parse the passed data, and try to attach
+ * stream-extractors for each specified entity as per \ref mrl,
+ *
+ * \warning The data in `*stream` can be modified even if this function only
+ * locates some of the entities specified in `psz_data`. It is up to
+ * the caller to free the resource referred to by `*stream`, no matter
+ * what this function returns.
+ *
+ * \warning Please see \ref vlc_stream_extractor_Attach for a function that
+ * will not modify the passed stream upon failure. \ref
+ * stream_extractor_AttachParsed shall only be used when the caller
+ * only cares about the stream on successful attachment of **all**
+ * stream-extractors referred to by `psz_data`, something which is not
+ * guaranteed.
+ *
+ * \param[out] source a pointer-to-pointer to stream where the attached
+ * stream-extractor will be applied. `*stream` will refer
+ * to the last successful attachment.
+ * \param[out] out_extra `*out_extra` will point to any additional data
+ * in `psz_data` that does not specify an entity (if any).
+ * \return VLC_SUCCESS on success, an error-code on failure
+ **/
+int stream_extractor_AttachParsed( stream_t** stream, const char* psz_data,
+ char const** out_extra );
+
char *get_path(const char *location);
#endif
diff --git a/src/input/stream_extractor.c b/src/input/stream_extractor.c
index 00cf5ee624..038912881c 100644
--- a/src/input/stream_extractor.c
+++ b/src/input/stream_extractor.c
@@ -340,6 +340,41 @@ vlc_stream_extractor_Attach( stream_t** source, char const* identifier,
return StreamExtractorAttach( source, identifier, module_name );
}
+int
+stream_extractor_AttachParsed( stream_t** source, char const* data,
+ char const** out_extra )
+{
+ vlc_array_t identifiers;
+
+ if( mrl_FragmentSplit( &identifiers, out_extra, data ) )
+ return VLC_EGENERIC;
+
+ while( vlc_array_count( &identifiers ) )
+ {
+ char* id = vlc_array_item_at_index( &identifiers, 0 );
+
+ if( vlc_stream_extractor_Attach( source, id, NULL ) )
+ break;
+
+ vlc_array_remove( &identifiers, 0 );
+ free( id );
+ }
+
+ size_t remaining = vlc_array_count( &identifiers );
+
+ for( size_t i = 0; i < remaining; ++i )
+ 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;
+}
+
char*
vlc_stream_extractor_CreateMRL( stream_directory_t* directory,
char const* subentry )
--
2.12.0
More information about the vlc-devel
mailing list