aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2024-08-16 01:26:43 +0200
committerAnton Khirnov <anton@khirnov.net>2024-08-19 21:45:25 +0200
commita83a30e899099ec76a3570c07ee40b013dbfd409 (patch)
treef8f313513a62813ce79db386652bf96c0e1a3180
parentf4bfdf789335e690dd92c9ee85974c338429103a (diff)
downloadffmpeg-a83a30e899099ec76a3570c07ee40b013dbfd409.tar.gz
lavfi: move ff_parse_{sample_rate,channel_layout}() to audio.[ch]
That is a more appropriate place for those functions.
-rw-r--r--libavfilter/audio.c36
-rw-r--r--libavfilter/audio.h25
-rw-r--r--libavfilter/formats.c38
-rw-r--r--libavfilter/internal.h27
-rw-r--r--libavfilter/tests/formats.c1
5 files changed, 62 insertions, 65 deletions
diff --git a/libavfilter/audio.c b/libavfilter/audio.c
index 1768b31184..11b3d0c9c3 100644
--- a/libavfilter/audio.c
+++ b/libavfilter/audio.c
@@ -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;
+}
diff --git a/libavfilter/audio.h b/libavfilter/audio.h
index aab80baa50..881df0cf87 100644
--- a/libavfilter/audio.h
+++ b/libavfilter/audio.h
@@ -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 */
diff --git a/libavfilter/formats.c b/libavfilter/formats.c
index 18f7b89104..cd7c68f592 100644
--- a/libavfilter/formats.c
+++ b/libavfilter/formats.c
@@ -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;
diff --git a/libavfilter/internal.h b/libavfilter/internal.h
index 343bc0b330..eb312ab485 100644
--- a/libavfilter/internal.h
+++ b/libavfilter/internal.h
@@ -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.
*
diff --git a/libavfilter/tests/formats.c b/libavfilter/tests/formats.c
index ed1de24a4c..5cc3ca3371 100644
--- a/libavfilter/tests/formats.c
+++ b/libavfilter/tests/formats.c
@@ -19,6 +19,7 @@
*/
#include "libavutil/channel_layout.h"
+#include "libavfilter/audio.h"
#include "libavfilter/formats.c"
#undef printf