X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fcontrol%2Fmedia.c;h=3f39841bd785178383c386cbd6a5f11e6156e822;hb=58b5d4a15ba661d7ef7046d9f64a5df688397274;hp=e97c4164939c38f37c0dce983cbcef5d6eb4aa9a;hpb=b7e0d3cc4874d66dd0b2db433caa620664345eac;p=vlc diff --git a/src/control/media.c b/src/control/media.c index e97c416493..3f39841bd7 100644 --- a/src/control/media.c +++ b/src/control/media.c @@ -36,6 +36,7 @@ #include #include #include /* For the preparser */ +#include #include "libvlc.h" @@ -96,7 +97,7 @@ static void input_item_subitem_added( const vlc_event_t *p_event, p_md_child = libvlc_media_new_from_input_item( p_md->p_libvlc_instance, - p_event->u.input_item_subitem_added.p_new_child, NULL ); + p_event->u.input_item_subitem_added.p_new_child ); /* Add this to our media list */ if( !p_md->p_subitems ) @@ -106,7 +107,7 @@ static void input_item_subitem_added( const vlc_event_t *p_event, } if( p_md->p_subitems ) { - libvlc_media_list_add_media( p_md->p_subitems, p_md_child, NULL ); + libvlc_media_list_add_media( p_md->p_subitems, p_md_child ); } /* Construct the event */ @@ -157,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 = + event.type = libvlc_MediaParsedChanged; + event.u.media_parsed_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); } /************************************************************************** @@ -224,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, pl_Unlocked ); - p_md->b_preparsed = true; + p_md->p_input_item ); + p_md->has_asked_preparse = true; } } @@ -240,14 +248,12 @@ static void preparse_if_needed( libvlc_media_t *p_md ) **************************************************************************/ libvlc_media_t * libvlc_media_new_from_input_item( libvlc_instance_t *p_instance, - input_item_t *p_input_item, - libvlc_exception_t *p_e ) + input_item_t *p_input_item ) { libvlc_media_t * p_md; if (!p_input_item) { - libvlc_exception_raise( p_e ); libvlc_printerr( "No input item given" ); return NULL; } @@ -255,7 +261,6 @@ libvlc_media_t * libvlc_media_new_from_input_item( p_md = calloc( 1, sizeof(libvlc_media_t) ); if( !p_md ) { - libvlc_exception_raise( p_e ); libvlc_printerr( "Not enough memory" ); return NULL; } @@ -264,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 @@ -276,16 +284,14 @@ libvlc_media_t * libvlc_media_new_from_input_item( free(p_md); return NULL; } - libvlc_event_manager_register_event_type( p_md->p_event_manager, - libvlc_MediaMetaChanged ); - libvlc_event_manager_register_event_type( p_md->p_event_manager, - libvlc_MediaSubItemAdded ); - libvlc_event_manager_register_event_type( p_md->p_event_manager, - libvlc_MediaFreed ); - libvlc_event_manager_register_event_type( p_md->p_event_manager, - libvlc_MediaDurationChanged ); - libvlc_event_manager_register_event_type( p_md->p_event_manager, - libvlc_MediaStateChanged ); + + libvlc_event_manager_t *em = p_md->p_event_manager; + libvlc_event_manager_register_event_type(em, libvlc_MediaMetaChanged); + libvlc_event_manager_register_event_type(em, libvlc_MediaSubItemAdded); + libvlc_event_manager_register_event_type(em, libvlc_MediaFreed); + libvlc_event_manager_register_event_type(em, libvlc_MediaDurationChanged); + libvlc_event_manager_register_event_type(em, libvlc_MediaStateChanged); + libvlc_event_manager_register_event_type(em, libvlc_MediaParsedChanged); vlc_gc_incref( p_md->p_input_item ); @@ -297,10 +303,8 @@ libvlc_media_t * libvlc_media_new_from_input_item( /************************************************************************** * Create a new media descriptor object **************************************************************************/ -libvlc_media_t * libvlc_media_new( - libvlc_instance_t *p_instance, - const char * psz_mrl, - libvlc_exception_t *p_e ) +libvlc_media_t *libvlc_media_new_location( libvlc_instance_t *p_instance, + const char * psz_mrl ) { input_item_t * p_input_item; libvlc_media_t * p_md; @@ -309,13 +313,11 @@ libvlc_media_t * libvlc_media_new( if (!p_input_item) { - libvlc_exception_raise( p_e ); libvlc_printerr( "Not enough memory" ); return NULL; } - p_md = libvlc_media_new_from_input_item( p_instance, - p_input_item, p_e ); + p_md = libvlc_media_new_from_input_item( p_instance, p_input_item ); /* The p_input_item is retained in libvlc_media_new_from_input_item */ vlc_gc_decref( p_input_item ); @@ -323,13 +325,26 @@ libvlc_media_t * libvlc_media_new( return p_md; } +libvlc_media_t *libvlc_media_new_path( libvlc_instance_t *p_instance, + const char *path ) +{ + char *mrl = make_URI( path, "file" ); + if( unlikely(mrl == NULL) ) + { + libvlc_printerr( "Not enough memory" ); + return NULL; + } + + libvlc_media_t *m = libvlc_media_new_location( p_instance, mrl ); + free( mrl ); + return m; +} + /************************************************************************** * Create a new media descriptor object **************************************************************************/ -libvlc_media_t * libvlc_media_new_as_node( - libvlc_instance_t *p_instance, - const char * psz_name, - libvlc_exception_t *p_e ) +libvlc_media_t * libvlc_media_new_as_node( libvlc_instance_t *p_instance, + const char * psz_name ) { input_item_t * p_input_item; libvlc_media_t * p_md; @@ -338,13 +353,11 @@ libvlc_media_t * libvlc_media_new_as_node( if (!p_input_item) { - libvlc_exception_raise( p_e ); libvlc_printerr( "Not enough memory" ); return NULL; } - p_md = libvlc_media_new_from_input_item( p_instance, - p_input_item, p_e ); + p_md = libvlc_media_new_from_input_item( p_instance, p_input_item ); p_md->p_subitems = libvlc_media_list_new( p_md->p_libvlc_instance ); @@ -359,24 +372,21 @@ libvlc_media_t * libvlc_media_new_as_node( * * The options are detailled in vlc --long-help, for instance "--sout-all" **************************************************************************/ -void libvlc_media_add_option( - libvlc_media_t * p_md, - const char * psz_option ) +void libvlc_media_add_option( libvlc_media_t * p_md, + const char * psz_option ) { - input_item_AddOption( p_md->p_input_item, psz_option, + libvlc_media_add_option_flag( p_md, psz_option, VLC_INPUT_OPTION_UNIQUE|VLC_INPUT_OPTION_TRUSTED ); } /************************************************************************** * Same as libvlc_media_add_option but with configurable flags. **************************************************************************/ -void libvlc_media_add_option_flag( - libvlc_media_t * p_md, +void libvlc_media_add_option_flag( libvlc_media_t * p_md, const char * ppsz_option, - libvlc_media_option_t i_flags ) + unsigned i_flags ) { - input_item_AddOption( p_md->p_input_item, ppsz_option, - i_flags ); + input_item_AddOption( p_md->p_input_item, ppsz_option, i_flags ); } /************************************************************************** @@ -398,6 +408,9 @@ void libvlc_media_release( libvlc_media_t *p_md ) uninstall_input_item_observer( p_md ); vlc_gc_decref( p_md->p_input_item ); + vlc_cond_destroy( &p_md->parsed_cond ); + vlc_mutex_destroy( &p_md->parsed_lock ); + /* Construct the event */ libvlc_event_t event; event.type = libvlc_MediaFreed; @@ -427,7 +440,7 @@ libvlc_media_t * libvlc_media_duplicate( libvlc_media_t *p_md_orig ) { return libvlc_media_new_from_input_item( - p_md_orig->p_libvlc_instance, p_md_orig->p_input_item, NULL ); + p_md_orig->p_libvlc_instance, p_md_orig->p_input_item ); } /************************************************************************** @@ -461,7 +474,7 @@ char *libvlc_media_get_meta( libvlc_media_t *p_md, libvlc_meta_t e_meta ) p_md->has_asked_art = true; playlist_AskForArtEnqueue( libvlc_priv(p_md->p_libvlc_instance->p_libvlc_int)->p_playlist, - p_md->p_input_item, pl_Unlocked ); + p_md->p_input_item ); } /* Should be integrated in core */ @@ -585,13 +598,12 @@ libvlc_media_event_manager( libvlc_media_t * p_md ) * Get duration of media object (in ms) **************************************************************************/ int64_t -libvlc_media_get_duration( libvlc_media_t * p_md, libvlc_exception_t *p_e ) +libvlc_media_get_duration( libvlc_media_t * p_md ) { assert( p_md ); if( !p_md->p_input_item ) { - libvlc_exception_raise( p_e ); libvlc_printerr( "No input item" ); return -1; } @@ -605,10 +617,33 @@ libvlc_media_get_duration( libvlc_media_t * p_md, libvlc_exception_t *p_e ) } /************************************************************************** - * Get preparsed status for media object. + * 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 parsed status for media object. **************************************************************************/ int -libvlc_media_is_preparsed( libvlc_media_t * p_md ) +libvlc_media_is_parsed( libvlc_media_t * p_md ) { assert( p_md ); @@ -619,11 +654,11 @@ libvlc_media_is_preparsed( libvlc_media_t * p_md ) } /************************************************************************** - * Sets media descriptor's user_data. user_data is specialized data - * accessed by the host application, VLC.framework uses it as a pointer to + * Sets media descriptor's user_data. user_data is specialized data + * accessed by the host application, VLC.framework uses it as a pointer to * an native object that references a libvlc_media_t pointer **************************************************************************/ -void +void libvlc_media_set_user_data( libvlc_media_t * p_md, void * p_new_user_data ) { assert( p_md ); @@ -631,8 +666,8 @@ libvlc_media_set_user_data( libvlc_media_t * p_md, void * p_new_user_data ) } /************************************************************************** - * Get media descriptor's user_data. user_data is specialized data - * accessed by the host application, VLC.framework uses it as a pointer to + * Get media descriptor's user_data. user_data is specialized data + * accessed by the host application, VLC.framework uses it as a pointer to * an native object that references a libvlc_media_t pointer **************************************************************************/ void * @@ -646,7 +681,7 @@ libvlc_media_get_user_data( libvlc_media_t * p_md ) * Get media descriptor's elementary streams description **************************************************************************/ int -libvlc_media_get_es( libvlc_media_t *p_md, libvlc_media_es_t ** pp_es ) +libvlc_media_get_tracks_info( libvlc_media_t *p_md, libvlc_media_track_info_t ** pp_es ) { assert( p_md ); @@ -654,7 +689,7 @@ libvlc_media_get_es( libvlc_media_t *p_md, libvlc_media_es_t ** pp_es ) vlc_mutex_lock( &p_input_item->lock ); const int i_es = p_input_item->i_es; - *pp_es = (i_es > 0) ? malloc( i_es * sizeof(libvlc_media_es_t) ) : NULL; + *pp_es = (i_es > 0) ? malloc( i_es * sizeof(libvlc_media_track_info_t) ) : NULL; if( !pp_es ) /* no ES, or OOM */ { @@ -665,13 +700,9 @@ libvlc_media_get_es( libvlc_media_t *p_md, libvlc_media_es_t ** pp_es ) /* Fill array */ for( int i = 0; i < i_es; i++ ) { - libvlc_media_es_t *p_mes = *pp_es+i; + libvlc_media_track_info_t *p_mes = *pp_es+i; const es_format_t *p_es = p_input_item->es[i]; - p_mes->i_channels = p_mes->i_rate = 0; - p_mes->i_width = p_mes->i_height = 0; - - p_mes->i_codec = p_es->i_codec; p_mes->i_id = p_es->i_id; @@ -682,20 +713,20 @@ libvlc_media_get_es( libvlc_media_t *p_md, libvlc_media_es_t ** pp_es ) { case UNKNOWN_ES: default: - p_mes->i_type = libvlc_es_unknown; + p_mes->i_type = libvlc_track_unknown; break; case VIDEO_ES: - p_mes->i_type = libvlc_es_video; - p_mes->i_height = p_es->video.i_height; - p_mes->i_width = p_es->video.i_width; + p_mes->i_type = libvlc_track_video; + p_mes->u.video.i_height = p_es->video.i_height; + p_mes->u.video.i_width = p_es->video.i_width; break; case AUDIO_ES: - p_mes->i_type = libvlc_es_audio; - p_mes->i_channels = p_es->audio.i_channels; - p_mes->i_rate = p_es->audio.i_rate; + p_mes->i_type = libvlc_track_audio; + p_mes->u.audio.i_channels = p_es->audio.i_channels; + p_mes->u.audio.i_rate = p_es->audio.i_rate; break; case SPU_ES: - p_mes->i_type = libvlc_es_text; + p_mes->i_type = libvlc_track_text; break; } }