22 #include "libavutil/avstring.h"
23 #include "libavutil/dict.h"
24 #include "libavutil/opt.h"
25 #include "libavutil/time.h"
90 if (!(p = *opaque))
return NULL;
101 memcpy(temp, protocol, size);
105 while (*p != NULL) p = &(*p)->
next;
107 protocol->
next = NULL;
112 const char *filename,
int flags,
124 "Impossible to open the '%s' protocol for reading\n", up->
name);
129 "Impossible to open the '%s' protocol for writing\n", up->
name);
151 int proto_len= strlen(up->
name);
161 while(ret >= 0 && (key= strchr(p, sep)) && p<key && (val = strchr(key+1, sep))){
176 memmove(start, key+1, strlen(key));
213 #define URL_SCHEME_CHARS \
214 "abcdefghijklmnopqrstuvwxyz" \
215 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
222 char proto_str[128], proto_nested[128], *ptr;
225 if (!first_protocol) {
227 "Missing call to av_register_all()?\n");
230 if (filename[proto_len] !=
':' &&
231 (filename[proto_len] !=
',' || !strchr(filename + proto_len + 1,
':')) ||
233 strcpy(proto_str,
"file");
235 av_strlcpy(proto_str, filename,
FFMIN(proto_len+1,
sizeof(proto_str)));
237 if ((ptr = strchr(proto_str,
',')))
239 av_strlcpy(proto_nested, proto_str,
sizeof(proto_nested));
240 if ((ptr = strchr(proto_nested,
'+')))
244 if (!strcmp(proto_str, up->
name))
247 !strcmp(proto_nested, up->
name))
251 if (!strcmp(
"https", proto_str))
252 av_log(NULL,
AV_LOG_WARNING,
"https protocol not found, recompile with openssl or gnutls enabled.\n");
262 if (options && (*puc)->prot->priv_data_class &&
275 int (*transfer_func)(
URLContext *h,
unsigned char *buf,
int size))
278 int fast_retries = 5;
279 int64_t wait_since = 0;
282 while (len < size_min) {
285 ret = transfer_func(h, buf+len, size-len);
306 fast_retries =
FFMAX(fast_retries, 2);
const char const char void * val
int ffurl_register_protocol(URLProtocol *protocol, int size)
Register the URLProtocol protocol.
#define URL_PROTOCOL_FLAG_NETWORK
int(* url_check)(URLContext *h, int mask)
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
int ffurl_write(URLContext *h, const unsigned char *buf, int size)
Write size bytes from buf to the resource accessed by h.
int av_usleep(unsigned usec)
Sleep for a period of time.
int is_streamed
true if streamed (no seek possible), default = false
static URLProtocol * first_protocol
int ffurl_connect(URLContext *uc, AVDictionary **options)
Connect an URLContext that has been allocated by ffurl_alloc.
AVIOInterruptCB interrupt_callback
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
int64_t rw_timeout
maximum time to wait for (network) read/write operation completion, in mcs
struct URLProtocol * prot
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
void ff_network_close(void)
static void * urlcontext_child_next(void *obj, void *prev)
int ffurl_shutdown(URLContext *h, int flags)
Signal the URLContext that we are done reading or writing the stream.
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
const AVClass * priv_data_class
struct URLProtocol * next
static double cb(void *priv, double x, double y)
int ff_network_init(void)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
miscellaneous OS support macros and functions.
static int url_alloc_for_protocol(URLContext **puc, struct URLProtocol *up, const char *filename, int flags, const AVIOInterruptCB *int_cb)
int(* url_get_file_handle)(URLContext *h)
static int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int size, int size_min, int(*transfer_func)(URLContext *h, unsigned char *buf, int size))
int(* url_get_multi_file_handle)(URLContext *h, int **handles, int *numhandles)
const OptionDef options[]
Callback for checking whether to abort blocking functions.
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...
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.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int ffurl_get_multi_file_handle(URLContext *h, int **handles, int *numhandles)
Return the file descriptors associated with this URL.
const AVIOInterruptCB int_cb
#define URL_PROTOCOL_FLAG_NESTED_SCHEME
int(* url_open)(URLContext *h, const char *url, int flags)
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.
static const char * urlcontext_to_name(void *ptr)
int(* url_write)(URLContext *h, const unsigned char *buf, int size)
int(* url_read)(URLContext *h, unsigned char *buf, int size)
Read data from the protocol.
int64_t av_gettime(void)
Get the current time in microseconds.
URLProtocol * ffurl_protocol_next(URLProtocol *prev)
Iterate over all available protocols.
static const AVClass * urlcontext_child_class_next(const AVClass *prev)
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int64_t(* url_seek)(URLContext *h, int64_t pos, int whence)
int ffurl_get_file_handle(URLContext *h)
Return the file descriptor associated with this URL.
int ffurl_closep(URLContext **hh)
Close the resource accessed by the URLContext h, and free the memory used by it.
static int is_dos_path(const char *path)
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrup a blocking function associated with cb.
int av_opt_set_dict(void *obj, struct AVDictionary **options)
Set all the options from a given dictionary on an object.
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_OPTION_NOT_FOUND
Describe the class of an AVClass context structure.
const AVClass * av_class
information for av_log().
int ffurl_close(URLContext *h)
const AVClass ffurl_context_class
void av_opt_free(void *obj)
Free all string and binary options in obj.
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...
int ffurl_open(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create an URLContext for accessing to the resource indicated by url, and open it. ...
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...
char * filename
specified URL
int max_packet_size
if non zero, the stream is packetized with this max packet size
int(* url_close)(URLContext *h)
unbuffered private I/O API
#define AVERROR_PROTOCOL_NOT_FOUND
int(* url_shutdown)(URLContext *h, int flags)
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
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...
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...