History

lavfi: add asink_abuffer - audio buffer sink

Mina Nagy Zaki committed 15 years ago

Commit a8dcf5e1 parent 3e12b586 files · +163 −2Browse files

Unified · Split

6 files
  1. doc/filters.texi +11 −0
  2. libavfilter/Makefile +1 −0
  3. libavfilter/allfilters.c +1 −0
  4. libavfilter/asink_abuffer.c +101 −0
  5. libavfilter/asink_abuffer.h +47 −0
  6. libavfilter/avfilter.h +2 −2
doc/filters.texi+11−0
@@ -144,6 +144,17 @@ anullsrc=48000:mono · 143 unmodified lines
144 144
145Below is a description of the currently available audio sinks.145Below is a description of the currently available audio sinks.
146 146
147@section abuffersink
148
149Buffer audio frames, and make them available to the end of filter chain.
150
151This sink is mainly intended for programmatic use, in particular
152through the interface defined in @file{libavfilter/asink_abuffer.h}.
153
154It requires a pointer to a ABufferSinkContext structure, which defines the
155incoming buffers' format, to be passed as the opaque parameter to
156@code{avfilter_init_filter} for initialization.
157
147@section anullsink158@section anullsink
148 159
149Null audio sink, do absolutely nothing with the input audio. It is160Null audio sink, do absolutely nothing with the input audio. It is
libavfilter/Makefile+1−0
@@ -22,6 +22,7 @@ OBJS-$(CONFIG_ANULL_FILTER) += af_anull.o · 21 unmodified lines
22 22
23OBJS-$(CONFIG_ANULLSRC_FILTER) += asrc_anullsrc.o23OBJS-$(CONFIG_ANULLSRC_FILTER) += asrc_anullsrc.o
24 24
25OBJS-$(CONFIG_ABUFFERSINK_FILTER) += asink_abuffer.o
25OBJS-$(CONFIG_ANULLSINK_FILTER) += asink_anullsink.o26OBJS-$(CONFIG_ANULLSINK_FILTER) += asink_anullsink.o
26 27
27OBJS-$(CONFIG_BLACKFRAME_FILTER) += vf_blackframe.o28OBJS-$(CONFIG_BLACKFRAME_FILTER) += vf_blackframe.o
libavfilter/allfilters.c+1−0
@@ -38,6 +38,7 @@ void avfilter_register_all(void) · 37 unmodified lines
38 38
39 REGISTER_FILTER (ANULLSRC, anullsrc, asrc);39 REGISTER_FILTER (ANULLSRC, anullsrc, asrc);
40 40
41 REGISTER_FILTER (ABUFFERSINK, abuffersink, asink);
41 REGISTER_FILTER (ANULLSINK, anullsink, asink);42 REGISTER_FILTER (ANULLSINK, anullsink, asink);
42 43
43 REGISTER_FILTER (BLACKFRAME, blackframe, vf);44 REGISTER_FILTER (BLACKFRAME, blackframe, vf);
libavfilter/asink_abuffer.c+101−0
@@ -0,0 +1,101 @@
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
30static void filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
31{
32}
33
34static 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
46static int query_formats(AVFilterContext *ctx)
47{
48 ABufferSinkContext *abuffersink = ctx->priv;
49 AVFilterFormats *formats;
50 int ret;
51
52 formats = NULL;
53 if ((ret = avfilter_add_format(&formats, abuffersink->sample_fmt)) < 0)
54 return ret;
55 avfilter_set_common_sample_formats(ctx, formats);
56
57 formats = NULL;
58 if ((ret = avfilter_add_format(&formats, abuffersink->channel_layout)) < 0)
59 return ret;
60 avfilter_set_common_channel_layouts(ctx, formats);
61
62 formats = NULL;
63 if ((ret = avfilter_add_format(&formats, abuffersink->planar)) < 0)
64 return ret;
65 avfilter_set_common_packing_formats(ctx, formats);
66
67 return 0;
68}
69
70int av_asink_abuffer_get_audio_buffer_ref(AVFilterContext *abuffersink,
71 AVFilterBufferRef **samplesref,
72 int av_unused flags)
73{
74 int ret;
75 AVFilterLink * const inlink = abuffersink->inputs[0];
76
77 if ((ret = avfilter_request_frame(inlink)))
78 return ret;
79 if (!inlink->cur_buf)
80 return AVERROR(EINVAL);
81 *samplesref = inlink->cur_buf;
82 inlink->cur_buf = NULL;
83
84 return 0;
85}
86
87AVFilter 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."),
90 .init = init,
91 .priv_size = sizeof(ABufferSinkContext),
92 .query_formats = query_formats,
93
94 .inputs = (AVFilterPad[]) {{ .name = "default",
95 .type = AVMEDIA_TYPE_AUDIO,
96 .filter_samples = filter_samples,
97 .min_perms = AV_PERM_READ, },
98 { .name = NULL }},
99 .outputs = (AVFilterPad[]) {{ .name = NULL }},
100};
101
libavfilter/asink_abuffer.h+47−0
@@ -0,0 +1,47 @@
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#ifndef AVFILTER_ASINK_ABUFFER_H
20#define AVFILTER_ASINK_ABUFFER_H
21
22/**
23 * @file
24 * audio buffer sink API
25 */
26
27#include "avfilter.h"
28
29typedef struct {
30 enum AVSampleFormat sample_fmt;
31 int64_t channel_layout;
32 int planar;
33} ABufferSinkContext;
34
35
36/**
37 * Get an audio buffer from abuffersink and put it in samplesref.
38 *
39 * @param abuffersink pointer to an abuffersink context
40 * @param flags unused
41 * @return >= 0 in case of success, a negative AVERROR code in case of failure
42 */
43int av_asink_abuffer_get_audio_buffer_ref(AVFilterContext *abuffersink,
44 AVFilterBufferRef **samplesref,
45 int av_unused flags);
46
47#endif /* AVFILTER_ASINK_ABUFFER_H */
libavfilter/avfilter.h+2−2
@@ -29,8 +29,8 @@ · 28 unmodified lines
29#include "libavutil/rational.h"29#include "libavutil/rational.h"
30 30
31#define LIBAVFILTER_VERSION_MAJOR 231#define LIBAVFILTER_VERSION_MAJOR 2
32#define LIBAVFILTER_VERSION_MINOR 2732#define LIBAVFILTER_VERSION_MINOR 28
33#define LIBAVFILTER_VERSION_MICRO 533#define LIBAVFILTER_VERSION_MICRO 0
34 34
35#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \35#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
36 LIBAVFILTER_VERSION_MINOR, \36 LIBAVFILTER_VERSION_MINOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t