1cabdff1aSopenharmony_ci/* 2cabdff1aSopenharmony_ci * This file is part of FFmpeg. 3cabdff1aSopenharmony_ci * 4cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or 5cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public 6cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either 7cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version. 8cabdff1aSopenharmony_ci * 9cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful, 10cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 11cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12cabdff1aSopenharmony_ci * Lesser General Public License for more details. 13cabdff1aSopenharmony_ci * 14cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public 15cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software 16cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17cabdff1aSopenharmony_ci */ 18cabdff1aSopenharmony_ci 19cabdff1aSopenharmony_ci#ifndef AVUTIL_PARSEUTILS_H 20cabdff1aSopenharmony_ci#define AVUTIL_PARSEUTILS_H 21cabdff1aSopenharmony_ci 22cabdff1aSopenharmony_ci#include <time.h> 23cabdff1aSopenharmony_ci 24cabdff1aSopenharmony_ci#include "rational.h" 25cabdff1aSopenharmony_ci 26cabdff1aSopenharmony_ci/** 27cabdff1aSopenharmony_ci * @file 28cabdff1aSopenharmony_ci * misc parsing utilities 29cabdff1aSopenharmony_ci */ 30cabdff1aSopenharmony_ci 31cabdff1aSopenharmony_ci/** 32cabdff1aSopenharmony_ci * Parse str and store the parsed ratio in q. 33cabdff1aSopenharmony_ci * 34cabdff1aSopenharmony_ci * Note that a ratio with infinite (1/0) or negative value is 35cabdff1aSopenharmony_ci * considered valid, so you should check on the returned value if you 36cabdff1aSopenharmony_ci * want to exclude those values. 37cabdff1aSopenharmony_ci * 38cabdff1aSopenharmony_ci * The undefined value can be expressed using the "0:0" string. 39cabdff1aSopenharmony_ci * 40cabdff1aSopenharmony_ci * @param[in,out] q pointer to the AVRational which will contain the ratio 41cabdff1aSopenharmony_ci * @param[in] str the string to parse: it has to be a string in the format 42cabdff1aSopenharmony_ci * num:den, a float number or an expression 43cabdff1aSopenharmony_ci * @param[in] max the maximum allowed numerator and denominator 44cabdff1aSopenharmony_ci * @param[in] log_offset log level offset which is applied to the log 45cabdff1aSopenharmony_ci * level of log_ctx 46cabdff1aSopenharmony_ci * @param[in] log_ctx parent logging context 47cabdff1aSopenharmony_ci * @return >= 0 on success, a negative error code otherwise 48cabdff1aSopenharmony_ci */ 49cabdff1aSopenharmony_ciint av_parse_ratio(AVRational *q, const char *str, int max, 50cabdff1aSopenharmony_ci int log_offset, void *log_ctx); 51cabdff1aSopenharmony_ci 52cabdff1aSopenharmony_ci#define av_parse_ratio_quiet(rate, str, max) \ 53cabdff1aSopenharmony_ci av_parse_ratio(rate, str, max, AV_LOG_MAX_OFFSET, NULL) 54cabdff1aSopenharmony_ci 55cabdff1aSopenharmony_ci/** 56cabdff1aSopenharmony_ci * Parse str and put in width_ptr and height_ptr the detected values. 57cabdff1aSopenharmony_ci * 58cabdff1aSopenharmony_ci * @param[in,out] width_ptr pointer to the variable which will contain the detected 59cabdff1aSopenharmony_ci * width value 60cabdff1aSopenharmony_ci * @param[in,out] height_ptr pointer to the variable which will contain the detected 61cabdff1aSopenharmony_ci * height value 62cabdff1aSopenharmony_ci * @param[in] str the string to parse: it has to be a string in the format 63cabdff1aSopenharmony_ci * width x height or a valid video size abbreviation. 64cabdff1aSopenharmony_ci * @return >= 0 on success, a negative error code otherwise 65cabdff1aSopenharmony_ci */ 66cabdff1aSopenharmony_ciint av_parse_video_size(int *width_ptr, int *height_ptr, const char *str); 67cabdff1aSopenharmony_ci 68cabdff1aSopenharmony_ci/** 69cabdff1aSopenharmony_ci * Parse str and store the detected values in *rate. 70cabdff1aSopenharmony_ci * 71cabdff1aSopenharmony_ci * @param[in,out] rate pointer to the AVRational which will contain the detected 72cabdff1aSopenharmony_ci * frame rate 73cabdff1aSopenharmony_ci * @param[in] str the string to parse: it has to be a string in the format 74cabdff1aSopenharmony_ci * rate_num / rate_den, a float number or a valid video rate abbreviation 75cabdff1aSopenharmony_ci * @return >= 0 on success, a negative error code otherwise 76cabdff1aSopenharmony_ci */ 77cabdff1aSopenharmony_ciint av_parse_video_rate(AVRational *rate, const char *str); 78cabdff1aSopenharmony_ci 79cabdff1aSopenharmony_ci/** 80cabdff1aSopenharmony_ci * Put the RGBA values that correspond to color_string in rgba_color. 81cabdff1aSopenharmony_ci * 82cabdff1aSopenharmony_ci * @param color_string a string specifying a color. It can be the name of 83cabdff1aSopenharmony_ci * a color (case insensitive match) or a [0x|#]RRGGBB[AA] sequence, 84cabdff1aSopenharmony_ci * possibly followed by "@" and a string representing the alpha 85cabdff1aSopenharmony_ci * component. 86cabdff1aSopenharmony_ci * The alpha component may be a string composed by "0x" followed by an 87cabdff1aSopenharmony_ci * hexadecimal number or a decimal number between 0.0 and 1.0, which 88cabdff1aSopenharmony_ci * represents the opacity value (0x00/0.0 means completely transparent, 89cabdff1aSopenharmony_ci * 0xff/1.0 completely opaque). 90cabdff1aSopenharmony_ci * If the alpha component is not specified then 0xff is assumed. 91cabdff1aSopenharmony_ci * The string "random" will result in a random color. 92cabdff1aSopenharmony_ci * @param slen length of the initial part of color_string containing the 93cabdff1aSopenharmony_ci * color. It can be set to -1 if color_string is a null terminated string 94cabdff1aSopenharmony_ci * containing nothing else than the color. 95cabdff1aSopenharmony_ci * @return >= 0 in case of success, a negative value in case of 96cabdff1aSopenharmony_ci * failure (for example if color_string cannot be parsed). 97cabdff1aSopenharmony_ci */ 98cabdff1aSopenharmony_ciint av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, 99cabdff1aSopenharmony_ci void *log_ctx); 100cabdff1aSopenharmony_ci 101cabdff1aSopenharmony_ci/** 102cabdff1aSopenharmony_ci * Get the name of a color from the internal table of hard-coded named 103cabdff1aSopenharmony_ci * colors. 104cabdff1aSopenharmony_ci * 105cabdff1aSopenharmony_ci * This function is meant to enumerate the color names recognized by 106cabdff1aSopenharmony_ci * av_parse_color(). 107cabdff1aSopenharmony_ci * 108cabdff1aSopenharmony_ci * @param color_idx index of the requested color, starting from 0 109cabdff1aSopenharmony_ci * @param rgbp if not NULL, will point to a 3-elements array with the color value in RGB 110cabdff1aSopenharmony_ci * @return the color name string or NULL if color_idx is not in the array 111cabdff1aSopenharmony_ci */ 112cabdff1aSopenharmony_ciconst char *av_get_known_color_name(int color_idx, const uint8_t **rgb); 113cabdff1aSopenharmony_ci 114cabdff1aSopenharmony_ci/** 115cabdff1aSopenharmony_ci * Parse timestr and return in *time a corresponding number of 116cabdff1aSopenharmony_ci * microseconds. 117cabdff1aSopenharmony_ci * 118cabdff1aSopenharmony_ci * @param timeval puts here the number of microseconds corresponding 119cabdff1aSopenharmony_ci * to the string in timestr. If the string represents a duration, it 120cabdff1aSopenharmony_ci * is the number of microseconds contained in the time interval. If 121cabdff1aSopenharmony_ci * the string is a date, is the number of microseconds since 1st of 122cabdff1aSopenharmony_ci * January, 1970 up to the time of the parsed date. If timestr cannot 123cabdff1aSopenharmony_ci * be successfully parsed, set *time to INT64_MIN. 124cabdff1aSopenharmony_ci 125cabdff1aSopenharmony_ci * @param timestr a string representing a date or a duration. 126cabdff1aSopenharmony_ci * - If a date the syntax is: 127cabdff1aSopenharmony_ci * @code 128cabdff1aSopenharmony_ci * [{YYYY-MM-DD|YYYYMMDD}[T|t| ]]{{HH:MM:SS[.m...]]]}|{HHMMSS[.m...]]]}}[Z] 129cabdff1aSopenharmony_ci * now 130cabdff1aSopenharmony_ci * @endcode 131cabdff1aSopenharmony_ci * If the value is "now" it takes the current time. 132cabdff1aSopenharmony_ci * Time is local time unless Z is appended, in which case it is 133cabdff1aSopenharmony_ci * interpreted as UTC. 134cabdff1aSopenharmony_ci * If the year-month-day part is not specified it takes the current 135cabdff1aSopenharmony_ci * year-month-day. 136cabdff1aSopenharmony_ci * - If a duration the syntax is: 137cabdff1aSopenharmony_ci * @code 138cabdff1aSopenharmony_ci * [-][HH:]MM:SS[.m...] 139cabdff1aSopenharmony_ci * [-]S+[.m...] 140cabdff1aSopenharmony_ci * @endcode 141cabdff1aSopenharmony_ci * @param duration flag which tells how to interpret timestr, if not 142cabdff1aSopenharmony_ci * zero timestr is interpreted as a duration, otherwise as a date 143cabdff1aSopenharmony_ci * @return >= 0 in case of success, a negative value corresponding to an 144cabdff1aSopenharmony_ci * AVERROR code otherwise 145cabdff1aSopenharmony_ci */ 146cabdff1aSopenharmony_ciint av_parse_time(int64_t *timeval, const char *timestr, int duration); 147cabdff1aSopenharmony_ci 148cabdff1aSopenharmony_ci/** 149cabdff1aSopenharmony_ci * Attempt to find a specific tag in a URL. 150cabdff1aSopenharmony_ci * 151cabdff1aSopenharmony_ci * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done. 152cabdff1aSopenharmony_ci * Return 1 if found. 153cabdff1aSopenharmony_ci */ 154cabdff1aSopenharmony_ciint av_find_info_tag(char *arg, int arg_size, const char *tag1, const char *info); 155cabdff1aSopenharmony_ci 156cabdff1aSopenharmony_ci/** 157cabdff1aSopenharmony_ci * Simplified version of strptime 158cabdff1aSopenharmony_ci * 159cabdff1aSopenharmony_ci * Parse the input string p according to the format string fmt and 160cabdff1aSopenharmony_ci * store its results in the structure dt. 161cabdff1aSopenharmony_ci * This implementation supports only a subset of the formats supported 162cabdff1aSopenharmony_ci * by the standard strptime(). 163cabdff1aSopenharmony_ci * 164cabdff1aSopenharmony_ci * The supported input field descriptors are listed below. 165cabdff1aSopenharmony_ci * - %H: the hour as a decimal number, using a 24-hour clock, in the 166cabdff1aSopenharmony_ci * range '00' through '23' 167cabdff1aSopenharmony_ci * - %J: hours as a decimal number, in the range '0' through INT_MAX 168cabdff1aSopenharmony_ci * - %M: the minute as a decimal number, using a 24-hour clock, in the 169cabdff1aSopenharmony_ci * range '00' through '59' 170cabdff1aSopenharmony_ci * - %S: the second as a decimal number, using a 24-hour clock, in the 171cabdff1aSopenharmony_ci * range '00' through '59' 172cabdff1aSopenharmony_ci * - %Y: the year as a decimal number, using the Gregorian calendar 173cabdff1aSopenharmony_ci * - %m: the month as a decimal number, in the range '1' through '12' 174cabdff1aSopenharmony_ci * - %d: the day of the month as a decimal number, in the range '1' 175cabdff1aSopenharmony_ci * through '31' 176cabdff1aSopenharmony_ci * - %T: alias for '%H:%M:%S' 177cabdff1aSopenharmony_ci * - %%: a literal '%' 178cabdff1aSopenharmony_ci * 179cabdff1aSopenharmony_ci * @return a pointer to the first character not processed in this function 180cabdff1aSopenharmony_ci * call. In case the input string contains more characters than 181cabdff1aSopenharmony_ci * required by the format string the return value points right after 182cabdff1aSopenharmony_ci * the last consumed input character. In case the whole input string 183cabdff1aSopenharmony_ci * is consumed the return value points to the null byte at the end of 184cabdff1aSopenharmony_ci * the string. On failure NULL is returned. 185cabdff1aSopenharmony_ci */ 186cabdff1aSopenharmony_cichar *av_small_strptime(const char *p, const char *fmt, struct tm *dt); 187cabdff1aSopenharmony_ci 188cabdff1aSopenharmony_ci/** 189cabdff1aSopenharmony_ci * Convert the decomposed UTC time in tm to a time_t value. 190cabdff1aSopenharmony_ci */ 191cabdff1aSopenharmony_citime_t av_timegm(struct tm *tm); 192cabdff1aSopenharmony_ci 193cabdff1aSopenharmony_ci#endif /* AVUTIL_PARSEUTILS_H */ 194