[vlc-commits] [Git][videolan/vlc][master] 2 commits: player: fix the reason passed to on_stopping_current_media

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Thu Oct 1 13:43:44 UTC 2026



Felix Paul Kühne pushed to branch master at VideoLAN / VLC


Commits:
7cbc627c by Ayush Dey at 2026-10-01T15:28:34+02:00
player: fix the reason passed to on_stopping_current_media

This commit fixes two situations in which an incorrect reason was
being passed to on_stopping_current_media:
- An error during playback was reported as EOS because END_S
overwrote VLC_PLAYER_MEDIA_STOPPING_ERROR.
- Suppose a user requests a stop and releases the player lock. And,
before the vlc-player-end thread could acquire the lock, the input
thread acquires it and emits END_S. In this case, an EOS/ERROR was
reported even though vlc_player_Stop returned VLC_SUCCESS. This
behaviour was also inconsistent with the on_error_changed callback's
behaviour, which only reports an error if the user didn't stop
before the error occurred.

- - - - -
e175eb55 by Ayush Dey at 2026-10-01T15:28:34+02:00
player: remove unreachable fallback on INPUT_EVENT_DEAD

Since 5b3b0f03b2744d8e9a626e9fb77f14a0723c83a0, input->started is
always unset when INPUT_EVENT_DEAD arrives, because ERROR_S, END_S
or user stop has already moved it to STOPPING state where the flag
has been cleared.

- - - - -


6 changed files:

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


Changes:

=====================================
include/vlc/libvlc_media_player.h
=====================================
@@ -209,7 +209,7 @@ typedef enum libvlc_list_action_t {
  * Enumeration of media stopping reasons
  */
 typedef enum libvlc_stopping_reason_t {
-    /** media is stopping due to an error (default) */
+    /** media is stopping due to an error */
     libvlc_stopping_reason_error,
     /** media has reached the end of stream */
     libvlc_stopping_reason_eos,


=====================================
include/vlc_player.h
=====================================
@@ -325,7 +325,7 @@ enum vlc_player_abloop
  */
 enum vlc_player_media_stopping_reason
 {
-    /** The media is stopping because of an error (default) */
+    /** The media is stopping because of an error */
     VLC_PLAYER_MEDIA_STOPPING_ERROR,
     /** The media reached the end of stream */
     VLC_PLAYER_MEDIA_STOPPING_EOS,


=====================================
lib/media_player.c
=====================================
@@ -104,7 +104,6 @@ on_stopping_current_media(vlc_player_t *player, input_item_t *item,
 {
     assert(item != NULL);
     (void) player;
-    (void) stopping_reason;
 
     libvlc_media_player_t *mp = data;
 


=====================================
src/player/input.c
=====================================
@@ -279,6 +279,19 @@ vlc_player_input_HandleState(struct vlc_player_input *input,
             send_event = !player->started && last_state != VLC_PLAYER_STATE_STOPPED;
             break;
         case VLC_PLAYER_STATE_STOPPING:
+        {
+            enum vlc_player_media_stopping_reason reason;
+            /* The order matters. input->error is only set while the
+               input->started flag is set, so an error or EOS that follows a
+               user stop request is ignored and the stop is reported as USER,
+               whereas an error that occurred before a user stop request takes
+               precedence and is reported as ERROR. */
+            if (input->error != VLC_PLAYER_ERROR_NONE)
+                reason = VLC_PLAYER_MEDIA_STOPPING_ERROR;
+            else if (!input->started)
+                reason = VLC_PLAYER_MEDIA_STOPPING_USER;
+            else
+                reason = VLC_PLAYER_MEDIA_STOPPING_EOS;
             input->started = false;
 
             /* Note: no need to hold the media here, as it is already protected
@@ -286,7 +299,7 @@ vlc_player_input_HandleState(struct vlc_player_input *input,
                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);
+                                 media, reason);
 
             vlc_player_UpdateTimerEvent(player, NULL,
                                         VLC_PLAYER_TIMER_EVENT_DISCONTINUITY,
@@ -303,6 +316,7 @@ vlc_player_input_HandleState(struct vlc_player_input *input,
                 player->started = false;
             send_event = !player->started;
             break;
+        }
         case VLC_PLAYER_STATE_PLAYING:
             input->pause_date = VLC_TICK_INVALID;
             vlc_player_SignalAtoBLoop(player);
@@ -361,7 +375,6 @@ 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);
@@ -370,7 +383,7 @@ vlc_player_input_HandleStateEvent(struct vlc_player_input *input,
             /* Don't send errors if the input is stopped by the user */
             if (input->started)
             {
-                /* Contrary to the input_thead_t, an error is not a state */
+                /* Contrary to the input_thread_t, an error is not a state */
                 input->error = VLC_PLAYER_ERROR_GENERIC;
                 vlc_player_SendEvent(input->player, on_error_changed, input->error);
             }
@@ -379,7 +392,6 @@ 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);
@@ -1149,12 +1161,6 @@ input_thread_Events(input_thread_t *input_thread,
             input_item_node_Delete(event->subitems);
             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:
@@ -1249,7 +1255,6 @@ 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
=====================================
@@ -251,7 +251,6 @@ vlc_player_mainloop_Thread(void *data)
         vlc_list_foreach(input, &player->mainloop.stop_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);


=====================================
src/player/player.h
=====================================
@@ -65,7 +65,6 @@ 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/15b71e3fa6d49ed2845dfb1324760984eae6101c...e175eb550e986e1d10550992b03e4d451a3ec6f2

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/15b71e3fa6d49ed2845dfb1324760984eae6101c...e175eb550e986e1d10550992b03e4d451a3ec6f2
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the vlc-commits mailing list