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

input: simplify/inline aout resource handling

parent 1925313d
......@@ -2075,7 +2075,7 @@ static void DeleteDecoder( decoder_t * p_dec )
/* TODO: REVISIT gap-less audio */
aout_DecFlush( p_owner->p_aout );
aout_DecDelete( p_owner->p_aout );
input_resource_RequestAout( p_owner->p_resource, p_owner->p_aout );
input_resource_PutAout( p_owner->p_resource, p_owner->p_aout );
if( p_owner->p_input != NULL )
input_SendEventAout( p_owner->p_input );
}
......@@ -2196,7 +2196,7 @@ static block_t *aout_new_buffer( decoder_t *p_dec, int i_samples )
p_owner->p_aout = NULL;
vlc_mutex_unlock( &p_owner->lock );
input_resource_RequestAout( p_owner->p_resource, p_aout );
input_resource_PutAout( p_owner->p_resource, p_aout );
}
if( p_owner->p_aout == NULL )
......@@ -2230,7 +2230,7 @@ static block_t *aout_new_buffer( decoder_t *p_dec, int i_samples )
request_vout.p_private = p_dec;
assert( p_owner->p_aout == NULL );
p_aout = input_resource_RequestAout( p_owner->p_resource, NULL );
p_aout = input_resource_GetAout( p_owner->p_resource );
if( p_aout )
{
aout_FormatPrepare( &format );
......@@ -2238,7 +2238,7 @@ static block_t *aout_new_buffer( decoder_t *p_dec, int i_samples )
&p_dec->fmt_out.audio_replay_gain,
&request_vout ) )
{
input_resource_RequestAout( p_owner->p_resource, p_aout );
input_resource_PutAout( p_owner->p_resource, p_aout );
p_aout = NULL;
}
}
......
......@@ -325,39 +325,15 @@ exit:
vlc_mutex_unlock( &p_resource->lock_hold );
}
/* */
static void DestroyAout( input_resource_t *p_resource )
{
if( p_resource->p_aout )
{
aout_Destroy( p_resource->p_aout );
p_resource->p_aout = NULL;
}
}
static void ReleaseAout( input_resource_t *p_resource,
audio_output_t *p_aout )
{
if( likely(p_aout == p_resource->p_aout) )
{
assert( p_resource->b_aout_busy );
p_resource->b_aout_busy = false;
msg_Dbg( p_resource->p_parent, "releasing audio output" );
vlc_object_release( p_aout );
}
else
{
msg_Dbg( p_resource->p_parent, "destroying extra audio output" );
aout_Destroy( p_aout );
}
}
static audio_output_t *AllocateAout( input_resource_t *p_resource )
/* Audio output */
audio_output_t *input_resource_GetAout( input_resource_t *p_resource )
{
audio_output_t *p_aout;
if( unlikely(p_resource->b_aout_busy) )
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 );
}
......@@ -367,61 +343,76 @@ static audio_output_t *AllocateAout( input_resource_t *p_resource )
{
msg_Dbg( p_resource->p_parent, "creating audio output" );
p_aout = aout_New( p_resource->p_parent );
if( unlikely(p_aout == NULL) )
return NULL;
}
else
msg_Dbg( p_resource->p_parent, "reusing audio output" );
if( p_aout != NULL )
{
vlc_mutex_lock( &p_resource->lock_hold );
assert( p_resource->p_aout == NULL );
p_resource->p_aout = p_aout;
vlc_mutex_unlock( &p_resource->lock_hold );
}
else
msg_Dbg( p_resource->p_parent, "recycling audio output" );
p_resource->b_aout_busy = true;
vlc_object_hold( p_aout );
p_resource->b_aout_busy = true;
vlc_object_hold( p_aout );
}
vlc_mutex_unlock( &p_resource->lock );
return p_aout;
}
static audio_output_t *RequestAout( input_resource_t *p_resource, audio_output_t *p_aout )
void input_resource_PutAout( input_resource_t *p_resource,
audio_output_t *p_aout )
{
vlc_assert_locked( &p_resource->lock );
assert( p_aout != NULL );
if( p_aout )
vlc_mutex_lock( &p_resource->lock );
if( p_aout == p_resource->p_aout )
{
ReleaseAout( p_resource, p_aout );
return NULL;
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;
}
return AllocateAout( p_resource );
else
msg_Dbg( p_resource->p_parent, "destroying extra audio output" );
vlc_mutex_unlock( &p_resource->lock );
if( p_aout != NULL )
aout_Destroy( p_aout );
}
static audio_output_t *HoldAout( input_resource_t *p_resource )
audio_output_t *input_resource_HoldAout( input_resource_t *p_resource )
{
vlc_mutex_lock( &p_resource->lock_hold );
audio_output_t *p_aout;
audio_output_t *p_aout = p_resource->p_aout;
vlc_mutex_lock( &p_resource->lock_hold );
p_aout = p_resource->p_aout;
if( p_aout )
vlc_object_hold( p_aout );
vlc_mutex_unlock( &p_resource->lock_hold );
return p_aout;
}
static void TerminateAout( input_resource_t *p_resource )
static void input_resource_TerminateAout( input_resource_t *p_resource )
{
vlc_mutex_lock( &p_resource->lock_hold );
audio_output_t *p_aout;
audio_output_t *p_aout = p_resource->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 );
if( p_aout )
if( p_aout != NULL )
aout_Destroy( p_aout );
}
/* */
/* Common */
input_resource_t *input_resource_New( vlc_object_t *p_parent )
{
input_resource_t *p_resource = calloc( 1, sizeof(*p_resource) );
......@@ -442,7 +433,8 @@ void input_resource_Release( input_resource_t *p_resource )
DestroySout( p_resource );
DestroyVout( p_resource );
DestroyAout( p_resource );
if( p_resource->p_aout != NULL )
aout_Destroy( p_resource->p_aout );
vlc_mutex_destroy( &p_resource->lock_hold );
vlc_mutex_destroy( &p_resource->lock );
......@@ -504,20 +496,6 @@ bool input_resource_HasVout( input_resource_t *p_resource )
return b_vout;
}
/* */
audio_output_t *input_resource_RequestAout( input_resource_t *p_resource, audio_output_t *p_aout )
{
vlc_mutex_lock( &p_resource->lock );
audio_output_t *p_ret = RequestAout( p_resource, p_aout );
vlc_mutex_unlock( &p_resource->lock );
return p_ret;
}
audio_output_t *input_resource_HoldAout( input_resource_t *p_resource )
{
return HoldAout( p_resource );
}
/* */
sout_instance_t *input_resource_RequestSout( input_resource_t *p_resource, sout_instance_t *p_sout, const char *psz_sout )
{
......@@ -535,11 +513,7 @@ void input_resource_TerminateSout( input_resource_t *p_resource )
void input_resource_Terminate( input_resource_t *p_resource )
{
input_resource_TerminateSout( p_resource );
vlc_mutex_lock( &p_resource->lock );
TerminateAout( p_resource );
vlc_mutex_unlock( &p_resource->lock );
input_resource_TerminateAout( p_resource );
input_resource_TerminateVout( p_resource );
}
......@@ -37,9 +37,14 @@ void input_resource_SetInput( input_resource_t *, input_thread_t * );
sout_instance_t *input_resource_RequestSout( input_resource_t *, sout_instance_t *, const char *psz_sout );
/**
* This function handles aout request.
* This function creates or recycles an audio output.
*/
audio_output_t *input_resource_RequestAout( input_resource_t *, audio_output_t * );
audio_output_t *input_resource_GetAout( input_resource_t * );
/**
* This function retains or destroys an audio output.
*/
void input_resource_PutAout( input_resource_t *, audio_output_t * );
/**
* This function returns the current aout if any.
......
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