FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 #if CONFIG_NETWORK
30 #include "network.h"
31 #endif
32 #include "url.h"
33 
34 /** @name Logging context. */
35 /*@{*/
36 static const char *urlcontext_to_name(void *ptr)
37 {
38  URLContext *h = (URLContext *)ptr;
39  if (h->prot)
40  return h->prot->name;
41  else
42  return "NULL";
43 }
44 
45 static void *urlcontext_child_next(void *obj, void *prev)
46 {
47  URLContext *h = obj;
48  if (!prev && h->priv_data && h->prot->priv_data_class)
49  return h->priv_data;
50  return NULL;
51 }
52 
53 #define OFFSET(x) offsetof(URLContext,x)
54 #define E AV_OPT_FLAG_ENCODING_PARAM
55 #define D AV_OPT_FLAG_DECODING_PARAM
56 static const AVOption options[] = {
57  {"protocol_whitelist", "List of protocols that are allowed to be used", OFFSET(protocol_whitelist), AV_OPT_TYPE_STRING, { .str = NULL }, CHAR_MIN, CHAR_MAX, D },
58  {"protocol_blacklist", "List of protocols that are not allowed to be used", OFFSET(protocol_blacklist), AV_OPT_TYPE_STRING, { .str = NULL }, CHAR_MIN, CHAR_MAX, D },
59  {"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 },
60  { NULL }
61 };
62 
64  .class_name = "URLContext",
65  .item_name = urlcontext_to_name,
66  .option = options,
67  .version = LIBAVUTIL_VERSION_INT,
68  .child_next = urlcontext_child_next,
69  .child_class_next = ff_urlcontext_child_class_next,
70 };
71 /*@}*/
72 
73 static int url_alloc_for_protocol(URLContext **puc, const URLProtocol *up,
74  const char *filename, int flags,
75  const AVIOInterruptCB *int_cb)
76 {
77  URLContext *uc;
78  int err;
79 
80 #if CONFIG_NETWORK
82  return AVERROR(EIO);
83 #endif
84  if ((flags & AVIO_FLAG_READ) && !up->url_read) {
86  "Impossible to open the '%s' protocol for reading\n", up->name);
87  return AVERROR(EIO);
88  }
89  if ((flags & AVIO_FLAG_WRITE) && !up->url_write) {
91  "Impossible to open the '%s' protocol for writing\n", up->name);
92  return AVERROR(EIO);
93  }
94  uc = av_mallocz(sizeof(URLContext) + strlen(filename) + 1);
95  if (!uc) {
96  err = AVERROR(ENOMEM);
97  goto fail;
98  }
100  uc->filename = (char *)&uc[1];
101  strcpy(uc->filename, filename);
102  uc->prot = up;
103  uc->flags = flags;
104  uc->is_streamed = 0; /* default = not streamed */
105  uc->max_packet_size = 0; /* default: stream file */
106  if (up->priv_data_size) {
108  if (!uc->priv_data) {
109  err = AVERROR(ENOMEM);
110  goto fail;
111  }
112  if (up->priv_data_class) {
113  int proto_len= strlen(up->name);
114  char *start = strchr(uc->filename, ',');
115  *(const AVClass **)uc->priv_data = up->priv_data_class;
117  if(!strncmp(up->name, uc->filename, proto_len) && uc->filename + proto_len == 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);
133  if (ret == AVERROR_OPTION_NOT_FOUND)
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 
287  return NULL;
288 }
289 
290 int ffurl_alloc(URLContext **puc, const char *filename, int flags,
291  const AVIOInterruptCB *int_cb)
292 {
293  const URLProtocol *p = NULL;
294 
295  p = url_find_protocol(filename);
296  if (p)
297  return url_alloc_for_protocol(puc, p, filename, flags, int_cb);
298 
299  *puc = NULL;
300  if (av_strstart(filename, "https:", NULL) || av_strstart(filename, "tls:", NULL))
301  av_log(NULL, AV_LOG_WARNING, "https protocol not found, recompile FFmpeg with "
302  "openssl, gnutls "
303  "or securetransport enabled.\n");
305 }
306 
307 int ffurl_open_whitelist(URLContext **puc, const char *filename, int flags,
308  const AVIOInterruptCB *int_cb, AVDictionary **options,
309  const char *whitelist, const char* blacklist,
310  URLContext *parent)
311 {
312  AVDictionary *tmp_opts = NULL;
314  int ret = ffurl_alloc(puc, filename, flags, int_cb);
315  if (ret < 0)
316  return ret;
317  if (parent)
318  av_opt_copy(*puc, parent);
319  if (options &&
320  (ret = av_opt_set_dict(*puc, options)) < 0)
321  goto fail;
322  if (options && (*puc)->prot->priv_data_class &&
323  (ret = av_opt_set_dict((*puc)->priv_data, options)) < 0)
324  goto fail;
325 
326  if (!options)
327  options = &tmp_opts;
328 
329  av_assert0(!whitelist ||
330  !(e=av_dict_get(*options, "protocol_whitelist", NULL, 0)) ||
331  !strcmp(whitelist, e->value));
332  av_assert0(!blacklist ||
333  !(e=av_dict_get(*options, "protocol_blacklist", NULL, 0)) ||
334  !strcmp(blacklist, e->value));
335 
336  if ((ret = av_dict_set(options, "protocol_whitelist", whitelist, 0)) < 0)
337  goto fail;
338 
339  if ((ret = av_dict_set(options, "protocol_blacklist", blacklist, 0)) < 0)
340  goto fail;
341 
342  if ((ret = av_opt_set_dict(*puc, options)) < 0)
343  goto fail;
344 
345  ret = ffurl_connect(*puc, options);
346 
347  if (!ret)
348  return 0;
349 fail:
350  ffurl_close(*puc);
351  *puc = NULL;
352  return ret;
353 }
354 
355 int ffurl_open(URLContext **puc, const char *filename, int flags,
356  const AVIOInterruptCB *int_cb, AVDictionary **options)
357 {
358  return ffurl_open_whitelist(puc, filename, flags,
359  int_cb, options, NULL, NULL, NULL);
360 }
361 
363  int size, int size_min,
364  int (*transfer_func)(URLContext *h,
365  uint8_t *buf,
366  int size))
367 {
368  int ret, len;
369  int fast_retries = 5;
370  int64_t wait_since = 0;
371 
372  len = 0;
373  while (len < size_min) {
375  return AVERROR_EXIT;
376  ret = transfer_func(h, buf + len, size - len);
377  if (ret == AVERROR(EINTR))
378  continue;
379  if (h->flags & AVIO_FLAG_NONBLOCK)
380  return ret;
381  if (ret == AVERROR(EAGAIN)) {
382  ret = 0;
383  if (fast_retries) {
384  fast_retries--;
385  } else {
386  if (h->rw_timeout) {
387  if (!wait_since)
388  wait_since = av_gettime_relative();
389  else if (av_gettime_relative() > wait_since + h->rw_timeout)
390  return AVERROR(EIO);
391  }
392  av_usleep(1000);
393  }
394  } else if (ret == AVERROR_EOF)
395  return (len > 0) ? len : AVERROR_EOF;
396  else if (ret < 0)
397  return ret;
398  if (ret) {
399  fast_retries = FFMAX(fast_retries, 2);
400  wait_since = 0;
401  }
402  len += ret;
403  }
404  return len;
405 }
406 
407 int ffurl_read(URLContext *h, unsigned char *buf, int size)
408 {
409  if (!(h->flags & AVIO_FLAG_READ))
410  return AVERROR(EIO);
411  return retry_transfer_wrapper(h, buf, size, 1, h->prot->url_read);
412 }
413 
414 int ffurl_read_complete(URLContext *h, unsigned char *buf, int size)
415 {
416  if (!(h->flags & AVIO_FLAG_READ))
417  return AVERROR(EIO);
418  return retry_transfer_wrapper(h, buf, size, size, h->prot->url_read);
419 }
420 
421 int ffurl_write(URLContext *h, const unsigned char *buf, int size)
422 {
423  if (!(h->flags & AVIO_FLAG_WRITE))
424  return AVERROR(EIO);
425  /* avoid sending too big packets */
426  if (h->max_packet_size && size > h->max_packet_size)
427  return AVERROR(EIO);
428 
429  return retry_transfer_wrapper(h, (unsigned char *)buf, size, size,
430  (int (*)(struct URLContext *, uint8_t *, int))
431  h->prot->url_write);
432 }
433 
434 int64_t ffurl_seek(URLContext *h, int64_t pos, int whence)
435 {
436  int64_t ret;
437 
438  if (!h->prot->url_seek)
439  return AVERROR(ENOSYS);
440  ret = h->prot->url_seek(h, pos, whence & ~AVSEEK_FORCE);
441  return ret;
442 }
443 
445 {
446  URLContext *h= *hh;
447  int ret = 0;
448  if (!h)
449  return 0; /* can happen when ffurl_open fails */
450 
451  if (h->is_connected && h->prot->url_close)
452  ret = h->prot->url_close(h);
453 #if CONFIG_NETWORK
456 #endif
457  if (h->prot->priv_data_size) {
458  if (h->prot->priv_data_class)
460  av_freep(&h->priv_data);
461  }
462  av_opt_free(h);
463  av_freep(hh);
464  return ret;
465 }
466 
468 {
469  return ffurl_closep(&h);
470 }
471 
472 
473 const char *avio_find_protocol_name(const char *url)
474 {
475  const URLProtocol *p = url_find_protocol(url);
476 
477  return p ? p->name : NULL;
478 }
479 
480 int avio_check(const char *url, int flags)
481 {
482  URLContext *h;
483  int ret = ffurl_alloc(&h, url, flags, NULL);
484  if (ret < 0)
485  return ret;
486 
487  if (h->prot->url_check) {
488  ret = h->prot->url_check(h, flags);
489  } else {
490  ret = ffurl_connect(h, NULL);
491  if (ret >= 0)
492  ret = flags;
493  }
494 
495  ffurl_close(h);
496  return ret;
497 }
498 
499 int avpriv_io_move(const char *url_src, const char *url_dst)
500 {
501  URLContext *h_src, *h_dst;
502  int ret = ffurl_alloc(&h_src, url_src, AVIO_FLAG_READ_WRITE, NULL);
503  if (ret < 0)
504  return ret;
505  ret = ffurl_alloc(&h_dst, url_dst, AVIO_FLAG_WRITE, NULL);
506  if (ret < 0) {
507  ffurl_close(h_src);
508  return ret;
509  }
510 
511  if (h_src->prot == h_dst->prot && h_src->prot->url_move)
512  ret = h_src->prot->url_move(h_src, h_dst);
513  else
514  ret = AVERROR(ENOSYS);
515 
516  ffurl_close(h_src);
517  ffurl_close(h_dst);
518  return ret;
519 }
520 
521 int avpriv_io_delete(const char *url)
522 {
523  URLContext *h;
524  int ret = ffurl_alloc(&h, url, AVIO_FLAG_WRITE, NULL);
525  if (ret < 0)
526  return ret;
527 
528  if (h->prot->url_delete)
529  ret = h->prot->url_delete(h);
530  else
531  ret = AVERROR(ENOSYS);
532 
533  ffurl_close(h);
534  return ret;
535 }
536 
537 int avio_open_dir(AVIODirContext **s, const char *url, AVDictionary **options)
538 {
539  URLContext *h = NULL;
541  int ret;
542  av_assert0(s);
543 
544  ctx = av_mallocz(sizeof(*ctx));
545  if (!ctx) {
546  ret = AVERROR(ENOMEM);
547  goto fail;
548  }
549 
550  if ((ret = ffurl_alloc(&h, url, AVIO_FLAG_READ, NULL)) < 0)
551  goto fail;
552 
553  if (h->prot->url_open_dir && h->prot->url_read_dir && h->prot->url_close_dir) {
554  if (options && h->prot->priv_data_class &&
555  (ret = av_opt_set_dict(h->priv_data, options)) < 0)
556  goto fail;
557  ret = h->prot->url_open_dir(h);
558  } else
559  ret = AVERROR(ENOSYS);
560  if (ret < 0)
561  goto fail;
562 
563  h->is_connected = 1;
564  ctx->url_context = h;
565  *s = ctx;
566  return 0;
567 
568  fail:
569  av_free(ctx);
570  *s = NULL;
571  ffurl_close(h);
572  return ret;
573 }
574 
576 {
577  URLContext *h;
578  int ret;
579 
580  if (!s || !s->url_context)
581  return AVERROR(EINVAL);
582  h = s->url_context;
583  if ((ret = h->prot->url_read_dir(h, next)) < 0)
585  return ret;
586 }
587 
589 {
590  URLContext *h;
591 
592  av_assert0(s);
593  if (!(*s) || !(*s)->url_context)
594  return AVERROR(EINVAL);
595  h = (*s)->url_context;
596  h->prot->url_close_dir(h);
597  ffurl_close(h);
598  av_freep(s);
599  *s = NULL;
600  return 0;
601 }
602 
604 {
605  if (!entry || !*entry)
606  return;
607  av_free((*entry)->name);
608  av_freep(entry);
609 }
610 
612 {
613  int64_t pos, size;
614 
615  size = ffurl_seek(h, 0, AVSEEK_SIZE);
616  if (size < 0) {
617  pos = ffurl_seek(h, 0, SEEK_CUR);
618  if ((size = ffurl_seek(h, -1, SEEK_END)) < 0)
619  return size;
620  size++;
621  ffurl_seek(h, pos, SEEK_SET);
622  }
623  return size;
624 }
625 
627 {
628  if (!h || !h->prot || !h->prot->url_get_file_handle)
629  return -1;
630  return h->prot->url_get_file_handle(h);
631 }
632 
633 int ffurl_get_multi_file_handle(URLContext *h, int **handles, int *numhandles)
634 {
635  if (!h || !h->prot)
636  return AVERROR(ENOSYS);
637  if (!h->prot->url_get_multi_file_handle) {
638  if (!h->prot->url_get_file_handle)
639  return AVERROR(ENOSYS);
640  *handles = av_malloc(sizeof(**handles));
641  if (!*handles)
642  return AVERROR(ENOMEM);
643  *numhandles = 1;
644  *handles[0] = h->prot->url_get_file_handle(h);
645  return 0;
646  }
647  return h->prot->url_get_multi_file_handle(h, handles, numhandles);
648 }
649 
651 {
652  if (!h || !h->prot || !h->prot->url_get_short_seek)
653  return AVERROR(ENOSYS);
654  return h->prot->url_get_short_seek(h);
655 }
656 
658 {
659  if (!h || !h->prot || !h->prot->url_shutdown)
660  return AVERROR(ENOSYS);
661  return h->prot->url_shutdown(h, flags);
662 }
663 
665 {
666  int ret;
667  if (cb && cb->callback && (ret = cb->callback(cb->opaque)))
668  return ret;
669  return 0;
670 }
int(* url_open_dir)(URLContext *h)
Definition: url.h:94
#define NULL
Definition: coverity.c:32
const char const char void * val
Definition: avisynth_c.h:771
const char * s
Definition: avisynth_c.h:768
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:307
#define URL_PROTOCOL_FLAG_NETWORK
Definition: url.h:34
int(* url_close_dir)(URLContext *h)
Definition: url.h:96
AVOption.
Definition: opt.h:246
int(* url_check)(URLContext *h, int mask)
Definition: url.h:93
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
int flags
Definition: url.h:92
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
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:421
int is_streamed
true if streamed (no seek possible), default = false
Definition: url.h:45
int ffurl_connect(URLContext *uc, AVDictionary **options)
Connect an URLContext that has been allocated by ffurl_alloc.
Definition: avio.c:166
AVIOInterruptCB interrupt_callback
Definition: url.h:47
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:1292
Describes single entry of the directory.
Definition: avio.h:86
#define AVIO_FLAG_READ
read-only
Definition: avio.h:654
int64_t rw_timeout
maximum time to wait for (network) read/write operation completion, in mcs
Definition: url.h:48
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:655
void ff_network_close(void)
Definition: network.c:115
int flags
Definition: url.h:43
const char * key
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:236
int av_usleep(unsigned usec)
Sleep for a period of time.
Definition: time.c:84
static void * urlcontext_child_next(void *obj, void *prev)
Definition: avio.c:45
static int url_alloc_for_protocol(URLContext **puc, const URLProtocol *up, const char *filename, int flags, const AVIOInterruptCB *int_cb)
Definition: avio.c:73
int ffurl_shutdown(URLContext *h, int flags)
Signal the URLContext that we are done reading or writing the stream.
Definition: avio.c:657
#define URL_SCHEME_CHARS
Definition: avio.c:246
int avpriv_io_move(const char *url_src, const char *url_dst)
Move or rename a resource.
Definition: avio.c:499
void * opaque
Definition: avio.h:60
const AVClass * priv_data_class
Definition: url.h:91
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:480
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
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
Public dictionary API.
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:112
uint8_t
#define av_malloc(s)
int ff_network_init(void)
Definition: network.c:57
AVOptions.
miscellaneous OS support macros and functions.
int avio_read_dir(AVIODirContext *s, AVIODirEntry **next)
Get next directory entry.
Definition: avio.c:575
#define OFFSET(x)
Definition: avio.c:53
int(* url_get_file_handle)(URLContext *h)
Definition: url.h:85
#define AVERROR_PROTOCOL_NOT_FOUND
Protocol not found.
Definition: error.h:63
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
const AVClass * ff_urlcontext_child_class_next(const AVClass *prev)
Definition: protocols.c:74
int(* url_get_multi_file_handle)(URLContext *h, int **handles, int *numhandles)
Definition: url.h:86
static int flags
Definition: log.c:55
#define AVERROR_EOF
End of file.
Definition: error.h:55
ptrdiff_t size
Definition: opengl_enc.c:101
#define av_log(a,...)
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
Definition: opt.h:276
int(* url_move)(URLContext *h_src, URLContext *h_dst)
Definition: url.h:98
Callback for checking whether to abort blocking functions.
Definition: avio.h:58
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:290
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
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int ffurl_get_multi_file_handle(URLContext *h, int **handles, int *numhandles)
Return the file descriptors associated with this URL.
Definition: avio.c:633
int(* callback)(void *)
Definition: avio.h:59
const AVIOInterruptCB int_cb
Definition: ffmpeg.c:475
const char * protocol_whitelist
Definition: url.h:49
#define AVERROR(e)
Definition: error.h:43
int av_match_list(const char *name, const char *list, char separator)
Check if a name is in a list.
Definition: avstring.c:442
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
#define URL_PROTOCOL_FLAG_NESTED_SCHEME
Definition: url.h:33
simple assert() macros that are a bit more flexible than ISO C assert().
int(* url_open)(URLContext *h, const char *url, int flags)
Definition: url.h:56
#define FFMAX(a, b)
Definition: common.h:94
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
#define fail()
Definition: checkasm.h:116
static const char * urlcontext_to_name(void *ptr)
Definition: avio.c:36
void avio_free_directory_entry(AVIODirEntry **entry)
Free entry allocated by avio_read_dir().
Definition: avio.c:603
int(* url_write)(URLContext *h, const unsigned char *buf, int size)
Definition: url.h:79
int(* url_read)(URLContext *h, unsigned char *buf, int size)
Read data from the protocol.
Definition: url.h:78
static const AVOption options[]
Definition: avio.c:56
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:362
int ffurl_get_short_seek(URLContext *h)
Return the current short seek threshold value for this URL.
Definition: avio.c:650
#define FFMIN(a, b)
Definition: common.h:96
AVFormatContext * ctx
Definition: movenc.c:48
int ffurl_handshake(URLContext *c)
Perform one step of the protocol handshake to accept a new client.
Definition: avio.c:234
int64_t(* url_seek)(URLContext *h, int64_t pos, int whence)
Definition: url.h:80
int ffurl_get_file_handle(URLContext *h)
Return the file descriptor associated with this URL.
Definition: avio.c:626
int ffurl_accept(URLContext *s, URLContext **c)
Accept an URLContext c on an URLContext s.
Definition: avio.c:226
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
Definition: error.h:56
int is_connected
Definition: url.h:46
int ffurl_closep(URLContext **hh)
Close the resource accessed by the URLContext h, and free the memory used by it.
Definition: avio.c:444
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:251
static int is_dos_path(const char *path)
Definition: os_support.h:70
const char * protocol_blacklist
Definition: url.h:50
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrupt a blocking function associated with cb.
Definition: avio.c:664
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
Definition: opt.c:1590
#define AVIO_FLAG_NONBLOCK
Use non-blocking mode.
Definition: avio.h:673
const char * default_whitelist
Definition: url.h:99
int avio_open_dir(AVIODirContext **s, const char *url, AVDictionary **options)
Open directory for reading.
Definition: avio.c:537
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:611
void * buf
Definition: avisynth_c.h:690
Definition: url.h:38
#define AVIO_FLAG_READ_WRITE
read-write pseudo flag
Definition: avio.h:656
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
Describe the class of an AVClass context structure.
Definition: log.h:67
#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
void * priv_data
Definition: url.h:41
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:277
int(* url_handshake)(URLContext *c)
Definition: url.h:64
int(* url_read_dir)(URLContext *h, AVIODirEntry **next)
Definition: url.h:95
const char * name
Definition: url.h:55
const char * avio_find_protocol_name(const char *url)
Return the name of the protocol that will handle the passed URL.
Definition: avio.c:473
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition: time.c:56
const AVClass * av_class
information for av_log().
Definition: url.h:39
int ffurl_close(URLContext *h)
Definition: avio.c:467
int(* url_accept)(URLContext *s, URLContext **c)
Definition: url.h:63
const AVClass ffurl_context_class
Definition: avio.c:63
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
Main libavformat public API header.
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1545
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:434
const struct URLProtocol * prot
Definition: url.h:40
int ffurl_open(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Definition: avio.c:355
int(* url_delete)(URLContext *h)
Definition: url.h:97
static double c[64]
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:414
char * filename
specified URL
Definition: url.h:42
int av_opt_copy(void *dst, const void *src)
Copy options from src object into dest object.
Definition: opt.c:1703
#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
int avio_close_dir(AVIODirContext **s)
Close directory.
Definition: avio.c:588
#define av_free(p)
#define AVERROR_OPTION_NOT_FOUND
Option not found.
Definition: error.h:61
char * value
Definition: dict.h:87
int len
int avpriv_io_delete(const char *url)
Delete a resource.
Definition: avio.c:521
int max_packet_size
if non zero, the stream is packetized with this max packet size
Definition: url.h:44
int(* url_close)(URLContext *h)
Definition: url.h:81
#define av_freep(p)
void INT64 start
Definition: avisynth_c.h:690
unbuffered private I/O API
#define D
Definition: avio.c:55
int(* url_get_short_seek)(URLContext *h)
Definition: url.h:88
static const struct URLProtocol * url_find_protocol(const char *filename)
Definition: avio.c:251
int(* url_shutdown)(URLContext *h, int flags)
Definition: url.h:89
struct URLContext * url_context
Definition: avio.h:104
int priv_data_size
Definition: url.h:90
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:109
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:449
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:407