2011-08-17 14:00:20 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011 Stefano Sabatini
|
|
|
|
* Copyright (c) 2011 Mina Nagy Zaki
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* resampling audio filter
|
|
|
|
*/
|
|
|
|
|
2012-05-17 14:10:14 +03:00
|
|
|
#include "libavutil/avstring.h"
|
2012-11-13 16:16:48 +03:00
|
|
|
#include "libavutil/channel_layout.h"
|
2012-05-17 14:10:14 +03:00
|
|
|
#include "libavutil/opt.h"
|
2012-05-17 17:12:54 +03:00
|
|
|
#include "libavutil/samplefmt.h"
|
|
|
|
#include "libavutil/avassert.h"
|
2012-01-21 22:26:31 +03:00
|
|
|
#include "libswresample/swresample.h"
|
2011-08-17 14:00:20 +03:00
|
|
|
#include "avfilter.h"
|
2012-05-12 18:58:14 +03:00
|
|
|
#include "audio.h"
|
2023-05-17 09:15:51 +02:00
|
|
|
#include "filters.h"
|
2023-08-03 23:44:07 +02:00
|
|
|
#include "formats.h"
|
2011-08-17 14:00:20 +03:00
|
|
|
|
2017-05-12 20:00:49 +02:00
|
|
|
typedef struct AResampleContext {
|
2013-04-11 21:23:52 +03:00
|
|
|
const AVClass *class;
|
|
|
|
int sample_rate_arg;
|
2011-08-17 14:00:20 +03:00
|
|
|
double ratio;
|
2012-01-21 22:26:31 +03:00
|
|
|
struct SwrContext *swr;
|
2012-05-17 23:39:02 +03:00
|
|
|
int64_t next_pts;
|
2014-11-04 17:01:07 +02:00
|
|
|
int more_data;
|
2023-05-17 09:15:51 +02:00
|
|
|
int eof;
|
2011-08-17 14:00:20 +03:00
|
|
|
} AResampleContext;
|
|
|
|
|
2021-09-13 16:54:58 +02:00
|
|
|
static av_cold int preinit(AVFilterContext *ctx)
|
2011-08-17 14:00:20 +03:00
|
|
|
{
|
|
|
|
AResampleContext *aresample = ctx->priv;
|
2012-05-17 14:10:14 +03:00
|
|
|
|
2012-05-17 23:39:02 +03:00
|
|
|
aresample->next_pts = AV_NOPTS_VALUE;
|
2012-05-17 14:10:14 +03:00
|
|
|
aresample->swr = swr_alloc();
|
2021-09-13 16:54:58 +02:00
|
|
|
if (!aresample->swr)
|
|
|
|
return AVERROR(ENOMEM);
|
2013-04-11 21:23:52 +03:00
|
|
|
|
2021-09-13 16:54:58 +02:00
|
|
|
return 0;
|
2011-08-17 14:00:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static av_cold void uninit(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
AResampleContext *aresample = ctx->priv;
|
2012-01-21 22:26:31 +03:00
|
|
|
swr_free(&aresample->swr);
|
2011-08-17 14:00:20 +03:00
|
|
|
}
|
|
|
|
|
2024-08-31 09:45:07 +02:00
|
|
|
static int query_formats(const AVFilterContext *ctx,
|
|
|
|
AVFilterFormatsConfig **cfg_in,
|
|
|
|
AVFilterFormatsConfig **cfg_out)
|
2012-05-16 03:27:31 +03:00
|
|
|
{
|
2024-08-31 09:45:07 +02:00
|
|
|
const AResampleContext *aresample = ctx->priv;
|
2015-08-16 22:11:13 +02:00
|
|
|
enum AVSampleFormat out_format;
|
2021-08-31 16:03:14 +02:00
|
|
|
AVChannelLayout out_layout = { 0 };
|
|
|
|
int64_t out_rate;
|
2012-05-16 03:27:31 +03:00
|
|
|
|
2015-07-17 20:27:25 +02:00
|
|
|
AVFilterFormats *in_formats, *out_formats;
|
|
|
|
AVFilterFormats *in_samplerates, *out_samplerates;
|
|
|
|
AVFilterChannelLayouts *in_layouts, *out_layouts;
|
2015-10-05 05:39:25 +02:00
|
|
|
int ret;
|
2012-05-16 03:27:31 +03:00
|
|
|
|
2021-09-13 16:54:58 +02:00
|
|
|
if (aresample->sample_rate_arg > 0)
|
|
|
|
av_opt_set_int(aresample->swr, "osr", aresample->sample_rate_arg, 0);
|
2015-08-16 22:11:13 +02:00
|
|
|
av_opt_get_sample_fmt(aresample->swr, "osf", 0, &out_format);
|
|
|
|
av_opt_get_int(aresample->swr, "osr", 0, &out_rate);
|
2015-07-17 20:27:25 +02:00
|
|
|
|
|
|
|
in_formats = ff_all_formats(AVMEDIA_TYPE_AUDIO);
|
2024-08-31 09:45:07 +02:00
|
|
|
if ((ret = ff_formats_ref(in_formats, &cfg_in[0]->formats)) < 0)
|
2015-10-05 05:39:25 +02:00
|
|
|
return ret;
|
2015-07-17 20:27:25 +02:00
|
|
|
|
|
|
|
in_samplerates = ff_all_samplerates();
|
2024-08-31 09:45:07 +02:00
|
|
|
if ((ret = ff_formats_ref(in_samplerates, &cfg_in[0]->samplerates)) < 0)
|
2015-10-05 05:39:25 +02:00
|
|
|
return ret;
|
2015-07-17 20:27:25 +02:00
|
|
|
|
|
|
|
in_layouts = ff_all_channel_counts();
|
2024-08-31 09:45:07 +02:00
|
|
|
if ((ret = ff_channel_layouts_ref(in_layouts, &cfg_in[0]->channel_layouts)) < 0)
|
2015-10-05 05:39:25 +02:00
|
|
|
return ret;
|
2012-05-16 03:27:31 +03:00
|
|
|
|
2012-05-17 17:12:54 +03:00
|
|
|
if(out_rate > 0) {
|
2013-12-30 02:52:48 +03:00
|
|
|
int ratelist[] = { out_rate, -1 };
|
|
|
|
out_samplerates = ff_make_format_list(ratelist);
|
2012-05-16 03:27:31 +03:00
|
|
|
} else {
|
|
|
|
out_samplerates = ff_all_samplerates();
|
|
|
|
}
|
2014-10-02 13:55:51 +03:00
|
|
|
|
2024-08-31 09:45:07 +02:00
|
|
|
if ((ret = ff_formats_ref(out_samplerates, &cfg_out[0]->samplerates)) < 0)
|
2015-10-05 05:39:25 +02:00
|
|
|
return ret;
|
2012-05-17 17:12:54 +03:00
|
|
|
|
|
|
|
if(out_format != AV_SAMPLE_FMT_NONE) {
|
2013-12-30 02:52:48 +03:00
|
|
|
int formatlist[] = { out_format, -1 };
|
|
|
|
out_formats = ff_make_format_list(formatlist);
|
2012-05-17 17:12:54 +03:00
|
|
|
} else
|
2012-06-24 03:09:53 +03:00
|
|
|
out_formats = ff_all_formats(AVMEDIA_TYPE_AUDIO);
|
2024-08-31 09:45:07 +02:00
|
|
|
if ((ret = ff_formats_ref(out_formats, &cfg_out[0]->formats)) < 0)
|
2015-10-05 05:39:25 +02:00
|
|
|
return ret;
|
2012-05-17 17:12:54 +03:00
|
|
|
|
2021-08-31 16:03:14 +02:00
|
|
|
av_opt_get_chlayout(aresample->swr, "ochl", 0, &out_layout);
|
|
|
|
if (av_channel_layout_check(&out_layout)) {
|
|
|
|
const AVChannelLayout layout_list[] = { out_layout, { 0 } };
|
|
|
|
out_layouts = ff_make_channel_layout_list(layout_list);
|
2012-05-17 17:12:54 +03:00
|
|
|
} else
|
2012-12-26 18:51:50 +03:00
|
|
|
out_layouts = ff_all_channel_counts();
|
2021-08-31 16:03:14 +02:00
|
|
|
av_channel_layout_uninit(&out_layout);
|
2012-05-16 03:27:31 +03:00
|
|
|
|
2024-08-31 09:45:07 +02:00
|
|
|
return ff_channel_layouts_ref(out_layouts, &cfg_out[0]->channel_layouts);
|
2012-05-16 03:27:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-17 14:00:20 +03:00
|
|
|
static int config_output(AVFilterLink *outlink)
|
|
|
|
{
|
2012-01-21 22:26:31 +03:00
|
|
|
int ret;
|
2011-08-17 14:00:20 +03:00
|
|
|
AVFilterContext *ctx = outlink->src;
|
|
|
|
AVFilterLink *inlink = ctx->inputs[0];
|
|
|
|
AResampleContext *aresample = ctx->priv;
|
2021-08-31 16:03:14 +02:00
|
|
|
AVChannelLayout out_layout = { 0 };
|
|
|
|
int64_t out_rate;
|
2012-05-17 17:12:54 +03:00
|
|
|
enum AVSampleFormat out_format;
|
2012-05-25 01:07:40 +03:00
|
|
|
char inchl_buf[128], outchl_buf[128];
|
2011-08-17 14:00:20 +03:00
|
|
|
|
2021-08-31 16:03:14 +02:00
|
|
|
ret = swr_alloc_set_opts2(&aresample->swr,
|
|
|
|
&outlink->ch_layout, outlink->format, outlink->sample_rate,
|
|
|
|
&inlink->ch_layout, inlink->format, inlink->sample_rate,
|
|
|
|
0, ctx);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2012-05-17 17:12:54 +03:00
|
|
|
|
2012-01-21 22:26:31 +03:00
|
|
|
ret = swr_init(aresample->swr);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2011-08-17 14:00:20 +03:00
|
|
|
|
2015-08-16 22:11:13 +02:00
|
|
|
av_opt_get_int(aresample->swr, "osr", 0, &out_rate);
|
2021-08-31 16:03:14 +02:00
|
|
|
av_opt_get_chlayout(aresample->swr, "ochl", 0, &out_layout);
|
2015-08-16 22:11:13 +02:00
|
|
|
av_opt_get_sample_fmt(aresample->swr, "osf", 0, &out_format);
|
2012-05-17 17:12:54 +03:00
|
|
|
outlink->time_base = (AVRational) {1, out_rate};
|
|
|
|
|
|
|
|
av_assert0(outlink->sample_rate == out_rate);
|
2021-08-31 16:03:14 +02:00
|
|
|
av_assert0(!av_channel_layout_compare(&outlink->ch_layout, &out_layout));
|
2012-05-17 17:12:54 +03:00
|
|
|
av_assert0(outlink->format == out_format);
|
|
|
|
|
2021-08-31 16:03:14 +02:00
|
|
|
av_channel_layout_uninit(&out_layout);
|
|
|
|
|
2011-08-17 14:00:20 +03:00
|
|
|
aresample->ratio = (double)outlink->sample_rate / inlink->sample_rate;
|
|
|
|
|
2021-08-31 16:03:14 +02:00
|
|
|
av_channel_layout_describe(&inlink ->ch_layout, inchl_buf, sizeof(inchl_buf));
|
|
|
|
av_channel_layout_describe(&outlink->ch_layout, outchl_buf, sizeof(outchl_buf));
|
2012-06-24 16:13:39 +03:00
|
|
|
|
2012-12-26 18:51:50 +03:00
|
|
|
av_log(ctx, AV_LOG_VERBOSE, "ch:%d chl:%s fmt:%s r:%dHz -> ch:%d chl:%s fmt:%s r:%dHz\n",
|
2021-08-31 16:03:14 +02:00
|
|
|
inlink ->ch_layout.nb_channels, inchl_buf, av_get_sample_fmt_name(inlink->format), inlink->sample_rate,
|
|
|
|
outlink->ch_layout.nb_channels, outchl_buf, av_get_sample_fmt_name(outlink->format), outlink->sample_rate);
|
2011-08-17 14:00:20 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-10 03:30:30 +03:00
|
|
|
static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref)
|
2011-08-17 14:00:20 +03:00
|
|
|
{
|
2023-05-17 09:15:51 +02:00
|
|
|
AVFilterContext *ctx = inlink->dst;
|
|
|
|
AResampleContext *aresample = ctx->priv;
|
2013-03-10 03:30:30 +03:00
|
|
|
const int n_in = insamplesref->nb_samples;
|
2013-11-07 00:59:16 +03:00
|
|
|
int64_t delay;
|
|
|
|
int n_out = n_in * aresample->ratio + 32;
|
2012-01-21 22:26:31 +03:00
|
|
|
AVFilterLink *const outlink = inlink->dst->outputs[0];
|
2013-11-07 00:59:16 +03:00
|
|
|
AVFrame *outsamplesref;
|
2012-07-09 23:10:38 +03:00
|
|
|
int ret;
|
2012-01-21 22:26:31 +03:00
|
|
|
|
2013-11-07 00:59:16 +03:00
|
|
|
delay = swr_get_delay(aresample->swr, outlink->sample_rate);
|
|
|
|
if (delay > 0)
|
2014-11-04 17:01:07 +02:00
|
|
|
n_out += FFMIN(delay, FFMAX(4096, n_out));
|
2013-11-07 00:59:16 +03:00
|
|
|
|
|
|
|
outsamplesref = ff_get_audio_buffer(outlink, n_out);
|
|
|
|
|
2017-06-24 18:36:46 +02:00
|
|
|
if(!outsamplesref) {
|
|
|
|
av_frame_free(&insamplesref);
|
2012-11-24 19:33:32 +03:00
|
|
|
return AVERROR(ENOMEM);
|
2017-06-24 18:36:46 +02:00
|
|
|
}
|
2012-11-24 19:33:32 +03:00
|
|
|
|
2013-03-10 03:30:30 +03:00
|
|
|
av_frame_copy_props(outsamplesref, insamplesref);
|
2012-09-12 20:34:21 +03:00
|
|
|
outsamplesref->format = outlink->format;
|
2021-08-31 16:03:14 +02:00
|
|
|
ret = av_channel_layout_copy(&outsamplesref->ch_layout, &outlink->ch_layout);
|
2024-06-10 21:24:47 +02:00
|
|
|
if (ret < 0) {
|
|
|
|
av_frame_free(&outsamplesref);
|
|
|
|
av_frame_free(&insamplesref);
|
2021-08-31 16:03:14 +02:00
|
|
|
return ret;
|
2024-06-10 21:24:47 +02:00
|
|
|
}
|
2013-03-10 03:30:30 +03:00
|
|
|
outsamplesref->sample_rate = outlink->sample_rate;
|
2012-05-17 23:39:02 +03:00
|
|
|
|
2012-05-19 19:48:53 +03:00
|
|
|
if(insamplesref->pts != AV_NOPTS_VALUE) {
|
|
|
|
int64_t inpts = av_rescale(insamplesref->pts, inlink->time_base.num * (int64_t)outlink->sample_rate * inlink->sample_rate, inlink->time_base.den);
|
|
|
|
int64_t outpts= swr_next_pts(aresample->swr, inpts);
|
|
|
|
aresample->next_pts =
|
2012-11-26 18:25:47 +03:00
|
|
|
outsamplesref->pts = ROUNDED_DIV(outpts, inlink->sample_rate);
|
2012-05-19 19:48:53 +03:00
|
|
|
} else {
|
|
|
|
outsamplesref->pts = AV_NOPTS_VALUE;
|
|
|
|
}
|
2012-05-26 17:17:47 +03:00
|
|
|
n_out = swr_convert(aresample->swr, outsamplesref->extended_data, n_out,
|
|
|
|
(void *)insamplesref->extended_data, n_in);
|
|
|
|
if (n_out <= 0) {
|
2013-03-10 03:30:30 +03:00
|
|
|
av_frame_free(&outsamplesref);
|
|
|
|
av_frame_free(&insamplesref);
|
2023-05-17 09:15:51 +02:00
|
|
|
ff_inlink_request_frame(inlink);
|
2012-07-09 23:10:38 +03:00
|
|
|
return 0;
|
2012-05-26 17:17:47 +03:00
|
|
|
}
|
|
|
|
|
2014-11-04 17:01:07 +02:00
|
|
|
aresample->more_data = outsamplesref->nb_samples == n_out; // Indicate that there is probably more data in our buffers
|
|
|
|
|
2013-03-10 03:30:30 +03:00
|
|
|
outsamplesref->nb_samples = n_out;
|
2012-05-26 17:17:47 +03:00
|
|
|
|
2012-11-28 15:53:48 +03:00
|
|
|
ret = ff_filter_frame(outlink, outsamplesref);
|
2013-03-10 03:30:30 +03:00
|
|
|
av_frame_free(&insamplesref);
|
2012-07-09 23:10:38 +03:00
|
|
|
return ret;
|
2011-08-17 14:00:20 +03:00
|
|
|
}
|
|
|
|
|
2014-11-04 17:00:07 +02:00
|
|
|
static int flush_frame(AVFilterLink *outlink, int final, AVFrame **outsamplesref_ret)
|
|
|
|
{
|
|
|
|
AVFilterContext *ctx = outlink->src;
|
|
|
|
AResampleContext *aresample = ctx->priv;
|
|
|
|
AVFilterLink *const inlink = outlink->src->inputs[0];
|
|
|
|
AVFrame *outsamplesref;
|
|
|
|
int n_out = 4096;
|
|
|
|
int64_t pts;
|
|
|
|
|
|
|
|
outsamplesref = ff_get_audio_buffer(outlink, n_out);
|
|
|
|
*outsamplesref_ret = outsamplesref;
|
|
|
|
if (!outsamplesref)
|
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
|
|
|
|
pts = swr_next_pts(aresample->swr, INT64_MIN);
|
|
|
|
pts = ROUNDED_DIV(pts, inlink->sample_rate);
|
|
|
|
|
|
|
|
n_out = swr_convert(aresample->swr, outsamplesref->extended_data, n_out, final ? NULL : (void*)outsamplesref->extended_data, 0);
|
|
|
|
if (n_out <= 0) {
|
|
|
|
av_frame_free(&outsamplesref);
|
|
|
|
return (n_out == 0) ? AVERROR_EOF : n_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
outsamplesref->sample_rate = outlink->sample_rate;
|
|
|
|
outsamplesref->nb_samples = n_out;
|
|
|
|
|
|
|
|
outsamplesref->pts = pts;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-17 23:39:02 +03:00
|
|
|
static int request_frame(AVFilterLink *outlink)
|
|
|
|
{
|
|
|
|
AVFilterContext *ctx = outlink->src;
|
2023-05-17 09:15:51 +02:00
|
|
|
AVFilterLink *inlink = ctx->inputs[0];
|
2012-05-17 23:39:02 +03:00
|
|
|
AResampleContext *aresample = ctx->priv;
|
2023-05-17 09:15:51 +02:00
|
|
|
int ret = 0, status;
|
|
|
|
int64_t pts;
|
2012-05-26 03:28:40 +03:00
|
|
|
|
2014-11-04 17:01:07 +02:00
|
|
|
// First try to get data from the internal buffers
|
|
|
|
if (aresample->more_data) {
|
|
|
|
AVFrame *outsamplesref;
|
|
|
|
|
|
|
|
if (flush_frame(outlink, 0, &outsamplesref) >= 0) {
|
|
|
|
return ff_filter_frame(outlink, outsamplesref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aresample->more_data = 0;
|
|
|
|
|
2023-05-17 09:15:51 +02:00
|
|
|
if (!aresample->eof && ff_inlink_acknowledge_status(inlink, &status, &pts))
|
|
|
|
aresample->eof = 1;
|
|
|
|
|
2014-11-04 17:01:07 +02:00
|
|
|
// Second request more data from the input
|
2023-05-17 09:15:51 +02:00
|
|
|
if (!aresample->eof)
|
|
|
|
FF_FILTER_FORWARD_WANTED(outlink, inlink);
|
2012-05-17 23:39:02 +03:00
|
|
|
|
2014-11-04 17:01:07 +02:00
|
|
|
// Third if we hit the end flush
|
2023-05-17 09:15:51 +02:00
|
|
|
if (aresample->eof) {
|
2013-03-10 03:30:30 +03:00
|
|
|
AVFrame *outsamplesref;
|
2013-11-15 04:56:36 +03:00
|
|
|
|
2023-05-17 09:15:51 +02:00
|
|
|
if ((ret = flush_frame(outlink, 1, &outsamplesref)) < 0) {
|
|
|
|
if (ret == AVERROR_EOF) {
|
|
|
|
ff_outlink_set_status(outlink, AVERROR_EOF, aresample->next_pts);
|
|
|
|
return 0;
|
|
|
|
}
|
2014-11-04 17:00:07 +02:00
|
|
|
return ret;
|
2023-05-17 09:15:51 +02:00
|
|
|
}
|
2012-05-17 23:39:02 +03:00
|
|
|
|
2013-03-13 11:55:18 +03:00
|
|
|
return ff_filter_frame(outlink, outsamplesref);
|
2012-05-17 23:39:02 +03:00
|
|
|
}
|
2023-05-17 09:15:51 +02:00
|
|
|
|
|
|
|
ff_filter_set_ready(ctx, 100);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int activate(AVFilterContext *ctx)
|
|
|
|
{
|
|
|
|
AResampleContext *aresample = ctx->priv;
|
|
|
|
AVFilterLink *inlink = ctx->inputs[0];
|
|
|
|
AVFilterLink *outlink = ctx->outputs[0];
|
|
|
|
|
|
|
|
FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
|
|
|
|
|
|
|
|
if (!aresample->eof && ff_inlink_queued_frames(inlink)) {
|
|
|
|
AVFrame *frame = NULL;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = ff_inlink_consume_frame(inlink, &frame);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
if (ret > 0)
|
|
|
|
return filter_frame(inlink, frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
return request_frame(outlink);
|
2012-05-17 23:39:02 +03:00
|
|
|
}
|
|
|
|
|
2020-05-27 15:34:07 +02:00
|
|
|
static const AVClass *resample_child_class_iterate(void **iter)
|
|
|
|
{
|
|
|
|
const AVClass *c = *iter ? NULL : swr_get_class();
|
|
|
|
*iter = (void*)(uintptr_t)c;
|
|
|
|
return c;
|
|
|
|
}
|
2013-04-11 21:23:52 +03:00
|
|
|
|
|
|
|
static void *resample_child_next(void *obj, void *prev)
|
|
|
|
{
|
|
|
|
AResampleContext *s = obj;
|
|
|
|
return prev ? NULL : s->swr;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define OFFSET(x) offsetof(AResampleContext, x)
|
|
|
|
#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
|
|
|
|
|
|
|
|
static const AVOption options[] = {
|
|
|
|
{"sample_rate", NULL, OFFSET(sample_rate_arg), AV_OPT_TYPE_INT, {.i64=0}, 0, INT_MAX, FLAGS },
|
|
|
|
{NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVClass aresample_class = {
|
|
|
|
.class_name = "aresample",
|
2024-01-19 14:33:28 +02:00
|
|
|
.item_name = av_default_item_name,
|
2013-04-11 21:23:52 +03:00
|
|
|
.option = options,
|
|
|
|
.version = LIBAVUTIL_VERSION_INT,
|
2020-05-27 15:34:07 +02:00
|
|
|
.child_class_iterate = resample_child_class_iterate,
|
2013-04-11 21:23:52 +03:00
|
|
|
.child_next = resample_child_next,
|
|
|
|
};
|
|
|
|
|
2012-11-28 22:01:59 +03:00
|
|
|
static const AVFilterPad aresample_outputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.config_props = config_output,
|
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-04-19 18:33:56 +02:00
|
|
|
const AVFilter ff_af_aresample = {
|
2011-08-17 14:00:20 +03:00
|
|
|
.name = "aresample",
|
|
|
|
.description = NULL_IF_CONFIG_SMALL("Resample audio data."),
|
2021-09-13 16:54:58 +02:00
|
|
|
.preinit = preinit,
|
2023-05-17 09:15:51 +02:00
|
|
|
.activate = activate,
|
2011-08-17 14:00:20 +03:00
|
|
|
.uninit = uninit,
|
|
|
|
.priv_size = sizeof(AResampleContext),
|
2013-04-11 21:23:52 +03:00
|
|
|
.priv_class = &aresample_class,
|
2023-08-03 00:59:02 +02:00
|
|
|
FILTER_INPUTS(ff_audio_default_filterpad),
|
2021-08-12 13:05:31 +02:00
|
|
|
FILTER_OUTPUTS(aresample_outputs),
|
2024-08-31 09:45:07 +02:00
|
|
|
FILTER_QUERY_FUNC2(query_formats),
|
2011-08-17 14:00:20 +03:00
|
|
|
};
|