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