Commit bf62d22f authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

resource: simplify & reduce aout locking

parent bb3fe09c
......@@ -330,33 +330,31 @@ audio_output_t *input_resource_GetAout( input_resource_t *p_resource )
{
audio_output_t *p_aout;
vlc_mutex_lock( &p_resource->lock );
if( p_resource->b_aout_busy )
{
vlc_mutex_unlock( &p_resource->lock );
msg_Dbg( p_resource->p_parent, "creating extra audio output" );
return aout_New( p_resource->p_parent );
}
vlc_mutex_lock( &p_resource->lock_hold );
p_aout = p_resource->p_aout;
if( p_aout == NULL )
if( p_aout == NULL || p_resource->b_aout_busy )
{
msg_Dbg( p_resource->p_parent, "creating audio output" );
vlc_mutex_unlock( &p_resource->lock_hold );
p_aout = aout_New( p_resource->p_parent );
if( p_aout == NULL )
return NULL; /* failed */
vlc_mutex_lock( &p_resource->lock_hold );
if( p_resource->p_aout == NULL )
p_resource->p_aout = p_aout;
}
else
msg_Dbg( p_resource->p_parent, "reusing audio output" );
if( p_aout != NULL )
if( p_resource->p_aout == p_aout )
{
vlc_mutex_lock( &p_resource->lock_hold );
p_resource->p_aout = p_aout;
vlc_mutex_unlock( &p_resource->lock_hold );
assert( !p_resource->b_aout_busy );
p_resource->b_aout_busy = true;
vlc_object_hold( p_aout );
}
vlc_mutex_unlock( &p_resource->lock );
vlc_mutex_unlock( &p_resource->lock_hold );
return p_aout;
}
......@@ -365,18 +363,17 @@ void input_resource_PutAout( input_resource_t *p_resource,
{
assert( p_aout != NULL );
vlc_mutex_lock( &p_resource->lock );
vlc_mutex_lock( &p_resource->lock_hold );
if( p_aout == p_resource->p_aout )
{
assert( p_resource->b_aout_busy );
p_resource->b_aout_busy = false;
msg_Dbg( p_resource->p_parent, "keeping audio output" );
vlc_object_release( p_aout );
p_aout = NULL;
}
else
msg_Dbg( p_resource->p_parent, "destroying extra audio output" );
vlc_mutex_unlock( &p_resource->lock );
vlc_mutex_unlock( &p_resource->lock_hold );
if( p_aout != NULL )
aout_Destroy( p_aout );
......@@ -388,7 +385,7 @@ audio_output_t *input_resource_HoldAout( input_resource_t *p_resource )
vlc_mutex_lock( &p_resource->lock_hold );
p_aout = p_resource->p_aout;
if( p_aout )
if( p_aout != NULL )
vlc_object_hold( p_aout );
vlc_mutex_unlock( &p_resource->lock_hold );
......@@ -399,13 +396,11 @@ static void input_resource_TerminateAout( input_resource_t *p_resource )
{
audio_output_t *p_aout;
vlc_mutex_lock( &p_resource->lock );
vlc_mutex_lock( &p_resource->lock_hold );
p_aout = p_resource->p_aout;
p_resource->p_aout = NULL;
vlc_mutex_unlock( &p_resource->lock_hold );
p_resource->b_aout_busy = false;
vlc_mutex_unlock( &p_resource->lock );
vlc_mutex_unlock( &p_resource->lock_hold );
if( p_aout != NULL )
aout_Destroy( p_aout );
......
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