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