Commit 664fa731 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

control/media_instance.c: Code factorization.

parent 6a1415be
...@@ -101,13 +101,12 @@ input_thread_t *libvlc_get_input_thread( libvlc_media_instance_t *p_mi, ...@@ -101,13 +101,12 @@ input_thread_t *libvlc_get_input_thread( libvlc_media_instance_t *p_mi,
return p_input_thread; return p_input_thread;
} }
/************************************************************************** /**************************************************************************
* Create a Media Instance object * Create a Media Instance object
**************************************************************************/ **************************************************************************/
libvlc_media_instance_t * libvlc_media_instance_t *
libvlc_media_instance_new( libvlc_instance_t * p_libvlc_instance, libvlc_media_instance_new( libvlc_instance_t * p_libvlc_instance,
libvlc_exception_t *p_e ) libvlc_exception_t * p_e )
{ {
libvlc_media_instance_t * p_mi; libvlc_media_instance_t * p_mi;
...@@ -146,22 +145,12 @@ libvlc_media_instance_new_from_media_descriptor( ...@@ -146,22 +145,12 @@ libvlc_media_instance_new_from_media_descriptor(
libvlc_exception_t *p_e ) libvlc_exception_t *p_e )
{ {
libvlc_media_instance_t * p_mi; libvlc_media_instance_t * p_mi;
p_mi = libvlc_media_instance_new( p_md->p_libvlc_instance, p_e );
if( !p_md ) if( !p_mi )
{
libvlc_exception_raise( p_e, "invalid media descriptor" );
return NULL; return NULL;
}
p_mi = malloc( sizeof(libvlc_media_instance_t) );
p_mi->p_md = libvlc_media_descriptor_duplicate( p_md ); p_mi->p_md = libvlc_media_descriptor_duplicate( p_md );
p_mi->p_libvlc_instance = p_mi->p_md->p_libvlc_instance;
p_mi->i_input_id = -1;
/* same strategy as before */
p_mi->i_refcount = 1;
/* same strategy as before */
vlc_mutex_init( p_mi->p_libvlc_instance->p_libvlc_int,
&p_mi->object_lock );
return p_mi; return p_mi;
} }
...@@ -182,24 +171,22 @@ libvlc_media_instance_t * libvlc_media_instance_new_from_input_thread( ...@@ -182,24 +171,22 @@ libvlc_media_instance_t * libvlc_media_instance_new_from_input_thread(
return NULL; return NULL;
} }
p_mi = malloc( sizeof(libvlc_media_instance_t) ); p_mi = libvlc_media_instance_new( p_libvlc_instance, p_e );
if( !p_mi )
return NULL;
p_mi->p_md = libvlc_media_descriptor_new_from_input_item( p_mi->p_md = libvlc_media_descriptor_new_from_input_item(
p_libvlc_instance, p_libvlc_instance,
p_input->p->input.p_item, p_e ); p_input->p->input.p_item, p_e );
if( !p_mi->p_md ) if( !p_mi->p_md )
{ {
free( p_mi ); libvlc_media_instance_destroy( p_mi );
return NULL; return NULL;
} }
p_mi->p_libvlc_instance = p_libvlc_instance;
p_mi->i_input_id = p_input->i_object_id; p_mi->i_input_id = p_input->i_object_id;
/* same strategy as before */
p_mi->i_refcount = 1;
/* same strategy as before */
vlc_mutex_init( p_mi->p_libvlc_instance->p_libvlc_int,
&p_mi->object_lock );
/* will be released in media_instance_release() */ /* will be released in media_instance_release() */
vlc_object_yield( p_input ); vlc_object_yield( p_input );
...@@ -229,7 +216,10 @@ void libvlc_media_instance_destroy( libvlc_media_instance_t *p_mi ) ...@@ -229,7 +216,10 @@ void libvlc_media_instance_destroy( libvlc_media_instance_t *p_mi )
p_input_thread = libvlc_get_input_thread( p_mi, &p_e ); p_input_thread = libvlc_get_input_thread( p_mi, &p_e );
if( libvlc_exception_raised( &p_e ) ) if( libvlc_exception_raised( &p_e ) )
{
free( p_mi );
return; /* no need to worry about no input thread */ return; /* no need to worry about no input thread */
}
input_DestroyThread( p_input_thread ); input_DestroyThread( p_input_thread );
......
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