[vlc-devel] [PATCH 6/7] player: handle unhandled nav controls

Thomas Guillem thomas at gllm.fr
Wed Oct 30 15:57:00 CET 2019


---
 src/input/event.h          |  9 +++++
 src/input/input.c          | 74 +-------------------------------------
 src/input/input_internal.h |  6 ++++
 src/player/input.c         | 72 +++++++++++++++++++++++++++++++++++++
 4 files changed, 88 insertions(+), 73 deletions(-)

diff --git a/src/input/event.h b/src/input/event.h
index dd9aec4a871..b8dce99f417 100644
--- a/src/input/event.h
+++ b/src/input/event.h
@@ -79,6 +79,15 @@ static inline void input_SendEventOutputClock(input_thread_t *p_input,
     });
 }
 
+static inline void input_SendEventNavNotHandled(input_thread_t *p_input,
+                                                enum input_control_e nav)
+{
+    input_SendEvent(p_input, &(struct vlc_input_event) {
+        .type = INPUT_EVENT_NAV_NOT_HANDLED,
+        .nav = nav,
+    });
+}
+
 static inline void input_SendEventStatistics(input_thread_t *p_input,
                                              const struct input_stats_t *stats)
 {
diff --git a/src/input/input.c b/src/input/input.c
index 429a6298bd9..3f6c5bbad0f 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -1693,79 +1693,7 @@ static void ControlNav( input_thread_t *p_input, int i_type )
         return; /* The demux handled the navigation control */
 
     /* Handle Up/Down/Left/Right if the demux can't navigate */
-    vlc_viewpoint_t vp = {0};
-    int vol_direction = 0;
-    int seek_direction = 0;
-    switch( i_type )
-    {
-        case INPUT_CONTROL_NAV_UP:
-            vol_direction = 1;
-            vp.pitch = -1.f;
-            break;
-        case INPUT_CONTROL_NAV_DOWN:
-            vol_direction = -1;
-            vp.pitch = 1.f;
-            break;
-        case INPUT_CONTROL_NAV_LEFT:
-            seek_direction = -1;
-            vp.yaw = -1.f;
-            break;
-        case INPUT_CONTROL_NAV_RIGHT:
-            seek_direction = 1;
-            vp.yaw = 1.f;
-            break;
-        case INPUT_CONTROL_NAV_ACTIVATE:
-        case INPUT_CONTROL_NAV_POPUP:
-        case INPUT_CONTROL_NAV_MENU:
-            return;
-        default:
-            vlc_assert_unreachable();
-    }
-
-    /* Try to change the viewpoint if possible */
-    vout_thread_t **pp_vout;
-    size_t i_vout;
-    bool b_viewpoint_ch = false;
-    input_resource_HoldVouts( priv->p_resource, &pp_vout, &i_vout );
-    for( size_t i = 0; i < i_vout; ++i )
-    {
-        if( !b_viewpoint_ch
-         && var_GetBool( pp_vout[i], "viewpoint-changeable" ) )
-            b_viewpoint_ch = true;
-        vout_Release(pp_vout[i]);
-    }
-    free( pp_vout );
-
-    if( b_viewpoint_ch )
-    {
-        priv->viewpoint_changed = true;
-        priv->viewpoint.yaw   += vp.yaw;
-        priv->viewpoint.pitch += vp.pitch;
-        priv->viewpoint.roll  += vp.roll;
-        priv->viewpoint.fov   += vp.fov;
-        ViewpointApply( p_input );
-        return;
-    }
-
-    /* Seek or change volume if the input doesn't have navigation or viewpoint */
-    if( seek_direction != 0 )
-    {
-        vlc_tick_t it = vlc_tick_from_sec( seek_direction * var_InheritInteger( p_input, "short-jump-size" ) );
-        Control( p_input, INPUT_CONTROL_JUMP_TIME, (input_control_param_t) {
-            .time.b_fast_seek = false,
-            .time.i_val = it
-        });
-    }
-    else
-    {
-        assert( vol_direction != 0 );
-        audio_output_t *p_aout = input_resource_HoldAout( priv->p_resource );
-        if( p_aout )
-        {
-            aout_VolumeUpdate( p_aout, vol_direction, NULL );
-            aout_Release(p_aout);
-        }
-    }
+    input_SendEventNavNotHandled( p_input, i_type );
 }
 
 #ifdef ENABLE_SOUT
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index c9596d2da75..b990a23c66b 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -158,6 +158,10 @@ typedef enum input_event_type_e
     /* The output PTS changed */
     INPUT_EVENT_OUTPUT_CLOCK,
 
+    /* The control nav was not handled by the demuxer, the input user can
+     * handle them now */
+    INPUT_EVENT_NAV_NOT_HANDLED,
+
     /* A title has been added or removed or selected.
      * It implies that the chapter has changed (no chapter event is sent) */
     INPUT_EVENT_TITLE,
@@ -332,6 +336,8 @@ struct vlc_input_event
         struct vlc_input_event_times times;
         /* INPUT_EVENT_OUTPUT_CLOCK */
         struct vlc_input_event_output_clock output_clock;
+        /* INPUT_EVENT_NAV_NOT_HANDLED */
+        enum input_control_e nav;
         /* INPUT_EVENT_TITLE */
         struct vlc_input_event_title title;
         /* INPUT_EVENT_CHAPTER */
diff --git a/src/player/input.c b/src/player/input.c
index 18d26466631..397453146e8 100644
--- a/src/player/input.c
+++ b/src/player/input.c
@@ -25,6 +25,7 @@
 #include <vlc_common.h>
 #include <vlc_interface.h>
 #include "player.h"
+#include "../input/resource.h"
 
 struct vlc_player_track_priv *
 vlc_player_input_FindTrackById(struct vlc_player_input *input, vlc_es_id_t *id,
@@ -268,6 +269,74 @@ vlc_player_input_HandleStateEvent(struct vlc_player_input *input,
     }
 }
 
+static void
+vlc_player_input_HandleNavEvent(struct vlc_player_input *input,
+                                enum input_control_e nav)
+{
+    vlc_player_t *player = input->player;
+
+    vlc_viewpoint_t vp = {0};
+    int vol_direction = 0;
+    int seek_direction = 0;
+    switch (nav)
+    {
+        case INPUT_CONTROL_NAV_UP:
+            vol_direction = 1;
+            vp.pitch = -1.f;
+            break;
+        case INPUT_CONTROL_NAV_DOWN:
+            vol_direction = -1;
+            vp.pitch = 1.f;
+            break;
+        case INPUT_CONTROL_NAV_LEFT:
+            seek_direction = -1;
+            vp.yaw = -1.f;
+            break;
+        case INPUT_CONTROL_NAV_RIGHT:
+            seek_direction = 1;
+            vp.yaw = 1.f;
+            break;
+        case INPUT_CONTROL_NAV_ACTIVATE:
+        case INPUT_CONTROL_NAV_POPUP:
+        case INPUT_CONTROL_NAV_MENU:
+            return;
+        default:
+            vlc_assert_unreachable();
+    }
+
+    /* Try to change the viewpoint if possible */
+    vout_thread_t **vouts;
+    size_t vout_count;
+    bool viewpoint_ch = false;
+    input_resource_HoldVouts(player->resource, &vouts, &vout_count);
+    for (size_t i = 0; i < vout_count; ++i)
+    {
+        if (!viewpoint_ch && var_GetBool(vouts[i], "viewpoint-changeable"))
+            viewpoint_ch = true;
+        vout_Release(vouts[i]);
+    }
+    free(vouts);
+
+    if (viewpoint_ch)
+    {
+        vlc_player_UpdateViewpoint(player, &vp, VLC_PLAYER_WHENCE_RELATIVE);
+        return;
+    }
+
+    /* Seek or change volume if the input doesn't have navigation or viewpoint */
+    if (seek_direction != 0 )
+    {
+        vlc_tick_t jump = vlc_tick_from_sec(seek_direction
+                        * var_InheritInteger(player, "short-jump-size"));
+        vlc_player_JumpTime(player, jump);
+    }
+    else
+    {
+        assert(vol_direction != 0);
+        vlc_player_aout_IncrementVolume(player, vol_direction, NULL);
+    }
+}
+
 static void
 vlc_player_input_HandleProgramEvent(struct vlc_player_input *input,
                                     const struct vlc_input_event_program *ev)
@@ -758,6 +827,9 @@ input_thread_Events(input_thread_t *input_thread,
             }
             break;
         }
+        case INPUT_EVENT_NAV_NOT_HANDLED:
+            vlc_player_input_HandleNavEvent(input, event->nav);
+            break;
         case INPUT_EVENT_PROGRAM:
             vlc_player_input_HandleProgramEvent(input, &event->program);
             break;
-- 
2.20.1



More information about the vlc-devel mailing list