[vlc-devel] [PATCH 7/7] libvlc: add libvlc_media_parse2
Thomas Guillem
thomas at gllm.fr
Fri Jan 9 10:04:51 CET 2015
maybe name it libvlc_media_parse_with_options ?
On Thu, Jan 8, 2015, at 18:10, Thomas Guillem wrote:
> Extended version of libvlc_media_parse_async and libvlc_media_parse. It
> uses a
> boolean to specify if parsing should be run asynchronously, and a flag to
> specify parse options.
> ---
> include/vlc/libvlc_media.h | 45
> +++++++++++++++++++++++++++++++++++++++--
> lib/libvlc.sym | 1 +
> lib/media.c | 50
> +++++++++++++++++++++++++++-------------------
> 3 files changed, 74 insertions(+), 22 deletions(-)
>
> diff --git a/include/vlc/libvlc_media.h b/include/vlc/libvlc_media.h
> index c93d87b..087f5ad 100644
> --- a/include/vlc/libvlc_media.h
> +++ b/include/vlc/libvlc_media.h
> @@ -33,6 +33,8 @@
>
> # ifdef __cplusplus
> extern "C" {
> +# else
> +# include <stdbool.h>
> # endif
>
> /** \defgroup libvlc_media LibVLC media
> @@ -223,6 +225,13 @@ typedef struct libvlc_media_track_t
>
> } libvlc_media_track_t;
>
> +typedef enum libvlc_media_parse_flag_t
> +{
> + libvlc_media_fetch_art_local = 0x01,
> + libvlc_media_fetch_art_network = 0x02,
> + libvlc_media_parse_network = 0x04,
> +} libvlc_media_parse_flag_t;
> +
>
> /**
> * Create a media with a certain given media resource location,
> @@ -485,7 +494,7 @@ LIBVLC_API libvlc_time_t
> /**
> * Parse a media.
> *
> - * This fetches (local) meta data and tracks information.
> + * This fetches (local) art, meta data and tracks information.
> * The method is synchronous.
> *
> * \see libvlc_media_parse_async
> @@ -500,7 +509,7 @@ libvlc_media_parse( libvlc_media_t *p_md );
> /**
> * Parse a media.
> *
> - * This fetches (local) meta data and tracks information.
> + * This fetches (local) art, meta data and tracks information.
> * The method is the asynchronous of libvlc_media_parse().
> *
> * To track when this is over you can listen to
> libvlc_MediaParsedChanged
> @@ -518,6 +527,38 @@ LIBVLC_API void
> libvlc_media_parse_async( libvlc_media_t *p_md );
>
> /**
> + * Parse a media.
> + *
> + * This fetches (local or network) art, meta data and/or tracks
> information.
> + * This method is the extended version of libvlc_media_parse_async() and
> + * libvlc_media_parse().
> + *
> + * It uses a boolean to specify if it should be run asynchronously.
> + * To track when this is over you can listen to
> libvlc_MediaParsedChanged
> + * event. However if the media was already parsed you will not receive
> this
> + * event.
> + *
> + * It uses a flag to specify parse options:
> + * libvlc_media_fetch_art_local: fetch covert art locally
> + * libvlc_media_fetch_art_network: fetch covert art using network
> resources
> + * libvlc_media_parse_network: parse media even if it's a network file
> + * Without any flag, media is parsed if it's a local file.
> + *
> + * \see libvlc_MediaParsedChanged
> + * \see libvlc_media_get_meta
> + * \see libvlc_media_get_tracks_info
> + * \see libvlc_media_parse_flag_t
> + *
> + * \param p_md media descriptor object
> + * \param p_async if true, this method is run asynchronously
> + * \param parse_flag parse options:
> + * \version LibVLC 3.0.0 or later
> + */
> +LIBVLC_API void
> +libvlc_media_parse2( libvlc_media_t *p_md, bool b_async,
> + libvlc_media_parse_flag_t parse_flag );
> +
> +/**
> * Get Parsed status for media descriptor object.
> *
> * \see libvlc_MediaParsedChanged
> diff --git a/lib/libvlc.sym b/lib/libvlc.sym
> index f0512c6..1c49081 100644
> --- a/lib/libvlc.sym
> +++ b/lib/libvlc.sym
> @@ -134,6 +134,7 @@ libvlc_media_new_path
> libvlc_media_new_as_node
> libvlc_media_new_from_input_item
> libvlc_media_parse
> +libvlc_media_parse2
> libvlc_media_parse_async
> libvlc_media_player_can_pause
> libvlc_media_player_program_scrambled
> diff --git a/lib/media.c b/lib/media.c
> index 9064d41..cec3b92 100644
> --- a/lib/media.c
> +++ b/lib/media.c
> @@ -660,14 +660,24 @@ libvlc_media_get_duration( libvlc_media_t * p_md )
> return from_mtime(input_item_GetDuration( p_md->p_input_item ));
> }
>
> -static int media_parse(libvlc_media_t *media)
> +static int media_parse(libvlc_media_t *media,
> + libvlc_media_parse_flag_t parse_flag)
> {
> libvlc_int_t *libvlc = media->p_libvlc_instance->p_libvlc_int;
> input_item_t *item = media->p_input_item;
> + input_item_meta_request_option_t art_scope =
> META_REQUEST_OPTION_NONE;
> + input_item_meta_request_option_t parse_scope =
> META_REQUEST_OPTION_SCOPE_LOCAL;
>
> - /* TODO: Fetch art on need basis. But how not to break
> compatibility? */
> - libvlc_ArtRequest(libvlc, item, META_REQUEST_OPTION_NONE);
> - return libvlc_MetaRequest(libvlc, item, META_REQUEST_OPTION_NONE);
> + if (parse_flag & libvlc_media_fetch_art_local)
> + art_scope |= META_REQUEST_OPTION_SCOPE_LOCAL;
> + if (parse_flag & libvlc_media_fetch_art_network)
> + art_scope |= META_REQUEST_OPTION_SCOPE_NETWORK;
> + if (art_scope != META_REQUEST_OPTION_NONE)
> + libvlc_ArtRequest(libvlc, item, art_scope);
> +
> + if (parse_flag & libvlc_media_parse_network)
> + parse_scope |= META_REQUEST_OPTION_SCOPE_NETWORK;
> + return libvlc_MetaRequest(libvlc, item, parse_scope);
> }
>
> /**************************************************************************
> @@ -676,21 +686,7 @@ static int media_parse(libvlc_media_t *media)
> void
> libvlc_media_parse(libvlc_media_t *media)
> {
> - vlc_mutex_lock(&media->parsed_lock);
> - if (!media->has_asked_preparse)
> - {
> - media->has_asked_preparse = true;
> - vlc_mutex_unlock(&media->parsed_lock);
> -
> - if (media_parse(media))
> - /* Parse failed: do not wait! */
> - return;
> - vlc_mutex_lock(&media->parsed_lock);
> - }
> -
> - while (!media->is_parsed)
> - vlc_cond_wait(&media->parsed_cond, &media->parsed_lock);
> - vlc_mutex_unlock(&media->parsed_lock);
> + libvlc_media_parse2( media, false, libvlc_media_fetch_art_local );
> }
>
> /**************************************************************************
> @@ -699,6 +695,13 @@ libvlc_media_parse(libvlc_media_t *media)
> void
> libvlc_media_parse_async(libvlc_media_t *media)
> {
> + libvlc_media_parse2( media, true, libvlc_media_fetch_art_local );
> +}
> +
> +void
> +libvlc_media_parse2( libvlc_media_t *media, bool b_async,
> + libvlc_media_parse_flag_t parse_flag )
> +{
> bool needed;
>
> vlc_mutex_lock(&media->parsed_lock);
> @@ -707,7 +710,14 @@ libvlc_media_parse_async(libvlc_media_t *media)
> vlc_mutex_unlock(&media->parsed_lock);
>
> if (needed)
> - media_parse(media);
> + media_parse(media, parse_flag);
> + if (!b_async)
> + {
> + vlc_mutex_lock(&media->parsed_lock);
> + while (!media->is_parsed)
> + vlc_cond_wait(&media->parsed_cond, &media->parsed_lock);
> + vlc_mutex_unlock(&media->parsed_lock);
> + }
> }
>
> /**************************************************************************
> --
> 2.1.3
>
More information about the vlc-devel
mailing list