Factorize code and provide ratio parsing consistency.
Showing the changes to libavutil/parseutils.h (1 of 7 files). Show all
Unified · Split
| @@ -28,6 +28,30 @@ · 27 unmodified lines | ||
| 28 | 28 | * misc parsing utilities |
| 29 | 29 | */ |
| 30 | 30 | |
| 31 | +/** | |
| 32 | + * Parse str and store the parsed ratio in q. | |
| 33 | + * | |
| 34 | + * Note that a ratio with infinite (1/0) or negative value is | |
| 35 | + * considered valid, so you should check on the returned value if you | |
| 36 | + * want to exclude those values. | |
| 37 | + * | |
| 38 | + * The undefined value can be expressed using the "0:0" string. | |
| 39 | + * | |
| 40 | + * @param[in,out] q pointer to the AVRational which will contain the ratio | |
| 41 | + * @param[in] str the string to parse: it has to be a string in the format | |
| 42 | + * num:den, a float number or an expression | |
| 43 | + * @param[in] max the maximum allowed numerator and denominator | |
| 44 | + * @param[in] log_offset log level offset which is applied to the log | |
| 45 | + * level of log_ctx | |
| 46 | + * @param[in] log_ctx parent logging context | |
| 47 | + * @return >= 0 on success, a negative error code otherwise | |
| 48 | + */ | |
| 49 | +int av_parse_ratio(AVRational *q, const char *str, int max, | |
| 50 | + int log_offset, void *log_ctx); | |
| 51 | + | |
| 52 | +#define av_parse_ratio_quiet(rate, str, max) \ | |
| 53 | + av_parse_ratio(rate, str, max, AV_LOG_MAX_OFFSET, NULL) | |
| 54 | + | |
| 31 | 55 | /** |
| 32 | 56 | * Parse str and put in width_ptr and height_ptr the detected values. |
| 33 | 57 | * |