[PATCH 2/7] Add a time_base field to AVFilterPad.

Stefano Sabatini stefano.sabatini-lala
Mon Jul 19 12:55:27 CEST 2010


This is required for allowing a filter to use a time base different
from AV_TIME_BASE_Q, as it was previously assumed.
---
 libavfilter/avfilter.c |   13 +++++++++++++
 libavfilter/avfilter.h |   15 ++++++++++++++-
 libavfilter/defaults.c |    2 ++
 3 files changed, 29 insertions(+), 1 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index e81fa48..4a24dcb 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -23,6 +23,7 @@
 
 #include "libavcodec/imgconvert.h"
 #include "libavutil/pixdesc.h"
+#include "libavutil/rational.h"
 #include "avfilter.h"
 #include "internal.h"
 
@@ -154,6 +155,8 @@ int avfilter_config_links(AVFilterContext *filter)
             if(config_link(link))
                 return -1;
 
+            if (!av_cmp_q(link_dpad(link).time_base, (AVRational) {0,0}))
+                link_dpad(link).time_base = link_spad(link).time_base;
             if((config_link = link_dpad(link).config_props))
                 if(config_link(link))
                     return -1;
@@ -240,6 +243,7 @@ void avfilter_start_frame(AVFilterLink *link, AVFilterPicRef *picref)
 {
     void (*start_frame)(AVFilterLink *, AVFilterPicRef *);
     AVFilterPad *dst = &link_dpad(link);
+    AVFilterPad *src = &link_spad(link);
 
     FF_DPRINTF_START(NULL, start_frame); ff_dprintf_link(NULL, link, 0); dprintf(NULL, " "); ff_dprintf_picref(NULL, picref, 1);
 
@@ -263,6 +267,15 @@ void avfilter_start_frame(AVFilterLink *link, AVFilterPicRef *picref)
     else
         link->cur_pic = picref;
 
+    if (av_cmp_q(dst->time_base, src->time_base)) {
+        int64_t av_unused pts1 = picref->pts;
+        link->cur_pic->pts = av_rescale_q(picref->pts, src->time_base, dst->time_base);
+        FF_DPRINTF_START(NULL, start_frame); ff_dprintf_link(NULL, link, 0);
+        dprintf(NULL, " Converting PTS tb1:%d/%d pts1:%"PRId64" -> tb2:%d/%d pts2:%"PRId64"\n",
+                src->time_base.num, src->time_base.den, pts1,
+                dst->time_base.num, dst->time_base.den, link->cur_pic->pts);
+    }
+
     start_frame(link, link->cur_pic);
 }
 
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index f5f9bce..e7fdcc2 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -105,7 +105,14 @@ typedef struct AVFilterPicRef
     int w;                      ///< image width
     int h;                      ///< image height
 
-    int64_t pts;                ///< presentation timestamp in units of 1/AV_TIME_BASE
+    /**
+     * presentation timestamp. The time unit may change during
+     * filtering, as it is specified in the input and output pads of a
+     * link. The framework automatically rescale the timestamp when
+     * sending a picref through a link and the source and destination
+     * time units differ.
+     */
+    int64_t pts;
     int64_t pos;                ///< byte position in stream, -1 if unknown
 
     AVRational pixel_aspect;    ///< pixel aspect ratio
@@ -383,6 +390,12 @@ struct AVFilterPad
      * and another value on error.
      */
     int (*config_props)(AVFilterLink *link);
+
+    /**
+     * Define the time base used by the PTS of the frames/samples
+     * which will pass through this link.
+     */
+    AVRational time_base;
 };
 
 /** default handler for start_frame() for video inputs */
diff --git a/libavfilter/defaults.c b/libavfilter/defaults.c
index ed1db94..c178c13 100644
--- a/libavfilter/defaults.c
+++ b/libavfilter/defaults.c
@@ -21,6 +21,7 @@
 
 #include "libavcodec/imgconvert.h"
 #include "avfilter.h"
+#include "internal.h"
 
 /* TODO: buffer pool.  see comment for avfilter_default_get_video_buffer() */
 static void avfilter_default_free_buffer(AVFilterBuffer *ptr)
@@ -117,6 +118,7 @@ int avfilter_default_config_output_link(AVFilterLink *link)
     if(link->src->input_count && link->src->inputs[0]) {
         link->w = link->src->inputs[0]->w;
         link->h = link->src->inputs[0]->h;
+        link_spad(link).time_base = link->src->input_pads[0].time_base;
     } else {
         /* XXX: any non-simple filter which would cause this branch to be taken
          * really should implement its own config_props() for this link. */
-- 
1.6.0.4


--jRHKVT23PllUwdXP--



More information about the ffmpeg-devel mailing list