Commit 91530a28 authored by Niklas Haas's avatar Niklas Haas
Browse files

utils/frame_queue: sanitize incoming fps/vps estimates

These can easily end up as Infinity, NaN or other magic values in the
cases where e.g. the user naively passes in values computed from streams
without known FPS, such as `plplay` currently does.
parent f60a8783
...@@ -219,8 +219,8 @@ static void report_estimates(struct pl_queue *p) ...@@ -219,8 +219,8 @@ static void report_estimates(struct pl_queue *p)
{ {
if (p->fps.total >= MIN_SAMPLES && p->vps.total >= MIN_SAMPLES) { if (p->fps.total >= MIN_SAMPLES && p->vps.total >= MIN_SAMPLES) {
if (p->reported_fps && p->reported_vps) { if (p->reported_fps && p->reported_vps) {
// Only re-eport the estimates if they've changed considerably from // Only re-report the estimates if they've changed considerably
// the previously reported values // from the previously reported values
static const float report_delta = 0.3; static const float report_delta = 0.3;
float delta_fps = delta(p->reported_fps, p->fps.estimate); float delta_fps = delta(p->reported_fps, p->fps.estimate);
float delta_vps = delta(p->reported_vps, p->vps.estimate); float delta_vps = delta(p->reported_vps, p->vps.estimate);
...@@ -508,12 +508,18 @@ static bool prefill(struct pl_queue *p, const struct pl_queue_params *params) ...@@ -508,12 +508,18 @@ static bool prefill(struct pl_queue *p, const struct pl_queue_params *params)
return true; return true;
} }
static inline void default_estimate(struct pool *pool, float val)
{
if (!pool->estimate && isnormal(val) && val > 0.0)
pool->estimate = val;
}
enum pl_queue_status pl_queue_update(struct pl_queue *p, enum pl_queue_status pl_queue_update(struct pl_queue *p,
struct pl_frame_mix *out_mix, struct pl_frame_mix *out_mix,
const struct pl_queue_params *params) const struct pl_queue_params *params)
{ {
p->fps.estimate = PL_DEF(p->fps.estimate, params->frame_duration); default_estimate(&p->fps, params->frame_duration);
p->vps.estimate = PL_DEF(p->vps.estimate, params->vsync_duration); default_estimate(&p->vps, params->vsync_duration);
float delta = params->pts - p->prev_pts; float delta = params->pts - p->prev_pts;
if (delta < 0.0) { if (delta < 0.0) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment