Commit a8f019f2 authored by Laurent Aimar's avatar Laurent Aimar
Browse files

Added a ref count on input_resource_t.

It should fix invalid accesses of input_resource_t using input_GetVout/Aout.
parent 4862094f
......@@ -663,13 +663,18 @@ VLC_EXPORT( char *, input_CreateFilename, ( vlc_object_t *, const char *psz_path
VLC_EXPORT( input_resource_t *, input_resource_New, ( vlc_object_t * ) );
/**
* It deletes an input resource.
* It releases an input resource.
*/
VLC_EXPORT(void, input_resource_Delete, ( input_resource_t * ) );
VLC_EXPORT(void, input_resource_Release, ( input_resource_t * ) );
/**
* Forcefully destroys the video output (e.g. when the playlist is stopped).
*/
VLC_EXPORT(void, input_resource_TerminateVout, ( input_resource_t * ) );
/**
* This function releases all resources (object).
*/
VLC_EXPORT( void, input_resource_Terminate, ( input_resource_t * ) );
#endif
......@@ -506,7 +506,8 @@ static void libvlc_media_player_destroy( libvlc_media_player_t *p_mi )
release_input_thread(p_mi, true);
if( p_mi->input.p_resource )
{
input_resource_Delete( p_mi->input.p_resource );
input_resource_Terminate( p_mi->input.p_resource );
input_resource_Release( p_mi->input.p_resource );
p_mi->input.p_resource = NULL;
}
vlc_mutex_destroy( &p_mi->input.lock );
......
......@@ -386,12 +386,12 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
if( p_resource )
{
p_input->p->p_resource_private = NULL;
p_input->p->p_resource = p_resource;
p_input->p->p_resource = input_resource_Hold( p_resource );
}
else
{
p_input->p->p_resource_private = input_resource_New( VLC_OBJECT( p_input ) );
p_input->p->p_resource = p_input->p->p_resource_private;
p_input->p->p_resource = input_resource_Hold( p_input->p->p_resource_private );
}
input_resource_SetInput( p_input->p->p_resource, p_input );
......@@ -500,8 +500,10 @@ static void Destructor( input_thread_t * p_input )
if( p_input->p->p_es_out_display )
es_out_Delete( p_input->p->p_es_out_display );
if( p_input->p->p_resource )
input_resource_Release( p_input->p->p_resource );
if( p_input->p->p_resource_private )
input_resource_Delete( p_input->p->p_resource_private );
input_resource_Release( p_input->p->p_resource_private );
vlc_gc_decref( p_input->p->p_item );
......
......@@ -44,6 +44,8 @@
struct input_resource_t
{
VLC_GC_MEMBERS
vlc_object_t *p_parent;
/* This lock is used to serialize request and protect
......@@ -387,6 +389,18 @@ static void TerminateAout( input_resource_t *p_resource )
vlc_object_release( p_aout );
}
static void Destructor( gc_object_t *p_gc )
{
input_resource_t *p_resource = vlc_priv( p_gc, input_resource_t );
DestroySout( p_resource );
DestroyVout( p_resource );
DestroyAout( p_resource );
vlc_mutex_destroy( &p_resource->lock_hold );
vlc_mutex_destroy( &p_resource->lock );
free( p_resource );
}
/* */
input_resource_t *input_resource_New( vlc_object_t *p_parent )
......@@ -395,21 +409,22 @@ input_resource_t *input_resource_New( vlc_object_t *p_parent )
if( !p_resource )
return NULL;
vlc_gc_init( p_resource, Destructor );
p_resource->p_parent = p_parent;
vlc_mutex_init( &p_resource->lock );
vlc_mutex_init( &p_resource->lock_hold );
return p_resource;
}
void input_resource_Delete( input_resource_t *p_resource )
void input_resource_Release( input_resource_t *p_resource )
{
DestroySout( p_resource );
DestroyVout( p_resource );
DestroyAout( p_resource );
vlc_gc_decref( p_resource );
}
vlc_mutex_destroy( &p_resource->lock_hold );
vlc_mutex_destroy( &p_resource->lock );
free( p_resource );
input_resource_t *input_resource_Hold( input_resource_t *p_resource )
{
vlc_gc_incref( p_resource );
return p_resource;
}
void input_resource_SetInput( input_resource_t *p_resource, input_thread_t *p_input )
......
......@@ -76,5 +76,10 @@ void input_resource_HoldVouts( input_resource_t *, vout_thread_t ***, size_t * )
*/
void input_resource_Terminate( input_resource_t * );
/**
* This function holds the input_resource_t itself
*/
input_resource_t *input_resource_Hold( input_resource_t * );
#endif
......@@ -867,7 +867,10 @@ static void vlm_MediaInstanceDelete( vlm_t *p_vlm, int64_t id, vlm_media_instanc
vlm_SendEventMediaInstanceStopped( p_vlm, id, p_media->cfg.psz_name );
}
if( p_instance->p_input_resource )
input_resource_Delete( p_instance->p_input_resource );
{
input_resource_Terminate( p_instance->p_input_resource );
input_resource_Release( p_instance->p_input_resource );
}
TAB_REMOVE( p_media->i_instance, p_media->instance, p_instance );
vlc_gc_decref( p_instance->p_item );
......
......@@ -219,8 +219,9 @@ input_item_SetURI
input_item_WriteMeta
input_Read
input_resource_New
input_resource_Delete
input_resource_Release
input_resource_TerminateVout
input_resource_Terminate
input_SplitMRL
input_Start
input_Stop
......
......@@ -84,7 +84,10 @@ void playlist_Deactivate( playlist_t *p_playlist )
/* release input resources */
if( p_sys->p_input_resource )
input_resource_Delete( p_sys->p_input_resource );
{
input_resource_Terminate( p_sys->p_input_resource );
input_resource_Release( p_sys->p_input_resource );
}
p_sys->p_input_resource = NULL;
if( var_InheritBool( p_playlist, "media-library" ) )
......
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