[vlc-commits] [Git][videolan/vlc][master] 3 commits: player: call input_Stop before reporting the stopping state

Thomas Guillem (@tguillem) gitlab at videolan.org
Mon Dec 1 05:19:08 UTC 2025



Thomas Guillem pushed to branch master at VideoLAN / VLC


Commits:
81d88be5 by Ayush Dey at 2025-12-01T04:53:48+00:00
player: call input_Stop before reporting the stopping state

Ensure that the player notifies the user about the stopping state
after the underlying input_thread begins stopping. Also, this is
required for the next commit, where the on_stopping_current_media
event notification will be moved inside vlc_player_input_HandleState

- - - - -
1d4af114 by Ayush Dey at 2025-12-01T04:53:48+00:00
player: report on_stopping_current_media for all stopping scenarios

Previously, on_stopping_current_media was emitted only when
the user stopped the media.
The callback notification is moved into vlc_player_input_HandleState,
ensuring it is reported when media reaches EOS, errors out,
or is stopped by the user.

- - - - -
fe65b13d by Ayush Dey at 2025-12-01T04:53:48+00:00
player: expose media stopping reason via on_stopping_current_media

Add an enum to expose whether media is stopping due to user request,
reaching EOS or encountering an error.

- - - - -


5 changed files:

- include/vlc_player.h
- lib/media_player.c
- src/player/input.c
- src/player/player.c
- src/player/player.h


Changes:

=====================================
include/vlc_player.h
=====================================
@@ -302,6 +302,19 @@ enum vlc_player_abloop
     VLC_PLAYER_ABLOOP_B,
 };
 
+/**
+ * Reason why the current media is stopping
+ */
+enum vlc_player_media_stopping_reason
+{
+    /** The media is stopping because of an error (default) */
+    VLC_PLAYER_MEDIA_STOPPING_ERROR,
+    /** The media reached the end of stream */
+    VLC_PLAYER_MEDIA_STOPPING_EOS,
+    /** The media is stopping because of a user request */
+    VLC_PLAYER_MEDIA_STOPPING_USER,
+};
+
 /** Player capability: can seek */
 #define VLC_PLAYER_CAP_SEEK (1<<0)
 /** Player capability: can pause */
@@ -3272,17 +3285,20 @@ struct vlc_player_cbs
      *
      * @note This can be called from the PLAYING state, before the
      * player requests the next media, or from the STOPPING state, ie.
-     * when the player is stopping.
+     * when the player is stopping, or by an internal transition
+     * (e.g., when the media reaches the end of file or errors out).
      *
      * @see vlc_player_SetCurrentMedia()
      * @see vlc_player_Stop()
      *
      * @param player locked player instance
-     * @param prev_media media currently stopping
+     * @param current_media media currently stopping
+     * @param stopping_reason reason why the media is stopping
      * @param data opaque pointer set by vlc_player_AddListener()
      */
-    void (*on_stopping_current_media)(vlc_player_t *player,
-            input_item_t *current_media, void *data);
+    void (*on_stopping_current_media)(vlc_player_t *player, input_item_t *current_media,
+                                      enum vlc_player_media_stopping_reason stopping_reason,
+                                      void *data);
 };
 
 /**


=====================================
lib/media_player.c
=====================================
@@ -79,10 +79,12 @@ on_current_media_changed(vlc_player_t *player, input_item_t *new_media,
 
 static void
 on_stopping_current_media(vlc_player_t *player, input_item_t *media,
-                         void *data)
+                          enum vlc_player_media_stopping_reason stopping_reason,
+                          void *data)
 {
     assert(media != NULL);
     (void) player;
+    (void) stopping_reason;
 
     libvlc_media_player_t *mp = data;
 


=====================================
src/player/input.c
=====================================
@@ -272,6 +272,13 @@ vlc_player_input_HandleState(struct vlc_player_input *input,
         case VLC_PLAYER_STATE_STOPPING:
             input->started = false;
 
+            /* Note: no need to hold the media here, as it is already protected
+               by the player lock. User can hold the input_item, if they want
+               to use it beyond the callback scope. */
+            input_item_t *media = input_GetItem(input->thread);
+            vlc_player_SendEvent(player, on_stopping_current_media,
+                                 media, input->stopping_reason);
+
             vlc_player_UpdateTimerEvent(player, NULL,
                                         VLC_PLAYER_TIMER_EVENT_DISCONTINUITY,
                                         VLC_TICK_INVALID);
@@ -341,6 +348,7 @@ vlc_player_input_HandleStateEvent(struct vlc_player_input *input,
             break;
         case END_S:
             input->playing = false;
+            input->stopping_reason = VLC_PLAYER_MEDIA_STOPPING_EOS;
             vlc_player_input_HandleState(input, VLC_PLAYER_STATE_STOPPING,
                                          VLC_TICK_INVALID);
             vlc_player_destructor_AddStoppingInput(input->player, input);
@@ -358,6 +366,7 @@ vlc_player_input_HandleStateEvent(struct vlc_player_input *input,
              * the input thread and we won't reach END_S. */
             if (!input->playing)
             {
+                input->stopping_reason = VLC_PLAYER_MEDIA_STOPPING_ERROR;
                 vlc_player_input_HandleState(input, VLC_PLAYER_STATE_STOPPING,
                                              VLC_TICK_INVALID);
                 vlc_player_destructor_AddStoppingInput(input->player, input);
@@ -1036,8 +1045,11 @@ input_thread_Events(input_thread_t *input_thread,
             break;
         case INPUT_EVENT_DEAD:
             if (input->started) /* Can happen with early input_thread fails */
+            {
+                input->stopping_reason = VLC_PLAYER_MEDIA_STOPPING_ERROR;
                 vlc_player_input_HandleState(input, VLC_PLAYER_STATE_STOPPING,
                                              VLC_TICK_INVALID);
+            }
             vlc_player_destructor_AddJoinableInput(player, input);
             break;
         case INPUT_EVENT_VBI_PAGE:
@@ -1124,6 +1136,7 @@ vlc_player_input_New(vlc_player_t *player, input_item_t *item)
 
     input->state = VLC_PLAYER_STATE_STOPPED;
     input->error = VLC_PLAYER_ERROR_NONE;
+    input->stopping_reason = VLC_PLAYER_MEDIA_STOPPING_ERROR;
     input->rate = 1.f;
     input->capabilities = 0;
     input->length = input->time = VLC_TICK_INVALID;


=====================================
src/player/player.c
=====================================
@@ -202,16 +202,11 @@ vlc_player_destructor_Thread(void *data)
         struct vlc_player_input *input;
         vlc_list_foreach(input, &player->destructor.inputs, node)
         {
+            input_Stop(input->thread);
+            input->stopping_reason = VLC_PLAYER_MEDIA_STOPPING_USER;
             vlc_player_input_HandleState(input, VLC_PLAYER_STATE_STOPPING,
                                          VLC_TICK_INVALID);
             vlc_player_destructor_AddStoppingInput(player, input);
-
-            /* Note: no need to hold the media here, it will be valid
-             * until input_Close() and the event is sent from the thread
-             * that will call this function. */
-            input_item_t *media = input_GetItem(input->thread);
-            input_Stop(input->thread);
-            vlc_player_SendEvent(player, on_stopping_current_media, media);
         }
 
         bool keep_sout = true;


=====================================
src/player/player.h
=====================================
@@ -65,6 +65,7 @@ struct vlc_player_input
 
     enum vlc_player_state state;
     enum vlc_player_error error;
+    enum vlc_player_media_stopping_reason stopping_reason;
     float rate;
     int capabilities;
     vlc_tick_t length;



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/7775fc1eaf467d8d1640df3af871e4bbac1c2950...fe65b13db01c470b34da1c647c5e6b0b395747a9

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/7775fc1eaf467d8d1640df3af871e4bbac1c2950...fe65b13db01c470b34da1c647c5e6b0b395747a9
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list