Acts a silence source filter for now
---
I tried to make a quite simple audio source filter, comments on how to make it
more correct welcome.
libavfilter/Makefile | 1 +
libavfilter/allfilters.c | 1 +
libavfilter/asrc_atestsrc.c | 82 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 84 insertions(+)
create mode 100644 libavfilter/asrc_atestsrc.c
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 7b94f22..677ad5b 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -37,6 +37,7 @@ OBJS-$(CONFIG_RESAMPLE_FILTER) += af_resample.o
OBJS-$(CONFIG_VOLUME_FILTER) += af_volume.o
OBJS-$(CONFIG_ANULLSRC_FILTER) += asrc_anullsrc.o
+OBJS-$(CONFIG_ATESTSRC_FILTER) += asrc_atestsrc.o
OBJS-$(CONFIG_ANULLSINK_FILTER) += asink_anullsink.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 67a298d..210b8be 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -62,6 +62,7 @@ void avfilter_register_all(void)
REGISTER_FILTER(VOLUME, volume, af);
REGISTER_FILTER(ANULLSRC, anullsrc, asrc);
+ REGISTER_FILTER(ATESTSRC, atestsrc, asrc);
REGISTER_FILTER(ANULLSINK, anullsink, asink);
diff --git a/libavfilter/asrc_atestsrc.c b/libavfilter/asrc_atestsrc.c
new file mode 100644
index 0000000..e58cdb0
--- /dev/null
+++ b/libavfilter/asrc_atestsrc.c
@@ -0,0 +1,82 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * test audio source
+ */
+
+#include <inttypes.h>
+#include <stdio.h>
+
+#include "libavutil/channel_layout.h"
+#include "libavutil/internal.h"
+
+#include "audio.h"
+#include "avfilter.h"
+#include "formats.h"
+#include "internal.h"
+
+static int atest_request_frame(AVFilterLink *link)
+{
+ AVFrame *frame = ff_default_get_audio_buffer(link, link->request_samples);
+
+ if (!frame)
+ return AVERROR(ENOMEM);
+
+ return ff_filter_frame(link, frame);
+}
+
+static int config_props(AVFilterLink *link)
+{
+ link->time_base = (AVRational){1, link->sample_rate};
+ link->request_samples = 1024;
+
+ return 0;
+}
+
+static int query_formats(AVFilterContext *ctx)
+{
+ AVFilterFormats *formats = NULL;
+ ff_add_format(&formats, AV_SAMPLE_FMT_FLT);
+ ff_add_format(&formats, AV_SAMPLE_FMT_FLTP);
+ ff_set_common_formats(ctx, formats);
+ ff_set_common_channel_layouts(ctx, ff_all_channel_layouts());
+ ff_set_common_samplerates(ctx, ff_all_samplerates());
+ return 0;
+}
+
+static const AVFilterPad avfilter_asrc_atestsrc_outputs[] = {
+ {
+ .name = "default",
+ .type = AVMEDIA_TYPE_AUDIO,
+ .request_frame = atest_request_frame,
+ .config_props = config_props,
+ },
+ { NULL }
+};
+
+AVFilter ff_asrc_atestsrc = {
+ .name = "atestsrc",
+ .description = NULL_IF_CONFIG_SMALL("Null audio source, never return
audio frames."),
+
+ .query_formats = query_formats,
+
+ .inputs = NULL,
+ .outputs = avfilter_asrc_atestsrc_outputs,
+};
--
1.9.0
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel