[vlc-devel] [RFC PATCH 06/12] decoder: reload module from start if aout device changes
Thomas Guillem
thomas at gllm.fr
Tue Jul 19 19:36:28 CEST 2016
In order to be able to change from PCM to SPDIF and from SPDIF to PCM.
---
src/input/decoder.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/src/input/decoder.c b/src/input/decoder.c
index c04de09..ada39ca 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -81,6 +81,7 @@ struct decoder_owner_sys_t
/* */
bool b_fmt_description;
vlc_meta_t *p_description;
+ atomic_bool aout_device_changed;
/* fifo */
block_fifo_t *p_fifo;
@@ -255,6 +256,20 @@ static vout_thread_t *aout_request_vout( void *p_private,
return p_vout;
}
+static int aout_device_changed( vlc_object_t *p_obj, const char *p_var,
+ vlc_value_t prev, vlc_value_t cur, void *p_data)
+{
+ (void) p_obj; (void) p_var;
+ decoder_t *p_dec = p_data;
+ decoder_owner_sys_t *p_owner = p_dec->p_owner;
+
+ if( prev.psz_string == NULL || cur.psz_string == NULL
+ || strcmp( prev.psz_string, cur.psz_string ) != 0 )
+ atomic_store( &p_owner->aout_device_changed, true );
+
+ return VLC_SUCCESS;
+}
+
static int aout_update_format( decoder_t *p_dec )
{
decoder_owner_sys_t *p_owner = p_dec->p_owner;
@@ -268,6 +283,7 @@ static int aout_update_format( decoder_t *p_dec )
vlc_mutex_lock( &p_owner->lock );
p_owner->p_aout = NULL;
vlc_mutex_unlock( &p_owner->lock );
+ var_DelCallback( p_aout, "device", aout_device_changed, p_dec );
aout_DecDelete( p_aout );
input_resource_PutAout( p_owner->p_resource, p_aout );
@@ -313,6 +329,8 @@ static int aout_update_format( decoder_t *p_dec )
input_resource_PutAout( p_owner->p_resource, p_aout );
p_aout = NULL;
}
+ else
+ var_AddCallback( p_aout, "device", aout_device_changed, p_dec );
}
vlc_mutex_lock( &p_owner->lock );
@@ -1356,6 +1374,15 @@ static void DecoderProcess( decoder_t *p_dec, block_t *p_block )
if( p_dec->b_fallback )
{
+ if( atomic_exchange( &p_owner->aout_device_changed, false ) )
+ {
+ free( p_owner->p_module_savectx );
+ p_owner->p_module_savectx = NULL;
+
+ msg_Warn( p_dec, "aout devices changed: retrying to load decoders "
+ "from start" );
+ }
+
if( ReloadDecoder( p_dec, false, &p_dec->fmt_in,
&p_owner->p_module_savectx ) != VLC_SUCCESS )
goto error;
@@ -1612,6 +1639,7 @@ static decoder_t * CreateDecoder( vlc_object_t *p_parent,
p_owner->flushing = false;
p_owner->b_draining = false;
atomic_init( &p_owner->drained, false );
+ atomic_init( &p_owner->aout_device_changed, false );
p_owner->b_idle = false;
es_format_Init( &p_owner->fmt, UNKNOWN_ES, 0 );
@@ -1731,6 +1759,7 @@ static void DeleteDecoder( decoder_t * p_dec )
{
/* TODO: REVISIT gap-less audio */
aout_DecFlush( p_owner->p_aout, false );
+ var_DelCallback( p_owner->p_aout, "device", aout_device_changed, p_dec );
aout_DecDelete( p_owner->p_aout );
input_resource_PutAout( p_owner->p_resource, p_owner->p_aout );
if( p_owner->p_input != NULL )
--
2.8.1
More information about the vlc-devel
mailing list