X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fcontrol%2Fmedia.c;h=6f853f8e62a84d0ad4a33dc0e50b0332d010451e;hb=120e7e6b9b99f3604b0ac70c28ded9e97f48a69d;hp=38326bcf3c48c37606baa94ed74f55ab154e4a1b;hpb=bf1292e44390c6469483cea3817d6c2a3dbd811c;p=vlc diff --git a/src/control/media.c b/src/control/media.c index 38326bcf3c..6f853f8e62 100644 --- a/src/control/media.c +++ b/src/control/media.c @@ -21,14 +21,24 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include "libvlc_internal.h" +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif #include +#include +#include // For the subitems, here for convenience +#include + +#include #include #include +#include /* For the preparser */ -/* For the preparser */ -#include +#include "libvlc.h" + +#include "libvlc_internal.h" +#include "media_internal.h" static const vlc_meta_type_t libvlc_to_vlc_meta[] = { @@ -98,7 +108,7 @@ static void input_item_subitem_added( const vlc_event_t *p_event, } /* Construct the event */ - event.type = libvlc_MediaDescriptorSubItemAdded; + event.type = libvlc_MediaSubItemAdded; event.u.media_subitem_added.new_child = p_md_child; /* Send the event */ @@ -116,7 +126,7 @@ static void input_item_meta_changed( const vlc_event_t *p_event, libvlc_event_t event; /* Construct the event */ - event.type = libvlc_MediaDescriptorMetaChanged; + event.type = libvlc_MediaMetaChanged; event.u.media_meta_changed.meta_type = vlc_to_libvlc_meta[p_event->u.input_item_meta_changed.meta_type]; @@ -134,7 +144,7 @@ static void input_item_duration_changed( const vlc_event_t *p_event, libvlc_event_t event; /* Construct the event */ - event.type = libvlc_MediaDescriptorDurationChanged; + event.type = libvlc_MediaDurationChanged; event.u.media_duration_changed.new_duration = p_event->u.input_item_duration_changed.new_duration; @@ -152,7 +162,7 @@ static void input_item_preparsed_changed( const vlc_event_t *p_event, libvlc_event_t event; /* Construct the event */ - event.type = libvlc_MediaDescriptorPreparsedChanged; + event.type = libvlc_MediaPreparsedChanged; event.u.media_preparsed_changed.new_status = p_event->u.input_item_preparsed_changed.new_status; @@ -215,9 +225,9 @@ static void preparse_if_needed( libvlc_media_t *p_md ) if (!p_md->b_preparsed) { playlist_PreparseEnqueue( - p_md->p_libvlc_instance->p_libvlc_int->p_playlist, - p_md->p_input_item ); - p_md->b_preparsed = VLC_TRUE; + libvlc_priv (p_md->p_libvlc_instance->p_libvlc_int)->p_playlist, + p_md->p_input_item, pl_Unlocked ); + p_md->b_preparsed = true; } } @@ -240,9 +250,15 @@ libvlc_media_t * libvlc_media_new_from_input_item( } p_md = malloc( sizeof(libvlc_media_t) ); + if( !p_md ) + { + libvlc_exception_raise( p_e, "Not enough memory" ); + return NULL; + } + p_md->p_libvlc_instance = p_instance; p_md->p_input_item = p_input_item; - p_md->b_preparsed = VLC_FALSE; + p_md->b_preparsed = false; p_md->i_refcount = 1; p_md->p_user_data = NULL; @@ -254,15 +270,15 @@ libvlc_media_t * libvlc_media_new_from_input_item( p_md->p_event_manager = libvlc_event_manager_new( p_md, p_instance, p_e ); libvlc_event_manager_register_event_type( p_md->p_event_manager, - libvlc_MediaDescriptorMetaChanged, p_e ); + libvlc_MediaMetaChanged, p_e ); libvlc_event_manager_register_event_type( p_md->p_event_manager, - libvlc_MediaDescriptorSubItemAdded, p_e ); + libvlc_MediaSubItemAdded, p_e ); libvlc_event_manager_register_event_type( p_md->p_event_manager, - libvlc_MediaDescriptorFreed, p_e ); + libvlc_MediaFreed, p_e ); libvlc_event_manager_register_event_type( p_md->p_event_manager, - libvlc_MediaDescriptorDurationChanged, p_e ); + libvlc_MediaDurationChanged, p_e ); libvlc_event_manager_register_event_type( p_md->p_event_manager, - libvlc_MediaDescriptorStateChanged, p_e ); + libvlc_MediaStateChanged, p_e ); vlc_gc_incref( p_md->p_input_item ); @@ -282,7 +298,7 @@ libvlc_media_t * libvlc_media_new( input_item_t * p_input_item; libvlc_media_t * p_md; - p_input_item = input_ItemNew( p_instance->p_libvlc_int, psz_mrl, NULL ); + p_input_item = input_item_New( p_instance->p_libvlc_int, psz_mrl, NULL ); if (!p_input_item) { @@ -295,7 +311,7 @@ libvlc_media_t * libvlc_media_new( /* The p_input_item is retained in libvlc_media_new_from_input_item */ vlc_gc_decref( p_input_item ); - + return p_md; } @@ -310,7 +326,7 @@ libvlc_media_t * libvlc_media_new_as_node( input_item_t * p_input_item; libvlc_media_t * p_md; - p_input_item = input_ItemNew( p_instance->p_libvlc_int, "vlc://nop", psz_name ); + p_input_item = input_item_New( p_instance->p_libvlc_int, "vlc://nop", psz_name ); if (!p_input_item) { @@ -335,13 +351,27 @@ 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, + libvlc_exception_t *p_e ) +{ + VLC_UNUSED(p_e); + input_item_AddOption( p_md->p_input_item, 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, const char * ppsz_option, + libvlc_media_option_t i_flags, libvlc_exception_t *p_e ) { - (void)p_e; - input_ItemAddOpt( p_md->p_input_item, ppsz_option, - VLC_INPUT_OPTION_UNIQUE|VLC_INPUT_OPTION_TRUSTED ); + VLC_UNUSED(p_e); + input_item_AddOption( p_md->p_input_item, ppsz_option, + i_flags ); } /************************************************************************** @@ -365,7 +395,7 @@ void libvlc_media_release( libvlc_media_t *p_md ) /* Construct the event */ libvlc_event_t event; - event.type = libvlc_MediaDescriptorFreed; + event.type = libvlc_MediaFreed; event.u.media_freed.md = p_md; /* Send the event */ @@ -398,13 +428,13 @@ libvlc_media_duplicate( libvlc_media_t *p_md_orig ) } /************************************************************************** - * Retain a media descriptor object + * Get mrl from a media descriptor object **************************************************************************/ char * libvlc_media_get_mrl( libvlc_media_t * p_md, libvlc_exception_t * p_e ) { - (void)p_e; + VLC_UNUSED(p_e); return input_item_GetURI( p_md->p_input_item ); } @@ -416,9 +446,8 @@ char * libvlc_media_get_meta( libvlc_media_t *p_md, libvlc_meta_t e_meta, libvlc_exception_t *p_e ) { - VLC_UNUSED(p_e); - char * psz_meta; + VLC_UNUSED(p_e); /* XXX: locking */ @@ -426,12 +455,12 @@ char * libvlc_media_get_meta( libvlc_media_t *p_md, psz_meta = input_item_GetMeta( p_md->p_input_item, libvlc_to_vlc_meta[e_meta] ); - + if( e_meta == libvlc_meta_ArtworkURL && !psz_meta ) { playlist_AskForArtEnqueue( - p_md->p_libvlc_instance->p_libvlc_int->p_playlist, - p_md->p_input_item ); + libvlc_priv(p_md->p_libvlc_instance->p_libvlc_int)->p_playlist, + p_md->p_input_item, pl_Unlocked ); } /* Should be integrated in core */ @@ -453,7 +482,7 @@ libvlc_state_t libvlc_media_get_state( libvlc_media_t *p_md, libvlc_exception_t *p_e ) { - (void)p_e; + VLC_UNUSED(p_e); return p_md->state; } @@ -466,13 +495,13 @@ libvlc_media_set_state( libvlc_media_t *p_md, libvlc_state_t state, libvlc_exception_t *p_e ) { - (void)p_e; libvlc_event_t event; + VLC_UNUSED(p_e); p_md->state = state; /* Construct the event */ - event.type = libvlc_MediaDescriptorStateChanged; + event.type = libvlc_MediaStateChanged; event.u.media_state_changed.new_state = state; /* Send the event */ @@ -506,22 +535,21 @@ libvlc_media_event_manager( libvlc_media_t * p_md, } /************************************************************************** - * Get duration of media object. + * Get duration of media object (in ms) **************************************************************************/ -vlc_int64_t +int64_t libvlc_media_get_duration( libvlc_media_t * p_md, libvlc_exception_t * p_e ) { VLC_UNUSED(p_e); - if( p_md && p_md->p_input_item) - { - return input_item_GetDuration( p_md->p_input_item ); - } - else + if( !p_md || !p_md->p_input_item) { + libvlc_exception_raise( p_e, "No input item" ); return -1; } + + return input_item_GetDuration( p_md->p_input_item ) / 1000; } /************************************************************************** @@ -533,14 +561,13 @@ libvlc_media_is_preparsed( libvlc_media_t * p_md, { VLC_UNUSED(p_e); - if( p_md && p_md->p_input_item) - { - return input_item_IsPreparsed( p_md->p_input_item ); - } - else + if( !p_md || !p_md->p_input_item) { - return VLC_FALSE; + libvlc_exception_raise( p_e, "No input item" ); + return false; } + + return input_item_IsPreparsed( p_md->p_input_item ); } /************************************************************************** @@ -571,14 +598,5 @@ libvlc_media_get_user_data( libvlc_media_t * p_md, libvlc_exception_t * p_e ) { VLC_UNUSED(p_e); - - if( p_md ) - { - return p_md->p_user_data; - } - else - { - return NULL; - } + return p_md ? p_md->p_user_data : NULL; } -