2011-06-11 16:43:11 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011 Stefano Sabatini
|
|
|
|
*
|
|
|
|
* 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
|
2012-07-05 23:10:28 +00:00
|
|
|
* buffer sink
|
2011-06-11 16:43:11 +00:00
|
|
|
*/
|
|
|
|
|
2012-04-24 10:51:37 +00:00
|
|
|
#include "libavutil/avassert.h"
|
2021-08-31 14:03:14 +00:00
|
|
|
#include "libavutil/avstring.h"
|
2012-11-13 13:16:48 +00:00
|
|
|
#include "libavutil/channel_layout.h"
|
2013-03-10 14:55:33 +00:00
|
|
|
#include "libavutil/common.h"
|
2013-03-27 17:36:51 +00:00
|
|
|
#include "libavutil/internal.h"
|
2013-04-11 12:58:07 +00:00
|
|
|
#include "libavutil/opt.h"
|
2013-03-10 14:55:33 +00:00
|
|
|
|
2016-01-03 14:44:42 +00:00
|
|
|
#define FF_INTERNAL_FIELDS 1
|
|
|
|
#include "framequeue.h"
|
|
|
|
|
2013-03-10 14:55:33 +00:00
|
|
|
#include "audio.h"
|
2011-06-11 16:43:11 +00:00
|
|
|
#include "avfilter.h"
|
2011-09-06 16:37:44 +00:00
|
|
|
#include "buffersink.h"
|
2016-12-19 07:38:25 +00:00
|
|
|
#include "filters.h"
|
2011-12-20 12:08:57 +00:00
|
|
|
#include "internal.h"
|
2011-06-11 16:43:11 +00:00
|
|
|
|
2014-04-11 09:54:15 +00:00
|
|
|
typedef struct BufferSinkContext {
|
2013-04-11 12:58:07 +00:00
|
|
|
const AVClass *class;
|
2012-06-28 09:21:42 +00:00
|
|
|
unsigned warning_limit;
|
2011-08-18 14:21:47 +00:00
|
|
|
|
|
|
|
/* only used for video */
|
2021-12-02 20:08:38 +00:00
|
|
|
enum AVPixelFormat *pixel_fmts; ///< list of accepted pixel formats
|
2013-04-11 12:58:07 +00:00
|
|
|
int pixel_fmts_size;
|
2011-08-18 14:21:47 +00:00
|
|
|
|
|
|
|
/* only used for audio */
|
2021-12-02 20:08:38 +00:00
|
|
|
enum AVSampleFormat *sample_fmts; ///< list of accepted sample formats
|
2013-04-11 12:58:07 +00:00
|
|
|
int sample_fmts_size;
|
2021-08-31 14:03:14 +00:00
|
|
|
#if FF_API_OLD_CHANNEL_LAYOUT
|
2021-12-02 20:08:38 +00:00
|
|
|
int64_t *channel_layouts; ///< list of accepted channel layouts
|
2013-04-11 12:58:07 +00:00
|
|
|
int channel_layouts_size;
|
2021-12-02 20:08:38 +00:00
|
|
|
int *channel_counts; ///< list of accepted channel counts
|
2013-04-11 12:58:07 +00:00
|
|
|
int channel_counts_size;
|
2021-08-31 14:03:14 +00:00
|
|
|
#endif
|
|
|
|
char *channel_layouts_str; ///< list of accepted channel layouts
|
2012-12-26 15:49:16 +00:00
|
|
|
int all_channel_counts;
|
2021-12-02 20:08:38 +00:00
|
|
|
int *sample_rates; ///< list of accepted sample rates
|
2013-04-11 12:58:07 +00:00
|
|
|
int sample_rates_size;
|
2013-03-10 15:44:46 +00:00
|
|
|
|
2016-12-19 07:38:25 +00:00
|
|
|
AVFrame *peeked_frame;
|
2011-06-11 16:43:11 +00:00
|
|
|
} BufferSinkContext;
|
|
|
|
|
2013-04-11 12:58:07 +00:00
|
|
|
#define NB_ITEMS(list) (list ## _size / sizeof(*list))
|
|
|
|
|
2021-08-31 14:03:14 +00:00
|
|
|
#if FF_API_OLD_CHANNEL_LAYOUT
|
2020-08-14 08:53:38 +00:00
|
|
|
static void cleanup_redundant_layouts(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
BufferSinkContext *buf = ctx->priv;
|
|
|
|
int nb_layouts = NB_ITEMS(buf->channel_layouts);
|
|
|
|
int nb_counts = NB_ITEMS(buf->channel_counts);
|
|
|
|
uint64_t counts = 0;
|
|
|
|
int i, lc, n;
|
|
|
|
|
|
|
|
for (i = 0; i < nb_counts; i++)
|
|
|
|
if (buf->channel_counts[i] < 64)
|
2020-09-08 17:55:41 +00:00
|
|
|
counts |= (uint64_t)1 << buf->channel_counts[i];
|
2020-08-14 08:53:38 +00:00
|
|
|
for (i = lc = 0; i < nb_layouts; i++) {
|
2021-08-31 14:03:14 +00:00
|
|
|
n = av_popcount64(buf->channel_layouts[i]);
|
2020-09-08 17:55:41 +00:00
|
|
|
if (n < 64 && (counts & ((uint64_t)1 << n)))
|
2020-08-14 08:53:38 +00:00
|
|
|
av_log(ctx, AV_LOG_WARNING,
|
|
|
|
"Removing channel layout 0x%"PRIx64", redundant with %d channels\n",
|
|
|
|
buf->channel_layouts[i], n);
|
|
|
|
else
|
|
|
|
buf->channel_layouts[lc++] = buf->channel_layouts[i];
|
|
|
|
}
|
|
|
|
buf->channel_layouts_size = lc * sizeof(*buf->channel_layouts);
|
|
|
|
}
|
2021-08-31 14:03:14 +00:00
|
|
|
#endif
|
2020-08-14 08:53:38 +00:00
|
|
|
|
2016-12-19 07:38:25 +00:00
|
|
|
int attribute_align_arg av_buffersink_get_frame(AVFilterContext *ctx, AVFrame *frame)
|
2011-06-11 16:43:11 +00:00
|
|
|
{
|
2016-12-19 07:38:25 +00:00
|
|
|
return av_buffersink_get_frame_flags(ctx, frame, 0);
|
2012-09-23 18:45:49 +00:00
|
|
|
}
|
|
|
|
|
2016-12-19 07:38:25 +00:00
|
|
|
static int return_or_keep_frame(BufferSinkContext *buf, AVFrame *out, AVFrame *in, int flags)
|
2012-09-23 18:45:49 +00:00
|
|
|
{
|
2016-12-19 07:38:25 +00:00
|
|
|
if ((flags & AV_BUFFERSINK_FLAG_PEEK)) {
|
|
|
|
buf->peeked_frame = in;
|
|
|
|
return out ? av_frame_ref(out, in) : 0;
|
|
|
|
} else {
|
|
|
|
av_assert1(out);
|
|
|
|
buf->peeked_frame = NULL;
|
|
|
|
av_frame_move_ref(out, in);
|
|
|
|
av_frame_free(&in);
|
|
|
|
return 0;
|
2012-06-28 09:21:42 +00:00
|
|
|
}
|
2012-06-24 22:30:15 +00:00
|
|
|
}
|
|
|
|
|
2016-12-19 07:38:25 +00:00
|
|
|
static int get_frame_internal(AVFilterContext *ctx, AVFrame *frame, int flags, int samples)
|
2011-06-11 16:43:11 +00:00
|
|
|
{
|
|
|
|
BufferSinkContext *buf = ctx->priv;
|
|
|
|
AVFilterLink *inlink = ctx->inputs[0];
|
2016-12-19 07:38:25 +00:00
|
|
|
int status, ret;
|
2013-03-10 00:30:30 +00:00
|
|
|
AVFrame *cur_frame;
|
2016-12-19 07:38:25 +00:00
|
|
|
int64_t pts;
|
2012-06-24 12:17:14 +00:00
|
|
|
|
2016-12-19 07:38:25 +00:00
|
|
|
if (buf->peeked_frame)
|
|
|
|
return return_or_keep_frame(buf, frame, buf->peeked_frame, flags);
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
ret = samples ? ff_inlink_consume_samples(inlink, samples, samples, &cur_frame) :
|
|
|
|
ff_inlink_consume_frame(inlink, &cur_frame);
|
|
|
|
if (ret < 0) {
|
2011-06-11 16:43:11 +00:00
|
|
|
return ret;
|
2016-12-19 07:38:25 +00:00
|
|
|
} else if (ret) {
|
|
|
|
/* TODO return the frame instead of copying it */
|
|
|
|
return return_or_keep_frame(buf, frame, cur_frame, flags);
|
|
|
|
} else if (ff_inlink_acknowledge_status(inlink, &status, &pts)) {
|
|
|
|
return status;
|
|
|
|
} else if ((flags & AV_BUFFERSINK_FLAG_NO_REQUEST)) {
|
|
|
|
return AVERROR(EAGAIN);
|
|
|
|
} else if (inlink->frame_wanted_out) {
|
2015-09-30 14:11:57 +00:00
|
|
|
ret = ff_filter_graph_run_once(ctx->graph);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2016-12-19 07:38:25 +00:00
|
|
|
} else {
|
|
|
|
ff_inlink_request_frame(inlink);
|
2015-09-30 14:11:57 +00:00
|
|
|
}
|
2011-06-11 16:43:11 +00:00
|
|
|
}
|
2013-03-10 00:30:30 +00:00
|
|
|
}
|
|
|
|
|
2016-12-19 07:38:25 +00:00
|
|
|
int attribute_align_arg av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags)
|
2013-03-10 15:44:46 +00:00
|
|
|
{
|
2016-12-19 07:38:25 +00:00
|
|
|
return get_frame_internal(ctx, frame, flags, ctx->inputs[0]->min_samples);
|
2013-03-10 15:44:46 +00:00
|
|
|
}
|
|
|
|
|
2013-03-15 19:44:57 +00:00
|
|
|
int attribute_align_arg av_buffersink_get_samples(AVFilterContext *ctx,
|
|
|
|
AVFrame *frame, int nb_samples)
|
2013-03-10 00:30:30 +00:00
|
|
|
{
|
2016-12-19 07:38:25 +00:00
|
|
|
return get_frame_internal(ctx, frame, 0, nb_samples);
|
2013-03-10 00:30:30 +00:00
|
|
|
}
|
|
|
|
|
2021-03-06 17:23:43 +00:00
|
|
|
#if FF_API_BUFFERSINK_ALLOC
|
2013-03-10 14:55:33 +00:00
|
|
|
AVBufferSinkParams *av_buffersink_params_alloc(void)
|
2013-03-10 00:30:30 +00:00
|
|
|
{
|
2013-03-10 14:55:33 +00:00
|
|
|
static const int pixel_fmts[] = { AV_PIX_FMT_NONE };
|
|
|
|
AVBufferSinkParams *params = av_malloc(sizeof(AVBufferSinkParams));
|
|
|
|
if (!params)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
params->pixel_fmts = pixel_fmts;
|
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|
|
|
|
AVABufferSinkParams *av_abuffersink_params_alloc(void)
|
|
|
|
{
|
|
|
|
AVABufferSinkParams *params = av_mallocz(sizeof(AVABufferSinkParams));
|
|
|
|
|
|
|
|
if (!params)
|
|
|
|
return NULL;
|
|
|
|
return params;
|
|
|
|
}
|
2019-12-06 07:06:17 +00:00
|
|
|
#endif
|
2013-03-10 14:55:33 +00:00
|
|
|
|
|
|
|
static av_cold int common_init(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
BufferSinkContext *buf = ctx->priv;
|
|
|
|
|
|
|
|
buf->warning_limit = 100;
|
2016-12-19 07:38:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int activate(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
BufferSinkContext *buf = ctx->priv;
|
|
|
|
|
|
|
|
if (buf->warning_limit &&
|
|
|
|
ff_framequeue_queued_frames(&ctx->inputs[0]->fifo) >= buf->warning_limit) {
|
|
|
|
av_log(ctx, AV_LOG_WARNING,
|
|
|
|
"%d buffers queued in %s, something may be wrong.\n",
|
|
|
|
buf->warning_limit,
|
|
|
|
(char *)av_x_if_null(ctx->name, ctx->filter->name));
|
|
|
|
buf->warning_limit *= 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The frame is queued, the rest is up to get_frame_internal */
|
2013-03-10 14:55:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size)
|
|
|
|
{
|
|
|
|
AVFilterLink *inlink = ctx->inputs[0];
|
|
|
|
|
2021-08-05 04:30:54 +00:00
|
|
|
inlink->min_samples = inlink->max_samples = frame_size;
|
2013-03-10 00:30:30 +00:00
|
|
|
}
|
|
|
|
|
2016-12-18 11:31:24 +00:00
|
|
|
#define MAKE_AVFILTERLINK_ACCESSOR(type, field) \
|
|
|
|
type av_buffersink_get_##field(const AVFilterContext *ctx) { \
|
2016-12-19 07:38:25 +00:00
|
|
|
av_assert0(ctx->filter->activate == activate); \
|
2016-12-18 11:31:24 +00:00
|
|
|
return ctx->inputs[0]->field; \
|
2012-06-05 10:40:37 +00:00
|
|
|
}
|
|
|
|
|
2017-01-12 13:43:51 +00:00
|
|
|
MAKE_AVFILTERLINK_ACCESSOR(enum AVMediaType , type )
|
|
|
|
MAKE_AVFILTERLINK_ACCESSOR(AVRational , time_base )
|
|
|
|
MAKE_AVFILTERLINK_ACCESSOR(int , format )
|
2016-12-18 11:31:24 +00:00
|
|
|
|
2017-01-12 13:43:51 +00:00
|
|
|
MAKE_AVFILTERLINK_ACCESSOR(AVRational , frame_rate )
|
|
|
|
MAKE_AVFILTERLINK_ACCESSOR(int , w )
|
|
|
|
MAKE_AVFILTERLINK_ACCESSOR(int , h )
|
|
|
|
MAKE_AVFILTERLINK_ACCESSOR(AVRational , sample_aspect_ratio)
|
2016-12-18 11:31:24 +00:00
|
|
|
|
2021-08-31 14:03:14 +00:00
|
|
|
#if FF_API_OLD_CHANNEL_LAYOUT
|
|
|
|
FF_DISABLE_DEPRECATION_WARNINGS
|
2017-01-12 13:43:51 +00:00
|
|
|
MAKE_AVFILTERLINK_ACCESSOR(uint64_t , channel_layout )
|
2021-08-31 14:03:14 +00:00
|
|
|
FF_ENABLE_DEPRECATION_WARNINGS
|
|
|
|
#endif
|
2017-01-12 13:43:51 +00:00
|
|
|
MAKE_AVFILTERLINK_ACCESSOR(int , sample_rate )
|
2016-12-18 11:31:24 +00:00
|
|
|
|
2017-01-12 13:43:51 +00:00
|
|
|
MAKE_AVFILTERLINK_ACCESSOR(AVBufferRef * , hw_frames_ctx )
|
2016-12-18 11:31:24 +00:00
|
|
|
|
2021-08-31 14:03:14 +00:00
|
|
|
int av_buffersink_get_channels(const AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
av_assert0(ctx->filter->activate == activate);
|
|
|
|
return ctx->inputs[0]->ch_layout.nb_channels;
|
|
|
|
}
|
|
|
|
|
|
|
|
int av_buffersink_get_ch_layout(const AVFilterContext *ctx, AVChannelLayout *out)
|
|
|
|
{
|
|
|
|
AVChannelLayout ch_layout = { 0 };
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
av_assert0(ctx->filter->activate == activate);
|
|
|
|
ret = av_channel_layout_copy(&ch_layout, &ctx->inputs[0]->ch_layout);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
*out = ch_layout;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-13 09:27:52 +00:00
|
|
|
#define CHECK_LIST_SIZE(field) \
|
|
|
|
if (buf->field ## _size % sizeof(*buf->field)) { \
|
|
|
|
av_log(ctx, AV_LOG_ERROR, "Invalid size for " #field ": %d, " \
|
|
|
|
"should be multiple of %d\n", \
|
|
|
|
buf->field ## _size, (int)sizeof(*buf->field)); \
|
|
|
|
return AVERROR(EINVAL); \
|
|
|
|
}
|
2011-08-18 14:21:47 +00:00
|
|
|
static int vsink_query_formats(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
BufferSinkContext *buf = ctx->priv;
|
2013-04-11 12:58:07 +00:00
|
|
|
AVFilterFormats *formats = NULL;
|
|
|
|
unsigned i;
|
|
|
|
int ret;
|
2011-06-11 16:43:11 +00:00
|
|
|
|
2013-04-13 09:27:52 +00:00
|
|
|
CHECK_LIST_SIZE(pixel_fmts)
|
2013-04-11 12:58:07 +00:00
|
|
|
if (buf->pixel_fmts_size) {
|
|
|
|
for (i = 0; i < NB_ITEMS(buf->pixel_fmts); i++)
|
2015-10-05 03:39:25 +00:00
|
|
|
if ((ret = ff_add_format(&formats, buf->pixel_fmts[i])) < 0)
|
2013-04-11 12:58:07 +00:00
|
|
|
return ret;
|
2015-10-05 03:39:25 +00:00
|
|
|
if ((ret = ff_set_common_formats(ctx, formats)) < 0)
|
|
|
|
return ret;
|
2013-04-11 12:58:07 +00:00
|
|
|
} else {
|
2015-10-05 03:39:25 +00:00
|
|
|
if ((ret = ff_default_query_formats(ctx)) < 0)
|
|
|
|
return ret;
|
2013-04-11 12:58:07 +00:00
|
|
|
}
|
2012-04-17 02:01:17 +00:00
|
|
|
|
2011-06-11 16:43:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-18 14:21:47 +00:00
|
|
|
static int asink_query_formats(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
BufferSinkContext *buf = ctx->priv;
|
|
|
|
AVFilterFormats *formats = NULL;
|
2021-08-31 14:03:14 +00:00
|
|
|
AVChannelLayout layout = { 0 };
|
2012-05-16 00:27:31 +00:00
|
|
|
AVFilterChannelLayouts *layouts = NULL;
|
2013-04-11 12:58:07 +00:00
|
|
|
unsigned i;
|
|
|
|
int ret;
|
2011-08-18 14:21:47 +00:00
|
|
|
|
2013-04-13 09:27:52 +00:00
|
|
|
CHECK_LIST_SIZE(sample_fmts)
|
|
|
|
CHECK_LIST_SIZE(sample_rates)
|
2021-08-31 14:03:14 +00:00
|
|
|
#if FF_API_OLD_CHANNEL_LAYOUT
|
2013-04-13 09:27:52 +00:00
|
|
|
CHECK_LIST_SIZE(channel_layouts)
|
|
|
|
CHECK_LIST_SIZE(channel_counts)
|
2021-08-31 14:03:14 +00:00
|
|
|
#endif
|
2013-04-11 12:58:07 +00:00
|
|
|
|
|
|
|
if (buf->sample_fmts_size) {
|
|
|
|
for (i = 0; i < NB_ITEMS(buf->sample_fmts); i++)
|
2015-10-05 03:39:25 +00:00
|
|
|
if ((ret = ff_add_format(&formats, buf->sample_fmts[i])) < 0)
|
2013-04-11 12:58:07 +00:00
|
|
|
return ret;
|
2015-10-05 03:39:25 +00:00
|
|
|
if ((ret = ff_set_common_formats(ctx, formats)) < 0)
|
|
|
|
return ret;
|
2012-06-24 21:28:29 +00:00
|
|
|
}
|
2011-08-18 14:21:47 +00:00
|
|
|
|
2021-08-31 14:03:14 +00:00
|
|
|
if (
|
|
|
|
#if FF_API_OLD_CHANNEL_LAYOUT
|
|
|
|
buf->channel_layouts_size || buf->channel_counts_size ||
|
|
|
|
#endif
|
|
|
|
buf->channel_layouts_str || buf->all_channel_counts) {
|
|
|
|
#if FF_API_OLD_CHANNEL_LAYOUT
|
2020-08-14 08:53:38 +00:00
|
|
|
cleanup_redundant_layouts(ctx);
|
2013-04-11 12:58:07 +00:00
|
|
|
for (i = 0; i < NB_ITEMS(buf->channel_layouts); i++)
|
2021-08-31 14:03:14 +00:00
|
|
|
if ((ret = av_channel_layout_from_mask(&layout, buf->channel_layouts[i])) < 0 ||
|
|
|
|
(ret = ff_add_channel_layout(&layouts, &layout) < 0))
|
2013-04-11 12:58:07 +00:00
|
|
|
return ret;
|
2021-08-31 14:03:14 +00:00
|
|
|
for (i = 0; i < NB_ITEMS(buf->channel_counts); i++) {
|
|
|
|
layout = FF_COUNT2LAYOUT(buf->channel_counts[i]);
|
|
|
|
if ((ret = ff_add_channel_layout(&layouts, &layout)) < 0)
|
2013-04-11 12:58:07 +00:00
|
|
|
return ret;
|
2021-08-31 14:03:14 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (buf->channel_layouts_str) {
|
|
|
|
const char *cur = buf->channel_layouts_str;
|
|
|
|
|
|
|
|
#if FF_API_OLD_CHANNEL_LAYOUT
|
|
|
|
if (layouts)
|
|
|
|
av_log(ctx, AV_LOG_WARNING,
|
|
|
|
"Conflicting ch_layouts and list of channel_counts/channel_layouts. Ignoring the former\n");
|
|
|
|
else
|
|
|
|
#endif
|
2022-03-15 17:18:24 +00:00
|
|
|
while (cur) {
|
|
|
|
char *next = strchr(cur, '|');
|
|
|
|
if (next)
|
|
|
|
*next++ = 0;
|
|
|
|
|
|
|
|
ret = av_channel_layout_from_string(&layout, cur);
|
2021-08-31 14:03:14 +00:00
|
|
|
if (ret < 0) {
|
2022-03-15 17:18:24 +00:00
|
|
|
av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout: %s.\n", cur);
|
2021-08-31 14:03:14 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret = ff_add_channel_layout(&layouts, &layout);
|
|
|
|
av_channel_layout_uninit(&layout);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2022-03-15 17:18:24 +00:00
|
|
|
|
|
|
|
cur = next;
|
2021-08-31 14:03:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-11 12:58:07 +00:00
|
|
|
if (buf->all_channel_counts) {
|
|
|
|
if (layouts)
|
|
|
|
av_log(ctx, AV_LOG_WARNING,
|
|
|
|
"Conflicting all_channel_counts and list in options\n");
|
|
|
|
else if (!(layouts = ff_all_channel_counts()))
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
}
|
2015-10-05 03:39:25 +00:00
|
|
|
if ((ret = ff_set_common_channel_layouts(ctx, layouts)) < 0)
|
|
|
|
return ret;
|
2012-06-24 21:28:29 +00:00
|
|
|
}
|
2012-05-16 00:27:31 +00:00
|
|
|
|
2013-04-11 12:58:07 +00:00
|
|
|
if (buf->sample_rates_size) {
|
|
|
|
formats = NULL;
|
|
|
|
for (i = 0; i < NB_ITEMS(buf->sample_rates); i++)
|
2015-10-05 03:39:25 +00:00
|
|
|
if ((ret = ff_add_format(&formats, buf->sample_rates[i])) < 0)
|
2013-04-11 12:58:07 +00:00
|
|
|
return ret;
|
2015-10-05 03:39:25 +00:00
|
|
|
if ((ret = ff_set_common_samplerates(ctx, formats)) < 0)
|
|
|
|
return ret;
|
2013-02-03 18:33:58 +00:00
|
|
|
}
|
|
|
|
|
2011-08-18 14:21:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-11 12:58:07 +00:00
|
|
|
#define OFFSET(x) offsetof(BufferSinkContext, x)
|
|
|
|
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
|
|
|
|
static const AVOption buffersink_options[] = {
|
|
|
|
{ "pix_fmts", "set the supported pixel formats", OFFSET(pixel_fmts), AV_OPT_TYPE_BINARY, .flags = FLAGS },
|
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
#undef FLAGS
|
2018-12-09 14:30:41 +00:00
|
|
|
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM
|
2013-04-11 12:58:07 +00:00
|
|
|
static const AVOption abuffersink_options[] = {
|
|
|
|
{ "sample_fmts", "set the supported sample formats", OFFSET(sample_fmts), AV_OPT_TYPE_BINARY, .flags = FLAGS },
|
|
|
|
{ "sample_rates", "set the supported sample rates", OFFSET(sample_rates), AV_OPT_TYPE_BINARY, .flags = FLAGS },
|
2021-08-31 14:03:14 +00:00
|
|
|
#if FF_API_OLD_CHANNEL_LAYOUT
|
|
|
|
{ "channel_layouts", "set the supported channel layouts (deprecated, use ch_layouts)",
|
|
|
|
OFFSET(channel_layouts), AV_OPT_TYPE_BINARY, .flags = FLAGS | AV_OPT_FLAG_DEPRECATED },
|
|
|
|
{ "channel_counts", "set the supported channel counts (deprecated, use ch_layouts)",
|
|
|
|
OFFSET(channel_counts), AV_OPT_TYPE_BINARY, .flags = FLAGS | AV_OPT_FLAG_DEPRECATED },
|
|
|
|
#endif
|
|
|
|
{ "ch_layouts", "set a '|'-separated list of supported channel layouts",
|
|
|
|
OFFSET(channel_layouts_str), AV_OPT_TYPE_STRING, .flags = FLAGS },
|
2015-09-08 21:34:18 +00:00
|
|
|
{ "all_channel_counts", "accept all channel counts", OFFSET(all_channel_counts), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS },
|
2013-04-11 12:58:07 +00:00
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
#undef FLAGS
|
|
|
|
|
|
|
|
AVFILTER_DEFINE_CLASS(buffersink);
|
|
|
|
AVFILTER_DEFINE_CLASS(abuffersink);
|
|
|
|
|
2013-03-11 20:26:03 +00:00
|
|
|
static const AVFilterPad avfilter_vsink_buffer_inputs[] = {
|
2013-03-10 18:59:48 +00:00
|
|
|
{
|
2019-10-18 08:54:05 +00:00
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
2013-03-10 18:59:48 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-04-19 16:33:56 +00:00
|
|
|
const AVFilter ff_vsink_buffer = {
|
2019-10-18 08:54:05 +00:00
|
|
|
.name = "buffersink",
|
|
|
|
.description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them available to the end of the filter graph."),
|
|
|
|
.priv_size = sizeof(BufferSinkContext),
|
|
|
|
.priv_class = &buffersink_class,
|
2019-12-06 07:06:16 +00:00
|
|
|
.init = common_init,
|
2019-10-18 08:54:05 +00:00
|
|
|
.activate = activate,
|
2021-08-12 11:05:31 +00:00
|
|
|
FILTER_INPUTS(avfilter_vsink_buffer_inputs),
|
2019-10-18 08:54:05 +00:00
|
|
|
.outputs = NULL,
|
2021-09-27 10:07:35 +00:00
|
|
|
FILTER_QUERY_FUNC(vsink_query_formats),
|
2013-03-10 18:59:48 +00:00
|
|
|
};
|
|
|
|
|
2013-03-11 20:26:03 +00:00
|
|
|
static const AVFilterPad avfilter_asink_abuffer_inputs[] = {
|
2012-11-28 19:01:59 +00:00
|
|
|
{
|
2019-10-18 08:54:05 +00:00
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
2012-11-28 19:01:59 +00:00
|
|
|
},
|
2012-08-31 20:02:08 +00:00
|
|
|
};
|
|
|
|
|
2021-04-19 16:33:56 +00:00
|
|
|
const AVFilter ff_asink_abuffer = {
|
2019-10-18 08:54:05 +00:00
|
|
|
.name = "abuffersink",
|
|
|
|
.description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."),
|
|
|
|
.priv_class = &abuffersink_class,
|
|
|
|
.priv_size = sizeof(BufferSinkContext),
|
2019-12-06 07:06:16 +00:00
|
|
|
.init = common_init,
|
2019-10-18 08:54:05 +00:00
|
|
|
.activate = activate,
|
2021-08-12 11:05:31 +00:00
|
|
|
FILTER_INPUTS(avfilter_asink_abuffer_inputs),
|
2019-10-18 08:54:05 +00:00
|
|
|
.outputs = NULL,
|
2021-09-27 10:07:35 +00:00
|
|
|
FILTER_QUERY_FUNC(asink_query_formats),
|
2011-08-18 14:21:47 +00:00
|
|
|
};
|