FFmpeg
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 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/bprint.h"
23 #include "libavutil/crc.h"
24 #include "libavutil/dict.h"
25 #include "libavutil/intreadwrite.h"
26 #include "libavutil/log.h"
27 #include "libavutil/opt.h"
28 #include "libavutil/avassert.h"
29 #include "libavcodec/defs.h"
30 #include "avio.h"
31 #include "avio_internal.h"
32 #include "internal.h"
33 #include "url.h"
34 #include <stdarg.h>
35 
36 #define IO_BUFFER_SIZE 32768
37 
38 /**
39  * Do seeks within this distance ahead of the current buffer by skipping
40  * data instead of calling the protocol seek function, for seekable
41  * protocols.
42  */
43 #define SHORT_SEEK_THRESHOLD 32768
44 
45 static void *ff_avio_child_next(void *obj, void *prev)
46 {
47  AVIOContext *s = obj;
48  return prev ? NULL : s->opaque;
49 }
50 
51 static const AVClass *child_class_iterate(void **iter)
52 {
53  const AVClass *c = *iter ? NULL : &ffurl_context_class;
54  *iter = (void*)(uintptr_t)c;
55  return c;
56 }
57 
58 #define OFFSET(x) offsetof(AVIOContext,x)
59 #define E AV_OPT_FLAG_ENCODING_PARAM
60 #define D AV_OPT_FLAG_DECODING_PARAM
61 static const AVOption ff_avio_options[] = {
62  {"protocol_whitelist", "List of protocols that are allowed to be used", OFFSET(protocol_whitelist), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, D },
63  { NULL },
64 };
65 
67  .class_name = "AVIOContext",
68  .item_name = av_default_item_name,
69  .version = LIBAVUTIL_VERSION_INT,
70  .option = ff_avio_options,
71  .child_next = ff_avio_child_next,
72  .child_class_iterate = child_class_iterate,
73 };
74 
75 static void fill_buffer(AVIOContext *s);
76 static int url_resetbuf(AVIOContext *s, int flags);
77 /** @warning must be called before any I/O */
78 static int set_buf_size(AVIOContext *s, int buf_size);
79 
81  unsigned char *buffer,
82  int buffer_size,
83  int write_flag,
84  void *opaque,
85  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
86  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
87  int64_t (*seek)(void *opaque, int64_t offset, int whence))
88 {
89  AVIOContext *const s = &ctx->pub;
90 
91  memset(ctx, 0, sizeof(*ctx));
92 
93  s->buffer = buffer;
94  ctx->orig_buffer_size =
95  s->buffer_size = buffer_size;
96  s->buf_ptr = buffer;
97  s->buf_ptr_max = buffer;
98  s->opaque = opaque;
99  s->direct = 0;
100 
101  url_resetbuf(s, write_flag ? AVIO_FLAG_WRITE : AVIO_FLAG_READ);
102 
103  s->write_packet = write_packet;
104  s->read_packet = read_packet;
105  s->seek = seek;
106  s->pos = 0;
107  s->eof_reached = 0;
108  s->error = 0;
109  s->seekable = seek ? AVIO_SEEKABLE_NORMAL : 0;
110  s->min_packet_size = 0;
111  s->max_packet_size = 0;
112  s->update_checksum = NULL;
113  ctx->short_seek_threshold = SHORT_SEEK_THRESHOLD;
114 
115  if (!read_packet && !write_flag) {
116  s->pos = buffer_size;
117  s->buf_end = s->buffer + buffer_size;
118  }
119  s->read_pause = NULL;
120  s->read_seek = NULL;
121 
122  s->write_data_type = NULL;
123  s->ignore_boundary_point = 0;
124  ctx->current_type = AVIO_DATA_MARKER_UNKNOWN;
125  ctx->last_time = AV_NOPTS_VALUE;
126  ctx->short_seek_get = NULL;
127  s->written = 0;
128 }
129 
131  unsigned char *buffer,
132  int buffer_size,
133  int write_flag,
134  void *opaque,
135  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
136  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
137  int64_t (*seek)(void *opaque, int64_t offset, int whence))
138 {
139  FFIOContext *s = av_malloc(sizeof(*s));
140  if (!s)
141  return NULL;
142  ffio_init_context(s, buffer, buffer_size, write_flag, opaque,
143  read_packet, write_packet, seek);
144  return &s->pub;
145 }
146 
148 {
149  av_freep(ps);
150 }
151 
152 static void writeout(AVIOContext *s, const uint8_t *data, int len)
153 {
154  FFIOContext *const ctx = ffiocontext(s);
155  if (!s->error) {
156  int ret = 0;
157  if (s->write_data_type)
158  ret = s->write_data_type(s->opaque, (uint8_t *)data,
159  len,
160  ctx->current_type,
161  ctx->last_time);
162  else if (s->write_packet)
163  ret = s->write_packet(s->opaque, (uint8_t *)data, len);
164  if (ret < 0) {
165  s->error = ret;
166  } else {
167  if (s->pos + len > s->written)
168  s->written = s->pos + len;
169  }
170  }
171  if (ctx->current_type == AVIO_DATA_MARKER_SYNC_POINT ||
172  ctx->current_type == AVIO_DATA_MARKER_BOUNDARY_POINT) {
173  ctx->current_type = AVIO_DATA_MARKER_UNKNOWN;
174  }
175  ctx->last_time = AV_NOPTS_VALUE;
176  ctx->writeout_count++;
177  s->pos += len;
178 }
179 
181 {
182  s->buf_ptr_max = FFMAX(s->buf_ptr, s->buf_ptr_max);
183  if (s->write_flag && s->buf_ptr_max > s->buffer) {
184  writeout(s, s->buffer, s->buf_ptr_max - s->buffer);
185  if (s->update_checksum) {
186  s->checksum = s->update_checksum(s->checksum, s->checksum_ptr,
187  s->buf_ptr_max - s->checksum_ptr);
188  s->checksum_ptr = s->buffer;
189  }
190  }
191  s->buf_ptr = s->buf_ptr_max = s->buffer;
192  if (!s->write_flag)
193  s->buf_end = s->buffer;
194 }
195 
196 void avio_w8(AVIOContext *s, int b)
197 {
198  av_assert2(b>=-128 && b<=255);
199  *s->buf_ptr++ = b;
200  if (s->buf_ptr >= s->buf_end)
201  flush_buffer(s);
202 }
203 
204 void ffio_fill(AVIOContext *s, int b, int64_t count)
205 {
206  while (count > 0) {
207  int len = FFMIN(s->buf_end - s->buf_ptr, count);
208  memset(s->buf_ptr, b, len);
209  s->buf_ptr += len;
210 
211  if (s->buf_ptr >= s->buf_end)
212  flush_buffer(s);
213 
214  count -= len;
215  }
216 }
217 
218 void avio_write(AVIOContext *s, const unsigned char *buf, int size)
219 {
220  if (s->direct && !s->update_checksum) {
221  avio_flush(s);
222  writeout(s, buf, size);
223  return;
224  }
225  while (size > 0) {
226  int len = FFMIN(s->buf_end - s->buf_ptr, size);
227  memcpy(s->buf_ptr, buf, len);
228  s->buf_ptr += len;
229 
230  if (s->buf_ptr >= s->buf_end)
231  flush_buffer(s);
232 
233  buf += len;
234  size -= len;
235  }
236 }
237 
239 {
240  int seekback = s->write_flag ? FFMIN(0, s->buf_ptr - s->buf_ptr_max) : 0;
241  flush_buffer(s);
242  if (seekback)
243  avio_seek(s, seekback, SEEK_CUR);
244 }
245 
246 int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
247 {
248  FFIOContext *const ctx = ffiocontext(s);
249  int64_t offset1;
250  int64_t pos;
251  int force = whence & AVSEEK_FORCE;
252  int buffer_size;
253  int short_seek;
254  whence &= ~AVSEEK_FORCE;
255 
256  if(!s)
257  return AVERROR(EINVAL);
258 
259  if ((whence & AVSEEK_SIZE))
260  return s->seek ? s->seek(s->opaque, offset, AVSEEK_SIZE) : AVERROR(ENOSYS);
261 
262  buffer_size = s->buf_end - s->buffer;
263  // pos is the absolute position that the beginning of s->buffer corresponds to in the file
264  pos = s->pos - (s->write_flag ? 0 : buffer_size);
265 
266  if (whence != SEEK_CUR && whence != SEEK_SET)
267  return AVERROR(EINVAL);
268 
269  if (whence == SEEK_CUR) {
270  offset1 = pos + (s->buf_ptr - s->buffer);
271  if (offset == 0)
272  return offset1;
273  if (offset > INT64_MAX - offset1)
274  return AVERROR(EINVAL);
275  offset += offset1;
276  }
277  if (offset < 0)
278  return AVERROR(EINVAL);
279 
280  short_seek = ctx->short_seek_threshold;
281  if (ctx->short_seek_get) {
282  int tmp = ctx->short_seek_get(s->opaque);
283  short_seek = FFMAX(tmp, short_seek);
284  }
285 
286  offset1 = offset - pos; // "offset1" is the relative offset from the beginning of s->buffer
287  s->buf_ptr_max = FFMAX(s->buf_ptr_max, s->buf_ptr);
288  if ((!s->direct || !s->seek) &&
289  offset1 >= 0 && offset1 <= (s->write_flag ? s->buf_ptr_max - s->buffer : buffer_size)) {
290  /* can do the seek inside the buffer */
291  s->buf_ptr = s->buffer + offset1;
292  } else if ((!(s->seekable & AVIO_SEEKABLE_NORMAL) ||
293  offset1 <= buffer_size + short_seek) &&
294  !s->write_flag && offset1 >= 0 &&
295  (!s->direct || !s->seek) &&
296  (whence != SEEK_END || force)) {
297  while(s->pos < offset && !s->eof_reached)
298  fill_buffer(s);
299  if (s->eof_reached)
300  return AVERROR_EOF;
301  s->buf_ptr = s->buf_end - (s->pos - offset);
302  } else if(!s->write_flag && offset1 < 0 && -offset1 < buffer_size>>1 && s->seek && offset > 0) {
303  int64_t res;
304 
305  pos -= FFMIN(buffer_size>>1, pos);
306  if ((res = s->seek(s->opaque, pos, SEEK_SET)) < 0)
307  return res;
308  s->buf_end =
309  s->buf_ptr = s->buffer;
310  s->pos = pos;
311  s->eof_reached = 0;
312  fill_buffer(s);
313  return avio_seek(s, offset, SEEK_SET | force);
314  } else {
315  int64_t res;
316  if (s->write_flag) {
317  flush_buffer(s);
318  }
319  if (!s->seek)
320  return AVERROR(EPIPE);
321  if ((res = s->seek(s->opaque, offset, SEEK_SET)) < 0)
322  return res;
323  ctx->seek_count++;
324  if (!s->write_flag)
325  s->buf_end = s->buffer;
326  s->buf_ptr = s->buf_ptr_max = s->buffer;
327  s->pos = offset;
328  }
329  s->eof_reached = 0;
330  return offset;
331 }
332 
333 int64_t avio_skip(AVIOContext *s, int64_t offset)
334 {
335  return avio_seek(s, offset, SEEK_CUR);
336 }
337 
339 {
340  int64_t size;
341 
342  if (!s)
343  return AVERROR(EINVAL);
344 
345  if (s->written)
346  return s->written;
347 
348  if (!s->seek)
349  return AVERROR(ENOSYS);
350  size = s->seek(s->opaque, 0, AVSEEK_SIZE);
351  if (size < 0) {
352  if ((size = s->seek(s->opaque, -1, SEEK_END)) < 0)
353  return size;
354  size++;
355  s->seek(s->opaque, s->pos, SEEK_SET);
356  }
357  return size;
358 }
359 
361 {
362  if(!s)
363  return 0;
364  if(s->eof_reached){
365  s->eof_reached=0;
366  fill_buffer(s);
367  }
368  return s->eof_reached;
369 }
370 
371 void avio_wl32(AVIOContext *s, unsigned int val)
372 {
373  avio_w8(s, (uint8_t) val );
374  avio_w8(s, (uint8_t)(val >> 8 ));
375  avio_w8(s, (uint8_t)(val >> 16));
376  avio_w8(s, val >> 24 );
377 }
378 
379 void avio_wb32(AVIOContext *s, unsigned int val)
380 {
381  avio_w8(s, val >> 24 );
382  avio_w8(s, (uint8_t)(val >> 16));
383  avio_w8(s, (uint8_t)(val >> 8 ));
384  avio_w8(s, (uint8_t) val );
385 }
386 
387 int avio_put_str(AVIOContext *s, const char *str)
388 {
389  int len = 1;
390  if (str) {
391  len += strlen(str);
392  avio_write(s, (const unsigned char *) str, len);
393  } else
394  avio_w8(s, 0);
395  return len;
396 }
397 
398 static inline int put_str16(AVIOContext *s, const char *str, const int be)
399 {
400  const uint8_t *q = str;
401  int ret = 0;
402  int err = 0;
403 
404  while (*q) {
405  uint32_t ch;
406  uint16_t tmp;
407 
408  GET_UTF8(ch, *q++, goto invalid;)
409  PUT_UTF16(ch, tmp, be ? avio_wb16(s, tmp) : avio_wl16(s, tmp);
410  ret += 2;)
411  continue;
412 invalid:
413  av_log(s, AV_LOG_ERROR, "Invalid UTF8 sequence in avio_put_str16%s\n", be ? "be" : "le");
414  err = AVERROR(EINVAL);
415  if (!*(q-1))
416  break;
417  }
418  if (be)
419  avio_wb16(s, 0);
420  else
421  avio_wl16(s, 0);
422  if (err)
423  return err;
424  ret += 2;
425  return ret;
426 }
427 
428 #define PUT_STR16(type, big_endian) \
429 int avio_put_str16 ## type(AVIOContext *s, const char *str) \
430 { \
431 return put_str16(s, str, big_endian); \
432 }
433 
434 PUT_STR16(le, 0)
435 PUT_STR16(be, 1)
436 
437 #undef PUT_STR16
438 
439 void avio_wl64(AVIOContext *s, uint64_t val)
440 {
441  avio_wl32(s, (uint32_t)(val & 0xffffffff));
442  avio_wl32(s, (uint32_t)(val >> 32));
443 }
444 
445 void avio_wb64(AVIOContext *s, uint64_t val)
446 {
447  avio_wb32(s, (uint32_t)(val >> 32));
448  avio_wb32(s, (uint32_t)(val & 0xffffffff));
449 }
450 
451 void avio_wl16(AVIOContext *s, unsigned int val)
452 {
453  avio_w8(s, (uint8_t)val);
454  avio_w8(s, (int)val >> 8);
455 }
456 
457 void avio_wb16(AVIOContext *s, unsigned int val)
458 {
459  avio_w8(s, (int)val >> 8);
460  avio_w8(s, (uint8_t)val);
461 }
462 
463 void avio_wl24(AVIOContext *s, unsigned int val)
464 {
465  avio_wl16(s, val & 0xffff);
466  avio_w8(s, (int)val >> 16);
467 }
468 
469 void avio_wb24(AVIOContext *s, unsigned int val)
470 {
471  avio_wb16(s, (int)val >> 8);
472  avio_w8(s, (uint8_t)val);
473 }
474 
476 {
477  FFIOContext *const ctx = ffiocontext(s);
479  if (s->buf_ptr - s->buffer >= s->min_packet_size)
480  avio_flush(s);
481  return;
482  }
483  if (!s->write_data_type)
484  return;
485  // If ignoring boundary points, just treat it as unknown
486  if (type == AVIO_DATA_MARKER_BOUNDARY_POINT && s->ignore_boundary_point)
488  // Avoid unnecessary flushes if we are already in non-header/trailer
489  // data and setting the type to unknown
491  (ctx->current_type != AVIO_DATA_MARKER_HEADER &&
492  ctx->current_type != AVIO_DATA_MARKER_TRAILER))
493  return;
494 
495  switch (type) {
498  // For header/trailer, ignore a new marker of the same type;
499  // consecutive header/trailer markers can be merged.
500  if (type == ctx->current_type)
501  return;
502  break;
503  }
504 
505  // If we've reached here, we have a new, noteworthy marker.
506  // Flush the previous data and mark the start of the new data.
507  avio_flush(s);
508  ctx->current_type = type;
509  ctx->last_time = time;
510 }
511 
512 static int read_packet_wrapper(AVIOContext *s, uint8_t *buf, int size)
513 {
514  int ret;
515 
516  if (!s->read_packet)
517  return AVERROR(EINVAL);
518  ret = s->read_packet(s->opaque, buf, size);
519  av_assert2(ret || s->max_packet_size);
520  return ret;
521 }
522 
523 /* Input stream */
524 
525 static void fill_buffer(AVIOContext *s)
526 {
527  FFIOContext *const ctx = (FFIOContext *)s;
528  int max_buffer_size = s->max_packet_size ?
529  s->max_packet_size : IO_BUFFER_SIZE;
530  uint8_t *dst = s->buf_end - s->buffer + max_buffer_size <= s->buffer_size ?
531  s->buf_end : s->buffer;
532  int len = s->buffer_size - (dst - s->buffer);
533 
534  /* can't fill the buffer without read_packet, just set EOF if appropriate */
535  if (!s->read_packet && s->buf_ptr >= s->buf_end)
536  s->eof_reached = 1;
537 
538  /* no need to do anything if EOF already reached */
539  if (s->eof_reached)
540  return;
541 
542  if (s->update_checksum && dst == s->buffer) {
543  if (s->buf_end > s->checksum_ptr)
544  s->checksum = s->update_checksum(s->checksum, s->checksum_ptr,
545  s->buf_end - s->checksum_ptr);
546  s->checksum_ptr = s->buffer;
547  }
548 
549  /* make buffer smaller in case it ended up large after probing */
550  if (s->read_packet && ctx->orig_buffer_size &&
551  s->buffer_size > ctx->orig_buffer_size && len >= ctx->orig_buffer_size) {
552  if (dst == s->buffer && s->buf_ptr != dst) {
553  int ret = set_buf_size(s, ctx->orig_buffer_size);
554  if (ret < 0)
555  av_log(s, AV_LOG_WARNING, "Failed to decrease buffer size\n");
556 
557  s->checksum_ptr = dst = s->buffer;
558  }
559  len = ctx->orig_buffer_size;
560  }
561 
562  len = read_packet_wrapper(s, dst, len);
563  if (len == AVERROR_EOF) {
564  /* do not modify buffer if EOF reached so that a seek back can
565  be done without rereading data */
566  s->eof_reached = 1;
567  } else if (len < 0) {
568  s->eof_reached = 1;
569  s->error= len;
570  } else {
571  s->pos += len;
572  s->buf_ptr = dst;
573  s->buf_end = dst + len;
575  }
576 }
577 
578 unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf,
579  unsigned int len)
580 {
582 }
583 
584 unsigned long ff_crcEDB88320_update(unsigned long checksum, const uint8_t *buf,
585  unsigned int len)
586 {
588 }
589 
590 unsigned long ff_crcA001_update(unsigned long checksum, const uint8_t *buf,
591  unsigned int len)
592 {
594 }
595 
597 {
598  s->checksum = s->update_checksum(s->checksum, s->checksum_ptr,
599  s->buf_ptr - s->checksum_ptr);
600  s->update_checksum = NULL;
601  return s->checksum;
602 }
603 
605  unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len),
606  unsigned long checksum)
607 {
608  s->update_checksum = update_checksum;
609  if (s->update_checksum) {
610  s->checksum = checksum;
611  s->checksum_ptr = s->buf_ptr;
612  }
613 }
614 
615 /* XXX: put an inline version */
617 {
618  if (s->buf_ptr >= s->buf_end)
619  fill_buffer(s);
620  if (s->buf_ptr < s->buf_end)
621  return *s->buf_ptr++;
622  return 0;
623 }
624 
625 int avio_read(AVIOContext *s, unsigned char *buf, int size)
626 {
627  int len, size1;
628 
629  size1 = size;
630  while (size > 0) {
631  len = FFMIN(s->buf_end - s->buf_ptr, size);
632  if (len == 0 || s->write_flag) {
633  if((s->direct || size > s->buffer_size) && !s->update_checksum) {
634  // bypass the buffer and read data directly into buf
635  len = read_packet_wrapper(s, buf, size);
636  if (len == AVERROR_EOF) {
637  /* do not modify buffer if EOF reached so that a seek back can
638  be done without rereading data */
639  s->eof_reached = 1;
640  break;
641  } else if (len < 0) {
642  s->eof_reached = 1;
643  s->error= len;
644  break;
645  } else {
646  s->pos += len;
648  size -= len;
649  buf += len;
650  // reset the buffer
651  s->buf_ptr = s->buffer;
652  s->buf_end = s->buffer/* + len*/;
653  }
654  } else {
655  fill_buffer(s);
656  len = s->buf_end - s->buf_ptr;
657  if (len == 0)
658  break;
659  }
660  } else {
661  memcpy(buf, s->buf_ptr, len);
662  buf += len;
663  s->buf_ptr += len;
664  size -= len;
665  }
666  }
667  if (size1 == size) {
668  if (s->error) return s->error;
669  if (avio_feof(s)) return AVERROR_EOF;
670  }
671  return size1 - size;
672 }
673 
674 int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
675 {
676  int ret = avio_read(s, buf, size);
677  if (ret == size)
678  return ret;
679  if (ret < 0 && ret != AVERROR_EOF)
680  return ret;
681  return AVERROR_INVALIDDATA;
682 }
683 
684 int ffio_read_indirect(AVIOContext *s, unsigned char *buf, int size, const unsigned char **data)
685 {
686  if (s->buf_end - s->buf_ptr >= size && !s->write_flag) {
687  *data = s->buf_ptr;
688  s->buf_ptr += size;
689  return size;
690  } else {
691  *data = buf;
692  return avio_read(s, buf, size);
693  }
694 }
695 
696 int avio_read_partial(AVIOContext *s, unsigned char *buf, int size)
697 {
698  int len;
699 
700  if (size < 0)
701  return AVERROR(EINVAL);
702 
703  if (s->read_packet && s->write_flag) {
704  len = read_packet_wrapper(s, buf, size);
705  if (len > 0)
706  s->pos += len;
707  return len;
708  }
709 
710  len = s->buf_end - s->buf_ptr;
711  if (len == 0) {
712  fill_buffer(s);
713  len = s->buf_end - s->buf_ptr;
714  }
715  if (len > size)
716  len = size;
717  memcpy(buf, s->buf_ptr, len);
718  s->buf_ptr += len;
719  if (!len) {
720  if (s->error) return s->error;
721  if (avio_feof(s)) return AVERROR_EOF;
722  }
723  return len;
724 }
725 
726 unsigned int avio_rl16(AVIOContext *s)
727 {
728  unsigned int val;
729  val = avio_r8(s);
730  val |= avio_r8(s) << 8;
731  return val;
732 }
733 
734 unsigned int avio_rl24(AVIOContext *s)
735 {
736  unsigned int val;
737  val = avio_rl16(s);
738  val |= avio_r8(s) << 16;
739  return val;
740 }
741 
742 unsigned int avio_rl32(AVIOContext *s)
743 {
744  unsigned int val;
745  val = avio_rl16(s);
746  val |= avio_rl16(s) << 16;
747  return val;
748 }
749 
751 {
752  uint64_t val;
753  val = (uint64_t)avio_rl32(s);
754  val |= (uint64_t)avio_rl32(s) << 32;
755  return val;
756 }
757 
758 unsigned int avio_rb16(AVIOContext *s)
759 {
760  unsigned int val;
761  val = avio_r8(s) << 8;
762  val |= avio_r8(s);
763  return val;
764 }
765 
766 unsigned int avio_rb24(AVIOContext *s)
767 {
768  unsigned int val;
769  val = avio_rb16(s) << 8;
770  val |= avio_r8(s);
771  return val;
772 }
773 unsigned int avio_rb32(AVIOContext *s)
774 {
775  unsigned int val;
776  val = avio_rb16(s) << 16;
777  val |= avio_rb16(s);
778  return val;
779 }
780 
781 int ff_get_line(AVIOContext *s, char *buf, int maxlen)
782 {
783  int i = 0;
784  char c;
785 
786  do {
787  c = avio_r8(s);
788  if (c && i < maxlen-1)
789  buf[i++] = c;
790  } while (c != '\n' && c != '\r' && c);
791  if (c == '\r' && avio_r8(s) != '\n' && !avio_feof(s))
792  avio_skip(s, -1);
793 
794  buf[i] = 0;
795  return i;
796 }
797 
798 int ff_get_chomp_line(AVIOContext *s, char *buf, int maxlen)
799 {
800  int len = ff_get_line(s, buf, maxlen);
801  while (len > 0 && av_isspace(buf[len - 1]))
802  buf[--len] = '\0';
803  return len;
804 }
805 
810 
811 static int64_t read_string_to_bprint(AVIOContext *s, AVBPrint *bp,
813  int64_t max_len)
814 {
815  int len, end;
816  int64_t read = 0;
817  char tmp[1024];
818  char c;
819 
820  if (!max_len)
821  return 0;
822 
823  do {
824  len = 0;
825  do {
826  c = avio_r8(s);
827  end = ((mode == FFBPrintReadLine && (c == '\r' || c == '\n')) ||
828  c == '\0');
829  if (!end)
830  tmp[len++] = c;
831  } while (!end && len < sizeof(tmp) &&
832  ((max_len < 0) || (read + len < max_len)));
834  read += len;
835  } while (!end && ((max_len < 0) || (read < max_len)));
836 
837  if (mode == FFBPrintReadLine &&
838  c == '\r' && avio_r8(s) != '\n' && !avio_feof(s))
839  avio_skip(s, -1);
840 
841  if (!c && s->error)
842  return s->error;
843 
844  if (!c && !read && avio_feof(s))
845  return AVERROR_EOF;
846 
847  return read;
848 }
849 
850 static int64_t read_string_to_bprint_overwrite(AVIOContext *s, AVBPrint *bp,
852  int64_t max_len)
853 {
854  int64_t ret;
855 
856  av_bprint_clear(bp);
857  ret = read_string_to_bprint(s, bp, mode, max_len);
858  if (ret < 0)
859  return ret;
860 
861  if (!av_bprint_is_complete(bp))
862  return AVERROR(ENOMEM);
863 
864  return bp->len;
865 }
866 
868 {
870 }
871 
873  int64_t max_len)
874 {
876 }
877 
878 int avio_get_str(AVIOContext *s, int maxlen, char *buf, int buflen)
879 {
880  int i;
881 
882  if (buflen <= 0)
883  return AVERROR(EINVAL);
884  // reserve 1 byte for terminating 0
885  buflen = FFMIN(buflen - 1, maxlen);
886  for (i = 0; i < buflen; i++)
887  if (!(buf[i] = avio_r8(s)))
888  return i + 1;
889  buf[i] = 0;
890  for (; i < maxlen; i++)
891  if (!avio_r8(s))
892  return i + 1;
893  return maxlen;
894 }
895 
896 #define GET_STR16(type, read) \
897  int avio_get_str16 ##type(AVIOContext *pb, int maxlen, char *buf, int buflen)\
898 {\
899  char* q = buf;\
900  int ret = 0;\
901  if (buflen <= 0) \
902  return AVERROR(EINVAL); \
903  while (ret + 1 < maxlen) {\
904  uint8_t tmp;\
905  uint32_t ch;\
906  GET_UTF16(ch, (ret += 2) <= maxlen ? read(pb) : 0, break;)\
907  if (!ch)\
908  break;\
909  PUT_UTF8(ch, tmp, if (q - buf < buflen - 1) *q++ = tmp;)\
910  }\
911  *q = 0;\
912  return ret;\
913 }\
914 
915 GET_STR16(le, avio_rl16)
917 
918 #undef GET_STR16
919 
921 {
922  uint64_t val;
923  val = (uint64_t)avio_rb32(s) << 32;
924  val |= (uint64_t)avio_rb32(s);
925  return val;
926 }
927 
929  uint64_t val = 0;
930  int tmp;
931 
932  do{
933  tmp = avio_r8(bc);
934  val= (val<<7) + (tmp&127);
935  }while(tmp&128);
936  return val;
937 }
938 
940 {
941  uint8_t *buffer = NULL;
942  int buffer_size, max_packet_size;
943 
944  max_packet_size = h->max_packet_size;
945  if (max_packet_size) {
946  buffer_size = max_packet_size; /* no need to bufferize more than one packet */
947  } else {
948  buffer_size = IO_BUFFER_SIZE;
949  }
950  if (!(h->flags & AVIO_FLAG_WRITE) && h->is_streamed) {
951  if (buffer_size > INT_MAX/2)
952  return AVERROR(EINVAL);
953  buffer_size *= 2;
954  }
955  buffer = av_malloc(buffer_size);
956  if (!buffer)
957  return AVERROR(ENOMEM);
958 
959  *s = avio_alloc_context(buffer, buffer_size, h->flags & AVIO_FLAG_WRITE, h,
960  (int (*)(void *, uint8_t *, int)) ffurl_read,
961  (int (*)(void *, uint8_t *, int)) ffurl_write,
962  (int64_t (*)(void *, int64_t, int))ffurl_seek);
963  if (!*s)
964  goto fail;
965 
966  (*s)->protocol_whitelist = av_strdup(h->protocol_whitelist);
967  if (!(*s)->protocol_whitelist && h->protocol_whitelist) {
968  avio_closep(s);
969  goto fail;
970  }
971  (*s)->protocol_blacklist = av_strdup(h->protocol_blacklist);
972  if (!(*s)->protocol_blacklist && h->protocol_blacklist) {
973  avio_closep(s);
974  goto fail;
975  }
976  (*s)->direct = h->flags & AVIO_FLAG_DIRECT;
977 
978  (*s)->seekable = h->is_streamed ? 0 : AVIO_SEEKABLE_NORMAL;
979  (*s)->max_packet_size = max_packet_size;
980  (*s)->min_packet_size = h->min_packet_size;
981  if(h->prot) {
982  (*s)->read_pause = (int (*)(void *, int))h->prot->url_read_pause;
983  (*s)->read_seek =
984  (int64_t (*)(void *, int, int64_t, int))h->prot->url_read_seek;
985 
986  if (h->prot->url_read_seek)
987  (*s)->seekable |= AVIO_SEEKABLE_TIME;
988  }
989  ((FFIOContext*)(*s))->short_seek_get = (int (*)(void *))ffurl_get_short_seek;
990  (*s)->av_class = &ff_avio_class;
991  return 0;
992 fail:
993  av_freep(&buffer);
994  return AVERROR(ENOMEM);
995 }
996 
998 {
999  if (!s)
1000  return NULL;
1001 
1002  if (s->opaque && s->read_packet == (int (*)(void *, uint8_t *, int))ffurl_read)
1003  return s->opaque;
1004  else
1005  return NULL;
1006 }
1007 
1009 {
1010  if (s->update_checksum && s->buf_ptr > s->checksum_ptr) {
1011  s->checksum = s->update_checksum(s->checksum, s->checksum_ptr,
1012  s->buf_ptr - s->checksum_ptr);
1013  }
1014 }
1015 
1016 int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
1017 {
1018  uint8_t *buffer;
1019  int max_buffer_size = s->max_packet_size ?
1020  s->max_packet_size : IO_BUFFER_SIZE;
1021  ptrdiff_t filled = s->buf_end - s->buf_ptr;
1022 
1023  if (buf_size <= s->buf_end - s->buf_ptr)
1024  return 0;
1025 
1026  buf_size += max_buffer_size - 1;
1027 
1028  if (buf_size + s->buf_ptr - s->buffer <= s->buffer_size || s->seekable || !s->read_packet)
1029  return 0;
1030  av_assert0(!s->write_flag);
1031 
1032  if (buf_size <= s->buffer_size) {
1033  update_checksum(s);
1034  memmove(s->buffer, s->buf_ptr, filled);
1035  } else {
1036  buffer = av_malloc(buf_size);
1037  if (!buffer)
1038  return AVERROR(ENOMEM);
1039  update_checksum(s);
1040  memcpy(buffer, s->buf_ptr, filled);
1041  av_free(s->buffer);
1042  s->buffer = buffer;
1043  s->buffer_size = buf_size;
1044  }
1045  s->buf_ptr = s->buffer;
1046  s->buf_end = s->buffer + filled;
1047  s->checksum_ptr = s->buffer;
1048  return 0;
1049 }
1050 
1052 {
1053  FFIOContext *const ctx = ffiocontext(s);
1054  if (ctx->maxsize >= 0) {
1055  int64_t pos = avio_tell(s);
1056  int64_t remaining = ctx->maxsize - pos;
1057  if (remaining < size) {
1058  int64_t newsize = avio_size(s);
1059  if (!ctx->maxsize || ctx->maxsize < newsize)
1060  ctx->maxsize = newsize - !newsize;
1061  if (pos > ctx->maxsize && ctx->maxsize >= 0)
1062  ctx->maxsize = AVERROR(EIO);
1063  if (ctx->maxsize >= 0)
1064  remaining = ctx->maxsize - pos;
1065  }
1066 
1067  if (ctx->maxsize >= 0 && remaining < size && size > 1) {
1068  av_log(NULL, remaining ? AV_LOG_ERROR : AV_LOG_DEBUG,
1069  "Truncating packet of size %d to %"PRId64"\n",
1070  size, remaining + !remaining);
1071  size = remaining + !remaining;
1072  }
1073  }
1074  return size;
1075 }
1076 
1077 static int set_buf_size(AVIOContext *s, int buf_size)
1078 {
1079  uint8_t *buffer;
1080  buffer = av_malloc(buf_size);
1081  if (!buffer)
1082  return AVERROR(ENOMEM);
1083 
1084  av_free(s->buffer);
1085  s->buffer = buffer;
1087  s->buffer_size = buf_size;
1088  s->buf_ptr = s->buf_ptr_max = buffer;
1089  url_resetbuf(s, s->write_flag ? AVIO_FLAG_WRITE : AVIO_FLAG_READ);
1090  return 0;
1091 }
1092 
1093 int ffio_realloc_buf(AVIOContext *s, int buf_size)
1094 {
1095  uint8_t *buffer;
1096  int data_size;
1097 
1098  if (!s->buffer_size)
1099  return set_buf_size(s, buf_size);
1100 
1101  if (buf_size <= s->buffer_size)
1102  return 0;
1103 
1104  buffer = av_malloc(buf_size);
1105  if (!buffer)
1106  return AVERROR(ENOMEM);
1107 
1108  data_size = s->write_flag ? (s->buf_ptr - s->buffer) : (s->buf_end - s->buf_ptr);
1109  if (data_size > 0)
1110  memcpy(buffer, s->write_flag ? s->buffer : s->buf_ptr, data_size);
1111  av_free(s->buffer);
1112  s->buffer = buffer;
1113  ffiocontext(s)->orig_buffer_size = buf_size;
1114  s->buffer_size = buf_size;
1115  s->buf_ptr = s->write_flag ? (s->buffer + data_size) : s->buffer;
1116  if (s->write_flag)
1117  s->buf_ptr_max = s->buffer + data_size;
1118 
1119  s->buf_end = s->write_flag ? (s->buffer + s->buffer_size) : (s->buf_ptr + data_size);
1120 
1121  return 0;
1122 }
1123 
1124 static int url_resetbuf(AVIOContext *s, int flags)
1125 {
1127 
1128  if (flags & AVIO_FLAG_WRITE) {
1129  s->buf_end = s->buffer + s->buffer_size;
1130  s->write_flag = 1;
1131  } else {
1132  s->buf_end = s->buffer;
1133  s->write_flag = 0;
1134  }
1135  return 0;
1136 }
1137 
1138 int ffio_rewind_with_probe_data(AVIOContext *s, unsigned char **bufp, int buf_size)
1139 {
1140  int64_t buffer_start;
1141  int buffer_size;
1142  int overlap, new_size, alloc_size;
1143  uint8_t *buf = *bufp;
1144 
1145  if (s->write_flag) {
1146  av_freep(bufp);
1147  return AVERROR(EINVAL);
1148  }
1149 
1150  buffer_size = s->buf_end - s->buffer;
1151 
1152  /* the buffers must touch or overlap */
1153  if ((buffer_start = s->pos - buffer_size) > buf_size) {
1154  av_freep(bufp);
1155  return AVERROR(EINVAL);
1156  }
1157 
1158  overlap = buf_size - buffer_start;
1159  new_size = buf_size + buffer_size - overlap;
1160 
1161  alloc_size = FFMAX(s->buffer_size, new_size);
1162  if (alloc_size > buf_size)
1163  if (!(buf = (*bufp) = av_realloc_f(buf, 1, alloc_size)))
1164  return AVERROR(ENOMEM);
1165 
1166  if (new_size > buf_size) {
1167  memcpy(buf + buf_size, s->buffer + overlap, buffer_size - overlap);
1168  buf_size = new_size;
1169  }
1170 
1171  av_free(s->buffer);
1172  s->buf_ptr = s->buffer = buf;
1173  s->buffer_size = alloc_size;
1174  s->pos = buf_size;
1175  s->buf_end = s->buf_ptr + buf_size;
1176  s->eof_reached = 0;
1177 
1178  return 0;
1179 }
1180 
1181 int avio_open(AVIOContext **s, const char *filename, int flags)
1182 {
1183  return avio_open2(s, filename, flags, NULL, NULL);
1184 }
1185 
1186 int ffio_open_whitelist(AVIOContext **s, const char *filename, int flags,
1188  const char *whitelist, const char *blacklist
1189  )
1190 {
1191  URLContext *h;
1192  int err;
1193 
1194  *s = NULL;
1195 
1196  err = ffurl_open_whitelist(&h, filename, flags, int_cb, options, whitelist, blacklist, NULL);
1197  if (err < 0)
1198  return err;
1199  err = ffio_fdopen(s, h);
1200  if (err < 0) {
1201  ffurl_close(h);
1202  return err;
1203  }
1204  return 0;
1205 }
1206 
1207 int avio_open2(AVIOContext **s, const char *filename, int flags,
1209 {
1210  return ffio_open_whitelist(s, filename, flags, int_cb, options, NULL, NULL);
1211 }
1212 
1214 {
1215  FFIOContext *const ctx = ffiocontext(s);
1216  URLContext *h;
1217 
1218  if (!s)
1219  return 0;
1220 
1221  avio_flush(s);
1222  h = s->opaque;
1223  s->opaque = NULL;
1224 
1225  av_freep(&s->buffer);
1226  if (s->write_flag)
1227  av_log(s, AV_LOG_VERBOSE, "Statistics: %d seeks, %d writeouts\n",
1228  ctx->seek_count, ctx->writeout_count);
1229  else
1230  av_log(s, AV_LOG_VERBOSE, "Statistics: %"PRId64" bytes read, %d seeks\n",
1231  ctx->bytes_read, ctx->seek_count);
1232  av_opt_free(s);
1233 
1234  avio_context_free(&s);
1235 
1236  return ffurl_close(h);
1237 }
1238 
1240 {
1241  int ret = avio_close(*s);
1242  *s = NULL;
1243  return ret;
1244 }
1245 
1246 int avio_printf(AVIOContext *s, const char *fmt, ...)
1247 {
1248  va_list ap;
1249  AVBPrint bp;
1250 
1251  av_bprint_init(&bp, 0, INT_MAX);
1252  va_start(ap, fmt);
1253  av_vbprintf(&bp, fmt, ap);
1254  va_end(ap);
1255  if (!av_bprint_is_complete(&bp)) {
1256  av_bprint_finalize(&bp, NULL);
1257  s->error = AVERROR(ENOMEM);
1258  return AVERROR(ENOMEM);
1259  }
1260  avio_write(s, bp.str, bp.len);
1261  av_bprint_finalize(&bp, NULL);
1262  return bp.len;
1263 }
1264 
1265 void avio_print_string_array(AVIOContext *s, const char *strings[])
1266 {
1267  for(; *strings; strings++)
1268  avio_write(s, (const unsigned char *)*strings, strlen(*strings));
1269 }
1270 
1271 int avio_pause(AVIOContext *s, int pause)
1272 {
1273  if (!s->read_pause)
1274  return AVERROR(ENOSYS);
1275  return s->read_pause(s->opaque, pause);
1276 }
1277 
1278 int64_t avio_seek_time(AVIOContext *s, int stream_index,
1279  int64_t timestamp, int flags)
1280 {
1281  int64_t ret;
1282  if (!s->read_seek)
1283  return AVERROR(ENOSYS);
1284  ret = s->read_seek(s->opaque, stream_index, timestamp, flags);
1285  if (ret >= 0) {
1286  int64_t pos;
1287  s->buf_ptr = s->buf_end; // Flush buffer
1288  pos = s->seek(s->opaque, 0, SEEK_CUR);
1289  if (pos >= 0)
1290  s->pos = pos;
1291  else if (pos != AVERROR(ENOSYS))
1292  ret = pos;
1293  }
1294  return ret;
1295 }
1296 
1297 int avio_read_to_bprint(AVIOContext *h, AVBPrint *pb, size_t max_size)
1298 {
1299  int ret;
1300  char buf[1024];
1301  while (max_size) {
1302  ret = avio_read(h, buf, FFMIN(max_size, sizeof(buf)));
1303  if (ret == AVERROR_EOF)
1304  return 0;
1305  if (ret <= 0)
1306  return ret;
1307  av_bprint_append_data(pb, buf, ret);
1308  if (!av_bprint_is_complete(pb))
1309  return AVERROR(ENOMEM);
1310  max_size -= ret;
1311  }
1312  return 0;
1313 }
1314 
1316 {
1317  int ret;
1318  URLContext *sc = s->opaque;
1319  URLContext *cc = NULL;
1320  ret = ffurl_accept(sc, &cc);
1321  if (ret < 0)
1322  return ret;
1323  return ffio_fdopen(c, cc);
1324 }
1325 
1327 {
1328  URLContext *cc = c->opaque;
1329  return ffurl_handshake(cc);
1330 }
1331 
1332 /* output in a dynamic buffer */
1333 
1334 typedef struct DynBuffer {
1336  uint8_t *buffer;
1338  uint8_t io_buffer[1];
1339 } DynBuffer;
1340 
1341 static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
1342 {
1343  DynBuffer *d = opaque;
1344  unsigned new_size;
1345 
1346  /* reallocate buffer if needed */
1347  new_size = (unsigned)d->pos + buf_size;
1348  if (new_size < d->pos || new_size > INT_MAX)
1349  return AVERROR(ERANGE);
1350  if (new_size > d->allocated_size) {
1351  unsigned new_allocated_size = d->allocated_size ? d->allocated_size
1352  : new_size;
1353  int err;
1354  while (new_size > new_allocated_size)
1355  new_allocated_size += new_allocated_size / 2 + 1;
1356 
1357  new_allocated_size = FFMIN(new_allocated_size, INT_MAX);
1358 
1359  if ((err = av_reallocp(&d->buffer, new_allocated_size)) < 0) {
1360  d->allocated_size = 0;
1361  d->size = 0;
1362  return err;
1363  }
1364  d->allocated_size = new_allocated_size;
1365  }
1366  memcpy(d->buffer + d->pos, buf, buf_size);
1367  d->pos = new_size;
1368  if (d->pos > d->size)
1369  d->size = d->pos;
1370  return buf_size;
1371 }
1372 
1373 static int dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
1374 {
1375  unsigned char buf1[4];
1376  int ret;
1377 
1378  /* packetized write: output the header */
1379  AV_WB32(buf1, buf_size);
1380  ret = dyn_buf_write(opaque, buf1, 4);
1381  if (ret < 0)
1382  return ret;
1383 
1384  /* then the data */
1385  return dyn_buf_write(opaque, buf, buf_size);
1386 }
1387 
1388 static int64_t dyn_buf_seek(void *opaque, int64_t offset, int whence)
1389 {
1390  DynBuffer *d = opaque;
1391 
1392  if (whence == SEEK_CUR)
1393  offset += d->pos;
1394  else if (whence == SEEK_END)
1395  offset += d->size;
1396  if (offset < 0)
1397  return AVERROR(EINVAL);
1398  if (offset > INT_MAX)
1399  return AVERROR(ERANGE);
1400  d->pos = offset;
1401  return 0;
1402 }
1403 
1404 static int url_open_dyn_buf_internal(AVIOContext **s, int max_packet_size)
1405 {
1406  struct { FFIOContext pb; DynBuffer d; } *ret;
1407  DynBuffer *d;
1408  unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
1409 
1410  if (sizeof(*ret) + io_buffer_size < io_buffer_size)
1411  return AVERROR(ERANGE);
1412  ret = av_mallocz(sizeof(*ret) + io_buffer_size);
1413  if (!ret)
1414  return AVERROR(ENOMEM);
1415  d = &ret->d;
1416  d->io_buffer_size = io_buffer_size;
1417  ffio_init_context(&ret->pb, d->io_buffer, d->io_buffer_size, 1, d, NULL,
1418  max_packet_size ? dyn_packet_buf_write : dyn_buf_write,
1419  max_packet_size ? NULL : dyn_buf_seek);
1420  *s = &ret->pb.pub;
1421  (*s)->max_packet_size = max_packet_size;
1422  return 0;
1423 }
1424 
1426 {
1427  return url_open_dyn_buf_internal(s, 0);
1428 }
1429 
1430 int ffio_open_dyn_packet_buf(AVIOContext **s, int max_packet_size)
1431 {
1432  if (max_packet_size <= 0)
1433  return AVERROR(EINVAL);
1434  return url_open_dyn_buf_internal(s, max_packet_size);
1435 }
1436 
1437 int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
1438 {
1439  DynBuffer *d;
1440 
1441  if (!s) {
1442  *pbuffer = NULL;
1443  return 0;
1444  }
1445  d = s->opaque;
1446 
1447  if (!s->error && !d->size) {
1448  *pbuffer = d->io_buffer;
1449  return FFMAX(s->buf_ptr, s->buf_ptr_max) - s->buffer;
1450  }
1451 
1452  avio_flush(s);
1453 
1454  *pbuffer = d->buffer;
1455 
1456  return d->size;
1457 }
1458 
1460 {
1461  DynBuffer *d = s->opaque;
1462  int max_packet_size = s->max_packet_size;
1463 
1464  ffio_init_context(ffiocontext(s), d->io_buffer, d->io_buffer_size,
1465  1, d, NULL, s->write_packet, s->seek);
1466  s->max_packet_size = max_packet_size;
1467  d->pos = d->size = 0;
1468 }
1469 
1470 int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
1471 {
1472  DynBuffer *d;
1473  int size;
1474  int padding = 0;
1475 
1476  if (!s) {
1477  *pbuffer = NULL;
1478  return 0;
1479  }
1480 
1481  /* don't attempt to pad fixed-size packet buffers */
1482  if (!s->max_packet_size) {
1484  padding = AV_INPUT_BUFFER_PADDING_SIZE;
1485  }
1486 
1487  avio_flush(s);
1488 
1489  d = s->opaque;
1490  *pbuffer = d->buffer;
1491  size = d->size;
1492 
1493  avio_context_free(&s);
1494 
1495  return size - padding;
1496 }
1497 
1499 {
1500  DynBuffer *d;
1501 
1502  if (!*s)
1503  return;
1504 
1505  d = (*s)->opaque;
1506  av_free(d->buffer);
1508 }
1509 
1510 static int null_buf_write(void *opaque, uint8_t *buf, int buf_size)
1511 {
1512  DynBuffer *d = opaque;
1513 
1514  d->pos += buf_size;
1515  if (d->pos > d->size)
1516  d->size = d->pos;
1517  return buf_size;
1518 }
1519 
1521 {
1522  int ret = url_open_dyn_buf_internal(s, 0);
1523  if (ret >= 0) {
1524  AVIOContext *pb = *s;
1526  }
1527  return ret;
1528 }
1529 
1531 {
1532  DynBuffer *d = s->opaque;
1533  int size;
1534 
1535  avio_flush(s);
1536 
1537  size = d->size;
1538 
1539  avio_context_free(&s);
1540 
1541  return size;
1542 }
ff_get_chomp_line
int ff_get_chomp_line(AVIOContext *s, char *buf, int maxlen)
Same as ff_get_line but strip the white-space characters in the text tail.
Definition: aviobuf.c:798
be
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it be(in the first position) for now. Options ------- Then comes the options array. This is what will define the user accessible options. For example
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
put_str16
static int put_str16(AVIOContext *s, const char *str, const int be)
Definition: aviobuf.c:398
avio_feof
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition: aviobuf.c:360
AVIO_DATA_MARKER_BOUNDARY_POINT
@ AVIO_DATA_MARKER_BOUNDARY_POINT
A point in the output bytestream where a demuxer can start parsing (for non self synchronizing bytest...
Definition: avio.h:128
null_buf_write
static int null_buf_write(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:1510
ffurl_context_class
const AVClass ffurl_context_class
Definition: avio.c:64
D
#define D
Definition: aviobuf.c:60
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
avio_get_dyn_buf
int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1437
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:234
url_open_dyn_buf_internal
static int url_open_dyn_buf_internal(AVIOContext **s, int max_packet_size)
Definition: aviobuf.c:1404
av_bprint_init
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:68
ffiocontext
static av_always_inline FFIOContext * ffiocontext(AVIOContext *ctx)
Definition: avio_internal.h:71
ffurl_seek
int64_t ffurl_seek(URLContext *h, int64_t pos, int whence)
Change the position that will be used by the next read/write operation on the resource accessed by h.
Definition: avio.c:428
avio_rl24
unsigned int avio_rl24(AVIOContext *s)
Definition: aviobuf.c:734
dyn_buf_seek
static int64_t dyn_buf_seek(void *opaque, int64_t offset, int whence)
Definition: aviobuf.c:1388
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
avio_wl24
void avio_wl24(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:463
av_isspace
static av_const int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
Definition: avstring.h:227
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:26
ffio_get_checksum
unsigned long ffio_get_checksum(AVIOContext *s)
Definition: aviobuf.c:596
DynBuffer::buffer
uint8_t * buffer
Definition: aviobuf.c:1336
ffio_open_null_buf
int ffio_open_null_buf(AVIOContext **s)
Open a write-only fake memory stream.
Definition: aviobuf.c:1520
ffio_geturlcontext
URLContext * ffio_geturlcontext(AVIOContext *s)
Return the URLContext associated with the AVIOContext.
Definition: aviobuf.c:997
AVOption
AVOption.
Definition: opt.h:247
b
#define b
Definition: input.c:40
AVSEEK_SIZE
#define AVSEEK_SIZE
ORing this as the "whence" parameter to a seek function causes it to return the filesize without seek...
Definition: avio.h:460
IO_BUFFER_SIZE
#define IO_BUFFER_SIZE
Definition: aviobuf.c:36
data
const char data[16]
Definition: mxf.c:143
avio_seek_time
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:1278
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
avio_accept
int avio_accept(AVIOContext *s, AVIOContext **c)
Accept and allocate a client context on a server context.
Definition: aviobuf.c:1315
ffurl_close
int ffurl_close(URLContext *h)
Definition: avio.c:461
DynBuffer::io_buffer
uint8_t io_buffer[1]
Definition: aviobuf.c:1338
avio_put_str
int avio_put_str(AVIOContext *s, const char *str)
Write a NULL-terminated string.
Definition: aviobuf.c:387
AVDictionary
Definition: dict.c:30
avio_wl32
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:371
av_bprint_append_data
void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size)
Append data to a print buffer.
Definition: bprint.c:157
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
avio_read_to_bprint
int avio_read_to_bprint(AVIOContext *h, AVBPrint *pb, size_t max_size)
Read contents of h into print buffer, up to max_size bytes, or up to EOF.
Definition: aviobuf.c:1297
ff_crcEDB88320_update
unsigned long ff_crcEDB88320_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:584
FFBPrintReadString
@ FFBPrintReadString
Definition: aviobuf.c:807
AVIODataMarkerType
AVIODataMarkerType
Different data types that can be returned via the AVIO write_data_type callback.
Definition: avio.h:111
FFIOContext
Definition: avio_internal.h:29
avio_w8
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:196
update_checksum
static void update_checksum(AVIOContext *s)
Definition: aviobuf.c:1008
fill_buffer
static void fill_buffer(AVIOContext *s)
Definition: aviobuf.c:525
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
AVIOInterruptCB
Callback for checking whether to abort blocking functions.
Definition: avio.h:58
crc.h
ffio_reset_dyn_buf
void ffio_reset_dyn_buf(AVIOContext *s)
Reset a dynamic buffer.
Definition: aviobuf.c:1459
fail
#define fail()
Definition: checkasm.h:127
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:486
AV_CRC_16_ANSI_LE
@ AV_CRC_16_ANSI_LE
Definition: crc.h:54
val
static double val(void *priv, double ch)
Definition: aeval.c:76
avio_wb24
void avio_wb24(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:469
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
avio_wl16
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:451
ffio_open_whitelist
int ffio_open_whitelist(AVIOContext **s, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char *blacklist)
Definition: aviobuf.c:1186
OFFSET
#define OFFSET(x)
Definition: aviobuf.c:58
ff_avio_child_next
static void * ff_avio_child_next(void *obj, void *prev)
Definition: aviobuf.c:45
avio_print_string_array
void avio_print_string_array(AVIOContext *s, const char *strings[])
Write a NULL terminated array of strings to the context.
Definition: aviobuf.c:1265
GET_UTF8
#define GET_UTF8(val, GET_BYTE, ERROR)
Convert a UTF-8 character (up to 4 bytes) to its 32-bit UCS-4 encoded form.
Definition: common.h:470
flush_buffer
static void flush_buffer(AVIOContext *s)
Definition: aviobuf.c:180
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
avio_write_marker
void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type)
Mark the written bytestream as a specific type.
Definition: aviobuf.c:475
avio_flush
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
Definition: aviobuf.c:238
ff_read_string_to_bprint_overwrite
int64_t ff_read_string_to_bprint_overwrite(AVIOContext *s, AVBPrint *bp, int64_t max_len)
Read a whole null-terminated string of text from AVIOContext to an AVBPrint buffer overwriting its co...
Definition: aviobuf.c:872
ffurl_open_whitelist
int ffurl_open_whitelist(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char *blacklist, URLContext *parent)
Create an URLContext for accessing to the resource indicated by url, and open it.
Definition: avio.c:306
FFIOContext::bytes_read
int64_t bytes_read
Bytes read statistic.
Definition: avio_internal.h:52
avio_wb32
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:379
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:257
ffio_read_size
int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:674
ff_avio_class
const AVClass ff_avio_class
Definition: aviobuf.c:66
avio_close_dyn_buf
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1470
ffio_init_context
void ffio_init_context(FFIOContext *ctx, 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:80
DynBuffer::pos
int pos
Definition: aviobuf.c:1335
ffio_fill
void ffio_fill(AVIOContext *s, int b, int64_t count)
Definition: aviobuf.c:204
ffio_read_indirect
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:684
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AVIO_FLAG_WRITE
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:604
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
ctx
AVFormatContext * ctx
Definition: movenc.c:48
avio_context_free
void avio_context_free(AVIOContext **ps)
Free the supplied IO context and everything associated with it.
Definition: aviobuf.c:147
if
if(ret)
Definition: filter_design.txt:179
ffurl_accept
int ffurl_accept(URLContext *s, URLContext **c)
Accept an URLContext c on an URLContext s.
Definition: avio.c:226
av_vbprintf
void av_vbprintf(AVBPrint *buf, const char *fmt, va_list vl_arg)
Append a formatted string to a print buffer.
Definition: bprint.c:116
av_realloc_f
#define av_realloc_f(p, o, n)
Definition: tableprint_vlc.h:33
internal.h
ffio_limit
int ffio_limit(AVIOContext *s, int size)
Definition: aviobuf.c:1051
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
avio_read
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:625
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
ff_avio_options
static const AVOption ff_avio_options[]
Definition: aviobuf.c:61
NULL
#define NULL
Definition: coverity.c:32
DynBuffer
Definition: aviobuf.c:1334
AVIO_DATA_MARKER_TRAILER
@ AVIO_DATA_MARKER_TRAILER
Trailer data, which doesn't contain actual content, but only for finalizing the output file.
Definition: avio.h:140
PUT_UTF16
#define PUT_UTF16(val, tmp, PUT_16BIT)
Definition: common.h:557
FFIOContext::orig_buffer_size
int orig_buffer_size
Original buffer size used after probing to ensure seekback and to reset the buffer size.
Definition: avio_internal.h:68
avio_printf
int avio_printf(AVIOContext *s, const char *fmt,...)
Definition: aviobuf.c:1246
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
read_string_to_bprint
static int64_t read_string_to_bprint(AVIOContext *s, AVBPrint *bp, FFBPrintReadStringMode mode, int64_t max_len)
Definition: aviobuf.c:811
av_opt_free
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1614
SHORT_SEEK_THRESHOLD
#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:43
read_packet_wrapper
static int read_packet_wrapper(AVIOContext *s, uint8_t *buf, int size)
Definition: aviobuf.c:512
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
avio_pause
int avio_pause(AVIOContext *s, int pause)
Pause and resume playing - only meaningful if using a network streaming protocol (e....
Definition: aviobuf.c:1271
av_bprint_is_complete
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Definition: bprint.h:185
AV_WB32
#define AV_WB32(p, v)
Definition: intreadwrite.h:419
avio_rb24
unsigned int avio_rb24(AVIOContext *s)
Definition: aviobuf.c:766
dyn_packet_buf_write
static int dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:1373
options
const OptionDef options[]
avio_rb16
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:758
ffio_realloc_buf
int ffio_realloc_buf(AVIOContext *s, int buf_size)
Reallocate a given buffer for AVIOContext.
Definition: aviobuf.c:1093
AVIOContext
Bytestream IO Context.
Definition: avio.h:161
ff_read_line_to_bprint_overwrite
int64_t ff_read_line_to_bprint_overwrite(AVIOContext *s, AVBPrint *bp)
Read a whole line of text from AVIOContext to an AVBPrint buffer overwriting its contents.
Definition: aviobuf.c:867
ffio_free_dyn_buf
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
Definition: aviobuf.c:1498
size
int size
Definition: twinvq_data.h:10344
avio.h
ffio_ensure_seekback
int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
Ensures that the requested seekback buffer size will be available.
Definition: aviobuf.c:1016
av_reallocp
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
Definition: mem.c:185
avio_open
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:1181
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
AVIO_SEEKABLE_TIME
#define AVIO_SEEKABLE_TIME
Seeking by timestamp with avio_seek_time() is possible.
Definition: avio.h:45
dyn_buf_write
static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:1341
avio_rl16
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:726
avio_rl64
uint64_t avio_rl64(AVIOContext *s)
Definition: aviobuf.c:750
ffio_rewind_with_probe_data
int ffio_rewind_with_probe_data(AVIOContext *s, unsigned char **bufp, int buf_size)
Rewind the AVIOContext using the specified buffer containing the first buf_size bytes of the file.
Definition: aviobuf.c:1138
AVIO_DATA_MARKER_SYNC_POINT
@ AVIO_DATA_MARKER_SYNC_POINT
A point in the output bytestream where a decoder can start decoding (i.e.
Definition: avio.h:122
avio_close
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: aviobuf.c:1213
AVIOContext::write_packet
int(* write_packet)(void *opaque, uint8_t *buf, int buf_size)
Definition: avio.h:236
av_crc_get_table
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
Definition: crc.c:374
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
avio_open2
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:1207
avio_rl32
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:742
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:218
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:246
ffurl_get_short_seek
int ffurl_get_short_seek(URLContext *h)
Return the current short seek threshold value for this URL.
Definition: avio.c:644
write_packet
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
Definition: ffmpeg.c:731
ffio_init_checksum
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:604
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:64
ffio_open_dyn_packet_buf
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 'max_packet_size'.
Definition: aviobuf.c:1430
bprint.h
URLContext
Definition: url.h:38
log.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
avio_internal.h
PUT_STR16
#define PUT_STR16(type, big_endian)
Definition: aviobuf.c:428
FFBPrintReadLine
@ FFBPrintReadLine
Definition: aviobuf.c:808
ffio_read_varlen
uint64_t ffio_read_varlen(AVIOContext *bc)
Definition: aviobuf.c:928
read_string_to_bprint_overwrite
static int64_t read_string_to_bprint_overwrite(AVIOContext *s, AVBPrint *bp, FFBPrintReadStringMode mode, int64_t max_len)
Definition: aviobuf.c:850
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
url.h
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:263
ff_get_line
int ff_get_line(AVIOContext *s, char *buf, int maxlen)
Read a whole line of text from AVIOContext.
Definition: aviobuf.c:781
GET_STR16
#define GET_STR16(type, read)
Definition: aviobuf.c:896
len
int len
Definition: vorbis_enc_data.h:426
int_cb
const AVIOInterruptCB int_cb
Definition: ffmpeg.c:513
AV_CRC_32_IEEE
@ AV_CRC_32_IEEE
Definition: crc.h:52
DynBuffer::io_buffer_size
int io_buffer_size
Definition: aviobuf.c:1337
avio_wb64
void avio_wb64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:445
AVIO_DATA_MARKER_UNKNOWN
@ AVIO_DATA_MARKER_UNKNOWN
This is any, unlabelled data.
Definition: avio.h:135
avio_get_str
int avio_get_str(AVIOContext *s, int maxlen, char *buf, int buflen)
Read a string from pb into buf.
Definition: aviobuf.c:878
ret
ret
Definition: filter_design.txt:187
read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
pos
unsigned int pos
Definition: spdifenc.c:412
checksum
static volatile int checksum
Definition: adler32.c:30
dict.h
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
av_bprint_clear
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
Definition: bprint.c:226
ff_crc04C11DB7_update
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:578
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:616
AVIO_SEEKABLE_NORMAL
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:40
ffurl_read
int ffurl_read(URLContext *h, unsigned char *buf, int size)
Read up to size bytes from the resource accessed by h, and store the read bytes in buf.
Definition: avio.c:401
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
av_crc
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:392
url_resetbuf
static int url_resetbuf(AVIOContext *s, int flags)
Definition: aviobuf.c:1124
mode
mode
Definition: ebur128.h:83
defs.h
AVIO_DATA_MARKER_HEADER
@ AVIO_DATA_MARKER_HEADER
Header data; this needs to be present for the stream to be decodeable.
Definition: avio.h:115
ffurl_write
int ffurl_write(URLContext *h, const unsigned char *buf, int size)
Write size bytes from buf to the resource accessed by h.
Definition: avio.c:415
ff_crcA001_update
unsigned long ff_crcA001_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:590
DynBuffer::size
int size
Definition: aviobuf.c:1335
AVSEEK_FORCE
#define AVSEEK_FORCE
Passing this flag as the "whence" parameter to a seek function causes it to seek by any means (like r...
Definition: avio.h:468
AVIO_FLAG_DIRECT
#define AVIO_FLAG_DIRECT
Use direct mode.
Definition: avio.h:630
AV_CRC_32_IEEE_LE
@ AV_CRC_32_IEEE_LE
Definition: crc.h:53
AVIO_FLAG_READ
#define AVIO_FLAG_READ
read-only
Definition: avio.h:603
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:279
avio_alloc_context
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:130
ffio_fdopen
int ffio_fdopen(AVIOContext **s, URLContext *h)
Create and initialize a AVIOContext for accessing the resource referenced by the URLContext h.
Definition: aviobuf.c:939
avio_open_dyn_buf
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1425
avio_wb16
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:457
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
ffurl_handshake
int ffurl_handshake(URLContext *c)
Perform one step of the protocol handshake to accept a new client.
Definition: avio.c:234
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
DynBuffer::allocated_size
int allocated_size
Definition: aviobuf.c:1335
set_buf_size
static int set_buf_size(AVIOContext *s, int buf_size)
Definition: aviobuf.c:1077
avio_rb32
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:773
d
d
Definition: ffmpeg_filter.c:156
convert_header.str
string str
Definition: convert_header.py:20
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
ffio_close_null_buf
int ffio_close_null_buf(AVIOContext *s)
Close a null buffer.
Definition: aviobuf.c:1530
h
h
Definition: vp9dsp_template.c:2038
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:228
avio_handshake
int avio_handshake(AVIOContext *c)
Perform one step of the protocol handshake to accept a new client.
Definition: aviobuf.c:1326
writeout
static void writeout(AVIOContext *s, const uint8_t *data, int len)
Definition: aviobuf.c:152
child_class_iterate
static const AVClass * child_class_iterate(void **iter)
Definition: aviobuf.c:51
avio_size
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:338
avio_read_partial
int avio_read_partial(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:696
int
int
Definition: ffmpeg_filter.c:156
avio_wl64
void avio_wl64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:439
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:333
avio_rb64
uint64_t avio_rb64(AVIOContext *s)
Definition: aviobuf.c:920
FFBPrintReadStringMode
FFBPrintReadStringMode
Definition: aviobuf.c:806
avio_closep
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:1239
AVIO_DATA_MARKER_FLUSH_POINT
@ AVIO_DATA_MARKER_FLUSH_POINT
A point in the output bytestream where the underlying AVIOContext might flush the buffer depending on...
Definition: avio.h:146