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