lavfi: move ff_parse_{sample_rate,channel_layout}() to audio.[ch]

That is a more appropriate place for those functions.
This commit is contained in:
Anton Khirnov 2024-08-16 01:26:43 +02:00
parent f4bfdf7893
commit a83a30e899
5 changed files with 62 additions and 65 deletions

View File

@ -23,6 +23,7 @@
#include "libavutil/channel_layout.h"
#include "libavutil/common.h"
#include "libavutil/cpu.h"
#include "libavutil/eval.h"
#include "audio.h"
#include "avfilter.h"
@ -107,3 +108,38 @@ AVFrame *ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
return ret;
}
int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx)
{
char *tail;
double srate = av_strtod(arg, &tail);
if (*tail || srate < 1 || (int)srate != srate || srate > INT_MAX) {
av_log(log_ctx, AV_LOG_ERROR, "Invalid sample rate '%s'\n", arg);
return AVERROR(EINVAL);
}
*ret = srate;
return 0;
}
int ff_parse_channel_layout(AVChannelLayout *ret, int *nret, const char *arg,
void *log_ctx)
{
AVChannelLayout chlayout = { 0 };
int res;
res = av_channel_layout_from_string(&chlayout, arg);
if (res < 0) {
av_log(log_ctx, AV_LOG_ERROR, "Invalid channel layout '%s'\n", arg);
return AVERROR(EINVAL);
}
if (chlayout.order == AV_CHANNEL_ORDER_UNSPEC && !nret) {
av_log(log_ctx, AV_LOG_ERROR, "Unknown channel layout '%s' is not supported.\n", arg);
return AVERROR(EINVAL);
}
*ret = chlayout;
if (nret)
*nret = chlayout.nb_channels;
return 0;
}

View File

@ -47,4 +47,29 @@ AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples);
*/
AVFrame *ff_get_audio_buffer(AVFilterLink *link, int nb_samples);
/**
* Parse a sample rate.
*
* @param ret unsigned integer pointer to where the value should be written
* @param arg string to parse
* @param log_ctx log context
* @return >= 0 in case of success, a negative AVERROR code on error
*/
av_warn_unused_result
int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx);
/**
* Parse a channel layout or a corresponding integer representation.
*
* @param ret 64bit integer pointer to where the value should be written.
* @param nret integer pointer to the number of channels;
* if not NULL, then unknown channel layouts are accepted
* @param arg string to parse
* @param log_ctx log context
* @return >= 0 in case of success, a negative AVERROR code on error
*/
av_warn_unused_result
int ff_parse_channel_layout(AVChannelLayout *ret, int *nret, const char *arg,
void *log_ctx);
#endif /* AVFILTER_AUDIO_H */

View File

@ -22,7 +22,6 @@
#include "libavutil/avassert.h"
#include "libavutil/channel_layout.h"
#include "libavutil/common.h"
#include "libavutil/eval.h"
#include "libavutil/mem.h"
#include "libavutil/pixdesc.h"
#include "avfilter.h"
@ -937,43 +936,6 @@ int ff_default_query_formats(AVFilterContext *ctx)
return 0;
}
/* internal functions for parsing audio format arguments */
int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx)
{
char *tail;
double srate = av_strtod(arg, &tail);
if (*tail || srate < 1 || (int)srate != srate || srate > INT_MAX) {
av_log(log_ctx, AV_LOG_ERROR, "Invalid sample rate '%s'\n", arg);
return AVERROR(EINVAL);
}
*ret = srate;
return 0;
}
int ff_parse_channel_layout(AVChannelLayout *ret, int *nret, const char *arg,
void *log_ctx)
{
AVChannelLayout chlayout = { 0 };
int res;
res = av_channel_layout_from_string(&chlayout, arg);
if (res < 0) {
av_log(log_ctx, AV_LOG_ERROR, "Invalid channel layout '%s'\n", arg);
return AVERROR(EINVAL);
}
if (chlayout.order == AV_CHANNEL_ORDER_UNSPEC && !nret) {
av_log(log_ctx, AV_LOG_ERROR, "Unknown channel layout '%s' is not supported.\n", arg);
return AVERROR(EINVAL);
}
*ret = chlayout;
if (nret)
*nret = chlayout.nb_channels;
return 0;
}
static int check_list(void *log, const char *name, const AVFilterFormats *fmts)
{
unsigned i, j;

View File

@ -33,33 +33,6 @@
*/
int ff_fmt_is_regular_yuv(enum AVPixelFormat fmt);
/* Functions to parse audio format arguments */
/**
* Parse a sample rate.
*
* @param ret unsigned integer pointer to where the value should be written
* @param arg string to parse
* @param log_ctx log context
* @return >= 0 in case of success, a negative AVERROR code on error
*/
av_warn_unused_result
int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx);
/**
* Parse a channel layout or a corresponding integer representation.
*
* @param ret 64bit integer pointer to where the value should be written.
* @param nret integer pointer to the number of channels;
* if not NULL, then unknown channel layouts are accepted
* @param arg string to parse
* @param log_ctx log context
* @return >= 0 in case of success, a negative AVERROR code on error
*/
av_warn_unused_result
int ff_parse_channel_layout(AVChannelLayout *ret, int *nret, const char *arg,
void *log_ctx);
/**
* Negotiate the media format, dimensions, etc of all inputs to a filter.
*

View File

@ -19,6 +19,7 @@
*/
#include "libavutil/channel_layout.h"
#include "libavfilter/audio.h"
#include "libavfilter/formats.c"
#undef printf