[FFmpeg-devel] [PATCH 2/4] lavfi: add asink_abuffer - audio sink buffer filter

Mina Nagy Zaki mnzaki at gmail.com
Wed Jul 27 00:05:18 CEST 2011


---
 libavfilter/Makefile        |    1 +
 libavfilter/allfilters.c    |    1 +
 libavfilter/asink_abuffer.c |   91 +++++++++++++++++++++++++++++++++++++++++++
 libavfilter/asink_abuffer.h |   44 +++++++++++++++++++++
 4 files changed, 137 insertions(+), 0 deletions(-)
 create mode 100644 libavfilter/asink_abuffer.c
 create mode 100644 libavfilter/asink_abuffer.h

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 686fd30..83b906d 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -23,6 +23,7 @@ OBJS-$(CONFIG_ANULL_FILTER)                  += af_anull.o
 
 OBJS-$(CONFIG_ANULLSRC_FILTER)               += asrc_anullsrc.o
 
+OBJS-$(CONFIG_ABUFFERSINK_FILTER)            += asink_abuffer.o
 OBJS-$(CONFIG_ANULLSINK_FILTER)              += asink_anullsink.o
 
 OBJS-$(CONFIG_BLACKFRAME_FILTER)             += vf_blackframe.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 49be7b7..b812ff7 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -40,6 +40,7 @@ void avfilter_register_all(void)
     REGISTER_FILTER (ABUFFER,     abuffer,     asrc);
     REGISTER_FILTER (ANULLSRC,    anullsrc,    asrc);
 
+    REGISTER_FILTER (ABUFFER,     abuffersink, asink);
     REGISTER_FILTER (ANULLSINK,   anullsink,   asink);
 
     REGISTER_FILTER (BLACKFRAME,  blackframe,  vf);
diff --git a/libavfilter/asink_abuffer.c b/libavfilter/asink_abuffer.c
new file mode 100644
index 0000000..96a32c1
--- /dev/null
+++ b/libavfilter/asink_abuffer.c
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2011 Stefano Sabatini
+ * Copyright (c) 2011 Mina Nagy Zaki
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * audio buffer sink
+ */
+
+#include "avfilter.h"
+#include "asink_abuffer.h"
+
+static void filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
+{
+}
+
+static int init(AVFilterContext *ctx, const char *args, void *opaque)
+{
+    if (!opaque)
+        return AVERROR(EINVAL);
+    memcpy(ctx->priv, opaque, sizeof(ABufferSinkContext));
+
+    return 0;
+}
+
+static int query_formats(AVFilterContext *ctx)
+{
+    ABufferSinkContext *abuffersink = ctx->priv;
+    AVFilterFormats *formats;
+
+    formats = NULL;
+    avfilter_add_format(&formats, abuffersink->sample_fmt);
+    avfilter_set_common_sample_formats(ctx, formats);
+
+    formats = NULL;
+    avfilter_add_format(&formats, abuffersink->channel_layout);
+    avfilter_set_common_channel_layouts(ctx, formats);
+
+    formats = NULL;
+    avfilter_add_format(&formats, AVFILTER_PACKED); //FIXME
+    avfilter_set_common_packing_formats(ctx, formats);
+
+    return 0;
+}
+
+int av_asink_abuffer_get_audio_buffer_ref(AVFilterContext *abuffer_asink,
+                              AVFilterBufferRef **samplesref)
+{
+    int ret;
+
+    if ((ret = avfilter_request_frame(abuffer_asink->inputs[0])))
+        return ret;
+    if (!abuffer_asink->inputs[0]->cur_buf)
+        return AVERROR(EINVAL);
+    *samplesref = abuffer_asink->inputs[0]->cur_buf;
+    abuffer_asink->inputs[0]->cur_buf = NULL;
+
+    return 0;
+}
+
+AVFilter avfilter_asink_abuffersink = {
+    .name      = "abuffersink",
+    .init      = init,
+    .priv_size = sizeof(ABufferSinkContext),
+    .query_formats = query_formats,
+
+    .inputs    = (AVFilterPad[]) {{ .name           = "default",
+                                    .type           = AVMEDIA_TYPE_AUDIO,
+                                    .filter_samples = filter_samples,
+                                    .min_perms      = AV_PERM_READ, },
+                                  { .name = NULL }},
+    .outputs   = (AVFilterPad[]) {{ .name = NULL }},
+};
+
diff --git a/libavfilter/asink_abuffer.h b/libavfilter/asink_abuffer.h
new file mode 100644
index 0000000..9105840
--- /dev/null
+++ b/libavfilter/asink_abuffer.h
@@ -0,0 +1,44 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVFILTER_ASINK_BUFFER_H
+#define AVFILTER_ASINK_BUFFER_H
+
+/**
+ * @file
+ * audio buffer sink API
+ */
+
+#include "avfilter.h"
+
+typedef struct {
+    enum AVSampleFormat sample_fmt;
+    int64_t channel_layout;
+} ABufferSinkContext;
+
+
+/**
+ * Get a video buffer data from buffer_sink and put it in picref.
+ *
+ * @param abuffer_sink pointer to a buffer sink context
+ * @return >= 0 in case of success, a negative AVERROR code in case of failure
+ */
+int av_asink_abuffer_get_audio_buffer_ref(AVFilterContext *abuffer_asink,
+                                          AVFilterBufferRef **samplesref);
+
+#endif /* AVFILTER_VSINK_BUFFER_H */
-- 
1.7.4.4



More information about the ffmpeg-devel mailing list