FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/utils.c
Date: 2024-07-26 21:54:09
Exec Total Coverage
Lines: 194 324 59.9%
Functions: 20 25 80.0%
Branches: 111 259 42.9%

Line Branch Exec Source
1 /*
2 * various utility functions for use within FFmpeg
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <stdint.h>
23
24 #include "config.h"
25
26 #include "libavutil/avstring.h"
27 #include "libavutil/bprint.h"
28 #include "libavutil/internal.h"
29 #include "libavutil/mem.h"
30 #include "libavutil/time.h"
31
32 #include "libavcodec/internal.h"
33
34 #include "avformat.h"
35 #include "avio_internal.h"
36 #include "internal.h"
37 #if CONFIG_NETWORK
38 #include "network.h"
39 #endif
40 #include "os_support.h"
41
42 /**
43 * @file
44 * various utility functions for use within FFmpeg
45 */
46
47 /* an arbitrarily chosen "sane" max packet size -- 50M */
48 #define SANE_CHUNK_SIZE (50000000)
49
50 /* Read the data in sane-sized chunks and append to pkt.
51 * Return the number of bytes read or an error. */
52 271193 static int append_packet_chunked(AVIOContext *s, AVPacket *pkt, int size)
53 {
54 271193 int orig_size = pkt->size;
55 int ret;
56
57 do {
58 271193 int prev_size = pkt->size;
59 int read_size;
60
61 /* When the caller requests a lot of data, limit it to the amount
62 * left in file or SANE_CHUNK_SIZE when it is not known. */
63 271193 read_size = size;
64
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 271193 times.
271193 if (read_size > SANE_CHUNK_SIZE/10) {
65 read_size = ffio_limit(s, read_size);
66 // If filesize/maxsize is unknown, limit to SANE_CHUNK_SIZE
67 if (ffiocontext(s)->maxsize < 0)
68 read_size = FFMIN(read_size, SANE_CHUNK_SIZE);
69 }
70
71 271193 ret = av_grow_packet(pkt, read_size);
72
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 271193 times.
271193 if (ret < 0)
73 break;
74
75 271193 ret = avio_read(s, pkt->data + prev_size, read_size);
76
2/2
✓ Branch 0 taken 894 times.
✓ Branch 1 taken 270299 times.
271193 if (ret != read_size) {
77 894 av_shrink_packet(pkt, prev_size + FFMAX(ret, 0));
78 894 break;
79 }
80
81 270299 size -= read_size;
82
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 270299 times.
270299 } while (size > 0);
83
2/2
✓ Branch 0 taken 849 times.
✓ Branch 1 taken 270344 times.
271193 if (size > 0)
84 849 pkt->flags |= AV_PKT_FLAG_CORRUPT;
85
86
2/2
✓ Branch 0 taken 2224 times.
✓ Branch 1 taken 268969 times.
271193 if (!pkt->size)
87 2224 av_packet_unref(pkt);
88
2/2
✓ Branch 0 taken 268964 times.
✓ Branch 1 taken 2229 times.
271193 return pkt->size > orig_size ? pkt->size - orig_size : ret;
89 }
90
91 259687 int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
92 {
93 #if FF_API_INIT_PACKET
94 FF_DISABLE_DEPRECATION_WARNINGS
95 259687 av_init_packet(pkt);
96 259687 pkt->data = NULL;
97 259687 pkt->size = 0;
98 FF_ENABLE_DEPRECATION_WARNINGS
99 #else
100 av_packet_unref(pkt);
101 #endif
102 259687 pkt->pos = avio_tell(s);
103
104 259687 return append_packet_chunked(s, pkt, size);
105 }
106
107 12096 int av_append_packet(AVIOContext *s, AVPacket *pkt, int size)
108 {
109
2/2
✓ Branch 0 taken 590 times.
✓ Branch 1 taken 11506 times.
12096 if (!pkt->size)
110 590 return av_get_packet(s, pkt, size);
111 11506 return append_packet_chunked(s, pkt, size);
112 }
113
114 995 int av_filename_number_test(const char *filename)
115 {
116 char buf[1024];
117
3/4
✓ Branch 0 taken 995 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 300 times.
✓ Branch 3 taken 695 times.
1990 return filename &&
118 995 (av_get_frame_filename(buf, sizeof(buf), filename, 1) >= 0);
119 }
120
121 /**********************************************************/
122
123 1125 unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id)
124 {
125
2/2
✓ Branch 0 taken 7769 times.
✓ Branch 1 taken 2 times.
7771 while (tags->id != AV_CODEC_ID_NONE) {
126
2/2
✓ Branch 0 taken 1123 times.
✓ Branch 1 taken 6646 times.
7769 if (tags->id == id)
127 1123 return tags->tag;
128 6646 tags++;
129 }
130 2 return 0;
131 }
132
133 2908 enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
134 {
135
2/2
✓ Branch 0 taken 246603 times.
✓ Branch 1 taken 837 times.
247440 for (int i = 0; tags[i].id != AV_CODEC_ID_NONE; i++)
136
2/2
✓ Branch 0 taken 2071 times.
✓ Branch 1 taken 244532 times.
246603 if (tag == tags[i].tag)
137 2071 return tags[i].id;
138
2/2
✓ Branch 0 taken 74503 times.
✓ Branch 1 taken 832 times.
75335 for (int i = 0; tags[i].id != AV_CODEC_ID_NONE; i++)
139
2/2
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 74498 times.
74503 if (ff_toupper4(tag) == ff_toupper4(tags[i].tag))
140 5 return tags[i].id;
141 832 return AV_CODEC_ID_NONE;
142 }
143
144 549 enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int be, int sflags)
145 {
146
2/4
✓ Branch 0 taken 549 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 549 times.
549 if (bps <= 0 || bps > 64)
147 return AV_CODEC_ID_NONE;
148
149
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 545 times.
549 if (flt) {
150
2/3
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 switch (bps) {
151 2 case 32:
152
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 return be ? AV_CODEC_ID_PCM_F32BE : AV_CODEC_ID_PCM_F32LE;
153 2 case 64:
154
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 return be ? AV_CODEC_ID_PCM_F64BE : AV_CODEC_ID_PCM_F64LE;
155 default:
156 return AV_CODEC_ID_NONE;
157 }
158 } else {
159 545 bps += 7;
160 545 bps >>= 3;
161
2/2
✓ Branch 0 taken 527 times.
✓ Branch 1 taken 18 times.
545 if (sflags & (1 << (bps - 1))) {
162
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 512 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
527 switch (bps) {
163 case 1:
164 return AV_CODEC_ID_PCM_S8;
165 512 case 2:
166
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 510 times.
512 return be ? AV_CODEC_ID_PCM_S16BE : AV_CODEC_ID_PCM_S16LE;
167 12 case 3:
168
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 11 times.
12 return be ? AV_CODEC_ID_PCM_S24BE : AV_CODEC_ID_PCM_S24LE;
169 3 case 4:
170
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 return be ? AV_CODEC_ID_PCM_S32BE : AV_CODEC_ID_PCM_S32LE;
171 case 8:
172 return be ? AV_CODEC_ID_PCM_S64BE : AV_CODEC_ID_PCM_S64LE;
173 default:
174 return AV_CODEC_ID_NONE;
175 }
176 } else {
177
1/5
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
18 switch (bps) {
178 18 case 1:
179 18 return AV_CODEC_ID_PCM_U8;
180 case 2:
181 return be ? AV_CODEC_ID_PCM_U16BE : AV_CODEC_ID_PCM_U16LE;
182 case 3:
183 return be ? AV_CODEC_ID_PCM_U24BE : AV_CODEC_ID_PCM_U24LE;
184 case 4:
185 return be ? AV_CODEC_ID_PCM_U32BE : AV_CODEC_ID_PCM_U32LE;
186 default:
187 return AV_CODEC_ID_NONE;
188 }
189 }
190 }
191 }
192
193 5442 unsigned int av_codec_get_tag(const AVCodecTag *const *tags, enum AVCodecID id)
194 {
195 unsigned int tag;
196
2/2
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 5430 times.
5442 if (!av_codec_get_tag2(tags, id, &tag))
197 12 return 0;
198 5430 return tag;
199 }
200
201 8395 int av_codec_get_tag2(const AVCodecTag * const *tags, enum AVCodecID id,
202 unsigned int *tag)
203 {
204
3/4
✓ Branch 0 taken 15726 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15699 times.
✓ Branch 3 taken 27 times.
15726 for (int i = 0; tags && tags[i]; i++) {
205 15699 const AVCodecTag *codec_tags = tags[i];
206
2/2
✓ Branch 0 taken 663829 times.
✓ Branch 1 taken 7331 times.
671160 while (codec_tags->id != AV_CODEC_ID_NONE) {
207
2/2
✓ Branch 0 taken 8368 times.
✓ Branch 1 taken 655461 times.
663829 if (codec_tags->id == id) {
208 8368 *tag = codec_tags->tag;
209 8368 return 1;
210 }
211 655461 codec_tags++;
212 }
213 }
214 27 return 0;
215 }
216
217 174 enum AVCodecID av_codec_get_id(const AVCodecTag *const *tags, unsigned int tag)
218 {
219
3/4
✓ Branch 0 taken 315 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256 times.
✓ Branch 3 taken 59 times.
315 for (int i = 0; tags && tags[i]; i++) {
220 256 enum AVCodecID id = ff_codec_get_id(tags[i], tag);
221
2/2
✓ Branch 0 taken 115 times.
✓ Branch 1 taken 141 times.
256 if (id != AV_CODEC_ID_NONE)
222 115 return id;
223 }
224 59 return AV_CODEC_ID_NONE;
225 }
226
227 862 int ff_alloc_extradata(AVCodecParameters *par, int size)
228 {
229 862 av_freep(&par->extradata);
230 862 par->extradata_size = 0;
231
232
2/4
✓ Branch 0 taken 862 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 862 times.
862 if (size < 0 || size >= INT32_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
233 return AVERROR(EINVAL);
234
235 862 par->extradata = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE);
236
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 862 times.
862 if (!par->extradata)
237 return AVERROR(ENOMEM);
238
239 862 memset(par->extradata + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
240 862 par->extradata_size = size;
241
242 862 return 0;
243 }
244
245 /*******************************************************/
246
247 37 uint64_t ff_ntp_time(void)
248 {
249 37 return (av_gettime() / 1000) * 1000 + NTP_OFFSET_US;
250 }
251
252 uint64_t ff_get_formatted_ntp_time(uint64_t ntp_time_us)
253 {
254 uint64_t ntp_ts, frac_part, sec;
255 uint32_t usec;
256
257 //current ntp time in seconds and micro seconds
258 sec = ntp_time_us / 1000000;
259 usec = ntp_time_us % 1000000;
260
261 //encoding in ntp timestamp format
262 frac_part = usec * 0xFFFFFFFFULL;
263 frac_part /= 1000000;
264
265 if (sec > 0xFFFFFFFFULL)
266 av_log(NULL, AV_LOG_WARNING, "NTP time format roll over detected\n");
267
268 ntp_ts = sec << 32;
269 ntp_ts |= frac_part;
270
271 return ntp_ts;
272 }
273
274 uint64_t ff_parse_ntp_time(uint64_t ntp_ts)
275 {
276 uint64_t sec = ntp_ts >> 32;
277 uint64_t frac_part = ntp_ts & 0xFFFFFFFFULL;
278 uint64_t usec = (frac_part * 1000000) / 0xFFFFFFFFULL;
279
280 return (sec * 1000000) + usec;
281 }
282
283 136120 int av_get_frame_filename2(char *buf, int buf_size, const char *path, int number, int flags)
284 {
285 const char *p;
286 char *q, buf1[20], c;
287 int nd, len, percentd_found;
288
289 136120 q = buf;
290 136120 p = path;
291 136120 percentd_found = 0;
292 for (;;) {
293 10378859 c = *p++;
294
2/2
✓ Branch 0 taken 136120 times.
✓ Branch 1 taken 10242739 times.
10378859 if (c == '\0')
295 136120 break;
296
2/2
✓ Branch 0 taken 135410 times.
✓ Branch 1 taken 10107329 times.
10242739 if (c == '%') {
297 do {
298 135410 nd = 0;
299
2/2
✓ Branch 0 taken 270708 times.
✓ Branch 1 taken 135410 times.
406118 while (av_isdigit(*p)) {
300
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 270708 times.
270708 if (nd >= INT_MAX / 10 - 255)
301 goto fail;
302 270708 nd = nd * 10 + *p++ - '0';
303 }
304 135410 c = *p++;
305
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 135410 times.
135410 } while (av_isdigit(c));
306
307
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 135410 times.
✗ Branch 2 not taken.
135410 switch (c) {
308 case '%':
309 goto addchar;
310 135410 case 'd':
311
3/4
✓ Branch 0 taken 134747 times.
✓ Branch 1 taken 663 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 134747 times.
135410 if (!(flags & AV_FRAME_FILENAME_FLAGS_MULTIPLE) && percentd_found)
312 goto fail;
313 135410 percentd_found = 1;
314
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 135410 times.
135410 if (number < 0)
315 nd += 1;
316 135410 snprintf(buf1, sizeof(buf1), "%0*d", nd, number);
317 135410 len = strlen(buf1);
318
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 135410 times.
135410 if ((q - buf + len) > buf_size - 1)
319 goto fail;
320 135410 memcpy(q, buf1, len);
321 135410 q += len;
322 135410 break;
323 default:
324 goto fail;
325 }
326 } else {
327 10107329 addchar:
328
1/2
✓ Branch 0 taken 10107329 times.
✗ Branch 1 not taken.
10107329 if ((q - buf) < buf_size - 1)
329 10107329 *q++ = c;
330 }
331 }
332
2/2
✓ Branch 0 taken 710 times.
✓ Branch 1 taken 135410 times.
136120 if (!percentd_found)
333 710 goto fail;
334 135410 *q = '\0';
335 135410 return 0;
336 710 fail:
337 710 *q = '\0';
338 710 return -1;
339 }
340
341 135450 int av_get_frame_filename(char *buf, int buf_size, const char *path, int number)
342 {
343 135450 return av_get_frame_filename2(buf, buf_size, path, number, 0);
344 }
345
346 9 void av_url_split(char *proto, int proto_size,
347 char *authorization, int authorization_size,
348 char *hostname, int hostname_size,
349 int *port_ptr, char *path, int path_size, const char *url)
350 {
351 const char *p, *ls, *at, *at2, *col, *brk;
352
353
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (port_ptr)
354 9 *port_ptr = -1;
355
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (proto_size > 0)
356 9 proto[0] = 0;
357
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (authorization_size > 0)
358 9 authorization[0] = 0;
359
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (hostname_size > 0)
360 9 hostname[0] = 0;
361
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (path_size > 0)
362 9 path[0] = 0;
363
364 /* parse protocol */
365
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
9 if ((p = strchr(url, ':'))) {
366 8 av_strlcpy(proto, url, FFMIN(proto_size, p + 1 - url));
367 8 p++; /* skip ':' */
368
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (*p == '/')
369 8 p++;
370
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (*p == '/')
371 8 p++;
372 } else {
373 /* no protocol means plain filename */
374 1 av_strlcpy(path, url, path_size);
375 1 return;
376 }
377
378 /* separate path from hostname */
379 8 ls = p + strcspn(p, "/?#");
380 8 av_strlcpy(path, ls, path_size);
381
382 /* the rest is hostname, use that to parse auth/port */
383
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (ls != p) {
384 /* authorization (user[:pass]@hostname) */
385 8 at2 = p;
386
4/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 1 times.
10 while ((at = strchr(p, '@')) && at < ls) {
387 2 av_strlcpy(authorization, at2,
388 2 FFMIN(authorization_size, at + 1 - at2));
389 2 p = at + 1; /* skip '@' */
390 }
391
392
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
8 if (*p == '[' && (brk = strchr(p, ']')) && brk < ls) {
393 /* [host]:port */
394 av_strlcpy(hostname, p + 1,
395 FFMIN(hostname_size, brk - p));
396 if (brk[1] == ':' && port_ptr)
397 *port_ptr = atoi(brk + 2);
398
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
8 } else if ((col = strchr(p, ':')) && col < ls) {
399 1 av_strlcpy(hostname, p,
400 1 FFMIN(col + 1 - p, hostname_size));
401
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (port_ptr)
402 1 *port_ptr = atoi(col + 1);
403 } else
404 7 av_strlcpy(hostname, p,
405 7 FFMIN(ls + 1 - p, hostname_size));
406 }
407 }
408
409 int ff_mkdir_p(const char *path)
410 {
411 int ret = 0;
412 char *temp = av_strdup(path);
413 char *pos = temp;
414 char tmp_ch = '\0';
415
416 if (!path || !temp) {
417 return -1;
418 }
419
420 if (!av_strncasecmp(temp, "/", 1) || !av_strncasecmp(temp, "\\", 1)) {
421 pos++;
422 } else if (!av_strncasecmp(temp, "./", 2) || !av_strncasecmp(temp, ".\\", 2)) {
423 pos += 2;
424 }
425
426 for ( ; *pos != '\0'; ++pos) {
427 if (*pos == '/' || *pos == '\\') {
428 tmp_ch = *pos;
429 *pos = '\0';
430 ret = mkdir(temp, 0755);
431 *pos = tmp_ch;
432 }
433 }
434
435 if ((*(pos - 1) != '/') && (*(pos - 1) != '\\')) {
436 ret = mkdir(temp, 0755);
437 }
438
439 av_free(temp);
440 return ret;
441 }
442
443 3091 char *ff_data_to_hex(char *buff, const uint8_t *src, int s, int lowercase)
444 {
445 static const char hex_table_uc[16] = { '0', '1', '2', '3',
446 '4', '5', '6', '7',
447 '8', '9', 'A', 'B',
448 'C', 'D', 'E', 'F' };
449 static const char hex_table_lc[16] = { '0', '1', '2', '3',
450 '4', '5', '6', '7',
451 '8', '9', 'a', 'b',
452 'c', 'd', 'e', 'f' };
453
2/2
✓ Branch 0 taken 2394 times.
✓ Branch 1 taken 697 times.
3091 const char *hex_table = lowercase ? hex_table_lc : hex_table_uc;
454
455
2/2
✓ Branch 0 taken 49470 times.
✓ Branch 1 taken 3091 times.
52561 for (int i = 0; i < s; i++) {
456 49470 buff[i * 2] = hex_table[src[i] >> 4];
457 49470 buff[i * 2 + 1] = hex_table[src[i] & 0xF];
458 }
459 3091 buff[2 * s] = '\0';
460
461 3091 return buff;
462 }
463
464 int ff_hex_to_data(uint8_t *data, const char *p)
465 {
466 int c, len, v;
467
468 len = 0;
469 v = 1;
470 for (;;) {
471 p += strspn(p, SPACE_CHARS);
472 if (*p == '\0')
473 break;
474 c = av_toupper((unsigned char) *p++);
475 if (c >= '0' && c <= '9')
476 c = c - '0';
477 else if (c >= 'A' && c <= 'F')
478 c = c - 'A' + 10;
479 else
480 break;
481 v = (v << 4) | c;
482 if (v & 0x100) {
483 if (data)
484 data[len] = v;
485 len++;
486 v = 1;
487 }
488 }
489 return len;
490 }
491
492 void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf,
493 void *context)
494 {
495 const char *ptr = str;
496
497 /* Parse key=value pairs. */
498 for (;;) {
499 const char *key;
500 char *dest = NULL, *dest_end;
501 int key_len, dest_len = 0;
502
503 /* Skip whitespace and potential commas. */
504 while (*ptr && (av_isspace(*ptr) || *ptr == ','))
505 ptr++;
506 if (!*ptr)
507 break;
508
509 key = ptr;
510
511 if (!(ptr = strchr(key, '=')))
512 break;
513 ptr++;
514 key_len = ptr - key;
515
516 callback_get_buf(context, key, key_len, &dest, &dest_len);
517 dest_end = dest ? dest + dest_len - 1 : NULL;
518
519 if (*ptr == '\"') {
520 ptr++;
521 while (*ptr && *ptr != '\"') {
522 if (*ptr == '\\') {
523 if (!ptr[1])
524 break;
525 if (dest && dest < dest_end)
526 *dest++ = ptr[1];
527 ptr += 2;
528 } else {
529 if (dest && dest < dest_end)
530 *dest++ = *ptr;
531 ptr++;
532 }
533 }
534 if (*ptr == '\"')
535 ptr++;
536 } else {
537 for (; *ptr && !(av_isspace(*ptr) || *ptr == ','); ptr++)
538 if (dest && dest < dest_end)
539 *dest++ = *ptr;
540 }
541 if (dest)
542 *dest = 0;
543 }
544 }
545
546 6929 int avformat_network_init(void)
547 {
548 #if CONFIG_NETWORK
549 int ret;
550
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6929 times.
6929 if ((ret = ff_network_init()) < 0)
551 return ret;
552
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 6929 times.
6929 if ((ret = ff_tls_init()) < 0)
553 return ret;
554 #endif
555 6929 return 0;
556 }
557
558 6929 int avformat_network_deinit(void)
559 {
560 #if CONFIG_NETWORK
561 6929 ff_network_close();
562 6929 ff_tls_deinit();
563 #endif
564 6929 return 0;
565 }
566
567 366 int ff_is_http_proto(const char *filename) {
568 366 const char *proto = avio_find_protocol_name(filename);
569
3/6
✓ Branch 0 taken 366 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 366 times.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 366 times.
366 return proto ? (!av_strcasecmp(proto, "http") || !av_strcasecmp(proto, "https")) : 0;
570 }
571
572 9 int ff_bprint_to_codecpar_extradata(AVCodecParameters *par, struct AVBPrint *buf)
573 {
574 int ret;
575 char *str;
576
577 9 ret = av_bprint_finalize(buf, &str);
578
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (ret < 0)
579 return ret;
580
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
9 if (!av_bprint_is_complete(buf)) {
581 av_free(str);
582 return AVERROR(ENOMEM);
583 }
584
585 9 par->extradata = str;
586 /* Note: the string is NUL terminated (so extradata can be read as a
587 * string), but the ending character is not accounted in the size (in
588 * binary formats you are likely not supposed to mux that character). When
589 * extradata is copied, it is also padded with AV_INPUT_BUFFER_PADDING_SIZE
590 * zeros. */
591 9 par->extradata_size = buf->len;
592 9 return 0;
593 }
594