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