Commit 34f81612 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

libvlc: Rename input to media_instance. And add the possibility to create a...

libvlc: Rename input to media_instance. And add the possibility to create a medi_instance from a media_descriptor.
parent 0dabfb1d
This diff is collapsed.
...@@ -79,6 +79,19 @@ typedef struct libvlc_media_descriptor_t libvlc_media_descriptor_t; ...@@ -79,6 +79,19 @@ typedef struct libvlc_media_descriptor_t libvlc_media_descriptor_t;
/**@} */ /**@} */
/*****************************************************************************
* Media Instance
*****************************************************************************/
/** defgroup libvlc_media_instance MediaInstance
* \ingroup libvlc
* LibVLC Media Instance handling
* @{
*/
typedef struct libvlc_media_instance_t libvlc_media_instance_t;
/**@} */
/***************************************************************************** /*****************************************************************************
* Playlist * Playlist
......
...@@ -28,33 +28,6 @@ ...@@ -28,33 +28,6 @@
#include <vlc_input.h> #include <vlc_input.h>
#include <vlc_aout.h> #include <vlc_aout.h>
/*
* Remember to release the returned input_thread_t since it is locked at
* the end of this function.
*/
static input_thread_t *GetInput( libvlc_input_t *p_input,
libvlc_exception_t *p_exception )
{
input_thread_t *p_input_thread = NULL;
if( !p_input )
{
libvlc_exception_raise( p_exception, "Input is NULL" );
return NULL;
}
p_input_thread = (input_thread_t*)vlc_object_get(
p_input->p_instance->p_libvlc_int,
p_input->i_input_id );
if( !p_input_thread )
{
libvlc_exception_raise( p_exception, "Input does not exist" );
return NULL;
}
return p_input_thread;
}
/* /*
* Remember to release the returned aout_instance_t since it is locked at * Remember to release the returned aout_instance_t since it is locked at
* the end of this function. * the end of this function.
...@@ -142,10 +115,10 @@ void libvlc_audio_set_volume( libvlc_instance_t *p_instance, int i_volume, ...@@ -142,10 +115,10 @@ void libvlc_audio_set_volume( libvlc_instance_t *p_instance, int i_volume,
/***************************************************************************** /*****************************************************************************
* libvlc_audio_get_track : Get the current audio track * libvlc_audio_get_track : Get the current audio track
*****************************************************************************/ *****************************************************************************/
int libvlc_audio_get_track( libvlc_input_t *p_input, int libvlc_audio_get_track( libvlc_media_instance_t *p_mi,
libvlc_exception_t *p_e ) libvlc_exception_t *p_e )
{ {
input_thread_t *p_input_thread = GetInput( p_input, p_e ); input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
vlc_value_t val_list; vlc_value_t val_list;
vlc_value_t val; vlc_value_t val;
int i_track = -1; int i_track = -1;
...@@ -180,10 +153,10 @@ int libvlc_audio_get_track( libvlc_input_t *p_input, ...@@ -180,10 +153,10 @@ int libvlc_audio_get_track( libvlc_input_t *p_input,
/***************************************************************************** /*****************************************************************************
* libvlc_audio_set_track : Set the current audio track * libvlc_audio_set_track : Set the current audio track
*****************************************************************************/ *****************************************************************************/
void libvlc_audio_set_track( libvlc_input_t *p_input, int i_track, void libvlc_audio_set_track( libvlc_media_instance_t *p_mi, int i_track,
libvlc_exception_t *p_e ) libvlc_exception_t *p_e )
{ {
input_thread_t *p_input_thread = GetInput( p_input, p_e ); input_thread_t *p_input_thread = libvlc_get_input_thread( p_mi, p_e );
vlc_value_t val_list; vlc_value_t val_list;
int i_ret = -1; int i_ret = -1;
int i; int i;
......
...@@ -90,15 +90,17 @@ static int handle_event( vlc_object_t *p_this, char const *psz_cmd, ...@@ -90,15 +90,17 @@ static int handle_event( vlc_object_t *p_this, char const *psz_cmd,
static input_thread_t * get_input(libvlc_instance_t * p_instance) static input_thread_t * get_input(libvlc_instance_t * p_instance)
{ {
libvlc_exception_t p_e_unused; /* FIXME: error checking here */ libvlc_exception_t p_e_unused; /* FIXME: error checking here */
libvlc_input_t * p_libvlc_input = libvlc_playlist_get_input( p_instance, &p_e_unused ); libvlc_media_instance_t * p_mi;
input_thread_t * p_input; input_thread_t * p_input;
if( !p_libvlc_input ) p_mi = libvlc_playlist_get_media_instance( p_instance, &p_e_unused );
if( !p_mi )
return NULL; return NULL;
p_input = libvlc_get_input_thread( p_libvlc_input, &p_e_unused );
libvlc_input_free(p_libvlc_input); p_input = libvlc_get_input_thread( p_mi, &p_e_unused );
libvlc_media_instance_destroy( p_mi );
return p_input; return p_input;
} }
......
This diff is collapsed.
...@@ -31,6 +31,8 @@ extern "C" { ...@@ -31,6 +31,8 @@ extern "C" {
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <vlc/libvlc_structures.h> #include <vlc/libvlc_structures.h>
#include <vlc_input.h>
/*************************************************************************** /***************************************************************************
* Internal creation and destruction functions * Internal creation and destruction functions
...@@ -82,18 +84,31 @@ struct libvlc_media_descriptor_t ...@@ -82,18 +84,31 @@ struct libvlc_media_descriptor_t
libvlc_instance_t *p_libvlc_instance; libvlc_instance_t *p_libvlc_instance;
}; };
struct libvlc_input_t struct libvlc_media_instance_t
{ {
int i_input_id; ///< Input object id. We don't use a pointer to int i_input_id; /* Input object id. We don't use a pointer to
/// avoid any crash avoid any crash */
struct libvlc_instance_t *p_instance; ///< Parent instance struct libvlc_instance_t *p_libvlc_instance; /* Parent instance */
libvlc_media_descriptor_t *p_md; /* current media descriptor */
}; };
/*************************************************************************** /***************************************************************************
* Other internal functions * Other internal functions
***************************************************************************/ ***************************************************************************/
VLC_EXPORT (input_thread_t *, libvlc_get_input_thread, VLC_EXPORT (input_thread_t *, libvlc_get_input_thread,
( struct libvlc_input_t *, libvlc_exception_t * ) ); ( struct libvlc_media_instance_t *, libvlc_exception_t * ) );
VLC_EXPORT (libvlc_media_instance_t *, libvlc_media_instance_new_from_input_thread,
( struct libvlc_instance_t *, input_thread_t * ) );
VLC_EXPORT (void, libvlc_media_instance_destroy_and_detach,
( libvlc_media_instance_t * ) );
VLC_EXPORT (libvlc_media_descriptor_t *, libvlc_media_descriptor_new_from_input_item,
( struct libvlc_instance_t *, input_item_t * ) );
VLC_EXPORT (libvlc_media_descriptor_t *, libvlc_media_descriptor_duplicate,
( libvlc_media_descriptor_t * ) );
#define RAISENULL( psz,a... ) { libvlc_exception_raise( p_e, psz,##a ); \ #define RAISENULL( psz,a... ) { libvlc_exception_raise( p_e, psz,##a ); \
return NULL; } return NULL; }
......
...@@ -58,7 +58,7 @@ libvlc_media_descriptor_t * libvlc_media_descriptor_new( ...@@ -58,7 +58,7 @@ libvlc_media_descriptor_t * libvlc_media_descriptor_new(
if (!p_input_item) if (!p_input_item)
return NULL; /* XXX: throw an exception */ return NULL; /* XXX: throw an exception */
p_media_desc = malloc( sizeof(libvlc_input_t) ); p_media_desc = malloc( sizeof(libvlc_media_descriptor_t) );
p_media_desc->p_libvlc_instance = p_instance; p_media_desc->p_libvlc_instance = p_instance;
p_media_desc->p_input_item = p_input_item; p_media_desc->p_input_item = p_input_item;
p_media_desc->b_preparsed = VLC_FALSE; p_media_desc->b_preparsed = VLC_FALSE;
...@@ -66,22 +66,57 @@ libvlc_media_descriptor_t * libvlc_media_descriptor_new( ...@@ -66,22 +66,57 @@ libvlc_media_descriptor_t * libvlc_media_descriptor_new(
return p_media_desc; return p_media_desc;
} }
/**************************************************************************
* Create a new media descriptor object from an input_item
* (libvlc internal)
**************************************************************************/
libvlc_media_descriptor_t * libvlc_media_descriptor_new_from_input_item(
libvlc_instance_t *p_instance,
input_item_t *p_input_item )
{
libvlc_media_descriptor_t * p_media_desc;
if (!p_input_item)
return NULL; /* XXX: throw an exception */
p_media_desc = malloc( sizeof(libvlc_media_descriptor_t) );
p_media_desc->p_libvlc_instance = p_instance;
p_media_desc->p_input_item = p_input_item;
p_media_desc->b_preparsed = VLC_TRUE;
return p_media_desc;
}
/************************************************************************** /**************************************************************************
* Delete a media descriptor object * Delete a media descriptor object
**************************************************************************/ **************************************************************************/
void libvlc_media_descriptor_destroy( libvlc_media_descriptor_t *p_meta_desc ) void libvlc_media_descriptor_destroy( libvlc_media_descriptor_t *p_md )
{ {
if (!p_meta_desc) if (!p_md)
return; return;
/* XXX: locking */ /* XXX: locking */
input_ItemClean( p_meta_desc->p_input_item ); input_ItemClean( p_md->p_input_item );
free( p_md );
}
/**************************************************************************
* Delete a media descriptor object
**************************************************************************/
libvlc_media_descriptor_t *
libvlc_media_descriptor_duplicate( libvlc_media_descriptor_t *p_md_orig )
{
libvlc_media_descriptor_t * p_md;
p_md = malloc( sizeof(libvlc_media_descriptor_t) );
bcopy( p_md_orig, p_md, sizeof(libvlc_media_descriptor_t) );
free( p_meta_desc ); return p_md;
} }
/************************************************************************** /**************************************************************************
* Getters for meta information * Getter for meta information
**************************************************************************/ **************************************************************************/
static const int meta_conversion[] = static const int meta_conversion[] =
{ {
......
...@@ -283,17 +283,17 @@ mediacontrol_get_rate( mediacontrol_Instance *self, ...@@ -283,17 +283,17 @@ mediacontrol_get_rate( mediacontrol_Instance *self,
mediacontrol_Exception *exception ) mediacontrol_Exception *exception )
{ {
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_input_t* p_input; libvlc_media_instance_t* p_mi;
int i_ret; int i_ret;
mediacontrol_exception_init( exception ); mediacontrol_exception_init( exception );
libvlc_exception_init( &ex ); libvlc_exception_init( &ex );
p_input = libvlc_playlist_get_input( self->p_instance, &ex ); p_mi = libvlc_playlist_get_media_instance( self->p_instance, &ex );
HANDLE_LIBVLC_EXCEPTION_ZERO( &ex ); HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
i_ret = libvlc_input_get_rate( p_input, &ex ); i_ret = libvlc_media_instance_get_rate( p_mi, &ex );
libvlc_input_free( p_input ); libvlc_media_instance_destroy_and_detach( p_mi );
HANDLE_LIBVLC_EXCEPTION_ZERO( &ex ); HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
return i_ret / 10; return i_ret / 10;
...@@ -305,16 +305,16 @@ mediacontrol_set_rate( mediacontrol_Instance *self, ...@@ -305,16 +305,16 @@ mediacontrol_set_rate( mediacontrol_Instance *self,
mediacontrol_Exception *exception ) mediacontrol_Exception *exception )
{ {
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_input_t* p_input; libvlc_media_instance_t* p_mi;
mediacontrol_exception_init( exception ); mediacontrol_exception_init( exception );
libvlc_exception_init( &ex ); libvlc_exception_init( &ex );
p_input = libvlc_playlist_get_input( self->p_instance, &ex ); p_mi = libvlc_playlist_get_media_instance( self->p_instance, &ex );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex ); HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
libvlc_input_set_rate( p_input, rate * 10, &ex ); libvlc_media_instance_set_rate( p_mi, rate * 10, &ex );
libvlc_input_free( p_input ); libvlc_media_instance_destroy_and_detach( p_mi );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex ); HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
} }
...@@ -323,17 +323,17 @@ mediacontrol_get_fullscreen( mediacontrol_Instance *self, ...@@ -323,17 +323,17 @@ mediacontrol_get_fullscreen( mediacontrol_Instance *self,
mediacontrol_Exception *exception ) mediacontrol_Exception *exception )
{ {
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_input_t* p_input; libvlc_media_instance_t* p_mi;
int i_ret; int i_ret;
mediacontrol_exception_init( exception ); mediacontrol_exception_init( exception );
libvlc_exception_init( &ex ); libvlc_exception_init( &ex );
p_input = libvlc_playlist_get_input( self->p_instance, &ex ); p_mi = libvlc_playlist_get_media_instance( self->p_instance, &ex );
HANDLE_LIBVLC_EXCEPTION_ZERO( &ex ); HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
i_ret = libvlc_get_fullscreen( p_input, &ex ); i_ret = libvlc_get_fullscreen( p_mi, &ex );
libvlc_input_free( p_input ); libvlc_media_instance_destroy_and_detach( p_mi );
HANDLE_LIBVLC_EXCEPTION_ZERO( &ex ); HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
return i_ret; return i_ret;
...@@ -345,15 +345,15 @@ mediacontrol_set_fullscreen( mediacontrol_Instance *self, ...@@ -345,15 +345,15 @@ mediacontrol_set_fullscreen( mediacontrol_Instance *self,
mediacontrol_Exception *exception ) mediacontrol_Exception *exception )
{ {
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_input_t* p_input; libvlc_media_instance_t* p_mi;
mediacontrol_exception_init( exception ); mediacontrol_exception_init( exception );
libvlc_exception_init( &ex ); libvlc_exception_init( &ex );
p_input = libvlc_playlist_get_input( self->p_instance, &ex ); p_mi = libvlc_playlist_get_media_instance( self->p_instance, &ex );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex ); HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
libvlc_set_fullscreen( p_input, b_fullscreen, &ex ); libvlc_set_fullscreen( p_mi, b_fullscreen, &ex );
libvlc_input_free( p_input ); libvlc_media_instance_destroy_and_detach( p_mi );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex ); HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
} }
...@@ -124,7 +124,7 @@ mediacontrol_get_media_position( mediacontrol_Instance *self, ...@@ -124,7 +124,7 @@ mediacontrol_get_media_position( mediacontrol_Instance *self,
mediacontrol_Position* retval = NULL; mediacontrol_Position* retval = NULL;
libvlc_exception_t ex; libvlc_exception_t ex;
vlc_int64_t pos; vlc_int64_t pos;
libvlc_input_t * p_input; libvlc_media_instance_t * p_mi;
mediacontrol_exception_init( exception ); mediacontrol_exception_init( exception );
libvlc_exception_init( &ex ); libvlc_exception_init( &ex );
...@@ -133,19 +133,19 @@ mediacontrol_get_media_position( mediacontrol_Instance *self, ...@@ -133,19 +133,19 @@ mediacontrol_get_media_position( mediacontrol_Instance *self,
retval->origin = an_origin; retval->origin = an_origin;
retval->key = a_key; retval->key = a_key;
p_input = libvlc_playlist_get_input( self->p_instance, &ex); p_mi = libvlc_playlist_get_media_instance( self->p_instance, &ex);
HANDLE_LIBVLC_EXCEPTION_NULL( &ex ); HANDLE_LIBVLC_EXCEPTION_NULL( &ex );
if( an_origin != mediacontrol_AbsolutePosition ) if( an_origin != mediacontrol_AbsolutePosition )
{ {
libvlc_input_free( p_input ); libvlc_media_instance_destroy_and_detach( p_mi );
/* Relative or ModuloPosition make no sense */ /* Relative or ModuloPosition make no sense */
RAISE_NULL( mediacontrol_PositionOriginNotSupported, RAISE_NULL( mediacontrol_PositionOriginNotSupported,
"Only absolute position is valid." ); "Only absolute position is valid." );
} }
/* We are asked for an AbsolutePosition. */ /* We are asked for an AbsolutePosition. */
pos = libvlc_input_get_time( p_input, &ex ); pos = libvlc_media_instance_get_time( p_mi, &ex );
if( a_key == mediacontrol_MediaTime ) if( a_key == mediacontrol_MediaTime )
{ {
...@@ -155,7 +155,7 @@ mediacontrol_get_media_position( mediacontrol_Instance *self, ...@@ -155,7 +155,7 @@ mediacontrol_get_media_position( mediacontrol_Instance *self,
{ {
if( ! self->p_playlist->p_input ) if( ! self->p_playlist->p_input )
{ {
libvlc_input_free( p_input ); libvlc_media_instance_destroy_and_detach( p_mi );
RAISE_NULL( mediacontrol_InternalException, RAISE_NULL( mediacontrol_InternalException,
"No input" ); "No input" );
} }
...@@ -164,7 +164,7 @@ mediacontrol_get_media_position( mediacontrol_Instance *self, ...@@ -164,7 +164,7 @@ mediacontrol_get_media_position( mediacontrol_Instance *self,
a_key, a_key,
pos ); pos );
} }
libvlc_input_free( p_input ); libvlc_media_instance_destroy_and_detach( p_mi );
return retval; return retval;
} }
...@@ -174,19 +174,19 @@ mediacontrol_set_media_position( mediacontrol_Instance *self, ...@@ -174,19 +174,19 @@ mediacontrol_set_media_position( mediacontrol_Instance *self,
const mediacontrol_Position * a_position, const mediacontrol_Position * a_position,
mediacontrol_Exception *exception ) mediacontrol_Exception *exception )
{ {
libvlc_input_t * p_input; libvlc_media_instance_t * p_mi;
libvlc_exception_t ex; libvlc_exception_t ex;
vlc_int64_t i_pos; vlc_int64_t i_pos;
libvlc_exception_init( &ex ); libvlc_exception_init( &ex );
mediacontrol_exception_init( exception ); mediacontrol_exception_init( exception );
p_input = libvlc_playlist_get_input( self->p_instance, &ex); p_mi = libvlc_playlist_get_media_instance( self->p_instance, &ex);
HANDLE_LIBVLC_EXCEPTION_VOID( &ex ); HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
i_pos = mediacontrol_position2microsecond( self->p_playlist->p_input, a_position ); i_pos = mediacontrol_position2microsecond( self->p_playlist->p_input, a_position );
libvlc_input_set_time( p_input, i_pos / 1000, &ex ); libvlc_media_instance_set_time( p_mi, i_pos / 1000, &ex );
libvlc_input_free( p_input ); libvlc_media_instance_destroy_and_detach( p_mi );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex ); HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
} }
......
...@@ -211,29 +211,17 @@ void libvlc_playlist_unlock( libvlc_instance_t *p_instance ) ...@@ -211,29 +211,17 @@ void libvlc_playlist_unlock( libvlc_instance_t *p_instance )
vlc_mutex_unlock( &PL->object_lock ); vlc_mutex_unlock( &PL->object_lock );
} }
libvlc_input_t * libvlc_playlist_get_input( libvlc_instance_t *p_instance, libvlc_media_instance_t * libvlc_playlist_get_media_instance(
libvlc_exception_t *p_e ) libvlc_instance_t *p_instance,
libvlc_exception_t *p_e )
{ {
libvlc_input_t *p_input; libvlc_media_instance_t *p_mi;
assert( PL ); assert( PL );
vlc_mutex_lock( &PL->object_lock ); vlc_mutex_lock( &PL->object_lock );
if( PL->p_input == NULL ) p_mi = libvlc_media_instance_new_from_input_thread(
{ p_instance, PL->p_input );
libvlc_exception_raise( p_e, "No active input" );
vlc_mutex_unlock( &PL->object_lock );
return NULL;
}
p_input = (libvlc_input_t *)malloc( sizeof( libvlc_input_t ) );
if( !p_input )
{
libvlc_exception_raise( p_e, "out of memory" );
vlc_mutex_unlock( &PL->object_lock );
return NULL;
}
p_input->i_input_id = PL->p_input->i_object_id;
p_input->p_instance = p_instance;
vlc_mutex_unlock( &PL->object_lock ); vlc_mutex_unlock( &PL->object_lock );
return p_input; return p_mi;
} }
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment