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