FFmpeg: libavformat/avio.c Source File
Go to the documentation of this file. 1 /*
2 * unbuffered I/O
3 * Copyright (c) 2001 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
30 #if CONFIG_NETWORK
32 #endif
34
35 /** @name Logging context. */
36 /*@{*/
38 {
42 else
43 return "NULL";
44 }
45
47 {
49 if (!prev &&
h->priv_data &&
h->prot->priv_data_class)
52 }
53
54 #define OFFSET(x) offsetof(URLContext,x)
55 #define E AV_OPT_FLAG_ENCODING_PARAM
56 #define D AV_OPT_FLAG_DECODING_PARAM
58 {
"protocol_whitelist",
"List of protocols that are allowed to be used",
OFFSET(protocol_whitelist),
AV_OPT_TYPE_STRING, { .str =
NULL }, 0, 0,
D },
59 {
"protocol_blacklist",
"List of protocols that are not allowed to be used",
OFFSET(protocol_blacklist),
AV_OPT_TYPE_STRING, { .str =
NULL }, 0, 0,
D },
62 };
63
71 };
72 /*@}*/
73
75 const char *filename,
int flags,
77 {
79 int err;
80
81 #if CONFIG_NETWORK
84 #endif
87 "Impossible to open the '%s' protocol for reading\n", up->
name);
89 }
92 "Impossible to open the '%s' protocol for writing\n", up->
name);
94 }
96 if (!uc) {
99 }
112 }
114 char *start;
119 char *p= start;
120 char sep= *++p;
122 p++;
123
124 if (strcmp(up->
name,
"subfile"))
126
127 while(
ret >= 0 && (
key= strchr(p, sep)) && p<
key && (
val = strchr(
key+1, sep))){
129 if (strcmp(p, "start") && strcmp(p, "end")) {
131 } else
137 }
144 }
145 memmove(start,
key+1, strlen(
key));
146 }
147 }
148 }
151
152 *puc = uc;
153 return 0;
156 if (uc)
159 #if CONFIG_NETWORK
162 #endif
163 return err;
164 }
165
167 {
168 int err;
171
174
175 // Check that URLContext was initialized correctly and lists are matching if set
180
184 }
185
189 }
190
196 }
198 av_log(uc,
AV_LOG_DEBUG,
"No default whitelist set\n");
// This should be an error once all declare a default whitelist
199
201 return err;
203 return err;
204
205 err =
211
214
215 if (err)
216 return err;
218 /* We must be careful here as ffurl_seek() could be slow,
219 * for example for http */
223 return 0;
224 }
225
227 {
229 if (
s->prot->url_accept)
230 return s->prot->url_accept(
s,
c);
232 }
233
235 {
237 if (
c->prot->url_handshake) {
238 ret =
c->prot->url_handshake(
c);
241 }
243 return 0;
244 }
245
246 #define URL_SCHEME_CHARS \
247 "abcdefghijklmnopqrstuvwxyz" \
248 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
249 "0123456789+-."
250
252 {
254 char proto_str[128], proto_nested[128], *ptr;
257
258 if (filename[proto_len] != ':' &&
259 (strncmp(filename, "subfile,", 8) || !strchr(filename + proto_len + 1, ':')) ||
261 strcpy(proto_str, "file");
262 else
264 FFMIN(proto_len + 1,
sizeof(proto_str)));
265
266 av_strlcpy(proto_nested, proto_str,
sizeof(proto_nested));
267 if ((ptr = strchr(proto_nested, '+')))
268 *ptr = '0円';
269
271 if (!protocols)
273 for (
i = 0; protocols[
i];
i++) {
275 if (!strcmp(proto_str, up->
name)) {
277 return up;
278 }
280 !strcmp(proto_nested, up->
name)) {
282 return up;
283 }
284 }
288 "openssl, gnutls or securetransport enabled.\n");
289
291 }
292
295 {
297
299 if (p)
301
304 }
305
308 const char *whitelist, const char* blacklist,
310 {
316 if (parent) {
320 }
324 if (
options && (*puc)->prot->priv_data_class &&
327
330
333 !strcmp(whitelist, e->
value));
336 !strcmp(blacklist, e->
value));
337
340
343
346
348
350 return 0;
354 }
355
357 int size,
int size_min,
359 uint8_t *buf,
361 {
363 int fast_retries = 5;
364 int64_t wait_since = 0;
365
367 while (
len < size_min) {
372 continue;
377 if (fast_retries) {
378 fast_retries--;
379 } else {
381 if (!wait_since)
385 }
387 }
393 fast_retries =
FFMAX(fast_retries, 2);
394 wait_since = 0;
395 }
397 }
399 }
400
402 {
406 }
407
409 {
413 }
414
416 {
419 /* avoid sending too big packets */
420 if (
h->max_packet_size &&
size >
h->max_packet_size)
422
424 (
int (*)(
struct URLContext *, uint8_t *,
int))
426 }
427
429 {
431
432 if (!
h->prot->url_seek)
436 }
437
439 {
443 return 0; /* can happen when ffurl_open fails */
444
445 if (
h->is_connected &&
h->prot->url_close)
446 ret =
h->prot->url_close(
h);
447 #if CONFIG_NETWORK
450 #endif
451 if (
h->prot->priv_data_size) {
452 if (
h->prot->priv_data_class)
455 }
459 }
460
462 {
464 }
465
466
468 {
470
472 }
473
475 {
480
481 if (
h->prot->url_check) {
483 } else {
487 }
488
491 }
492
494 {
503 }
504
507 else
509
513 }
514
516 {
521
522 if (
h->prot->url_delete)
523 ret =
h->prot->url_delete(
h);
524 else
526
529 }
530
532 {
537
542 }
543
546
547 if (
h->prot->url_open_dir &&
h->prot->url_read_dir &&
h->prot->url_close_dir) {
548 if (
options &&
h->prot->priv_data_class &&
551 ret =
h->prot->url_open_dir(
h);
552 } else
556
558 ctx->url_context =
h;
560 return 0;
561
567 }
568
570 {
573
574 if (!
s || !
s->url_context)
577 if ((
ret =
h->prot->url_read_dir(
h, next)) < 0)
580 }
581
583 {
585
587 if (!(*
s) || !(*s)->url_context)
589 h = (*s)->url_context;
590 h->prot->url_close_dir(
h);
594 return 0;
595 }
596
598 {
599 if (!entry || !*entry)
600 return;
603 }
604
606 {
608
616 }
618 }
619
621 {
622 if (!
h || !
h->prot || !
h->prot->url_get_file_handle)
623 return -1;
624 return h->prot->url_get_file_handle(
h);
625 }
626
628 {
631 if (!
h->prot->url_get_multi_file_handle) {
632 if (!
h->prot->url_get_file_handle)
635 if (!*handles)
637 *numhandles = 1;
638 *handles[0] =
h->prot->url_get_file_handle(
h);
639 return 0;
640 }
641 return h->prot->url_get_multi_file_handle(
h, handles, numhandles);
642 }
643
645 {
646 if (!
h || !
h->prot || !
h->prot->url_get_short_seek)
648 return h->prot->url_get_short_seek(
h);
649 }
650
652 {
653 if (!
h || !
h->prot || !
h->prot->url_shutdown)
655 return h->prot->url_shutdown(
h,
flags);
656 }
657
659 {
660 if (
cb &&
cb->callback)
661 return cb->callback(
cb->opaque);
662 return 0;
663 }
664
665 int ff_rename(
const char *url_src,
const char *url_dst,
void *logctx)
666 {
671 }
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
#define AV_LOG_WARNING
Something somehow does not look correct.
const AVClass ffurl_context_class
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
char * filename
specified URL
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
#define URL_PROTOCOL_FLAG_NETWORK
int(* url_read)(URLContext *h, unsigned char *buf, int size)
Read data from the protocol.
static double cb(void *priv, double x, double y)
int64_t ffurl_seek(URLContext *h, int64_t pos, int whence)
Change the position that will be used by the next read/write operation on the resource accessed by h.
#define AVERROR_EOF
End of file.
#define AVIO_FLAG_READ_WRITE
read-write pseudo flag
int max_packet_size
if non zero, the stream is packetized with this max packet size
#define AVSEEK_SIZE
ORing this as the "whence" parameter to a seek function causes it to return the filesize without seek...
int ffurl_close(URLContext *h)
static const char * urlcontext_to_name(void *ptr)
void ff_network_close(void)
int ff_network_init(void)
Callback for checking whether to abort blocking functions.
const AVClass * ff_urlcontext_child_class_iterate(void **iter)
int ffurl_connect(URLContext *uc, AVDictionary **options)
Connect an URLContext that has been allocated by ffurl_alloc.
#define AVERROR_OPTION_NOT_FOUND
Option not found.
static double val(void *priv, double ch)
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrupt a blocking function associated with cb.
int ff_rename(const char *url_src, const char *url_dst, void *logctx)
Wrap ffurl_move() and log if error happens.
int(* url_open)(URLContext *h, const char *url, int flags)
void avio_free_directory_entry(AVIODirEntry **entry)
Free entry allocated by avio_read_dir().
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int url_alloc_for_protocol(URLContext **puc, const URLProtocol *up, const char *filename, int flags, const AVIOInterruptCB *int_cb)
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
int ffurl_open_whitelist(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char *blacklist, URLContext *parent)
Create an URLContext for accessing to the resource indicated by url, and open it.
static int retry_transfer_wrapper(URLContext *h, uint8_t *buf, int size, int size_min, int(*transfer_func)(URLContext *h, uint8_t *buf, int size))
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
static int is_dos_path(const char *path)
int avio_close_dir(AVIODirContext **s)
Close directory.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define AVIO_FLAG_WRITE
write-only
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int av_usleep(unsigned usec)
Sleep for a period of time.
int ffurl_accept(URLContext *s, URLContext **c)
Accept an URLContext c on an URLContext s.
#define LIBAVUTIL_VERSION_INT
const URLProtocol ** ffurl_get_protocols(const char *whitelist, const char *blacklist)
Construct a list of protocols matching a given whitelist and/or blacklist.
Describe the class of an AVClass context structure.
const char * protocol_whitelist
static void * urlcontext_child_next(void *obj, void *prev)
int av_match_list(const char *name, const char *list, char separator)
Check if a name is in a list.
const char * protocol_blacklist
int ffurl_move(const char *url_src, const char *url_dst)
Move or rename a resource.
int ffurl_shutdown(URLContext *h, int flags)
Signal the URLContext that we are done reading or writing the stream.
void av_opt_free(void *obj)
Free all allocated objects in obj.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
int avio_read_dir(AVIODirContext *s, AVIODirEntry **next)
Get next directory entry.
int ffurl_get_multi_file_handle(URLContext *h, int **handles, int *numhandles)
Return the file descriptors associated with this URL.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
const AVClass * priv_data_class
#define URL_PROTOCOL_FLAG_NESTED_SCHEME
Describes single entry of the directory.
const char * default_whitelist
int avio_check(const char *url, int flags)
Return AVIO_FLAG_* access flags corresponding to the access permissions of the resource in url,...
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
int ffurl_get_short_seek(URLContext *h)
Return the current short seek threshold value for this URL.
int ffurl_alloc(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb)
Create a URLContext for accessing to the resource indicated by url, but do not initiate the connectio...
#define i(width, name, range_min, range_max)
const struct URLProtocol * prot
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
int avio_open_dir(AVIODirContext **s, const char *url, AVDictionary **options)
Open directory for reading.
const AVIOInterruptCB int_cb
int ffurl_closep(URLContext **hh)
Close the resource accessed by the URLContext h, and free the memory used by it.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
AVIOInterruptCB interrupt_callback
int(* url_move)(URLContext *h_src, URLContext *h_dst)
static const AVOption options[]
static const struct URLProtocol * url_find_protocol(const char *filename)
int ffurl_read(URLContext *h, unsigned char *buf, int size)
Read up to size bytes from the resource accessed by h, and store the read bytes in buf.
const AVClass * av_class
information for av_log().
int ffurl_write(URLContext *h, const unsigned char *buf, int size)
Write size bytes from buf to the resource accessed by h.
#define AVSEEK_FORCE
Passing this flag as the "whence" parameter to a seek function causes it to seek by any means (like r...
int is_streamed
true if streamed (no seek possible), default = false
#define AVIO_FLAG_READ
read-only
char * av_strdup(const char *s)
Duplicate a string.
int ffurl_read_complete(URLContext *h, unsigned char *buf, int size)
Read as many bytes as possible (up to size), calling the read function multiple times if necessary.
int av_opt_copy(void *dst, const void *src)
Copy options from src object into dest object.
int ffurl_handshake(URLContext *c)
Perform one step of the protocol handshake to accept a new client.
#define AVIO_FLAG_NONBLOCK
Use non-blocking mode.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
int(* url_write)(URLContext *h, const unsigned char *buf, int size)
const char * avio_find_protocol_name(const char *url)
Return the name of the protocol that will handle the passed URL.
#define flags(name, subs,...)
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
int64_t ffurl_size(URLContext *h)
Return the filesize of the resource accessed by h, AVERROR(ENOSYS) if the operation is not supported ...
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
int ffurl_delete(const char *url)
Delete a resource.
#define AVERROR_PROTOCOL_NOT_FOUND
Protocol not found.
int ffurl_get_file_handle(URLContext *h)
Return the file descriptor associated with this URL.
int(* url_open2)(URLContext *h, const char *url, int flags, AVDictionary **options)
This callback is to be used by protocols which open further nested protocols.
Generated on Wed Aug 24 2022 21:38:20 for FFmpeg by
doxygen
1.8.17