From a1b192fb4b93fb668cd410930d58aeab2c49013b Mon Sep 17 00:00:00 2001 From: Thomas Guillem Date: Thu, 27 Nov 2025 10:24:52 +0100 Subject: [PATCH] input: add external EOF handling The INPUT_EVENT_EOF listener can return true if it handles the EOF itself. In that case, the input_thread_t will wait for any controls (input_Stop() will definitively stop it). No changes if the event is not handled. --- src/input/input.c | 18 +++++++++++++++++- src/input/input_internal.h | 3 +++ src/player/input.c | 3 +++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/input/input.c b/src/input/input.c index c283faa493..8530fa9bba 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -664,6 +664,7 @@ static void MainLoop( input_thread_t *p_input, bool b_interactive ) bool b_pause_after_eof = b_interactive && var_InheritBool( p_input, "play-and-pause" ); bool b_paused_at_eof = false; + bool eof_signaled = false; demux_t *p_demux = input_priv(p_input)->master->p_demux; const bool b_can_demux = p_demux->ops != NULL ? @@ -695,6 +696,7 @@ static void MainLoop( input_thread_t *p_input, bool b_interactive ) i_intf_update = 0; b_paused_at_eof = false; + eof_signaled = false; } else if( !es_out_IsEmpty( input_priv(p_input)->p_es_out ) ) { @@ -703,9 +705,23 @@ static void MainLoop( input_thread_t *p_input, bool b_interactive ) } else { + bool eof_handled; + if( !eof_signaled ) + { + eof_handled = + input_SendEvent(p_input, &(struct vlc_input_event) { + .type = INPUT_EVENT_EOF, + }); + eof_signaled = true; + } + else + eof_handled = true; + + if (eof_handled) + i_wakeup = -1; /* Pause after eof only if the input is pausable. * This way we won't trigger timeshifting for nothing */ - if( b_pause_after_eof && input_priv(p_input)->master->b_can_pause ) + else if( b_pause_after_eof && input_priv(p_input)->master->b_can_pause ) { if( b_paused_at_eof ) break; diff --git a/src/input/input_internal.h b/src/input/input_internal.h index 0854a908d2..925632d4be 100644 --- a/src/input/input_internal.h +++ b/src/input/input_internal.h @@ -82,6 +82,9 @@ typedef enum input_event_type_e INPUT_EVENT_STATE, /* b_dead is true */ INPUT_EVENT_DEAD, + /* If the event is not handled, or if the listener is returning false, + * the input will be stopped normally at EOF */ + INPUT_EVENT_EOF, /* "rate" has changed */ INPUT_EVENT_RATE, diff --git a/src/player/input.c b/src/player/input.c index 629f5b11a9..e702c33dc8 100644 --- a/src/player/input.c +++ b/src/player/input.c @@ -926,6 +926,9 @@ input_thread_Events(input_thread_t *input_thread, vlc_player_input_HandleStateEvent(input, event->state.value, event->state.date); break; + case INPUT_EVENT_EOF: + handled = false; + break; case INPUT_EVENT_RATE: input->rate = event->rate; vlc_player_SendEvent(player, on_rate_changed, input->rate);