[FFmpeg-devel] [PATCH 2/3] timefilter: allow irregular updates.
Nicolas George
nicolas.george at normalesup.org
Wed Feb 15 19:35:11 CET 2012
The timefilter model requires updates at constant interval,
as the interval is used to compute the feedback factors.
This change introduces an API to update and query the timefilter
at irregular intervals using small constant intervals and linear
interpolation.
Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
libavdevice/timefilter.c | 30 ++++++++++++++++++++++++++++++
libavdevice/timefilter.h | 17 +++++++++++++++++
2 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/libavdevice/timefilter.c b/libavdevice/timefilter.c
index b800615..13ca7ea 100644
--- a/libavdevice/timefilter.c
+++ b/libavdevice/timefilter.c
@@ -33,6 +33,8 @@ struct TimeFilter {
double feedback2_factor;
double feedback3_factor;
double clock_period;
+ double period_step;
+ double period_remainder;
int count;
};
@@ -43,6 +45,7 @@ TimeFilter *ff_timefilter_new(double time_base,
TimeFilter *self = av_mallocz(sizeof(TimeFilter));
double o = 2 * M_PI * bandwidth * period * time_base;
self->clock_period = time_base;
+ self->period_step = period;
self->feedback2_factor = M_SQRT2 * o;
self->feedback3_factor = o * o;
return self;
@@ -77,6 +80,33 @@ double ff_timefilter_update(TimeFilter *self, double system_time, double period)
return self->cycle_time;
}
+void ff_timefilter_update_irregular(TimeFilter *self, double system_time, double period)
+{
+ double t, dt;
+
+ if (!self->count || period <= 1E-6) {
+ self->cycle_time = system_time;
+ self->period_remainder = 0;
+ self->count = 1;
+ return;
+ }
+ period += self->period_remainder;
+ t = self->cycle_time;
+ dt = (system_time - t) * self->period_step / period;
+ while (period >= self->period_step) {
+ t += dt;
+ ff_timefilter_update(self, t, self->period_step);
+ period -= self->period_step;
+ }
+ self->period_remainder = period;
+}
+
+double ff_timefilter_eval(TimeFilter *self, double delta)
+{
+ return self->cycle_time + self->clock_period *
+ (self->period_remainder + delta);
+}
+
#ifdef TEST
#include "libavutil/lfg.h"
#define LFG_MAX ((1LL << 32) - 1)
diff --git a/libavdevice/timefilter.h b/libavdevice/timefilter.h
index c6f0d78..2f4f791 100644
--- a/libavdevice/timefilter.h
+++ b/libavdevice/timefilter.h
@@ -83,6 +83,23 @@ TimeFilter * ff_timefilter_new(double clock_period, double feedback2_factor, dou
double ff_timefilter_update(TimeFilter *self, double system_time, double period);
/**
+ * Update the filter with irregular periods
+ *
+ * The parameters are the same as the parameters for ff_timefilter_update,
+ * but period is not required to be constant.
+ */
+void ff_timefilter_update_irregular(TimeFilter *self, double system_time, double period);
+
+/**
+ * Evaluate the filter at a specified time
+ *
+ * @param delta difference between the requested time and the current time
+ * (last call to ff_timefilter_update).
+ * @ return the filtered time
+ */
+double ff_timefilter_eval(TimeFilter *self, double delta);
+
+/**
* Reset the filter
*
* This function should mainly be called in case of XRUN.
--
1.7.9
More information about the ffmpeg-devel
mailing list