This commit is contained in:
Dexter Gaon-Shatford 2024-05-03 19:46:45 +03:00 committed by GitHub
commit 6b7567543e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 45 additions and 0 deletions

View File

@ -237,6 +237,21 @@ Playback Control
speed higher than normal automatically inserts the ``scaletempo2`` audio
filter.
``--rt-catchup``
Enable the player to speed up by a factor equal to the sum of 1, and the
square of the product of how many seconds behind the the delay given by
``--rt-catchup-max-delay`` the player has fallen and the value given by
``--rt-catchup-multiplier`` unless the delay does not exceed the delay
given by ``--rt-catchup-max-delay``.
``--rt-catchup-max-delay=<0.0..>``
The maximum delay in seconds behind the media source the player may reach
before it starts speeding up, if ``--rt-catchup`` is enabled.
``--rt-catchup-multiplier=<0.0..>``
A coefficient applied during the speed multiplier calculation according to
``--rt-catchup`` and ``--rt-catchup-max-delay``
``--pause``
Start the player in paused state.

View File

@ -657,6 +657,13 @@ static const m_option_t mp_opts[] = {
// set a-v distance
{"audio-delay", OPT_FLOAT(audio_delay)},
// set live/realtime catch-up parameters
{"rt-catchup", OPT_FLAG(realtime_catchup)},
{"rt-catchup-multiplier", OPT_DOUBLE(realtime_catchup_speed_multiplier),
M_RANGE(0, DBL_MAX)},
{"rt-catchup-max-delay", OPT_DOUBLE(realtime_catchup_max_delay),
M_RANGE(0, DBL_MAX)},
// ------------------------- codec/vfilter options --------------------
{"af", OPT_SETTINGSLIST(af_settings, &af_obj_list)},

View File

@ -245,6 +245,9 @@ typedef struct MPOpts {
bool hr_seek_framedrop;
float audio_delay;
float default_max_pts_correction;
int realtime_catchup;
double realtime_catchup_speed_multiplier;
double realtime_catchup_max_delay;
int autosync;
int frame_dropping;
bool video_latency_hacks;

View File

@ -182,9 +182,29 @@ void audio_update_volume(struct MPContext *mpctx)
ao_set_gain(ao_c->ao, gain);
}
// Calculate a speed multiplier proportional to the delay between the current
// playback time and the media source. This multiplier is used to keep up with a
// real-time source such as a live stream.
static double calc_realtime_catchup_speed(struct MPContext *mpctx)
{
double max_delay = mpctx->opts->realtime_catchup_max_delay;
double delay = get_time_length(mpctx) - get_playback_time(mpctx);
if (delay > max_delay) {
double multiplier = mpctx->opts->realtime_catchup_speed_multiplier;
return 1.0 + powf((delay - max_delay) * multiplier, 2.0);
} else {
return 1.0;
}
}
// Call this if opts->playback_speed or mpctx->speed_factor_* change.
void update_playback_speed(struct MPContext *mpctx)
{
if (mpctx->opts->realtime_catchup) {
mpctx->opts->playback_speed = calc_realtime_catchup_speed(mpctx);
}
mpctx->audio_speed = mpctx->opts->playback_speed * mpctx->speed_factor_a;
mpctx->video_speed = mpctx->opts->playback_speed * mpctx->speed_factor_v;