2011-06-11 19:43:11 +03: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-06 02:10:28 +03:00
|
|
|
* buffer sink
|
2011-06-11 19:43:11 +03:00
|
|
|
*/
|
|
|
|
|
2012-04-24 13:51:37 +03:00
|
|
|
#include "libavutil/avassert.h"
|
2021-08-31 16:03:14 +02:00
|
|
|
#include "libavutil/avstring.h"
|
2012-11-13 16:16:48 +03:00
|
|
|
#include "libavutil/channel_layout.h"
|
2013-03-10 17:55:33 +03:00
|
|
|
#include "libavutil/common.h"
|
2013-03-27 20:36:51 +03:00
|
|
|
#include "libavutil/internal.h"
|
2024-09-25 17:34:13 +02:00
|
|
|
#include "libavutil/mem.h"
|
2013-04-11 15:58:07 +03:00
|
|
|
#include "libavutil/opt.h"
|
2013-03-10 17:55:33 +03:00
|
|
|
|
|
|
|
#include "audio.h"
|
2011-06-11 19:43:11 +03:00
|
|
|
#include "avfilter.h"
|
2024-02-10 18:31:13 +02:00
|
|
|
#include "avfilter_internal.h"
|
2011-09-06 19:37:44 +03:00
|
|
|
#include "buffersink.h"
|
2016-12-19 09:38:25 +02:00
|
|
|
#include "filters.h"
|
2023-08-03 23:44:07 +02:00
|
|
|
#include "formats.h"
|
2022-10-25 15:36:36 +02:00
|
|
|
#include "framequeue.h"
|
2023-08-03 14:37:51 +02:00
|
|
|
#include "video.h"
|
2011-06-11 19:43:11 +03:00
|
|
|
|
2014-04-11 12:54:15 +03:00
|
|
|
typedef struct BufferSinkContext {
|
2013-04-11 15:58:07 +03:00
|
|
|
const AVClass *class;
|
2012-06-28 12:21:42 +03:00
|
|
|
unsigned warning_limit;
|
2024-09-25 14:38:49 +02:00
|
|
|
unsigned frame_size;
|
2011-08-18 17:21:47 +03:00
|
|
|
|
|
|
|
/* only used for video */
|
2024-09-25 17:34:13 +02:00
|
|
|
#if FF_API_BUFFERSINK_OPTS
|
2021-12-02 22:08:38 +02:00
|
|
|
enum AVPixelFormat *pixel_fmts; ///< list of accepted pixel formats
|
2013-04-11 15:58:07 +03:00
|
|
|
int pixel_fmts_size;
|
2024-02-05 20:22:04 +02:00
|
|
|
enum AVColorSpace *color_spaces; ///< list of accepted color spaces
|
|
|
|
int color_spaces_size;
|
|
|
|
enum AVColorRange *color_ranges; ///< list of accepted color ranges
|
|
|
|
int color_ranges_size;
|
2024-09-25 17:34:13 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
enum AVPixelFormat *pixel_formats;
|
|
|
|
unsigned nb_pixel_formats;
|
|
|
|
|
|
|
|
int *colorspaces;
|
|
|
|
unsigned nb_colorspaces;
|
|
|
|
|
|
|
|
int *colorranges;
|
|
|
|
unsigned nb_colorranges;
|
2011-08-18 17:21:47 +03:00
|
|
|
|
|
|
|
/* only used for audio */
|
2024-09-25 17:34:13 +02:00
|
|
|
#if FF_API_BUFFERSINK_OPTS
|
2021-12-02 22:08:38 +02:00
|
|
|
enum AVSampleFormat *sample_fmts; ///< list of accepted sample formats
|
2013-04-11 15:58:07 +03:00
|
|
|
int sample_fmts_size;
|
2021-08-31 16:03:14 +02:00
|
|
|
char *channel_layouts_str; ///< list of accepted channel layouts
|
2012-12-26 18:49:16 +03:00
|
|
|
int all_channel_counts;
|
2021-12-02 22:08:38 +02:00
|
|
|
int *sample_rates; ///< list of accepted sample rates
|
2013-04-11 15:58:07 +03:00
|
|
|
int sample_rates_size;
|
2024-09-25 17:34:13 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
enum AVSampleFormat *sample_formats;
|
|
|
|
unsigned nb_sample_formats;
|
|
|
|
|
|
|
|
int *samplerates;
|
|
|
|
unsigned nb_samplerates;
|
|
|
|
|
|
|
|
AVChannelLayout *channel_layouts;
|
|
|
|
unsigned nb_channel_layouts;
|
2013-03-10 18:44:46 +03:00
|
|
|
|
2016-12-19 09:38:25 +02:00
|
|
|
AVFrame *peeked_frame;
|
2011-06-11 19:43:11 +03:00
|
|
|
} BufferSinkContext;
|
|
|
|
|
2016-12-19 09:38:25 +02:00
|
|
|
int attribute_align_arg av_buffersink_get_frame(AVFilterContext *ctx, AVFrame *frame)
|
2011-06-11 19:43:11 +03:00
|
|
|
{
|
2016-12-19 09:38:25 +02:00
|
|
|
return av_buffersink_get_frame_flags(ctx, frame, 0);
|
2012-09-23 21:45:49 +03:00
|
|
|
}
|
|
|
|
|
2016-12-19 09:38:25 +02:00
|
|
|
static int return_or_keep_frame(BufferSinkContext *buf, AVFrame *out, AVFrame *in, int flags)
|
2012-09-23 21:45:49 +03:00
|
|
|
{
|
2016-12-19 09:38:25 +02: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 12:21:42 +03:00
|
|
|
}
|
2012-06-25 01:30:15 +03:00
|
|
|
}
|
|
|
|
|
2016-12-19 09:38:25 +02:00
|
|
|
static int get_frame_internal(AVFilterContext *ctx, AVFrame *frame, int flags, int samples)
|
2011-06-11 19:43:11 +03:00
|
|
|
{
|
|
|
|
BufferSinkContext *buf = ctx->priv;
|
|
|
|
AVFilterLink *inlink = ctx->inputs[0];
|
2024-08-11 16:31:11 +02:00
|
|
|
FilterLinkInternal *li = ff_link_internal(inlink);
|
2016-12-19 09:38:25 +02:00
|
|
|
int status, ret;
|
2013-03-10 03:30:30 +03:00
|
|
|
AVFrame *cur_frame;
|
2016-12-19 09:38:25 +02:00
|
|
|
int64_t pts;
|
2012-06-24 15:17:14 +03:00
|
|
|
|
2016-12-19 09:38:25 +02: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 19:43:11 +03:00
|
|
|
return ret;
|
2016-12-19 09:38:25 +02: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);
|
2024-08-11 16:31:11 +02:00
|
|
|
} else if (li->frame_wanted_out) {
|
2015-09-30 16:11:57 +02:00
|
|
|
ret = ff_filter_graph_run_once(ctx->graph);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2016-12-19 09:38:25 +02:00
|
|
|
} else {
|
|
|
|
ff_inlink_request_frame(inlink);
|
2015-09-30 16:11:57 +02:00
|
|
|
}
|
2011-06-11 19:43:11 +03:00
|
|
|
}
|
2013-03-10 03:30:30 +03:00
|
|
|
}
|
|
|
|
|
2016-12-19 09:38:25 +02:00
|
|
|
int attribute_align_arg av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags)
|
2013-03-10 18:44:46 +03:00
|
|
|
{
|
2024-08-05 11:41:53 +02:00
|
|
|
return get_frame_internal(ctx, frame, flags,
|
|
|
|
ff_filter_link(ctx->inputs[0])->min_samples);
|
2013-03-10 18:44:46 +03:00
|
|
|
}
|
|
|
|
|
2013-03-15 22:44:57 +03:00
|
|
|
int attribute_align_arg av_buffersink_get_samples(AVFilterContext *ctx,
|
|
|
|
AVFrame *frame, int nb_samples)
|
2013-03-10 03:30:30 +03:00
|
|
|
{
|
2016-12-19 09:38:25 +02:00
|
|
|
return get_frame_internal(ctx, frame, 0, nb_samples);
|
2013-03-10 03:30:30 +03:00
|
|
|
}
|
|
|
|
|
2013-03-10 17:55:33 +03:00
|
|
|
static av_cold int common_init(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
BufferSinkContext *buf = ctx->priv;
|
2024-09-25 11:09:58 +02:00
|
|
|
int ret = 0;
|
2013-03-10 17:55:33 +03:00
|
|
|
|
2024-09-25 10:52:19 +02:00
|
|
|
#if FF_API_BUFFERSINK_OPTS
|
|
|
|
|
|
|
|
#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); \
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx->input_pads[0].type == AVMEDIA_TYPE_VIDEO) {
|
|
|
|
if ((buf->pixel_fmts_size || buf->color_spaces_size || buf->color_ranges_size) &&
|
|
|
|
(buf->nb_pixel_formats || buf->nb_colorspaces || buf->nb_colorranges)) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR, "Cannot combine old and new format lists\n");
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK_LIST_SIZE(pixel_fmts)
|
|
|
|
CHECK_LIST_SIZE(color_spaces)
|
|
|
|
CHECK_LIST_SIZE(color_ranges)
|
|
|
|
} else {
|
|
|
|
if ((buf->sample_fmts_size || buf->channel_layouts_str || buf->sample_rates_size) &&
|
|
|
|
(buf->nb_sample_formats || buf->nb_samplerates || buf->nb_channel_layouts)) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR, "Cannot combine old and new format lists\n");
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK_LIST_SIZE(sample_fmts)
|
|
|
|
CHECK_LIST_SIZE(sample_rates)
|
2024-09-25 11:09:58 +02:00
|
|
|
|
|
|
|
if (buf->channel_layouts_str) {
|
|
|
|
const char *cur = buf->channel_layouts_str;
|
|
|
|
|
|
|
|
if (buf->all_channel_counts)
|
|
|
|
av_log(ctx, AV_LOG_WARNING,
|
|
|
|
"Conflicting all_channel_counts and list in options\n");
|
|
|
|
|
|
|
|
while (cur) {
|
|
|
|
void *tmp;
|
|
|
|
char *next = strchr(cur, '|');
|
|
|
|
if (next)
|
|
|
|
*next++ = 0;
|
|
|
|
|
|
|
|
// +2 for the new element and terminator
|
|
|
|
tmp = av_realloc_array(buf->channel_layouts, buf->nb_channel_layouts + 2,
|
|
|
|
sizeof(*buf->channel_layouts));
|
|
|
|
if (!tmp)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
|
|
|
memset(&buf->channel_layouts[buf->nb_channel_layouts], 0,
|
|
|
|
sizeof(*buf->channel_layouts));
|
|
|
|
buf->nb_channel_layouts++;
|
|
|
|
|
|
|
|
ret = av_channel_layout_from_string(&buf->channel_layouts[buf->nb_channel_layouts - 1], cur);
|
|
|
|
if (ret < 0) {
|
|
|
|
av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout: %s.\n", cur);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
cur = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buf->nb_channel_layouts)
|
|
|
|
buf->channel_layouts[buf->nb_channel_layouts] = (AVChannelLayout){ 0 };
|
|
|
|
}
|
2024-09-25 10:52:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef CHECK_LIST_SIZE
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-03-10 17:55:33 +03:00
|
|
|
buf->warning_limit = 100;
|
2016-12-19 09:38:25 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-09-25 17:34:13 +02:00
|
|
|
#define TERMINATE_ARRAY(arr, val) \
|
|
|
|
if (s->arr) { \
|
|
|
|
void *tmp = av_realloc_array(s->arr, s->nb_ ## arr + 1, sizeof(*s->arr)); \
|
|
|
|
if (!tmp) \
|
|
|
|
return AVERROR(ENOMEM); \
|
|
|
|
s->arr = tmp; \
|
|
|
|
s->arr[s->nb_ ## arr] = val; \
|
|
|
|
}
|
|
|
|
|
|
|
|
static int init_video(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
BufferSinkContext *s = ctx->priv;
|
|
|
|
|
|
|
|
TERMINATE_ARRAY(pixel_formats, AV_PIX_FMT_NONE);
|
|
|
|
TERMINATE_ARRAY(colorranges, -1);
|
|
|
|
TERMINATE_ARRAY(colorspaces, -1);
|
|
|
|
|
|
|
|
return common_init(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int init_audio(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
BufferSinkContext *s = ctx->priv;
|
|
|
|
|
|
|
|
TERMINATE_ARRAY(sample_formats, AV_SAMPLE_FMT_NONE);
|
|
|
|
TERMINATE_ARRAY(samplerates, -1);
|
|
|
|
TERMINATE_ARRAY(channel_layouts, (AVChannelLayout){ .nb_channels = 0 });
|
|
|
|
|
|
|
|
return common_init(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef TERMINATE_ARRAY
|
|
|
|
|
2023-11-23 17:31:53 +02:00
|
|
|
static void uninit(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
BufferSinkContext *buf = ctx->priv;
|
|
|
|
|
|
|
|
av_frame_free(&buf->peeked_frame);
|
|
|
|
}
|
|
|
|
|
2016-12-19 09:38:25 +02:00
|
|
|
static int activate(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
BufferSinkContext *buf = ctx->priv;
|
2022-10-25 15:36:36 +02:00
|
|
|
FilterLinkInternal * const li = ff_link_internal(ctx->inputs[0]);
|
2016-12-19 09:38:25 +02:00
|
|
|
|
|
|
|
if (buf->warning_limit &&
|
2022-10-25 15:36:36 +02:00
|
|
|
ff_framequeue_queued_frames(&li->fifo) >= buf->warning_limit) {
|
2016-12-19 09:38:25 +02:00
|
|
|
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 17:55:33 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-09-25 14:38:49 +02:00
|
|
|
static int config_input_audio(AVFilterLink *inlink)
|
|
|
|
{
|
|
|
|
BufferSinkContext *buf = inlink->dst->priv;
|
|
|
|
FilterLink *l = ff_filter_link(inlink);
|
|
|
|
|
|
|
|
l->min_samples = l->max_samples = buf->frame_size;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-10 17:55:33 +03:00
|
|
|
void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size)
|
|
|
|
{
|
2024-09-25 14:38:49 +02:00
|
|
|
BufferSinkContext *buf = ctx->priv;
|
|
|
|
buf->frame_size = frame_size;
|
2013-03-10 17:55:33 +03:00
|
|
|
|
2024-09-25 14:38:49 +02:00
|
|
|
if (ctx->inputs && ctx->inputs[0]) {
|
|
|
|
FilterLink *l = ff_filter_link(ctx->inputs[0]);
|
|
|
|
l->min_samples = l->max_samples = buf->frame_size;
|
|
|
|
}
|
2013-03-10 03:30:30 +03:00
|
|
|
}
|
|
|
|
|
2016-12-18 13:31:24 +02:00
|
|
|
#define MAKE_AVFILTERLINK_ACCESSOR(type, field) \
|
|
|
|
type av_buffersink_get_##field(const AVFilterContext *ctx) { \
|
2016-12-19 09:38:25 +02:00
|
|
|
av_assert0(ctx->filter->activate == activate); \
|
2016-12-18 13:31:24 +02:00
|
|
|
return ctx->inputs[0]->field; \
|
2012-06-05 13:40:37 +03:00
|
|
|
}
|
|
|
|
|
2017-01-12 15:43:51 +02:00
|
|
|
MAKE_AVFILTERLINK_ACCESSOR(enum AVMediaType , type )
|
|
|
|
MAKE_AVFILTERLINK_ACCESSOR(AVRational , time_base )
|
|
|
|
MAKE_AVFILTERLINK_ACCESSOR(int , format )
|
2016-12-18 13:31:24 +02:00
|
|
|
|
2017-01-12 15:43:51 +02:00
|
|
|
MAKE_AVFILTERLINK_ACCESSOR(int , w )
|
|
|
|
MAKE_AVFILTERLINK_ACCESSOR(int , h )
|
|
|
|
MAKE_AVFILTERLINK_ACCESSOR(AVRational , sample_aspect_ratio)
|
2023-12-31 23:36:12 +02:00
|
|
|
MAKE_AVFILTERLINK_ACCESSOR(enum AVColorSpace, colorspace)
|
|
|
|
MAKE_AVFILTERLINK_ACCESSOR(enum AVColorRange, color_range)
|
2016-12-18 13:31:24 +02:00
|
|
|
|
2017-01-12 15:43:51 +02:00
|
|
|
MAKE_AVFILTERLINK_ACCESSOR(int , sample_rate )
|
2016-12-18 13:31:24 +02:00
|
|
|
|
2024-08-06 08:50:21 +02:00
|
|
|
AVRational av_buffersink_get_frame_rate(const AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
FilterLink *l = ff_filter_link(ctx->inputs[0]);
|
|
|
|
av_assert0(ctx->filter->activate == activate);
|
|
|
|
return l->frame_rate;
|
|
|
|
}
|
|
|
|
|
2024-08-05 18:00:30 +02:00
|
|
|
AVBufferRef* av_buffersink_get_hw_frames_ctx(const AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
FilterLink *l = ff_filter_link(ctx->inputs[0]);
|
|
|
|
av_assert0(ctx->filter->activate == activate);
|
|
|
|
return l->hw_frames_ctx;
|
|
|
|
}
|
2016-12-18 13:31:24 +02:00
|
|
|
|
2021-08-31 16:03:14 +02: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;
|
|
|
|
}
|
|
|
|
|
2024-09-25 17:34:13 +02:00
|
|
|
#if FF_API_BUFFERSINK_OPTS
|
|
|
|
#define NB_ITEMS(list) (list ## _size / sizeof(*list))
|
|
|
|
#endif
|
|
|
|
|
2024-09-25 10:38:59 +02:00
|
|
|
static int vsink_query_formats(const AVFilterContext *ctx,
|
|
|
|
AVFilterFormatsConfig **cfg_in,
|
|
|
|
AVFilterFormatsConfig **cfg_out)
|
2011-08-18 17:21:47 +03:00
|
|
|
{
|
2024-09-25 10:38:59 +02:00
|
|
|
const BufferSinkContext *buf = ctx->priv;
|
2013-04-11 15:58:07 +03:00
|
|
|
int ret;
|
2011-06-11 19:43:11 +03:00
|
|
|
|
2024-09-25 17:34:13 +02:00
|
|
|
#if FF_API_BUFFERSINK_OPTS
|
|
|
|
if (buf->nb_pixel_formats || buf->nb_colorspaces || buf->nb_colorranges) {
|
|
|
|
#endif
|
|
|
|
if (buf->nb_pixel_formats) {
|
2024-09-25 10:38:59 +02:00
|
|
|
ret = ff_set_common_formats_from_list2(ctx, cfg_in, cfg_out, buf->pixel_formats);
|
2024-09-25 17:34:13 +02:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (buf->nb_colorspaces) {
|
2024-09-25 10:38:59 +02:00
|
|
|
ret = ff_set_common_color_spaces_from_list2(ctx, cfg_in, cfg_out, buf->colorspaces);
|
2024-09-25 17:34:13 +02:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (buf->nb_colorranges) {
|
2024-09-25 10:38:59 +02:00
|
|
|
ret = ff_set_common_color_ranges_from_list2(ctx, cfg_in, cfg_out, buf->colorranges);
|
2024-09-25 17:34:13 +02:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#if FF_API_BUFFERSINK_OPTS
|
|
|
|
} else {
|
|
|
|
unsigned i;
|
2013-04-11 15:58:07 +03:00
|
|
|
if (buf->pixel_fmts_size) {
|
2024-02-05 20:22:04 +02:00
|
|
|
AVFilterFormats *formats = NULL;
|
2013-04-11 15:58:07 +03:00
|
|
|
for (i = 0; i < NB_ITEMS(buf->pixel_fmts); i++)
|
2015-10-05 05:39:25 +02:00
|
|
|
if ((ret = ff_add_format(&formats, buf->pixel_fmts[i])) < 0)
|
2013-04-11 15:58:07 +03:00
|
|
|
return ret;
|
2024-09-25 10:38:59 +02:00
|
|
|
if ((ret = ff_set_common_formats2(ctx, cfg_in, cfg_out, formats)) < 0)
|
2015-10-05 05:39:25 +02:00
|
|
|
return ret;
|
2024-02-05 20:22:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (buf->color_spaces_size) {
|
|
|
|
AVFilterFormats *formats = NULL;
|
|
|
|
for (i = 0; i < NB_ITEMS(buf->color_spaces); i++)
|
|
|
|
if ((ret = ff_add_format(&formats, buf->color_spaces[i])) < 0)
|
|
|
|
return ret;
|
2024-09-25 10:38:59 +02:00
|
|
|
if ((ret = ff_set_common_color_spaces2(ctx, cfg_in, cfg_out, formats)) < 0)
|
2024-02-05 20:22:04 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buf->color_ranges_size) {
|
|
|
|
AVFilterFormats *formats = NULL;
|
|
|
|
for (i = 0; i < NB_ITEMS(buf->color_ranges); i++)
|
|
|
|
if ((ret = ff_add_format(&formats, buf->color_ranges[i])) < 0)
|
|
|
|
return ret;
|
2024-09-25 10:38:59 +02:00
|
|
|
if ((ret = ff_set_common_color_ranges2(ctx, cfg_in, cfg_out, formats)) < 0)
|
2015-10-05 05:39:25 +02:00
|
|
|
return ret;
|
2013-04-11 15:58:07 +03:00
|
|
|
}
|
2024-09-25 17:34:13 +02:00
|
|
|
}
|
|
|
|
#endif
|
2012-04-17 05:01:17 +03:00
|
|
|
|
2011-06-11 19:43:11 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-09-25 10:38:59 +02:00
|
|
|
static int asink_query_formats(const AVFilterContext *ctx,
|
|
|
|
AVFilterFormatsConfig **cfg_in,
|
|
|
|
AVFilterFormatsConfig **cfg_out)
|
2011-08-18 17:21:47 +03:00
|
|
|
{
|
2024-09-25 10:38:59 +02:00
|
|
|
const BufferSinkContext *buf = ctx->priv;
|
2024-09-25 17:34:13 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
#if FF_API_BUFFERSINK_OPTS
|
|
|
|
if (buf->nb_sample_formats || buf->nb_samplerates || buf->nb_channel_layouts) {
|
|
|
|
#endif
|
|
|
|
if (buf->nb_sample_formats) {
|
2024-09-25 10:38:59 +02:00
|
|
|
ret = ff_set_common_formats_from_list2(ctx, cfg_in, cfg_out, buf->sample_formats);
|
2024-09-25 17:34:13 +02:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (buf->nb_samplerates) {
|
2024-09-25 10:38:59 +02:00
|
|
|
ret = ff_set_common_samplerates_from_list2(ctx, cfg_in, cfg_out, buf->samplerates);
|
2024-09-25 17:34:13 +02:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if (buf->nb_channel_layouts) {
|
2024-09-25 10:38:59 +02:00
|
|
|
ret = ff_set_common_channel_layouts_from_list2(ctx, cfg_in, cfg_out, buf->channel_layouts);
|
2024-09-25 17:34:13 +02:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#if FF_API_BUFFERSINK_OPTS
|
|
|
|
} else {
|
2011-08-18 17:21:47 +03:00
|
|
|
AVFilterFormats *formats = NULL;
|
2013-04-11 15:58:07 +03:00
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
if (buf->sample_fmts_size) {
|
|
|
|
for (i = 0; i < NB_ITEMS(buf->sample_fmts); i++)
|
2015-10-05 05:39:25 +02:00
|
|
|
if ((ret = ff_add_format(&formats, buf->sample_fmts[i])) < 0)
|
2013-04-11 15:58:07 +03:00
|
|
|
return ret;
|
2024-09-25 10:38:59 +02:00
|
|
|
if ((ret = ff_set_common_formats2(ctx, cfg_in, cfg_out, formats)) < 0)
|
2015-10-05 05:39:25 +02:00
|
|
|
return ret;
|
2012-06-25 00:28:29 +03:00
|
|
|
}
|
2011-08-18 17:21:47 +03:00
|
|
|
|
2024-09-25 11:09:58 +02:00
|
|
|
if (buf->nb_channel_layouts) {
|
2024-09-25 10:38:59 +02:00
|
|
|
ret = ff_set_common_channel_layouts_from_list2(ctx, cfg_in, cfg_out, buf->channel_layouts);
|
2024-09-25 11:09:58 +02:00
|
|
|
if (ret < 0)
|
2015-10-05 05:39:25 +02:00
|
|
|
return ret;
|
2012-06-25 00:28:29 +03:00
|
|
|
}
|
2012-05-16 03:27:31 +03:00
|
|
|
|
2013-04-11 15:58:07 +03:00
|
|
|
if (buf->sample_rates_size) {
|
|
|
|
formats = NULL;
|
|
|
|
for (i = 0; i < NB_ITEMS(buf->sample_rates); i++)
|
2015-10-05 05:39:25 +02:00
|
|
|
if ((ret = ff_add_format(&formats, buf->sample_rates[i])) < 0)
|
2013-04-11 15:58:07 +03:00
|
|
|
return ret;
|
2024-09-25 10:38:59 +02:00
|
|
|
if ((ret = ff_set_common_samplerates2(ctx, cfg_in, cfg_out, formats)) < 0)
|
2015-10-05 05:39:25 +02:00
|
|
|
return ret;
|
2013-02-03 21:33:58 +03:00
|
|
|
}
|
2024-09-25 17:34:13 +02:00
|
|
|
}
|
|
|
|
#endif
|
2013-02-03 21:33:58 +03:00
|
|
|
|
2011-08-18 17:21:47 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-11 15:58:07 +03:00
|
|
|
#define OFFSET(x) offsetof(BufferSinkContext, x)
|
|
|
|
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
|
|
|
|
static const AVOption buffersink_options[] = {
|
2024-09-25 17:34:13 +02:00
|
|
|
#if FF_API_BUFFERSINK_OPTS
|
|
|
|
{ "pix_fmts", "set the supported pixel formats", OFFSET(pixel_fmts), AV_OPT_TYPE_BINARY, .flags = FLAGS | AV_OPT_FLAG_DEPRECATED },
|
|
|
|
{ "color_spaces", "set the supported color spaces", OFFSET(color_spaces), AV_OPT_TYPE_BINARY, .flags = FLAGS | AV_OPT_FLAG_DEPRECATED },
|
|
|
|
{ "color_ranges", "set the supported color ranges", OFFSET(color_ranges), AV_OPT_TYPE_BINARY, .flags = FLAGS | AV_OPT_FLAG_DEPRECATED },
|
|
|
|
#endif
|
|
|
|
|
|
|
|
{ "pixel_formats", "array of supported pixel formats", OFFSET(pixel_formats),
|
|
|
|
AV_OPT_TYPE_PIXEL_FMT | AV_OPT_TYPE_FLAG_ARRAY, .max = INT_MAX, .flags = FLAGS },
|
|
|
|
{ "colorspaces", "array of supported color spaces", OFFSET(colorspaces),
|
|
|
|
AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY, .max = INT_MAX, .flags = FLAGS },
|
|
|
|
{ "colorranges", "array of supported color ranges", OFFSET(colorranges),
|
|
|
|
AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY, .max = INT_MAX, .flags = FLAGS },
|
|
|
|
|
2013-04-11 15:58:07 +03:00
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
#undef FLAGS
|
2018-12-09 16:30:41 +02:00
|
|
|
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_AUDIO_PARAM
|
2013-04-11 15:58:07 +03:00
|
|
|
static const AVOption abuffersink_options[] = {
|
2024-09-25 17:34:13 +02:00
|
|
|
#if FF_API_BUFFERSINK_OPTS
|
|
|
|
{ "sample_fmts", "set the supported sample formats", OFFSET(sample_fmts), AV_OPT_TYPE_BINARY, .flags = FLAGS | AV_OPT_FLAG_DEPRECATED },
|
|
|
|
{ "sample_rates", "set the supported sample rates", OFFSET(sample_rates), AV_OPT_TYPE_BINARY, .flags = FLAGS | AV_OPT_FLAG_DEPRECATED },
|
2021-08-31 16:03:14 +02:00
|
|
|
{ "ch_layouts", "set a '|'-separated list of supported channel layouts",
|
2024-09-25 17:34:13 +02:00
|
|
|
OFFSET(channel_layouts_str), AV_OPT_TYPE_STRING, .flags = FLAGS | AV_OPT_FLAG_DEPRECATED },
|
|
|
|
{ "all_channel_counts", "accept all channel counts", OFFSET(all_channel_counts), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS | AV_OPT_FLAG_DEPRECATED },
|
|
|
|
#endif
|
|
|
|
|
|
|
|
{ "sample_formats", "array of supported sample formats", OFFSET(sample_formats),
|
|
|
|
AV_OPT_TYPE_SAMPLE_FMT | AV_OPT_TYPE_FLAG_ARRAY, .max = INT_MAX, .flags = FLAGS },
|
|
|
|
{ "samplerates", "array of supported sample formats", OFFSET(samplerates),
|
|
|
|
AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY, .max = INT_MAX, .flags = FLAGS },
|
|
|
|
{ "channel_layouts", "array of supported channel layouts", OFFSET(channel_layouts),
|
|
|
|
AV_OPT_TYPE_CHLAYOUT | AV_OPT_TYPE_FLAG_ARRAY, .flags = FLAGS },
|
2013-04-11 15:58:07 +03:00
|
|
|
{ NULL },
|
|
|
|
};
|
|
|
|
#undef FLAGS
|
|
|
|
|
|
|
|
AVFILTER_DEFINE_CLASS(buffersink);
|
|
|
|
AVFILTER_DEFINE_CLASS(abuffersink);
|
|
|
|
|
2021-04-19 18:33:56 +02:00
|
|
|
const AVFilter ff_vsink_buffer = {
|
2019-10-18 10:54:05 +02: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,
|
2024-09-25 17:34:13 +02:00
|
|
|
.init = init_video,
|
2023-11-23 17:31:53 +02:00
|
|
|
.uninit = uninit,
|
2019-10-18 10:54:05 +02:00
|
|
|
.activate = activate,
|
2023-08-03 14:37:51 +02:00
|
|
|
FILTER_INPUTS(ff_video_default_filterpad),
|
2019-10-18 10:54:05 +02:00
|
|
|
.outputs = NULL,
|
2024-09-25 10:38:59 +02:00
|
|
|
FILTER_QUERY_FUNC2(vsink_query_formats),
|
2013-03-10 21:59:48 +03:00
|
|
|
};
|
|
|
|
|
2024-09-25 14:38:49 +02:00
|
|
|
static const AVFilterPad inputs_audio[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
.config_props = config_input_audio,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-04-19 18:33:56 +02:00
|
|
|
const AVFilter ff_asink_abuffer = {
|
2019-10-18 10:54:05 +02: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),
|
2024-09-25 17:34:13 +02:00
|
|
|
.init = init_audio,
|
2023-11-23 17:31:53 +02:00
|
|
|
.uninit = uninit,
|
2019-10-18 10:54:05 +02:00
|
|
|
.activate = activate,
|
2024-09-25 14:38:49 +02:00
|
|
|
FILTER_INPUTS(inputs_audio),
|
2019-10-18 10:54:05 +02:00
|
|
|
.outputs = NULL,
|
2024-09-25 10:38:59 +02:00
|
|
|
FILTER_QUERY_FUNC2(asink_query_formats),
|
2011-08-18 17:21:47 +03:00
|
|
|
};
|