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

That is a more appropriate place for those functions.
release/7.1
Anton Khirnov 4 months ago
parent f4bfdf7893
commit a83a30e899
  1. 36
      libavfilter/audio.c
  2. 25
      libavfilter/audio.h
  3. 38
      libavfilter/formats.c
  4. 27
      libavfilter/internal.h
  5. 1
      libavfilter/tests/formats.c

@ -23,6 +23,7 @@
#include "libavutil/channel_layout.h" #include "libavutil/channel_layout.h"
#include "libavutil/common.h" #include "libavutil/common.h"
#include "libavutil/cpu.h" #include "libavutil/cpu.h"
#include "libavutil/eval.h"
#include "audio.h" #include "audio.h"
#include "avfilter.h" #include "avfilter.h"
@ -107,3 +108,38 @@ AVFrame *ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
return ret; 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;
}

@ -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); 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 */ #endif /* AVFILTER_AUDIO_H */

@ -22,7 +22,6 @@
#include "libavutil/avassert.h" #include "libavutil/avassert.h"
#include "libavutil/channel_layout.h" #include "libavutil/channel_layout.h"
#include "libavutil/common.h" #include "libavutil/common.h"
#include "libavutil/eval.h"
#include "libavutil/mem.h" #include "libavutil/mem.h"
#include "libavutil/pixdesc.h" #include "libavutil/pixdesc.h"
#include "avfilter.h" #include "avfilter.h"
@ -937,43 +936,6 @@ int ff_default_query_formats(AVFilterContext *ctx)
return 0; 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) static int check_list(void *log, const char *name, const AVFilterFormats *fmts)
{ {
unsigned i, j; unsigned i, j;

@ -33,33 +33,6 @@
*/ */
int ff_fmt_is_regular_yuv(enum AVPixelFormat fmt); 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. * Negotiate the media format, dimensions, etc of all inputs to a filter.
* *

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

Loading…
Cancel
Save