Merge branch 'player-timer-fix-state-paused' into 'master'

player: timer: fix paused state overridden

Closes #28622

See merge request videolan/vlc!5353
This commit is contained in:
Thomas Guillem 2024-05-07 07:33:48 +00:00
commit 25ec5700ef
3 changed files with 37 additions and 39 deletions

View File

@ -272,12 +272,12 @@ vlc_player_input_HandleState(struct vlc_player_input *input,
case VLC_PLAYER_STATE_STOPPING:
input->started = false;
vlc_player_UpdateTimerState(player, NULL,
VLC_PLAYER_TIMER_STATE_DISCONTINUITY,
vlc_player_UpdateTimerEvent(player, NULL,
VLC_PLAYER_TIMER_EVENT_DISCONTINUITY,
VLC_TICK_INVALID);
vlc_player_UpdateTimerState(player, NULL,
VLC_PLAYER_TIMER_STATE_STOPPING,
vlc_player_UpdateTimerEvent(player, NULL,
VLC_PLAYER_TIMER_EVENT_STOPPING,
VLC_TICK_INVALID);
if (input == player->input)
@ -289,8 +289,8 @@ vlc_player_input_HandleState(struct vlc_player_input *input,
break;
case VLC_PLAYER_STATE_PLAYING:
input->pause_date = VLC_TICK_INVALID;
vlc_player_UpdateTimerState(player, NULL,
VLC_PLAYER_TIMER_STATE_PLAYING,
vlc_player_UpdateTimerEvent(player, NULL,
VLC_PLAYER_TIMER_EVENT_PLAYING,
input->pause_date);
/* fall through */
case VLC_PLAYER_STATE_STARTED:
@ -304,8 +304,8 @@ vlc_player_input_HandleState(struct vlc_player_input *input,
assert(state_date != VLC_TICK_INVALID);
input->pause_date = state_date;
vlc_player_UpdateTimerState(player, NULL,
VLC_PLAYER_TIMER_STATE_PAUSED,
vlc_player_UpdateTimerEvent(player, NULL,
VLC_PLAYER_TIMER_EVENT_PAUSED,
input->pause_date);
break;
default:
@ -884,8 +884,8 @@ input_thread_Events(input_thread_t *input_thread,
}
else
{
vlc_player_UpdateTimerState(player, event->output_clock.id,
VLC_PLAYER_TIMER_STATE_DISCONTINUITY,
vlc_player_UpdateTimerEvent(player, event->output_clock.id,
VLC_PLAYER_TIMER_EVENT_DISCONTINUITY,
VLC_TICK_INVALID);
}
return;
@ -986,8 +986,8 @@ input_thread_Events(input_thread_t *input_thread,
break;
case INPUT_EVENT_CACHE:
if (event->cache == 0.0f)
vlc_player_UpdateTimerState(player, NULL,
VLC_PLAYER_TIMER_STATE_DISCONTINUITY,
vlc_player_UpdateTimerEvent(player, NULL,
VLC_PLAYER_TIMER_EVENT_DISCONTINUITY,
VLC_TICK_INVALID);
input->cache = event->cache;
vlc_player_SendEvent(player, on_buffering_changed, event->cache);

View File

@ -203,20 +203,18 @@ struct vlc_player_timer_source
};
};
enum vlc_player_timer_state
enum vlc_player_timer_event
{
VLC_PLAYER_TIMER_STATE_PLAYING,
VLC_PLAYER_TIMER_STATE_PAUSED,
VLC_PLAYER_TIMER_STATE_DISCONTINUITY,
VLC_PLAYER_TIMER_STATE_STOPPING,
VLC_PLAYER_TIMER_EVENT_PLAYING,
VLC_PLAYER_TIMER_EVENT_PAUSED,
VLC_PLAYER_TIMER_EVENT_DISCONTINUITY,
VLC_PLAYER_TIMER_EVENT_STOPPING,
};
struct vlc_player_timer
{
vlc_mutex_t lock;
enum vlc_player_timer_state state;
vlc_tick_t input_length;
vlc_tick_t input_normal_time;
vlc_tick_t last_ts;
@ -224,6 +222,8 @@ struct vlc_player_timer
vlc_tick_t seek_ts;
double seek_position;
bool paused;
bool stopping;
bool seeking;
struct vlc_player_timer_source sources[VLC_PLAYER_TIMER_TYPE_COUNT];
@ -476,8 +476,8 @@ void
vlc_player_ResetTimer(vlc_player_t *player);
void
vlc_player_UpdateTimerState(vlc_player_t *player, vlc_es_id_t *es_source,
enum vlc_player_timer_state state,
vlc_player_UpdateTimerEvent(vlc_player_t *player, vlc_es_id_t *es_source,
enum vlc_player_timer_event event,
vlc_tick_t system_date);
void

View File

@ -31,7 +31,6 @@ vlc_player_ResetTimer(vlc_player_t *player)
{
vlc_mutex_lock(&player->timer.lock);
player->timer.state = VLC_PLAYER_TIMER_STATE_DISCONTINUITY;
player->timer.input_length = VLC_TICK_INVALID;
player->timer.input_normal_time = VLC_TICK_0;
player->timer.last_ts = VLC_TICK_INVALID;
@ -39,7 +38,9 @@ vlc_player_ResetTimer(vlc_player_t *player)
player->timer.smpte_source.smpte.last_framenum = ULONG_MAX;
player->timer.seek_ts = VLC_TICK_INVALID;
player->timer.seek_position = -1;
player->timer.paused = false;
player->timer.seeking = false;
player->timer.stopping = false;
vlc_mutex_unlock(&player->timer.lock);
}
@ -190,8 +191,8 @@ vlc_player_UpdateSmpteTimerFPS(vlc_player_t *player,
}
void
vlc_player_UpdateTimerState(vlc_player_t *player, vlc_es_id_t *es_source,
enum vlc_player_timer_state state,
vlc_player_UpdateTimerEvent(vlc_player_t *player, vlc_es_id_t *es_source,
enum vlc_player_timer_event event,
vlc_tick_t system_date)
{
vlc_mutex_lock(&player->timer.lock);
@ -202,9 +203,9 @@ vlc_player_UpdateTimerState(vlc_player_t *player, vlc_es_id_t *es_source,
bool notify = false;
struct vlc_player_timer_source *bestsource = &player->timer.best_source;
switch(state)
switch (event)
{
case VLC_PLAYER_TIMER_STATE_DISCONTINUITY:
case VLC_PLAYER_TIMER_EVENT_DISCONTINUITY:
assert(system_date == VLC_TICK_INVALID);
for (size_t i = 0; i < VLC_PLAYER_TIMER_TYPE_COUNT; ++i)
{
@ -232,24 +233,25 @@ vlc_player_UpdateTimerState(vlc_player_t *player, vlc_es_id_t *es_source,
}
break;
case VLC_PLAYER_TIMER_STATE_PAUSED:
case VLC_PLAYER_TIMER_EVENT_PAUSED:
notify = true;
assert(system_date != VLC_TICK_INVALID);
player->timer.paused = true;
break;
case VLC_PLAYER_TIMER_STATE_PLAYING:
case VLC_PLAYER_TIMER_EVENT_PLAYING:
assert(!player->timer.stopping);
player->timer.paused = false;
break;
case VLC_PLAYER_TIMER_STATE_STOPPING:
case VLC_PLAYER_TIMER_EVENT_STOPPING:
player->timer.stopping = true;
break;
default:
vlc_assert_unreachable();
}
if (player->timer.state != VLC_PLAYER_TIMER_STATE_STOPPING)
player->timer.state = state;
if (!notify)
{
vlc_mutex_unlock(&player->timer.lock);
@ -351,7 +353,7 @@ vlc_player_UpdateTimerBestSource(vlc_player_t *player, vlc_es_id_t *es_source,
*/
struct vlc_player_timer_source *source = &player->timer.best_source;
if (!source->es || es_source_is_master
|| (es_source && player->timer.state == VLC_PLAYER_TIMER_STATE_PAUSED))
|| (es_source && player->timer.paused))
source->es = es_source;
/* Notify the best source */
@ -472,14 +474,10 @@ vlc_player_UpdateTimer(vlc_player_t *player, vlc_es_id_t *es_source,
assert(point->ts != VLC_TICK_INVALID);
vlc_tick_t system_date = point->system_date;
if (player->timer.state == VLC_PLAYER_TIMER_STATE_PAUSED)
if (player->timer.paused)
system_date = VLC_TICK_MAX;
/* An update after a discontinuity means that the playback is resumed */
if (player->timer.state == VLC_PLAYER_TIMER_STATE_DISCONTINUITY)
player->timer.state = VLC_PLAYER_TIMER_STATE_PLAYING;
if (player->timer.state != VLC_PLAYER_TIMER_STATE_STOPPING)
if (!player->timer.stopping)
vlc_player_UpdateTimerBestSource(player, es_source,
es_source_is_master, point, system_date,
force_update);