Skip to content

Commit

Permalink
libvlc_media_new_path: create a media from a file path
Browse files Browse the repository at this point in the history
Also rename libvlc_media_new to libvlc_media_new_location to remove
the ambiguity.
  • Loading branch information
Rémi Denis-Courmont committed Feb 18, 2010
1 parent 501f845 commit 7eccf3a
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 30 deletions.
4 changes: 2 additions & 2 deletions bindings/mediacontrol/mediacontrol_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );
Expand Down
15 changes: 13 additions & 2 deletions include/vlc/libvlc_media.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion projects/activex/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion projects/macosx/framework/Sources/VLCMedia.m
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ - (id)initWithURL:(NSURL *)anURL
{
if (self = [super init])
{
p_md = libvlc_media_new([VLCLibrary sharedInstance],
p_md = libvlc_media_new_location([VLCLibrary sharedInstance],
[[anURL absoluteString] UTF8String]);

delegate = nil;
Expand Down
4 changes: 2 additions & 2 deletions projects/mozilla/vlcplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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;

Expand Down
20 changes: 18 additions & 2 deletions src/control/media.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <vlc_input.h>
#include <vlc_meta.h>
#include <vlc_playlist.h> /* For the preparser */
#include <vlc_url.h>

#include "libvlc.h"

Expand Down Expand Up @@ -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;
Expand All @@ -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
**************************************************************************/
Expand Down
3 changes: 2 additions & 1 deletion src/libvlc.sym
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/libvlc/libvlc_additions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions test/libvlc/media_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 */
Expand Down
20 changes: 10 additions & 10 deletions test/libvlc/media_list_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions test/libvlc/media_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/libvlc/meta.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7eccf3a

Please sign in to comment.