Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dejitter debug #982

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/upipe/uprobe_dejitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ struct uprobe_dejitter {
/** cr_sys of the last debug print */
uint64_t last_print;

/** initial offset between cr_sys and cr_prog */
int64_t first_real_offset;

/** structure exported to modules */
struct uprobe uprobe;
};
Expand Down
28 changes: 19 additions & 9 deletions lib/upipe/uprobe_dejitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,14 @@ static int uprobe_dejitter_clock_ref(struct uprobe *uprobe, struct upipe *upipe,
if (unlikely(discontinuity)) {
uprobe_dejitter->offset_count = 0;
uprobe_dejitter->offset = 0;
uprobe_dejitter->first_real_offset = 0;
/* but do not reset the deviation */
}

/* offset has an arbitrary value, as it is the difference between 2 unrelated clocks. */
if (uprobe_dejitter->first_real_offset == 0)
uprobe_dejitter->first_real_offset = offset;

/* low-pass filter */
uprobe_dejitter->offset =
(uprobe_dejitter->offset * uprobe_dejitter->offset_count + offset) /
Expand All @@ -121,10 +126,11 @@ static int uprobe_dejitter_clock_ref(struct uprobe *uprobe, struct upipe *upipe,
uprobe_dejitter->offset_count++;

double deviation = offset - uprobe_dejitter->offset;
uprobe_dejitter->deviation =
sqrt((uprobe_dejitter->deviation * uprobe_dejitter->deviation *
uprobe_dejitter->deviation_count + deviation * deviation) /
(uprobe_dejitter->deviation_count + 1));
if (uprobe_dejitter->deviation_count)
uprobe_dejitter->deviation =
sqrt((uprobe_dejitter->deviation * uprobe_dejitter->deviation *
uprobe_dejitter->deviation_count + deviation * deviation) /
(uprobe_dejitter->deviation_count + 1));
if (uprobe_dejitter->deviation_count < uprobe_dejitter->deviation_divider)
uprobe_dejitter->deviation_count++;

Expand Down Expand Up @@ -194,16 +200,19 @@ static int uprobe_dejitter_clock_ref(struct uprobe *uprobe, struct upipe *upipe,

if (cr_sys > uprobe_dejitter->last_print + PRINT_PERIODICITY) {
upipe_dbg_va(upipe,
"dejitter drift %f error %"PRId64" deviation %g",
"dejitter drift %f error %g us deviation %g us",
(double)uprobe_dejitter->drift_rate.num /
uprobe_dejitter->drift_rate.den,
error_offset, uprobe_dejitter->deviation);
(double)error_offset * 1000000 / UCLOCK_FREQ,
uprobe_dejitter->deviation * 1000000 / UCLOCK_FREQ);
uprobe_dejitter->last_print = cr_sys;
}

upipe_verbose_va(upipe,
"new ref offset %"PRId64" error %"PRId64" deviation %g",
real_offset, error_offset, uprobe_dejitter->deviation);
"new ref offset %g us error %g us deviation %g us",
(double)(real_offset - uprobe_dejitter->first_real_offset) * 1000000. / UCLOCK_FREQ,
(double)error_offset * 1000000. / UCLOCK_FREQ,
uprobe_dejitter->deviation * 1000000. / UCLOCK_FREQ);
return UBASE_ERR_NONE;
}

Expand Down Expand Up @@ -282,7 +291,8 @@ void uprobe_dejitter_set(struct uprobe *uprobe, bool enabled,
uprobe_dejitter->offset_divider = enabled ? OFFSET_DIVIDER : 0;
uprobe_dejitter->deviation_divider = enabled ? DEVIATION_DIVIDER : 0;
uprobe_dejitter->offset_count = 0;
uprobe_dejitter->deviation_count = 1;
uprobe_dejitter->first_real_offset = 0;
uprobe_dejitter->deviation_count = 0;
uprobe_dejitter->offset = 0;
if (deviation)
uprobe_dejitter->deviation = deviation;
Expand Down
4 changes: 2 additions & 2 deletions tests/uprobe_dejitter_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ int main(int argc, char **argv)
uref_clock_set_pts_prog(uref, clock);
upipe_throw_clock_ts(upipe, uref);
ubase_assert(uref_clock_get_pts_sys(uref, &pts));
assert(pts == systime + 2);
assert(pts == systime + 3);

systime += 8000;
clock += 10000;
Expand All @@ -109,7 +109,7 @@ int main(int argc, char **argv)
uref_clock_set_pts_prog(uref, clock);
upipe_throw_clock_ts(upipe, uref);
ubase_assert(uref_clock_get_pts_sys(uref, &pts));
assert(pts == systime + 2002);
assert(pts == systime + 2003);

uref_free(uref);
uprobe_release(uprobe_dejitter);
Expand Down