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