Signed-off-by: Stefano Sabatini <stefano.sabatini-lala@poste.it>
Mina Nagy Zaki authored on 2011/08/04 18:28:14... | ... |
@@ -19,6 +19,7 @@ |
19 | 19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | 20 |
*/ |
21 | 21 |
|
22 |
+#include "libavutil/eval.h" |
|
22 | 23 |
#include "libavutil/pixdesc.h" |
23 | 24 |
#include "libavutil/audioconvert.h" |
24 | 25 |
#include "avfilter.h" |
... | ... |
@@ -233,3 +234,61 @@ void avfilter_formats_changeref(AVFilterFormats **oldref, |
233 | 233 |
} |
234 | 234 |
} |
235 | 235 |
|
236 |
+/* internal functions for parsing audio format arguments */ |
|
237 |
+ |
|
238 |
+int ff_parse_sample_format(int *ret, const char *arg, void *log_ctx) |
|
239 |
+{ |
|
240 |
+ char *tail; |
|
241 |
+ int sfmt = av_get_sample_fmt(arg); |
|
242 |
+ if (sfmt == AV_SAMPLE_FMT_NONE) { |
|
243 |
+ sfmt = strtol(arg, &tail, 0); |
|
244 |
+ if (*tail || (unsigned)sfmt >= AV_SAMPLE_FMT_NB) { |
|
245 |
+ av_log(log_ctx, AV_LOG_ERROR, "Invalid sample format '%s'\n", arg); |
|
246 |
+ return AVERROR(EINVAL); |
|
247 |
+ } |
|
248 |
+ } |
|
249 |
+ *ret = sfmt; |
|
250 |
+ return 0; |
|
251 |
+} |
|
252 |
+ |
|
253 |
+int ff_parse_sample_rate(unsigned *ret, const char *arg, void *log_ctx) |
|
254 |
+{ |
|
255 |
+ char *tail; |
|
256 |
+ double srate = av_strtod(arg, &tail); |
|
257 |
+ if (*tail || srate < 1 || (int)srate != srate) { |
|
258 |
+ av_log(log_ctx, AV_LOG_ERROR, "Invalid sample rate '%s'\n", arg); |
|
259 |
+ return AVERROR(EINVAL); |
|
260 |
+ } |
|
261 |
+ *ret = srate; |
|
262 |
+ return 0; |
|
263 |
+} |
|
264 |
+ |
|
265 |
+int ff_parse_channel_layout(int64_t *ret, const char *arg, void *log_ctx) |
|
266 |
+{ |
|
267 |
+ char *tail; |
|
268 |
+ int64_t chlayout = av_get_channel_layout(arg); |
|
269 |
+ if (chlayout == 0) { |
|
270 |
+ chlayout = strtol(arg, &tail, 10); |
|
271 |
+ if (*tail || chlayout == 0) { |
|
272 |
+ av_log(log_ctx, AV_LOG_ERROR, "Invalid channel layout '%s'\n", arg); |
|
273 |
+ return AVERROR(EINVAL); |
|
274 |
+ } |
|
275 |
+ } |
|
276 |
+ *ret = chlayout; |
|
277 |
+ return 0; |
|
278 |
+} |
|
279 |
+ |
|
280 |
+int ff_parse_packing_format(int *ret, const char *arg, void *log_ctx) |
|
281 |
+{ |
|
282 |
+ char *tail; |
|
283 |
+ int planar = strtol(arg, &tail, 10); |
|
284 |
+ if (*tail) { |
|
285 |
+ planar = (strcmp(arg, "packed") != 0); |
|
286 |
+ } else if (planar != 0 && planar != 1) { |
|
287 |
+ av_log(log_ctx, AV_LOG_ERROR, "Invalid packing format '%s'\n", arg); |
|
288 |
+ return AVERROR(EINVAL); |
|
289 |
+ } |
|
290 |
+ *ret = planar; |
|
291 |
+ return 0; |
|
292 |
+} |
|
293 |
+ |
... | ... |
@@ -61,4 +61,46 @@ void ff_avfilter_default_free_buffer(AVFilterBuffer *buf); |
61 | 61 |
/** Tell is a format is contained in the provided list terminated by -1. */ |
62 | 62 |
int ff_fmt_is_in(int fmt, const int *fmts); |
63 | 63 |
|
64 |
+/* Functions to parse audio format arguments */ |
|
65 |
+ |
|
66 |
+/** |
|
67 |
+ * Parse a sample rate. |
|
68 |
+ * |
|
69 |
+ * @param ret unsigned integer pointer to where the value should be written |
|
70 |
+ * @param arg string to parse |
|
71 |
+ * @param log_ctx log context |
|
72 |
+ * @return 0 in case of success, a negative AVERROR code on error |
|
73 |
+ */ |
|
74 |
+int ff_parse_sample_rate(unsigned *ret, const char *arg, void *log_ctx); |
|
75 |
+ |
|
76 |
+/** |
|
77 |
+ * Parse a sample format name or a corresponding integer representation. |
|
78 |
+ * |
|
79 |
+ * @param ret integer pointer to where the value should be written |
|
80 |
+ * @param arg string to parse |
|
81 |
+ * @param log_ctx log context |
|
82 |
+ * @return 0 in case of success, a negative AVERROR code on error |
|
83 |
+ */ |
|
84 |
+int ff_parse_sample_format(int *ret, const char *arg, void *log_ctx); |
|
85 |
+ |
|
86 |
+/** |
|
87 |
+ * Parse a channel layout or a corresponding integer representation. |
|
88 |
+ * |
|
89 |
+ * @param ret 64bit integer pointer to where the value should be written. |
|
90 |
+ * @param arg string to parse |
|
91 |
+ * @param log_ctx log context |
|
92 |
+ * @return 0 in case of success, a negative AVERROR code on error |
|
93 |
+ */ |
|
94 |
+int ff_parse_channel_layout(int64_t *ret, const char *arg, void *log_ctx); |
|
95 |
+ |
|
96 |
+/** |
|
97 |
+ * Parse a packing format or a corresponding integer representation. |
|
98 |
+ * |
|
99 |
+ * @param ret integer pointer to where the value should be written |
|
100 |
+ * @param arg string to parse |
|
101 |
+ * @param log_ctx log context |
|
102 |
+ * @return 0 in case of success, a negative AVERROR code on error |
|
103 |
+ */ |
|
104 |
+int ff_parse_packing_format(int *ret, const char *arg, void *log_ctx); |
|
105 |
+ |
|
64 | 106 |
#endif /* AVFILTER_INTERNAL_H */ |