[vlc-devel] [PATCH 08/14] input: merge input_ControlSync and input_ControlPush

Thomas Guillem thomas at gllm.fr
Fri Feb 21 16:59:39 CET 2020


Some controls could be send synchronously (when the input is not started) or
asynchronously (when the input is started). It's better to let the
input_thread_t decice.
---
 src/input/input.c          | 27 ++++++++++++++++++++-------
 src/input/input_internal.h |  5 -----
 src/player/medialib.c      |  6 +++---
 3 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/src/input/input.c b/src/input/input.c
index 18024ea6e06..0ca2c4d92b9 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -1463,11 +1463,31 @@ static size_t ControlGetReducedIndexLocked( input_thread_t *p_input,
 /*****************************************************************************
  * Control
  *****************************************************************************/
+static int input_ControlSync(input_thread_t *p_input, int i_type,
+                             const input_control_param_t* param )
+{
+    switch( i_type )
+    {
+        /* Not all controls can be handled when the input is not started. There
+         * are possibly more sync controls, add them here when needed.
+         * Synchronous controls need to be NON-BLOCKING. */
+        case INPUT_CONTROL_SET_ES_AUTOSELECT:
+            Control( p_input, i_type, *param );
+            return VLC_SUCCESS;
+        default:
+            return VLC_EGENERIC;
+    }
+}
+
 int input_ControlPush( input_thread_t *p_input,
                        int i_type, const input_control_param_t *p_param )
 {
     input_thread_private_t *sys = input_priv(p_input);
 
+    if( !sys->is_running && !sys->is_stopped
+     && input_ControlSync( p_input, i_type, p_param ) == VLC_SUCCESS )
+        return VLC_SUCCESS;
+
     vlc_mutex_lock( &sys->lock_control );
     input_control_t c = {
         .i_type = i_type,
@@ -1801,13 +1821,6 @@ static void ControlInsertDemuxFilter( input_thread_t* p_input, const char* psz_d
         msg_Dbg(p_input, "Failed to create demux filter %s", psz_demux_chain);
 }
 
-void input_ControlSync(input_thread_t *p_input, int i_type,
-                       const input_control_param_t* param )
-{
-    assert( !input_priv(p_input)->is_running );
-    Control( p_input, i_type, *param );
-}
-
 static bool Control( input_thread_t *p_input,
                      int i_type, input_control_param_t param )
 {
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index 91a02b392d5..3cc86c294f2 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -635,11 +635,6 @@ static inline int input_ControlPushEsHelper( input_thread_t *p_input, int i_type
     } );
 }
 
-/** Synchronously execute a control sequence. This MUST only be used before the
- * input is started
- */
-void input_ControlSync(input_thread_t *, int, const input_control_param_t *);
-
 bool input_Stopped( input_thread_t * );
 
 int input_GetAttachments(input_thread_t *input, input_attachment_t ***attachments);
diff --git a/src/player/medialib.c b/src/player/medialib.c
index 02249f41ea5..ef0e4bf7d0d 100644
--- a/src/player/medialib.c
+++ b/src/player/medialib.c
@@ -79,7 +79,7 @@ vlc_player_input_RestoreMlStates(struct vlc_player_input* input, bool force_pos)
     if (input->ml.states.current_video_track == -1)
     {
         input->ml.default_video_track = -1;
-        input_ControlSync(input->thread, INPUT_CONTROL_SET_ES_AUTOSELECT,
+        input_ControlPush(input->thread, INPUT_CONTROL_SET_ES_AUTOSELECT,
                           &(input_control_param_t) {
                               .es_autoselect.cat = VIDEO_ES,
                               .es_autoselect.enabled = false,
@@ -88,7 +88,7 @@ vlc_player_input_RestoreMlStates(struct vlc_player_input* input, bool force_pos)
     if (input->ml.states.current_audio_track == -1)
     {
         input->ml.default_audio_track = -1;
-        input_ControlSync(input->thread, INPUT_CONTROL_SET_ES_AUTOSELECT,
+        input_ControlPush(input->thread, INPUT_CONTROL_SET_ES_AUTOSELECT,
                           &(input_control_param_t) {
                               .es_autoselect.cat = AUDIO_ES,
                               .es_autoselect.enabled = false,
@@ -97,7 +97,7 @@ vlc_player_input_RestoreMlStates(struct vlc_player_input* input, bool force_pos)
     if (input->ml.states.current_subtitle_track == -1)
     {
         input->ml.default_subtitle_track = -1;
-        input_ControlSync(input->thread, INPUT_CONTROL_SET_ES_AUTOSELECT,
+        input_ControlPush(input->thread, INPUT_CONTROL_SET_ES_AUTOSELECT,
                           &(input_control_param_t) {
                               .es_autoselect.cat = SPU_ES,
                               .es_autoselect.enabled = false,
-- 
2.20.1



More information about the vlc-devel mailing list