[vlc-devel] [PATCH 4/7] libvlc: add libvlc_media_parse_with_options
Thomas Guillem
thomas at gllm.fr
Thu Jan 15 16:24:38 CET 2015
Extended version of libvlc_media_parse_async. It uses a flag to specify parse
options and returns an int for error handling.
---
include/vlc/libvlc_media.h | 40 +++++++++++++++++++++--
lib/libvlc.sym | 1 +
lib/media.c | 79 +++++++++++++++++++++++++++++-----------------
3 files changed, 89 insertions(+), 31 deletions(-)
diff --git a/include/vlc/libvlc_media.h b/include/vlc/libvlc_media.h
index d3fb9f5..74a3e92 100644
--- a/include/vlc/libvlc_media.h
+++ b/include/vlc/libvlc_media.h
@@ -223,6 +223,12 @@ 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 +491,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 +506,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 +524,36 @@ LIBVLC_API void
libvlc_media_parse_async( libvlc_media_t *p_md );
/**
+ * Parse the media asynchronously with options.
+ *
+ * This fetches (local or network) art, meta data and/or tracks information.
+ * This method is the extended version of libvlc_media_parse_async().
+ *
+ * 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_tracks_get
+ * \see libvlc_media_parse_flag_t
+ *
+ * \param p_md media descriptor object
+ * \param parse_flag parse options:
+ * \return -1 in case of error, 0 otherwise
+ * \version LibVLC 3.0.0 or later
+ */
+LIBVLC_API int
+libvlc_media_parse_with_options( libvlc_media_t *p_md,
+ 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 494097e..551e3b2 100644
--- a/lib/libvlc.sym
+++ b/lib/libvlc.sym
@@ -136,6 +136,7 @@ libvlc_media_new_as_node
libvlc_media_new_from_input_item
libvlc_media_parse
libvlc_media_parse_async
+libvlc_media_parse_with_options
libvlc_media_player_can_pause
libvlc_media_player_program_scrambled
libvlc_media_player_next_frame
diff --git a/lib/media.c b/lib/media.c
index 9790989..bfed267 100644
--- a/lib/media.c
+++ b/lib/media.c
@@ -660,14 +660,47 @@ 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, bool b_async,
+ 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;
+ bool needed;
+
+ vlc_mutex_lock(&media->parsed_lock);
+ needed = !media->has_asked_preparse;
+ media->has_asked_preparse = true;
+ vlc_mutex_unlock(&media->parsed_lock);
+
+ if (needed) {
+ 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;
+ int ret;
+
+ 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) {
+ ret = libvlc_ArtRequest(libvlc, item, art_scope);
+ if (ret != VLC_SUCCESS)
+ return ret;
+ }
- /* 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_parse_network)
+ parse_scope |= META_REQUEST_OPTION_SCOPE_NETWORK;
+ ret = libvlc_MetaRequest(libvlc, item, parse_scope);
+ if (ret != VLC_SUCCESS)
+ return ret;
+ }
+ 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);
+ }
+ return VLC_SUCCESS;
}
/**************************************************************************
@@ -676,21 +709,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);
+ media_parse( media, false, libvlc_media_fetch_art_local );
}
/**************************************************************************
@@ -699,15 +718,17 @@ libvlc_media_parse(libvlc_media_t *media)
void
libvlc_media_parse_async(libvlc_media_t *media)
{
- bool needed;
-
- vlc_mutex_lock(&media->parsed_lock);
- needed = !media->has_asked_preparse;
- media->has_asked_preparse = true;
- vlc_mutex_unlock(&media->parsed_lock);
+ media_parse( media, true, libvlc_media_fetch_art_local );
+}
- if (needed)
- media_parse(media);
+/**************************************************************************
+ * Parse the media asynchronously with options.
+ **************************************************************************/
+int
+libvlc_media_parse_with_options( libvlc_media_t *media,
+ libvlc_media_parse_flag_t parse_flag )
+{
+ return media_parse( media, true, parse_flag ) == VLC_SUCCESS ? 0 : -1;
}
/**************************************************************************
--
2.1.3
More information about the vlc-devel
mailing list