]> git.sesse.net Git - ffmpeg/blob - libavfilter/asink_abuffer.c
Support speex in avi.
[ffmpeg] / libavfilter / asink_abuffer.c
1 /*
2  * Copyright (c) 2011 Stefano Sabatini
3  * Copyright (c) 2011 Mina Nagy Zaki
4  *
5  * This file is part of FFmpeg.
6  *
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.
11  *
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.
16  *
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
20  */
21
22 /**
23  * @file
24  * audio buffer sink
25  */
26
27 #include "avfilter.h"
28 #include "asink_abuffer.h"
29
30 static void filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
31 {
32 }
33
34 static int init(AVFilterContext *ctx, const char *args, void *opaque)
35 {
36     if (!opaque) {
37         av_log(ctx, AV_LOG_ERROR, "Opaque field required, please pass"
38                                   " an initialized ABufferSinkContext");
39         return AVERROR(EINVAL);
40     }
41     memcpy(ctx->priv, opaque, sizeof(ABufferSinkContext));
42
43     return 0;
44 }
45
46 static int query_formats(AVFilterContext *ctx)
47 {
48     ABufferSinkContext *abuffersink = ctx->priv;
49     AVFilterFormats *formats = NULL;
50
51     if (!(formats = avfilter_make_format_list(abuffersink->sample_fmts)))
52         return AVERROR(ENOMEM);
53     avfilter_set_common_sample_formats(ctx, formats);
54
55     if (!(formats = avfilter_make_format64_list(abuffersink->channel_layouts)))
56         return AVERROR(ENOMEM);
57     avfilter_set_common_channel_layouts(ctx, formats);
58
59     if (!(formats = avfilter_make_format_list(abuffersink->packing_fmts)))
60         return AVERROR(ENOMEM);
61     avfilter_set_common_packing_formats(ctx, formats);
62
63     return 0;
64 }
65
66 int av_asink_abuffer_get_audio_buffer_ref(AVFilterContext *abuffersink,
67                                           AVFilterBufferRef **samplesref,
68                                           int av_unused flags)
69 {
70     int ret;
71     AVFilterLink * const inlink = abuffersink->inputs[0];
72
73     if ((ret = avfilter_request_frame(inlink)))
74         return ret;
75     if (!inlink->cur_buf)
76         return AVERROR(EINVAL);
77     *samplesref = inlink->cur_buf;
78     inlink->cur_buf = NULL;
79
80     return 0;
81 }
82
83 AVFilter avfilter_asink_abuffersink = {
84     .name      = "abuffersink",
85     .description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."),
86     .init      = init,
87     .priv_size = sizeof(ABufferSinkContext),
88     .query_formats = query_formats,
89
90     .inputs    = (AVFilterPad[]) {{ .name           = "default",
91                                     .type           = AVMEDIA_TYPE_AUDIO,
92                                     .filter_samples = filter_samples,
93                                     .min_perms      = AV_PERM_READ, },
94                                   { .name = NULL }},
95     .outputs   = (AVFilterPad[]) {{ .name = NULL }},
96 };
97