Go to the documentation of this file.
22 #include "config_components.h"
40 #define IO_BUFFER_SIZE 32768
56 if (!prev &&
h->priv_data &&
h->prot->priv_data_class)
61 #define OFFSET(x) offsetof(URLContext,x)
62 #define E AV_OPT_FLAG_ENCODING_PARAM
63 #define D AV_OPT_FLAG_DECODING_PARAM
65 {
"protocol_whitelist",
"List of protocols that are allowed to be used",
OFFSET(protocol_whitelist),
AV_OPT_TYPE_STRING, { .str =
NULL }, 0, 0,
D },
66 {
"protocol_blacklist",
"List of protocols that are not allowed to be used",
OFFSET(protocol_blacklist),
AV_OPT_TYPE_STRING, { .str =
NULL }, 0, 0,
D },
68 {
"prefer_libcurl",
"use the libcurl protocol for http(s) URLs when available",
OFFSET(prefer_libcurl),
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1,
D },
85 return prev ?
NULL :
s->opaque;
91 *iter = (
void*)(uintptr_t)
c;
95 #define AVIOOFFSET(x) offsetof(AVIOContext,x)
96 #define E AV_OPT_FLAG_ENCODING_PARAM
97 #define D AV_OPT_FLAG_DECODING_PARAM
124 const char *filename,
int flags,
136 "Impossible to open the '%s' protocol for reading\n", up->
name);
141 "Impossible to open the '%s' protocol for writing\n", up->
name);
173 if (strcmp(up->
name,
"subfile"))
189 memmove(start,
key+1, strlen(
key));
278 if (
s->prot->url_accept)
279 return s->prot->url_accept(
s,
c);
297 if (
c->prot->url_handshake) {
298 ret =
c->prot->url_handshake(
c);
312 #define URL_SCHEME_CHARS \
313 "abcdefghijklmnopqrstuvwxyz" \
314 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
320 char proto_str[128], proto_nested[128], *ptr;
324 if (filename[proto_len] !=
':' &&
325 (strncmp(filename,
"subfile,", 8) || !strchr(filename + proto_len + 1,
':')) ||
327 strcpy(proto_str,
"file");
330 FFMIN(proto_len + 1,
sizeof(proto_str)));
332 av_strlcpy(proto_nested, proto_str,
sizeof(proto_nested));
333 if ((ptr = strchr(proto_nested,
'+')))
339 for (
i = 0; protocols[
i];
i++) {
341 if (!strcmp(proto_str, up->
name)) {
346 !strcmp(proto_nested, up->
name)) {
355 "openssl, gnutls or securetransport enabled.\n");
373 #if CONFIG_LIBCURL_PROTOCOL
396 return dummy.prefer_libcurl;
402 const char *whitelist,
const char* blacklist,
409 #if CONFIG_LIBCURL_PROTOCOL
412 if (prefer_libcurl(filename,
options, parent))
429 if (
options && (*puc)->prot->priv_data_class &&
438 !strcmp(whitelist, e->
value));
441 !strcmp(blacklist, e->
value));
463 const char *whitelist,
const char* blacklist,
467 whitelist, blacklist, parent,
NULL);
474 int buffer_size, max_packet_size;
476 max_packet_size =
h->max_packet_size;
477 if (max_packet_size) {
478 buffer_size = max_packet_size;
483 if (buffer_size > INT_MAX/2)
498 if (
h->protocol_whitelist) {
499 s->protocol_whitelist =
av_strdup(
h->protocol_whitelist);
500 if (!
s->protocol_whitelist) {
505 if (
h->protocol_blacklist) {
506 s->protocol_blacklist =
av_strdup(
h->protocol_blacklist);
507 if (!
s->protocol_blacklist) {
515 s->max_packet_size = max_packet_size;
516 s->min_packet_size =
h->min_packet_size;
518 s->read_pause =
h->prot->url_read_pause;
519 s->read_seek =
h->prot->url_read_seek;
521 if (
h->prot->url_read_seek)
531 const char *whitelist,
const char *blacklist,
540 blacklist,
NULL, avfc);
553 const char *whitelist,
const char *blacklist)
556 whitelist, blacklist,
NULL);
573 int size,
int size_min,
577 int fast_retries = 5;
581 while (
len < size_min) {
608 fast_retries =
FFMAX(fast_retries, 2);
639 if (
h->max_packet_size &&
size >
h->max_packet_size)
650 if (!
h->prot->url_seek)
663 if (
h->is_connected &&
h->prot->url_close)
664 ret =
h->prot->url_close(
h);
669 if (
h->prot->priv_data_size) {
670 if (
h->prot->priv_data_class)
700 "Statistics: %"PRId64
" bytes written, %d seeks, %d writeouts\n",
701 ctx->bytes_written,
ctx->seek_count,
ctx->writeout_count);
704 ctx->bytes_read,
ctx->seek_count);
729 return p ?
p->name :
NULL;
739 if (
h->prot->url_check) {
780 if (
h->prot->url_delete)
781 ret =
h->prot->url_delete(
h);
809 if (
h->prot->url_open_dir &&
h->prot->url_read_dir &&
h->prot->url_close_dir) {
810 if (
options &&
h->prot->priv_data_class &&
813 ret =
h->prot->url_open_dir(
h);
820 ctx->url_context =
h;
836 if (!
s || !
s->url_context)
839 if ((
ret =
h->prot->url_read_dir(
h, next)) < 0)
849 if (!(*
s) || !(*s)->url_context)
851 h = (*s)->url_context;
852 h->prot->url_close_dir(
h);
884 if (!
h || !
h->prot || !
h->prot->url_get_file_handle)
886 return h->prot->url_get_file_handle(
h);
893 if (!
h->prot->url_get_multi_file_handle) {
894 if (!
h->prot->url_get_file_handle)
900 *handles[0] =
h->prot->url_get_file_handle(
h);
903 return h->prot->url_get_multi_file_handle(
h, handles, numhandles);
910 if (!
h || !
h->prot || !
h->prot->url_get_short_seek)
912 return h->prot->url_get_short_seek(
h);
917 if (!
h || !
h->prot || !
h->prot->url_shutdown)
919 return h->prot->url_shutdown(
h,
flags);
924 if (
cb &&
cb->callback)
925 return cb->callback(
cb->opaque);
929 int ff_rename(
const char *url_src,
const char *url_dst,
void *logctx)
static void error(const char *err)
static 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.
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
int ffio_open_whitelist(AVIOContext **s, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char *blacklist)
#define AV_LOG_WARNING
Something somehow does not look correct.
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
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
#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)
int prefer_libcurl
route http(s) opens through the libcurl protocol
static av_always_inline FFIOContext * ffiocontext(AVIOContext *ctx)
int avio_accept(AVIOContext *s, AVIOContext **c)
Accept and allocate a client context on a server context.
#define AVERROR_EOF
End of file.
#define AVIO_FLAG_READ_WRITE
read-write pseudo flag
void avio_context_free(AVIOContext **s)
Free the supplied IO context and everything associated with it.
int avio_handshake(AVIOContext *c)
Perform one step of the protocol handshake to accept a new client.
static const AVOption urlcontext_options[]
int max_packet_size
if non zero, the stream is packetized with this max packet size
AVIOContext * avio_alloc_context(unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, const uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
Allocate and initialize an AVIOContext for buffered I/O.
#define AVSEEK_SIZE
Passing this as the "whence" parameter to a seek function causes it to return the filesize without se...
int avio_open(AVIOContext **s, const char *filename, int flags)
Create and initialize a AVIOContext for accessing the resource indicated by url.
#define AV_LOG_VERBOSE
Detailed information.
int ffurl_close(URLContext *h)
static const char * urlcontext_to_name(void *ptr)
void ff_network_close(void)
int ff_network_init(void)
Initialize the network subsystem.
Callback for checking whether to abort blocking functions.
const AVClass * ff_urlcontext_child_class_iterate(void **iter)
int ffurl_get_short_seek(void *urlcontext)
Return the current short seek threshold value for this URL.
static const AVOption avio_options[]
int ffurl_connect(URLContext *uc, AVDictionary **options)
Connect an URLContext that has been allocated by ffurl_alloc.
void av_opt_free(void *obj)
Free all allocated objects in obj.
#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 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.
#define flags(name, subs,...)
static int url_open_whitelist(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char *blacklist, URLContext *parent, AVFormatContext *avfc)
static int is_dos_path(const char *path)
int ffio_open_whitelist2(AVIOContext **s, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char *blacklist, AVFormatContext *avfc)
Like ffio_open_whitelist(), but additionally records avfc on the underlying URLContext before it is c...
int avio_close_dir(AVIODirContext **s)
Close directory.
@ AV_OPT_TYPE_INT64
Underlying C type is int64_t.
#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.
static AVFormatContext * ctx
static void * avio_child_next(void *obj, void *prev)
int av_usleep(unsigned usec)
Sleep for a period of time.
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
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.
const char * av_default_item_name(void *ptr)
Return the context name.
int ffurl_shutdown(URLContext *h, int flags)
Signal the URLContext that we are done reading or writing the stream.
URLContext * ffio_geturlcontext(AVIOContext *s)
Return the URLContext associated with the AVIOContext.
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
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 av_opt_copy(void *dst, const void *src)
Copy options from src object into dest object.
static const AVClass url_context_class
const URLProtocol ff_libcurl_protocol
int ffurl_get_multi_file_handle(URLContext *h, int **handles, int *numhandles)
Return the file descriptors associated with this URL.
#define i(width, name, range_min, range_max)
#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.
#define AVIO_SEEKABLE_TIME
Seeking by timestamp with avio_seek_time() is possible.
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,...
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
int ffurl_write2(void *urlcontext, const uint8_t *buf, int size)
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...
const struct URLProtocol * prot
int ffio_fdopen(AVIOContext **sp, URLContext *h)
Create and initialize a AVIOContext for accessing the resource referenced by the URLContext h.
const AVClass ff_avio_class
int avio_open_dir(AVIODirContext **s, const char *url, AVDictionary **options)
Open directory for reading.
const AVIOInterruptCB int_cb
static const AVClass * child_class_iterate(void **iter)
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...
int ffurl_read2(void *urlcontext, uint8_t *buf, int size)
int64_t ffurl_seek2(void *urlcontext, int64_t pos, int whence)
AVIOInterruptCB interrupt_callback
int(* url_move)(URLContext *h_src, URLContext *h_dst)
static const struct URLProtocol * url_find_protocol(const char *filename)
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
const AVClass * av_class
information for av_log().
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
static int retry_transfer_wrapper(URLContext *h, uint8_t *buf, const uint8_t *cbuf, int size, int size_min, int read)
#define AVSEEK_FORCE
OR'ing this flag into the "whence" parameter to a seek function causes it to seek by any means (like ...
int is_streamed
true if streamed (no seek possible), default = false
#define AVIO_FLAG_DIRECT
Use direct mode.
#define AVIO_FLAG_READ
read-only
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
int avio_open2(AVIOContext **s, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create and initialize a AVIOContext for accessing the resource indicated by url.
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 ffurl_handshake(URLContext *c)
Perform one step of the protocol handshake to accept a new client.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
#define AVIO_FLAG_NONBLOCK
Use non-blocking mode.
int avio_closep(AVIOContext **s)
Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL...
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)
struct URLContext * url_context
const char * avio_find_protocol_name(const char *url)
Return the name of the protocol that will handle the passed URL.
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
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 av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
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.
static uint32_t BS_FUNC() read(BSCTX *bc, unsigned int n)
Return n bits from the buffer, n has to be in the 0-32 range.