[vlc-devel] commit: libvlc: Export libvlc_media_parse() and libvlc_media_parse_async(). (Pierre d'Herbemont )
git version control
git at videolan.org
Mon Feb 22 18:36:14 CET 2010
vlc | branch: master | Pierre d'Herbemont <pdherbemont at free.fr> | Mon Feb 22 17:23:14 2010 +0100| [8119b3280c178fc00eba57eea5ad694cd675fca6] | committer: Pierre d'Herbemont
libvlc: Export libvlc_media_parse() and libvlc_media_parse_async().
Else there is no way to properly trigger meta preparsing from libvlc.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8119b3280c178fc00eba57eea5ad694cd675fca6
---
include/vlc/libvlc_media.h | 45 ++++++++++++++++++++++++++++++++++++++++++
src/control/media.c | 45 ++++++++++++++++++++++++++++++++++++-----
src/control/media_internal.h | 7 +++++-
src/libvlc.sym | 2 +
4 files changed, 92 insertions(+), 7 deletions(-)
diff --git a/include/vlc/libvlc_media.h b/include/vlc/libvlc_media.h
index ffe98ec..0468940 100644
--- a/include/vlc/libvlc_media.h
+++ b/include/vlc/libvlc_media.h
@@ -278,6 +278,16 @@ VLC_PUBLIC_API libvlc_media_t * libvlc_media_duplicate( libvlc_media_t *p_md );
/**
* Read the meta of the media.
*
+ * If the media has not yet been parsed this will return NULL.
+ *
+ * This methods automatically calls libvlc_media_parse_async(), so after calling
+ * it you may receive a libvlc_MediaMetaChanged event. If you prefer a synchronous
+ * version ensure that you call libvlc_media_parse() before get_meta().
+ *
+ * \see libvlc_media_parse
+ * \see libvlc_media_parse_async
+ * \see libvlc_MediaMetaChanged
+ *
* \param p_md the media descriptor
* \param e_meta the meta to read
* \return the media's meta
@@ -368,6 +378,41 @@ VLC_PUBLIC_API libvlc_time_t
libvlc_media_get_duration( libvlc_media_t * p_md );
/**
+ * Parse a media.
+ *
+ * This fetches (local) meta data and tracks information.
+ * The method is synchronous.
+ *
+ * \see libvlc_media_parse_async
+ * \see libvlc_media_get_meta
+ * \see libvlc_media_get_es
+ *
+ * \param media media descriptor object
+ */
+VLC_PUBLIC_API void
+libvlc_media_parse(libvlc_media_t *media);
+
+/**
+ * Parse a media.
+ *
+ * This fetches (local) meta data and tracks information.
+ * The method is the asynchronous of libvlc_media_parse_async().
+ *
+ * To track when this is over you can listen to libvlc_MediaPreparsedChanged
+ * event. However if the media was already preparsed you will not receive this
+ * event.
+ *
+ * \see libvlc_media_parse
+ * \see libvlc_MediaPreparsedChanged
+ * \see libvlc_media_get_meta
+ * \see libvlc_media_get_es
+ *
+ * \param media media descriptor object
+ */
+VLC_PUBLIC_API void
+libvlc_media_parse_async(libvlc_media_t *media);
+
+/**
* Get preparsed status for media descriptor object.
*
* \param p_md media descriptor object
diff --git a/src/control/media.c b/src/control/media.c
index 8712961..3313a05 100644
--- a/src/control/media.c
+++ b/src/control/media.c
@@ -158,19 +158,26 @@ static void input_item_duration_changed( const vlc_event_t *p_event,
/**************************************************************************
* input_item_preparsed_changed (Private) (vlc event Callback)
**************************************************************************/
-static void input_item_preparsed_changed( const vlc_event_t *p_event,
- void * user_data )
+static void input_item_preparsed_changed(const vlc_event_t *p_event,
+ void * user_data)
{
- libvlc_media_t * p_md = user_data;
+ libvlc_media_t *media = user_data;
libvlc_event_t event;
+ /* Eventually notify libvlc_media_parse() */
+ vlc_mutex_lock(&media->parsed_lock);
+ media->is_parsed = true;
+ vlc_cond_broadcast(&media->parsed_cond);
+ vlc_mutex_unlock(&media->parsed_lock);
+
+
/* Construct the event */
event.type = libvlc_MediaPreparsedChanged;
event.u.media_preparsed_changed.new_status =
p_event->u.input_item_preparsed_changed.new_status;
/* Send the event */
- libvlc_event_send( p_md->p_event_manager, &event );
+ libvlc_event_send(media->p_event_manager, &event);
}
/**************************************************************************
@@ -225,12 +232,12 @@ static void uninstall_input_item_observer( libvlc_media_t *p_md )
static void preparse_if_needed( libvlc_media_t *p_md )
{
/* XXX: need some locking here */
- if (!p_md->b_preparsed)
+ if (!p_md->has_asked_preparse)
{
playlist_PreparseEnqueue(
libvlc_priv (p_md->p_libvlc_instance->p_libvlc_int)->p_playlist,
p_md->p_input_item );
- p_md->b_preparsed = true;
+ p_md->has_asked_preparse = true;
}
}
@@ -262,6 +269,9 @@ libvlc_media_t * libvlc_media_new_from_input_item(
p_md->p_input_item = p_input_item;
p_md->i_refcount = 1;
+ vlc_cond_init(&p_md->parsed_cond);
+ vlc_mutex_init(&p_md->parsed_lock);
+
p_md->state = libvlc_NothingSpecial;
/* A media descriptor can be a playlist. When you open a playlist
@@ -608,6 +618,29 @@ libvlc_media_get_duration( libvlc_media_t * p_md )
}
/**************************************************************************
+ * Parse the media.
+ **************************************************************************/
+void
+libvlc_media_parse(libvlc_media_t *media)
+{
+ preparse_if_needed(media);
+
+ 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);
+}
+
+/**************************************************************************
+ * Parse the media.
+ **************************************************************************/
+void
+libvlc_media_parse_async(libvlc_media_t *media)
+{
+ preparse_if_needed(media);
+}
+
+/**************************************************************************
* Get preparsed status for media object.
**************************************************************************/
int
diff --git a/src/control/media_internal.h b/src/control/media_internal.h
index c8f057f..cd1c42a 100644
--- a/src/control/media_internal.h
+++ b/src/control/media_internal.h
@@ -34,13 +34,18 @@
struct libvlc_media_t
{
libvlc_event_manager_t * p_event_manager;
- int b_preparsed;
input_item_t *p_input_item;
int i_refcount;
libvlc_instance_t *p_libvlc_instance;
libvlc_state_t state;
VLC_FORWARD_DECLARE_OBJECT(libvlc_media_list_t*) p_subitems; /* A media descriptor can have Sub items. This is the only dependancy we really have on media_list */
void *p_user_data;
+
+ vlc_cond_t parsed_cond;
+ vlc_mutex_t parsed_lock;
+
+ bool is_parsed;
+ bool has_asked_preparse;
bool has_asked_art;
};
diff --git a/src/libvlc.sym b/src/libvlc.sym
index b38ec01..369f49c 100644
--- a/src/libvlc.sym
+++ b/src/libvlc.sym
@@ -102,6 +102,8 @@ libvlc_media_new_location
libvlc_media_new_path
libvlc_media_new_as_node
libvlc_media_new_from_input_item
+libvlc_media_parse
+libvlc_media_parse_async
libvlc_media_player_can_pause
libvlc_media_player_next_frame
libvlc_media_player_event_manager
More information about the vlc-devel
mailing list