[vlc-devel] [PATCH V2 07/13] input: send pause/playing date via events

Thomas Guillem thomas at gllm.fr
Fri Aug 23 16:45:12 CEST 2019


In order to get the pause and play date from the player.
---
 src/input/event.h          |  5 +++--
 src/input/input.c          | 25 +++++++++++++------------
 src/input/input_internal.h |  9 ++++++++-
 src/input/item.c           |  2 +-
 src/input/thumbnailer.c    |  4 ++--
 src/player/input.c         | 22 ++++++++++++++--------
 src/player/player.c        |  6 ++++--
 src/player/player.h        |  3 ++-
 8 files changed, 47 insertions(+), 29 deletions(-)

diff --git a/src/input/event.h b/src/input/event.h
index f4f44ba5e1..8dfb75fc39 100644
--- a/src/input/event.h
+++ b/src/input/event.h
@@ -128,11 +128,12 @@ static inline void input_SendEventSignal(input_thread_t *p_input,
     });
 }
 
-static inline void input_SendEventState(input_thread_t *p_input, int i_state)
+static inline void input_SendEventState(input_thread_t *p_input, int i_state,
+                                        vlc_tick_t state_date)
 {
     input_SendEvent(p_input, &(struct vlc_input_event) {
         .type = INPUT_EVENT_STATE,
-        .state = i_state
+        .state = { i_state, state_date, },
     });
 }
 
diff --git a/src/input/input.c b/src/input/input.c
index a15ce6cab9..2473cae292 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -116,7 +116,7 @@ static void AppendAttachment( int *pi_attachment, input_attachment_t ***ppp_atta
 static int input_SlaveSourceAdd( input_thread_t *, enum slave_type,
                                  const char *, unsigned );
 static char *input_SubtitleFile2Uri( input_thread_t *, const char * );
-static void input_ChangeState( input_thread_t *p_input, int i_state ); /* TODO fix name */
+static void input_ChangeState( input_thread_t *p_input, int i_state, vlc_tick_t ); /* TODO fix name */
 
 #undef input_Create
 /**
@@ -560,7 +560,7 @@ static void MainLoopDemux( input_thread_t *p_input, bool *pb_changed )
     }
     else if( i_ret == VLC_DEMUXER_EGENERIC )
     {
-        input_ChangeState( p_input, ERROR_S );
+        input_ChangeState( p_input, ERROR_S, VLC_TICK_INVALID );
     }
     else if( p_priv->i_slave > 0 )
         SlaveDemux( p_input );
@@ -797,7 +797,7 @@ static int InitSout( input_thread_t * p_input )
         priv->p_sout  = input_resource_RequestSout( priv->p_resource, NULL, psz );
         if( priv->p_sout == NULL )
         {
-            input_ChangeState( p_input, ERROR_S );
+            input_ChangeState( p_input, ERROR_S, VLC_TICK_INVALID );
             msg_Err( p_input, "cannot start stream output instance, " \
                               "aborting" );
             free( psz );
@@ -1233,7 +1233,7 @@ static int Init( input_thread_t * p_input )
     input_source_t *master;
 
     /* */
-    input_ChangeState( p_input, OPENING_S );
+    input_ChangeState( p_input, OPENING_S, VLC_TICK_INVALID );
     input_SendEventCache( p_input, 0.0 );
 
     if( var_Type( vlc_object_parent(p_input), "meta-file" ) )
@@ -1319,12 +1319,12 @@ static int Init( input_thread_t * p_input )
              input_priv(p_input)->p_item->psz_uri );
 
     /* initialization is complete */
-    input_ChangeState( p_input, PLAYING_S );
+    input_ChangeState( p_input, PLAYING_S, vlc_tick_now() );
 
     return VLC_SUCCESS;
 
 error:
-    input_ChangeState( p_input, ERROR_S );
+    input_ChangeState( p_input, ERROR_S, VLC_TICK_INVALID );
 
     if( input_priv(p_input)->p_es_out )
         es_out_Delete( input_priv(p_input)->p_es_out );
@@ -1357,7 +1357,7 @@ static void End( input_thread_t * p_input )
     input_thread_private_t *priv = input_priv(p_input);
 
     /* We are at the end */
-    input_ChangeState( p_input, END_S );
+    input_ChangeState( p_input, END_S, VLC_TICK_INVALID );
 
     /* Stop es out activity */
     es_out_SetMode( priv->p_es_out, ES_OUT_MODE_NONE );
@@ -1619,7 +1619,7 @@ static void ControlPause( input_thread_t *p_input, vlc_tick_t i_control_date )
     }
 
     /* Switch to new state */
-    input_ChangeState( p_input, i_state );
+    input_ChangeState( p_input, i_state, i_control_date );
 }
 
 static void ControlUnpause( input_thread_t *p_input, vlc_tick_t i_control_date )
@@ -1631,13 +1631,13 @@ static void ControlUnpause( input_thread_t *p_input, vlc_tick_t i_control_date )
         if( demux_Control( p_demux, DEMUX_SET_PAUSE_STATE, false ) )
         {
             msg_Err( p_input, "cannot resume" );
-            input_ChangeState( p_input, ERROR_S );
+            input_ChangeState( p_input, ERROR_S, i_control_date );
             return;
         }
     }
 
     /* Switch to play */
-    input_ChangeState( p_input, PLAYING_S );
+    input_ChangeState( p_input, PLAYING_S, i_control_date );
     es_out_SetPauseState( input_priv(p_input)->p_es_out, false, false, i_control_date );
 }
 
@@ -3079,7 +3079,8 @@ static void InputGetExtraFiles( input_thread_t *p_input,
 }
 
 /* */
-static void input_ChangeState( input_thread_t *p_input, int i_state )
+static void input_ChangeState( input_thread_t *p_input, int i_state,
+                               vlc_tick_t state_date )
 {
     if( input_priv(p_input)->i_state == i_state )
         return;
@@ -3087,7 +3088,7 @@ static void input_ChangeState( input_thread_t *p_input, int i_state )
     input_priv(p_input)->i_state = i_state;
     if( i_state == ERROR_S )
         input_item_SetErrorWhenReading( input_priv(p_input)->p_item, true );
-    input_SendEventState( p_input, i_state );
+    input_SendEventState( p_input, i_state, state_date );
 }
 
 
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index a627c2b080..67ee8a03ae 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -150,6 +150,13 @@ typedef enum input_event_type_e
 #define VLC_INPUT_CAPABILITIES_REWINDABLE (1<<3)
 #define VLC_INPUT_CAPABILITIES_RECORDABLE (1<<4)
 
+struct vlc_input_event_state
+{
+    input_state_e value;
+    /* Only valid for PAUSE_S and PLAYING_S states */
+    vlc_tick_t date;
+};
+
 struct vlc_input_event_times
 {
     float percentage;
@@ -248,7 +255,7 @@ struct vlc_input_event
 
     union {
         /* INPUT_EVENT_STATE */
-        input_state_e state;
+        struct vlc_input_event_state state;
         /* INPUT_EVENT_RATE */
         float rate;
         /* INPUT_EVENT_CAPABILITIES */
diff --git a/src/input/item.c b/src/input/item.c
index b1b92cdf9b..0fa056513a 100644
--- a/src/input/item.c
+++ b/src/input/item.c
@@ -1362,7 +1362,7 @@ input_item_parser_InputEvent(input_thread_t *input,
     switch (event->type)
     {
         case INPUT_EVENT_STATE:
-            parser->state = event->state;
+            parser->state = event->state.value;
             break;
         case INPUT_EVENT_DEAD:
         {
diff --git a/src/input/thumbnailer.c b/src/input/thumbnailer.c
index 524651364d..dbf23b5115 100644
--- a/src/input/thumbnailer.c
+++ b/src/input/thumbnailer.c
@@ -74,8 +74,8 @@ on_thumbnailer_input_event( input_thread_t *input,
 {
     VLC_UNUSED(input);
     if ( event->type != INPUT_EVENT_THUMBNAIL_READY &&
-         ( event->type != INPUT_EVENT_STATE || ( event->state != ERROR_S &&
-                                                 event->state != END_S ) ) )
+         ( event->type != INPUT_EVENT_STATE || ( event->state.value != ERROR_S &&
+                                                 event->state.value != END_S ) ) )
          return;
 
     vlc_thumbnailer_request_t* request = userdata;
diff --git a/src/player/input.c b/src/player/input.c
index 74cfd3272d..d63b2ff59c 100644
--- a/src/player/input.c
+++ b/src/player/input.c
@@ -112,7 +112,7 @@ vlc_player_WaitRetryDelay(vlc_player_t *player)
 
 void
 vlc_player_input_HandleState(struct vlc_player_input *input,
-                             enum vlc_player_state state)
+                             enum vlc_player_state state, vlc_tick_t state_date)
 {
     vlc_player_t *player = input->player;
 
@@ -206,21 +206,25 @@ vlc_player_input_HandleState(struct vlc_player_input *input,
 
 static void
 vlc_player_input_HandleStateEvent(struct vlc_player_input *input,
-                                  input_state_e state)
+                                  input_state_e state, vlc_tick_t state_date)
 {
     switch (state)
     {
         case OPENING_S:
-            vlc_player_input_HandleState(input, VLC_PLAYER_STATE_STARTED);
+            vlc_player_input_HandleState(input, VLC_PLAYER_STATE_STARTED,
+                                         VLC_TICK_INVALID);
             break;
         case PLAYING_S:
-            vlc_player_input_HandleState(input, VLC_PLAYER_STATE_PLAYING);
+            vlc_player_input_HandleState(input, VLC_PLAYER_STATE_PLAYING,
+                                         state_date);
             break;
         case PAUSE_S:
-            vlc_player_input_HandleState(input, VLC_PLAYER_STATE_PAUSED);
+            vlc_player_input_HandleState(input, VLC_PLAYER_STATE_PAUSED,
+                                         state_date);
             break;
         case END_S:
-            vlc_player_input_HandleState(input, VLC_PLAYER_STATE_STOPPING);
+            vlc_player_input_HandleState(input, VLC_PLAYER_STATE_STOPPING,
+                                         VLC_TICK_INVALID);
             vlc_player_destructor_AddStoppingInput(input->player, input);
             break;
         case ERROR_S:
@@ -574,7 +578,8 @@ input_thread_Events(input_thread_t *input_thread,
     switch (event->type)
     {
         case INPUT_EVENT_STATE:
-            vlc_player_input_HandleStateEvent(input, event->state);
+            vlc_player_input_HandleStateEvent(input, event->state.value,
+                                              event->state.date);
             break;
         case INPUT_EVENT_RATE:
             input->rate = event->rate;
@@ -653,7 +658,8 @@ input_thread_Events(input_thread_t *input_thread,
             break;
         case INPUT_EVENT_DEAD:
             if (input->started) /* Can happen with early input_thread fails */
-                vlc_player_input_HandleState(input, VLC_PLAYER_STATE_STOPPING);
+                vlc_player_input_HandleState(input, VLC_PLAYER_STATE_STOPPING,
+                                             VLC_TICK_INVALID);
             vlc_player_destructor_AddJoinableInput(player, input);
             break;
         case INPUT_EVENT_VBI_PAGE:
diff --git a/src/player/player.c b/src/player/player.c
index a0c421511b..b23b7ae212 100644
--- a/src/player/player.c
+++ b/src/player/player.c
@@ -203,7 +203,8 @@ vlc_player_destructor_Thread(void *data)
         struct vlc_player_input *input;
         vlc_list_foreach(input, &player->destructor.inputs, node)
         {
-            vlc_player_input_HandleState(input, VLC_PLAYER_STATE_STOPPING);
+            vlc_player_input_HandleState(input, VLC_PLAYER_STATE_STOPPING,
+                                         VLC_TICK_INVALID);
             vlc_player_destructor_AddStoppingInput(player, input);
 
             input_Stop(input->thread);
@@ -217,7 +218,8 @@ vlc_player_destructor_Thread(void *data)
             keep_sout = var_GetBool(input->thread, "sout-keep");
 
             if (input->state == VLC_PLAYER_STATE_STOPPING)
-                vlc_player_input_HandleState(input, VLC_PLAYER_STATE_STOPPED);
+                vlc_player_input_HandleState(input, VLC_PLAYER_STATE_STOPPED,
+                                             VLC_TICK_INVALID);
 
             vlc_list_remove(&input->node);
             vlc_player_input_Delete(input);
diff --git a/src/player/player.h b/src/player/player.h
index 36caa46299..576bc57110 100644
--- a/src/player/player.h
+++ b/src/player/player.h
@@ -309,7 +309,8 @@ int
 vlc_player_input_Start(struct vlc_player_input *input);
 
 void
-vlc_player_input_HandleState(struct vlc_player_input *, enum vlc_player_state);
+vlc_player_input_HandleState(struct vlc_player_input *, enum vlc_player_state,
+                             vlc_tick_t state_date);
 
 /*
  * player_vout.c
-- 
2.20.1



More information about the vlc-devel mailing list