Skip to content
Snippets Groups Projects
Commit e759db90 authored by Romain Vimont's avatar Romain Vimont Committed by Hugo Beauzée-Luyssen
Browse files

player: temporize on EOS bursts

A mechanism was implemented to temporize on consecutive input errors, to
mitigate infinite busy loops (see commit
d0662265).

Although it avoided the most common issues, this mechanism was not
triggered for other problematic cases:
 - empty inputs;
 - inputs with unreported errors from demuxers.

Therefore, to encompass these other cases, consider the number of
consecutive stops in a small period of time instead of relying on
reported errors:
 - if a VLC_PLAYER_STATE_STOPPED occurs less than 100ms after the
   previous one, then increment the EOS burst count;
 - when more than 4 EOS burst count occur successively, start
   temporizing:
     - 100ms for the 5th
     - 200ms for the 6th
     - 400ms for the 7th
     - 800ms for the 8th
     - 1.6s for the 9th
     - 3.2s for the following

Fixes #5901
Fixes #26733
parent b65cd1f0
No related branches found
No related tags found
1 merge request!1639player: temporize on EOS bursts
Pipeline #203553 passed with stage
in 28 minutes and 22 seconds
......@@ -105,19 +105,21 @@ vlc_player_WaitRetryDelay(vlc_player_t *player)
{
#define RETRY_TIMEOUT_BASE VLC_TICK_FROM_MS(100)
#define RETRY_TIMEOUT_MAX VLC_TICK_FROM_MS(3200)
if (player->error_count)
#define MAX_EOS_BURST 4
/* Temporize only after a few successive EOS */
if (player->eos_burst_count > MAX_EOS_BURST)
{
/* Delay the next opening in case of error to avoid busy loops */
unsigned pow = player->eos_burst_count - MAX_EOS_BURST;
/* Delay the next opening to avoid busy loops */
vlc_tick_t delay = RETRY_TIMEOUT_BASE;
for (unsigned i = 1; i < player->error_count
&& delay < RETRY_TIMEOUT_MAX; ++i)
for (unsigned i = 1; i < pow && delay < RETRY_TIMEOUT_MAX; ++i)
delay *= 2; /* Wait 100, 200, 400, 800, 1600 and finally 3200ms */
delay += vlc_tick_now();
while (player->error_count > 0
while (player->eos_burst_count != 0
&& vlc_cond_timedwait(&player->start_delay_cond, &player->lock,
delay) == 0);
if (player->error_count == 0)
if (player->eos_burst_count == 0)
return false; /* canceled */
}
return true;
......@@ -156,13 +158,20 @@ vlc_player_input_HandleState(struct vlc_player_input *input,
vlc_player_ResetTimer(player);
if (input->error != VLC_PLAYER_ERROR_NONE)
player->error_count++;
else
player->error_count = 0;
if (player->last_eos != VLC_TICK_INVALID)
{
vlc_tick_t diff = vlc_tick_now() - player->last_eos;
if (diff < VLC_PLAYER_EOS_BURST_THRESHOLD)
++player->eos_burst_count;
else
player->eos_burst_count = 0;
}
vlc_player_WaitRetryDelay(player);
/* Assign the current date after the wait */
player->last_eos = vlc_tick_now();
if (!player->deleting)
vlc_player_OpenNextMedia(player);
if (!player->input)
......
......@@ -119,9 +119,9 @@ vlc_player_OpenNextMedia(vlc_player_t *player)
static void
vlc_player_CancelWaitError(vlc_player_t *player)
{
if (player->error_count != 0)
if (player->eos_burst_count != 0)
{
player->error_count = 0;
player->eos_burst_count = 0;
vlc_cond_signal(&player->start_delay_cond);
}
}
......@@ -1952,7 +1952,8 @@ vlc_player_New(vlc_object_t *parent, enum vlc_player_lock_type lock_type,
player->global_state = VLC_PLAYER_STATE_STOPPED;
player->started = false;
player->error_count = 0;
player->last_eos = VLC_TICK_INVALID;
player->eos_burst_count = 0;
player->releasing_media = false;
player->next_media_requested = false;
......
......@@ -267,7 +267,14 @@ struct vlc_player_t
enum vlc_player_state global_state;
bool started;
unsigned error_count;
/**
* Playing a tiny stream (either empty, or with unreported errors) in a loop
* would cause high CPU usage. To mitigate the problem, temporize if
* several EOS are received too quickly.
*/
#define VLC_PLAYER_EOS_BURST_THRESHOLD VLC_TICK_FROM_MS(250)
vlc_tick_t last_eos;
unsigned eos_burst_count;
bool deleting;
struct
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment