Libav
aviobuf.c
Go to the documentation of this file.
1 /*
2  * buffered I/O
3  * Copyright (c) 2000,2001 Fabrice Bellard
4  *
5  * This file is part of Libav.
6  *
7  * Libav 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  * Libav 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 Libav; 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/crc.h"
23 #include "libavutil/dict.h"
24 #include "libavutil/intreadwrite.h"
25 #include "libavutil/log.h"
26 #include "libavutil/opt.h"
27 #include "avformat.h"
28 #include "avio.h"
29 #include "avio_internal.h"
30 #include "internal.h"
31 #include "url.h"
32 #include <stdarg.h>
33 
34 #define IO_BUFFER_SIZE 32768
35 
41 #define SHORT_SEEK_THRESHOLD 4096
42 
43 typedef struct AVIOInternal {
44  const AVClass *class;
45 
48 
51 } AVIOInternal;
52 
53 static void *io_priv_child_next(void *obj, void *prev)
54 {
55  AVIOInternal *internal = obj;
56  return prev ? NULL : internal->h;
57 }
58 
59 static const AVClass *io_priv_child_class_next(const AVClass *prev)
60 {
61  return prev ? NULL : &ffurl_context_class;
62 }
63 
64 #define OFFSET(x) offsetof(AVIOInternal, x)
65 static const AVOption io_priv_options[] = {
66  { "protocol_whitelist", "A comma-separated list of allowed protocols",
68  { "protocol_blacklist", "A comma-separated list of forbidden protocols",
70  { NULL },
71 };
72 
73 static const AVClass io_priv_class = {
74  .class_name = "AVIOContext",
75  .item_name = av_default_item_name,
76  .version = LIBAVUTIL_VERSION_INT,
77  .option = io_priv_options,
78  .child_next = io_priv_child_next,
79  .child_class_next = io_priv_child_class_next,
80 };
81 
82 static void *ff_avio_child_next(void *obj, void *prev)
83 {
84  AVIOContext *s = obj;
85  return prev ? NULL : s->opaque;
86 }
87 
88 static const AVClass *ff_avio_child_class_next(const AVClass *prev)
89 {
90  return prev ? NULL : &io_priv_class;
91 }
92 
93 static const AVOption ff_avio_options[] = {
94  { NULL },
95 };
96 
98  .class_name = "AVIOContext",
99  .item_name = av_default_item_name,
100  .version = LIBAVUTIL_VERSION_INT,
101  .option = ff_avio_options,
102  .child_next = ff_avio_child_next,
103  .child_class_next = ff_avio_child_class_next,
104 };
105 
106 static void fill_buffer(AVIOContext *s);
107 static int url_resetbuf(AVIOContext *s, int flags);
108 
110  unsigned char *buffer,
111  int buffer_size,
112  int write_flag,
113  void *opaque,
114  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
115  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
116  int64_t (*seek)(void *opaque, int64_t offset, int whence))
117 {
118  s->buffer = buffer;
119  s->buffer_size = buffer_size;
120  s->buf_ptr = buffer;
121  s->opaque = opaque;
122 
123  url_resetbuf(s, write_flag ? AVIO_FLAG_WRITE : AVIO_FLAG_READ);
124 
127  s->seek = seek;
128  s->pos = 0;
129  s->must_flush = 0;
130  s->eof_reached = 0;
131  s->error = 0;
132  s->seekable = seek ? AVIO_SEEKABLE_NORMAL : 0;
133  s->max_packet_size = 0;
134  s->update_checksum = NULL;
135 
136  if (!read_packet && !write_flag) {
137  s->pos = buffer_size;
138  s->buf_end = s->buffer + buffer_size;
139  }
140  s->read_pause = NULL;
141  s->read_seek = NULL;
142 
143  s->write_data_type = NULL;
144  s->ignore_boundary_point = 0;
147 
148  return 0;
149 }
150 
152  unsigned char *buffer,
153  int buffer_size,
154  int write_flag,
155  void *opaque,
156  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
157  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
158  int64_t (*seek)(void *opaque, int64_t offset, int whence))
159 {
160  AVIOContext *s = av_mallocz(sizeof(AVIOContext));
161  if (!s)
162  return NULL;
163  ffio_init_context(s, buffer, buffer_size, write_flag, opaque,
164  read_packet, write_packet, seek);
165  return s;
166 }
167 
168 static void flush_buffer(AVIOContext *s)
169 {
170  if (s->buf_ptr > s->buffer) {
171  if (!s->error) {
172  int ret = 0;
173  if (s->write_data_type)
174  ret = s->write_data_type(s->opaque, s->buffer,
175  s->buf_ptr - s->buffer,
176  s->current_type,
177  s->last_time);
178  else if (s->write_packet)
179  ret = s->write_packet(s->opaque, s->buffer,
180  s->buf_ptr - s->buffer);
181  if (ret < 0) {
182  s->error = ret;
183  }
184  }
188  }
190  if (s->update_checksum) {
192  s->buf_ptr - s->checksum_ptr);
193  s->checksum_ptr = s->buffer;
194  }
195  s->pos += s->buf_ptr - s->buffer;
196  }
197  s->buf_ptr = s->buffer;
198 }
199 
200 void avio_w8(AVIOContext *s, int b)
201 {
202  *s->buf_ptr++ = b;
203  if (s->buf_ptr >= s->buf_end)
204  flush_buffer(s);
205 }
206 
207 void ffio_fill(AVIOContext *s, int b, int count)
208 {
209  while (count > 0) {
210  int len = FFMIN(s->buf_end - s->buf_ptr, count);
211  memset(s->buf_ptr, b, len);
212  s->buf_ptr += len;
213 
214  if (s->buf_ptr >= s->buf_end)
215  flush_buffer(s);
216 
217  count -= len;
218  }
219 }
220 
221 void avio_write(AVIOContext *s, const unsigned char *buf, int size)
222 {
223  while (size > 0) {
224  int len = FFMIN(s->buf_end - s->buf_ptr, size);
225  memcpy(s->buf_ptr, buf, len);
226  s->buf_ptr += len;
227 
228  if (s->buf_ptr >= s->buf_end)
229  flush_buffer(s);
230 
231  buf += len;
232  size -= len;
233  }
234 }
235 
237 {
238  flush_buffer(s);
239  s->must_flush = 0;
240 }
241 
242 int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
243 {
244  int64_t offset1;
245  int64_t pos;
246  int force = whence & AVSEEK_FORCE;
247  whence &= ~AVSEEK_FORCE;
248 
249  if(!s)
250  return AVERROR(EINVAL);
251 
252  pos = s->pos - (s->write_flag ? 0 : (s->buf_end - s->buffer));
253 
254  if (whence != SEEK_CUR && whence != SEEK_SET)
255  return AVERROR(EINVAL);
256 
257  if (whence == SEEK_CUR) {
258  offset1 = pos + (s->buf_ptr - s->buffer);
259  if (offset == 0)
260  return offset1;
261  offset += offset1;
262  }
263  offset1 = offset - pos;
264  if (!s->must_flush &&
265  offset1 >= 0 && offset1 < (s->buf_end - s->buffer)) {
266  /* can do the seek inside the buffer */
267  s->buf_ptr = s->buffer + offset1;
268  } else if ((!s->seekable ||
269  offset1 <= s->buf_end + SHORT_SEEK_THRESHOLD - s->buffer) &&
270  !s->write_flag && offset1 >= 0 &&
271  (whence != SEEK_END || force)) {
272  while(s->pos < offset && !s->eof_reached)
273  fill_buffer(s);
274  if (s->eof_reached)
275  return AVERROR_EOF;
276  s->buf_ptr = s->buf_end + offset - s->pos;
277  } else {
278  int64_t res;
279 
280  if (s->write_flag) {
281  flush_buffer(s);
282  s->must_flush = 1;
283  }
284  if (!s->seek)
285  return AVERROR(EPIPE);
286  if ((res = s->seek(s->opaque, offset, SEEK_SET)) < 0)
287  return res;
288  if (!s->write_flag)
289  s->buf_end = s->buffer;
290  s->buf_ptr = s->buffer;
291  s->pos = offset;
292  }
293  s->eof_reached = 0;
294  return offset;
295 }
296 
298 {
299  int64_t size;
300 
301  if (!s)
302  return AVERROR(EINVAL);
303 
304  if (!s->seek)
305  return AVERROR(ENOSYS);
306  size = s->seek(s->opaque, 0, AVSEEK_SIZE);
307  if (size < 0) {
308  if ((size = s->seek(s->opaque, -1, SEEK_END)) < 0)
309  return size;
310  size++;
311  s->seek(s->opaque, s->pos, SEEK_SET);
312  }
313  return size;
314 }
315 
316 void avio_wl32(AVIOContext *s, unsigned int val)
317 {
318  avio_w8(s, val);
319  avio_w8(s, val >> 8);
320  avio_w8(s, val >> 16);
321  avio_w8(s, val >> 24);
322 }
323 
324 void avio_wb32(AVIOContext *s, unsigned int val)
325 {
326  avio_w8(s, val >> 24);
327  avio_w8(s, val >> 16);
328  avio_w8(s, val >> 8);
329  avio_w8(s, val);
330 }
331 
332 int avio_put_str(AVIOContext *s, const char *str)
333 {
334  int len = 1;
335  if (str) {
336  len += strlen(str);
337  avio_write(s, (const unsigned char *) str, len);
338  } else
339  avio_w8(s, 0);
340  return len;
341 }
342 
343 #define PUT_STR16(type, write) \
344  int avio_put_str16 ## type(AVIOContext * s, const char *str) \
345  { \
346  const uint8_t *q = str; \
347  int ret = 0; \
348  \
349  while (*q) { \
350  uint32_t ch; \
351  uint16_t tmp; \
352  \
353  GET_UTF8(ch, *q++, break; ) \
354  PUT_UTF16(ch, tmp, write(s, tmp); ret += 2; ) \
355  } \
356  write(s, 0); \
357  ret += 2; \
358  return ret; \
359  }
360 
362 PUT_STR16(be, avio_wb16)
363 
364 #undef PUT_STR16
365 
366 int ff_get_v_length(uint64_t val)
367 {
368  int i = 1;
369 
370  while (val >>= 7)
371  i++;
372 
373  return i;
374 }
375 
376 void ff_put_v(AVIOContext *bc, uint64_t val)
377 {
378  int i = ff_get_v_length(val);
379 
380  while (--i > 0)
381  avio_w8(bc, 128 | (val >> (7 * i)));
382 
383  avio_w8(bc, val & 127);
384 }
385 
386 void avio_wl64(AVIOContext *s, uint64_t val)
387 {
388  avio_wl32(s, (uint32_t)(val & 0xffffffff));
389  avio_wl32(s, (uint32_t)(val >> 32));
390 }
391 
392 void avio_wb64(AVIOContext *s, uint64_t val)
393 {
394  avio_wb32(s, (uint32_t)(val >> 32));
395  avio_wb32(s, (uint32_t)(val & 0xffffffff));
396 }
397 
398 void avio_wl16(AVIOContext *s, unsigned int val)
399 {
400  avio_w8(s, val);
401  avio_w8(s, val >> 8);
402 }
403 
404 void avio_wb16(AVIOContext *s, unsigned int val)
405 {
406  avio_w8(s, val >> 8);
407  avio_w8(s, val);
408 }
409 
410 void avio_wl24(AVIOContext *s, unsigned int val)
411 {
412  avio_wl16(s, val & 0xffff);
413  avio_w8(s, val >> 16);
414 }
415 
416 void avio_wb24(AVIOContext *s, unsigned int val)
417 {
418  avio_wb16(s, val >> 8);
419  avio_w8(s, val);
420 }
421 
422 void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type)
423 {
424  if (!s->write_data_type)
425  return;
426  // If ignoring boundary points, just treat it as unknown
429  // Avoid unnecessary flushes if we are already in non-header/trailer
430  // data and setting the type to unknown
431  if (type == AVIO_DATA_MARKER_UNKNOWN &&
434  return;
435 
436  switch (type) {
439  // For header/trailer, ignore a new marker of the same type;
440  // consecutive header/trailer markers can be merged.
441  if (type == s->current_type)
442  return;
443  break;
444  }
445 
446  // If we've reached here, we have a new, noteworthy marker.
447  // Flush the previous data and mark the start of the new data.
448  avio_flush(s);
449  s->current_type = type;
450  s->last_time = time;
451 }
452 
453 /* Input stream */
454 
455 static void fill_buffer(AVIOContext *s)
456 {
457  uint8_t *dst = !s->max_packet_size &&
458  s->buf_end - s->buffer < s->buffer_size ?
459  s->buf_end : s->buffer;
460  int len = s->buffer_size - (dst - s->buffer);
461  int max_buffer_size = s->max_packet_size ?
463 
464  /* can't fill the buffer without read_packet, just set EOF if appropriate */
465  if (!s->read_packet && s->buf_ptr >= s->buf_end)
466  s->eof_reached = 1;
467 
468  /* no need to do anything if EOF already reached */
469  if (s->eof_reached)
470  return;
471 
472  if (s->update_checksum && dst == s->buffer) {
473  if (s->buf_end > s->checksum_ptr)
475  s->buf_end - s->checksum_ptr);
476  s->checksum_ptr = s->buffer;
477  }
478 
479  /* make buffer smaller in case it ended up large after probing */
480  if (s->buffer_size > max_buffer_size) {
481  ffio_set_buf_size(s, max_buffer_size);
482 
483  s->checksum_ptr = dst = s->buffer;
484  len = s->buffer_size;
485  }
486 
487  if (s->read_packet)
488  len = s->read_packet(s->opaque, dst, len);
489  else
490  len = 0;
491  if (len <= 0) {
492  /* do not modify buffer if EOF reached so that a seek back can
493  be done without rereading data */
494  s->eof_reached = 1;
495  if (len < 0)
496  s->error = len;
497  } else {
498  s->pos += len;
499  s->buf_ptr = dst;
500  s->buf_end = dst + len;
501  }
502 }
503 
504 unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf,
505  unsigned int len)
506 {
507  return av_crc(av_crc_get_table(AV_CRC_32_IEEE), checksum, buf, len);
508 }
509 
510 unsigned long ff_crcA001_update(unsigned long checksum, const uint8_t *buf,
511  unsigned int len)
512 {
513  return av_crc(av_crc_get_table(AV_CRC_16_ANSI_LE), checksum, buf, len);
514 }
515 
517 {
519  s->buf_ptr - s->checksum_ptr);
520  s->update_checksum = NULL;
521  return s->checksum;
522 }
523 
525  unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len),
526  unsigned long checksum)
527 {
528  s->update_checksum = update_checksum;
529  if (s->update_checksum) {
530  s->checksum = checksum;
531  s->checksum_ptr = s->buf_ptr;
532  }
533 }
534 
535 /* XXX: put an inline version */
537 {
538  if (s->buf_ptr >= s->buf_end)
539  fill_buffer(s);
540  if (s->buf_ptr < s->buf_end)
541  return *s->buf_ptr++;
542  return 0;
543 }
544 
545 int avio_read(AVIOContext *s, unsigned char *buf, int size)
546 {
547  int len, size1;
548 
549  size1 = size;
550  while (size > 0) {
551  len = s->buf_end - s->buf_ptr;
552  if (len > size)
553  len = size;
554  if (len == 0 || s->write_flag) {
555  if(size > s->buffer_size && !s->update_checksum){
556  if(s->read_packet)
557  len = s->read_packet(s->opaque, buf, size);
558  if (len <= 0) {
559  /* do not modify buffer if EOF reached so that a seek back can
560  be done without rereading data */
561  s->eof_reached = 1;
562  if(len<0)
563  s->error= len;
564  break;
565  } else {
566  s->pos += len;
567  size -= len;
568  buf += len;
569  s->buf_ptr = s->buffer;
570  s->buf_end = s->buffer/* + len*/;
571  }
572  } else {
573  fill_buffer(s);
574  len = s->buf_end - s->buf_ptr;
575  if (len == 0)
576  break;
577  }
578  } else {
579  memcpy(buf, s->buf_ptr, len);
580  buf += len;
581  s->buf_ptr += len;
582  size -= len;
583  }
584  }
585  if (size1 == size) {
586  if (s->error) return s->error;
587  if (s->eof_reached) return AVERROR_EOF;
588  }
589  return size1 - size;
590 }
591 
592 int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
593 {
594  int ret = avio_read(s, buf, size);
595  if (ret != size)
596  return AVERROR_INVALIDDATA;
597  return ret;
598 }
599 
600 int ffio_read_indirect(AVIOContext *s, unsigned char *buf, int size, const unsigned char **data)
601 {
602  if (s->buf_end - s->buf_ptr >= size && !s->write_flag) {
603  *data = s->buf_ptr;
604  s->buf_ptr += size;
605  return size;
606  } else {
607  *data = buf;
608  return avio_read(s, buf, size);
609  }
610 }
611 
612 int ffio_read_partial(AVIOContext *s, unsigned char *buf, int size)
613 {
614  int len;
615 
616  if (size < 0)
617  return -1;
618 
619  if (s->read_packet && s->write_flag) {
620  len = s->read_packet(s->opaque, buf, size);
621  if (len > 0)
622  s->pos += len;
623  return len;
624  }
625 
626  len = s->buf_end - s->buf_ptr;
627  if (len == 0) {
628  /* Reset the buf_end pointer to the start of the buffer, to make sure
629  * the fill_buffer call tries to read as much data as fits into the
630  * full buffer, instead of just what space is left after buf_end.
631  * This avoids returning partial packets at the end of the buffer,
632  * for packet based inputs.
633  */
634  s->buf_end = s->buf_ptr = s->buffer;
635  fill_buffer(s);
636  len = s->buf_end - s->buf_ptr;
637  }
638  if (len > size)
639  len = size;
640  memcpy(buf, s->buf_ptr, len);
641  s->buf_ptr += len;
642  if (!len) {
643  if (s->error) return s->error;
644  if (s->eof_reached) return AVERROR_EOF;
645  }
646  return len;
647 }
648 
649 unsigned int avio_rl16(AVIOContext *s)
650 {
651  unsigned int val;
652  val = avio_r8(s);
653  val |= avio_r8(s) << 8;
654  return val;
655 }
656 
657 unsigned int avio_rl24(AVIOContext *s)
658 {
659  unsigned int val;
660  val = avio_rl16(s);
661  val |= avio_r8(s) << 16;
662  return val;
663 }
664 
665 unsigned int avio_rl32(AVIOContext *s)
666 {
667  unsigned int val;
668  val = avio_rl16(s);
669  val |= avio_rl16(s) << 16;
670  return val;
671 }
672 
673 uint64_t avio_rl64(AVIOContext *s)
674 {
675  uint64_t val;
676  val = (uint64_t)avio_rl32(s);
677  val |= (uint64_t)avio_rl32(s) << 32;
678  return val;
679 }
680 
681 unsigned int avio_rb16(AVIOContext *s)
682 {
683  unsigned int val;
684  val = avio_r8(s) << 8;
685  val |= avio_r8(s);
686  return val;
687 }
688 
689 unsigned int avio_rb24(AVIOContext *s)
690 {
691  unsigned int val;
692  val = avio_rb16(s) << 8;
693  val |= avio_r8(s);
694  return val;
695 }
696 unsigned int avio_rb32(AVIOContext *s)
697 {
698  unsigned int val;
699  val = avio_rb16(s) << 16;
700  val |= avio_rb16(s);
701  return val;
702 }
703 
704 int ff_get_line(AVIOContext *s, char *buf, int maxlen)
705 {
706  int i = 0;
707  char c;
708 
709  do {
710  c = avio_r8(s);
711  if (c && i < maxlen-1)
712  buf[i++] = c;
713  } while (c != '\n' && c);
714 
715  buf[i] = 0;
716  return i;
717 }
718 
719 int avio_get_str(AVIOContext *s, int maxlen, char *buf, int buflen)
720 {
721  int i;
722 
723  if (buflen <= 0)
724  return AVERROR(EINVAL);
725  // reserve 1 byte for terminating 0
726  buflen = FFMIN(buflen - 1, maxlen);
727  for (i = 0; i < buflen; i++)
728  if (!(buf[i] = avio_r8(s)))
729  return i + 1;
730  buf[i] = 0;
731  for (; i < maxlen; i++)
732  if (!avio_r8(s))
733  return i + 1;
734  return maxlen;
735 }
736 
737 #define GET_STR16(type, read) \
738  int avio_get_str16 ##type(AVIOContext *pb, int maxlen, char *buf, int buflen)\
739 {\
740  char* q = buf;\
741  int ret = 0;\
742  if (buflen <= 0) \
743  return AVERROR(EINVAL); \
744  while (ret + 1 < maxlen) {\
745  uint8_t tmp;\
746  uint32_t ch;\
747  GET_UTF16(ch, (ret += 2) <= maxlen ? read(pb) : 0, break;)\
748  if (!ch)\
749  break;\
750  PUT_UTF8(ch, tmp, if (q - buf < buflen - 1) *q++ = tmp;)\
751  }\
752  *q = 0;\
753  return ret;\
754 }\
755 
757 GET_STR16(be, avio_rb16)
758 
759 #undef GET_STR16
760 
761 uint64_t avio_rb64(AVIOContext *s)
762 {
763  uint64_t val;
764  val = (uint64_t)avio_rb32(s) << 32;
765  val |= (uint64_t)avio_rb32(s);
766  return val;
767 }
768 
770  uint64_t val = 0;
771  int tmp;
772 
773  do{
774  tmp = avio_r8(bc);
775  val= (val<<7) + (tmp&127);
776  }while(tmp&128);
777  return val;
778 }
779 
780 static int io_read_packet(void *opaque, uint8_t *buf, int buf_size)
781 {
782  AVIOInternal *internal = opaque;
783  return ffurl_read(internal->h, buf, buf_size);
784 }
785 
786 static int io_write_packet(void *opaque, uint8_t *buf, int buf_size)
787 {
788  AVIOInternal *internal = opaque;
789  return ffurl_write(internal->h, buf, buf_size);
790 }
791 
792 static int64_t io_seek(void *opaque, int64_t offset, int whence)
793 {
794  AVIOInternal *internal = opaque;
795  return ffurl_seek(internal->h, offset, whence);
796 }
797 
798 static int io_read_pause(void *opaque, int pause)
799 {
800  AVIOInternal *internal = opaque;
801  if (!internal->h->prot->url_read_pause)
802  return AVERROR(ENOSYS);
803  return internal->h->prot->url_read_pause(internal->h, pause);
804 }
805 
806 static int64_t io_read_seek(void *opaque, int stream_index, int64_t timestamp, int flags)
807 {
808  AVIOInternal *internal = opaque;
809  if (!internal->h->prot->url_read_seek)
810  return AVERROR(ENOSYS);
811  return internal->h->prot->url_read_seek(internal->h, stream_index, timestamp, flags);
812 }
813 
815 {
816  AVIOInternal *internal = NULL;
817  uint8_t *buffer = NULL;
818  int buffer_size, max_packet_size;
819 
820  max_packet_size = h->max_packet_size;
821  if (max_packet_size) {
822  buffer_size = max_packet_size; /* no need to bufferize more than one packet */
823  } else {
824  buffer_size = IO_BUFFER_SIZE;
825  }
826  buffer = av_malloc(buffer_size);
827  if (!buffer)
828  return AVERROR(ENOMEM);
829 
830  internal = av_mallocz(sizeof(*internal));
831  if (!internal)
832  goto fail;
833 
834  internal->class = &io_priv_class;
835  internal->h = h;
836 
837  av_opt_set_defaults(internal);
838 
839  *s = avio_alloc_context(buffer, buffer_size, h->flags & AVIO_FLAG_WRITE,
841  if (!*s)
842  goto fail;
843 
844  (*s)->seekable = h->is_streamed ? 0 : AVIO_SEEKABLE_NORMAL;
845  (*s)->max_packet_size = max_packet_size;
846  if(h->prot) {
847  (*s)->read_pause = io_read_pause;
848  (*s)->read_seek = io_read_seek;
849  }
850  (*s)->av_class = &ff_avio_class;
851  return 0;
852 fail:
853  if (internal)
854  av_opt_free(internal);
855  av_freep(&internal);
856  av_freep(&buffer);
857  return AVERROR(ENOMEM);
858 }
859 
860 int ffio_set_buf_size(AVIOContext *s, int buf_size)
861 {
862  uint8_t *buffer;
863  buffer = av_malloc(buf_size);
864  if (!buffer)
865  return AVERROR(ENOMEM);
866 
867  av_free(s->buffer);
868  s->buffer = buffer;
869  s->buffer_size = buf_size;
870  s->buf_ptr = buffer;
872  return 0;
873 }
874 
875 static int url_resetbuf(AVIOContext *s, int flags)
876 {
877  assert(flags == AVIO_FLAG_WRITE || flags == AVIO_FLAG_READ);
878 
879  if (flags & AVIO_FLAG_WRITE) {
880  s->buf_end = s->buffer + s->buffer_size;
881  s->write_flag = 1;
882  } else {
883  s->buf_end = s->buffer;
884  s->write_flag = 0;
885  }
886  return 0;
887 }
888 
889 int ffio_rewind_with_probe_data(AVIOContext *s, unsigned char *buf, int buf_size)
890 {
891  int64_t buffer_start;
892  int buffer_size;
893  int overlap, new_size, alloc_size;
894 
895  if (s->write_flag)
896  return AVERROR(EINVAL);
897 
898  buffer_size = s->buf_end - s->buffer;
899 
900  /* the buffers must touch or overlap */
901  if ((buffer_start = s->pos - buffer_size) > buf_size)
902  return AVERROR(EINVAL);
903 
904  overlap = buf_size - buffer_start;
905  new_size = buf_size + buffer_size - overlap;
906 
907  alloc_size = FFMAX(s->buffer_size, new_size);
908  if (alloc_size > buf_size)
909  if (!(buf = av_realloc(buf, alloc_size)))
910  return AVERROR(ENOMEM);
911 
912  if (new_size > buf_size) {
913  memcpy(buf + buf_size, s->buffer + overlap, buffer_size - overlap);
914  buf_size = new_size;
915  }
916 
917  av_free(s->buffer);
918  s->buf_ptr = s->buffer = buf;
919  s->buffer_size = alloc_size;
920  s->pos = buf_size;
921  s->buf_end = s->buf_ptr + buf_size;
922  s->eof_reached = 0;
923  s->must_flush = 0;
924 
925  return 0;
926 }
927 
928 int avio_open(AVIOContext **s, const char *filename, int flags)
929 {
930  return avio_open2(s, filename, flags, NULL, NULL);
931 }
932 
933 int avio_open2(AVIOContext **s, const char *filename, int flags,
935 {
936  AVIOInternal *internal;
937  const URLProtocol **protocols;
938  char *proto_whitelist = NULL, *proto_blacklist = NULL;
940  URLContext *h;
941  int err;
942 
943  if (options) {
944  e = av_dict_get(*options, "protocol_whitelist", NULL, 0);
945  if (e)
946  proto_whitelist = e->value;
947  e = av_dict_get(*options, "protocol_blacklist", NULL, 0);
948  if (e)
949  proto_blacklist = e->value;
950  }
951 
952  protocols = ffurl_get_protocols(proto_whitelist, proto_blacklist);
953  if (!protocols)
954  return AVERROR(ENOMEM);
955 
956  err = ffurl_open(&h, filename, flags, int_cb, options, protocols, NULL);
957  if (err < 0) {
958  av_freep(&protocols);
959  return err;
960  }
961 
962  err = ffio_fdopen(s, h);
963  if (err < 0) {
964  ffurl_close(h);
965  av_freep(&protocols);
966  return err;
967  }
968 
969  internal = (*s)->opaque;
970  internal->protocols = protocols;
971 
972  if (options) {
973  err = av_opt_set_dict(internal, options);
974  if (err < 0) {
975  avio_closep(s);
976  return err;
977  }
978  }
979 
980  return 0;
981 }
982 
984 {
985  AVIOInternal *internal;
986  URLContext *h;
987 
988  if (!s)
989  return 0;
990 
991  avio_flush(s);
992  internal = s->opaque;
993  h = internal->h;
994 
995  av_opt_free(internal);
996 
997  av_freep(&internal->protocols);
998  av_freep(&s->opaque);
999  av_freep(&s->buffer);
1000  av_free(s);
1001  return ffurl_close(h);
1002 }
1003 
1005 {
1006  int ret = avio_close(*s);
1007  *s = NULL;
1008  return ret;
1009 }
1010 
1011 int avio_printf(AVIOContext *s, const char *fmt, ...)
1012 {
1013  va_list ap;
1014  char buf[4096];
1015  int ret;
1016 
1017  va_start(ap, fmt);
1018  ret = vsnprintf(buf, sizeof(buf), fmt, ap);
1019  va_end(ap);
1020  avio_write(s, buf, strlen(buf));
1021  return ret;
1022 }
1023 
1024 int avio_pause(AVIOContext *s, int pause)
1025 {
1026  if (!s->read_pause)
1027  return AVERROR(ENOSYS);
1028  return s->read_pause(s->opaque, pause);
1029 }
1030 
1031 int64_t avio_seek_time(AVIOContext *s, int stream_index,
1032  int64_t timestamp, int flags)
1033 {
1034  int64_t ret;
1035  if (!s->read_seek)
1036  return AVERROR(ENOSYS);
1037  ret = s->read_seek(s->opaque, stream_index, timestamp, flags);
1038  if (ret >= 0) {
1039  int64_t pos;
1040  s->buf_ptr = s->buf_end; // Flush buffer
1041  pos = s->seek(s->opaque, 0, SEEK_CUR);
1042  if (pos >= 0)
1043  s->pos = pos;
1044  else if (pos != AVERROR(ENOSYS))
1045  ret = pos;
1046  }
1047  return ret;
1048 }
1049 
1050 /* output in a dynamic buffer */
1051 
1052 typedef struct DynBuffer {
1053  int pos, size, allocated_size;
1056  uint8_t io_buffer[1];
1057 } DynBuffer;
1058 
1059 static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
1060 {
1061  DynBuffer *d = opaque;
1062  unsigned new_size, new_allocated_size;
1063 
1064  /* reallocate buffer if needed */
1065  new_size = d->pos + buf_size;
1066  new_allocated_size = d->allocated_size;
1067  if (new_size < d->pos || new_size > INT_MAX/2)
1068  return -1;
1069  while (new_size > new_allocated_size) {
1070  if (!new_allocated_size)
1071  new_allocated_size = new_size;
1072  else
1073  new_allocated_size += new_allocated_size / 2 + 1;
1074  }
1075 
1076  if (new_allocated_size > d->allocated_size) {
1077  int err;
1078  if ((err = av_reallocp(&d->buffer, new_allocated_size)) < 0) {
1079  d->allocated_size = 0;
1080  d->size = 0;
1081  return err;
1082  }
1083  d->allocated_size = new_allocated_size;
1084  }
1085  memcpy(d->buffer + d->pos, buf, buf_size);
1086  d->pos = new_size;
1087  if (d->pos > d->size)
1088  d->size = d->pos;
1089  return buf_size;
1090 }
1091 
1092 static int dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
1093 {
1094  unsigned char buf1[4];
1095  int ret;
1096 
1097  /* packetized write: output the header */
1098  AV_WB32(buf1, buf_size);
1099  ret = dyn_buf_write(opaque, buf1, 4);
1100  if (ret < 0)
1101  return ret;
1102 
1103  /* then the data */
1104  return dyn_buf_write(opaque, buf, buf_size);
1105 }
1106 
1107 static int64_t dyn_buf_seek(void *opaque, int64_t offset, int whence)
1108 {
1109  DynBuffer *d = opaque;
1110 
1111  if (whence == SEEK_CUR)
1112  offset += d->pos;
1113  else if (whence == SEEK_END)
1114  offset += d->size;
1115  if (offset < 0 || offset > 0x7fffffffLL)
1116  return -1;
1117  d->pos = offset;
1118  return 0;
1119 }
1120 
1121 static int url_open_dyn_buf_internal(AVIOContext **s, int max_packet_size)
1122 {
1123  DynBuffer *d;
1124  unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
1125 
1126  if (sizeof(DynBuffer) + io_buffer_size < io_buffer_size)
1127  return -1;
1128  d = av_mallocz(sizeof(DynBuffer) + io_buffer_size);
1129  if (!d)
1130  return AVERROR(ENOMEM);
1131  d->io_buffer_size = io_buffer_size;
1132  *s = avio_alloc_context(d->io_buffer, d->io_buffer_size, 1, d, NULL,
1133  max_packet_size ? dyn_packet_buf_write : dyn_buf_write,
1134  max_packet_size ? NULL : dyn_buf_seek);
1135  if(!*s) {
1136  av_free(d);
1137  return AVERROR(ENOMEM);
1138  }
1139  (*s)->max_packet_size = max_packet_size;
1140  return 0;
1141 }
1142 
1144 {
1145  return url_open_dyn_buf_internal(s, 0);
1146 }
1147 
1148 int ffio_open_dyn_packet_buf(AVIOContext **s, int max_packet_size)
1149 {
1150  if (max_packet_size <= 0)
1151  return -1;
1152  return url_open_dyn_buf_internal(s, max_packet_size);
1153 }
1154 
1156 {
1157  DynBuffer *d;
1158  int size;
1159  static const char padbuf[AV_INPUT_BUFFER_PADDING_SIZE] = {0};
1160  int padding = 0;
1161 
1162  if (!s) {
1163  *pbuffer = NULL;
1164  return 0;
1165  }
1166 
1167  /* don't attempt to pad fixed-size packet buffers */
1168  if (!s->max_packet_size) {
1169  avio_write(s, padbuf, sizeof(padbuf));
1170  padding = AV_INPUT_BUFFER_PADDING_SIZE;
1171  }
1172 
1173  avio_flush(s);
1174 
1175  d = s->opaque;
1176  *pbuffer = d->buffer;
1177  size = d->size;
1178  av_free(d);
1179  av_free(s);
1180  return size - padding;
1181 }
1182 
1184 {
1185  uint8_t *tmp;
1186  if (!*s)
1187  return;
1188  avio_close_dyn_buf(*s, &tmp);
1189  av_free(tmp);
1190  *s = NULL;
1191 }
1192 
1193 static int null_buf_write(void *opaque, uint8_t *buf, int buf_size)
1194 {
1195  DynBuffer *d = opaque;
1196 
1197  d->pos += buf_size;
1198  if (d->pos > d->size)
1199  d->size = d->pos;
1200  return buf_size;
1201 }
1202 
1204 {
1205  int ret = url_open_dyn_buf_internal(s, 0);
1206  if (ret >= 0) {
1207  AVIOContext *pb = *s;
1209  }
1210  return ret;
1211 }
1212 
1214 {
1215  DynBuffer *d = s->opaque;
1216  int size;
1217 
1218  avio_flush(s);
1219 
1220  size = d->size;
1221  av_free(d);
1222  av_free(s);
1223  return size;
1224 }
void avio_wl64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:386
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
AVIOContext * avio_alloc_context(unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
Allocate and initialize an AVIOContext for buffered I/O.
Definition: aviobuf.c:151
static int64_t dyn_buf_seek(void *opaque, int64_t offset, int whence)
Definition: aviobuf.c:1107
Bytestream IO Context.
Definition: avio.h:104
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
Buffered I/O operations.
uint64_t avio_rb64(AVIOContext *s)
Definition: aviobuf.c:761
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1143
int size
uint8_t io_buffer[1]
Definition: aviobuf.c:1056
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:404
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
Definition: crc.c:312
AVOption.
Definition: opt.h:234
static int64_t io_read_seek(void *opaque, int stream_index, int64_t timestamp, int flags)
Definition: aviobuf.c:806
int64_t last_time
Definition: avio.h:171
unsigned char * buf_ptr
Current position in the buffer.
Definition: avio.h:120
unsigned char * buf_end
End of the data, may be less than buffer+buffer_size if the read function returned less data than req...
Definition: avio.h:121
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:257
int write_flag
true if open for writing
Definition: avio.h:133
int is_streamed
true if streamed (no seek possible), default = false
Definition: url.h:49
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:599
int ffio_read_partial(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:612
void ffio_fill(AVIOContext *s, int b, int count)
Definition: aviobuf.c:207
#define AVIO_FLAG_READ
read-only
Definition: avio.h:368
unsigned int avio_rl24(AVIOContext *s)
Definition: aviobuf.c:657
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:369
unsigned char * buffer
Start of the buffer.
Definition: avio.h:118
#define OFFSET(x)
Definition: aviobuf.c:64
void avio_wl24(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:410
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:200
int flags
Definition: url.h:47
int avio_closep(AVIOContext **s)
Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL...
Definition: aviobuf.c:1004
void * opaque
A private pointer, passed to the read/write/seek/...
Definition: avio.h:125
const URLProtocol ** protocols
Definition: aviobuf.c:50
static void * io_priv_child_next(void *obj, void *prev)
Definition: aviobuf.c:53
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:324
#define IO_BUFFER_SIZE
Definition: aviobuf.c:34
static const AVClass * ff_avio_child_class_next(const AVClass *prev)
Definition: aviobuf.c:88
#define AV_WB32(p, val)
Definition: intreadwrite.h:246
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:202
static int io_read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:780
Trailer data, which doesn&#39;t contain actual content, but only for finalizing the output file...
Definition: avio.h:89
URLContext * h
Definition: aviobuf.c:49
int avio_put_str(AVIOContext *s, const char *str)
Write a NULL-terminated string.
Definition: aviobuf.c:332
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:316
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:39
Public dictionary API.
static char buffer[20]
Definition: seek.c:32
uint8_t
AVOptions.
static void fill_buffer(AVIOContext *s)
Definition: aviobuf.c:455
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
Definition: crc.c:298
static int io_read_pause(void *opaque, int pause)
Definition: aviobuf.c:798
#define b
Definition: input.c:52
unsigned long ffio_get_checksum(AVIOContext *s)
Definition: aviobuf.c:516
void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type)
Mark the written bytestream as a specific type.
Definition: aviobuf.c:422
void avio_flush(AVIOContext *s)
Definition: aviobuf.c:236
int ffio_open_null_buf(AVIOContext **s)
Open a write-only fake memory stream.
Definition: aviobuf.c:1203
int ffio_init_context(AVIOContext *s, unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
Definition: aviobuf.c:109
A point in the output bytestream where a demuxer can start parsing (for non self synchronizing bytest...
Definition: avio.h:77
const char data[16]
Definition: mxf.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:38
int av_reallocp(void *ptr, size_t size)
Allocate or reallocate a block of memory.
Definition: mem.c:140
static int flags
Definition: log.c:50
#define AVERROR_EOF
End of file.
Definition: error.h:51
int ffio_set_buf_size(AVIOContext *s, int buf_size)
Definition: aviobuf.c:860
int ffio_read_indirect(AVIOContext *s, unsigned char *buf, int size, const unsigned char **data)
Read size bytes from AVIOContext, returning a pointer.
Definition: aviobuf.c:600
int ffurl_open(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const URLProtocol **protocols, URLContext *parent)
Create an URLContext for accessing to the resource indicated by url, and open it. ...
Definition: avio.c:175
void avio_wb24(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:416
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:398
const OptionDef options[]
Definition: avconv_opt.c:2447
static void flush_buffer(AVIOContext *s)
Definition: aviobuf.c:168
int max_packet_size
Definition: avio.h:134
Callback for checking whether to abort blocking functions.
Definition: avio.h:51
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:190
int io_buffer_size
Definition: aviobuf.c:1055
unsigned int avio_rb24(AVIOContext *s)
Definition: aviobuf.c:689
static int dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:1092
static const AVOption ff_avio_options[]
Definition: aviobuf.c:93
#define AVERROR(e)
Definition: error.h:43
unsigned long checksum
Definition: avio.h:135
static void * ff_avio_child_next(void *obj, void *prev)
Definition: aviobuf.c:82
#define SHORT_SEEK_THRESHOLD
Do seeks within this distance ahead of the current buffer by skipping data instead of calling the pro...
Definition: aviobuf.c:41
#define FFMAX(a, b)
Definition: common.h:64
#define fail()
Definition: checkasm.h:80
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:649
int avio_pause(AVIOContext *s, int pause)
Pause and resume playing - only meaningful if using a network streaming protocol (e.g.
Definition: aviobuf.c:1024
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:665
char * protocol_blacklist
Definition: aviobuf.c:47
This is any, unlabelled data.
Definition: avio.h:84
int size
Definition: aviobuf.c:1053
int(* read_packet)(void *opaque, uint8_t *buf, int buf_size)
Definition: avio.h:127
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:153
int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:592
const AVIOInterruptCB int_cb
Definition: avconv.c:140
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:242
#define FFMIN(a, b)
Definition: common.h:66
const AVClass ff_avio_class
Definition: aviobuf.c:97
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1155
unsigned char * checksum_ptr
Definition: avio.h:136
int avio_printf(AVIOContext *s, const char *fmt,...)
Definition: aviobuf.c:1011
AVIODataMarkerType
Different data types that can be returned via the AVIO write_data_type callback.
Definition: avio.h:60
int64_t(* seek)(void *opaque, int64_t offset, int whence)
Definition: avio.h:129
int allocated_size
Definition: aviobuf.c:1053
int must_flush
true if the next seek should flush
Definition: avio.h:131
static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:1059
int ff_get_line(AVIOContext *s, char *buf, int maxlen)
Read a whole line of text from AVIOContext.
Definition: aviobuf.c:704
#define GET_STR16(type, read)
Definition: aviobuf.c:737
static volatile int checksum
Definition: adler32.c:27
int buffer_size
Maximum buffer size.
Definition: avio.h:119
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
void avio_wb64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:392
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:545
#define PUT_STR16(type, write)
Definition: aviobuf.c:343
uint8_t le
Definition: crc.c:251
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:38
NULL
Definition: eval.c:55
int ffio_open_dyn_packet_buf(AVIOContext **s, int max_packet_size)
Open a write only packetized memory stream with a maximum packet size of &#39;max_packet_size&#39;.
Definition: aviobuf.c:1148
int av_opt_set_dict(void *obj, AVDictionary **options)
Definition: opt.c:735
int avio_open(AVIOContext **s, const char *filename, int flags)
Create and initialize a AVIOContext for accessing the resource indicated by url.
Definition: aviobuf.c:928
av_default_item_name
Definition: dnxhdenc.c:55
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost)
Definition: avconv.c:278
static int url_resetbuf(AVIOContext *s, int flags)
Definition: aviobuf.c:875
uint64_t avio_rl64(AVIOContext *s)
Definition: aviobuf.c:673
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: aviobuf.c:983
int(* write_packet)(void *opaque, uint8_t *buf, int buf_size)
Definition: avio.h:128
Definition: url.h:38
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
Definition: libcdio.c:114
Describe the class of an AVClass context structure.
Definition: log.h:34
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:221
#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:274
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:681
int pos
Definition: aviobuf.c:1053
int ignore_boundary_point
If set, don&#39;t call write_data_type separately for AVIO_DATA_MARKER_BOUNDARY_POINT, but ignore them and treat them as AVIO_DATA_MARKER_UNKNOWN (to avoid needlessly small chunks of data returned from the callback).
Definition: avio.h:165
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
Definition: aviobuf.c:1183
int error
contains the error code or 0 if no error happened
Definition: avio.h:138
static const AVClass io_priv_class
Definition: aviobuf.c:73
int ffio_rewind_with_probe_data(AVIOContext *s, unsigned char *buf, int buf_size)
Rewind the AVIOContext using the specified buffer containing the first buf_size bytes of the file...
Definition: aviobuf.c:889
static const AVOption io_priv_options[]
Definition: aviobuf.c:65
int ff_get_v_length(uint64_t val)
Get the length in bytes which is needed to store val as v.
Definition: aviobuf.c:366
int ffurl_close(URLContext *h)
Close the resource accessed by the URLContext h, and free the memory used by it.
Definition: avio.c:280
const AVClass ffurl_context_class
Definition: avio.c:56
enum AVIODataMarkerType current_type
Internal, not meant to be used from outside of AVIOContext.
Definition: avio.h:170
int avio_open2(AVIOContext **s, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create and initialize a AVIOContext for accessing the resource indicated by url.
Definition: aviobuf.c:933
int(* read_pause)(void *opaque, int pause)
Pause or resume playback for network streaming protocols - e.g.
Definition: avio.h:142
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:297
Main libavformat public API header.
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:715
int avio_get_str(AVIOContext *s, int maxlen, char *buf, int buflen)
Read a string from pb into buf.
Definition: aviobuf.c:719
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:270
const struct URLProtocol * prot
Definition: url.h:40
int(* write_data_type)(void *opaque, uint8_t *buf, int buf_size, enum AVIODataMarkerType type, int64_t time)
A callback that is used instead of write_packet.
Definition: avio.h:158
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
Definition: mem.c:117
unsigned long(* update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size)
Definition: avio.h:137
int ffio_fdopen(AVIOContext **s, URLContext *h)
Create and initialize a AVIOContext for accessing the resource referenced by the URLContext h...
Definition: aviobuf.c:814
void ffio_init_checksum(AVIOContext *s, unsigned long(*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum)
Definition: aviobuf.c:524
int64_t pos
position in the file of the current buffer
Definition: avio.h:130
#define AVSEEK_SIZE
ORing this as the "whence" parameter to a seek function causes it to return the filesize without seek...
Definition: avio.h:266
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:638
uint64_t ffio_read_varlen(AVIOContext *bc)
Definition: aviobuf.c:769
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:696
A point in the output bytestream where a decoder can start decoding (i.e.
Definition: avio.h:71
uint8_t * buffer
Definition: aviobuf.c:1054
char * value
Definition: dict.h:74
int eof_reached
true if eof reached
Definition: avio.h:132
static int io_write_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:786
void ff_put_v(AVIOContext *bc, uint64_t val)
Put val using a variable number of bytes.
Definition: aviobuf.c:376
int len
int ffio_close_null_buf(AVIOContext *s)
Close a null buffer.
Definition: aviobuf.c:1213
static int null_buf_write(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:1193
static uint8_t tmp[8]
Definition: des.c:38
static int url_open_dyn_buf_internal(AVIOContext **s, int max_packet_size)
Definition: aviobuf.c:1121
int max_packet_size
if non zero, the stream is packetized with this max packet size
Definition: url.h:48
unbuffered private I/O API
char * protocol_whitelist
Definition: aviobuf.c:46
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:504
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:536
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:98
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:243
int64_t(* read_seek)(void *opaque, int stream_index, int64_t timestamp, int flags)
Seek to a given timestamp in stream with the specified stream_index.
Definition: avio.h:148
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:211
static int64_t io_seek(void *opaque, int64_t offset, int whence)
Definition: aviobuf.c:792
Header data; this needs to be present for the stream to be decodeable.
Definition: avio.h:64
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:235
int64_t avio_seek_time(AVIOContext *s, int stream_index, int64_t timestamp, int flags)
Seek to a given timestamp relative to some component stream.
Definition: aviobuf.c:1031
unsigned long ff_crcA001_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:510
static const AVClass * io_priv_child_class_next(const AVClass *prev)
Definition: aviobuf.c:59