[PATCH 01/10] Add a time_base field to AVFilterLink.
Stefano Sabatini
stefano.sabatini-lala
Mon Sep 27 20:24:44 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 | 4 ++++
libavfilter/avfilter.h | 13 ++++++++++++-
libavfilter/defaults.c | 14 +++++++++++++-
3 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index ea6f9fe..d528455 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -23,6 +23,7 @@
#include "libavcodec/audioconvert.c"
#include "libavutil/pixdesc.h"
+#include "libavutil/rational.h"
#include "libavcore/imgutils.h"
#include "avfilter.h"
#include "internal.h"
@@ -179,6 +180,9 @@ int avfilter_config_links(AVFilterContext *filter)
if (config_link(link))
return -1;
+ if (link->time_base.num == 0 && link->time_base.den == 0)
+ link->time_base = AV_TIME_BASE_Q;
+
if ((config_link = link->dstpad->config_props))
if (config_link(link))
return -1;
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 20901a3..9762960 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -127,7 +127,12 @@ typedef struct AVFilterBufferRef {
int linesize[8]; ///< number of bytes per line
int format; ///< media format
- 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 link and the filter code
+ * may need to rescale the PTS accordingly.
+ */
+ int64_t pts;
int64_t pos; ///< byte position in stream, -1 if unknown
int perms; ///< permissions, see the AV_PERM_* flags
@@ -598,6 +603,12 @@ struct AVFilterLink {
AVFilterBufferRef *cur_buf;
AVFilterBufferRef *out_buf;
+
+ /**
+ * Define the time base used by the PTS of the frames/samples
+ * which will pass through this link.
+ */
+ AVRational time_base;
};
/**
diff --git a/libavfilter/defaults.c b/libavfilter/defaults.c
index cb9ed19..838ed99 100644
--- a/libavfilter/defaults.c
+++ b/libavfilter/defaults.c
@@ -169,6 +169,8 @@ void avfilter_default_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
if (out) {
out->out_buf = avfilter_get_video_buffer(out, AV_PERM_WRITE, out->w, out->h);
avfilter_copy_buffer_ref_props(out->out_buf, picref);
+ if (av_cmp_q(link->time_base, out->time_base))
+ out->out_buf->pts = av_rescale_q(picref->pts, link->time_base, out->time_base);
avfilter_start_frame(out, avfilter_ref_buffer(out->out_buf, ~0));
}
}
@@ -235,6 +237,7 @@ int avfilter_default_config_output_link(AVFilterLink *link)
if (link->type == AVMEDIA_TYPE_VIDEO) {
link->w = link->src->inputs[0]->w;
link->h = link->src->inputs[0]->h;
+ link->time_base = link->src->inputs[0]->time_base;
} else if (link->type == AVMEDIA_TYPE_AUDIO) {
link->channel_layout = link->src->inputs[0]->channel_layout;
link->sample_rate = link->src->inputs[0]->sample_rate;
@@ -292,7 +295,16 @@ int avfilter_default_query_formats(AVFilterContext *ctx)
void avfilter_null_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
{
- avfilter_start_frame(link->dst->outputs[0], picref);
+ AVFilterLink *outlink = link->dst->outputs[0];
+ AVFilterBufferRef *picref2 = picref;
+
+ if (av_cmp_q(link->time_base, outlink->time_base)) {
+ picref2 = avfilter_ref_buffer(picref, ~0);
+ avfilter_unref_buffer(picref);
+ picref2->pts = av_rescale_q(picref->pts, link->time_base, outlink->time_base);
+ }
+
+ avfilter_start_frame(outlink, picref2);
}
void avfilter_null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
--
1.7.1
--KsGdsel6WgEHnImy--
More information about the ffmpeg-devel
mailing list