2 * Copyright (c) 2011 Stefano Sabatini
3 * Copyright (c) 2011 Mina Nagy Zaki
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 #include "asink_abuffer.h"
30 static void filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
34 static int init(AVFilterContext *ctx, const char *args, void *opaque)
37 av_log(ctx, AV_LOG_ERROR, "Opaque field required, please pass"
38 " an initialized ABufferSinkContext");
39 return AVERROR(EINVAL);
41 memcpy(ctx->priv, opaque, sizeof(ABufferSinkContext));
46 static int query_formats(AVFilterContext *ctx)
48 ABufferSinkContext *abuffersink = ctx->priv;
49 AVFilterFormats *formats;
53 if ((ret = avfilter_add_format(&formats, abuffersink->sample_fmt)) < 0)
55 avfilter_set_common_sample_formats(ctx, formats);
58 if ((ret = avfilter_add_format(&formats, abuffersink->channel_layout)) < 0)
60 avfilter_set_common_channel_layouts(ctx, formats);
63 if ((ret = avfilter_add_format(&formats, abuffersink->planar)) < 0)
65 avfilter_set_common_packing_formats(ctx, formats);
70 int av_asink_abuffer_get_audio_buffer_ref(AVFilterContext *abuffersink,
71 AVFilterBufferRef **samplesref,
75 AVFilterLink * const inlink = abuffersink->inputs[0];
77 if ((ret = avfilter_request_frame(inlink)))
80 return AVERROR(EINVAL);
81 *samplesref = inlink->cur_buf;
82 inlink->cur_buf = NULL;
87 AVFilter avfilter_asink_abuffersink = {
88 .name = "abuffersink",
89 .description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."),
91 .priv_size = sizeof(ABufferSinkContext),
92 .query_formats = query_formats,
94 .inputs = (AVFilterPad[]) {{ .name = "default",
95 .type = AVMEDIA_TYPE_AUDIO,
96 .filter_samples = filter_samples,
97 .min_perms = AV_PERM_READ, },
99 .outputs = (AVFilterPad[]) {{ .name = NULL }},