]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/f_realtime.c
avfilter: Constify all AVFilters
[ffmpeg] / libavfilter / f_realtime.c
index 171c16aaaa3ca815c87971eca421bd655269374c..332ef21ac58055124d064250bd790a43ff2264a7 100644 (file)
 #include "libavutil/time.h"
 #include "avfilter.h"
 #include "internal.h"
+#include <float.h>
 
 typedef struct RealtimeContext {
     const AVClass *class;
     int64_t delta;
     int64_t limit;
+    double speed;
     unsigned inited;
 } RealtimeContext;
 
@@ -36,7 +38,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
     RealtimeContext *s = ctx->priv;
 
     if (frame->pts != AV_NOPTS_VALUE) {
-        int64_t pts = av_rescale_q(frame->pts, inlink->time_base, AV_TIME_BASE_Q);
+        int64_t pts = av_rescale_q(frame->pts, inlink->time_base, AV_TIME_BASE_Q) / s->speed;
         int64_t now = av_gettime_relative();
         int64_t sleep = pts - now + s->delta;
         if (!s->inited) {
@@ -44,7 +46,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
             sleep = 0;
             s->delta = now - pts;
         }
-        if (sleep > s->limit || sleep < -s->limit) {
+        if (FFABS(sleep) > s->limit / s->speed) {
             av_log(ctx, AV_LOG_WARNING,
                    "time discontinuity detected: %"PRIi64" us, resetting\n",
                    sleep);
@@ -65,6 +67,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
 static const AVOption options[] = {
     { "limit", "sleep time limit", OFFSET(limit), AV_OPT_TYPE_DURATION, { .i64 = 2000000 }, 0, INT64_MAX, FLAGS },
+    { "speed", "speed factor", OFFSET(speed), AV_OPT_TYPE_DOUBLE, { .dbl = 1.0 }, DBL_MIN, DBL_MAX, FLAGS },
     { NULL }
 };
 
@@ -89,7 +92,7 @@ static const AVFilterPad avfilter_vf_realtime_outputs[] = {
     { NULL }
 };
 
-AVFilter ff_vf_realtime = {
+const AVFilter ff_vf_realtime = {
     .name        = "realtime",
     .description = NULL_IF_CONFIG_SMALL("Slow down filtering to match realtime."),
     .priv_size   = sizeof(RealtimeContext),
@@ -121,7 +124,7 @@ static const AVFilterPad arealtime_outputs[] = {
     { NULL }
 };
 
-AVFilter ff_af_arealtime = {
+const AVFilter ff_af_arealtime = {
     .name        = "arealtime",
     .description = NULL_IF_CONFIG_SMALL("Slow down filtering to match realtime."),
     .priv_size   = sizeof(RealtimeContext),