Commit 72f780a4 authored by Thomas Guillem's avatar Thomas Guillem

input: fix restart of all ES when changing renderer

The sout was destroyed before decoders were deleted. This could lead to a
use-after-free of the sout from the DecoderThread.

To fix this issue, we stop all ES, save the stopped state of all ES, change the
renderer/sout configuration and restart all previously stopped ES.

Deprecate ES_OUT_RESTART_ALL_ES since it was only used for this case. And
replace it by ES_OUT_STOP_ALL_ES/ES_OUT_START_ALL_ES, but in private headers.
parent 5d0056dc
......@@ -38,9 +38,7 @@ enum es_out_query_e
/* set or change the selected ES in its category (audio/video/spu) */
ES_OUT_SET_ES, /* arg1= es_out_id_t* */
ES_OUT_RESTART_ES, /* arg1= es_out_id_t* */
/* Restart all ES, destroying and recreating decoder/sout and potential
* video/audio outputs. This is not recommended and might not even work */
ES_OUT_RESTART_ALL_ES, /* No arg */
ES_OUT_RESTART_ALL_ES, /* Deprecated, no effect */
/* set 'default' tag on ES (copied across from container) */
ES_OUT_SET_ES_DEFAULT, /* arg1= es_out_id_t* */
......
......@@ -2384,16 +2384,39 @@ static int EsOutControlLocked( es_out_t *out, int i_query, va_list args )
}
return VLC_SUCCESS;
}
case ES_OUT_RESTART_ALL_ES:
case ES_OUT_STOP_ALL_ES:
{
int *selected_es = vlc_alloc(p_sys->i_es + 1, sizeof(int));
if (!selected_es)
return VLC_ENOMEM;
selected_es[0] = p_sys->i_es;
for( int i = 0; i < p_sys->i_es; i++ )
{
if( EsIsSelected( p_sys->es[i] ) )
{
EsDestroyDecoder( out, p_sys->es[i] );
EsCreateDecoder( out, p_sys->es[i] );
selected_es[i + 1] = p_sys->es[i]->i_id;
}
else
selected_es[i + 1] = -1;
}
*va_arg( args, void **) = selected_es;
return VLC_SUCCESS;
}
case ES_OUT_START_ALL_ES:
{
int *selected_es = va_arg( args, void * );
int count = selected_es[0];
for( int i = 0; i < count; ++i )
{
int i_id = selected_es[i + 1];
if( i_id != -1 )
{
es_out_id_t *p_es = EsOutGetFromID( out, i_id );
EsCreateDecoder( out, p_es );
}
}
free(selected_es);
return VLC_SUCCESS;
}
......
......@@ -50,6 +50,12 @@ enum es_out_query_private_e
ES_OUT_SET_ES_DEFAULT_BY_ID,
ES_OUT_GET_ES_OBJECTS_BY_ID, /* arg1=int id, vlc_object_t **dec, vout_thread_t **, audio_output_t ** res=can fail*/
/* Stop all selected ES and save the stopped state in a context. free the
* context or call ES_OUT_STOP_ALL_ES */
ES_OUT_STOP_ALL_ES, /* arg1=void ** */
/* Start all ES from the context returned by ES_OUT_STOP_ALL_ES */
ES_OUT_START_ALL_ES, /* arg1=void * */
/* Get buffering state */
ES_OUT_GET_BUFFERING, /* arg1=bool* res=cannot fail */
......
......@@ -743,6 +743,8 @@ static int ControlLocked( es_out_t *p_out, int i_query, va_list args )
case ES_OUT_RESTART_ES_BY_ID:
case ES_OUT_SET_ES_DEFAULT_BY_ID:
case ES_OUT_GET_ES_OBJECTS_BY_ID:
case ES_OUT_STOP_ALL_ES:
case ES_OUT_START_ALL_ES:
case ES_OUT_SET_DELAY:
case ES_OUT_SET_RECORD_STATE:
default:
......
......@@ -1809,7 +1809,6 @@ static void ControlUpdateRenderer( input_thread_t *p_input, bool b_enable )
input_priv(p_input)->p_sout, NULL );
input_priv(p_input)->p_sout = NULL;
}
es_out_Control( input_priv(p_input)->p_es_out, ES_OUT_RESTART_ALL_ES );
}
#endif
......@@ -2238,6 +2237,11 @@ static bool Control( input_thread_t *p_input,
if ( p_item == NULL && p_priv->p_renderer == NULL )
break;
void *context;
if( es_out_Control( input_priv(p_input)->p_es_out_display,
ES_OUT_STOP_ALL_ES, &context ) != VLC_SUCCESS )
break;
if ( p_priv->p_renderer )
{
ControlUpdateRenderer( p_input, false );
......@@ -2258,6 +2262,8 @@ static bool Control( input_thread_t *p_input,
}
input_resource_TerminateVout( p_priv->p_resource );
}
es_out_Control( input_priv(p_input)->p_es_out_display, ES_OUT_START_ALL_ES,
context );
#endif
break;
}
......
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