FFmpeg
avio.c
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 
22 #include "libavutil/avstring.h"
23 #include "libavutil/dict.h"
24 #include "libavutil/opt.h"
25 #include "libavutil/time.h"
26 #include "libavutil/avassert.h"
27 #include "os_support.h"
28 #include "avformat.h"
29 #include "internal.h"
30 #if CONFIG_NETWORK
31 #include "network.h"
32 #endif
33 #include "url.h"
34 
35 /** @name Logging context. */
36 /*@{*/
37 static const char *urlcontext_to_name(void *ptr)
38 {
39  URLContext *h = (URLContext *)ptr;
40  if (h->prot)
41  return h->prot->name;
42  else
43  return "NULL";
44 }
45 
46 static void *urlcontext_child_next(void *obj, void *prev)
47 {
48  URLContext *h = obj;
49  if (!prev && h->priv_data && h->prot->priv_data_class)
50  return h->priv_data;
51  return NULL;
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
57 static const AVOption options[] = {
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 },
60  {"rw_timeout", "Timeout for IO operations (in microseconds)", offsetof(URLContext, rw_timeout), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, INT64_MAX, AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_DECODING_PARAM },
61  { NULL }
62 };
63 
65  .class_name = "URLContext",
66  .item_name = urlcontext_to_name,
67  .option = options,
68  .version = LIBAVUTIL_VERSION_INT,
69  .child_next = urlcontext_child_next,
70  .child_class_iterate = ff_urlcontext_child_class_iterate,
71 };
72 /*@}*/
73 
74 static int url_alloc_for_protocol(URLContext **puc, const URLProtocol *up,
75  const char *filename, int flags,
76  const AVIOInterruptCB *int_cb)
77 {
78  URLContext *uc;
79  int err;
80 
81 #if CONFIG_NETWORK
83  return AVERROR(EIO);
84 #endif
85  if ((flags & AVIO_FLAG_READ) && !up->url_read) {
87  "Impossible to open the '%s' protocol for reading\n", up->name);
88  return AVERROR(EIO);
89  }
90  if ((flags & AVIO_FLAG_WRITE) && !up->url_write) {
92  "Impossible to open the '%s' protocol for writing\n", up->name);
93  return AVERROR(EIO);
94  }
95  uc = av_mallocz(sizeof(URLContext) + strlen(filename) + 1);
96  if (!uc) {
97  err = AVERROR(ENOMEM);
98  goto fail;
99  }
101  uc->filename = (char *)&uc[1];
102  strcpy(uc->filename, filename);
103  uc->prot = up;
104  uc->flags = flags;
105  uc->is_streamed = 0; /* default = not streamed */
106  uc->max_packet_size = 0; /* default: stream file */
107  if (up->priv_data_size) {
109  if (!uc->priv_data) {
110  err = AVERROR(ENOMEM);
111  goto fail;
112  }
113  if (up->priv_data_class) {
114  char *start;
115  *(const AVClass **)uc->priv_data = up->priv_data_class;
117  if (av_strstart(uc->filename, up->name, (const char**)&start) && *start == ',') {
118  int ret= 0;
119  char *p= start;
120  char sep= *++p;
121  char *key, *val;
122  p++;
123 
124  if (strcmp(up->name, "subfile"))
125  ret = AVERROR(EINVAL);
126 
127  while(ret >= 0 && (key= strchr(p, sep)) && p<key && (val = strchr(key+1, sep))){
128  *val= *key= 0;
129  if (strcmp(p, "start") && strcmp(p, "end")) {
131  } else
132  ret= av_opt_set(uc->priv_data, p, key+1, 0);
134  av_log(uc, AV_LOG_ERROR, "Key '%s' not found.\n", p);
135  *val= *key= sep;
136  p= val+1;
137  }
138  if(ret<0 || p!=key){
139  av_log(uc, AV_LOG_ERROR, "Error parsing options string %s\n", start);
140  av_freep(&uc->priv_data);
141  av_freep(&uc);
142  err = AVERROR(EINVAL);
143  goto fail;
144  }
145  memmove(start, key+1, strlen(key));
146  }
147  }
148  }
149  if (int_cb)
150  uc->interrupt_callback = *int_cb;
151 
152  *puc = uc;
153  return 0;
154 fail:
155  *puc = NULL;
156  if (uc)
157  av_freep(&uc->priv_data);
158  av_freep(&uc);
159 #if CONFIG_NETWORK
162 #endif
163  return err;
164 }
165 
167 {
168  int err;
169  AVDictionary *tmp_opts = NULL;
171 
172  if (!options)
173  options = &tmp_opts;
174 
175  // Check that URLContext was initialized correctly and lists are matching if set
176  av_assert0(!(e=av_dict_get(*options, "protocol_whitelist", NULL, 0)) ||
177  (uc->protocol_whitelist && !strcmp(uc->protocol_whitelist, e->value)));
178  av_assert0(!(e=av_dict_get(*options, "protocol_blacklist", NULL, 0)) ||
179  (uc->protocol_blacklist && !strcmp(uc->protocol_blacklist, e->value)));
180 
181  if (uc->protocol_whitelist && av_match_list(uc->prot->name, uc->protocol_whitelist, ',') <= 0) {
182  av_log(uc, AV_LOG_ERROR, "Protocol '%s' not on whitelist '%s'!\n", uc->prot->name, uc->protocol_whitelist);
183  return AVERROR(EINVAL);
184  }
185 
186  if (uc->protocol_blacklist && av_match_list(uc->prot->name, uc->protocol_blacklist, ',') > 0) {
187  av_log(uc, AV_LOG_ERROR, "Protocol '%s' on blacklist '%s'!\n", uc->prot->name, uc->protocol_blacklist);
188  return AVERROR(EINVAL);
189  }
190 
191  if (!uc->protocol_whitelist && uc->prot->default_whitelist) {
192  av_log(uc, AV_LOG_DEBUG, "Setting default whitelist '%s'\n", uc->prot->default_whitelist);
194  if (!uc->protocol_whitelist) {
195  return AVERROR(ENOMEM);
196  }
197  } else if (!uc->protocol_whitelist)
198  av_log(uc, AV_LOG_DEBUG, "No default whitelist set\n"); // This should be an error once all declare a default whitelist
199 
200  if ((err = av_dict_set(options, "protocol_whitelist", uc->protocol_whitelist, 0)) < 0)
201  return err;
202  if ((err = av_dict_set(options, "protocol_blacklist", uc->protocol_blacklist, 0)) < 0)
203  return err;
204 
205  err =
206  uc->prot->url_open2 ? uc->prot->url_open2(uc,
207  uc->filename,
208  uc->flags,
209  options) :
210  uc->prot->url_open(uc, uc->filename, uc->flags);
211 
212  av_dict_set(options, "protocol_whitelist", NULL, 0);
213  av_dict_set(options, "protocol_blacklist", NULL, 0);
214 
215  if (err)
216  return err;
217  uc->is_connected = 1;
218  /* We must be careful here as ffurl_seek() could be slow,
219  * for example for http */
220  if ((uc->flags & AVIO_FLAG_WRITE) || !strcmp(uc->prot->name, "file"))
221  if (!uc->is_streamed && ffurl_seek(uc, 0, SEEK_SET) < 0)
222  uc->is_streamed = 1;
223  return 0;
224 }
225 
227 {
228  av_assert0(!*c);
229  if (s->prot->url_accept)
230  return s->prot->url_accept(s, c);
231  return AVERROR(EBADF);
232 }
233 
235 {
236  int ret;
237  if (c->prot->url_handshake) {
238  ret = c->prot->url_handshake(c);
239  if (ret)
240  return ret;
241  }
242  c->is_connected = 1;
243  return 0;
244 }
245 
246 #define URL_SCHEME_CHARS \
247  "abcdefghijklmnopqrstuvwxyz" \
248  "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
249  "0123456789+-."
250 
251 static const struct URLProtocol *url_find_protocol(const char *filename)
252 {
253  const URLProtocol **protocols;
254  char proto_str[128], proto_nested[128], *ptr;
255  size_t proto_len = strspn(filename, URL_SCHEME_CHARS);
256  int i;
257 
258  if (filename[proto_len] != ':' &&
259  (strncmp(filename, "subfile,", 8) || !strchr(filename + proto_len + 1, ':')) ||
260  is_dos_path(filename))
261  strcpy(proto_str, "file");
262  else
263  av_strlcpy(proto_str, filename,
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 
270  protocols = ffurl_get_protocols(NULL, NULL);
271  if (!protocols)
272  return NULL;
273  for (i = 0; protocols[i]; i++) {
274  const URLProtocol *up = protocols[i];
275  if (!strcmp(proto_str, up->name)) {
276  av_freep(&protocols);
277  return up;
278  }
280  !strcmp(proto_nested, up->name)) {
281  av_freep(&protocols);
282  return up;
283  }
284  }
285  av_freep(&protocols);
286  if (av_strstart(filename, "https:", NULL) || av_strstart(filename, "tls:", NULL))
287  av_log(NULL, AV_LOG_WARNING, "https protocol not found, recompile FFmpeg with "
288  "openssl, gnutls or securetransport enabled.\n");
289 
290  return NULL;
291 }
292 
293 int ffurl_alloc(URLContext **puc, const char *filename, int flags,
294  const AVIOInterruptCB *int_cb)
295 {
296  const URLProtocol *p = NULL;
297 
298  p = url_find_protocol(filename);
299  if (p)
300  return url_alloc_for_protocol(puc, p, filename, flags, int_cb);
301 
302  *puc = NULL;
304 }
305 
306 int ffurl_open_whitelist(URLContext **puc, const char *filename, int flags,
308  const char *whitelist, const char* blacklist,
309  URLContext *parent)
310 {
311  AVDictionary *tmp_opts = NULL;
313  int ret = ffurl_alloc(puc, filename, flags, int_cb);
314  if (ret < 0)
315  return ret;
316  if (parent)
317  av_opt_copy(*puc, parent);
318  if (options &&
319  (ret = av_opt_set_dict(*puc, options)) < 0)
320  goto fail;
321  if (options && (*puc)->prot->priv_data_class &&
322  (ret = av_opt_set_dict((*puc)->priv_data, options)) < 0)
323  goto fail;
324 
325  if (!options)
326  options = &tmp_opts;
327 
328  av_assert0(!whitelist ||
329  !(e=av_dict_get(*options, "protocol_whitelist", NULL, 0)) ||
330  !strcmp(whitelist, e->value));
331  av_assert0(!blacklist ||
332  !(e=av_dict_get(*options, "protocol_blacklist", NULL, 0)) ||
333  !strcmp(blacklist, e->value));
334 
335  if ((ret = av_dict_set(options, "protocol_whitelist", whitelist, 0)) < 0)
336  goto fail;
337 
338  if ((ret = av_dict_set(options, "protocol_blacklist", blacklist, 0)) < 0)
339  goto fail;
340 
341  if ((ret = av_opt_set_dict(*puc, options)) < 0)
342  goto fail;
343 
344  ret = ffurl_connect(*puc, options);
345 
346  if (!ret)
347  return 0;
348 fail:
349  ffurl_closep(puc);
350  return ret;
351 }
352 
353 static inline int retry_transfer_wrapper(URLContext *h, uint8_t *buf,
354  int size, int size_min,
355  int (*transfer_func)(URLContext *h,
356  uint8_t *buf,
357  int size))
358 {
359  int ret, len;
360  int fast_retries = 5;
361  int64_t wait_since = 0;
362 
363  len = 0;
364  while (len < size_min) {
365  if (ff_check_interrupt(&h->interrupt_callback))
366  return AVERROR_EXIT;
367  ret = transfer_func(h, buf + len, size - len);
368  if (ret == AVERROR(EINTR))
369  continue;
370  if (h->flags & AVIO_FLAG_NONBLOCK)
371  return ret;
372  if (ret == AVERROR(EAGAIN)) {
373  ret = 0;
374  if (fast_retries) {
375  fast_retries--;
376  } else {
377  if (h->rw_timeout) {
378  if (!wait_since)
379  wait_since = av_gettime_relative();
380  else if (av_gettime_relative() > wait_since + h->rw_timeout)
381  return AVERROR(EIO);
382  }
383  av_usleep(1000);
384  }
385  } else if (ret == AVERROR_EOF)
386  return (len > 0) ? len : AVERROR_EOF;
387  else if (ret < 0)
388  return ret;
389  if (ret) {
390  fast_retries = FFMAX(fast_retries, 2);
391  wait_since = 0;
392  }
393  len += ret;
394  }
395  return len;
396 }
397 
398 int ffurl_read(URLContext *h, unsigned char *buf, int size)
399 {
400  if (!(h->flags & AVIO_FLAG_READ))
401  return AVERROR(EIO);
402  return retry_transfer_wrapper(h, buf, size, 1, h->prot->url_read);
403 }
404 
405 int ffurl_read_complete(URLContext *h, unsigned char *buf, int size)
406 {
407  if (!(h->flags & AVIO_FLAG_READ))
408  return AVERROR(EIO);
409  return retry_transfer_wrapper(h, buf, size, size, h->prot->url_read);
410 }
411 
412 int ffurl_write(URLContext *h, const unsigned char *buf, int size)
413 {
414  if (!(h->flags & AVIO_FLAG_WRITE))
415  return AVERROR(EIO);
416  /* avoid sending too big packets */
417  if (h->max_packet_size && size > h->max_packet_size)
418  return AVERROR(EIO);
419 
420  return retry_transfer_wrapper(h, (unsigned char *)buf, size, size,
421  (int (*)(struct URLContext *, uint8_t *, int))
422  h->prot->url_write);
423 }
424 
425 int64_t ffurl_seek(URLContext *h, int64_t pos, int whence)
426 {
427  int64_t ret;
428 
429  if (!h->prot->url_seek)
430  return AVERROR(ENOSYS);
431  ret = h->prot->url_seek(h, pos, whence & ~AVSEEK_FORCE);
432  return ret;
433 }
434 
436 {
437  URLContext *h= *hh;
438  int ret = 0;
439  if (!h)
440  return 0; /* can happen when ffurl_open fails */
441 
442  if (h->is_connected && h->prot->url_close)
443  ret = h->prot->url_close(h);
444 #if CONFIG_NETWORK
445  if (h->prot->flags & URL_PROTOCOL_FLAG_NETWORK)
447 #endif
448  if (h->prot->priv_data_size) {
449  if (h->prot->priv_data_class)
450  av_opt_free(h->priv_data);
451  av_freep(&h->priv_data);
452  }
453  av_opt_free(h);
454  av_freep(hh);
455  return ret;
456 }
457 
459 {
460  return ffurl_closep(&h);
461 }
462 
463 
464 const char *avio_find_protocol_name(const char *url)
465 {
466  const URLProtocol *p = url_find_protocol(url);
467 
468  return p ? p->name : NULL;
469 }
470 
471 int avio_check(const char *url, int flags)
472 {
473  URLContext *h;
474  int ret = ffurl_alloc(&h, url, flags, NULL);
475  if (ret < 0)
476  return ret;
477 
478  if (h->prot->url_check) {
479  ret = h->prot->url_check(h, flags);
480  } else {
481  ret = ffurl_connect(h, NULL);
482  if (ret >= 0)
483  ret = flags;
484  }
485 
486  ffurl_close(h);
487  return ret;
488 }
489 
490 int avpriv_io_move(const char *url_src, const char *url_dst)
491 {
492  URLContext *h_src, *h_dst;
493  int ret = ffurl_alloc(&h_src, url_src, AVIO_FLAG_READ_WRITE, NULL);
494  if (ret < 0)
495  return ret;
496  ret = ffurl_alloc(&h_dst, url_dst, AVIO_FLAG_WRITE, NULL);
497  if (ret < 0) {
498  ffurl_close(h_src);
499  return ret;
500  }
501 
502  if (h_src->prot == h_dst->prot && h_src->prot->url_move)
503  ret = h_src->prot->url_move(h_src, h_dst);
504  else
505  ret = AVERROR(ENOSYS);
506 
507  ffurl_close(h_src);
508  ffurl_close(h_dst);
509  return ret;
510 }
511 
512 int avpriv_io_delete(const char *url)
513 {
514  URLContext *h;
515  int ret = ffurl_alloc(&h, url, AVIO_FLAG_WRITE, NULL);
516  if (ret < 0)
517  return ret;
518 
519  if (h->prot->url_delete)
520  ret = h->prot->url_delete(h);
521  else
522  ret = AVERROR(ENOSYS);
523 
524  ffurl_close(h);
525  return ret;
526 }
527 
529 {
530  URLContext *h = NULL;
532  int ret;
533  av_assert0(s);
534 
535  ctx = av_mallocz(sizeof(*ctx));
536  if (!ctx) {
537  ret = AVERROR(ENOMEM);
538  goto fail;
539  }
540 
541  if ((ret = ffurl_alloc(&h, url, AVIO_FLAG_READ, NULL)) < 0)
542  goto fail;
543 
544  if (h->prot->url_open_dir && h->prot->url_read_dir && h->prot->url_close_dir) {
545  if (options && h->prot->priv_data_class &&
546  (ret = av_opt_set_dict(h->priv_data, options)) < 0)
547  goto fail;
548  ret = h->prot->url_open_dir(h);
549  } else
550  ret = AVERROR(ENOSYS);
551  if (ret < 0)
552  goto fail;
553 
554  h->is_connected = 1;
555  ctx->url_context = h;
556  *s = ctx;
557  return 0;
558 
559  fail:
560  av_free(ctx);
561  *s = NULL;
562  ffurl_close(h);
563  return ret;
564 }
565 
567 {
568  URLContext *h;
569  int ret;
570 
571  if (!s || !s->url_context)
572  return AVERROR(EINVAL);
573  h = s->url_context;
574  if ((ret = h->prot->url_read_dir(h, next)) < 0)
576  return ret;
577 }
578 
580 {
581  URLContext *h;
582 
583  av_assert0(s);
584  if (!(*s) || !(*s)->url_context)
585  return AVERROR(EINVAL);
586  h = (*s)->url_context;
587  h->prot->url_close_dir(h);
588  ffurl_close(h);
589  av_freep(s);
590  *s = NULL;
591  return 0;
592 }
593 
595 {
596  if (!entry || !*entry)
597  return;
598  av_free((*entry)->name);
599  av_freep(entry);
600 }
601 
603 {
604  int64_t pos, size;
605 
606  size = ffurl_seek(h, 0, AVSEEK_SIZE);
607  if (size < 0) {
608  pos = ffurl_seek(h, 0, SEEK_CUR);
609  if ((size = ffurl_seek(h, -1, SEEK_END)) < 0)
610  return size;
611  size++;
612  ffurl_seek(h, pos, SEEK_SET);
613  }
614  return size;
615 }
616 
618 {
619  if (!h || !h->prot || !h->prot->url_get_file_handle)
620  return -1;
621  return h->prot->url_get_file_handle(h);
622 }
623 
624 int ffurl_get_multi_file_handle(URLContext *h, int **handles, int *numhandles)
625 {
626  if (!h || !h->prot)
627  return AVERROR(ENOSYS);
628  if (!h->prot->url_get_multi_file_handle) {
629  if (!h->prot->url_get_file_handle)
630  return AVERROR(ENOSYS);
631  *handles = av_malloc(sizeof(**handles));
632  if (!*handles)
633  return AVERROR(ENOMEM);
634  *numhandles = 1;
635  *handles[0] = h->prot->url_get_file_handle(h);
636  return 0;
637  }
638  return h->prot->url_get_multi_file_handle(h, handles, numhandles);
639 }
640 
642 {
643  if (!h || !h->prot || !h->prot->url_get_short_seek)
644  return AVERROR(ENOSYS);
645  return h->prot->url_get_short_seek(h);
646 }
647 
649 {
650  if (!h || !h->prot || !h->prot->url_shutdown)
651  return AVERROR(ENOSYS);
652  return h->prot->url_shutdown(h, flags);
653 }
654 
656 {
657  if (cb && cb->callback)
658  return cb->callback(cb->opaque);
659  return 0;
660 }
661 
662 int ff_rename(const char *url_src, const char *url_dst, void *logctx)
663 {
664  int ret = avpriv_io_move(url_src, url_dst);
665  if (ret < 0)
666  av_log(logctx, AV_LOG_ERROR, "failed to rename file %s to %s: %s\n", url_src, url_dst, av_err2str(ret));
667  return ret;
668 }
av_gettime_relative
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition: time.c:56
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:187
ffurl_context_class
const AVClass ffurl_context_class
Definition: avio.c:64
AVERROR
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
opt.h
URLContext::filename
char * filename
specified URL
Definition: url.h:42
av_opt_set_defaults
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:1358
URL_PROTOCOL_FLAG_NETWORK
#define URL_PROTOCOL_FLAG_NETWORK
Definition: url.h:34
URLProtocol::url_read
int(* url_read)(URLContext *h, unsigned char *buf, int size)
Read data from the protocol.
Definition: url.h:78
cb
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:215
ffurl_seek
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.
Definition: avio.c:425
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:55
AVIO_FLAG_READ_WRITE
#define AVIO_FLAG_READ_WRITE
read-write pseudo flag
Definition: avio.h:676
URLContext::max_packet_size
int max_packet_size
if non zero, the stream is packetized with this max packet size
Definition: url.h:44
AVOption
AVOption.
Definition: opt.h:248
AVSEEK_SIZE
#define AVSEEK_SIZE
ORing this as the "whence" parameter to a seek function causes it to return the filesize without seek...
Definition: avio.h:531
ffurl_close
int ffurl_close(URLContext *h)
Definition: avio.c:458
urlcontext_to_name
static const char * urlcontext_to_name(void *ptr)
Definition: avio.c:37
AVDictionary
Definition: dict.c:30
ff_network_close
void ff_network_close(void)
Definition: network.c:116
URLProtocol
Definition: url.h:54
os_support.h
ff_network_init
int ff_network_init(void)
Definition: network.c:58
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
AVIOInterruptCB
Callback for checking whether to abort blocking functions.
Definition: avio.h:58
ff_urlcontext_child_class_iterate
const AVClass * ff_urlcontext_child_class_iterate(void **iter)
Definition: protocols.c:78
URLContext::is_connected
int is_connected
Definition: url.h:46
fail
#define fail()
Definition: checkasm.h:134
ffurl_connect
int ffurl_connect(URLContext *uc, AVDictionary **options)
Connect an URLContext that has been allocated by ffurl_alloc.
Definition: avio.c:166
AVERROR_OPTION_NOT_FOUND
#define AVERROR_OPTION_NOT_FOUND
Option not found.
Definition: error.h:61
val
static double val(void *priv, double ch)
Definition: aeval.c:76
av_opt_set
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:465
ff_check_interrupt
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrupt a blocking function associated with cb.
Definition: avio.c:655
ff_rename
int ff_rename(const char *url_src, const char *url_dst, void *logctx)
Wrap avpriv_io_move and log if error happens.
Definition: avio.c:662
URLProtocol::url_open
int(* url_open)(URLContext *h, const char *url, int flags)
Definition: url.h:56
URLContext::priv_data
void * priv_data
Definition: url.h:41
avio_free_directory_entry
void avio_free_directory_entry(AVIODirEntry **entry)
Free entry allocated by avio_read_dir().
Definition: avio.c:594
URLProtocol::flags
int flags
Definition: url.h:92
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:181
url_alloc_for_protocol
static int url_alloc_for_protocol(URLContext **puc, const URLProtocol *up, const char *filename, int flags, const AVIOInterruptCB *int_cb)
Definition: avio.c:74
av_dict_get
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:40
av_opt_set_dict
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
Definition: opt.c:1656
ffurl_open_whitelist
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.
Definition: avio.c:306
retry_transfer_wrapper
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))
Definition: avio.c:353
s
#define s(width, name)
Definition: cbs_vp9.c:257
AV_OPT_FLAG_ENCODING_PARAM
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
Definition: opt.h:278
avpriv_io_move
int avpriv_io_move(const char *url_src, const char *url_dst)
Move or rename a resource.
Definition: avio.c:490
is_dos_path
static int is_dos_path(const char *path)
Definition: os_support.h:70
URLContext::flags
int flags
Definition: url.h:43
avio_close_dir
int avio_close_dir(AVIODirContext **s)
Close directory.
Definition: avio.c:579
AV_OPT_TYPE_INT64
@ AV_OPT_TYPE_INT64
Definition: opt.h:226
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AVIO_FLAG_WRITE
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:675
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:202
ctx
AVFormatContext * ctx
Definition: movenc.c:48
key
const char * key
Definition: hwcontext_opencl.c:168
av_usleep
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition: time.c:84
ffurl_accept
int ffurl_accept(URLContext *s, URLContext **c)
Accept an URLContext c on an URLContext s.
Definition: avio.c:226
internal.h
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
ffurl_get_protocols
const URLProtocol ** ffurl_get_protocols(const char *whitelist, const char *blacklist)
Construct a list of protocols matching a given whitelist and/or blacklist.
Definition: protocols.c:118
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
URLContext::protocol_whitelist
const char * protocol_whitelist
Definition: url.h:49
D
#define D
Definition: avio.c:56
NULL
#define NULL
Definition: coverity.c:32
urlcontext_child_next
static void * urlcontext_child_next(void *obj, void *prev)
Definition: avio.c:46
av_match_list
int av_match_list(const char *name, const char *list, char separator)
Check if a name is in a list.
Definition: avstring.c:452
URLContext::protocol_blacklist
const char * protocol_blacklist
Definition: url.h:50
ffurl_shutdown
int ffurl_shutdown(URLContext *h, int flags)
Signal the URLContext that we are done reading or writing the stream.
Definition: avio.c:648
URL_SCHEME_CHARS
#define URL_SCHEME_CHARS
Definition: avio.c:246
av_opt_free
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1611
time.h
c
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
Definition: undefined.txt:32
avio_read_dir
int avio_read_dir(AVIODirContext *s, AVIODirEntry **next)
Get next directory entry.
Definition: avio.c:566
OFFSET
#define OFFSET(x)
Definition: avio.c:54
ffurl_get_multi_file_handle
int ffurl_get_multi_file_handle(URLContext *h, int **handles, int *numhandles)
Return the file descriptors associated with this URL.
Definition: avio.c:624
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:119
URLProtocol::priv_data_class
const AVClass * priv_data_class
Definition: url.h:90
FFMAX
#define FFMAX(a, b)
Definition: common.h:103
URL_PROTOCOL_FLAG_NESTED_SCHEME
#define URL_PROTOCOL_FLAG_NESTED_SCHEME
Definition: url.h:33
size
int size
Definition: twinvq_data.h:10344
AVIODirEntry
Describes single entry of the directory.
Definition: avio.h:86
URLProtocol::name
const char * name
Definition: url.h:55
URLProtocol::default_whitelist
const char * default_whitelist
Definition: url.h:99
avio_check
int avio_check(const char *url, int flags)
Return AVIO_FLAG_* access flags corresponding to the access permissions of the resource in url,...
Definition: avio.c:471
avpriv_io_delete
int avpriv_io_delete(const char *url)
Delete a resource.
Definition: avio.c:512
FFMIN
#define FFMIN(a, b)
Definition: common.h:105
av_strstart
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
Definition: avstring.c:34
ffurl_get_short_seek
int ffurl_get_short_seek(URLContext *h)
Return the current short seek threshold value for this URL.
Definition: avio.c:641
ffurl_alloc
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...
Definition: avio.c:293
i
int i
Definition: input.c:407
URLContext
Definition: url.h:38
URLContext::prot
const struct URLProtocol * prot
Definition: url.h:40
AV_OPT_FLAG_DECODING_PARAM
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:279
url.h
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:243
avio_open_dir
int avio_open_dir(AVIODirContext **s, const char *url, AVDictionary **options)
Open directory for reading.
Definition: avio.c:528
len
int len
Definition: vorbis_enc_data.h:452
int_cb
const AVIOInterruptCB int_cb
Definition: ffmpeg.c:513
ffurl_closep
int ffurl_closep(URLContext **hh)
Close the resource accessed by the URLContext h, and free the memory used by it.
Definition: avio.c:435
ret
ret
Definition: filter_design.txt:187
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
AVIODirContext
Definition: avio.h:103
URLContext::interrupt_callback
AVIOInterruptCB interrupt_callback
Definition: url.h:47
pos
unsigned int pos
Definition: spdifenc.c:412
avformat.h
dict.h
URLProtocol::url_move
int(* url_move)(URLContext *h_src, URLContext *h_dst)
Definition: url.h:98
network.h
options
static const AVOption options[]
Definition: avio.c:57
url_find_protocol
static const struct URLProtocol * url_find_protocol(const char *filename)
Definition: avio.c:251
ffurl_read
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.
Definition: avio.c:398
URLContext::av_class
const AVClass * av_class
information for av_log().
Definition: url.h:39
ffurl_write
int ffurl_write(URLContext *h, const unsigned char *buf, int size)
Write size bytes from buf to the resource accessed by h.
Definition: avio.c:412
AVSEEK_FORCE
#define AVSEEK_FORCE
Passing this flag as the "whence" parameter to a seek function causes it to seek by any means (like r...
Definition: avio.h:539
URLContext::is_streamed
int is_streamed
true if streamed (no seek possible), default = false
Definition: url.h:45
AVIO_FLAG_READ
#define AVIO_FLAG_READ
read-only
Definition: avio.h:674
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:259
ffurl_read_complete
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.
Definition: avio.c:405
av_opt_copy
int av_opt_copy(void *dst, const void *src)
Copy options from src object into dest object.
Definition: opt.c:1770
URLProtocol::priv_data_size
int priv_data_size
Definition: url.h:91
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVDictionaryEntry
Definition: dict.h:81
ffurl_handshake
int ffurl_handshake(URLContext *c)
Perform one step of the protocol handshake to accept a new client.
Definition: avio.c:234
AVIO_FLAG_NONBLOCK
#define AVIO_FLAG_NONBLOCK
Use non-blocking mode.
Definition: avio.h:693
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:70
URLProtocol::url_write
int(* url_write)(URLContext *h, const unsigned char *buf, int size)
Definition: url.h:79
avio_find_protocol_name
const char * avio_find_protocol_name(const char *url)
Return the name of the protocol that will handle the passed URL.
Definition: avio.c:464
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
av_strlcpy
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.
Definition: avstring.c:83
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
ffurl_size
int64_t ffurl_size(URLContext *h)
Return the filesize of the resource accessed by h, AVERROR(ENOSYS) if the operation is not supported ...
Definition: avio.c:602
h
h
Definition: vp9dsp_template.c:2038
AVERROR_EXIT
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
Definition: error.h:56
AVDictionaryEntry::value
char * value
Definition: dict.h:83
avstring.h
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
AVERROR_PROTOCOL_NOT_FOUND
#define AVERROR_PROTOCOL_NOT_FOUND
Protocol not found.
Definition: error.h:63
ffurl_get_file_handle
int ffurl_get_file_handle(URLContext *h)
Return the file descriptor associated with this URL.
Definition: avio.c:617
URLProtocol::url_open2
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.
Definition: url.h:62