../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
305 / 329
92.7%
Branches:
265 / 345
76.8%
Functions:
12 / 12
100.0%

libavutil/parseutils.c
Line Branch Exec Source
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 /**
20 * @file
21 * misc parsing utilities
22 */
23
24 #include <time.h>
25
26 #include "avstring.h"
27 #include "avutil.h"
28 #include "common.h"
29 #include "eval.h"
30 #include "log.h"
31 #include "random_seed.h"
32 #include "time_internal.h"
33 #include "parseutils.h"
34 #include "time.h"
35
36 #ifdef TEST
37
38 #define av_get_random_seed av_get_random_seed_deterministic
39 static uint32_t av_get_random_seed_deterministic(void);
40
41 #define av_gettime() 1331972053200000
42
43 #endif
44
45 10702 int av_parse_ratio(AVRational *q, const char *str, int max,
46 int log_offset, void *log_ctx)
47 {
48 char c;
49 int ret;
50
51
2/2
✓ Branch 2 → 3 taken 10698 times.
✓ Branch 2 → 7 taken 4 times.
10702 if (sscanf(str, "%d:%d%c", &q->num, &q->den, &c) != 2) {
52 double d;
53 10698 ret = av_expr_parse_and_eval(&d, str, NULL, NULL,
54 NULL, NULL, NULL, NULL,
55 NULL, log_offset, log_ctx);
56
2/2
✓ Branch 4 → 5 taken 11 times.
✓ Branch 4 → 6 taken 10687 times.
10698 if (ret < 0)
57 11 return ret;
58 10687 *q = av_d2q(d, max);
59 } else {
60 4 av_reduce(&q->num, &q->den, q->num, q->den, max);
61 }
62
63 10691 return 0;
64 }
65
66 typedef struct VideoSizeAbbr {
67 const char *abbr;
68 int width, height;
69 } VideoSizeAbbr;
70
71 typedef struct VideoRateAbbr {
72 const char *abbr;
73 AVRational rate;
74 } VideoRateAbbr;
75
76 static const VideoSizeAbbr video_size_abbrs[] = {
77 { "ntsc", 720, 480 },
78 { "pal", 720, 576 },
79 { "qntsc", 352, 240 }, /* VCD compliant NTSC */
80 { "qpal", 352, 288 }, /* VCD compliant PAL */
81 { "sntsc", 640, 480 }, /* square pixel NTSC */
82 { "spal", 768, 576 }, /* square pixel PAL */
83 { "film", 352, 240 },
84 { "ntsc-film", 352, 240 },
85 { "sqcif", 128, 96 },
86 { "qcif", 176, 144 },
87 { "cif", 352, 288 },
88 { "4cif", 704, 576 },
89 { "16cif", 1408,1152 },
90 { "qqvga", 160, 120 },
91 { "qvga", 320, 240 },
92 { "vga", 640, 480 },
93 { "svga", 800, 600 },
94 { "xga", 1024, 768 },
95 { "uxga", 1600,1200 },
96 { "qxga", 2048,1536 },
97 { "sxga", 1280,1024 },
98 { "qsxga", 2560,2048 },
99 { "hsxga", 5120,4096 },
100 { "wvga", 852, 480 },
101 { "wxga", 1366, 768 },
102 { "wsxga", 1600,1024 },
103 { "wuxga", 1920,1200 },
104 { "woxga", 2560,1600 },
105 { "wqhd", 2560,1440 },
106 { "wqsxga", 3200,2048 },
107 { "wquxga", 3840,2400 },
108 { "whsxga", 6400,4096 },
109 { "whuxga", 7680,4800 },
110 { "cga", 320, 200 },
111 { "ega", 640, 350 },
112 { "hd480", 852, 480 },
113 { "hd720", 1280, 720 },
114 { "hd1080", 1920,1080 },
115 { "quadhd", 2560,1440 },
116 { "2k", 2048,1080 }, /* Digital Cinema System Specification */
117 { "2kdci", 2048,1080 },
118 { "2kflat", 1998,1080 },
119 { "2kscope", 2048, 858 },
120 { "4k", 4096,2160 }, /* Digital Cinema System Specification */
121 { "4kdci", 4096,2160 },
122 { "4kflat", 3996,2160 },
123 { "4kscope", 4096,1716 },
124 { "nhd", 640,360 },
125 { "hqvga", 240,160 },
126 { "wqvga", 400,240 },
127 { "fwqvga", 432,240 },
128 { "hvga", 480,320 },
129 { "qhd", 960,540 },
130 { "uhd2160", 3840,2160 },
131 { "uhd4320", 7680,4320 },
132 };
133
134 static const VideoRateAbbr video_rate_abbrs[]= {
135 { "ntsc", { 30000, 1001 } },
136 { "pal", { 25, 1 } },
137 { "qntsc", { 30000, 1001 } }, /* VCD compliant NTSC */
138 { "qpal", { 25, 1 } }, /* VCD compliant PAL */
139 { "sntsc", { 30000, 1001 } }, /* square pixel NTSC */
140 { "spal", { 25, 1 } }, /* square pixel PAL */
141 { "film", { 24, 1 } },
142 { "ntsc-film", { 24000, 1001 } },
143 };
144
145 static const char *months[12] = {
146 "january", "february", "march", "april", "may", "june", "july", "august",
147 "september", "october", "november", "december"
148 };
149
150 9761 int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
151 {
152 int i;
153 9761 int n = FF_ARRAY_ELEMS(video_size_abbrs);
154 const char *p;
155 9761 int width = 0, height = 0;
156
157
2/2
✓ Branch 6 → 3 taken 534844 times.
✓ Branch 6 → 7 taken 9684 times.
544528 for (i = 0; i < n; i++) {
158
2/2
✓ Branch 3 → 4 taken 77 times.
✓ Branch 3 → 5 taken 534767 times.
534844 if (!strcmp(video_size_abbrs[i].abbr, str)) {
159 77 width = video_size_abbrs[i].width;
160 77 height = video_size_abbrs[i].height;
161 77 break;
162 }
163 }
164
2/2
✓ Branch 7 → 8 taken 9684 times.
✓ Branch 7 → 14 taken 77 times.
9761 if (i == n) {
165 9684 width = strtol(str, (void*)&p, 10);
166
1/2
✓ Branch 9 → 10 taken 9684 times.
✗ Branch 9 → 11 not taken.
9684 if (*p)
167 9684 p++;
168 9684 height = strtol(p, (void*)&p, 10);
169
170 /* trailing extraneous data detected, like in 123x345foobar */
171
2/2
✓ Branch 12 → 13 taken 1 time.
✓ Branch 12 → 14 taken 9683 times.
9684 if (*p)
172 1 return AVERROR(EINVAL);
173 }
174
2/4
✓ Branch 14 → 15 taken 9760 times.
✗ Branch 14 → 16 not taken.
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 9760 times.
9760 if (width <= 0 || height <= 0)
175 ✗ return AVERROR(EINVAL);
176 9760 *width_ptr = width;
177 9760 *height_ptr = height;
178 9760 return 0;
179 }
180
181 10697 int av_parse_video_rate(AVRational *rate, const char *arg)
182 {
183 int i, ret;
184 10697 int n = FF_ARRAY_ELEMS(video_rate_abbrs);
185
186 /* First, we check our abbreviation table */
187
2/2
✓ Branch 6 → 3 taken 85535 times.
✓ Branch 6 → 7 taken 10691 times.
96226 for (i = 0; i < n; ++i)
188
2/2
✓ Branch 3 → 4 taken 6 times.
✓ Branch 3 → 5 taken 85529 times.
85535 if (!strcmp(video_rate_abbrs[i].abbr, arg)) {
189 6 *rate = video_rate_abbrs[i].rate;
190 6 return 0;
191 }
192
193 /* Then, we try to parse it as fraction */
194
2/2
✓ Branch 8 → 9 taken 11 times.
✓ Branch 8 → 10 taken 10680 times.
10691 if ((ret = av_parse_ratio_quiet(rate, arg, 1001000)) < 0)
195 11 return ret;
196
4/4
✓ Branch 10 → 11 taken 10678 times.
✓ Branch 10 → 12 taken 2 times.
✓ Branch 11 → 12 taken 4 times.
✓ Branch 11 → 15 taken 10674 times.
10680 if (!rate->num || !rate->den)
197
1/2
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 15 taken 6 times.
6 if ((ret = av_parse_ratio_quiet(rate, arg, INT_MAX)) < 0)
198 ✗ return ret;
199
4/4
✓ Branch 15 → 16 taken 10672 times.
✓ Branch 15 → 17 taken 8 times.
✓ Branch 16 → 17 taken 2 times.
✓ Branch 16 → 18 taken 10670 times.
10680 if (rate->num <= 0 || rate->den <= 0)
200 10 return AVERROR(EINVAL);
201 10670 return 0;
202 }
203
204 typedef struct ColorEntry {
205 const char *name; ///< a string representing the name of the color
206 uint8_t rgb_color[3]; ///< RGB values for the color
207 } ColorEntry;
208
209 static const ColorEntry color_table[] = {
210 { "AliceBlue", { 0xF0, 0xF8, 0xFF } },
211 { "AntiqueWhite", { 0xFA, 0xEB, 0xD7 } },
212 { "Aqua", { 0x00, 0xFF, 0xFF } },
213 { "Aquamarine", { 0x7F, 0xFF, 0xD4 } },
214 { "Azure", { 0xF0, 0xFF, 0xFF } },
215 { "Beige", { 0xF5, 0xF5, 0xDC } },
216 { "Bisque", { 0xFF, 0xE4, 0xC4 } },
217 { "Black", { 0x00, 0x00, 0x00 } },
218 { "BlanchedAlmond", { 0xFF, 0xEB, 0xCD } },
219 { "Blue", { 0x00, 0x00, 0xFF } },
220 { "BlueViolet", { 0x8A, 0x2B, 0xE2 } },
221 { "Brown", { 0xA5, 0x2A, 0x2A } },
222 { "BurlyWood", { 0xDE, 0xB8, 0x87 } },
223 { "CadetBlue", { 0x5F, 0x9E, 0xA0 } },
224 { "Chartreuse", { 0x7F, 0xFF, 0x00 } },
225 { "Chocolate", { 0xD2, 0x69, 0x1E } },
226 { "Coral", { 0xFF, 0x7F, 0x50 } },
227 { "CornflowerBlue", { 0x64, 0x95, 0xED } },
228 { "Cornsilk", { 0xFF, 0xF8, 0xDC } },
229 { "Crimson", { 0xDC, 0x14, 0x3C } },
230 { "Cyan", { 0x00, 0xFF, 0xFF } },
231 { "DarkBlue", { 0x00, 0x00, 0x8B } },
232 { "DarkCyan", { 0x00, 0x8B, 0x8B } },
233 { "DarkGoldenRod", { 0xB8, 0x86, 0x0B } },
234 { "DarkGray", { 0xA9, 0xA9, 0xA9 } },
235 { "DarkGreen", { 0x00, 0x64, 0x00 } },
236 { "DarkKhaki", { 0xBD, 0xB7, 0x6B } },
237 { "DarkMagenta", { 0x8B, 0x00, 0x8B } },
238 { "DarkOliveGreen", { 0x55, 0x6B, 0x2F } },
239 { "Darkorange", { 0xFF, 0x8C, 0x00 } },
240 { "DarkOrchid", { 0x99, 0x32, 0xCC } },
241 { "DarkRed", { 0x8B, 0x00, 0x00 } },
242 { "DarkSalmon", { 0xE9, 0x96, 0x7A } },
243 { "DarkSeaGreen", { 0x8F, 0xBC, 0x8F } },
244 { "DarkSlateBlue", { 0x48, 0x3D, 0x8B } },
245 { "DarkSlateGray", { 0x2F, 0x4F, 0x4F } },
246 { "DarkTurquoise", { 0x00, 0xCE, 0xD1 } },
247 { "DarkViolet", { 0x94, 0x00, 0xD3 } },
248 { "DeepPink", { 0xFF, 0x14, 0x93 } },
249 { "DeepSkyBlue", { 0x00, 0xBF, 0xFF } },
250 { "DimGray", { 0x69, 0x69, 0x69 } },
251 { "DodgerBlue", { 0x1E, 0x90, 0xFF } },
252 { "FireBrick", { 0xB2, 0x22, 0x22 } },
253 { "FloralWhite", { 0xFF, 0xFA, 0xF0 } },
254 { "ForestGreen", { 0x22, 0x8B, 0x22 } },
255 { "Fuchsia", { 0xFF, 0x00, 0xFF } },
256 { "Gainsboro", { 0xDC, 0xDC, 0xDC } },
257 { "GhostWhite", { 0xF8, 0xF8, 0xFF } },
258 { "Gold", { 0xFF, 0xD7, 0x00 } },
259 { "GoldenRod", { 0xDA, 0xA5, 0x20 } },
260 { "Gray", { 0x80, 0x80, 0x80 } },
261 { "Green", { 0x00, 0x80, 0x00 } },
262 { "GreenYellow", { 0xAD, 0xFF, 0x2F } },
263 { "HoneyDew", { 0xF0, 0xFF, 0xF0 } },
264 { "HotPink", { 0xFF, 0x69, 0xB4 } },
265 { "IndianRed", { 0xCD, 0x5C, 0x5C } },
266 { "Indigo", { 0x4B, 0x00, 0x82 } },
267 { "Ivory", { 0xFF, 0xFF, 0xF0 } },
268 { "Khaki", { 0xF0, 0xE6, 0x8C } },
269 { "Lavender", { 0xE6, 0xE6, 0xFA } },
270 { "LavenderBlush", { 0xFF, 0xF0, 0xF5 } },
271 { "LawnGreen", { 0x7C, 0xFC, 0x00 } },
272 { "LemonChiffon", { 0xFF, 0xFA, 0xCD } },
273 { "LightBlue", { 0xAD, 0xD8, 0xE6 } },
274 { "LightCoral", { 0xF0, 0x80, 0x80 } },
275 { "LightCyan", { 0xE0, 0xFF, 0xFF } },
276 { "LightGoldenRodYellow", { 0xFA, 0xFA, 0xD2 } },
277 { "LightGreen", { 0x90, 0xEE, 0x90 } },
278 { "LightGrey", { 0xD3, 0xD3, 0xD3 } },
279 { "LightPink", { 0xFF, 0xB6, 0xC1 } },
280 { "LightSalmon", { 0xFF, 0xA0, 0x7A } },
281 { "LightSeaGreen", { 0x20, 0xB2, 0xAA } },
282 { "LightSkyBlue", { 0x87, 0xCE, 0xFA } },
283 { "LightSlateGray", { 0x77, 0x88, 0x99 } },
284 { "LightSteelBlue", { 0xB0, 0xC4, 0xDE } },
285 { "LightYellow", { 0xFF, 0xFF, 0xE0 } },
286 { "Lime", { 0x00, 0xFF, 0x00 } },
287 { "LimeGreen", { 0x32, 0xCD, 0x32 } },
288 { "Linen", { 0xFA, 0xF0, 0xE6 } },
289 { "Magenta", { 0xFF, 0x00, 0xFF } },
290 { "Maroon", { 0x80, 0x00, 0x00 } },
291 { "MediumAquaMarine", { 0x66, 0xCD, 0xAA } },
292 { "MediumBlue", { 0x00, 0x00, 0xCD } },
293 { "MediumOrchid", { 0xBA, 0x55, 0xD3 } },
294 { "MediumPurple", { 0x93, 0x70, 0xD8 } },
295 { "MediumSeaGreen", { 0x3C, 0xB3, 0x71 } },
296 { "MediumSlateBlue", { 0x7B, 0x68, 0xEE } },
297 { "MediumSpringGreen", { 0x00, 0xFA, 0x9A } },
298 { "MediumTurquoise", { 0x48, 0xD1, 0xCC } },
299 { "MediumVioletRed", { 0xC7, 0x15, 0x85 } },
300 { "MidnightBlue", { 0x19, 0x19, 0x70 } },
301 { "MintCream", { 0xF5, 0xFF, 0xFA } },
302 { "MistyRose", { 0xFF, 0xE4, 0xE1 } },
303 { "Moccasin", { 0xFF, 0xE4, 0xB5 } },
304 { "NavajoWhite", { 0xFF, 0xDE, 0xAD } },
305 { "Navy", { 0x00, 0x00, 0x80 } },
306 { "OldLace", { 0xFD, 0xF5, 0xE6 } },
307 { "Olive", { 0x80, 0x80, 0x00 } },
308 { "OliveDrab", { 0x6B, 0x8E, 0x23 } },
309 { "Orange", { 0xFF, 0xA5, 0x00 } },
310 { "OrangeRed", { 0xFF, 0x45, 0x00 } },
311 { "Orchid", { 0xDA, 0x70, 0xD6 } },
312 { "PaleGoldenRod", { 0xEE, 0xE8, 0xAA } },
313 { "PaleGreen", { 0x98, 0xFB, 0x98 } },
314 { "PaleTurquoise", { 0xAF, 0xEE, 0xEE } },
315 { "PaleVioletRed", { 0xD8, 0x70, 0x93 } },
316 { "PapayaWhip", { 0xFF, 0xEF, 0xD5 } },
317 { "PeachPuff", { 0xFF, 0xDA, 0xB9 } },
318 { "Peru", { 0xCD, 0x85, 0x3F } },
319 { "Pink", { 0xFF, 0xC0, 0xCB } },
320 { "Plum", { 0xDD, 0xA0, 0xDD } },
321 { "PowderBlue", { 0xB0, 0xE0, 0xE6 } },
322 { "Purple", { 0x80, 0x00, 0x80 } },
323 { "Red", { 0xFF, 0x00, 0x00 } },
324 { "RosyBrown", { 0xBC, 0x8F, 0x8F } },
325 { "RoyalBlue", { 0x41, 0x69, 0xE1 } },
326 { "SaddleBrown", { 0x8B, 0x45, 0x13 } },
327 { "Salmon", { 0xFA, 0x80, 0x72 } },
328 { "SandyBrown", { 0xF4, 0xA4, 0x60 } },
329 { "SeaGreen", { 0x2E, 0x8B, 0x57 } },
330 { "SeaShell", { 0xFF, 0xF5, 0xEE } },
331 { "Sienna", { 0xA0, 0x52, 0x2D } },
332 { "Silver", { 0xC0, 0xC0, 0xC0 } },
333 { "SkyBlue", { 0x87, 0xCE, 0xEB } },
334 { "SlateBlue", { 0x6A, 0x5A, 0xCD } },
335 { "SlateGray", { 0x70, 0x80, 0x90 } },
336 { "Snow", { 0xFF, 0xFA, 0xFA } },
337 { "SpringGreen", { 0x00, 0xFF, 0x7F } },
338 { "SteelBlue", { 0x46, 0x82, 0xB4 } },
339 { "Tan", { 0xD2, 0xB4, 0x8C } },
340 { "Teal", { 0x00, 0x80, 0x80 } },
341 { "Thistle", { 0xD8, 0xBF, 0xD8 } },
342 { "Tomato", { 0xFF, 0x63, 0x47 } },
343 { "Turquoise", { 0x40, 0xE0, 0xD0 } },
344 { "Violet", { 0xEE, 0x82, 0xEE } },
345 { "Wheat", { 0xF5, 0xDE, 0xB3 } },
346 { "White", { 0xFF, 0xFF, 0xFF } },
347 { "WhiteSmoke", { 0xF5, 0xF5, 0xF5 } },
348 { "Yellow", { 0xFF, 0xFF, 0x00 } },
349 { "YellowGreen", { 0x9A, 0xCD, 0x32 } },
350 };
351
352 5284 static int color_table_compare(const void *lhs, const void *rhs)
353 {
354 5284 return av_strcasecmp(lhs, ((const ColorEntry *)rhs)->name);
355 }
356
357 #define ALPHA_SEP '@'
358
359 867 int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen,
360 void *log_ctx)
361 {
362 char *tail, color_string2[128];
363 const ColorEntry *entry;
364 867 int len, hex_offset = 0;
365
366
2/2
✓ Branch 2 → 3 taken 48 times.
✓ Branch 2 → 4 taken 819 times.
867 if (color_string[0] == '#') {
367 48 hex_offset = 1;
368
2/2
✓ Branch 4 → 5 taken 45 times.
✓ Branch 4 → 6 taken 774 times.
819 } else if (!strncmp(color_string, "0x", 2))
369 45 hex_offset = 2;
370
371
2/2
✓ Branch 6 → 7 taken 770 times.
✓ Branch 6 → 8 taken 97 times.
867 if (slen < 0)
372 770 slen = strlen(color_string);
373 867 av_strlcpy(color_string2, color_string + hex_offset,
374
1/2
✓ Branch 8 → 9 taken 867 times.
✗ Branch 8 → 10 not taken.
867 FFMIN(slen-hex_offset+1, sizeof(color_string2)));
375
2/2
✓ Branch 12 → 13 taken 33 times.
✓ Branch 12 → 14 taken 834 times.
867 if ((tail = strchr(color_string2, ALPHA_SEP)))
376 33 *tail++ = 0;
377 867 len = strlen(color_string2);
378 867 rgba_color[3] = 255;
379
380
4/4
✓ Branch 15 → 16 taken 865 times.
✓ Branch 15 → 18 taken 2 times.
✓ Branch 17 → 18 taken 1 time.
✓ Branch 17 → 20 taken 864 times.
867 if (!av_strcasecmp(color_string2, "random") || !av_strcasecmp(color_string2, "bikeshed")) {
381 3 int rgba = av_get_random_seed();
382 3 rgba_color[0] = rgba >> 24;
383 3 rgba_color[1] = rgba >> 16;
384 3 rgba_color[2] = rgba >> 8;
385 3 rgba_color[3] = rgba;
386
2/2
✓ Branch 20 → 21 taken 771 times.
✓ Branch 20 → 22 taken 93 times.
864 } else if (hex_offset ||
387
2/2
✓ Branch 21 → 22 taken 10 times.
✓ Branch 21 → 31 taken 761 times.
771 strspn(color_string2, "0123456789ABCDEFabcdef") == len) {
388 char *tail;
389 103 unsigned int rgba = strtoul(color_string2, &tail, 16);
390
391
6/6
✓ Branch 23 → 24 taken 100 times.
✓ Branch 23 → 26 taken 3 times.
✓ Branch 24 → 25 taken 7 times.
✓ Branch 24 → 28 taken 93 times.
✓ Branch 25 → 26 taken 2 times.
✓ Branch 25 → 28 taken 5 times.
103 if (*tail || (len != 6 && len != 8)) {
392 5 av_log(log_ctx, AV_LOG_ERROR, "Invalid 0xRRGGBB[AA] color string: '%s'\n", color_string2);
393 5 return AVERROR(EINVAL);
394 }
395
2/2
✓ Branch 28 → 29 taken 5 times.
✓ Branch 28 → 30 taken 93 times.
98 if (len == 8) {
396 5 rgba_color[3] = rgba;
397 5 rgba >>= 8;
398 }
399 98 rgba_color[0] = rgba >> 16;
400 98 rgba_color[1] = rgba >> 8;
401 98 rgba_color[2] = rgba;
402 } else {
403 761 entry = bsearch(color_string2,
404 color_table,
405 FF_ARRAY_ELEMS(color_table),
406 sizeof(ColorEntry),
407 color_table_compare);
408
2/2
✓ Branch 32 → 33 taken 3 times.
✓ Branch 32 → 35 taken 758 times.
761 if (!entry) {
409 3 av_log(log_ctx, AV_LOG_ERROR, "Cannot find color '%s'\n", color_string2);
410 3 return AVERROR(EINVAL);
411 }
412 758 memcpy(rgba_color, entry->rgb_color, 3);
413 }
414
415
2/2
✓ Branch 36 → 37 taken 33 times.
✓ Branch 36 → 52 taken 826 times.
859 if (tail) {
416 double alpha;
417 33 const char *alpha_string = tail;
418
2/2
✓ Branch 37 → 38 taken 18 times.
✓ Branch 37 → 40 taken 15 times.
33 if (!strncmp(alpha_string, "0x", 2)) {
419 18 alpha = strtoul(alpha_string, &tail, 16);
420 } else {
421 15 double norm_alpha = strtod(alpha_string, &tail);
422
4/4
✓ Branch 41 → 42 taken 13 times.
✓ Branch 41 → 43 taken 2 times.
✓ Branch 42 → 43 taken 4 times.
✓ Branch 42 → 44 taken 9 times.
15 if (norm_alpha < 0.0 || norm_alpha > 1.0)
423 6 alpha = 256;
424 else
425 9 alpha = 255 * norm_alpha;
426 }
427
428
7/8
✓ Branch 45 → 46 taken 31 times.
✓ Branch 45 → 49 taken 2 times.
✓ Branch 46 → 47 taken 30 times.
✓ Branch 46 → 49 taken 1 time.
✓ Branch 47 → 48 taken 24 times.
✓ Branch 47 → 49 taken 6 times.
✗ Branch 48 → 49 not taken.
✓ Branch 48 → 51 taken 24 times.
33 if (tail == alpha_string || *tail || alpha > 255 || alpha < 0) {
429 9 av_log(log_ctx, AV_LOG_ERROR, "Invalid alpha value specifier '%s' in '%s'\n",
430 alpha_string, color_string);
431 9 return AVERROR(EINVAL);
432 }
433 24 rgba_color[3] = alpha;
434 }
435
436 850 return 0;
437 }
438
439 140 const char *av_get_known_color_name(int color_idx, const uint8_t **rgbp)
440 {
441 const ColorEntry *color;
442
443
1/2
✗ Branch 2 → 3 not taken.
✓ Branch 2 → 4 taken 140 times.
140 if ((unsigned)color_idx >= FF_ARRAY_ELEMS(color_table))
444 ✗ return NULL;
445
446 140 color = &color_table[color_idx];
447
1/2
✓ Branch 4 → 5 taken 140 times.
✗ Branch 4 → 6 not taken.
140 if (rgbp)
448 140 *rgbp = color->rgb_color;
449
450 140 return color->name;
451 }
452
453 /* get a positive number between n_min and n_max, for a maximum length
454 of len_max. Return -1 if error. */
455 5334 static int date_get_num(const char **pp,
456 int n_min, int n_max, int len_max)
457 {
458 int i, val, c;
459 const char *p;
460
461 5334 p = *pp;
462 5334 val = 0;
463
2/2
✓ Branch 6 → 3 taken 11321 times.
✓ Branch 6 → 7 taken 978 times.
12299 for(i = 0; i < len_max; i++) {
464 11321 c = *p;
465
2/2
✓ Branch 3 → 4 taken 4356 times.
✓ Branch 3 → 5 taken 6965 times.
11321 if (!av_isdigit(c))
466 4356 break;
467 6965 val = (val * 10) + c - '0';
468 6965 p++;
469 }
470 /* no number read ? */
471
2/2
✓ Branch 7 → 8 taken 4 times.
✓ Branch 7 → 9 taken 5330 times.
5334 if (p == *pp)
472 4 return -1;
473
3/4
✓ Branch 9 → 10 taken 5330 times.
✗ Branch 9 → 11 not taken.
✓ Branch 10 → 11 taken 4 times.
✓ Branch 10 → 12 taken 5326 times.
5330 if (val < n_min || val > n_max)
474 4 return -1;
475 5326 *pp = p;
476 5326 return val;
477 }
478
479 7 static int date_get_month(const char **pp) {
480 7 int i = 0;
481
2/2
✓ Branch 11 → 3 taken 47 times.
✓ Branch 11 → 12 taken 1 time.
48 for (; i < 12; i++) {
482
2/2
✓ Branch 4 → 5 taken 6 times.
✓ Branch 4 → 10 taken 41 times.
47 if (!av_strncasecmp(*pp, months[i], 3)) {
483 6 const char *mo_full = months[i] + 3;
484 6 int len = strlen(mo_full);
485 6 *pp += 3;
486
4/4
✓ Branch 5 → 6 taken 5 times.
✓ Branch 5 → 9 taken 1 time.
✓ Branch 7 → 8 taken 3 times.
✓ Branch 7 → 9 taken 2 times.
6 if (len > 0 && !av_strncasecmp(*pp, mo_full, len))
487 3 *pp += len;
488 6 return i;
489 }
490 }
491 1 return -1;
492 }
493
494 4983 char *av_small_strptime(const char *p, const char *fmt, struct tm *dt)
495 {
496 int c, val;
497
498
2/2
✓ Branch 57 → 3 taken 10620 times.
✓ Branch 57 → 58 taken 168 times.
10788 while((c = *fmt++)) {
499
2/2
✓ Branch 3 → 4 taken 5279 times.
✓ Branch 3 → 13 taken 5341 times.
10620 if (c != '%') {
500
2/2
✓ Branch 4 → 5 taken 127 times.
✓ Branch 4 → 9 taken 5152 times.
5279 if (av_isspace(c))
501
3/4
✓ Branch 7 → 8 taken 227 times.
✗ Branch 7 → 12 not taken.
✓ Branch 8 → 6 taken 100 times.
✓ Branch 8 → 12 taken 127 times.
227 for (; *p && av_isspace(*p); p++);
502
2/2
✓ Branch 9 → 10 taken 4806 times.
✓ Branch 9 → 11 taken 346 times.
5152 else if (*p != c)
503 4806 return NULL;
504 346 else p++;
505 473 continue;
506 }
507
508 5341 c = *fmt++;
509
7/10
✓ Branch 13 → 14 taken 2502 times.
✓ Branch 13 → 24 taken 2617 times.
✓ Branch 13 → 28 taken 152 times.
✓ Branch 13 → 32 taken 25 times.
✓ Branch 13 → 36 taken 17 times.
✓ Branch 13 → 40 taken 21 times.
✗ Branch 13 → 44 not taken.
✓ Branch 13 → 48 taken 7 times.
✗ Branch 13 → 52 not taken.
✗ Branch 13 → 55 not taken.
5341 switch(c) {
510 2502 case 'H':
511 case 'J':
512
4/4
✓ Branch 14 → 15 taken 25 times.
✓ Branch 14 → 16 taken 2477 times.
✓ Branch 17 → 18 taken 25 times.
✓ Branch 17 → 19 taken 2477 times.
2502 val = date_get_num(&p, 0, c == 'H' ? 23 : INT_MAX, c == 'H' ? 2 : 4);
513
514
2/2
✓ Branch 21 → 22 taken 1 time.
✓ Branch 21 → 23 taken 2501 times.
2502 if (val == -1)
515 1 return NULL;
516 2501 dt->tm_hour = val;
517 2501 break;
518 2617 case 'M':
519 2617 val = date_get_num(&p, 0, 59, 2);
520
2/2
✓ Branch 25 → 26 taken 6 times.
✓ Branch 25 → 27 taken 2611 times.
2617 if (val == -1)
521 6 return NULL;
522 2611 dt->tm_min = val;
523 2611 break;
524 152 case 'S':
525 152 val = date_get_num(&p, 0, 59, 2);
526
1/2
✗ Branch 29 → 30 not taken.
✓ Branch 29 → 31 taken 152 times.
152 if (val == -1)
527 ✗ return NULL;
528 152 dt->tm_sec = val;
529 152 break;
530 25 case 'Y':
531 25 val = date_get_num(&p, 0, 9999, 4);
532
1/2
✗ Branch 33 → 34 not taken.
✓ Branch 33 → 35 taken 25 times.
25 if (val == -1)
533 ✗ return NULL;
534 25 dt->tm_year = val - 1900;
535 25 break;
536 17 case 'm':
537 17 val = date_get_num(&p, 1, 12, 2);
538
2/2
✓ Branch 37 → 38 taken 1 time.
✓ Branch 37 → 39 taken 16 times.
17 if (val == -1)
539 1 return NULL;
540 16 dt->tm_mon = val - 1;
541 16 break;
542 21 case 'd':
543 21 val = date_get_num(&p, 1, 31, 2);
544
1/2
✗ Branch 41 → 42 not taken.
✓ Branch 41 → 43 taken 21 times.
21 if (val == -1)
545 ✗ return NULL;
546 21 dt->tm_mday = val;
547 21 break;
548 ✗ case 'T':
549 ✗ p = av_small_strptime(p, "%H:%M:%S", dt);
550
0/2
✗ Branch 45 → 46 not taken.
✗ Branch 45 → 47 not taken.
✗ if (!p)
551 ✗ return NULL;
552 ✗ break;
553 7 case 'b':
554 case 'B':
555 case 'h':
556 7 val = date_get_month(&p);
557
2/2
✓ Branch 49 → 50 taken 1 time.
✓ Branch 49 → 51 taken 6 times.
7 if (val == -1)
558 1 return NULL;
559 6 dt->tm_mon = val;
560 6 break;
561 ✗ case '%':
562
0/2
✗ Branch 52 → 53 not taken.
✗ Branch 52 → 54 not taken.
✗ if (*p++ != '%')
563 ✗ return NULL;
564 ✗ break;
565 ✗ default:
566 ✗ return NULL;
567 }
568 }
569
570 168 return (char*)p;
571 }
572
573 44 time_t av_timegm(struct tm *tm)
574 {
575 int64_t t;
576
577 44 int y = tm->tm_year + 1900, m = tm->tm_mon + 1, d = tm->tm_mday;
578
579
2/2
✓ Branch 2 → 3 taken 5 times.
✓ Branch 2 → 4 taken 39 times.
44 if (m < 3) {
580 5 m += 12;
581 5 y--;
582 }
583
584 44 t = 86400LL *
585 44 (d + (153 * m - 457) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 719469);
586
587 44 t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec;
588
589 // saturate if time_t cannot hold the result
590 if ((time_t)t != t) {
591 const time_t max = (time_t)-1 < 0 ? (time_t)(INT64_MAX >> (64 - 8 * sizeof(time_t))) : (time_t)-1;
592 return t > 0 ? max : (time_t)-1 < 0 ? -max - 1 : 0;
593 }
594
595 44 return t;
596 }
597
598 2491 int av_parse_time(int64_t *timeval, const char *timestr, int duration)
599 {
600 const char *p, *q;
601 int64_t t, now64;
602 time_t now;
603 2491 struct tm dt = { 0 }, tmbuf;
604 2491 int today = 0, negative = 0, microseconds = 0, suffix = 1000000;
605 int i;
606 static const char * const date_fmt[] = {
607 "%Y - %m - %d",
608 "%Y%m%d",
609 };
610 static const char * const time_fmt[] = {
611 "%H:%M:%S",
612 "%H%M%S",
613 };
614 static const char * const tz_fmt[] = {
615 "%H:%M",
616 "%H%M",
617 "%H",
618 };
619
620 2491 p = timestr;
621 2491 q = NULL;
622 2491 *timeval = INT64_MIN;
623
3/3
✓ Branch 2 → 3 taken 14 times.
✓ Branch 2 → 27 taken 9 times.
✓ Branch 2 → 28 taken 2468 times.
2491 if (!duration) {
624 14 now64 = av_gettime();
625 14 now = now64 / 1000000;
626
627
3/4
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 6 times.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 7 times.
14 if (!av_strcasecmp(timestr, "now")) {
628 1 *timeval = now64;
629 1 return 0;
630 }
631
632 /* parse the year-month-day part */
633
3/4
✓ Branch 11 → 7 taken 7 times.
✓ Branch 11 → 12 taken 1 time.
✓ Branch 12 → 8 taken 7 times.
✗ Branch 12 → 13 not taken.
15 for (i = 0; i < FF_ARRAY_ELEMS(date_fmt); i++) {
634 14 q = av_small_strptime(p, date_fmt[i], &dt);
635
3/4
✓ Branch 8 → 9 taken 5 times.
✓ Branch 8 → 10 taken 2 times.
✓ Branch 9 → 10 taken 7 times.
✗ Branch 9 → 11 not taken.
14 if (q)
636 12 break;
637 }
638
639 /* if the year-month-day part is missing, then take the
640 * current year-month-day time */
641
3/4
✓ Branch 12 → 13 taken 1 time.
✓ Branch 12 → 14 taken 5 times.
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 15 taken 7 times.
13 if (!q) {
642 1 today = 1;
643 1 q = p;
644 }
645 13 p = q;
646
647
3/6
✓ Branch 14 → 15 taken 5 times.
✓ Branch 14 → 16 taken 1 time.
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 12 times.
✗ Branch 16 → 17 not taken.
✗ Branch 16 → 18 not taken.
13 if (*p == 'T' || *p == 't')
648 8 p++;
649 else
650
2/4
✓ Branch 19 → 18 taken 5 times.
✓ Branch 19 → 20 taken 5 times.
✗ Branch 20 → 19 not taken.
✗ Branch 20 → 21 not taken.
10 while (av_isspace(*p))
651 5 p++;
652
653 /* parse the hour-minute-second part */
654
2/4
✓ Branch 25 → 21 taken 7 times.
✗ Branch 25 → 26 not taken.
✓ Branch 26 → 22 taken 7 times.
✗ Branch 26 → 27 not taken.
14 for (i = 0; i < FF_ARRAY_ELEMS(time_fmt); i++) {
655 14 q = av_small_strptime(p, time_fmt[i], &dt);
656
3/4
✓ Branch 22 → 23 taken 6 times.
✓ Branch 22 → 24 taken 1 time.
✓ Branch 23 → 24 taken 7 times.
✗ Branch 23 → 25 not taken.
14 if (q)
657 13 break;
658 }
659 } else {
660 /* parse timestr as a duration */
661
4/4
✓ Branch 27 → 28 taken 2 times.
✓ Branch 27 → 29 taken 7 times.
✓ Branch 28 → 29 taken 5 times.
✓ Branch 28 → 30 taken 2463 times.
2477 if (p[0] == '-') {
662 7 negative = 1;
663 7 ++p;
664 }
665 /* parse timestr as HH:MM:SS */
666 2477 q = av_small_strptime(p, "%J:%M:%S", &dt);
667
4/4
✓ Branch 30 → 31 taken 7 times.
✓ Branch 30 → 33 taken 2 times.
✓ Branch 31 → 32 taken 2456 times.
✓ Branch 31 → 34 taken 12 times.
2477 if (!q) {
668 /* parse timestr as MM:SS */
669 2463 q = av_small_strptime(p, "%M:%S", &dt);
670 2463 dt.tm_hour = 0;
671 }
672
4/4
✓ Branch 33 → 34 taken 6 times.
✓ Branch 33 → 41 taken 3 times.
✓ Branch 34 → 35 taken 2339 times.
✓ Branch 34 → 42 taken 129 times.
2477 if (!q) {
673 char *o;
674 /* parse timestr as S+ */
675 2345 errno = 0;
676 2345 t = strtoll(p, &o, 10);
677
3/4
✗ Branch 35 → 36 not taken.
✓ Branch 35 → 37 taken 6 times.
✓ Branch 36 → 37 taken 1 time.
✓ Branch 36 → 38 taken 2338 times.
2345 if (o == p) /* the parsing didn't succeed */
678 2 return AVERROR(EINVAL);
679
3/4
✓ Branch 37 → 38 taken 1 time.
✓ Branch 37 → 39 taken 5 times.
✗ Branch 38 → 39 not taken.
✓ Branch 38 → 40 taken 2338 times.
2344 if (errno == ERANGE)
680 1 return AVERROR(ERANGE);
681 2343 q = o;
682 } else {
683 132 t = dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec;
684 }
685 }
686
687 /* Now we have all the fields that we can get */
688
2/4
✗ Branch 42 → 43 not taken.
✓ Branch 42 → 44 taken 14 times.
✗ Branch 43 → 44 not taken.
✓ Branch 43 → 45 taken 2474 times.
2488 if (!q)
689 ✗ return AVERROR(EINVAL);
690
691 /* parse the .m... part */
692
4/4
✓ Branch 44 → 45 taken 6 times.
✓ Branch 44 → 53 taken 8 times.
✓ Branch 45 → 46 taken 473 times.
✓ Branch 45 → 54 taken 2001 times.
2488 if (*q == '.') {
693 int n;
694 479 q++;
695
3/4
✓ Branch 49 → 46 taken 18 times.
✗ Branch 49 → 50 not taken.
✓ Branch 50 → 47 taken 1327 times.
✓ Branch 50 → 51 taken 16 times.
1361 for (n = 100000; n >= 1; n /= 10, q++) {
696
4/4
✓ Branch 46 → 47 taken 6 times.
✓ Branch 46 → 48 taken 12 times.
✓ Branch 47 → 48 taken 457 times.
✓ Branch 47 → 49 taken 870 times.
1345 if (!av_isdigit(*q))
697 463 break;
698 882 microseconds += n * (*q - '0');
699 }
700
3/4
✗ Branch 52 → 51 not taken.
✓ Branch 52 → 53 taken 6 times.
✓ Branch 53 → 52 taken 30 times.
✓ Branch 53 → 54 taken 473 times.
509 while (av_isdigit(*q))
701 30 q++;
702 }
703
704
4/4
✓ Branch 53 → 54 taken 8 times.
✓ Branch 53 → 63 taken 6 times.
✓ Branch 54 → 55 taken 2467 times.
✓ Branch 54 → 64 taken 7 times.
2488 if (duration) {
705
5/7
✓ Branch 54 → 55 taken 1 time.
✓ Branch 54 → 57 taken 7 times.
✓ Branch 55 → 56 taken 2 times.
✗ Branch 55 → 57 not taken.
✓ Branch 55 → 58 taken 2466 times.
✓ Branch 56 → 57 taken 1 time.
✗ Branch 56 → 58 not taken.
2475 if (q[0] == 'm' && q[1] == 's') {
706 2 suffix = 1000;
707 2 microseconds /= 1000;
708 2 q += 2;
709
4/7
✓ Branch 57 → 58 taken 1 time.
✓ Branch 57 → 60 taken 6 times.
✓ Branch 58 → 59 taken 1 time.
✗ Branch 58 → 60 not taken.
✓ Branch 58 → 61 taken 2466 times.
✗ Branch 59 → 60 not taken.
✗ Branch 59 → 61 not taken.
2473 } else if (q[0] == 'u' && q[1] == 's') {
710 1 suffix = 1;
711 1 microseconds = 0;
712 1 q += 2;
713
4/4
✓ Branch 60 → 61 taken 1 time.
✓ Branch 60 → 62 taken 5 times.
✓ Branch 61 → 62 taken 5 times.
✓ Branch 61 → 63 taken 2461 times.
2472 } else if (*q == 's')
714 6 q++;
715 } else {
716
4/6
✓ Branch 63 → 64 taken 6 times.
✗ Branch 63 → 65 not taken.
✓ Branch 64 → 65 taken 6 times.
✓ Branch 64 → 66 taken 7 times.
✗ Branch 65 → 66 not taken.
✓ Branch 65 → 67 taken 5 times.
13 int is_utc = *q == 'Z' || *q == 'z';
717 13 int tzoffset = 0;
718 13 q += is_utc;
719
10/13
✓ Branch 67 → 68 taken 5 times.
✓ Branch 67 → 83 taken 1 time.
✓ Branch 68 → 69 taken 11 times.
✓ Branch 68 → 83 taken 1 time.
✗ Branch 68 → 84 not taken.
✓ Branch 69 → 70 taken 8 times.
✓ Branch 69 → 71 taken 1 time.
✓ Branch 69 → 84 taken 2 times.
✓ Branch 70 → 71 taken 6 times.
✗ Branch 70 → 72 not taken.
✓ Branch 70 → 83 taken 2 times.
✗ Branch 71 → 72 not taken.
✓ Branch 71 → 84 taken 5 times.
13 if (!today && !is_utc && (*q == '+' || *q == '-')) {
720 2 struct tm tz = { 0 };
721
2/4
✓ Branch 71 → 72 taken 1 time.
✓ Branch 71 → 73 taken 1 time.
✗ Branch 72 → 73 not taken.
✗ Branch 72 → 74 not taken.
2 int sign = (*q == '+' ? -1 : 1);
722 2 q++;
723 2 p = q;
724
1/4
✓ Branch 79 → 75 taken 4 times.
✗ Branch 79 → 80 not taken.
✗ Branch 80 → 76 not taken.
✗ Branch 80 → 81 not taken.
4 for (i = 0; i < FF_ARRAY_ELEMS(tz_fmt); i++) {
725 4 q = av_small_strptime(p, tz_fmt[i], &tz);
726
2/4
✓ Branch 76 → 77 taken 2 times.
✓ Branch 76 → 78 taken 2 times.
✗ Branch 77 → 78 not taken.
✗ Branch 77 → 79 not taken.
4 if (q)
727 2 break;
728 }
729
1/4
✗ Branch 80 → 81 not taken.
✓ Branch 80 → 82 taken 2 times.
✗ Branch 81 → 82 not taken.
✗ Branch 81 → 83 not taken.
2 if (!q)
730 ✗ return AVERROR(EINVAL);
731 2 tzoffset = sign * (tz.tm_hour * 60 + tz.tm_min) * 60;
732 2 is_utc = 1;
733 }
734
3/4
✓ Branch 83 → 84 taken 1 time.
✓ Branch 83 → 90 taken 5 times.
✗ Branch 84 → 85 not taken.
✓ Branch 84 → 91 taken 7 times.
13 if (today) { /* fill in today's date */
735
1/4
✗ Branch 84 → 85 not taken.
✓ Branch 84 → 87 taken 1 time.
✗ Branch 85 → 86 not taken.
✗ Branch 85 → 88 not taken.
1 struct tm dt2 = is_utc ? *gmtime_r(&now, &tmbuf) : *localtime_r(&now, &tmbuf);
736 1 dt2.tm_hour = dt.tm_hour;
737 1 dt2.tm_min = dt.tm_min;
738 1 dt2.tm_sec = dt.tm_sec;
739 1 dt = dt2;
740 }
741
4/4
✓ Branch 90 → 91 taken 3 times.
✓ Branch 90 → 92 taken 3 times.
✓ Branch 91 → 92 taken 2 times.
✓ Branch 91 → 93 taken 5 times.
13 dt.tm_isdst = is_utc ? 0 : -1;
742
4/4
✓ Branch 93 → 94 taken 3 times.
✓ Branch 93 → 95 taken 3 times.
✓ Branch 94 → 95 taken 2 times.
✓ Branch 94 → 96 taken 5 times.
13 t = is_utc ? av_timegm(&dt) : mktime(&dt);
743 13 t += tzoffset;
744 }
745
746 /* Check that we are at the end of the string */
747
2/4
✗ Branch 97 → 98 not taken.
✓ Branch 97 → 99 taken 14 times.
✗ Branch 98 → 99 not taken.
✓ Branch 98 → 100 taken 2474 times.
2488 if (*q)
748 ✗ return AVERROR(EINVAL);
749
750
4/6
✓ Branch 99 → 100 taken 14 times.
✗ Branch 99 → 101 not taken.
✓ Branch 100 → 101 taken 2474 times.
✓ Branch 100 → 102 taken 14 times.
✗ Branch 101 → 102 not taken.
✓ Branch 101 → 103 taken 2474 times.
2488 if (INT64_MAX / suffix < t || t < INT64_MIN / suffix)
751 ✗ return AVERROR(ERANGE);
752 2488 t *= suffix;
753
2/4
✗ Branch 102 → 103 not taken.
✓ Branch 102 → 104 taken 14 times.
✗ Branch 103 → 104 not taken.
✓ Branch 103 → 105 taken 2474 times.
2488 if (INT64_MAX - microseconds < t)
754 ✗ return AVERROR(ERANGE);
755 2488 t += microseconds;
756
2/7
✗ Branch 104 → 105 not taken.
✓ Branch 104 → 107 taken 14 times.
✗ Branch 105 → 106 not taken.
✗ Branch 105 → 107 not taken.
✓ Branch 105 → 108 taken 2474 times.
✗ Branch 106 → 107 not taken.
✗ Branch 106 → 108 not taken.
2488 if (t == INT64_MIN && negative)
757 ✗ return AVERROR(ERANGE);
758
4/4
✓ Branch 107 → 108 taken 2 times.
✓ Branch 107 → 109 taken 12 times.
✓ Branch 108 → 109 taken 5 times.
✓ Branch 108 → 110 taken 2469 times.
2488 *timeval = negative ? -t : t;
759 2488 return 0;
760 }
761
762 7 int av_find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)
763 {
764 const char *p;
765 char tag[128], *q;
766
767 7 p = info;
768
1/2
✓ Branch 2 → 3 taken 7 times.
✗ Branch 2 → 4 not taken.
7 if (*p == '?')
769 7 p++;
770 for(;;) {
771 25 q = tag;
772
4/6
✓ Branch 9 → 10 taken 132 times.
✗ Branch 9 → 12 not taken.
✓ Branch 10 → 11 taken 107 times.
✓ Branch 10 → 12 taken 25 times.
✓ Branch 11 → 6 taken 107 times.
✗ Branch 11 → 12 not taken.
132 while (*p != '\0' && *p != '=' && *p != '&') {
773
1/2
✓ Branch 6 → 7 taken 107 times.
✗ Branch 6 → 8 not taken.
107 if ((q - tag) < sizeof(tag) - 1)
774 107 *q++ = *p;
775 107 p++;
776 }
777 25 *q = '\0';
778 25 q = arg;
779
1/2
✓ Branch 12 → 13 taken 25 times.
✗ Branch 12 → 21 not taken.
25 if (*p == '=') {
780 25 p++;
781
4/4
✓ Branch 19 → 20 taken 128 times.
✓ Branch 19 → 21 taken 22 times.
✓ Branch 20 → 14 taken 125 times.
✓ Branch 20 → 21 taken 3 times.
150 while (*p != '&' && *p != '\0') {
782
1/2
✓ Branch 14 → 15 taken 125 times.
✗ Branch 14 → 18 not taken.
125 if ((q - arg) < arg_size - 1) {
783
1/2
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 125 times.
125 if (*p == '+')
784 ✗ *q++ = ' ';
785 else
786 125 *q++ = *p;
787 }
788 125 p++;
789 }
790 }
791 25 *q = '\0';
792
2/2
✓ Branch 21 → 22 taken 4 times.
✓ Branch 21 → 23 taken 21 times.
25 if (!strcmp(tag, tag1))
793 4 return 1;
794
2/2
✓ Branch 23 → 24 taken 3 times.
✓ Branch 23 → 25 taken 18 times.
21 if (*p != '&')
795 3 break;
796 18 p++;
797 }
798 3 return 0;
799 }
800