lavfi: implement asettb filter.
authorNicolas George <nicolas.george@normalesup.org>
Sat, 23 Jun 2012 10:19:14 +0000 (12:19 +0200)
committerNicolas George <nicolas.george@normalesup.org>
Sun, 8 Jul 2012 17:54:08 +0000 (19:54 +0200)
Changelog
doc/filters.texi
libavfilter/Makefile
libavfilter/allfilters.c
libavfilter/version.h
libavfilter/vf_settb.c

index b5db610..5b86bbc 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -21,6 +21,7 @@ version next:
 - RealText demuxer and decoder
 - Heart Of Darkness PAF playback support
 - iec61883 device
 - RealText demuxer and decoder
 - Heart Of Darkness PAF playback support
 - iec61883 device
+- asettb filter
 
 
 version 0.11:
 
 
 version 0.11:
index 5fef9d1..0d94eba 100644 (file)
@@ -2937,14 +2937,15 @@ setpts=N/(25*TB)
 setpts='1/(25*TB) * (N + 0.05 * sin(N*2*PI/25))'
 @end example
 
 setpts='1/(25*TB) * (N + 0.05 * sin(N*2*PI/25))'
 @end example
 
-@section settb
+@section settb, asettb
 
 Set the timebase to use for the output frames timestamps.
 It is mainly useful for testing timebase configuration.
 
 It accepts in input an arithmetic expression representing a rational.
 The expression can contain the constants "AVTB" (the
 
 Set the timebase to use for the output frames timestamps.
 It is mainly useful for testing timebase configuration.
 
 It accepts in input an arithmetic expression representing a rational.
 The expression can contain the constants "AVTB" (the
-default timebase), and "intb" (the input timebase).
+default timebase), "intb" (the input timebase) and "sr" (the sample rate,
+audio only).
 
 The default value for the input is "intb".
 
 
 The default value for the input is "intb".
 
index a8af5b5..b39a4f6 100644 (file)
@@ -53,6 +53,7 @@ OBJS-$(CONFIG_AMIX_FILTER)                   += af_amix.o
 OBJS-$(CONFIG_ANULL_FILTER)                  += af_anull.o
 OBJS-$(CONFIG_ARESAMPLE_FILTER)              += af_aresample.o
 OBJS-$(CONFIG_ASETNSAMPLES_FILTER)           += af_asetnsamples.o
 OBJS-$(CONFIG_ANULL_FILTER)                  += af_anull.o
 OBJS-$(CONFIG_ARESAMPLE_FILTER)              += af_aresample.o
 OBJS-$(CONFIG_ASETNSAMPLES_FILTER)           += af_asetnsamples.o
+OBJS-$(CONFIG_ASETTB_FILTER)                 += vf_settb.o
 OBJS-$(CONFIG_ASHOWINFO_FILTER)              += af_ashowinfo.o
 OBJS-$(CONFIG_ASPLIT_FILTER)                 += split.o
 OBJS-$(CONFIG_ASTREAMSYNC_FILTER)            += af_astreamsync.o
 OBJS-$(CONFIG_ASHOWINFO_FILTER)              += af_ashowinfo.o
 OBJS-$(CONFIG_ASPLIT_FILTER)                 += split.o
 OBJS-$(CONFIG_ASTREAMSYNC_FILTER)            += af_astreamsync.o
index 6458fc5..706405e 100644 (file)
@@ -42,6 +42,7 @@ void avfilter_register_all(void)
     REGISTER_FILTER (ANULL,       anull,       af);
     REGISTER_FILTER (ARESAMPLE,   aresample,   af);
     REGISTER_FILTER (ASETNSAMPLES, asetnsamples, af);
     REGISTER_FILTER (ANULL,       anull,       af);
     REGISTER_FILTER (ARESAMPLE,   aresample,   af);
     REGISTER_FILTER (ASETNSAMPLES, asetnsamples, af);
+    REGISTER_FILTER (ASETTB,      asettb,      af);
     REGISTER_FILTER (ASHOWINFO,   ashowinfo,   af);
     REGISTER_FILTER (ASPLIT,      asplit,      af);
     REGISTER_FILTER (ASTREAMSYNC, astreamsync, af);
     REGISTER_FILTER (ASHOWINFO,   ashowinfo,   af);
     REGISTER_FILTER (ASPLIT,      asplit,      af);
     REGISTER_FILTER (ASTREAMSYNC, astreamsync, af);
index 526df71..8116465 100644 (file)
@@ -29,8 +29,8 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVFILTER_VERSION_MAJOR  3
 #include "libavutil/avutil.h"
 
 #define LIBAVFILTER_VERSION_MAJOR  3
-#define LIBAVFILTER_VERSION_MINOR  0
-#define LIBAVFILTER_VERSION_MICRO 101
+#define LIBAVFILTER_VERSION_MINOR  1
+#define LIBAVFILTER_VERSION_MICRO 100
 
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
                                                LIBAVFILTER_VERSION_MINOR, \
 
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
                                                LIBAVFILTER_VERSION_MINOR, \
index b6e951b..3c5ac6a 100644 (file)
 #include "libavutil/rational.h"
 #include "avfilter.h"
 #include "internal.h"
 #include "libavutil/rational.h"
 #include "avfilter.h"
 #include "internal.h"
+#include "audio.h"
 #include "video.h"
 
 static const char *const var_names[] = {
     "AVTB",   /* default timebase 1/AV_TIME_BASE */
     "intb",   /* input timebase */
 #include "video.h"
 
 static const char *const var_names[] = {
     "AVTB",   /* default timebase 1/AV_TIME_BASE */
     "intb",   /* input timebase */
+    "sr",     /* sample rate */
     NULL
 };
 
 enum var_name {
     VAR_AVTB,
     VAR_INTB,
     NULL
 };
 
 enum var_name {
     VAR_AVTB,
     VAR_INTB,
+    VAR_SR,
     VAR_VARS_NB
 };
 
     VAR_VARS_NB
 };
 
@@ -70,6 +73,7 @@ static int config_output_props(AVFilterLink *outlink)
 
     settb->var_values[VAR_AVTB] = av_q2d(AV_TIME_BASE_Q);
     settb->var_values[VAR_INTB] = av_q2d(inlink->time_base);
 
     settb->var_values[VAR_AVTB] = av_q2d(AV_TIME_BASE_Q);
     settb->var_values[VAR_INTB] = av_q2d(inlink->time_base);
+    settb->var_values[VAR_SR]   = inlink->sample_rate;
 
     outlink->w = inlink->w;
     outlink->h = inlink->h;
 
     outlink->w = inlink->w;
     outlink->h = inlink->h;
@@ -113,9 +117,28 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
     ff_start_frame(outlink, picref2);
 }
 
     ff_start_frame(outlink, picref2);
 }
 
+static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
+{
+    AVFilterContext *ctx = inlink->dst;
+    AVFilterLink *outlink = ctx->outputs[0];
+    AVFilterBufferRef *outsamples = insamples;
+
+    if (av_cmp_q(inlink->time_base, outlink->time_base)) {
+        outsamples = avfilter_ref_buffer(insamples, ~0);
+        outsamples->pts = av_rescale_q(insamples->pts, inlink->time_base, outlink->time_base);
+        av_log(ctx, AV_LOG_DEBUG, "tb:%d/%d pts:%"PRId64" -> tb:%d/%d pts:%"PRId64"\n",
+               inlink ->time_base.num, inlink ->time_base.den, insamples ->pts,
+               outlink->time_base.num, outlink->time_base.den, outsamples->pts);
+        avfilter_unref_buffer(insamples);
+    }
+
+    ff_filter_samples(outlink, outsamples);
+}
+
+#if CONFIG_SETTB_FILTER
 AVFilter avfilter_vf_settb = {
     .name      = "settb",
 AVFilter avfilter_vf_settb = {
     .name      = "settb",
-    .description = NULL_IF_CONFIG_SMALL("Set timebase for the output link."),
+    .description = NULL_IF_CONFIG_SMALL("Set timebase for the video output link."),
     .init      = init,
 
     .priv_size = sizeof(SetTBContext),
     .init      = init,
 
     .priv_size = sizeof(SetTBContext),
@@ -132,3 +155,28 @@ AVFilter avfilter_vf_settb = {
                                     .config_props    = config_output_props, },
                                   { .name = NULL}},
 };
                                     .config_props    = config_output_props, },
                                   { .name = NULL}},
 };
+#endif
+
+#if CONFIG_ASETTB_FILTER
+AVFilter avfilter_af_asettb = {
+    .name      = "asettb",
+    .description = NULL_IF_CONFIG_SMALL("Set timebase for the audio output link."),
+    .init      = init,
+
+    .priv_size = sizeof(SetTBContext),
+
+    .inputs    = (const AVFilterPad[]) {
+        { .name             = "default",
+          .type             = AVMEDIA_TYPE_AUDIO,
+          .get_audio_buffer = ff_null_get_audio_buffer,
+          .filter_samples   = filter_samples, },
+        { .name = NULL }
+    },
+    .outputs   = (const AVFilterPad[]) {
+        { .name            = "default",
+          .type            = AVMEDIA_TYPE_AUDIO,
+          .config_props    = config_output_props, },
+        { .name = NULL}
+    },
+};
+#endif