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 static void *ff_avio_child_next(void *obj, void *prev)
46 {
47  AVIOContext *s = obj;
48  return prev ? NULL : s->opaque;
49 }
50 
51 static const AVClass *ff_avio_child_class_next(const AVClass *prev)
52 {
53  return prev ? NULL : &ffurl_context_class;
54 }
55 
56 #define OFFSET(x) offsetof(AVIOContext,x)
57 #define E AV_OPT_FLAG_ENCODING_PARAM
58 #define D AV_OPT_FLAG_DECODING_PARAM
59 static const AVOption ff_avio_options[] = {
60  {"protocol_whitelist", "List of protocols that are allowed to be used", OFFSET(protocol_whitelist), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, D },
61  { NULL },
62 };
63 
65  .class_name = "AVIOContext",
66  .item_name = av_default_item_name,
67  .version = LIBAVUTIL_VERSION_INT,
68  .option = ff_avio_options,
69  .child_next = ff_avio_child_next,
70  .child_class_next = ff_avio_child_class_next,
71 };
72 
73 static void fill_buffer(AVIOContext *s);
74 static int url_resetbuf(AVIOContext *s, int flags);
75 
77  unsigned char *buffer,
78  int buffer_size,
79  int write_flag,
80  void *opaque,
81  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
82  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
83  int64_t (*seek)(void *opaque, int64_t offset, int whence))
84 {
85  memset(s, 0, sizeof(AVIOContext));
86 
87  s->buffer = buffer;
88  s->orig_buffer_size =
89  s->buffer_size = buffer_size;
90  s->buf_ptr = buffer;
91  s->buf_ptr_max = buffer;
92  s->opaque = opaque;
93  s->direct = 0;
94 
95  url_resetbuf(s, write_flag ? AVIO_FLAG_WRITE : AVIO_FLAG_READ);
96 
99  s->seek = seek;
100  s->pos = 0;
101  s->eof_reached = 0;
102  s->error = 0;
103  s->seekable = seek ? AVIO_SEEKABLE_NORMAL : 0;
104  s->min_packet_size = 0;
105  s->max_packet_size = 0;
106  s->update_checksum = NULL;
108 
109  if (!read_packet && !write_flag) {
110  s->pos = buffer_size;
111  s->buf_end = s->buffer + buffer_size;
112  }
113  s->read_pause = NULL;
114  s->read_seek = NULL;
115 
116  s->write_data_type = NULL;
117  s->ignore_boundary_point = 0;
120  s->short_seek_get = NULL;
121  s->written = 0;
122 
123  return 0;
124 }
125 
127  unsigned char *buffer,
128  int buffer_size,
129  int write_flag,
130  void *opaque,
131  int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
132  int (*write_packet)(void *opaque, uint8_t *buf, int buf_size),
133  int64_t (*seek)(void *opaque, int64_t offset, int whence))
134 {
135  AVIOContext *s = av_malloc(sizeof(AVIOContext));
136  if (!s)
137  return NULL;
138  ffio_init_context(s, buffer, buffer_size, write_flag, opaque,
139  read_packet, write_packet, seek);
140  return s;
141 }
142 
144 {
145  av_freep(ps);
146 }
147 
148 static void writeout(AVIOContext *s, const uint8_t *data, int len)
149 {
150  if (!s->error) {
151  int ret = 0;
152  if (s->write_data_type)
153  ret = s->write_data_type(s->opaque, (uint8_t *)data,
154  len,
155  s->current_type,
156  s->last_time);
157  else if (s->write_packet)
158  ret = s->write_packet(s->opaque, (uint8_t *)data, len);
159  if (ret < 0) {
160  s->error = ret;
161  } else {
162  if (s->pos + len > s->written)
163  s->written = s->pos + len;
164  }
165  }
169  }
171  s->writeout_count ++;
172  s->pos += len;
173 }
174 
175 static void flush_buffer(AVIOContext *s)
176 {
177  s->buf_ptr_max = FFMAX(s->buf_ptr, s->buf_ptr_max);
178  if (s->write_flag && s->buf_ptr_max > s->buffer) {
179  writeout(s, s->buffer, s->buf_ptr_max - s->buffer);
180  if (s->update_checksum) {
182  s->buf_ptr_max - s->checksum_ptr);
183  s->checksum_ptr = s->buffer;
184  }
185  }
186  s->buf_ptr = s->buf_ptr_max = s->buffer;
187  if (!s->write_flag)
188  s->buf_end = s->buffer;
189 }
190 
191 void avio_w8(AVIOContext *s, int b)
192 {
193  av_assert2(b>=-128 && b<=255);
194  *s->buf_ptr++ = b;
195  if (s->buf_ptr >= s->buf_end)
196  flush_buffer(s);
197 }
198 
199 void ffio_fill(AVIOContext *s, int b, int count)
200 {
201  while (count > 0) {
202  int len = FFMIN(s->buf_end - s->buf_ptr, count);
203  memset(s->buf_ptr, b, len);
204  s->buf_ptr += len;
205 
206  if (s->buf_ptr >= s->buf_end)
207  flush_buffer(s);
208 
209  count -= len;
210  }
211 }
212 
213 void avio_write(AVIOContext *s, const unsigned char *buf, int size)
214 {
215  if (s->direct && !s->update_checksum) {
216  avio_flush(s);
217  writeout(s, buf, size);
218  return;
219  }
220  while (size > 0) {
221  int len = FFMIN(s->buf_end - s->buf_ptr, size);
222  memcpy(s->buf_ptr, buf, len);
223  s->buf_ptr += len;
224 
225  if (s->buf_ptr >= s->buf_end)
226  flush_buffer(s);
227 
228  buf += len;
229  size -= len;
230  }
231 }
232 
234 {
235  int seekback = s->write_flag ? FFMIN(0, s->buf_ptr - s->buf_ptr_max) : 0;
236  flush_buffer(s);
237  if (seekback)
238  avio_seek(s, seekback, SEEK_CUR);
239 }
240 
241 int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
242 {
243  int64_t offset1;
244  int64_t pos;
245  int force = whence & AVSEEK_FORCE;
246  int buffer_size;
247  int short_seek;
248  whence &= ~AVSEEK_FORCE;
249 
250  if(!s)
251  return AVERROR(EINVAL);
252 
253  if ((whence & AVSEEK_SIZE))
254  return s->seek ? s->seek(s->opaque, offset, AVSEEK_SIZE) : AVERROR(ENOSYS);
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 void avio_wl32(AVIOContext *s, unsigned int val)
368 {
369  avio_w8(s, (uint8_t) val );
370  avio_w8(s, (uint8_t)(val >> 8 ));
371  avio_w8(s, (uint8_t)(val >> 16));
372  avio_w8(s, val >> 24 );
373 }
374 
375 void avio_wb32(AVIOContext *s, unsigned int val)
376 {
377  avio_w8(s, val >> 24 );
378  avio_w8(s, (uint8_t)(val >> 16));
379  avio_w8(s, (uint8_t)(val >> 8 ));
380  avio_w8(s, (uint8_t) val );
381 }
382 
383 int avio_put_str(AVIOContext *s, const char *str)
384 {
385  int len = 1;
386  if (str) {
387  len += strlen(str);
388  avio_write(s, (const unsigned char *) str, len);
389  } else
390  avio_w8(s, 0);
391  return len;
392 }
393 
394 static inline int put_str16(AVIOContext *s, const char *str, const int be)
395 {
396  const uint8_t *q = str;
397  int ret = 0;
398  int err = 0;
399 
400  while (*q) {
401  uint32_t ch;
402  uint16_t tmp;
403 
404  GET_UTF8(ch, *q++, goto invalid;)
405  PUT_UTF16(ch, tmp, be ? avio_wb16(s, tmp) : avio_wl16(s, tmp);
406  ret += 2;)
407  continue;
408 invalid:
409  av_log(s, AV_LOG_ERROR, "Invalid UTF8 sequence in avio_put_str16%s\n", be ? "be" : "le");
410  err = AVERROR(EINVAL);
411  if (!*(q-1))
412  break;
413  }
414  if (be)
415  avio_wb16(s, 0);
416  else
417  avio_wl16(s, 0);
418  if (err)
419  return err;
420  ret += 2;
421  return ret;
422 }
423 
424 #define PUT_STR16(type, big_endian) \
425 int avio_put_str16 ## type(AVIOContext *s, const char *str) \
426 { \
427 return put_str16(s, str, big_endian); \
428 }
429 
430 PUT_STR16(le, 0)
431 PUT_STR16(be, 1)
432 
433 #undef PUT_STR16
434 
435 int ff_get_v_length(uint64_t val)
436 {
437  int i = 1;
438 
439  while (val >>= 7)
440  i++;
441 
442  return i;
443 }
444 
445 void ff_put_v(AVIOContext *bc, uint64_t val)
446 {
447  int i = ff_get_v_length(val);
448 
449  while (--i > 0)
450  avio_w8(bc, 128 | (uint8_t)(val >> (7*i)));
451 
452  avio_w8(bc, val & 127);
453 }
454 
455 void avio_wl64(AVIOContext *s, uint64_t val)
456 {
457  avio_wl32(s, (uint32_t)(val & 0xffffffff));
458  avio_wl32(s, (uint32_t)(val >> 32));
459 }
460 
461 void avio_wb64(AVIOContext *s, uint64_t val)
462 {
463  avio_wb32(s, (uint32_t)(val >> 32));
464  avio_wb32(s, (uint32_t)(val & 0xffffffff));
465 }
466 
467 void avio_wl16(AVIOContext *s, unsigned int val)
468 {
469  avio_w8(s, (uint8_t)val);
470  avio_w8(s, (int)val >> 8);
471 }
472 
473 void avio_wb16(AVIOContext *s, unsigned int val)
474 {
475  avio_w8(s, (int)val >> 8);
476  avio_w8(s, (uint8_t)val);
477 }
478 
479 void avio_wl24(AVIOContext *s, unsigned int val)
480 {
481  avio_wl16(s, val & 0xffff);
482  avio_w8(s, (int)val >> 16);
483 }
484 
485 void avio_wb24(AVIOContext *s, unsigned int val)
486 {
487  avio_wb16(s, (int)val >> 8);
488  avio_w8(s, (uint8_t)val);
489 }
490 
492 {
493  if (type == AVIO_DATA_MARKER_FLUSH_POINT) {
494  if (s->buf_ptr - s->buffer >= s->min_packet_size)
495  avio_flush(s);
496  return;
497  }
498  if (!s->write_data_type)
499  return;
500  // If ignoring boundary points, just treat it as unknown
503  // Avoid unnecessary flushes if we are already in non-header/trailer
504  // data and setting the type to unknown
505  if (type == AVIO_DATA_MARKER_UNKNOWN &&
508  return;
509 
510  switch (type) {
513  // For header/trailer, ignore a new marker of the same type;
514  // consecutive header/trailer markers can be merged.
515  if (type == s->current_type)
516  return;
517  break;
518  }
519 
520  // If we've reached here, we have a new, noteworthy marker.
521  // Flush the previous data and mark the start of the new data.
522  avio_flush(s);
523  s->current_type = type;
524  s->last_time = time;
525 }
526 
527 static int read_packet_wrapper(AVIOContext *s, uint8_t *buf, int size)
528 {
529  int ret;
530 
531  if (!s->read_packet)
532  return AVERROR(EINVAL);
533  ret = s->read_packet(s->opaque, buf, size);
534 #if FF_API_OLD_AVIO_EOF_0
535  if (!ret && !s->max_packet_size) {
536  av_log(NULL, AV_LOG_WARNING, "Invalid return value 0 for stream protocol\n");
537  ret = AVERROR_EOF;
538  }
539 #else
540  av_assert2(ret || s->max_packet_size);
541 #endif
542  return ret;
543 }
544 
545 /* Input stream */
546 
547 static void fill_buffer(AVIOContext *s)
548 {
549  int max_buffer_size = s->max_packet_size ?
551  uint8_t *dst = s->buf_end - s->buffer + max_buffer_size < s->buffer_size ?
552  s->buf_end : s->buffer;
553  int len = s->buffer_size - (dst - s->buffer);
554 
555  /* can't fill the buffer without read_packet, just set EOF if appropriate */
556  if (!s->read_packet && s->buf_ptr >= s->buf_end)
557  s->eof_reached = 1;
558 
559  /* no need to do anything if EOF already reached */
560  if (s->eof_reached)
561  return;
562 
563  if (s->update_checksum && dst == s->buffer) {
564  if (s->buf_end > s->checksum_ptr)
566  s->buf_end - s->checksum_ptr);
567  s->checksum_ptr = s->buffer;
568  }
569 
570  /* make buffer smaller in case it ended up large after probing */
571  if (s->read_packet && s->orig_buffer_size && s->buffer_size > s->orig_buffer_size && len >= s->orig_buffer_size) {
572  if (dst == s->buffer && s->buf_ptr != dst) {
574  if (ret < 0)
575  av_log(s, AV_LOG_WARNING, "Failed to decrease buffer size\n");
576 
577  s->checksum_ptr = dst = s->buffer;
578  }
579  len = s->orig_buffer_size;
580  }
581 
582  len = read_packet_wrapper(s, dst, len);
583  if (len == AVERROR_EOF) {
584  /* do not modify buffer if EOF reached so that a seek back can
585  be done without rereading data */
586  s->eof_reached = 1;
587  } else if (len < 0) {
588  s->eof_reached = 1;
589  s->error= len;
590  } else {
591  s->pos += len;
592  s->buf_ptr = dst;
593  s->buf_end = dst + len;
594  s->bytes_read += len;
595  }
596 }
597 
598 unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf,
599  unsigned int len)
600 {
601  return av_crc(av_crc_get_table(AV_CRC_32_IEEE), checksum, buf, len);
602 }
603 
604 unsigned long ff_crcEDB88320_update(unsigned long checksum, const uint8_t *buf,
605  unsigned int len)
606 {
607  return av_crc(av_crc_get_table(AV_CRC_32_IEEE_LE), checksum, buf, len);
608 }
609 
610 unsigned long ff_crcA001_update(unsigned long checksum, const uint8_t *buf,
611  unsigned int len)
612 {
613  return av_crc(av_crc_get_table(AV_CRC_16_ANSI_LE), checksum, buf, len);
614 }
615 
617 {
619  s->buf_ptr - s->checksum_ptr);
620  s->update_checksum = NULL;
621  return s->checksum;
622 }
623 
625  unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len),
626  unsigned long checksum)
627 {
628  s->update_checksum = update_checksum;
629  if (s->update_checksum) {
630  s->checksum = checksum;
631  s->checksum_ptr = s->buf_ptr;
632  }
633 }
634 
635 /* XXX: put an inline version */
637 {
638  if (s->buf_ptr >= s->buf_end)
639  fill_buffer(s);
640  if (s->buf_ptr < s->buf_end)
641  return *s->buf_ptr++;
642  return 0;
643 }
644 
645 int avio_read(AVIOContext *s, unsigned char *buf, int size)
646 {
647  int len, size1;
648 
649  size1 = size;
650  while (size > 0) {
651  len = FFMIN(s->buf_end - s->buf_ptr, size);
652  if (len == 0 || s->write_flag) {
653  if((s->direct || size > s->buffer_size) && !s->update_checksum) {
654  // bypass the buffer and read data directly into buf
655  len = read_packet_wrapper(s, buf, size);
656  if (len == AVERROR_EOF) {
657  /* do not modify buffer if EOF reached so that a seek back can
658  be done without rereading data */
659  s->eof_reached = 1;
660  break;
661  } else if (len < 0) {
662  s->eof_reached = 1;
663  s->error= len;
664  break;
665  } else {
666  s->pos += len;
667  s->bytes_read += len;
668  size -= len;
669  buf += len;
670  // reset the buffer
671  s->buf_ptr = s->buffer;
672  s->buf_end = s->buffer/* + len*/;
673  }
674  } else {
675  fill_buffer(s);
676  len = s->buf_end - s->buf_ptr;
677  if (len == 0)
678  break;
679  }
680  } else {
681  memcpy(buf, s->buf_ptr, len);
682  buf += len;
683  s->buf_ptr += len;
684  size -= len;
685  }
686  }
687  if (size1 == size) {
688  if (s->error) return s->error;
689  if (avio_feof(s)) return AVERROR_EOF;
690  }
691  return size1 - size;
692 }
693 
694 int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
695 {
696  int ret = avio_read(s, buf, size);
697  if (ret != size)
698  return AVERROR_INVALIDDATA;
699  return ret;
700 }
701 
702 int ffio_read_indirect(AVIOContext *s, unsigned char *buf, int size, const unsigned char **data)
703 {
704  if (s->buf_end - s->buf_ptr >= size && !s->write_flag) {
705  *data = s->buf_ptr;
706  s->buf_ptr += size;
707  return size;
708  } else {
709  *data = buf;
710  return avio_read(s, buf, size);
711  }
712 }
713 
714 int avio_read_partial(AVIOContext *s, unsigned char *buf, int size)
715 {
716  int len;
717 
718  if (size < 0)
719  return -1;
720 
721  if (s->read_packet && s->write_flag) {
722  len = read_packet_wrapper(s, buf, size);
723  if (len > 0)
724  s->pos += len;
725  return len;
726  }
727 
728  len = s->buf_end - s->buf_ptr;
729  if (len == 0) {
730  /* Reset the buf_end pointer to the start of the buffer, to make sure
731  * the fill_buffer call tries to read as much data as fits into the
732  * full buffer, instead of just what space is left after buf_end.
733  * This avoids returning partial packets at the end of the buffer,
734  * for packet based inputs.
735  */
736  s->buf_end = s->buf_ptr = s->buffer;
737  fill_buffer(s);
738  len = s->buf_end - s->buf_ptr;
739  }
740  if (len > size)
741  len = size;
742  memcpy(buf, s->buf_ptr, len);
743  s->buf_ptr += len;
744  if (!len) {
745  if (s->error) return s->error;
746  if (avio_feof(s)) return AVERROR_EOF;
747  }
748  return len;
749 }
750 
751 unsigned int avio_rl16(AVIOContext *s)
752 {
753  unsigned int val;
754  val = avio_r8(s);
755  val |= avio_r8(s) << 8;
756  return val;
757 }
758 
759 unsigned int avio_rl24(AVIOContext *s)
760 {
761  unsigned int val;
762  val = avio_rl16(s);
763  val |= avio_r8(s) << 16;
764  return val;
765 }
766 
767 unsigned int avio_rl32(AVIOContext *s)
768 {
769  unsigned int val;
770  val = avio_rl16(s);
771  val |= avio_rl16(s) << 16;
772  return val;
773 }
774 
775 uint64_t avio_rl64(AVIOContext *s)
776 {
777  uint64_t val;
778  val = (uint64_t)avio_rl32(s);
779  val |= (uint64_t)avio_rl32(s) << 32;
780  return val;
781 }
782 
783 unsigned int avio_rb16(AVIOContext *s)
784 {
785  unsigned int val;
786  val = avio_r8(s) << 8;
787  val |= avio_r8(s);
788  return val;
789 }
790 
791 unsigned int avio_rb24(AVIOContext *s)
792 {
793  unsigned int val;
794  val = avio_rb16(s) << 8;
795  val |= avio_r8(s);
796  return val;
797 }
798 unsigned int avio_rb32(AVIOContext *s)
799 {
800  unsigned int val;
801  val = avio_rb16(s) << 16;
802  val |= avio_rb16(s);
803  return val;
804 }
805 
806 int ff_get_line(AVIOContext *s, char *buf, int maxlen)
807 {
808  int i = 0;
809  char c;
810 
811  do {
812  c = avio_r8(s);
813  if (c && i < maxlen-1)
814  buf[i++] = c;
815  } while (c != '\n' && c != '\r' && c);
816  if (c == '\r' && avio_r8(s) != '\n' && !avio_feof(s))
817  avio_skip(s, -1);
818 
819  buf[i] = 0;
820  return i;
821 }
822 
823 int ff_get_chomp_line(AVIOContext *s, char *buf, int maxlen)
824 {
825  int len = ff_get_line(s, buf, maxlen);
826  while (len > 0 && av_isspace(buf[len - 1]))
827  buf[--len] = '\0';
828  return len;
829 }
830 
831 int64_t ff_read_line_to_bprint(AVIOContext *s, AVBPrint *bp)
832 {
833  int len, end;
834  int64_t read = 0;
835  char tmp[1024];
836  char c;
837 
838  do {
839  len = 0;
840  do {
841  c = avio_r8(s);
842  end = (c == '\r' || c == '\n' || c == '\0');
843  if (!end)
844  tmp[len++] = c;
845  } while (!end && len < sizeof(tmp));
846  av_bprint_append_data(bp, tmp, len);
847  read += len;
848  } while (!end);
849 
850  if (c == '\r' && avio_r8(s) != '\n' && !avio_feof(s))
851  avio_skip(s, -1);
852 
853  if (!c && s->error)
854  return s->error;
855 
856  if (!c && !read && avio_feof(s))
857  return AVERROR_EOF;
858 
859  return read;
860 }
861 
863 {
864  int64_t ret;
865 
866  av_bprint_clear(bp);
867  ret = ff_read_line_to_bprint(s, bp);
868  if (ret < 0)
869  return ret;
870 
871  if (!av_bprint_is_complete(bp))
872  return AVERROR(ENOMEM);
873 
874  return bp->len;
875 }
876 
877 int avio_get_str(AVIOContext *s, int maxlen, char *buf, int buflen)
878 {
879  int i;
880 
881  if (buflen <= 0)
882  return AVERROR(EINVAL);
883  // reserve 1 byte for terminating 0
884  buflen = FFMIN(buflen - 1, maxlen);
885  for (i = 0; i < buflen; i++)
886  if (!(buf[i] = avio_r8(s)))
887  return i + 1;
888  buf[i] = 0;
889  for (; i < maxlen; i++)
890  if (!avio_r8(s))
891  return i + 1;
892  return maxlen;
893 }
894 
895 #define GET_STR16(type, read) \
896  int avio_get_str16 ##type(AVIOContext *pb, int maxlen, char *buf, int buflen)\
897 {\
898  char* q = buf;\
899  int ret = 0;\
900  if (buflen <= 0) \
901  return AVERROR(EINVAL); \
902  while (ret + 1 < maxlen) {\
903  uint8_t tmp;\
904  uint32_t ch;\
905  GET_UTF16(ch, (ret += 2) <= maxlen ? read(pb) : 0, break;)\
906  if (!ch)\
907  break;\
908  PUT_UTF8(ch, tmp, if (q - buf < buflen - 1) *q++ = tmp;)\
909  }\
910  *q = 0;\
911  return ret;\
912 }\
913 
914 GET_STR16(le, avio_rl16)
915 GET_STR16(be, avio_rb16)
916 
917 #undef GET_STR16
918 
919 uint64_t avio_rb64(AVIOContext *s)
920 {
921  uint64_t val;
922  val = (uint64_t)avio_rb32(s) << 32;
923  val |= (uint64_t)avio_rb32(s);
924  return val;
925 }
926 
928  uint64_t val = 0;
929  int tmp;
930 
931  do{
932  tmp = avio_r8(bc);
933  val= (val<<7) + (tmp&127);
934  }while(tmp&128);
935  return val;
936 }
937 
939 {
940  uint8_t *buffer = NULL;
941  int buffer_size, max_packet_size;
942 
943  max_packet_size = h->max_packet_size;
944  if (max_packet_size) {
945  buffer_size = max_packet_size; /* no need to bufferize more than one packet */
946  } else {
947  buffer_size = IO_BUFFER_SIZE;
948  }
949  buffer = av_malloc(buffer_size);
950  if (!buffer)
951  return AVERROR(ENOMEM);
952 
953  *s = avio_alloc_context(buffer, buffer_size, h->flags & AVIO_FLAG_WRITE, h,
954  (int (*)(void *, uint8_t *, int)) ffurl_read,
955  (int (*)(void *, uint8_t *, int)) ffurl_write,
956  (int64_t (*)(void *, int64_t, int))ffurl_seek);
957  if (!*s)
958  goto fail;
959 
960  (*s)->protocol_whitelist = av_strdup(h->protocol_whitelist);
961  if (!(*s)->protocol_whitelist && h->protocol_whitelist) {
962  avio_closep(s);
963  goto fail;
964  }
965  (*s)->protocol_blacklist = av_strdup(h->protocol_blacklist);
966  if (!(*s)->protocol_blacklist && h->protocol_blacklist) {
967  avio_closep(s);
968  goto fail;
969  }
970  (*s)->direct = h->flags & AVIO_FLAG_DIRECT;
971 
972  (*s)->seekable = h->is_streamed ? 0 : AVIO_SEEKABLE_NORMAL;
973  (*s)->max_packet_size = max_packet_size;
974  (*s)->min_packet_size = h->min_packet_size;
975  if(h->prot) {
976  (*s)->read_pause = (int (*)(void *, int))h->prot->url_read_pause;
977  (*s)->read_seek =
978  (int64_t (*)(void *, int, int64_t, int))h->prot->url_read_seek;
979 
980  if (h->prot->url_read_seek)
981  (*s)->seekable |= AVIO_SEEKABLE_TIME;
982  }
983  (*s)->short_seek_get = (int (*)(void *))ffurl_get_short_seek;
984  (*s)->av_class = &ff_avio_class;
985  return 0;
986 fail:
987  av_freep(&buffer);
988  return AVERROR(ENOMEM);
989 }
990 
992 {
993  if (!s)
994  return NULL;
995 
996  if (s->opaque && s->read_packet == (int (*)(void *, uint8_t *, int))ffurl_read)
997  return s->opaque;
998  else
999  return NULL;
1000 }
1001 
1002 int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
1003 {
1004  uint8_t *buffer;
1005  int max_buffer_size = s->max_packet_size ?
1007  int filled = s->buf_end - s->buffer;
1008  ptrdiff_t checksum_ptr_offset = s->checksum_ptr ? s->checksum_ptr - s->buffer : -1;
1009 
1010  buf_size += s->buf_ptr - s->buffer + max_buffer_size;
1011 
1012  if (buf_size < filled || s->seekable || !s->read_packet)
1013  return 0;
1014  av_assert0(!s->write_flag);
1015 
1016  buffer = av_malloc(buf_size);
1017  if (!buffer)
1018  return AVERROR(ENOMEM);
1019 
1020  memcpy(buffer, s->buffer, filled);
1021  av_free(s->buffer);
1022  s->buf_ptr = buffer + (s->buf_ptr - s->buffer);
1023  s->buf_end = buffer + (s->buf_end - s->buffer);
1024  s->buffer = buffer;
1025  s->buffer_size = buf_size;
1026  if (checksum_ptr_offset >= 0)
1027  s->checksum_ptr = s->buffer + checksum_ptr_offset;
1028  return 0;
1029 }
1030 
1031 int ffio_set_buf_size(AVIOContext *s, int buf_size)
1032 {
1033  uint8_t *buffer;
1034  buffer = av_malloc(buf_size);
1035  if (!buffer)
1036  return AVERROR(ENOMEM);
1037 
1038  av_free(s->buffer);
1039  s->buffer = buffer;
1040  s->orig_buffer_size =
1041  s->buffer_size = buf_size;
1042  s->buf_ptr = s->buf_ptr_max = buffer;
1044  return 0;
1045 }
1046 
1047 int ffio_realloc_buf(AVIOContext *s, int buf_size)
1048 {
1049  uint8_t *buffer;
1050  int data_size;
1051 
1052  if (!s->buffer_size)
1053  return ffio_set_buf_size(s, buf_size);
1054 
1055  if (buf_size <= s->buffer_size)
1056  return 0;
1057 
1058  buffer = av_malloc(buf_size);
1059  if (!buffer)
1060  return AVERROR(ENOMEM);
1061 
1062  data_size = s->write_flag ? (s->buf_ptr - s->buffer) : (s->buf_end - s->buf_ptr);
1063  if (data_size > 0)
1064  memcpy(buffer, s->write_flag ? s->buffer : s->buf_ptr, data_size);
1065  av_free(s->buffer);
1066  s->buffer = buffer;
1067  s->orig_buffer_size = buf_size;
1068  s->buffer_size = buf_size;
1069  s->buf_ptr = s->write_flag ? (s->buffer + data_size) : s->buffer;
1070  if (s->write_flag)
1071  s->buf_ptr_max = s->buffer + data_size;
1072 
1073  s->buf_end = s->write_flag ? (s->buffer + s->buffer_size) : (s->buf_ptr + data_size);
1074 
1075  return 0;
1076 }
1077 
1078 static int url_resetbuf(AVIOContext *s, int flags)
1079 {
1080  av_assert1(flags == AVIO_FLAG_WRITE || flags == AVIO_FLAG_READ);
1081 
1082  if (flags & AVIO_FLAG_WRITE) {
1083  s->buf_end = s->buffer + s->buffer_size;
1084  s->write_flag = 1;
1085  } else {
1086  s->buf_end = s->buffer;
1087  s->write_flag = 0;
1088  }
1089  return 0;
1090 }
1091 
1092 int ffio_rewind_with_probe_data(AVIOContext *s, unsigned char **bufp, int buf_size)
1093 {
1094  int64_t buffer_start;
1095  int buffer_size;
1096  int overlap, new_size, alloc_size;
1097  uint8_t *buf = *bufp;
1098 
1099  if (s->write_flag) {
1100  av_freep(bufp);
1101  return AVERROR(EINVAL);
1102  }
1103 
1104  buffer_size = s->buf_end - s->buffer;
1105 
1106  /* the buffers must touch or overlap */
1107  if ((buffer_start = s->pos - buffer_size) > buf_size) {
1108  av_freep(bufp);
1109  return AVERROR(EINVAL);
1110  }
1111 
1112  overlap = buf_size - buffer_start;
1113  new_size = buf_size + buffer_size - overlap;
1114 
1115  alloc_size = FFMAX(s->buffer_size, new_size);
1116  if (alloc_size > buf_size)
1117  if (!(buf = (*bufp) = av_realloc_f(buf, 1, alloc_size)))
1118  return AVERROR(ENOMEM);
1119 
1120  if (new_size > buf_size) {
1121  memcpy(buf + buf_size, s->buffer + overlap, buffer_size - overlap);
1122  buf_size = new_size;
1123  }
1124 
1125  av_free(s->buffer);
1126  s->buf_ptr = s->buffer = buf;
1127  s->buffer_size = alloc_size;
1128  s->pos = buf_size;
1129  s->buf_end = s->buf_ptr + buf_size;
1130  s->eof_reached = 0;
1131 
1132  return 0;
1133 }
1134 
1135 int avio_open(AVIOContext **s, const char *filename, int flags)
1136 {
1137  return avio_open2(s, filename, flags, NULL, NULL);
1138 }
1139 
1140 int ffio_open_whitelist(AVIOContext **s, const char *filename, int flags,
1142  const char *whitelist, const char *blacklist
1143  )
1144 {
1145  URLContext *h;
1146  int err;
1147 
1148  *s = NULL;
1149 
1150  err = ffurl_open_whitelist(&h, filename, flags, int_cb, options, whitelist, blacklist, NULL);
1151  if (err < 0)
1152  return err;
1153  err = ffio_fdopen(s, h);
1154  if (err < 0) {
1155  ffurl_close(h);
1156  return err;
1157  }
1158  return 0;
1159 }
1160 
1161 int avio_open2(AVIOContext **s, const char *filename, int flags,
1163 {
1164  return ffio_open_whitelist(s, filename, flags, int_cb, options, NULL, NULL);
1165 }
1166 
1168 {
1169  URLContext *h;
1170 
1171  if (!s)
1172  return 0;
1173 
1174  avio_flush(s);
1175  h = s->opaque;
1176  s->opaque = NULL;
1177 
1178  av_freep(&s->buffer);
1179  if (s->write_flag)
1180  av_log(s, AV_LOG_VERBOSE, "Statistics: %d seeks, %d writeouts\n", s->seek_count, s->writeout_count);
1181  else
1182  av_log(s, AV_LOG_VERBOSE, "Statistics: %"PRId64" bytes read, %d seeks\n", s->bytes_read, s->seek_count);
1183  av_opt_free(s);
1184 
1185  avio_context_free(&s);
1186 
1187  return ffurl_close(h);
1188 }
1189 
1191 {
1192  int ret = avio_close(*s);
1193  *s = NULL;
1194  return ret;
1195 }
1196 
1197 int avio_printf(AVIOContext *s, const char *fmt, ...)
1198 {
1199  va_list ap;
1200  AVBPrint bp;
1201 
1202  av_bprint_init(&bp, 0, INT_MAX);
1203  va_start(ap, fmt);
1204  av_vbprintf(&bp, fmt, ap);
1205  va_end(ap);
1206  if (!av_bprint_is_complete(&bp)) {
1207  av_bprint_finalize(&bp, NULL);
1208  s->error = AVERROR(ENOMEM);
1209  return AVERROR(ENOMEM);
1210  }
1211  avio_write(s, bp.str, bp.len);
1212  av_bprint_finalize(&bp, NULL);
1213  return bp.len;
1214 }
1215 
1216 void avio_print_string_array(AVIOContext *s, const char *strings[])
1217 {
1218  for(; *strings; strings++)
1219  avio_write(s, (const unsigned char *)*strings, strlen(*strings));
1220 }
1221 
1222 int avio_pause(AVIOContext *s, int pause)
1223 {
1224  if (!s->read_pause)
1225  return AVERROR(ENOSYS);
1226  return s->read_pause(s->opaque, pause);
1227 }
1228 
1229 int64_t avio_seek_time(AVIOContext *s, int stream_index,
1230  int64_t timestamp, int flags)
1231 {
1232  int64_t ret;
1233  if (!s->read_seek)
1234  return AVERROR(ENOSYS);
1235  ret = s->read_seek(s->opaque, stream_index, timestamp, flags);
1236  if (ret >= 0) {
1237  int64_t pos;
1238  s->buf_ptr = s->buf_end; // Flush buffer
1239  pos = s->seek(s->opaque, 0, SEEK_CUR);
1240  if (pos >= 0)
1241  s->pos = pos;
1242  else if (pos != AVERROR(ENOSYS))
1243  ret = pos;
1244  }
1245  return ret;
1246 }
1247 
1248 int avio_read_to_bprint(AVIOContext *h, AVBPrint *pb, size_t max_size)
1249 {
1250  int ret;
1251  char buf[1024];
1252  while (max_size) {
1253  ret = avio_read(h, buf, FFMIN(max_size, sizeof(buf)));
1254  if (ret == AVERROR_EOF)
1255  return 0;
1256  if (ret <= 0)
1257  return ret;
1258  av_bprint_append_data(pb, buf, ret);
1259  if (!av_bprint_is_complete(pb))
1260  return AVERROR(ENOMEM);
1261  max_size -= ret;
1262  }
1263  return 0;
1264 }
1265 
1267 {
1268  int ret;
1269  URLContext *sc = s->opaque;
1270  URLContext *cc = NULL;
1271  ret = ffurl_accept(sc, &cc);
1272  if (ret < 0)
1273  return ret;
1274  return ffio_fdopen(c, cc);
1275 }
1276 
1278 {
1279  URLContext *cc = c->opaque;
1280  return ffurl_handshake(cc);
1281 }
1282 
1283 /* output in a dynamic buffer */
1284 
1285 typedef struct DynBuffer {
1290 } DynBuffer;
1291 
1292 static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
1293 {
1294  DynBuffer *d = opaque;
1295  unsigned new_size, new_allocated_size;
1296 
1297  /* reallocate buffer if needed */
1298  new_size = d->pos + buf_size;
1299  new_allocated_size = d->allocated_size;
1300  if (new_size < d->pos || new_size > INT_MAX/2)
1301  return -1;
1302  while (new_size > new_allocated_size) {
1303  if (!new_allocated_size)
1304  new_allocated_size = new_size;
1305  else
1306  new_allocated_size += new_allocated_size / 2 + 1;
1307  }
1308 
1309  if (new_allocated_size > d->allocated_size) {
1310  int err;
1311  if ((err = av_reallocp(&d->buffer, new_allocated_size)) < 0) {
1312  d->allocated_size = 0;
1313  d->size = 0;
1314  return err;
1315  }
1316  d->allocated_size = new_allocated_size;
1317  }
1318  memcpy(d->buffer + d->pos, buf, buf_size);
1319  d->pos = new_size;
1320  if (d->pos > d->size)
1321  d->size = d->pos;
1322  return buf_size;
1323 }
1324 
1325 static int dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
1326 {
1327  unsigned char buf1[4];
1328  int ret;
1329 
1330  /* packetized write: output the header */
1331  AV_WB32(buf1, buf_size);
1332  ret = dyn_buf_write(opaque, buf1, 4);
1333  if (ret < 0)
1334  return ret;
1335 
1336  /* then the data */
1337  return dyn_buf_write(opaque, buf, buf_size);
1338 }
1339 
1340 static int64_t dyn_buf_seek(void *opaque, int64_t offset, int whence)
1341 {
1342  DynBuffer *d = opaque;
1343 
1344  if (whence == SEEK_CUR)
1345  offset += d->pos;
1346  else if (whence == SEEK_END)
1347  offset += d->size;
1348  if (offset < 0 || offset > 0x7fffffffLL)
1349  return -1;
1350  d->pos = offset;
1351  return 0;
1352 }
1353 
1354 static int url_open_dyn_buf_internal(AVIOContext **s, int max_packet_size)
1355 {
1356  DynBuffer *d;
1357  unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
1358 
1359  if (sizeof(DynBuffer) + io_buffer_size < io_buffer_size)
1360  return -1;
1361  d = av_mallocz(sizeof(DynBuffer) + io_buffer_size);
1362  if (!d)
1363  return AVERROR(ENOMEM);
1365  *s = avio_alloc_context(d->io_buffer, d->io_buffer_size, 1, d, NULL,
1366  max_packet_size ? dyn_packet_buf_write : dyn_buf_write,
1367  max_packet_size ? NULL : dyn_buf_seek);
1368  if(!*s) {
1369  av_free(d);
1370  return AVERROR(ENOMEM);
1371  }
1372  (*s)->max_packet_size = max_packet_size;
1373  return 0;
1374 }
1375 
1377 {
1378  return url_open_dyn_buf_internal(s, 0);
1379 }
1380 
1381 int ffio_open_dyn_packet_buf(AVIOContext **s, int max_packet_size)
1382 {
1383  if (max_packet_size <= 0)
1384  return -1;
1385  return url_open_dyn_buf_internal(s, max_packet_size);
1386 }
1387 
1389 {
1390  DynBuffer *d;
1391 
1392  if (!s || s->error) {
1393  *pbuffer = NULL;
1394  return 0;
1395  }
1396  d = s->opaque;
1397 
1398  if (!d->size) {
1399  *pbuffer = d->io_buffer;
1400  return FFMAX(s->buf_ptr, s->buf_ptr_max) - s->buffer;
1401  }
1402 
1403  avio_flush(s);
1404 
1405  *pbuffer = d->buffer;
1406 
1407  return d->size;
1408 }
1409 
1411 {
1412  DynBuffer *d = s->opaque;
1413  int max_packet_size = s->max_packet_size;
1414 
1416  s->write_packet, s->seek);
1417  s->max_packet_size = max_packet_size;
1418  d->pos = d->size = 0;
1419 }
1420 
1422 {
1423  DynBuffer *d;
1424  int size;
1425  static const char padbuf[AV_INPUT_BUFFER_PADDING_SIZE] = {0};
1426  int padding = 0;
1427 
1428  if (!s) {
1429  *pbuffer = NULL;
1430  return 0;
1431  }
1432 
1433  /* don't attempt to pad fixed-size packet buffers */
1434  if (!s->max_packet_size) {
1435  avio_write(s, padbuf, sizeof(padbuf));
1436  padding = AV_INPUT_BUFFER_PADDING_SIZE;
1437  }
1438 
1439  avio_flush(s);
1440 
1441  d = s->opaque;
1442  *pbuffer = d->buffer;
1443  size = d->size;
1444  av_free(d);
1445 
1446  avio_context_free(&s);
1447 
1448  return size - padding;
1449 }
1450 
1452 {
1453  DynBuffer *d;
1454 
1455  if (!*s)
1456  return;
1457 
1458  d = (*s)->opaque;
1459  av_free(d->buffer);
1460  av_free(d);
1461  avio_context_free(s);
1462 }
1463 
1464 static int null_buf_write(void *opaque, uint8_t *buf, int buf_size)
1465 {
1466  DynBuffer *d = opaque;
1467 
1468  d->pos += buf_size;
1469  if (d->pos > d->size)
1470  d->size = d->pos;
1471  return buf_size;
1472 }
1473 
1475 {
1476  int ret = url_open_dyn_buf_internal(s, 0);
1477  if (ret >= 0) {
1478  AVIOContext *pb = *s;
1480  }
1481  return ret;
1482 }
1483 
1485 {
1486  DynBuffer *d = s->opaque;
1487  int size;
1488 
1489  avio_flush(s);
1490 
1491  size = d->size;
1492  av_free(d);
1493 
1494  avio_context_free(&s);
1495 
1496  return size;
1497 }
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
Definition: ffmpeg.c:698
void avio_wl64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:455
#define NULL
Definition: coverity.c:32
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:126
static int64_t dyn_buf_seek(void *opaque, int64_t offset, int whence)
Definition: aviobuf.c:1340
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:919
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1376
#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:387
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:1289
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:473
AVOption.
Definition: opt.h:246
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:100
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:356
#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:58
int write_flag
true if open for writing
Definition: avio.h:240
void ffio_reset_dyn_buf(AVIOContext *s)
Reset a dynamic buffer.
Definition: aviobuf.c:1410
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:1388
#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:199
#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:235
unsigned int avio_rl24(AVIOContext *s)
Definition: aviobuf.c:759
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:1248
#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:56
GLint GLenum type
Definition: opengl_enc.c:104
void avio_wl24(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:479
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:191
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:1190
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:375
#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:51
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:1266
int avio_put_str(AVIOContext *s, const char *str)
Write a NULL-terminated string.
Definition: aviobuf.c:383
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:367
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:547
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:616
void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type)
Mark the written bytestream as a specific type.
Definition: aviobuf.c:491
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
Definition: aviobuf.c:233
int ffio_open_null_buf(AVIOContext **s)
Open a write-only fake memory stream.
Definition: aviobuf.c:1474
URLContext * ffio_geturlcontext(AVIOContext *s)
Return the URLContext associated with the AVIOContext.
Definition: aviobuf.c:991
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:76
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:1031
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:702
ptrdiff_t size
Definition: opengl_enc.c:100
void avio_wb24(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:485
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:467
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:1140
unsigned long ff_crcEDB88320_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:604
#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:1216
static void flush_buffer(AVIOContext *s)
Definition: aviobuf.c:175
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:1288
unsigned int avio_rb24(AVIOContext *s)
Definition: aviobuf.c:791
const AVIOInterruptCB int_cb
Definition: ffmpeg.c:489
static int dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:1325
const char * protocol_whitelist
Definition: url.h:49
static const AVOption ff_avio_options[]
Definition: aviobuf.c:59
int ffio_realloc_buf(AVIOContext *s, int buf_size)
Reallocate a given buffer for AVIOContext.
Definition: aviobuf.c:1047
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:862
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
unsigned int pos
Definition: spdifenc.c:410
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:45
#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:751
static int read_packet_wrapper(AVIOContext *s, uint8_t *buf, int size)
Definition: aviobuf.c:527
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:1222
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:767
This is any, unlabelled data.
Definition: avio.h:135
int size
Definition: aviobuf.c:1286
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:694
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:241
#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:64
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1421
unsigned char * checksum_ptr
Definition: avio.h:243
int avio_printf(AVIOContext *s, const char *fmt,...)
Definition: aviobuf.c:1197
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:1286
int ffurl_handshake(URLContext *c)
Perform one step of the protocol handshake to accept a new client.
Definition: avio.c:235
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:143
static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:1292
#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:806
#define GET_STR16(type, read)
Definition: aviobuf.c:895
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:227
int buffer_size
Maximum buffer size.
Definition: avio.h:227
void avio_wb64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:461
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:645
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:1381
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:424
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:1135
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:1092
static int url_resetbuf(AVIOContext *s, int flags)
Definition: aviobuf.c:1078
int(* url_read_pause)(URLContext *h, int pause)
Definition: url.h:82
uint64_t avio_rl64(AVIOContext *s)
Definition: aviobuf.c:775
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: aviobuf.c:1167
int(* write_packet)(void *opaque, uint8_t *buf, int buf_size)
Definition: avio.h:236
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:213
#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:783
int pos
Definition: aviobuf.c:1286
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:474
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:1451
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:1002
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:435
#define flags(name, subs,...)
Definition: cbs_av1.c:564
int ffurl_close(URLContext *h)
Definition: avio.c:466
const AVClass ffurl_context_class
Definition: avio.c:64
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:1277
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:1161
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:334
Main libavformat public API header.
int
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1607
const OptionDef options[]
Definition: ffmpeg_opt.c:3439
int avio_get_str(AVIOContext *s, int maxlen, char *buf, int buflen)
Read a string from pb into buf.
Definition: aviobuf.c:877
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:938
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:624
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:808
uint64_t ffio_read_varlen(AVIOContext *bc)
Definition: aviobuf.c:927
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:831
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:798
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:1287
static int put_str16(AVIOContext *s, const char *str, const int be)
Definition: aviobuf.c:394
int eof_reached
true if was unable to read due to error or eof
Definition: avio.h:239
void ff_put_v(AVIOContext *bc, uint64_t val)
Put val using a variable number of bytes.
Definition: aviobuf.c:445
int len
int ffio_close_null_buf(AVIOContext *s)
Close a null buffer.
Definition: aviobuf.c:1484
static int null_buf_write(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:1464
static void writeout(AVIOContext *s, const uint8_t *data, int len)
Definition: aviobuf.c:148
int avio_read_partial(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:714
static int url_open_dyn_buf_internal(AVIOContext **s, int max_packet_size)
Definition: aviobuf.c:1354
int max_packet_size
if non zero, the stream is packetized with this max packet size
Definition: url.h:44
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:329
#define av_freep(p)
unbuffered private I/O API
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:823
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:598
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:636
int min_packet_size
if non zero, the stream is packetized with this min packet size
Definition: url.h:51
static double val(void *priv, double ch)
Definition: aeval.c:76
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
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:1229
unsigned long ff_crcA001_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:610
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