yading@11: /* yading@11: * This file is part of FFmpeg. yading@11: * yading@11: * FFmpeg is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * FFmpeg is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with FFmpeg; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: #ifndef AVUTIL_PARSEUTILS_H yading@11: #define AVUTIL_PARSEUTILS_H yading@11: yading@11: #include yading@11: yading@11: #include "rational.h" yading@11: yading@11: /** yading@11: * @file yading@11: * misc parsing utilities yading@11: */ yading@11: yading@11: /** yading@11: * Parse str and store the parsed ratio in q. yading@11: * yading@11: * Note that a ratio with infinite (1/0) or negative value is yading@11: * considered valid, so you should check on the returned value if you yading@11: * want to exclude those values. yading@11: * yading@11: * The undefined value can be expressed using the "0:0" string. yading@11: * yading@11: * @param[in,out] q pointer to the AVRational which will contain the ratio yading@11: * @param[in] str the string to parse: it has to be a string in the format yading@11: * num:den, a float number or an expression yading@11: * @param[in] max the maximum allowed numerator and denominator yading@11: * @param[in] log_offset log level offset which is applied to the log yading@11: * level of log_ctx yading@11: * @param[in] log_ctx parent logging context yading@11: * @return >= 0 on success, a negative error code otherwise yading@11: */ yading@11: int av_parse_ratio(AVRational *q, const char *str, int max, yading@11: int log_offset, void *log_ctx); yading@11: yading@11: #define av_parse_ratio_quiet(rate, str, max) \ yading@11: av_parse_ratio(rate, str, max, AV_LOG_MAX_OFFSET, NULL) yading@11: yading@11: /** yading@11: * Parse str and put in width_ptr and height_ptr the detected values. yading@11: * yading@11: * @param[in,out] width_ptr pointer to the variable which will contain the detected yading@11: * width value yading@11: * @param[in,out] height_ptr pointer to the variable which will contain the detected yading@11: * height value yading@11: * @param[in] str the string to parse: it has to be a string in the format yading@11: * width x height or a valid video size abbreviation. yading@11: * @return >= 0 on success, a negative error code otherwise yading@11: */ yading@11: int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str); yading@11: yading@11: /** yading@11: * Parse str and store the detected values in *rate. yading@11: * yading@11: * @param[in,out] rate pointer to the AVRational which will contain the detected yading@11: * frame rate yading@11: * @param[in] str the string to parse: it has to be a string in the format yading@11: * rate_num / rate_den, a float number or a valid video rate abbreviation yading@11: * @return >= 0 on success, a negative error code otherwise yading@11: */ yading@11: int av_parse_video_rate(AVRational *rate, const char *str); yading@11: yading@11: /** yading@11: * Put the RGBA values that correspond to color_string in rgba_color. yading@11: * yading@11: * @param color_string a string specifying a color. It can be the name of yading@11: * a color (case insensitive match) or a [0x|#]RRGGBB[AA] sequence, yading@11: * possibly followed by "@" and a string representing the alpha yading@11: * component. yading@11: * The alpha component may be a string composed by "0x" followed by an yading@11: * hexadecimal number or a decimal number between 0.0 and 1.0, which yading@11: * represents the opacity value (0x00/0.0 means completely transparent, yading@11: * 0xff/1.0 completely opaque). yading@11: * If the alpha component is not specified then 0xff is assumed. yading@11: * The string "random" will result in a random color. yading@11: * @param slen length of the initial part of color_string containing the yading@11: * color. It can be set to -1 if color_string is a null terminated string yading@11: * containing nothing else than the color. yading@11: * @return >= 0 in case of success, a negative value in case of yading@11: * failure (for example if color_string cannot be parsed). yading@11: */ yading@11: int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, yading@11: void *log_ctx); yading@11: yading@11: /** yading@11: * Parse timestr and return in *time a corresponding number of yading@11: * microseconds. yading@11: * yading@11: * @param timeval puts here the number of microseconds corresponding yading@11: * to the string in timestr. If the string represents a duration, it yading@11: * is the number of microseconds contained in the time interval. If yading@11: * the string is a date, is the number of microseconds since 1st of yading@11: * January, 1970 up to the time of the parsed date. If timestr cannot yading@11: * be successfully parsed, set *time to INT64_MIN. yading@11: yading@11: * @param timestr a string representing a date or a duration. yading@11: * - If a date the syntax is: yading@11: * @code yading@11: * [{YYYY-MM-DD|YYYYMMDD}[T|t| ]]{{HH:MM:SS[.m...]]]}|{HHMMSS[.m...]]]}}[Z] yading@11: * now yading@11: * @endcode yading@11: * If the value is "now" it takes the current time. yading@11: * Time is local time unless Z is appended, in which case it is yading@11: * interpreted as UTC. yading@11: * If the year-month-day part is not specified it takes the current yading@11: * year-month-day. yading@11: * - If a duration the syntax is: yading@11: * @code yading@11: * [-][HH:]MM:SS[.m...] yading@11: * [-]S+[.m...] yading@11: * @endcode yading@11: * @param duration flag which tells how to interpret timestr, if not yading@11: * zero timestr is interpreted as a duration, otherwise as a date yading@11: * @return 0 in case of success, a negative value corresponding to an yading@11: * AVERROR code otherwise yading@11: */ yading@11: int av_parse_time(int64_t *timeval, const char *timestr, int duration); yading@11: yading@11: /** yading@11: * Parse the input string p according to the format string fmt and yading@11: * store its results in the structure dt. yading@11: * This implementation supports only a subset of the formats supported yading@11: * by the standard strptime(). yading@11: * yading@11: * In particular it actually supports the parameters: yading@11: * - %H: the hour as a decimal number, using a 24-hour clock, in the yading@11: * range '00' through '23' yading@11: * - %J: hours as a decimal number, in the range '0' through INT_MAX yading@11: * - %M: the minute as a decimal number, using a 24-hour clock, in the yading@11: * range '00' through '59' yading@11: * - %S: the second as a decimal number, using a 24-hour clock, in the yading@11: * range '00' through '59' yading@11: * - %Y: the year as a decimal number, using the Gregorian calendar yading@11: * - %m: the month as a decimal number, in the range '1' through '12' yading@11: * - %d: the day of the month as a decimal number, in the range '1' yading@11: * through '31' yading@11: * - %%: a literal '%' yading@11: * yading@11: * @return a pointer to the first character not processed in this yading@11: * function call, or NULL in case the function fails to match all of yading@11: * the fmt string and therefore an error occurred yading@11: */ yading@11: char *av_small_strptime(const char *p, const char *fmt, struct tm *dt); yading@11: yading@11: /** yading@11: * Attempt to find a specific tag in a URL. yading@11: * yading@11: * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done. yading@11: * Return 1 if found. yading@11: */ yading@11: int av_find_info_tag(char *arg, int arg_size, const char *tag1, const char *info); yading@11: yading@11: /** yading@11: * Convert the decomposed UTC time in tm to a time_t value. yading@11: */ yading@11: time_t av_timegm(struct tm *tm); yading@11: yading@11: #endif /* AVUTIL_PARSEUTILS_H */