From 7eccf3a2cf7bdf158f58b8f4ef006ad604738c0b Mon Sep 17 00:00:00 2001 From: =?utf8?q?R=C3=A9mi=20Denis-Courmont?= Date: Thu, 18 Feb 2010 19:56:15 +0200 Subject: [PATCH] libvlc_media_new_path: create a media from a file path Also rename libvlc_media_new to libvlc_media_new_location to remove the ambiguity. --- bindings/mediacontrol/mediacontrol_core.c | 4 ++-- include/vlc/libvlc_media.h | 15 +++++++++++++-- projects/activex/plugin.cpp | 2 +- projects/macosx/framework/Sources/VLCMedia.m | 2 +- projects/mozilla/vlcplugin.cpp | 4 ++-- src/control/media.c | 20 ++++++++++++++++++-- src/libvlc.sym | 3 ++- test/libvlc/libvlc_additions.h | 2 +- test/libvlc/media_list.c | 8 ++++---- test/libvlc/media_list_player.c | 20 ++++++++++---------- test/libvlc/media_player.c | 6 +++--- test/libvlc/meta.c | 2 +- 12 files changed, 58 insertions(+), 30 deletions(-) diff --git a/bindings/mediacontrol/mediacontrol_core.c b/bindings/mediacontrol/mediacontrol_core.c index f721ec8745..d52d8cd801 100644 --- a/bindings/mediacontrol/mediacontrol_core.c +++ b/bindings/mediacontrol/mediacontrol_core.c @@ -196,7 +196,7 @@ mediacontrol_start( mediacontrol_Instance *self, HANDLE_LIBVLC_EXCEPTION_VOID( &ex ); /* Create a new media */ - p_media = libvlc_media_new( self->p_instance, psz_name, &ex ); + p_media = libvlc_media_new_location( self->p_instance, psz_name, &ex ); HANDLE_LIBVLC_EXCEPTION_VOID( &ex ); if( a_position->value ) @@ -257,7 +257,7 @@ mediacontrol_set_mrl( mediacontrol_Instance *self, mediacontrol_exception_init( exception ); libvlc_exception_init( &ex ); - p_media = libvlc_media_new( self->p_instance, psz_file, &ex ); + p_media = libvlc_media_new_location( self->p_instance, psz_file, &ex ); HANDLE_LIBVLC_EXCEPTION_VOID( &ex ); libvlc_media_player_set_media( self->p_media_player, p_media ); diff --git a/include/vlc/libvlc_media.h b/include/vlc/libvlc_media.h index 409a521372..a2222864c9 100644 --- a/include/vlc/libvlc_media.h +++ b/include/vlc/libvlc_media.h @@ -170,16 +170,27 @@ typedef struct libvlc_media_es_t /** - * Create a media with the given MRL. + * Create a media with a certain given media resource location. * * \param p_instance the instance * \param psz_mrl the MRL to read * \return the newly created media or NULL on error */ -VLC_PUBLIC_API libvlc_media_t * libvlc_media_new( +VLC_PUBLIC_API libvlc_media_t *libvlc_media_new_location( libvlc_instance_t *p_instance, const char * psz_mrl ); +/** + * Create a media with a certain file path. + * + * \param p_instance the instance + * \param path local filesystem path + * \return the newly created media or NULL on error + */ +VLC_PUBLIC_API libvlc_media_t *libvlc_media_new_path( + libvlc_instance_t *p_instance, + const char *path ); + /** * Create a media as an empty node with a given name. * diff --git a/projects/activex/plugin.cpp b/projects/activex/plugin.cpp index 1b3efdd43a..434f582e09 100644 --- a/projects/activex/plugin.cpp +++ b/projects/activex/plugin.cpp @@ -1398,7 +1398,7 @@ void VLCPlugin::player_unregister_events() int VLCPlugin::playlist_add_extended_untrusted(const char *mrl, int optc, const char **optv) { int item = -1; - libvlc_media_t *p_m = libvlc_media_new(_p_libvlc,mrl); + libvlc_media_t *p_m = libvlc_media_new_location(_p_libvlc,mrl); if( !p_m ) return -1; diff --git a/projects/macosx/framework/Sources/VLCMedia.m b/projects/macosx/framework/Sources/VLCMedia.m index 9da8409649..e4cbef9338 100644 --- a/projects/macosx/framework/Sources/VLCMedia.m +++ b/projects/macosx/framework/Sources/VLCMedia.m @@ -177,7 +177,7 @@ static void HandleMediaSubItemAdded(const libvlc_event_t * event, void * self) { if (self = [super init]) { - p_md = libvlc_media_new([VLCLibrary sharedInstance], + p_md = libvlc_media_new_location([VLCLibrary sharedInstance], [[anURL absoluteString] UTF8String]); delegate = nil; diff --git a/projects/mozilla/vlcplugin.cpp b/projects/mozilla/vlcplugin.cpp index c0d7dd1e92..76316d14ea 100644 --- a/projects/mozilla/vlcplugin.cpp +++ b/projects/mozilla/vlcplugin.cpp @@ -452,7 +452,7 @@ void VlcPlugin::set_player_window() int VlcPlugin::playlist_add( const char *mrl ) { int item = -1; - libvlc_media_t *p_m = libvlc_media_new(libvlc_instance,mrl); + libvlc_media_t *p_m = libvlc_media_new_location(libvlc_instance,mrl); if( !p_m ) return -1; assert( libvlc_media_list ); @@ -474,7 +474,7 @@ int VlcPlugin::playlist_add_extended_untrusted( const char *mrl, const char *nam assert( libvlc_media_list ); - p_m = libvlc_media_new(libvlc_instance, mrl); + p_m = libvlc_media_new_location(libvlc_instance, mrl); if( !p_m ) return -1; diff --git a/src/control/media.c b/src/control/media.c index 0b6147ef06..bdb0ce310d 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" @@ -294,8 +295,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_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; @@ -316,6 +317,21 @@ libvlc_media_t * libvlc_media_new( libvlc_instance_t *p_instance, return p_md; } +libvlc_media_t *libvlc_media_new_path( libvlc_instance_t *p_instance, + const char *path ) +{ + char *mrl = make_URI( path ); + 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 **************************************************************************/ diff --git a/src/libvlc.sym b/src/libvlc.sym index 6f8820ec87..b38ec01755 100644 --- a/src/libvlc.sym +++ b/src/libvlc.sym @@ -98,7 +98,8 @@ libvlc_media_list_remove_index libvlc_media_list_retain libvlc_media_list_set_media libvlc_media_list_unlock -libvlc_media_new +libvlc_media_new_location +libvlc_media_new_path libvlc_media_new_as_node libvlc_media_new_from_input_item libvlc_media_player_can_pause diff --git a/test/libvlc/libvlc_additions.h b/test/libvlc/libvlc_additions.h index c3f33dd0b2..a81787e4f2 100644 --- a/test/libvlc/libvlc_additions.h +++ b/test/libvlc/libvlc_additions.h @@ -21,7 +21,7 @@ static void* media_list_add_file_path(libvlc_instance_t *vlc, libvlc_media_list_t *ml, const char * file_path) { - libvlc_media_t *md = libvlc_media_new (vlc, file_path); + libvlc_media_t *md = libvlc_media_new_location (vlc, file_path); libvlc_media_list_add_media (ml, md); libvlc_media_release (md); return md; diff --git a/test/libvlc/media_list.c b/test/libvlc/media_list.c index 9d1399c1b2..7eab6b9f48 100644 --- a/test/libvlc/media_list.c +++ b/test/libvlc/media_list.c @@ -38,11 +38,11 @@ static void test_media_list (const char ** argv, int argc) ml = libvlc_media_list_new (vlc); assert (ml != NULL); - md1 = libvlc_media_new (vlc, "/dev/null"); + md1 = libvlc_media_new_path (vlc, "/dev/null"); assert (md1 != NULL); - md2 = libvlc_media_new (vlc, "/dev/null"); + md2 = libvlc_media_new_path (vlc, "/dev/null"); assert (md2 != NULL); - md3 = libvlc_media_new (vlc, "/dev/null"); + md3 = libvlc_media_new_path (vlc, "/dev/null"); assert (md3 != NULL); ret = libvlc_media_list_add_media (ml, md1); @@ -103,7 +103,7 @@ static void test_media_list (const char ** argv, int argc) p_non_exist = libvlc_media_list_item_at_index (ml, -1); assert (p_non_exist == NULL); - md4 = libvlc_media_new (vlc, "/dev/null"); + md4 = libvlc_media_new_path (vlc, "/dev/null"); assert (md4 != NULL); /* try to find non inserted item */ diff --git a/test/libvlc/media_list_player.c b/test/libvlc/media_list_player.c index cebaefc685..36543ebe3a 100644 --- a/test/libvlc/media_list_player.c +++ b/test/libvlc/media_list_player.c @@ -103,7 +103,7 @@ static void test_media_list_player_items_queue(const char** argv, int argc) vlc = libvlc_new (argc, argv); assert (vlc != NULL); - md = libvlc_media_new (vlc, file, &ex); + md = libvlc_media_new_path (vlc, file, &ex); catch (); ml = libvlc_media_list_new (vlc); @@ -173,7 +173,7 @@ static void test_media_list_player_previous(const char** argv, int argc) vlc = libvlc_new (argc, argv); assert (vlc != NULL); - md = libvlc_media_new (vlc, file, &ex); + md = libvlc_media_new_path (vlc, file, &ex); catch (); ml = libvlc_media_list_new (vlc); @@ -249,7 +249,7 @@ static void test_media_list_player_next(const char** argv, int argc) vlc = libvlc_new (argc, argv); assert (vlc != NULL); - md = libvlc_media_new (vlc, file, &ex); + md = libvlc_media_new_path (vlc, file, &ex); catch (); ml = libvlc_media_list_new (vlc); @@ -324,7 +324,7 @@ static void test_media_list_player_pause_stop(const char** argv, int argc) vlc = libvlc_new (argc, argv); assert (vlc != NULL); - md = libvlc_media_new (vlc, file, &ex); + md = libvlc_media_new_path (vlc, file, &ex); catch (); ml = libvlc_media_list_new (vlc); @@ -370,7 +370,7 @@ static void test_media_list_player_play_item_at_index(const char** argv, int arg vlc = libvlc_new (argc, argv, &ex); assert (vlc != NULL); - md = libvlc_media_new (vlc, file, &ex); + md = libvlc_media_new_path (vlc, file, &ex); catch (); ml = libvlc_media_list_new (vlc); @@ -437,19 +437,19 @@ static void test_media_list_player_playback_options (const char** argv, int argc * ml5&6: 0 0 -- 1 */ - md = libvlc_media_new (vlc, file, &ex); + md = libvlc_media_new_path (vlc, file, &ex); catch (); - md2 = libvlc_media_new (vlc, file, &ex); + md2 = libvlc_media_new_path (vlc, file, &ex); catch (); - md3 = libvlc_media_new (vlc, file, &ex); + md3 = libvlc_media_new_path (vlc, file, &ex); catch (); - md4 = libvlc_media_new (vlc, file, &ex); + md4 = libvlc_media_new_path (vlc, file, &ex); catch (); - md5 = libvlc_media_new (vlc, file, &ex); + md5 = libvlc_media_new_path (vlc, file, &ex); catch (); ml = libvlc_media_list_new (vlc); diff --git a/test/libvlc/media_player.c b/test/libvlc/media_player.c index a843b65d57..cba2a90fb2 100644 --- a/test/libvlc/media_player.c +++ b/test/libvlc/media_player.c @@ -32,7 +32,7 @@ static void test_media_player_set_media(const char** argv, int argc) libvlc_instance_t *vlc = libvlc_new (argc, argv); assert (vlc != NULL); - libvlc_media_t *md = libvlc_media_new (vlc, file); + libvlc_media_t *md = libvlc_media_new_path (vlc, file); assert (md != NULL); libvlc_media_player_t *mp = libvlc_media_player_new (vlc); @@ -71,7 +71,7 @@ static void test_media_player_play_stop(const char** argv, int argc) vlc = libvlc_new (argc, argv); assert (vlc != NULL); - md = libvlc_media_new (vlc, file); + md = libvlc_media_new_path (vlc, file); assert (md != NULL); mi = libvlc_media_player_new_from_media (md); @@ -108,7 +108,7 @@ static void test_media_player_pause_stop(const char** argv, int argc) vlc = libvlc_new (argc, argv); assert (vlc != NULL); - md = libvlc_media_new (vlc, file); + md = libvlc_media_new_path (vlc, file); assert (md != NULL); mi = libvlc_media_player_new_from_media (md); diff --git a/test/libvlc/meta.c b/test/libvlc/meta.c index 2b621c054b..690578d7ae 100644 --- a/test/libvlc/meta.c +++ b/test/libvlc/meta.c @@ -37,7 +37,7 @@ static void test_meta (const char ** argv, int argc) vlc = libvlc_new (argc, argv); assert (vlc != NULL); - media = libvlc_media_new (vlc, "samples/meta.sample"); + media = libvlc_media_new_path (vlc, "samples/meta.sample"); assert( media ); /* Tell that we are interested in this precise meta data -- 2.39.2