FFmpeg  3.4.9
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 
498 void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type)
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 && len >= 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  len = s->orig_buffer_size;
569  }
570 
571  if (s->read_packet)
572  len = s->read_packet(s->opaque, dst, len);
573  else
574  len = 0;
575  if (len <= 0) {
576  /* do not modify buffer if EOF reached so that a seek back can
577  be done without rereading data */
578  s->eof_reached = 1;
579  if (len < 0)
580  s->error = len;
581  } else {
582  s->pos += len;
583  s->buf_ptr = dst;
584  s->buf_end = dst + len;
585  s->bytes_read += len;
586  }
587 }
588 
589 unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf,
590  unsigned int len)
591 {
592  return av_crc(av_crc_get_table(AV_CRC_32_IEEE), checksum, buf, len);
593 }
594 
595 unsigned long ff_crcEDB88320_update(unsigned long checksum, const uint8_t *buf,
596  unsigned int len)
597 {
598  return av_crc(av_crc_get_table(AV_CRC_32_IEEE_LE), checksum, buf, len);
599 }
600 
601 unsigned long ff_crcA001_update(unsigned long checksum, const uint8_t *buf,
602  unsigned int len)
603 {
604  return av_crc(av_crc_get_table(AV_CRC_16_ANSI_LE), checksum, buf, len);
605 }
606 
608 {
610  s->buf_ptr - s->checksum_ptr);
611  s->update_checksum = NULL;
612  return s->checksum;
613 }
614 
616  unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len),
617  unsigned long checksum)
618 {
619  s->update_checksum = update_checksum;
620  if (s->update_checksum) {
621  s->checksum = checksum;
622  s->checksum_ptr = s->buf_ptr;
623  }
624 }
625 
626 /* XXX: put an inline version */
628 {
629  if (s->buf_ptr >= s->buf_end)
630  fill_buffer(s);
631  if (s->buf_ptr < s->buf_end)
632  return *s->buf_ptr++;
633  return 0;
634 }
635 
636 int avio_read(AVIOContext *s, unsigned char *buf, int size)
637 {
638  int len, size1;
639 
640  size1 = size;
641  while (size > 0) {
642  len = FFMIN(s->buf_end - s->buf_ptr, size);
643  if (len == 0 || s->write_flag) {
644  if((s->direct || size > s->buffer_size) && !s->update_checksum) {
645  // bypass the buffer and read data directly into buf
646  if(s->read_packet)
647  len = s->read_packet(s->opaque, buf, size);
648 
649  if (len <= 0) {
650  /* do not modify buffer if EOF reached so that a seek back can
651  be done without rereading data */
652  s->eof_reached = 1;
653  if(len<0)
654  s->error= len;
655  break;
656  } else {
657  s->pos += len;
658  s->bytes_read += len;
659  size -= len;
660  buf += len;
661  // reset the buffer
662  s->buf_ptr = s->buffer;
663  s->buf_end = s->buffer/* + len*/;
664  }
665  } else {
666  fill_buffer(s);
667  len = s->buf_end - s->buf_ptr;
668  if (len == 0)
669  break;
670  }
671  } else {
672  memcpy(buf, s->buf_ptr, len);
673  buf += len;
674  s->buf_ptr += len;
675  size -= len;
676  }
677  }
678  if (size1 == size) {
679  if (s->error) return s->error;
680  if (avio_feof(s)) return AVERROR_EOF;
681  }
682  return size1 - size;
683 }
684 
685 int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
686 {
687  int ret = avio_read(s, buf, size);
688  if (ret != size)
689  return AVERROR_INVALIDDATA;
690  return ret;
691 }
692 
693 int ffio_read_indirect(AVIOContext *s, unsigned char *buf, int size, const unsigned char **data)
694 {
695  if (s->buf_end - s->buf_ptr >= size && !s->write_flag) {
696  *data = s->buf_ptr;
697  s->buf_ptr += size;
698  return size;
699  } else {
700  *data = buf;
701  return avio_read(s, buf, size);
702  }
703 }
704 
705 int avio_read_partial(AVIOContext *s, unsigned char *buf, int size)
706 {
707  int len;
708 
709  if (size < 0)
710  return -1;
711 
712  if (s->read_packet && s->write_flag) {
713  len = s->read_packet(s->opaque, buf, size);
714  if (len > 0)
715  s->pos += len;
716  return len;
717  }
718 
719  len = s->buf_end - s->buf_ptr;
720  if (len == 0) {
721  /* Reset the buf_end pointer to the start of the buffer, to make sure
722  * the fill_buffer call tries to read as much data as fits into the
723  * full buffer, instead of just what space is left after buf_end.
724  * This avoids returning partial packets at the end of the buffer,
725  * for packet based inputs.
726  */
727  s->buf_end = s->buf_ptr = s->buffer;
728  fill_buffer(s);
729  len = s->buf_end - s->buf_ptr;
730  }
731  if (len > size)
732  len = size;
733  memcpy(buf, s->buf_ptr, len);
734  s->buf_ptr += len;
735  if (!len) {
736  if (s->error) return s->error;
737  if (avio_feof(s)) return AVERROR_EOF;
738  }
739  return len;
740 }
741 
742 unsigned int avio_rl16(AVIOContext *s)
743 {
744  unsigned int val;
745  val = avio_r8(s);
746  val |= avio_r8(s) << 8;
747  return val;
748 }
749 
750 unsigned int avio_rl24(AVIOContext *s)
751 {
752  unsigned int val;
753  val = avio_rl16(s);
754  val |= avio_r8(s) << 16;
755  return val;
756 }
757 
758 unsigned int avio_rl32(AVIOContext *s)
759 {
760  unsigned int val;
761  val = avio_rl16(s);
762  val |= avio_rl16(s) << 16;
763  return val;
764 }
765 
766 uint64_t avio_rl64(AVIOContext *s)
767 {
768  uint64_t val;
769  val = (uint64_t)avio_rl32(s);
770  val |= (uint64_t)avio_rl32(s) << 32;
771  return val;
772 }
773 
774 unsigned int avio_rb16(AVIOContext *s)
775 {
776  unsigned int val;
777  val = avio_r8(s) << 8;
778  val |= avio_r8(s);
779  return val;
780 }
781 
782 unsigned int avio_rb24(AVIOContext *s)
783 {
784  unsigned int val;
785  val = avio_rb16(s) << 8;
786  val |= avio_r8(s);
787  return val;
788 }
789 unsigned int avio_rb32(AVIOContext *s)
790 {
791  unsigned int val;
792  val = avio_rb16(s) << 16;
793  val |= avio_rb16(s);
794  return val;
795 }
796 
797 int ff_get_line(AVIOContext *s, char *buf, int maxlen)
798 {
799  int i = 0;
800  char c;
801 
802  do {
803  c = avio_r8(s);
804  if (c && i < maxlen-1)
805  buf[i++] = c;
806  } while (c != '\n' && c != '\r' && c);
807  if (c == '\r' && avio_r8(s) != '\n' && !avio_feof(s))
808  avio_skip(s, -1);
809 
810  buf[i] = 0;
811  return i;
812 }
813 
814 int avio_get_str(AVIOContext *s, int maxlen, char *buf, int buflen)
815 {
816  int i;
817 
818  if (buflen <= 0)
819  return AVERROR(EINVAL);
820  // reserve 1 byte for terminating 0
821  buflen = FFMIN(buflen - 1, maxlen);
822  for (i = 0; i < buflen; i++)
823  if (!(buf[i] = avio_r8(s)))
824  return i + 1;
825  buf[i] = 0;
826  for (; i < maxlen; i++)
827  if (!avio_r8(s))
828  return i + 1;
829  return maxlen;
830 }
831 
832 #define GET_STR16(type, read) \
833  int avio_get_str16 ##type(AVIOContext *pb, int maxlen, char *buf, int buflen)\
834 {\
835  char* q = buf;\
836  int ret = 0;\
837  if (buflen <= 0) \
838  return AVERROR(EINVAL); \
839  while (ret + 1 < maxlen) {\
840  uint8_t tmp;\
841  uint32_t ch;\
842  GET_UTF16(ch, (ret += 2) <= maxlen ? read(pb) : 0, break;)\
843  if (!ch)\
844  break;\
845  PUT_UTF8(ch, tmp, if (q - buf < buflen - 1) *q++ = tmp;)\
846  }\
847  *q = 0;\
848  return ret;\
849 }\
850 
852 GET_STR16(be, avio_rb16)
853 
854 #undef GET_STR16
855 
856 uint64_t avio_rb64(AVIOContext *s)
857 {
858  uint64_t val;
859  val = (uint64_t)avio_rb32(s) << 32;
860  val |= (uint64_t)avio_rb32(s);
861  return val;
862 }
863 
865  uint64_t val = 0;
866  int tmp;
867 
868  do{
869  tmp = avio_r8(bc);
870  val= (val<<7) + (tmp&127);
871  }while(tmp&128);
872  return val;
873 }
874 
875 static int io_read_packet(void *opaque, uint8_t *buf, int buf_size)
876 {
877  AVIOInternal *internal = opaque;
878  return ffurl_read(internal->h, buf, buf_size);
879 }
880 
881 static int io_write_packet(void *opaque, uint8_t *buf, int buf_size)
882 {
883  AVIOInternal *internal = opaque;
884  return ffurl_write(internal->h, buf, buf_size);
885 }
886 
887 static int64_t io_seek(void *opaque, int64_t offset, int whence)
888 {
889  AVIOInternal *internal = opaque;
890  return ffurl_seek(internal->h, offset, whence);
891 }
892 
893 static int io_short_seek(void *opaque)
894 {
895  AVIOInternal *internal = opaque;
896  return ffurl_get_short_seek(internal->h);
897 }
898 
899 static int io_read_pause(void *opaque, int pause)
900 {
901  AVIOInternal *internal = opaque;
902  if (!internal->h->prot->url_read_pause)
903  return AVERROR(ENOSYS);
904  return internal->h->prot->url_read_pause(internal->h, pause);
905 }
906 
907 static int64_t io_read_seek(void *opaque, int stream_index, int64_t timestamp, int flags)
908 {
909  AVIOInternal *internal = opaque;
910  if (!internal->h->prot->url_read_seek)
911  return AVERROR(ENOSYS);
912  return internal->h->prot->url_read_seek(internal->h, stream_index, timestamp, flags);
913 }
914 
916 {
917  AVIOInternal *internal = NULL;
918  uint8_t *buffer = NULL;
919  int buffer_size, max_packet_size;
920 
921  max_packet_size = h->max_packet_size;
922  if (max_packet_size) {
923  buffer_size = max_packet_size; /* no need to bufferize more than one packet */
924  } else {
925  buffer_size = IO_BUFFER_SIZE;
926  }
927  buffer = av_malloc(buffer_size);
928  if (!buffer)
929  return AVERROR(ENOMEM);
930 
931  internal = av_mallocz(sizeof(*internal));
932  if (!internal)
933  goto fail;
934 
935  internal->h = h;
936 
937  *s = avio_alloc_context(buffer, buffer_size, h->flags & AVIO_FLAG_WRITE,
939  if (!*s)
940  goto fail;
941 
942  (*s)->protocol_whitelist = av_strdup(h->protocol_whitelist);
943  if (!(*s)->protocol_whitelist && h->protocol_whitelist) {
944  avio_closep(s);
945  goto fail;
946  }
947  (*s)->protocol_blacklist = av_strdup(h->protocol_blacklist);
948  if (!(*s)->protocol_blacklist && h->protocol_blacklist) {
949  avio_closep(s);
950  goto fail;
951  }
952  (*s)->direct = h->flags & AVIO_FLAG_DIRECT;
953 
954  (*s)->seekable = h->is_streamed ? 0 : AVIO_SEEKABLE_NORMAL;
955  (*s)->max_packet_size = max_packet_size;
956  (*s)->min_packet_size = h->min_packet_size;
957  if(h->prot) {
958  (*s)->read_pause = io_read_pause;
959  (*s)->read_seek = io_read_seek;
960 
961  if (h->prot->url_read_seek)
962  (*s)->seekable |= AVIO_SEEKABLE_TIME;
963  }
964  (*s)->short_seek_get = io_short_seek;
965  (*s)->av_class = &ff_avio_class;
966  return 0;
967 fail:
968  av_freep(&internal);
969  av_freep(&buffer);
970  return AVERROR(ENOMEM);
971 }
972 
973 int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
974 {
975  uint8_t *buffer;
976  int max_buffer_size = s->max_packet_size ?
978  int filled = s->buf_end - s->buffer;
979  ptrdiff_t checksum_ptr_offset = s->checksum_ptr ? s->checksum_ptr - s->buffer : -1;
980 
981  buf_size += s->buf_ptr - s->buffer + max_buffer_size;
982 
983  if (buf_size < filled || s->seekable || !s->read_packet)
984  return 0;
985  av_assert0(!s->write_flag);
986 
987  buffer = av_malloc(buf_size);
988  if (!buffer)
989  return AVERROR(ENOMEM);
990 
991  memcpy(buffer, s->buffer, filled);
992  av_free(s->buffer);
993  s->buf_ptr = buffer + (s->buf_ptr - s->buffer);
994  s->buf_end = buffer + (s->buf_end - s->buffer);
995  s->buffer = buffer;
996  s->buffer_size = buf_size;
997  if (checksum_ptr_offset >= 0)
998  s->checksum_ptr = s->buffer + checksum_ptr_offset;
999  return 0;
1000 }
1001 
1002 int ffio_set_buf_size(AVIOContext *s, int buf_size)
1003 {
1004  uint8_t *buffer;
1005  buffer = av_malloc(buf_size);
1006  if (!buffer)
1007  return AVERROR(ENOMEM);
1008 
1009  av_free(s->buffer);
1010  s->buffer = buffer;
1011  s->orig_buffer_size =
1012  s->buffer_size = buf_size;
1013  s->buf_ptr = s->buf_ptr_max = buffer;
1015  return 0;
1016 }
1017 
1018 static int url_resetbuf(AVIOContext *s, int flags)
1019 {
1020  av_assert1(flags == AVIO_FLAG_WRITE || flags == AVIO_FLAG_READ);
1021 
1022  if (flags & AVIO_FLAG_WRITE) {
1023  s->buf_end = s->buffer + s->buffer_size;
1024  s->write_flag = 1;
1025  } else {
1026  s->buf_end = s->buffer;
1027  s->write_flag = 0;
1028  }
1029  return 0;
1030 }
1031 
1032 int ffio_rewind_with_probe_data(AVIOContext *s, unsigned char **bufp, int buf_size)
1033 {
1034  int64_t buffer_start;
1035  int buffer_size;
1036  int overlap, new_size, alloc_size;
1037  uint8_t *buf = *bufp;
1038 
1039  if (s->write_flag) {
1040  av_freep(bufp);
1041  return AVERROR(EINVAL);
1042  }
1043 
1044  buffer_size = s->buf_end - s->buffer;
1045 
1046  /* the buffers must touch or overlap */
1047  if ((buffer_start = s->pos - buffer_size) > buf_size) {
1048  av_freep(bufp);
1049  return AVERROR(EINVAL);
1050  }
1051 
1052  overlap = buf_size - buffer_start;
1053  new_size = buf_size + buffer_size - overlap;
1054 
1055  alloc_size = FFMAX(s->buffer_size, new_size);
1056  if (alloc_size > buf_size)
1057  if (!(buf = (*bufp) = av_realloc_f(buf, 1, alloc_size)))
1058  return AVERROR(ENOMEM);
1059 
1060  if (new_size > buf_size) {
1061  memcpy(buf + buf_size, s->buffer + overlap, buffer_size - overlap);
1062  buf_size = new_size;
1063  }
1064 
1065  av_free(s->buffer);
1066  s->buf_ptr = s->buffer = buf;
1067  s->buffer_size = alloc_size;
1068  s->pos = buf_size;
1069  s->buf_end = s->buf_ptr + buf_size;
1070  s->eof_reached = 0;
1071 
1072  return 0;
1073 }
1074 
1075 int avio_open(AVIOContext **s, const char *filename, int flags)
1076 {
1077  return avio_open2(s, filename, flags, NULL, NULL);
1078 }
1079 
1080 int ffio_open_whitelist(AVIOContext **s, const char *filename, int flags,
1082  const char *whitelist, const char *blacklist
1083  )
1084 {
1085  URLContext *h;
1086  int err;
1087 
1088  err = ffurl_open_whitelist(&h, filename, flags, int_cb, options, whitelist, blacklist, NULL);
1089  if (err < 0)
1090  return err;
1091  err = ffio_fdopen(s, h);
1092  if (err < 0) {
1093  ffurl_close(h);
1094  return err;
1095  }
1096  return 0;
1097 }
1098 
1099 int avio_open2(AVIOContext **s, const char *filename, int flags,
1101 {
1102  return ffio_open_whitelist(s, filename, flags, int_cb, options, NULL, NULL);
1103 }
1104 
1105 int ffio_open2_wrapper(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags,
1107 {
1108  return ffio_open_whitelist(pb, url, flags, int_cb, options, s->protocol_whitelist, s->protocol_blacklist);
1109 }
1110 
1112 {
1113  AVIOInternal *internal;
1114  URLContext *h;
1115 
1116  if (!s)
1117  return 0;
1118 
1119  avio_flush(s);
1120  internal = s->opaque;
1121  h = internal->h;
1122 
1123  av_freep(&s->opaque);
1124  av_freep(&s->buffer);
1125  if (s->write_flag)
1126  av_log(s, AV_LOG_DEBUG, "Statistics: %d seeks, %d writeouts\n", s->seek_count, s->writeout_count);
1127  else
1128  av_log(s, AV_LOG_DEBUG, "Statistics: %"PRId64" bytes read, %d seeks\n", s->bytes_read, s->seek_count);
1129  av_opt_free(s);
1130 
1131  avio_context_free(&s);
1132 
1133  return ffurl_close(h);
1134 }
1135 
1137 {
1138  int ret = avio_close(*s);
1139  *s = NULL;
1140  return ret;
1141 }
1142 
1143 int avio_printf(AVIOContext *s, const char *fmt, ...)
1144 {
1145  va_list ap;
1146  char buf[4096]; /* update doc entry in avio.h if changed */
1147  int ret;
1148 
1149  va_start(ap, fmt);
1150  ret = vsnprintf(buf, sizeof(buf), fmt, ap);
1151  va_end(ap);
1152  avio_write(s, buf, strlen(buf));
1153  return ret;
1154 }
1155 
1156 int avio_pause(AVIOContext *s, int pause)
1157 {
1158  if (!s->read_pause)
1159  return AVERROR(ENOSYS);
1160  return s->read_pause(s->opaque, pause);
1161 }
1162 
1163 int64_t avio_seek_time(AVIOContext *s, int stream_index,
1164  int64_t timestamp, int flags)
1165 {
1166  int64_t ret;
1167  if (!s->read_seek)
1168  return AVERROR(ENOSYS);
1169  ret = s->read_seek(s->opaque, stream_index, timestamp, flags);
1170  if (ret >= 0) {
1171  int64_t pos;
1172  s->buf_ptr = s->buf_end; // Flush buffer
1173  pos = s->seek(s->opaque, 0, SEEK_CUR);
1174  if (pos >= 0)
1175  s->pos = pos;
1176  else if (pos != AVERROR(ENOSYS))
1177  ret = pos;
1178  }
1179  return ret;
1180 }
1181 
1182 int avio_read_to_bprint(AVIOContext *h, AVBPrint *pb, size_t max_size)
1183 {
1184  int ret;
1185  char buf[1024];
1186  while (max_size) {
1187  ret = avio_read(h, buf, FFMIN(max_size, sizeof(buf)));
1188  if (ret == AVERROR_EOF)
1189  return 0;
1190  if (ret <= 0)
1191  return ret;
1192  av_bprint_append_data(pb, buf, ret);
1193  if (!av_bprint_is_complete(pb))
1194  return AVERROR(ENOMEM);
1195  max_size -= ret;
1196  }
1197  return 0;
1198 }
1199 
1201 {
1202  int ret;
1203  AVIOInternal *internal = s->opaque;
1204  URLContext *sc = internal->h;
1205  URLContext *cc = NULL;
1206  ret = ffurl_accept(sc, &cc);
1207  if (ret < 0)
1208  return ret;
1209  return ffio_fdopen(c, cc);
1210 }
1211 
1213 {
1214  AVIOInternal *internal = c->opaque;
1215  URLContext *cc = internal->h;
1216  return ffurl_handshake(cc);
1217 }
1218 
1219 /* output in a dynamic buffer */
1220 
1221 typedef struct DynBuffer {
1222  int pos, size, allocated_size;
1225  uint8_t io_buffer[1];
1226 } DynBuffer;
1227 
1228 static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
1229 {
1230  DynBuffer *d = opaque;
1231  unsigned new_size, new_allocated_size;
1232 
1233  /* reallocate buffer if needed */
1234  new_size = (unsigned)d->pos + buf_size;
1235  new_allocated_size = d->allocated_size;
1236  if (new_size < d->pos || new_size > INT_MAX/2)
1237  return -1;
1238  while (new_size > new_allocated_size) {
1239  if (!new_allocated_size)
1240  new_allocated_size = new_size;
1241  else
1242  new_allocated_size += new_allocated_size / 2 + 1;
1243  }
1244 
1245  if (new_allocated_size > d->allocated_size) {
1246  int err;
1247  if ((err = av_reallocp(&d->buffer, new_allocated_size)) < 0) {
1248  d->allocated_size = 0;
1249  d->size = 0;
1250  return err;
1251  }
1252  d->allocated_size = new_allocated_size;
1253  }
1254  memcpy(d->buffer + d->pos, buf, buf_size);
1255  d->pos = new_size;
1256  if (d->pos > d->size)
1257  d->size = d->pos;
1258  return buf_size;
1259 }
1260 
1261 static int dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
1262 {
1263  unsigned char buf1[4];
1264  int ret;
1265 
1266  /* packetized write: output the header */
1267  AV_WB32(buf1, buf_size);
1268  ret = dyn_buf_write(opaque, buf1, 4);
1269  if (ret < 0)
1270  return ret;
1271 
1272  /* then the data */
1273  return dyn_buf_write(opaque, buf, buf_size);
1274 }
1275 
1276 static int64_t dyn_buf_seek(void *opaque, int64_t offset, int whence)
1277 {
1278  DynBuffer *d = opaque;
1279 
1280  if (whence == SEEK_CUR)
1281  offset += d->pos;
1282  else if (whence == SEEK_END)
1283  offset += d->size;
1284  if (offset < 0 || offset > 0x7fffffffLL)
1285  return -1;
1286  d->pos = offset;
1287  return 0;
1288 }
1289 
1290 static int url_open_dyn_buf_internal(AVIOContext **s, int max_packet_size)
1291 {
1292  DynBuffer *d;
1293  unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
1294 
1295  if (sizeof(DynBuffer) + io_buffer_size < io_buffer_size)
1296  return -1;
1297  d = av_mallocz(sizeof(DynBuffer) + io_buffer_size);
1298  if (!d)
1299  return AVERROR(ENOMEM);
1300  d->io_buffer_size = io_buffer_size;
1301  *s = avio_alloc_context(d->io_buffer, d->io_buffer_size, 1, d, NULL,
1302  max_packet_size ? dyn_packet_buf_write : dyn_buf_write,
1303  max_packet_size ? NULL : dyn_buf_seek);
1304  if(!*s) {
1305  av_free(d);
1306  return AVERROR(ENOMEM);
1307  }
1308  (*s)->max_packet_size = max_packet_size;
1309  return 0;
1310 }
1311 
1313 {
1314  return url_open_dyn_buf_internal(s, 0);
1315 }
1316 
1317 int ffio_open_dyn_packet_buf(AVIOContext **s, int max_packet_size)
1318 {
1319  if (max_packet_size <= 0)
1320  return -1;
1321  return url_open_dyn_buf_internal(s, max_packet_size);
1322 }
1323 
1325 {
1326  DynBuffer *d;
1327 
1328  if (!s) {
1329  *pbuffer = NULL;
1330  return 0;
1331  }
1332 
1333  avio_flush(s);
1334 
1335  d = s->opaque;
1336  *pbuffer = d->buffer;
1337 
1338  return d->size;
1339 }
1340 
1342 {
1343  DynBuffer *d;
1344  int size;
1345  static const char padbuf[AV_INPUT_BUFFER_PADDING_SIZE] = {0};
1346  int padding = 0;
1347 
1348  if (!s) {
1349  *pbuffer = NULL;
1350  return 0;
1351  }
1352 
1353  /* don't attempt to pad fixed-size packet buffers */
1354  if (!s->max_packet_size) {
1355  avio_write(s, padbuf, sizeof(padbuf));
1356  padding = AV_INPUT_BUFFER_PADDING_SIZE;
1357  }
1358 
1359  avio_flush(s);
1360 
1361  d = s->opaque;
1362  *pbuffer = d->buffer;
1363  size = d->size;
1364  av_free(d);
1365 
1366  avio_context_free(&s);
1367 
1368  return size - padding;
1369 }
1370 
1372 {
1373  uint8_t *tmp;
1374  if (!*s)
1375  return;
1376  avio_close_dyn_buf(*s, &tmp);
1377  av_free(tmp);
1378  *s = NULL;
1379 }
1380 
1381 static int null_buf_write(void *opaque, uint8_t *buf, int buf_size)
1382 {
1383  DynBuffer *d = opaque;
1384 
1385  d->pos += buf_size;
1386  if (d->pos > d->size)
1387  d->size = d->pos;
1388  return buf_size;
1389 }
1390 
1392 {
1393  int ret = url_open_dyn_buf_internal(s, 0);
1394  if (ret >= 0) {
1395  AVIOContext *pb = *s;
1397  }
1398  return ret;
1399 }
1400 
1402 {
1403  DynBuffer *d = s->opaque;
1404  int size;
1405 
1406  avio_flush(s);
1407 
1408  size = d->size;
1409  av_free(d);
1410 
1411  avio_context_free(&s);
1412 
1413  return size;
1414 }
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
Definition: ffmpeg.c:672
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:1276
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:856
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1312
#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 size
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:1225
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:907
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:422
#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:1324
#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:750
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:1182
#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:1136
void * opaque
A private pointer, passed to the read/write/seek/...
Definition: avio.h:233
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:875
Trailer data, which doesn&#39;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:1200
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.
static char buffer[20]
Definition: seek.c:32
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:899
unsigned long ffio_get_checksum(AVIOContext *s)
Definition: aviobuf.c:607
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:1391
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
const char data[16]
Definition: mxf.c:90
char * protocol_whitelist
&#39;,&#39; 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:1002
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:693
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:1080
unsigned long ff_crcEDB88320_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:595
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:1224
unsigned int avio_rb24(AVIOContext *s)
Definition: aviobuf.c:782
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:1261
const char * protocol_whitelist
Definition: url.h:49
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().
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
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
#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:742
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:1156
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:758
This is any, unlabelled data.
Definition: avio.h:135
int size
Definition: aviobuf.c:1222
int(* read_packet)(void *opaque, uint8_t *buf, int buf_size)
Definition: avio.h:235
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:685
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:649
#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:1341
unsigned char * checksum_ptr
Definition: avio.h:244
int avio_printf(AVIOContext *s, const char *fmt,...)
Definition: aviobuf.c:1143
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:1105
int64_t(* seek)(void *opaque, int64_t offset, int whence)
Definition: avio.h:237
int allocated_size
Definition: aviobuf.c:1222
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:1228
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:797
#define GET_STR16(type, read)
Definition: aviobuf.c:832
static volatile int checksum
Definition: adler32.c:30
int ffurl_accept(URLContext *s, URLContext **c)
Accept an URLContext c on an URLContext s.
Definition: avio.c:226
if(ret< 0)
Definition: vf_mcdeint.c:279
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:636
uint8_t le
Definition: crc.c:295
int(* short_seek_get)(void *opaque)
A callback that is used instead of short_seek_threshold.
Definition: avio.h:339
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 &#39;max_packet_size&#39;.
Definition: aviobuf.c:1317
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:1075
static int io_short_seek(void *opaque)
Definition: aviobuf.c:893
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:1032
static int url_resetbuf(AVIOContext *s, int flags)
Definition: aviobuf.c:1018
uint64_t avio_rl64(AVIOContext *s)
Definition: aviobuf.c:766
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: aviobuf.c:1111
int(* write_packet)(void *opaque, uint8_t *buf, int buf_size)
Definition: avio.h:236
void * buf
Definition: avisynth_c.h:690
Definition: url.h:38
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:774
int pos
Definition: aviobuf.c:1222
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&#39;t call write_data_type separately for AVIO_DATA_MARKER_BOUNDARY_POINT, but ignore them and treat them as AVIO_DATA_MARKER_UNKNOWN (to avoid needlessly small chunks of data returned from the callback).
Definition: avio.h:327
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(INT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_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), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { 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) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;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)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } if(HAVE_X86ASM &&HAVE_MMX) 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);return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=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) { int planes=out->planar ? out->ch_count :1;unsigned m=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){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
Definition: aviobuf.c:1371
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:973
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:468
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:1212
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:1099
int(* read_pause)(void *opaque, int pause)
Pause or resume playback for network streaming protocols - e.g.
Definition: avio.h:250
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:814
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:435
const struct URLProtocol * prot
Definition: url.h:40
int(* write_data_type)(void *opaque, uint8_t *buf, int buf_size, enum AVIODataMarkerType type, int64_t time)
A callback that is used instead of write_packet.
Definition: avio.h:320
unsigned long(* update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size)
Definition: avio.h:245
int ffio_fdopen(AVIOContext **s, URLContext *h)
Create and initialize a AVIOContext for accessing the resource referenced by the URLContext h...
Definition: aviobuf.c:915
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:615
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:864
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:789
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:1223
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:881
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:1401
static int null_buf_write(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:1381
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:705
static int url_open_dyn_buf_internal(AVIOContext **s, int max_packet_size)
Definition: aviobuf.c:1290
char * protocol_blacklist
&#39;,&#39; 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)
void INT64 INT64 count
Definition: avisynth_c.h:690
unbuffered private I/O API
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:589
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:627
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:408
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
static int64_t io_seek(void *opaque, int64_t offset, int whence)
Definition: aviobuf.c:887
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:1163
unsigned long ff_crcA001_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:601
int64_t(* url_read_seek)(URLContext *h, int stream_index, int64_t timestamp, int flags)
Definition: url.h:83
static uint8_t tmp[11]
Definition: aes_ctr.c:26