History

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

That is a more appropriate place for those functions.

Anton Khirnov committed 2 years ago

Commit a83a30e1 parent f4bfdf75 files · +62 −65Browse files

Unified · Split

5 files
  1. libavfilter/audio.c +36 −0
  2. libavfilter/audio.h +25 −0
  3. libavfilter/formats.c +0 −38
  4. libavfilter/internal.h +0 −27
  5. libavfilter/tests/formats.c +1 −0
libavfilter/audio.c+36−0
@@ -23,6 +23,7 @@ · 22 unmodified lines
2323 #include "libavutil/channel_layout.h"
2424 #include "libavutil/common.h"
2525 #include "libavutil/cpu.h"
26+#include "libavutil/eval.h"
2627
2728 #include "audio.h"
2829 #include "avfilter.h"
@@ -107,3 +108,38 @@ AVFrame *ff_get_audio_buffer(AVFilterLink *link, int nb_samples) · 78 unmodified lines
107108
108109 return ret;
109110 }
111+
112+int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx)
113+{
114+ char *tail;
115+ double srate = av_strtod(arg, &tail);
116+ if (*tail || srate < 1 || (int)srate != srate || srate > INT_MAX) {
117+ av_log(log_ctx, AV_LOG_ERROR, "Invalid sample rate '%s'\n", arg);
118+ return AVERROR(EINVAL);
119+ }
120+ *ret = srate;
121+ return 0;
122+}
123+
124+int ff_parse_channel_layout(AVChannelLayout *ret, int *nret, const char *arg,
125+ void *log_ctx)
126+{
127+ AVChannelLayout chlayout = { 0 };
128+ int res;
129+
130+ res = av_channel_layout_from_string(&chlayout, arg);
131+ if (res < 0) {
132+ av_log(log_ctx, AV_LOG_ERROR, "Invalid channel layout '%s'\n", arg);
133+ return AVERROR(EINVAL);
134+ }
135+
136+ if (chlayout.order == AV_CHANNEL_ORDER_UNSPEC && !nret) {
137+ av_log(log_ctx, AV_LOG_ERROR, "Unknown channel layout '%s' is not supported.\n", arg);
138+ return AVERROR(EINVAL);
139+ }
140+ *ret = chlayout;
141+ if (nret)
142+ *nret = chlayout.nb_channels;
143+
144+ return 0;
145+}
libavfilter/audio.h+25−0
@@ -47,4 +47,29 @@ AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples); · 46 unmodified lines
4747 */
4848 AVFrame *ff_get_audio_buffer(AVFilterLink *link, int nb_samples);
4949
50+/**
51+ * Parse a sample rate.
52+ *
53+ * @param ret unsigned integer pointer to where the value should be written
54+ * @param arg string to parse
55+ * @param log_ctx log context
56+ * @return >= 0 in case of success, a negative AVERROR code on error
57+ */
58+av_warn_unused_result
59+int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx);
60+
61+/**
62+ * Parse a channel layout or a corresponding integer representation.
63+ *
64+ * @param ret 64bit integer pointer to where the value should be written.
65+ * @param nret integer pointer to the number of channels;
66+ * if not NULL, then unknown channel layouts are accepted
67+ * @param arg string to parse
68+ * @param log_ctx log context
69+ * @return >= 0 in case of success, a negative AVERROR code on error
70+ */
71+av_warn_unused_result
72+int ff_parse_channel_layout(AVChannelLayout *ret, int *nret, const char *arg,
73+ void *log_ctx);
74+
5075 #endif /* AVFILTER_AUDIO_H */
libavfilter/formats.c+0−38
@@ -22,7 +22,6 @@ · 21 unmodified lines
2222 #include "libavutil/avassert.h"
2323 #include "libavutil/channel_layout.h"
2424 #include "libavutil/common.h"
25−#include "libavutil/eval.h"
2625 #include "libavutil/mem.h"
2726 #include "libavutil/pixdesc.h"
2827 #include "avfilter.h"
@@ -937,43 +936,6 @@ int ff_default_query_formats(AVFilterContext *ctx) · 908 unmodified lines
937936 return 0;
938937 }
939938
940−/* internal functions for parsing audio format arguments */
941−
942−int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx)
943−{
944− char *tail;
945− double srate = av_strtod(arg, &tail);
946− if (*tail || srate < 1 || (int)srate != srate || srate > INT_MAX) {
947− av_log(log_ctx, AV_LOG_ERROR, "Invalid sample rate '%s'\n", arg);
948− return AVERROR(EINVAL);
949− }
950− *ret = srate;
951− return 0;
952−}
953−
954−int ff_parse_channel_layout(AVChannelLayout *ret, int *nret, const char *arg,
955− void *log_ctx)
956−{
957− AVChannelLayout chlayout = { 0 };
958− int res;
959−
960− res = av_channel_layout_from_string(&chlayout, arg);
961− if (res < 0) {
962− av_log(log_ctx, AV_LOG_ERROR, "Invalid channel layout '%s'\n", arg);
963− return AVERROR(EINVAL);
964− }
965−
966− if (chlayout.order == AV_CHANNEL_ORDER_UNSPEC && !nret) {
967− av_log(log_ctx, AV_LOG_ERROR, "Unknown channel layout '%s' is not supported.\n", arg);
968− return AVERROR(EINVAL);
969− }
970− *ret = chlayout;
971− if (nret)
972− *nret = chlayout.nb_channels;
973−
974− return 0;
975−}
976−
977939 static int check_list(void *log, const char *name, const AVFilterFormats *fmts)
978940 {
979941 unsigned i, j;
libavfilter/internal.h+0−27
@@ -33,33 +33,6 @@ · 32 unmodified lines
3333 */
3434 int ff_fmt_is_regular_yuv(enum AVPixelFormat fmt);
3535
36−/* Functions to parse audio format arguments */
37−
38−/**
39− * Parse a sample rate.
40− *
41− * @param ret unsigned integer pointer to where the value should be written
42− * @param arg string to parse
43− * @param log_ctx log context
44− * @return >= 0 in case of success, a negative AVERROR code on error
45− */
46−av_warn_unused_result
47−int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx);
48−
49−/**
50− * Parse a channel layout or a corresponding integer representation.
51− *
52− * @param ret 64bit integer pointer to where the value should be written.
53− * @param nret integer pointer to the number of channels;
54− * if not NULL, then unknown channel layouts are accepted
55− * @param arg string to parse
56− * @param log_ctx log context
57− * @return >= 0 in case of success, a negative AVERROR code on error
58− */
59−av_warn_unused_result
60−int ff_parse_channel_layout(AVChannelLayout *ret, int *nret, const char *arg,
61− void *log_ctx);
62−
6336 /**
6437 * Negotiate the media format, dimensions, etc of all inputs to a filter.
6538 *
libavfilter/tests/formats.c+1−0
@@ -19,6 +19,7 @@ · 18 unmodified lines
1919 */
2020
2121 #include "libavutil/channel_layout.h"
22+#include "libavfilter/audio.h"
2223 #include "libavfilter/formats.c"
2324
2425 #undef printf

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t