FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 "avformat.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 4096
44 
45 typedef struct AVIOInternal {
47 } AVIOInternal;
48 
49 static void *ff_avio_child_next(void *obj, void *prev)
50 {
51  AVIOContext *s = obj;
52  AVIOInternal *internal = s->opaque;
53  return prev ? NULL : internal->h;
54 }
55 
56 static const AVClass *ff_avio_child_class_next(const AVClass *prev)
57 {
58  return prev ? NULL : &ffurl_context_class;
59 }
60 
61 #define OFFSET(x) offsetof(AVIOContext,x)
62 #define E AV_OPT_FLAG_ENCODING_PARAM
63 #define D AV_OPT_FLAG_DECODING_PARAM
64 static const AVOption ff_avio_options[] = {
65  {"protocol_whitelist", "List of protocols that are allowed to be used", OFFSET(protocol_whitelist), AV_OPT_TYPE_STRING, { .str = NULL }, CHAR_MIN, CHAR_MAX, D },
66  { NULL },
67 };
68 
70  .class_name = "AVIOContext",
71  .item_name = av_default_item_name,
72  .version = LIBAVUTIL_VERSION_INT,
73  .option = ff_avio_options,
74  .child_next = ff_avio_child_next,
75  .child_class_next = ff_avio_child_class_next,
76 };
77 
78 static void fill_buffer(AVIOContext *s);
79 static int url_resetbuf(AVIOContext *s, int flags);
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  s->buffer = buffer;
91  s->orig_buffer_size =
92  s->buffer_size = buffer_size;
93  s->buf_ptr = buffer;
94  s->buf_ptr_max = buffer;
95  s->opaque = opaque;
96  s->direct = 0;
97 
98  url_resetbuf(s, write_flag ? AVIO_FLAG_WRITE : AVIO_FLAG_READ);
99 
102  s->seek = seek;
103  s->pos = 0;
104  s->eof_reached = 0;
105  s->error = 0;
106  s->seekable = seek ? AVIO_SEEKABLE_NORMAL : 0;
107  s->min_packet_size = 0;
108  s->max_packet_size = 0;
109  s->update_checksum = NULL;
111 
112  if (!read_packet && !write_flag) {
113  s->pos = buffer_size;
114  s->buf_end = s->buffer + buffer_size;
115  }
116  s->read_pause = NULL;
117  s->read_seek = NULL;
118 
119  s->write_data_type = NULL;
120  s->ignore_boundary_point = 0;
123  s->short_seek_get = NULL;
124  s->written = 0;
125 
126  return 0;
127 }
128 
130  unsigned char *buffer,
131  int buffer_size,
132  int write_flag,
133  void *opaque,
134  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
135  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
136  int64_t (*seek)(void *opaque, int64_t offset, int whence))
137 {
138  AVIOContext *s = av_mallocz(sizeof(AVIOContext));
139  if (!s)
140  return NULL;
141  ffio_init_context(s, buffer, buffer_size, write_flag, opaque,
142  read_packet, write_packet, seek);
143  return s;
144 }
145 
147 {
148  av_freep(ps);
149 }
150 
151 static void writeout(AVIOContext *s, const uint8_t *data, int len)
152 {
153  if (!s->error) {
154  int ret = 0;
155  if (s->write_data_type)
156  ret = s->write_data_type(s->opaque, (uint8_t *)data,
157  len,
158  s->current_type,
159  s->last_time);
160  else if (s->write_packet)
161  ret = s->write_packet(s->opaque, (uint8_t *)data, len);
162  if (ret < 0) {
163  s->error = ret;
164  } else {
165  if (s->pos + len > s->written)
166  s->written = s->pos + len;
167  }
168  }
172  }
174  s->writeout_count ++;
175  s->pos += len;
176 }
177 
178 static void flush_buffer(AVIOContext *s)
179 {
180  s->buf_ptr_max = FFMAX(s->buf_ptr, s->buf_ptr_max);
181  if (s->write_flag && s->buf_ptr_max > s->buffer) {
182  writeout(s, s->buffer, s->buf_ptr_max - s->buffer);
183  if (s->update_checksum) {
185  s->buf_ptr_max - s->checksum_ptr);
186  s->checksum_ptr = s->buffer;
187  }
188  }
189  s->buf_ptr = s->buf_ptr_max = s->buffer;
190  if (!s->write_flag)
191  s->buf_end = s->buffer;
192 }
193 
194 void avio_w8(AVIOContext *s, int b)
195 {
196  av_assert2(b>=-128 && b<=255);
197  *s->buf_ptr++ = b;
198  if (s->buf_ptr >= s->buf_end)
199  flush_buffer(s);
200 }
201 
202 void ffio_fill(AVIOContext *s, int b, int count)
203 {
204  while (count > 0) {
205  int len = FFMIN(s->buf_end - s->buf_ptr, count);
206  memset(s->buf_ptr, b, len);
207  s->buf_ptr += len;
208 
209  if (s->buf_ptr >= s->buf_end)
210  flush_buffer(s);
211 
212  count -= len;
213  }
214 }
215 
216 void avio_write(AVIOContext *s, const unsigned char *buf, int size)
217 {
218  if (s->direct && !s->update_checksum) {
219  avio_flush(s);
220  writeout(s, buf, size);
221  return;
222  }
223  while (size > 0) {
224  int len = FFMIN(s->buf_end - s->buf_ptr, size);
225  memcpy(s->buf_ptr, buf, len);
226  s->buf_ptr += len;
227 
228  if (s->buf_ptr >= s->buf_end)
229  flush_buffer(s);
230 
231  buf += len;
232  size -= len;
233  }
234 }
235 
237 {
238  int seekback = s->write_flag ? FFMIN(0, s->buf_ptr - s->buf_ptr_max) : 0;
239  flush_buffer(s);
240  if (seekback)
241  avio_seek(s, seekback, SEEK_CUR);
242 }
243 
244 int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
245 {
246  int64_t offset1;
247  int64_t pos;
248  int force = whence & AVSEEK_FORCE;
249  int buffer_size;
250  int short_seek;
251  whence &= ~AVSEEK_FORCE;
252 
253  if(!s)
254  return AVERROR(EINVAL);
255 
256  buffer_size = s->buf_end - s->buffer;
257  // pos is the absolute position that the beginning of s->buffer corresponds to in the file
258  pos = s->pos - (s->write_flag ? 0 : buffer_size);
259 
260  if (whence != SEEK_CUR && whence != SEEK_SET)
261  return AVERROR(EINVAL);
262 
263  if (whence == SEEK_CUR) {
264  offset1 = pos + (s->buf_ptr - s->buffer);
265  if (offset == 0)
266  return offset1;
267  if (offset > INT64_MAX - offset1)
268  return AVERROR(EINVAL);
269  offset += offset1;
270  }
271  if (offset < 0)
272  return AVERROR(EINVAL);
273 
274  if (s->short_seek_get) {
275  short_seek = s->short_seek_get(s->opaque);
276  /* fallback to default short seek */
277  if (short_seek <= 0)
278  short_seek = s->short_seek_threshold;
279  } else
280  short_seek = s->short_seek_threshold;
281 
282  offset1 = offset - pos; // "offset1" is the relative offset from the beginning of s->buffer
283  s->buf_ptr_max = FFMAX(s->buf_ptr_max, s->buf_ptr);
284  if ((!s->direct || !s->seek) &&
285  offset1 >= 0 && offset1 <= (s->write_flag ? s->buf_ptr_max - s->buffer : buffer_size)) {
286  /* can do the seek inside the buffer */
287  s->buf_ptr = s->buffer + offset1;
288  } else if ((!(s->seekable & AVIO_SEEKABLE_NORMAL) ||
289  offset1 <= buffer_size + short_seek) &&
290  !s->write_flag && offset1 >= 0 &&
291  (!s->direct || !s->seek) &&
292  (whence != SEEK_END || force)) {
293  while(s->pos < offset && !s->eof_reached)
294  fill_buffer(s);
295  if (s->eof_reached)
296  return AVERROR_EOF;
297  s->buf_ptr = s->buf_end - (s->pos - offset);
298  } else if(!s->write_flag && offset1 < 0 && -offset1 < buffer_size>>1 && s->seek && offset > 0) {
299  int64_t res;
300 
301  pos -= FFMIN(buffer_size>>1, pos);
302  if ((res = s->seek(s->opaque, pos, SEEK_SET)) < 0)
303  return res;
304  s->buf_end =
305  s->buf_ptr = s->buffer;
306  s->pos = pos;
307  s->eof_reached = 0;
308  fill_buffer(s);
309  return avio_seek(s, offset, SEEK_SET | force);
310  } else {
311  int64_t res;
312  if (s->write_flag) {
313  flush_buffer(s);
314  }
315  if (!s->seek)
316  return AVERROR(EPIPE);
317  if ((res = s->seek(s->opaque, offset, SEEK_SET)) < 0)
318  return res;
319  s->seek_count ++;
320  if (!s->write_flag)
321  s->buf_end = s->buffer;
322  s->buf_ptr = s->buf_ptr_max = s->buffer;
323  s->pos = offset;
324  }
325  s->eof_reached = 0;
326  return offset;
327 }
328 
329 int64_t avio_skip(AVIOContext *s, int64_t offset)
330 {
331  return avio_seek(s, offset, SEEK_CUR);
332 }
333 
335 {
336  int64_t size;
337 
338  if (!s)
339  return AVERROR(EINVAL);
340 
341  if (s->written)
342  return s->written;
343 
344  if (!s->seek)
345  return AVERROR(ENOSYS);
346  size = s->seek(s->opaque, 0, AVSEEK_SIZE);
347  if (size < 0) {
348  if ((size = s->seek(s->opaque, -1, SEEK_END)) < 0)
349  return size;
350  size++;
351  s->seek(s->opaque, s->pos, SEEK_SET);
352  }
353  return size;
354 }
355 
357 {
358  if(!s)
359  return 0;
360  if(s->eof_reached){
361  s->eof_reached=0;
362  fill_buffer(s);
363  }
364  return s->eof_reached;
365 }
366 
367 #if FF_API_URL_FEOF
368 int url_feof(AVIOContext *s)
369 {
370  return avio_feof(s);
371 }
372 #endif
373 
374 void avio_wl32(AVIOContext *s, unsigned int val)
375 {
376  avio_w8(s, (uint8_t) val );
377  avio_w8(s, (uint8_t)(val >> 8 ));
378  avio_w8(s, (uint8_t)(val >> 16));
379  avio_w8(s, val >> 24 );
380 }
381 
382 void avio_wb32(AVIOContext *s, unsigned int val)
383 {
384  avio_w8(s, val >> 24 );
385  avio_w8(s, (uint8_t)(val >> 16));
386  avio_w8(s, (uint8_t)(val >> 8 ));
387  avio_w8(s, (uint8_t) val );
388 }
389 
390 int avio_put_str(AVIOContext *s, const char *str)
391 {
392  int len = 1;
393  if (str) {
394  len += strlen(str);
395  avio_write(s, (const unsigned char *) str, len);
396  } else
397  avio_w8(s, 0);
398  return len;
399 }
400 
401 static inline int put_str16(AVIOContext *s, const char *str, const int be)
402 {
403  const uint8_t *q = str;
404  int ret = 0;
405  int err = 0;
406 
407  while (*q) {
408  uint32_t ch;
409  uint16_t tmp;
410 
411  GET_UTF8(ch, *q++, goto invalid;)
412  PUT_UTF16(ch, tmp, be ? avio_wb16(s, tmp) : avio_wl16(s, tmp);
413  ret += 2;)
414  continue;
415 invalid:
416  av_log(s, AV_LOG_ERROR, "Invalid UTF8 sequence in avio_put_str16%s\n", be ? "be" : "le");
417  err = AVERROR(EINVAL);
418  if (!*(q-1))
419  break;
420  }
421  if (be)
422  avio_wb16(s, 0);
423  else
424  avio_wl16(s, 0);
425  if (err)
426  return err;
427  ret += 2;
428  return ret;
429 }
430 
431 #define PUT_STR16(type, big_endian) \
432 int avio_put_str16 ## type(AVIOContext *s, const char *str) \
433 { \
434 return put_str16(s, str, big_endian); \
435 }
436 
437 PUT_STR16(le, 0)
438 PUT_STR16(be, 1)
439 
440 #undef PUT_STR16
441 
442 int ff_get_v_length(uint64_t val)
443 {
444  int i = 1;
445 
446  while (val >>= 7)
447  i++;
448 
449  return i;
450 }
451 
452 void ff_put_v(AVIOContext *bc, uint64_t val)
453 {
454  int i = ff_get_v_length(val);
455 
456  while (--i > 0)
457  avio_w8(bc, 128 | (uint8_t)(val >> (7*i)));
458 
459  avio_w8(bc, val & 127);
460 }
461 
462 void avio_wl64(AVIOContext *s, uint64_t val)
463 {
464  avio_wl32(s, (uint32_t)(val & 0xffffffff));
465  avio_wl32(s, (uint32_t)(val >> 32));
466 }
467 
468 void avio_wb64(AVIOContext *s, uint64_t val)
469 {
470  avio_wb32(s, (uint32_t)(val >> 32));
471  avio_wb32(s, (uint32_t)(val & 0xffffffff));
472 }
473 
474 void avio_wl16(AVIOContext *s, unsigned int val)
475 {
476  avio_w8(s, (uint8_t)val);
477  avio_w8(s, (int)val >> 8);
478 }
479 
480 void avio_wb16(AVIOContext *s, unsigned int val)
481 {
482  avio_w8(s, (int)val >> 8);
483  avio_w8(s, (uint8_t)val);
484 }
485 
486 void avio_wl24(AVIOContext *s, unsigned int val)
487 {
488  avio_wl16(s, val & 0xffff);
489  avio_w8(s, (int)val >> 16);
490 }
491 
492 void avio_wb24(AVIOContext *s, unsigned int val)
493 {
494  avio_wb16(s, (int)val >> 8);
495  avio_w8(s, (uint8_t)val);
496 }
497 
499 {
500  if (type == AVIO_DATA_MARKER_FLUSH_POINT) {
501  if (s->buf_ptr - s->buffer >= s->min_packet_size)
502  avio_flush(s);
503  return;
504  }
505  if (!s->write_data_type)
506  return;
507  // If ignoring boundary points, just treat it as unknown
510  // Avoid unnecessary flushes if we are already in non-header/trailer
511  // data and setting the type to unknown
512  if (type == AVIO_DATA_MARKER_UNKNOWN &&
515  return;
516 
517  switch (type) {
520  // For header/trailer, ignore a new marker of the same type;
521  // consecutive header/trailer markers can be merged.
522  if (type == s->current_type)
523  return;
524  break;
525  }
526 
527  // If we've reached here, we have a new, noteworthy marker.
528  // Flush the previous data and mark the start of the new data.
529  avio_flush(s);
530  s->current_type = type;
531  s->last_time = time;
532 }
533 
534 /* Input stream */
535 
536 static void fill_buffer(AVIOContext *s)
537 {
538  int max_buffer_size = s->max_packet_size ?
540  uint8_t *dst = s->buf_end - s->buffer + max_buffer_size < s->buffer_size ?
541  s->buf_end : s->buffer;
542  int len = s->buffer_size - (dst - s->buffer);
543 
544  /* can't fill the buffer without read_packet, just set EOF if appropriate */
545  if (!s->read_packet && s->buf_ptr >= s->buf_end)
546  s->eof_reached = 1;
547 
548  /* no need to do anything if EOF already reached */
549  if (s->eof_reached)
550  return;
551 
552  if (s->update_checksum && dst == s->buffer) {
553  if (s->buf_end > s->checksum_ptr)
555  s->buf_end - s->checksum_ptr);
556  s->checksum_ptr = s->buffer;
557  }
558 
559  /* make buffer smaller in case it ended up large after probing */
560  if (s->read_packet && s->orig_buffer_size && s->buffer_size > s->orig_buffer_size) {
561  if (dst == s->buffer && s->buf_ptr != dst) {
562  int ret = ffio_set_buf_size(s, s->orig_buffer_size);
563  if (ret < 0)
564  av_log(s, AV_LOG_WARNING, "Failed to decrease buffer size\n");
565 
566  s->checksum_ptr = dst = s->buffer;
567  }
568  av_assert0(len >= s->orig_buffer_size);
569  len = s->orig_buffer_size;
570  }
571 
572  if (s->read_packet)
573  len = s->read_packet(s->opaque, dst, len);
574  else
575  len = 0;
576  if (len <= 0) {
577  /* do not modify buffer if EOF reached so that a seek back can
578  be done without rereading data */
579  s->eof_reached = 1;
580  if (len < 0)
581  s->error = len;
582  } else {
583  s->pos += len;
584  s->buf_ptr = dst;
585  s->buf_end = dst + len;
586  s->bytes_read += len;
587  }
588 }
589 
590 unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf,
591  unsigned int len)
592 {
593  return av_crc(av_crc_get_table(AV_CRC_32_IEEE), checksum, buf, len);
594 }
595 
596 unsigned long ff_crcEDB88320_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_LE), checksum, buf, len);
600 }
601 
602 unsigned long ff_crcA001_update(unsigned long checksum, const uint8_t *buf,
603  unsigned int len)
604 {
605  return av_crc(av_crc_get_table(AV_CRC_16_ANSI_LE), checksum, buf, len);
606 }
607 
609 {
611  s->buf_ptr - s->checksum_ptr);
612  s->update_checksum = NULL;
613  return s->checksum;
614 }
615 
617  unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len),
618  unsigned long checksum)
619 {
620  s->update_checksum = update_checksum;
621  if (s->update_checksum) {
622  s->checksum = checksum;
623  s->checksum_ptr = s->buf_ptr;
624  }
625 }
626 
627 /* XXX: put an inline version */
629 {
630  if (s->buf_ptr >= s->buf_end)
631  fill_buffer(s);
632  if (s->buf_ptr < s->buf_end)
633  return *s->buf_ptr++;
634  return 0;
635 }
636 
637 int avio_read(AVIOContext *s, unsigned char *buf, int size)
638 {
639  int len, size1;
640 
641  size1 = size;
642  while (size > 0) {
643  len = FFMIN(s->buf_end - s->buf_ptr, size);
644  if (len == 0 || s->write_flag) {
645  if((s->direct || size > s->buffer_size) && !s->update_checksum) {
646  // bypass the buffer and read data directly into buf
647  if(s->read_packet)
648  len = s->read_packet(s->opaque, buf, size);
649 
650  if (len <= 0) {
651  /* do not modify buffer if EOF reached so that a seek back can
652  be done without rereading data */
653  s->eof_reached = 1;
654  if(len<0)
655  s->error= len;
656  break;
657  } else {
658  s->pos += len;
659  s->bytes_read += len;
660  size -= len;
661  buf += len;
662  // reset the buffer
663  s->buf_ptr = s->buffer;
664  s->buf_end = s->buffer/* + len*/;
665  }
666  } else {
667  fill_buffer(s);
668  len = s->buf_end - s->buf_ptr;
669  if (len == 0)
670  break;
671  }
672  } else {
673  memcpy(buf, s->buf_ptr, len);
674  buf += len;
675  s->buf_ptr += len;
676  size -= len;
677  }
678  }
679  if (size1 == size) {
680  if (s->error) return s->error;
681  if (avio_feof(s)) return AVERROR_EOF;
682  }
683  return size1 - size;
684 }
685 
686 int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
687 {
688  int ret = avio_read(s, buf, size);
689  if (ret != size)
690  return AVERROR_INVALIDDATA;
691  return ret;
692 }
693 
694 int ffio_read_indirect(AVIOContext *s, unsigned char *buf, int size, const unsigned char **data)
695 {
696  if (s->buf_end - s->buf_ptr >= size && !s->write_flag) {
697  *data = s->buf_ptr;
698  s->buf_ptr += size;
699  return size;
700  } else {
701  *data = buf;
702  return avio_read(s, buf, size);
703  }
704 }
705 
706 int avio_read_partial(AVIOContext *s, unsigned char *buf, int size)
707 {
708  int len;
709 
710  if (size < 0)
711  return -1;
712 
713  if (s->read_packet && s->write_flag) {
714  len = s->read_packet(s->opaque, buf, size);
715  if (len > 0)
716  s->pos += len;
717  return len;
718  }
719 
720  len = s->buf_end - s->buf_ptr;
721  if (len == 0) {
722  /* Reset the buf_end pointer to the start of the buffer, to make sure
723  * the fill_buffer call tries to read as much data as fits into the
724  * full buffer, instead of just what space is left after buf_end.
725  * This avoids returning partial packets at the end of the buffer,
726  * for packet based inputs.
727  */
728  s->buf_end = s->buf_ptr = s->buffer;
729  fill_buffer(s);
730  len = s->buf_end - s->buf_ptr;
731  }
732  if (len > size)
733  len = size;
734  memcpy(buf, s->buf_ptr, len);
735  s->buf_ptr += len;
736  if (!len) {
737  if (s->error) return s->error;
738  if (avio_feof(s)) return AVERROR_EOF;
739  }
740  return len;
741 }
742 
743 unsigned int avio_rl16(AVIOContext *s)
744 {
745  unsigned int val;
746  val = avio_r8(s);
747  val |= avio_r8(s) << 8;
748  return val;
749 }
750 
751 unsigned int avio_rl24(AVIOContext *s)
752 {
753  unsigned int val;
754  val = avio_rl16(s);
755  val |= avio_r8(s) << 16;
756  return val;
757 }
758 
759 unsigned int avio_rl32(AVIOContext *s)
760 {
761  unsigned int val;
762  val = avio_rl16(s);
763  val |= avio_rl16(s) << 16;
764  return val;
765 }
766 
767 uint64_t avio_rl64(AVIOContext *s)
768 {
769  uint64_t val;
770  val = (uint64_t)avio_rl32(s);
771  val |= (uint64_t)avio_rl32(s) << 32;
772  return val;
773 }
774 
775 unsigned int avio_rb16(AVIOContext *s)
776 {
777  unsigned int val;
778  val = avio_r8(s) << 8;
779  val |= avio_r8(s);
780  return val;
781 }
782 
783 unsigned int avio_rb24(AVIOContext *s)
784 {
785  unsigned int val;
786  val = avio_rb16(s) << 8;
787  val |= avio_r8(s);
788  return val;
789 }
790 unsigned int avio_rb32(AVIOContext *s)
791 {
792  unsigned int val;
793  val = avio_rb16(s) << 16;
794  val |= avio_rb16(s);
795  return val;
796 }
797 
798 int ff_get_line(AVIOContext *s, char *buf, int maxlen)
799 {
800  int i = 0;
801  char c;
802 
803  do {
804  c = avio_r8(s);
805  if (c && i < maxlen-1)
806  buf[i++] = c;
807  } while (c != '\n' && c != '\r' && c);
808  if (c == '\r' && avio_r8(s) != '\n' && !avio_feof(s))
809  avio_skip(s, -1);
810 
811  buf[i] = 0;
812  return i;
813 }
814 
815 int avio_get_str(AVIOContext *s, int maxlen, char *buf, int buflen)
816 {
817  int i;
818 
819  if (buflen <= 0)
820  return AVERROR(EINVAL);
821  // reserve 1 byte for terminating 0
822  buflen = FFMIN(buflen - 1, maxlen);
823  for (i = 0; i < buflen; i++)
824  if (!(buf[i] = avio_r8(s)))
825  return i + 1;
826  buf[i] = 0;
827  for (; i < maxlen; i++)
828  if (!avio_r8(s))
829  return i + 1;
830  return maxlen;
831 }
832 
833 #define GET_STR16(type, read) \
834  int avio_get_str16 ##type(AVIOContext *pb, int maxlen, char *buf, int buflen)\
835 {\
836  char* q = buf;\
837  int ret = 0;\
838  if (buflen <= 0) \
839  return AVERROR(EINVAL); \
840  while (ret + 1 < maxlen) {\
841  uint8_t tmp;\
842  uint32_t ch;\
843  GET_UTF16(ch, (ret += 2) <= maxlen ? read(pb) : 0, break;)\
844  if (!ch)\
845  break;\
846  PUT_UTF8(ch, tmp, if (q - buf < buflen - 1) *q++ = tmp;)\
847  }\
848  *q = 0;\
849  return ret;\
850 }\
851 
853 GET_STR16(be, avio_rb16)
854 
855 #undef GET_STR16
856 
857 uint64_t avio_rb64(AVIOContext *s)
858 {
859  uint64_t val;
860  val = (uint64_t)avio_rb32(s) << 32;
861  val |= (uint64_t)avio_rb32(s);
862  return val;
863 }
864 
866  uint64_t val = 0;
867  int tmp;
868 
869  do{
870  tmp = avio_r8(bc);
871  val= (val<<7) + (tmp&127);
872  }while(tmp&128);
873  return val;
874 }
875 
876 static int io_read_packet(void *opaque, uint8_t *buf, int buf_size)
877 {
878  AVIOInternal *internal = opaque;
879  return ffurl_read(internal->h, buf, buf_size);
880 }
881 
882 static int io_write_packet(void *opaque, uint8_t *buf, int buf_size)
883 {
884  AVIOInternal *internal = opaque;
885  return ffurl_write(internal->h, buf, buf_size);
886 }
887 
888 static int64_t io_seek(void *opaque, int64_t offset, int whence)
889 {
890  AVIOInternal *internal = opaque;
891  return ffurl_seek(internal->h, offset, whence);
892 }
893 
894 static int io_short_seek(void *opaque)
895 {
896  AVIOInternal *internal = opaque;
897  return ffurl_get_short_seek(internal->h);
898 }
899 
900 static int io_read_pause(void *opaque, int pause)
901 {
902  AVIOInternal *internal = opaque;
903  if (!internal->h->prot->url_read_pause)
904  return AVERROR(ENOSYS);
905  return internal->h->prot->url_read_pause(internal->h, pause);
906 }
907 
908 static int64_t io_read_seek(void *opaque, int stream_index, int64_t timestamp, int flags)
909 {
910  AVIOInternal *internal = opaque;
911  if (!internal->h->prot->url_read_seek)
912  return AVERROR(ENOSYS);
913  return internal->h->prot->url_read_seek(internal->h, stream_index, timestamp, flags);
914 }
915 
917 {
918  AVIOInternal *internal = NULL;
919  uint8_t *buffer = NULL;
920  int buffer_size, max_packet_size;
921 
922  max_packet_size = h->max_packet_size;
923  if (max_packet_size) {
924  buffer_size = max_packet_size; /* no need to bufferize more than one packet */
925  } else {
926  buffer_size = IO_BUFFER_SIZE;
927  }
928  buffer = av_malloc(buffer_size);
929  if (!buffer)
930  return AVERROR(ENOMEM);
931 
932  internal = av_mallocz(sizeof(*internal));
933  if (!internal)
934  goto fail;
935 
936  internal->h = h;
937 
938  *s = avio_alloc_context(buffer, buffer_size, h->flags & AVIO_FLAG_WRITE,
940  if (!*s)
941  goto fail;
942 
943  (*s)->protocol_whitelist = av_strdup(h->protocol_whitelist);
944  if (!(*s)->protocol_whitelist && h->protocol_whitelist) {
945  avio_closep(s);
946  goto fail;
947  }
948  (*s)->protocol_blacklist = av_strdup(h->protocol_blacklist);
949  if (!(*s)->protocol_blacklist && h->protocol_blacklist) {
950  avio_closep(s);
951  goto fail;
952  }
953  (*s)->direct = h->flags & AVIO_FLAG_DIRECT;
954 
955  (*s)->seekable = h->is_streamed ? 0 : AVIO_SEEKABLE_NORMAL;
956  (*s)->max_packet_size = max_packet_size;
957  (*s)->min_packet_size = h->min_packet_size;
958  if(h->prot) {
959  (*s)->read_pause = io_read_pause;
960  (*s)->read_seek = io_read_seek;
961 
962  if (h->prot->url_read_seek)
963  (*s)->seekable |= AVIO_SEEKABLE_TIME;
964  }
965  (*s)->short_seek_get = io_short_seek;
966  (*s)->av_class = &ff_avio_class;
967  return 0;
968 fail:
969  av_freep(&internal);
970  av_freep(&buffer);
971  return AVERROR(ENOMEM);
972 }
973 
974 int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
975 {
976  uint8_t *buffer;
977  int max_buffer_size = s->max_packet_size ?
979  int filled = s->buf_end - s->buffer;
980  ptrdiff_t checksum_ptr_offset = s->checksum_ptr ? s->checksum_ptr - s->buffer : -1;
981 
982  buf_size += s->buf_ptr - s->buffer + max_buffer_size;
983 
984  if (buf_size < filled || s->seekable || !s->read_packet)
985  return 0;
986  av_assert0(!s->write_flag);
987 
988  buffer = av_malloc(buf_size);
989  if (!buffer)
990  return AVERROR(ENOMEM);
991 
992  memcpy(buffer, s->buffer, filled);
993  av_free(s->buffer);
994  s->buf_ptr = buffer + (s->buf_ptr - s->buffer);
995  s->buf_end = buffer + (s->buf_end - s->buffer);
996  s->buffer = buffer;
997  s->buffer_size = buf_size;
998  if (checksum_ptr_offset >= 0)
999  s->checksum_ptr = s->buffer + checksum_ptr_offset;
1000  return 0;
1001 }
1002 
1003 int ffio_set_buf_size(AVIOContext *s, int buf_size)
1004 {
1005  uint8_t *buffer;
1006  buffer = av_malloc(buf_size);
1007  if (!buffer)
1008  return AVERROR(ENOMEM);
1009 
1010  av_free(s->buffer);
1011  s->buffer = buffer;
1012  s->orig_buffer_size =
1013  s->buffer_size = buf_size;
1014  s->buf_ptr = s->buf_ptr_max = buffer;
1016  return 0;
1017 }
1018 
1019 static int url_resetbuf(AVIOContext *s, int flags)
1020 {
1021  av_assert1(flags == AVIO_FLAG_WRITE || flags == AVIO_FLAG_READ);
1022 
1023  if (flags & AVIO_FLAG_WRITE) {
1024  s->buf_end = s->buffer + s->buffer_size;
1025  s->write_flag = 1;
1026  } else {
1027  s->buf_end = s->buffer;
1028  s->write_flag = 0;
1029  }
1030  return 0;
1031 }
1032 
1033 int ffio_rewind_with_probe_data(AVIOContext *s, unsigned char **bufp, int buf_size)
1034 {
1035  int64_t buffer_start;
1036  int buffer_size;
1037  int overlap, new_size, alloc_size;
1038  uint8_t *buf = *bufp;
1039 
1040  if (s->write_flag) {
1041  av_freep(bufp);
1042  return AVERROR(EINVAL);
1043  }
1044 
1045  buffer_size = s->buf_end - s->buffer;
1046 
1047  /* the buffers must touch or overlap */
1048  if ((buffer_start = s->pos - buffer_size) > buf_size) {
1049  av_freep(bufp);
1050  return AVERROR(EINVAL);
1051  }
1052 
1053  overlap = buf_size - buffer_start;
1054  new_size = buf_size + buffer_size - overlap;
1055 
1056  alloc_size = FFMAX(s->buffer_size, new_size);
1057  if (alloc_size > buf_size)
1058  if (!(buf = (*bufp) = av_realloc_f(buf, 1, alloc_size)))
1059  return AVERROR(ENOMEM);
1060 
1061  if (new_size > buf_size) {
1062  memcpy(buf + buf_size, s->buffer + overlap, buffer_size - overlap);
1063  buf_size = new_size;
1064  }
1065 
1066  av_free(s->buffer);
1067  s->buf_ptr = s->buffer = buf;
1068  s->buffer_size = alloc_size;
1069  s->pos = buf_size;
1070  s->buf_end = s->buf_ptr + buf_size;
1071  s->eof_reached = 0;
1072 
1073  return 0;
1074 }
1075 
1076 int avio_open(AVIOContext **s, const char *filename, int flags)
1077 {
1078  return avio_open2(s, filename, flags, NULL, NULL);
1079 }
1080 
1081 int ffio_open_whitelist(AVIOContext **s, const char *filename, int flags,
1083  const char *whitelist, const char *blacklist
1084  )
1085 {
1086  URLContext *h;
1087  int err;
1088 
1089  err = ffurl_open_whitelist(&h, filename, flags, int_cb, options, whitelist, blacklist, NULL);
1090  if (err < 0)
1091  return err;
1092  err = ffio_fdopen(s, h);
1093  if (err < 0) {
1094  ffurl_close(h);
1095  return err;
1096  }
1097  return 0;
1098 }
1099 
1100 int avio_open2(AVIOContext **s, const char *filename, int flags,
1102 {
1103  return ffio_open_whitelist(s, filename, flags, int_cb, options, NULL, NULL);
1104 }
1105 
1106 int ffio_open2_wrapper(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags,
1108 {
1109  return ffio_open_whitelist(pb, url, flags, int_cb, options, s->protocol_whitelist, s->protocol_blacklist);
1110 }
1111 
1113 {
1114  AVIOInternal *internal;
1115  URLContext *h;
1116 
1117  if (!s)
1118  return 0;
1119 
1120  avio_flush(s);
1121  internal = s->opaque;
1122  h = internal->h;
1123 
1124  av_freep(&s->opaque);
1125  av_freep(&s->buffer);
1126  if (s->write_flag)
1127  av_log(s, AV_LOG_DEBUG, "Statistics: %d seeks, %d writeouts\n", s->seek_count, s->writeout_count);
1128  else
1129  av_log(s, AV_LOG_DEBUG, "Statistics: %"PRId64" bytes read, %d seeks\n", s->bytes_read, s->seek_count);
1130  av_opt_free(s);
1131 
1132  avio_context_free(&s);
1133 
1134  return ffurl_close(h);
1135 }
1136 
1138 {
1139  int ret = avio_close(*s);
1140  *s = NULL;
1141  return ret;
1142 }
1143 
1144 int avio_printf(AVIOContext *s, const char *fmt, ...)
1145 {
1146  va_list ap;
1147  char buf[4096]; /* update doc entry in avio.h if changed */
1148  int ret;
1149 
1150  va_start(ap, fmt);
1151  ret = vsnprintf(buf, sizeof(buf), fmt, ap);
1152  va_end(ap);
1153  avio_write(s, buf, strlen(buf));
1154  return ret;
1155 }
1156 
1157 int avio_pause(AVIOContext *s, int pause)
1158 {
1159  if (!s->read_pause)
1160  return AVERROR(ENOSYS);
1161  return s->read_pause(s->opaque, pause);
1162 }
1163 
1164 int64_t avio_seek_time(AVIOContext *s, int stream_index,
1165  int64_t timestamp, int flags)
1166 {
1167  int64_t ret;
1168  if (!s->read_seek)
1169  return AVERROR(ENOSYS);
1170  ret = s->read_seek(s->opaque, stream_index, timestamp, flags);
1171  if (ret >= 0) {
1172  int64_t pos;
1173  s->buf_ptr = s->buf_end; // Flush buffer
1174  pos = s->seek(s->opaque, 0, SEEK_CUR);
1175  if (pos >= 0)
1176  s->pos = pos;
1177  else if (pos != AVERROR(ENOSYS))
1178  ret = pos;
1179  }
1180  return ret;
1181 }
1182 
1183 int avio_read_to_bprint(AVIOContext *h, AVBPrint *pb, size_t max_size)
1184 {
1185  int ret;
1186  char buf[1024];
1187  while (max_size) {
1188  ret = avio_read(h, buf, FFMIN(max_size, sizeof(buf)));
1189  if (ret == AVERROR_EOF)
1190  return 0;
1191  if (ret <= 0)
1192  return ret;
1193  av_bprint_append_data(pb, buf, ret);
1194  if (!av_bprint_is_complete(pb))
1195  return AVERROR(ENOMEM);
1196  max_size -= ret;
1197  }
1198  return 0;
1199 }
1200 
1202 {
1203  int ret;
1204  AVIOInternal *internal = s->opaque;
1205  URLContext *sc = internal->h;
1206  URLContext *cc = NULL;
1207  ret = ffurl_accept(sc, &cc);
1208  if (ret < 0)
1209  return ret;
1210  return ffio_fdopen(c, cc);
1211 }
1212 
1214 {
1215  AVIOInternal *internal = c->opaque;
1216  URLContext *cc = internal->h;
1217  return ffurl_handshake(cc);
1218 }
1219 
1220 /* output in a dynamic buffer */
1221 
1222 typedef struct DynBuffer {
1227 } DynBuffer;
1228 
1229 static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
1230 {
1231  DynBuffer *d = opaque;
1232  unsigned new_size, new_allocated_size;
1233 
1234  /* reallocate buffer if needed */
1235  new_size = d->pos + buf_size;
1236  new_allocated_size = d->allocated_size;
1237  if (new_size < d->pos || new_size > INT_MAX/2)
1238  return -1;
1239  while (new_size > new_allocated_size) {
1240  if (!new_allocated_size)
1241  new_allocated_size = new_size;
1242  else
1243  new_allocated_size += new_allocated_size / 2 + 1;
1244  }
1245 
1246  if (new_allocated_size > d->allocated_size) {
1247  int err;
1248  if ((err = av_reallocp(&d->buffer, new_allocated_size)) < 0) {
1249  d->allocated_size = 0;
1250  d->size = 0;
1251  return err;
1252  }
1253  d->allocated_size = new_allocated_size;
1254  }
1255  memcpy(d->buffer + d->pos, buf, buf_size);
1256  d->pos = new_size;
1257  if (d->pos > d->size)
1258  d->size = d->pos;
1259  return buf_size;
1260 }
1261 
1262 static int dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
1263 {
1264  unsigned char buf1[4];
1265  int ret;
1266 
1267  /* packetized write: output the header */
1268  AV_WB32(buf1, buf_size);
1269  ret = dyn_buf_write(opaque, buf1, 4);
1270  if (ret < 0)
1271  return ret;
1272 
1273  /* then the data */
1274  return dyn_buf_write(opaque, buf, buf_size);
1275 }
1276 
1277 static int64_t dyn_buf_seek(void *opaque, int64_t offset, int whence)
1278 {
1279  DynBuffer *d = opaque;
1280 
1281  if (whence == SEEK_CUR)
1282  offset += d->pos;
1283  else if (whence == SEEK_END)
1284  offset += d->size;
1285  if (offset < 0 || offset > 0x7fffffffLL)
1286  return -1;
1287  d->pos = offset;
1288  return 0;
1289 }
1290 
1291 static int url_open_dyn_buf_internal(AVIOContext **s, int max_packet_size)
1292 {
1293  DynBuffer *d;
1294  unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
1295 
1296  if (sizeof(DynBuffer) + io_buffer_size < io_buffer_size)
1297  return -1;
1298  d = av_mallocz(sizeof(DynBuffer) + io_buffer_size);
1299  if (!d)
1300  return AVERROR(ENOMEM);
1301  d->io_buffer_size = io_buffer_size;
1302  *s = avio_alloc_context(d->io_buffer, d->io_buffer_size, 1, d, NULL,
1303  max_packet_size ? dyn_packet_buf_write : dyn_buf_write,
1304  max_packet_size ? NULL : dyn_buf_seek);
1305  if(!*s) {
1306  av_free(d);
1307  return AVERROR(ENOMEM);
1308  }
1309  (*s)->max_packet_size = max_packet_size;
1310  return 0;
1311 }
1312 
1314 {
1315  return url_open_dyn_buf_internal(s, 0);
1316 }
1317 
1318 int ffio_open_dyn_packet_buf(AVIOContext **s, int max_packet_size)
1319 {
1320  if (max_packet_size <= 0)
1321  return -1;
1322  return url_open_dyn_buf_internal(s, max_packet_size);
1323 }
1324 
1326 {
1327  DynBuffer *d;
1328 
1329  if (!s) {
1330  *pbuffer = NULL;
1331  return 0;
1332  }
1333 
1334  avio_flush(s);
1335 
1336  d = s->opaque;
1337  *pbuffer = d->buffer;
1338 
1339  return d->size;
1340 }
1341 
1343 {
1344  DynBuffer *d;
1345  int size;
1346  static const char padbuf[AV_INPUT_BUFFER_PADDING_SIZE] = {0};
1347  int padding = 0;
1348 
1349  if (!s) {
1350  *pbuffer = NULL;
1351  return 0;
1352  }
1353 
1354  /* don't attempt to pad fixed-size packet buffers */
1355  if (!s->max_packet_size) {
1356  avio_write(s, padbuf, sizeof(padbuf));
1357  padding = AV_INPUT_BUFFER_PADDING_SIZE;
1358  }
1359 
1360  avio_flush(s);
1361 
1362  d = s->opaque;
1363  *pbuffer = d->buffer;
1364  size = d->size;
1365  av_free(d);
1366 
1367  avio_context_free(&s);
1368 
1369  return size - padding;
1370 }
1371 
1373 {
1374  uint8_t *tmp;
1375  if (!*s)
1376  return;
1377  avio_close_dyn_buf(*s, &tmp);
1378  av_free(tmp);
1379  *s = NULL;
1380 }
1381 
1382 static int null_buf_write(void *opaque, uint8_t *buf, int buf_size)
1383 {
1384  DynBuffer *d = opaque;
1385 
1386  d->pos += buf_size;
1387  if (d->pos > d->size)
1388  d->size = d->pos;
1389  return buf_size;
1390 }
1391 
1393 {
1394  int ret = url_open_dyn_buf_internal(s, 0);
1395  if (ret >= 0) {
1396  AVIOContext *pb = *s;
1398  }
1399  return ret;
1400 }
1401 
1403 {
1404  DynBuffer *d = s->opaque;
1405  int size;
1406 
1407  avio_flush(s);
1408 
1409  size = d->size;
1410  av_free(d);
1411 
1412  avio_context_free(&s);
1413 
1414  return size;
1415 }
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
Definition: ffmpeg.c:671
void avio_wl64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:462
#define NULL
Definition: coverity.c:32
const char const char void * val
Definition: avisynth_c.h:771
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:129
static int64_t dyn_buf_seek(void *opaque, int64_t offset, int whence)
Definition: aviobuf.c:1277
const char * s
Definition: avisynth_c.h:768
Bytestream IO Context.
Definition: avio.h:161
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
Buffered I/O operations.
uint64_t avio_rb64(AVIOContext *s)
Definition: aviobuf.c:857
int64_t(* read_seek)(void *opaque, int stream_index, int64_t timestamp, int flags)
Seek to a given timestamp in stream with the specified stream_index.
Definition: avio.h:256
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1313
#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:361
int ffurl_open_whitelist(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char *blacklist, URLContext *parent)
Create an URLContext for accessing to the resource indicated by url, and open it. ...
Definition: avio.c:307
#define av_realloc_f(p, o, n)
uint8_t io_buffer[1]
Definition: aviobuf.c:1226
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:480
AVOption.
Definition: opt.h:246
static int64_t io_read_seek(void *opaque, int stream_index, int64_t timestamp, int flags)
Definition: aviobuf.c:908
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
int(* short_seek_get)(void *opaque)
A callback that is used instead of short_seek_threshold.
Definition: avio.h:339
const char * fmt
Definition: avisynth_c.h:769
int64_t last_time
Definition: avio.h:333
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
int avio_feof(AVIOContext *s)
feof() equivalent for AVIOContext.
Definition: aviobuf.c:356
#define LIBAVUTIL_VERSION_INT
Definition: version.h:86
unsigned char * buf_ptr
Current position in the buffer.
Definition: avio.h:228
int writeout_count
writeout statistic This field is internal to libavformat and access from outside is not allowed...
Definition: avio.h:292
unsigned char * buf_end
End of the data, may be less than buffer+buffer_size if the read function returned less data than req...
Definition: avio.h:229
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:419
#define D
Definition: aviobuf.c:63
int write_flag
true if open for writing
Definition: avio.h:241
int is_streamed
true if streamed (no seek possible), default = false
Definition: url.h:45
int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1325
#define AVIO_SEEKABLE_TIME
Seeking by timestamp with avio_seek_time() is possible.
Definition: avio.h:45
#define vsnprintf
Definition: snprintf.h:36
void ffio_fill(AVIOContext *s, int b, int count)
Definition: aviobuf.c:202
const char * b
Definition: vf_curves.c:113
#define AVIO_FLAG_READ
read-only
Definition: avio.h:660
unsigned int avio_rl24(AVIOContext *s)
Definition: aviobuf.c:751
int min_packet_size
Try to buffer at least this amount of data before flushing it.
Definition: avio.h:352
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:1183
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:661
unsigned char * buffer
Start of the buffer.
Definition: avio.h:226
#define OFFSET(x)
Definition: aviobuf.c:61
void avio_wl24(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:486
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:194
int flags
Definition: url.h:43
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:1137
int64_t(* seek)(void *opaque, int64_t offset, int whence)
Definition: avio.h:237
void * opaque
A private pointer, passed to the read/write/seek/...
Definition: avio.h:233
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:222
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:382
#define IO_BUFFER_SIZE
Definition: aviobuf.c:36
static const AVClass * ff_avio_child_class_next(const AVClass *prev)
Definition: aviobuf.c:56
static int io_read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:876
Trailer data, which doesn't contain actual content, but only for finalizing the output file...
Definition: avio.h:140
Format I/O context.
Definition: avformat.h:1349
int avio_accept(AVIOContext *s, AVIOContext **c)
Accept and allocate a client context on a server context.
Definition: aviobuf.c:1201
URLContext * h
Definition: aviobuf.c:46
int avio_put_str(AVIOContext *s, const char *str)
Write a NULL-terminated string.
Definition: aviobuf.c:390
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:374
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
Public dictionary API.
uint8_t
#define av_malloc(s)
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:64
AVOptions.
A point in the output bytestream where the underlying AVIOContext might flush the buffer depending on...
Definition: avio.h:146
static void fill_buffer(AVIOContext *s)
Definition: aviobuf.c:536
static int io_read_pause(void *opaque, int pause)
Definition: aviobuf.c:900
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){intplanes=out->planar?out->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
unsigned long ffio_get_checksum(AVIOContext *s)
Definition: aviobuf.c:608
void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type)
Mark the written bytestream as a specific type.
Definition: aviobuf.c:498
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
Definition: aviobuf.c:236
int ffio_open_null_buf(AVIOContext **s)
Open a write-only fake memory stream.
Definition: aviobuf.c:1392
int ffio_init_context(AVIOContext *s, unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
Definition: aviobuf.c:81
A point in the output bytestream where a demuxer can start parsing (for non self synchronizing bytest...
Definition: avio.h:128
void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size)
Append data to a print buffer.
Definition: bprint.c:158
Public header for CRC hash function implementation.
int64_t bytes_read
Bytes read statistic This field is internal to libavformat and access from outside is not allowed...
Definition: avio.h:280
char * protocol_whitelist
',' separated list of allowed protocols.
Definition: avformat.h:1887
static int flags
Definition: log.c:57
#define AVERROR_EOF
End of file.
Definition: error.h:55
int ffio_set_buf_size(AVIOContext *s, int buf_size)
Definition: aviobuf.c:1003
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:694
ptrdiff_t size
Definition: opengl_enc.c:101
void avio_wb24(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:492
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:474
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:1081
unsigned long ff_crcEDB88320_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:596
const OptionDef options[]
Definition: ffserver.c:3948
#define av_log(a,...)
static void flush_buffer(AVIOContext *s)
Definition: aviobuf.c:178
int max_packet_size
Definition: avio.h:242
Callback for checking whether to abort blocking functions.
Definition: avio.h:58
int64_t written
Definition: avio.h:341
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int io_buffer_size
Definition: aviobuf.c:1225
int(* write_packet)(void *opaque, uint8_t *buf, int buf_size)
Definition: avio.h:236
unsigned int avio_rb24(AVIOContext *s)
Definition: aviobuf.c:783
const AVIOInterruptCB int_cb
Definition: ffmpeg.c:464
static int dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:1262
const char * protocol_whitelist
Definition: url.h:49
int(* read_packet)(void *opaque, uint8_t *buf, int buf_size)
Definition: avio.h:235
av_default_item_name
static const AVOption ff_avio_options[]
Definition: aviobuf.c:64
#define AVERROR(e)
Definition: error.h:43
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
simple assert() macros that are a bit more flexible than ISO C assert().
unsigned long checksum
Definition: avio.h:243
static void * ff_avio_child_next(void *obj, void *prev)
Definition: aviobuf.c:49
#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
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
GLsizei count
Definition: opengl_enc.c:109
#define FFMAX(a, b)
Definition: common.h:94
int direct
avio_read and avio_write should if possible be satisfied directly instead of going through a buffer...
Definition: avio.h:274
#define fail()
Definition: checkasm.h:109
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:743
int seek_count
seek statistic This field is internal to libavformat and access from outside is not allowed...
Definition: avio.h:286
int avio_pause(AVIOContext *s, int pause)
Pause and resume playing - only meaningful if using a network streaming protocol (e.g.
Definition: aviobuf.c:1157
int(* write_data_type)(void *opaque, uint8_t *buf, int buf_size, enum AVIODataMarkerType type, int64_t time)
A callback that is used instead of write_packet.
Definition: avio.h:320
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:759
This is any, unlabelled data.
Definition: avio.h:135
int size
Definition: aviobuf.c:1223
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:261
int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:686
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:244
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
int ffurl_get_short_seek(URLContext *h)
Return the current short seek threshold value for this URL.
Definition: avio.c:646
#define FFMIN(a, b)
Definition: common.h:96
const AVClass ff_avio_class
Definition: aviobuf.c:69
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1342
unsigned char * checksum_ptr
Definition: avio.h:244
int avio_printf(AVIOContext *s, const char *fmt,...)
Definition: aviobuf.c:1144
AVIODataMarkerType
Different data types that can be returned via the AVIO write_data_type callback.
Definition: avio.h:111
int ffio_open2_wrapper(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Definition: aviobuf.c:1106
int allocated_size
Definition: aviobuf.c:1223
int ffurl_handshake(URLContext *c)
Perform one step of the protocol handshake to accept a new client.
Definition: avio.c:234
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:357
void avio_context_free(AVIOContext **ps)
Free the supplied IO context and everything associated with it.
Definition: aviobuf.c:146
static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:1229
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Definition: bprint.h:185
int ff_get_line(AVIOContext *s, char *buf, int maxlen)
Read a whole line of text from AVIOContext.
Definition: aviobuf.c:798
#define GET_STR16(type, read)
Definition: aviobuf.c:833
static volatile int checksum
Definition: adler32.c:30
unsigned long(* update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size)
Definition: avio.h:245
int ffurl_accept(URLContext *s, URLContext **c)
Accept an URLContext c on an URLContext s.
Definition: avio.c:226
int buffer_size
Maximum buffer size.
Definition: avio.h:227
void avio_wb64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:468
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:637
uint8_t le
Definition: crc.c:295
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:40
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:1318
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:163
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:237
const char * protocol_blacklist
Definition: url.h:50
#define PUT_STR16(type, big_endian)
Definition: aviobuf.c:431
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:1076
static int io_short_seek(void *opaque)
Definition: aviobuf.c:894
int64_t(* url_read_seek)(URLContext *h, int stream_index, int64_t timestamp, int flags)
Definition: url.h:83
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:1033
static int url_resetbuf(AVIOContext *s, int flags)
Definition: aviobuf.c:1019
uint64_t avio_rl64(AVIOContext *s)
Definition: aviobuf.c:767
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: aviobuf.c:1112
void * buf
Definition: avisynth_c.h:690
Definition: url.h:38
GLint GLenum type
Definition: opengl_enc.c:105
Describe the class of an AVClass context structure.
Definition: log.h:67
#define AV_WB32(p, v)
Definition: intreadwrite.h:424
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:216
#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:538
#define AVIO_FLAG_DIRECT
Use direct mode.
Definition: avio.h:687
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:775
int pos
Definition: aviobuf.c:1223
int short_seek_threshold
Threshold to favor readahead over seek.
Definition: avio.h:305
#define PUT_UTF16(val, tmp, PUT_16BIT)
Convert a 32-bit Unicode character to its UTF-16 encoded form (2 or 4 bytes).
Definition: common.h:448
int ignore_boundary_point
If set, don't call write_data_type separately for AVIO_DATA_MARKER_BOUNDARY_POINT, but ignore them and treat them as AVIO_DATA_MARKER_UNKNOWN (to avoid needlessly small chunks of data returned from the callback).
Definition: avio.h:327
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
Definition: aviobuf.c:1372
int error
contains the error code or 0 if no error happened
Definition: avio.h:246
int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
Ensures that the requested seekback buffer size will be available.
Definition: aviobuf.c:974
int(* read_pause)(void *opaque, int pause)
Pause or resume playback for network streaming protocols - e.g.
Definition: avio.h:250
int ff_get_v_length(uint64_t val)
Get the length in bytes which is needed to store val as v.
Definition: aviobuf.c:442
int ffurl_close(URLContext *h)
Definition: avio.c:465
const AVClass ffurl_context_class
Definition: avio.c:63
int orig_buffer_size
Original buffer size used internally after probing and ensure seekback to reset the buffer size This ...
Definition: avio.h:299
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
Definition: crc.c:343
enum AVIODataMarkerType current_type
Internal, not meant to be used from outside of AVIOContext.
Definition: avio.h:332
int avio_handshake(AVIOContext *c)
Perform one step of the protocol handshake to accept a new client.
Definition: aviobuf.c:1213
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:1100
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:334
Main libavformat public API header.
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1544
int avio_get_str(AVIOContext *s, int maxlen, char *buf, int buflen)
Read a string from pb into buf.
Definition: aviobuf.c:815
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:432
const struct URLProtocol * prot
Definition: url.h:40
int ffio_fdopen(AVIOContext **s, URLContext *h)
Create and initialize a AVIOContext for accessing the resource referenced by the URLContext h...
Definition: aviobuf.c:916
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:616
static double c[64]
int64_t pos
position in the file of the current buffer
Definition: avio.h:238
#define AVSEEK_SIZE
ORing this as the "whence" parameter to a seek function causes it to return the filesize without seek...
Definition: avio.h:530
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:777
uint64_t ffio_read_varlen(AVIOContext *bc)
Definition: aviobuf.c:865
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:790
unsigned char * buf_ptr_max
Maximum reached position before a backward seek in the write buffer, used keeping track of already wr...
Definition: avio.h:347
A point in the output bytestream where a decoder can start decoding (i.e.
Definition: avio.h:122
#define av_free(p)
uint8_t * buffer
Definition: aviobuf.c:1224
static int put_str16(AVIOContext *s, const char *str, const int be)
Definition: aviobuf.c:401
int eof_reached
true if eof reached
Definition: avio.h:240
static int io_write_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:882
void ff_put_v(AVIOContext *bc, uint64_t val)
Put val using a variable number of bytes.
Definition: aviobuf.c:452
int len
int ffio_close_null_buf(AVIOContext *s)
Close a null buffer.
Definition: aviobuf.c:1402
static int null_buf_write(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:1382
static void writeout(AVIOContext *s, const uint8_t *data, int len)
Definition: aviobuf.c:151
int avio_read_partial(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:706
static int url_open_dyn_buf_internal(AVIOContext **s, int max_packet_size)
Definition: aviobuf.c:1291
char * protocol_blacklist
',' separated list of disallowed protocols.
Definition: avformat.h:1922
int max_packet_size
if non zero, the stream is packetized with this max packet size
Definition: url.h:44
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:329
#define av_freep(p)
unbuffered private I/O API
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:590
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:628
int min_packet_size
if non zero, the stream is packetized with this min packet size
Definition: url.h:51
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:405
static int64_t io_seek(void *opaque, int64_t offset, int whence)
Definition: aviobuf.c:888
Header data; this needs to be present for the stream to be decodeable.
Definition: avio.h:115
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
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:1164
unsigned long ff_crcA001_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:602
GLuint buffer
Definition: opengl_enc.c:102
static uint8_t tmp[11]
Definition: aes_ctr.c:26