Commit be6efa20 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

Libvlc: replace media_instance_destroy_and_detach by media_instance_release.

parent 8b356767
...@@ -83,6 +83,9 @@ libvlc_media_instance_t * libvlc_media_instance_new_from_input_thread( ...@@ -83,6 +83,9 @@ libvlc_media_instance_t * libvlc_media_instance_new_from_input_thread(
p_mi->p_libvlc_instance = p_libvlc_instance; 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;
/* will be released in media_instance_release() */
vlc_object_retain( p_input );
return p_mi; return p_mi;
} }
...@@ -113,13 +116,35 @@ void libvlc_media_instance_destroy( libvlc_media_instance_t *p_mi ) ...@@ -113,13 +116,35 @@ void libvlc_media_instance_destroy( libvlc_media_instance_t *p_mi )
} }
/************************************************************************** /**************************************************************************
* Free a Media Instance object (libvlc internal) * Release a Media Instance object
**************************************************************************/ **************************************************************************/
void libvlc_media_instance_destroy_and_detach( libvlc_media_instance_t *p_mi ) void libvlc_media_instance_release( libvlc_media_instance_t *p_mi )
{ {
input_thread_t *p_input_thread;
libvlc_exception_t p_e;
/* XXX: locking */
libvlc_exception_init( &p_e );
if( !p_mi ) if( !p_mi )
return; return;
p_input_thread = libvlc_get_input_thread( p_mi, &p_e );
if( !libvlc_exception_raised( &p_e ) )
{
/* release for previous libvlc_get_input_thread */
vlc_object_release( p_input_thread );
/* release for initial p_input_thread yield (see _new()) */
vlc_object_release( p_input_thread );
/* No one is tracking this input_thread appart us. Destroy it */
if( p_input_thread->i_refcount <= 0 )
input_DestroyThread( p_input_thread );
/* btw, we still have an XXX locking here */
}
libvlc_media_descriptor_destroy( p_mi->p_md ); libvlc_media_descriptor_destroy( p_mi->p_md );
free( p_mi ); free( p_mi );
...@@ -145,12 +170,16 @@ void libvlc_media_instance_play( libvlc_media_instance_t *p_mi, ...@@ -145,12 +170,16 @@ void libvlc_media_instance_play( libvlc_media_instance_t *p_mi,
return; return;
input_Control( p_input_thread, INPUT_CONTROL_SET_STATE, PLAYING_S ); input_Control( p_input_thread, INPUT_CONTROL_SET_STATE, PLAYING_S );
vlc_object_release( p_input_thread );
return; return;
} }
p_input_thread = input_CreateThread( p_mi->p_libvlc_instance->p_libvlc_int, p_input_thread = input_CreateThread( p_mi->p_libvlc_instance->p_libvlc_int,
p_mi->p_md->p_input_item ); p_mi->p_md->p_input_item );
p_mi->i_input_id = p_input_thread->i_object_id; p_mi->i_input_id = p_input_thread->i_object_id;
/* will be released in media_instance_release() */
vlc_object_yield( p_input_thread );
} }
/************************************************************************** /**************************************************************************
...@@ -169,6 +198,7 @@ void libvlc_media_instance_pause( libvlc_media_instance_t *p_mi, ...@@ -169,6 +198,7 @@ void libvlc_media_instance_pause( libvlc_media_instance_t *p_mi,
return; return;
input_Control( p_input_thread, INPUT_CONTROL_SET_STATE, val ); input_Control( p_input_thread, INPUT_CONTROL_SET_STATE, val );
vlc_object_release( p_input_thread );
} }
/************************************************************************** /**************************************************************************
......
...@@ -294,7 +294,7 @@ mediacontrol_get_rate( mediacontrol_Instance *self, ...@@ -294,7 +294,7 @@ mediacontrol_get_rate( mediacontrol_Instance *self,
HANDLE_LIBVLC_EXCEPTION_ZERO( &ex ); HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
i_ret = libvlc_media_instance_get_rate( p_mi, &ex ); i_ret = libvlc_media_instance_get_rate( p_mi, &ex );
libvlc_media_instance_destroy_and_detach( p_mi ); libvlc_media_instance_release( p_mi );
HANDLE_LIBVLC_EXCEPTION_ZERO( &ex ); HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
return i_ret / 10; return i_ret / 10;
...@@ -315,7 +315,7 @@ mediacontrol_set_rate( mediacontrol_Instance *self, ...@@ -315,7 +315,7 @@ mediacontrol_set_rate( mediacontrol_Instance *self,
HANDLE_LIBVLC_EXCEPTION_VOID( &ex ); HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
libvlc_media_instance_set_rate( p_mi, rate * 10, &ex ); libvlc_media_instance_set_rate( p_mi, rate * 10, &ex );
libvlc_media_instance_destroy_and_detach( p_mi ); libvlc_media_instance_release( p_mi );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex ); HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
} }
...@@ -334,7 +334,7 @@ mediacontrol_get_fullscreen( mediacontrol_Instance *self, ...@@ -334,7 +334,7 @@ mediacontrol_get_fullscreen( mediacontrol_Instance *self,
HANDLE_LIBVLC_EXCEPTION_ZERO( &ex ); HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
i_ret = libvlc_get_fullscreen( p_mi, &ex ); i_ret = libvlc_get_fullscreen( p_mi, &ex );
libvlc_media_instance_destroy_and_detach( p_mi ); libvlc_media_instance_release( p_mi );
HANDLE_LIBVLC_EXCEPTION_ZERO( &ex ); HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
return i_ret; return i_ret;
...@@ -355,6 +355,6 @@ mediacontrol_set_fullscreen( mediacontrol_Instance *self, ...@@ -355,6 +355,6 @@ mediacontrol_set_fullscreen( mediacontrol_Instance *self,
HANDLE_LIBVLC_EXCEPTION_VOID( &ex ); HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
libvlc_set_fullscreen( p_mi, b_fullscreen, &ex ); libvlc_set_fullscreen( p_mi, b_fullscreen, &ex );
libvlc_media_instance_destroy_and_detach( p_mi ); libvlc_media_instance_release( p_mi );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex ); HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
} }
...@@ -138,7 +138,7 @@ mediacontrol_get_media_position( mediacontrol_Instance *self, ...@@ -138,7 +138,7 @@ mediacontrol_get_media_position( mediacontrol_Instance *self,
if( an_origin != mediacontrol_AbsolutePosition ) if( an_origin != mediacontrol_AbsolutePosition )
{ {
libvlc_media_instance_destroy_and_detach( p_mi ); libvlc_media_instance_release( 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." );
...@@ -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_media_instance_destroy_and_detach( p_mi ); libvlc_media_instance_release( 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_media_instance_destroy_and_detach( p_mi ); libvlc_media_instance_release( p_mi );
return retval; return retval;
} }
...@@ -186,7 +186,7 @@ mediacontrol_set_media_position( mediacontrol_Instance *self, ...@@ -186,7 +186,7 @@ mediacontrol_set_media_position( mediacontrol_Instance *self,
i_pos = mediacontrol_position2microsecond( self->p_playlist->p_input, a_position ); i_pos = mediacontrol_position2microsecond( self->p_playlist->p_input, a_position );
libvlc_media_instance_set_time( p_mi, i_pos / 1000, &ex ); libvlc_media_instance_set_time( p_mi, i_pos / 1000, &ex );
libvlc_media_instance_destroy_and_detach( p_mi ); libvlc_media_instance_release( p_mi );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex ); HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
} }
......
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