[vlc-devel] [PATCH 1/6] input/stream: add stream_extractor_AttachedParsed

Hugo Beauzée-Luyssen hugo at beauzee.fr
Fri Mar 17 11:08:07 CET 2017


On Fri, Mar 17, 2017, at 03:22 AM, Filip Roséen wrote:
> 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;
> +}

Couldn't this be written in a way that has no vlc_array_remove and a
single unconditional vlc_array_clean? You should be able to guess if
some items weren't processed if you index is < vlc_array_count.
This would prevent quite a bunch of reallocs/memmove

> +
>  char*
>  vlc_stream_extractor_CreateMRL( stream_directory_t* directory,
>                                  char const* subentry )
> -- 
> 2.12.0
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


-- 
  Hugo Beauzée-Luyssen
  hugo at beauzee.fr


More information about the vlc-devel mailing list