[FFmpeg-devel,06/17] lavfi: add ff_link_process_timeline().

Submitted by Nicolas George on Dec. 24, 2016, 5:41 p.m.

Details

Message ID 20161224174149.8995-7-george@nsup.org
State New
Headers show

Commit Message

Nicolas George Dec. 24, 2016, 5:41 p.m.
Signed-off-by: Nicolas George <george@nsup.org>
---
 libavfilter/avfilter.c | 34 +++++++++++++++++++++-------------
 libavfilter/internal.h |  6 ++++++
 2 files changed, 27 insertions(+), 13 deletions(-)

Comments

Michael Niedermayer Dec. 25, 2016, 12:41 a.m.
On Sat, Dec 24, 2016 at 06:41:38PM +0100, Nicolas George wrote:
> Signed-off-by: Nicolas George <george@nsup.org>
> ---
>  libavfilter/avfilter.c | 34 +++++++++++++++++++++-------------
>  libavfilter/internal.h |  6 ++++++
>  2 files changed, 27 insertions(+), 13 deletions(-)

This seems to just factorize code
LGTM

[...]
Nicolas George Dec. 25, 2016, 12:46 a.m.
Le quintidi 5 nivôse, an CCXXV, Michael Niedermayer a écrit :
> This seems to just factorize code
> LGTM

Yes; the previous one too. As I said, quite straightforward, just making
existing pieces of code available for the next steps.

Regards,

Patch hide | download patch | download mbox

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index b05a75182a..92cba6f7a1 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -1099,7 +1099,6 @@  static int ff_filter_frame_framed(AVFilterLink *link, AVFrame *frame)
     AVFilterContext *dstctx = link->dst;
     AVFilterPad *dst = link->dstpad;
     int ret;
-    int64_t pts;
 
     if (!(filter_frame = dst->filter_frame))
         filter_frame = default_filter_frame;
@@ -1111,24 +1110,15 @@  static int ff_filter_frame_framed(AVFilterLink *link, AVFrame *frame)
     }
 
     ff_link_process_commands(link, frame);
+    ff_link_process_timeline(link, frame);
 
-    pts = frame->pts;
-    if (dstctx->enable_str) {
-        int64_t pos = av_frame_get_pkt_pos(frame);
-        dstctx->var_values[VAR_N] = link->frame_count_out;
-        dstctx->var_values[VAR_T] = pts == AV_NOPTS_VALUE ? NAN : pts * av_q2d(link->time_base);
-        dstctx->var_values[VAR_W] = link->w;
-        dstctx->var_values[VAR_H] = link->h;
-        dstctx->var_values[VAR_POS] = pos == -1 ? NAN : pos;
-
-        dstctx->is_disabled = fabs(av_expr_eval(dstctx->enable, dstctx->var_values, NULL)) < 0.5;
+        /* TODO reindent */
         if (dstctx->is_disabled &&
             (dstctx->filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC))
             filter_frame = default_filter_frame;
-    }
     ret = filter_frame(link, frame);
     link->frame_count_out++;
-    ff_update_link_current_pts(link, pts);
+    ff_update_link_current_pts(link, frame->pts);
     return ret;
 
 fail:
@@ -1571,6 +1561,24 @@  void ff_link_process_commands(AVFilterLink *link, const AVFrame *frame)
     }
 }
 
+void ff_link_process_timeline(AVFilterLink *link, const AVFrame *frame)
+{
+    AVFilterContext *dstctx = link->dst;
+    int64_t pts = frame->pts;
+    int64_t pos = av_frame_get_pkt_pos(frame);
+
+    if (!dstctx->enable_str)
+        return;
+
+    dstctx->var_values[VAR_N] = link->frame_count_out;
+    dstctx->var_values[VAR_T] = pts == AV_NOPTS_VALUE ? NAN : pts * av_q2d(link->time_base);
+    dstctx->var_values[VAR_W] = link->w;
+    dstctx->var_values[VAR_H] = link->h;
+    dstctx->var_values[VAR_POS] = pos == -1 ? NAN : pos;
+
+    dstctx->is_disabled = fabs(av_expr_eval(dstctx->enable, dstctx->var_values, NULL)) < 0.5;
+}
+
 const AVClass *avfilter_get_class(void)
 {
     return &avfilter_class;
diff --git a/libavfilter/internal.h b/libavfilter/internal.h
index 1a78dc2785..4488821fe0 100644
--- a/libavfilter/internal.h
+++ b/libavfilter/internal.h
@@ -637,4 +637,10 @@  int ff_link_make_frame_writable(AVFilterLink *link, AVFrame **rframe);
  */
 void ff_link_process_commands(AVFilterLink *link, const AVFrame *frame);
 
+/**
+ * Process the timeline expression of the link for the time of the frame.
+ * It will update link->is_disabled.
+ */
+void ff_link_process_timeline(AVFilterLink *link, const AVFrame *frame);
+
 #endif /* AVFILTER_INTERNAL_H */