]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/f_sendcmd.c
avfilter: Constify all AVFilters
[ffmpeg] / libavfilter / f_sendcmd.c
index 5a62a338eec811cf0498c5ef57b52ece0d06cd0c..71b0a5c41102e2b347569f3125dfa19f921b20ba 100644 (file)
@@ -43,6 +43,9 @@ static const char *const var_names[] = {
     "T",     /* frame time in seconds */
     "POS",   /* original position in the file of the frame */
     "PTS",   /* frame pts */
+    "TS",    /* interval start time in seconds */
+    "TE",    /* interval end time in seconds */
+    "TI",    /* interval interpolated value: TI = (T - TS) / (TE - TS) */
     NULL
 };
 
@@ -51,6 +54,9 @@ enum var_name {
     VAR_T,
     VAR_POS,
     VAR_PTS,
+    VAR_TS,
+    VAR_TE,
+    VAR_TI,
     VAR_VARS_NB
 };
 
@@ -469,9 +475,6 @@ static av_cold void uninit(AVFilterContext *ctx)
     av_freep(&s->intervals);
 }
 
-#define TS2D(ts) ((ts) == AV_NOPTS_VALUE ? NAN : (double)(ts))
-#define TS2T(ts, tb) ((ts) == AV_NOPTS_VALUE ? NAN : (double)(ts)*av_q2d(tb))
-
 static int filter_frame(AVFilterLink *inlink, AVFrame *ref)
 {
     AVFilterContext *ctx = inlink->dst;
@@ -517,11 +520,17 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *ref)
                 if (cmd->flags & flags) {
                     if (cmd->flags & COMMAND_FLAG_EXPR) {
                         double var_values[VAR_VARS_NB], res;
+                        double start = TS2T(interval->start_ts, AV_TIME_BASE_Q);
+                        double end = TS2T(interval->end_ts, AV_TIME_BASE_Q);
+                        double current = TS2T(ref->pts, inlink->time_base);
 
                         var_values[VAR_N]   = inlink->frame_count_in;
                         var_values[VAR_POS] = ref->pkt_pos == -1 ? NAN : ref->pkt_pos;
                         var_values[VAR_PTS] = TS2D(ref->pts);
-                        var_values[VAR_T]   = TS2T(ref->pts, inlink->time_base);
+                        var_values[VAR_T]   = current;
+                        var_values[VAR_TS]  = start;
+                        var_values[VAR_TE]  = end;
+                        var_values[VAR_TI]  = (current - start) / (end - start);
 
                         if ((ret = av_expr_parse_and_eval(&res, cmd->arg, var_names, var_values,
                                                           NULL, NULL, NULL, NULL, NULL, 0, NULL)) < 0) {
@@ -585,7 +594,7 @@ static const AVFilterPad sendcmd_outputs[] = {
     { NULL }
 };
 
-AVFilter ff_vf_sendcmd = {
+const AVFilter ff_vf_sendcmd = {
     .name        = "sendcmd",
     .description = NULL_IF_CONFIG_SMALL("Send commands to filters."),
     .init        = init,
@@ -620,7 +629,7 @@ static const AVFilterPad asendcmd_outputs[] = {
     { NULL }
 };
 
-AVFilter ff_af_asendcmd = {
+const AVFilter ff_af_asendcmd = {
     .name        = "asendcmd",
     .description = NULL_IF_CONFIG_SMALL("Send commands to filters."),
     .init        = init,