/**
* 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
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.
*
/**************************************************************************
* 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);
}
/**************************************************************************
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;
}
}
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
return from_mtime(input_item_GetDuration( p_md->p_input_item ));
}
+/**************************************************************************
+ * 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.
**************************************************************************/