That is a more appropriate place for those functions.
Showing the changes to libavfilter (5 of 5 files). Show all
Unified · Split
| @@ -23,6 +23,7 @@ · 22 unmodified lines | |||
| 23 | #include "libavutil/channel_layout.h" | 23 | #include "libavutil/channel_layout.h" |
| 24 | #include "libavutil/common.h" | 24 | #include "libavutil/common.h" |
| 25 | #include "libavutil/cpu.h" | 25 | #include "libavutil/cpu.h" |
| 26 | #include "libavutil/eval.h" | ||
| 26 | 27 | ||
| 27 | #include "audio.h" | 28 | #include "audio.h" |
| 28 | #include "avfilter.h" | 29 | #include "avfilter.h" |
| @@ -107,3 +108,38 @@ AVFrame *ff_get_audio_buffer(AVFilterLink *link, int nb_samples) · 78 unmodified lines | |||
| 107 | 108 | ||
| 108 | return ret; | 109 | return ret; |
| 109 | } | 110 | } |
| 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 | } | ||
| @@ -47,4 +47,29 @@ AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples); · 46 unmodified lines | |||
| 47 | */ | 47 | */ |
| 48 | AVFrame *ff_get_audio_buffer(AVFilterLink *link, int nb_samples); | 48 | AVFrame *ff_get_audio_buffer(AVFilterLink *link, int nb_samples); |
| 49 | 49 | ||
| 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 | |||
| 50 | #endif /* AVFILTER_AUDIO_H */ | 75 | #endif /* AVFILTER_AUDIO_H */ |
| @@ -22,7 +22,6 @@ · 21 unmodified lines | |||
| 22 | #include "libavutil/avassert.h" | 22 | #include "libavutil/avassert.h" |
| 23 | #include "libavutil/channel_layout.h" | 23 | #include "libavutil/channel_layout.h" |
| 24 | #include "libavutil/common.h" | 24 | #include "libavutil/common.h" |
| 25 | #include "libavutil/eval.h" | ||
| 26 | #include "libavutil/mem.h" | 25 | #include "libavutil/mem.h" |
| 27 | #include "libavutil/pixdesc.h" | 26 | #include "libavutil/pixdesc.h" |
| 28 | #include "avfilter.h" | 27 | #include "avfilter.h" |
| @@ -937,43 +936,6 @@ int ff_default_query_formats(AVFilterContext *ctx) · 908 unmodified lines | |||
| 937 | return 0; | 936 | return 0; |
| 938 | } | 937 | } |
| 939 | 938 | ||
| 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 | |||
| 977 | static int check_list(void *log, const char *name, const AVFilterFormats *fmts) | 939 | static int check_list(void *log, const char *name, const AVFilterFormats *fmts) |
| 978 | { | 940 | { |
| 979 | unsigned i, j; | 941 | unsigned i, j; |
| @@ -33,33 +33,6 @@ · 32 unmodified lines | |||
| 33 | */ | 33 | */ |
| 34 | int ff_fmt_is_regular_yuv(enum AVPixelFormat fmt); | 34 | int ff_fmt_is_regular_yuv(enum AVPixelFormat fmt); |
| 35 | 35 | ||
| 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 | |||
| 63 | /** | 36 | /** |
| 64 | * Negotiate the media format, dimensions, etc of all inputs to a filter. | 37 | * Negotiate the media format, dimensions, etc of all inputs to a filter. |
| 65 | * | 38 | * |
| @@ -19,6 +19,7 @@ · 18 unmodified lines | |||
| 19 | */ | 19 | */ |
| 20 | 20 | ||
| 21 | #include "libavutil/channel_layout.h" | 21 | #include "libavutil/channel_layout.h" |
| 22 | #include "libavfilter/audio.h" | ||
| 22 | #include "libavfilter/formats.c" | 23 | #include "libavfilter/formats.c" |
| 23 | 24 | ||
| 24 | #undef printf | 25 | #undef printf |