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 
102  s->write_packet = write_packet;
103  s->read_packet = read_packet;
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;
112  s->short_seek_threshold = SHORT_SEEK_THRESHOLD;
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;
123  s->current_type = AVIO_DATA_MARKER_UNKNOWN;
124  s->last_time = AV_NOPTS_VALUE;
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  }
171  if (s->current_type == AVIO_DATA_MARKER_SYNC_POINT ||
172  s->current_type == AVIO_DATA_MARKER_BOUNDARY_POINT) {
173  s->current_type = AVIO_DATA_MARKER_UNKNOWN;
174  }
175  s->last_time = AV_NOPTS_VALUE;
176  s->writeout_count ++;
177  s->pos += len;
178 }
179 
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) {
186  s->checksum = s->update_checksum(s->checksum, s->checksum_ptr,
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  buffer_size = s->buf_end - s->buffer;
259  // pos is the absolute position that the beginning of s->buffer corresponds to in the file
260  pos = s->pos - (s->write_flag ? 0 : buffer_size);
261 
262  if (whence != SEEK_CUR && whence != SEEK_SET)
263  return AVERROR(EINVAL);
264 
265  if (whence == SEEK_CUR) {
266  offset1 = pos + (s->buf_ptr - s->buffer);
267  if (offset == 0)
268  return offset1;
269  if (offset > INT64_MAX - offset1)
270  return AVERROR(EINVAL);
271  offset += offset1;
272  }
273  if (offset < 0)
274  return AVERROR(EINVAL);
275 
276  if (s->short_seek_get) {
277  short_seek = s->short_seek_get(s->opaque);
278  /* fallback to default short seek */
279  if (short_seek <= 0)
280  short_seek = s->short_seek_threshold;
281  } else
282  short_seek = s->short_seek_threshold;
283 
284  offset1 = offset - pos; // "offset1" is the relative offset from the beginning of s->buffer
285  s->buf_ptr_max = FFMAX(s->buf_ptr_max, s->buf_ptr);
286  if ((!s->direct || !s->seek) &&
287  offset1 >= 0 && offset1 <= (s->write_flag ? s->buf_ptr_max - s->buffer : buffer_size)) {
288  /* can do the seek inside the buffer */
289  s->buf_ptr = s->buffer + offset1;
290  } else if ((!(s->seekable & AVIO_SEEKABLE_NORMAL) ||
291  offset1 <= buffer_size + short_seek) &&
292  !s->write_flag && offset1 >= 0 &&
293  (!s->direct || !s->seek) &&
294  (whence != SEEK_END || force)) {
295  while(s->pos < offset && !s->eof_reached)
296  fill_buffer(s);
297  if (s->eof_reached)
298  return AVERROR_EOF;
299  s->buf_ptr = s->buf_end - (s->pos - offset);
300  } else if(!s->write_flag && offset1 < 0 && -offset1 < buffer_size>>1 && s->seek && offset > 0) {
301  int64_t res;
302 
303  pos -= FFMIN(buffer_size>>1, pos);
304  if ((res = s->seek(s->opaque, pos, SEEK_SET)) < 0)
305  return res;
306  s->buf_end =
307  s->buf_ptr = s->buffer;
308  s->pos = pos;
309  s->eof_reached = 0;
310  fill_buffer(s);
311  return avio_seek(s, offset, SEEK_SET | force);
312  } else {
313  int64_t res;
314  if (s->write_flag) {
315  flush_buffer(s);
316  }
317  if (!s->seek)
318  return AVERROR(EPIPE);
319  if ((res = s->seek(s->opaque, offset, SEEK_SET)) < 0)
320  return res;
321  s->seek_count ++;
322  if (!s->write_flag)
323  s->buf_end = s->buffer;
324  s->buf_ptr = s->buf_ptr_max = s->buffer;
325  s->pos = offset;
326  }
327  s->eof_reached = 0;
328  return offset;
329 }
330 
331 int64_t avio_skip(AVIOContext *s, int64_t offset)
332 {
333  return avio_seek(s, offset, SEEK_CUR);
334 }
335 
337 {
338  int64_t size;
339 
340  if (!s)
341  return AVERROR(EINVAL);
342 
343  if (s->written)
344  return s->written;
345 
346  if (!s->seek)
347  return AVERROR(ENOSYS);
348  size = s->seek(s->opaque, 0, AVSEEK_SIZE);
349  if (size < 0) {
350  if ((size = s->seek(s->opaque, -1, SEEK_END)) < 0)
351  return size;
352  size++;
353  s->seek(s->opaque, s->pos, SEEK_SET);
354  }
355  return size;
356 }
357 
359 {
360  if(!s)
361  return 0;
362  if(s->eof_reached){
363  s->eof_reached=0;
364  fill_buffer(s);
365  }
366  return s->eof_reached;
367 }
368 
369 void avio_wl32(AVIOContext *s, unsigned int val)
370 {
371  avio_w8(s, (uint8_t) val );
372  avio_w8(s, (uint8_t)(val >> 8 ));
373  avio_w8(s, (uint8_t)(val >> 16));
374  avio_w8(s, val >> 24 );
375 }
376 
377 void avio_wb32(AVIOContext *s, unsigned int val)
378 {
379  avio_w8(s, val >> 24 );
380  avio_w8(s, (uint8_t)(val >> 16));
381  avio_w8(s, (uint8_t)(val >> 8 ));
382  avio_w8(s, (uint8_t) val );
383 }
384 
385 int avio_put_str(AVIOContext *s, const char *str)
386 {
387  int len = 1;
388  if (str) {
389  len += strlen(str);
390  avio_write(s, (const unsigned char *) str, len);
391  } else
392  avio_w8(s, 0);
393  return len;
394 }
395 
396 static inline int put_str16(AVIOContext *s, const char *str, const int be)
397 {
398  const uint8_t *q = str;
399  int ret = 0;
400  int err = 0;
401 
402  while (*q) {
403  uint32_t ch;
404  uint16_t tmp;
405 
406  GET_UTF8(ch, *q++, goto invalid;)
408  ret += 2;)
409  continue;
410 invalid:
411  av_log(s, AV_LOG_ERROR, "Invalid UTF8 sequence in avio_put_str16%s\n", be ? "be" : "le");
412  err = AVERROR(EINVAL);
413  if (!*(q-1))
414  break;
415  }
416  if (be)
417  avio_wb16(s, 0);
418  else
419  avio_wl16(s, 0);
420  if (err)
421  return err;
422  ret += 2;
423  return ret;
424 }
425 
426 #define PUT_STR16(type, big_endian) \
427 int avio_put_str16 ## type(AVIOContext *s, const char *str) \
428 { \
429 return put_str16(s, str, big_endian); \
430 }
431 
432 PUT_STR16(le, 0)
433 PUT_STR16(be, 1)
434 
435 #undef PUT_STR16
436 
437 int ff_get_v_length(uint64_t val)
438 {
439  int i = 1;
440 
441  while (val >>= 7)
442  i++;
443 
444  return i;
445 }
446 
447 void ff_put_v(AVIOContext *bc, uint64_t val)
448 {
449  int i = ff_get_v_length(val);
450 
451  while (--i > 0)
452  avio_w8(bc, 128 | (uint8_t)(val >> (7*i)));
453 
454  avio_w8(bc, val & 127);
455 }
456 
457 void avio_wl64(AVIOContext *s, uint64_t val)
458 {
459  avio_wl32(s, (uint32_t)(val & 0xffffffff));
460  avio_wl32(s, (uint32_t)(val >> 32));
461 }
462 
463 void avio_wb64(AVIOContext *s, uint64_t val)
464 {
465  avio_wb32(s, (uint32_t)(val >> 32));
466  avio_wb32(s, (uint32_t)(val & 0xffffffff));
467 }
468 
469 void avio_wl16(AVIOContext *s, unsigned int val)
470 {
471  avio_w8(s, (uint8_t)val);
472  avio_w8(s, (int)val >> 8);
473 }
474 
475 void avio_wb16(AVIOContext *s, unsigned int val)
476 {
477  avio_w8(s, (int)val >> 8);
478  avio_w8(s, (uint8_t)val);
479 }
480 
481 void avio_wl24(AVIOContext *s, unsigned int val)
482 {
483  avio_wl16(s, val & 0xffff);
484  avio_w8(s, (int)val >> 16);
485 }
486 
487 void avio_wb24(AVIOContext *s, unsigned int val)
488 {
489  avio_wb16(s, (int)val >> 8);
490  avio_w8(s, (uint8_t)val);
491 }
492 
494 {
496  if (s->buf_ptr - s->buffer >= s->min_packet_size)
497  avio_flush(s);
498  return;
499  }
500  if (!s->write_data_type)
501  return;
502  // If ignoring boundary points, just treat it as unknown
503  if (type == AVIO_DATA_MARKER_BOUNDARY_POINT && s->ignore_boundary_point)
505  // Avoid unnecessary flushes if we are already in non-header/trailer
506  // data and setting the type to unknown
508  (s->current_type != AVIO_DATA_MARKER_HEADER &&
509  s->current_type != AVIO_DATA_MARKER_TRAILER))
510  return;
511 
512  switch (type) {
515  // For header/trailer, ignore a new marker of the same type;
516  // consecutive header/trailer markers can be merged.
517  if (type == s->current_type)
518  return;
519  break;
520  }
521 
522  // If we've reached here, we have a new, noteworthy marker.
523  // Flush the previous data and mark the start of the new data.
524  avio_flush(s);
525  s->current_type = type;
526  s->last_time = time;
527 }
528 
530 {
531  int ret;
532 
533  if (!s->read_packet)
534  return AVERROR(EINVAL);
535  ret = s->read_packet(s->opaque, buf, size);
536 #if FF_API_OLD_AVIO_EOF_0
537  if (!ret && !s->max_packet_size) {
538  av_log(NULL, AV_LOG_WARNING, "Invalid return value 0 for stream protocol\n");
539  ret = AVERROR_EOF;
540  }
541 #else
542  av_assert2(ret || s->max_packet_size);
543 #endif
544  return ret;
545 }
546 
547 /* Input stream */
548 
549 static void fill_buffer(AVIOContext *s)
550 {
551  int max_buffer_size = s->max_packet_size ?
552  s->max_packet_size : IO_BUFFER_SIZE;
553  uint8_t *dst = s->buf_end - s->buffer + max_buffer_size < s->buffer_size ?
554  s->buf_end : s->buffer;
555  int len = s->buffer_size - (dst - s->buffer);
556 
557  /* can't fill the buffer without read_packet, just set EOF if appropriate */
558  if (!s->read_packet && s->buf_ptr >= s->buf_end)
559  s->eof_reached = 1;
560 
561  /* no need to do anything if EOF already reached */
562  if (s->eof_reached)
563  return;
564 
565  if (s->update_checksum && dst == s->buffer) {
566  if (s->buf_end > s->checksum_ptr)
567  s->checksum = s->update_checksum(s->checksum, s->checksum_ptr,
568  s->buf_end - s->checksum_ptr);
569  s->checksum_ptr = s->buffer;
570  }
571 
572  /* make buffer smaller in case it ended up large after probing */
573  if (s->read_packet && s->orig_buffer_size && s->buffer_size > s->orig_buffer_size && len >= s->orig_buffer_size) {
574  if (dst == s->buffer && s->buf_ptr != dst) {
575  int ret = ffio_set_buf_size(s, s->orig_buffer_size);
576  if (ret < 0)
577  av_log(s, AV_LOG_WARNING, "Failed to decrease buffer size\n");
578 
579  s->checksum_ptr = dst = s->buffer;
580  }
581  len = s->orig_buffer_size;
582  }
583 
584  len = read_packet_wrapper(s, dst, len);
585  if (len == AVERROR_EOF) {
586  /* do not modify buffer if EOF reached so that a seek back can
587  be done without rereading data */
588  s->eof_reached = 1;
589  } else if (len < 0) {
590  s->eof_reached = 1;
591  s->error= len;
592  } else {
593  s->pos += len;
594  s->buf_ptr = dst;
595  s->buf_end = dst + len;
596  s->bytes_read += len;
597  }
598 }
599 
600 unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf,
601  unsigned int len)
602 {
604 }
605 
606 unsigned long ff_crcEDB88320_update(unsigned long checksum, const uint8_t *buf,
607  unsigned int len)
608 {
610 }
611 
612 unsigned long ff_crcA001_update(unsigned long checksum, const uint8_t *buf,
613  unsigned int len)
614 {
616 }
617 
619 {
620  s->checksum = s->update_checksum(s->checksum, s->checksum_ptr,
621  s->buf_ptr - s->checksum_ptr);
622  s->update_checksum = NULL;
623  return s->checksum;
624 }
625 
627  unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len),
628  unsigned long checksum)
629 {
630  s->update_checksum = update_checksum;
631  if (s->update_checksum) {
632  s->checksum = checksum;
633  s->checksum_ptr = s->buf_ptr;
634  }
635 }
636 
637 /* XXX: put an inline version */
639 {
640  if (s->buf_ptr >= s->buf_end)
641  fill_buffer(s);
642  if (s->buf_ptr < s->buf_end)
643  return *s->buf_ptr++;
644  return 0;
645 }
646 
647 int avio_read(AVIOContext *s, unsigned char *buf, int size)
648 {
649  int len, size1;
650 
651  size1 = size;
652  while (size > 0) {
653  len = FFMIN(s->buf_end - s->buf_ptr, size);
654  if (len == 0 || s->write_flag) {
655  if((s->direct || size > s->buffer_size) && !s->update_checksum) {
656  // bypass the buffer and read data directly into buf
658  if (len == AVERROR_EOF) {
659  /* do not modify buffer if EOF reached so that a seek back can
660  be done without rereading data */
661  s->eof_reached = 1;
662  break;
663  } else if (len < 0) {
664  s->eof_reached = 1;
665  s->error= len;
666  break;
667  } else {
668  s->pos += len;
669  s->bytes_read += len;
670  size -= len;
671  buf += len;
672  // reset the buffer
673  s->buf_ptr = s->buffer;
674  s->buf_end = s->buffer/* + len*/;
675  }
676  } else {
677  fill_buffer(s);
678  len = s->buf_end - s->buf_ptr;
679  if (len == 0)
680  break;
681  }
682  } else {
683  memcpy(buf, s->buf_ptr, len);
684  buf += len;
685  s->buf_ptr += len;
686  size -= len;
687  }
688  }
689  if (size1 == size) {
690  if (s->error) return s->error;
691  if (avio_feof(s)) return AVERROR_EOF;
692  }
693  return size1 - size;
694 }
695 
696 int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
697 {
698  int ret = avio_read(s, buf, size);
699  if (ret != size)
700  return AVERROR_INVALIDDATA;
701  return ret;
702 }
703 
704 int ffio_read_indirect(AVIOContext *s, unsigned char *buf, int size, const unsigned char **data)
705 {
706  if (s->buf_end - s->buf_ptr >= size && !s->write_flag) {
707  *data = s->buf_ptr;
708  s->buf_ptr += size;
709  return size;
710  } else {
711  *data = buf;
712  return avio_read(s, buf, size);
713  }
714 }
715 
716 int avio_read_partial(AVIOContext *s, unsigned char *buf, int size)
717 {
718  int len;
719 
720  if (size < 0)
721  return -1;
722 
723  if (s->read_packet && s->write_flag) {
725  if (len > 0)
726  s->pos += len;
727  return len;
728  }
729 
730  len = s->buf_end - s->buf_ptr;
731  if (len == 0) {
732  /* Reset the buf_end pointer to the start of the buffer, to make sure
733  * the fill_buffer call tries to read as much data as fits into the
734  * full buffer, instead of just what space is left after buf_end.
735  * This avoids returning partial packets at the end of the buffer,
736  * for packet based inputs.
737  */
738  s->buf_end = s->buf_ptr = s->buffer;
739  fill_buffer(s);
740  len = s->buf_end - s->buf_ptr;
741  }
742  if (len > size)
743  len = size;
744  memcpy(buf, s->buf_ptr, len);
745  s->buf_ptr += len;
746  if (!len) {
747  if (s->error) return s->error;
748  if (avio_feof(s)) return AVERROR_EOF;
749  }
750  return len;
751 }
752 
753 unsigned int avio_rl16(AVIOContext *s)
754 {
755  unsigned int val;
756  val = avio_r8(s);
757  val |= avio_r8(s) << 8;
758  return val;
759 }
760 
761 unsigned int avio_rl24(AVIOContext *s)
762 {
763  unsigned int val;
764  val = avio_rl16(s);
765  val |= avio_r8(s) << 16;
766  return val;
767 }
768 
769 unsigned int avio_rl32(AVIOContext *s)
770 {
771  unsigned int val;
772  val = avio_rl16(s);
773  val |= avio_rl16(s) << 16;
774  return val;
775 }
776 
778 {
779  uint64_t val;
780  val = (uint64_t)avio_rl32(s);
781  val |= (uint64_t)avio_rl32(s) << 32;
782  return val;
783 }
784 
785 unsigned int avio_rb16(AVIOContext *s)
786 {
787  unsigned int val;
788  val = avio_r8(s) << 8;
789  val |= avio_r8(s);
790  return val;
791 }
792 
793 unsigned int avio_rb24(AVIOContext *s)
794 {
795  unsigned int val;
796  val = avio_rb16(s) << 8;
797  val |= avio_r8(s);
798  return val;
799 }
800 unsigned int avio_rb32(AVIOContext *s)
801 {
802  unsigned int val;
803  val = avio_rb16(s) << 16;
804  val |= avio_rb16(s);
805  return val;
806 }
807 
808 int ff_get_line(AVIOContext *s, char *buf, int maxlen)
809 {
810  int i = 0;
811  char c;
812 
813  do {
814  c = avio_r8(s);
815  if (c && i < maxlen-1)
816  buf[i++] = c;
817  } while (c != '\n' && c != '\r' && c);
818  if (c == '\r' && avio_r8(s) != '\n' && !avio_feof(s))
819  avio_skip(s, -1);
820 
821  buf[i] = 0;
822  return i;
823 }
824 
825 int ff_get_chomp_line(AVIOContext *s, char *buf, int maxlen)
826 {
827  int len = ff_get_line(s, buf, maxlen);
828  while (len > 0 && av_isspace(buf[len - 1]))
829  buf[--len] = '\0';
830  return len;
831 }
832 
833 int64_t ff_read_line_to_bprint(AVIOContext *s, AVBPrint *bp)
834 {
835  int len, end;
836  int64_t read = 0;
837  char tmp[1024];
838  char c;
839 
840  do {
841  len = 0;
842  do {
843  c = avio_r8(s);
844  end = (c == '\r' || c == '\n' || c == '\0');
845  if (!end)
846  tmp[len++] = c;
847  } while (!end && len < sizeof(tmp));
849  read += len;
850  } while (!end);
851 
852  if (c == '\r' && avio_r8(s) != '\n' && !avio_feof(s))
853  avio_skip(s, -1);
854 
855  if (!c && s->error)
856  return s->error;
857 
858  if (!c && !read && avio_feof(s))
859  return AVERROR_EOF;
860 
861  return read;
862 }
863 
865 {
866  int64_t ret;
867 
868  av_bprint_clear(bp);
870  if (ret < 0)
871  return ret;
872 
873  if (!av_bprint_is_complete(bp))
874  return AVERROR(ENOMEM);
875 
876  return bp->len;
877 }
878 
879 int avio_get_str(AVIOContext *s, int maxlen, char *buf, int buflen)
880 {
881  int i;
882 
883  if (buflen <= 0)
884  return AVERROR(EINVAL);
885  // reserve 1 byte for terminating 0
886  buflen = FFMIN(buflen - 1, maxlen);
887  for (i = 0; i < buflen; i++)
888  if (!(buf[i] = avio_r8(s)))
889  return i + 1;
890  buf[i] = 0;
891  for (; i < maxlen; i++)
892  if (!avio_r8(s))
893  return i + 1;
894  return maxlen;
895 }
896 
897 #define GET_STR16(type, read) \
898  int avio_get_str16 ##type(AVIOContext *pb, int maxlen, char *buf, int buflen)\
899 {\
900  char* q = buf;\
901  int ret = 0;\
902  if (buflen <= 0) \
903  return AVERROR(EINVAL); \
904  while (ret + 1 < maxlen) {\
905  uint8_t tmp;\
906  uint32_t ch;\
907  GET_UTF16(ch, (ret += 2) <= maxlen ? read(pb) : 0, break;)\
908  if (!ch)\
909  break;\
910  PUT_UTF8(ch, tmp, if (q - buf < buflen - 1) *q++ = tmp;)\
911  }\
912  *q = 0;\
913  return ret;\
914 }\
915 
916 GET_STR16(le, avio_rl16)
918 
919 #undef GET_STR16
920 
922 {
923  uint64_t val;
924  val = (uint64_t)avio_rb32(s) << 32;
925  val |= (uint64_t)avio_rb32(s);
926  return val;
927 }
928 
930  uint64_t val = 0;
931  int tmp;
932 
933  do{
934  tmp = avio_r8(bc);
935  val= (val<<7) + (tmp&127);
936  }while(tmp&128);
937  return val;
938 }
939 
940 static int io_read_packet(void *opaque, uint8_t *buf, int buf_size)
941 {
942  AVIOInternal *internal = opaque;
943  return ffurl_read(internal->h, buf, buf_size);
944 }
945 
946 static int io_write_packet(void *opaque, uint8_t *buf, int buf_size)
947 {
948  AVIOInternal *internal = opaque;
949  return ffurl_write(internal->h, buf, buf_size);
950 }
951 
952 static int64_t io_seek(void *opaque, int64_t offset, int whence)
953 {
954  AVIOInternal *internal = opaque;
955  return ffurl_seek(internal->h, offset, whence);
956 }
957 
958 static int io_short_seek(void *opaque)
959 {
960  AVIOInternal *internal = opaque;
961  return ffurl_get_short_seek(internal->h);
962 }
963 
964 static int io_read_pause(void *opaque, int pause)
965 {
966  AVIOInternal *internal = opaque;
967  if (!internal->h->prot->url_read_pause)
968  return AVERROR(ENOSYS);
969  return internal->h->prot->url_read_pause(internal->h, pause);
970 }
971 
972 static int64_t io_read_seek(void *opaque, int stream_index, int64_t timestamp, int flags)
973 {
974  AVIOInternal *internal = opaque;
975  if (!internal->h->prot->url_read_seek)
976  return AVERROR(ENOSYS);
977  return internal->h->prot->url_read_seek(internal->h, stream_index, timestamp, flags);
978 }
979 
981 {
982  AVIOInternal *internal = NULL;
983  uint8_t *buffer = NULL;
984  int buffer_size, max_packet_size;
985 
986  max_packet_size = h->max_packet_size;
987  if (max_packet_size) {
988  buffer_size = max_packet_size; /* no need to bufferize more than one packet */
989  } else {
990  buffer_size = IO_BUFFER_SIZE;
991  }
992  buffer = av_malloc(buffer_size);
993  if (!buffer)
994  return AVERROR(ENOMEM);
995 
996  internal = av_mallocz(sizeof(*internal));
997  if (!internal)
998  goto fail;
999 
1000  internal->h = h;
1001 
1002  *s = avio_alloc_context(buffer, buffer_size, h->flags & AVIO_FLAG_WRITE,
1003  internal, io_read_packet, io_write_packet, io_seek);
1004  if (!*s)
1005  goto fail;
1006 
1007  (*s)->protocol_whitelist = av_strdup(h->protocol_whitelist);
1008  if (!(*s)->protocol_whitelist && h->protocol_whitelist) {
1009  avio_closep(s);
1010  goto fail;
1011  }
1012  (*s)->protocol_blacklist = av_strdup(h->protocol_blacklist);
1013  if (!(*s)->protocol_blacklist && h->protocol_blacklist) {
1014  avio_closep(s);
1015  goto fail;
1016  }
1017  (*s)->direct = h->flags & AVIO_FLAG_DIRECT;
1018 
1019  (*s)->seekable = h->is_streamed ? 0 : AVIO_SEEKABLE_NORMAL;
1020  (*s)->max_packet_size = max_packet_size;
1021  (*s)->min_packet_size = h->min_packet_size;
1022  if(h->prot) {
1023  (*s)->read_pause = io_read_pause;
1024  (*s)->read_seek = io_read_seek;
1025 
1026  if (h->prot->url_read_seek)
1027  (*s)->seekable |= AVIO_SEEKABLE_TIME;
1028  }
1029  (*s)->short_seek_get = io_short_seek;
1030  (*s)->av_class = &ff_avio_class;
1031  return 0;
1032 fail:
1033  av_freep(&internal);
1034  av_freep(&buffer);
1035  return AVERROR(ENOMEM);
1036 }
1037 
1039 {
1040  AVIOInternal *internal;
1041  if (!s)
1042  return NULL;
1043 
1044  internal = s->opaque;
1045  if (internal && s->read_packet == io_read_packet)
1046  return internal->h;
1047  else
1048  return NULL;
1049 }
1050 
1051 int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
1052 {
1053  uint8_t *buffer;
1054  int max_buffer_size = s->max_packet_size ?
1055  s->max_packet_size : IO_BUFFER_SIZE;
1056  int filled = s->buf_end - s->buffer;
1057  ptrdiff_t checksum_ptr_offset = s->checksum_ptr ? s->checksum_ptr - s->buffer : -1;
1058 
1059  buf_size += s->buf_ptr - s->buffer + max_buffer_size;
1060 
1061  if (buf_size < filled || s->seekable || !s->read_packet)
1062  return 0;
1063  av_assert0(!s->write_flag);
1064 
1065  buffer = av_malloc(buf_size);
1066  if (!buffer)
1067  return AVERROR(ENOMEM);
1068 
1069  memcpy(buffer, s->buffer, filled);
1070  av_free(s->buffer);
1071  s->buf_ptr = buffer + (s->buf_ptr - s->buffer);
1072  s->buf_end = buffer + (s->buf_end - s->buffer);
1073  s->buffer = buffer;
1074  s->buffer_size = buf_size;
1075  if (checksum_ptr_offset >= 0)
1076  s->checksum_ptr = s->buffer + checksum_ptr_offset;
1077  return 0;
1078 }
1079 
1080 int ffio_set_buf_size(AVIOContext *s, int buf_size)
1081 {
1082  uint8_t *buffer;
1083  buffer = av_malloc(buf_size);
1084  if (!buffer)
1085  return AVERROR(ENOMEM);
1086 
1087  av_free(s->buffer);
1088  s->buffer = buffer;
1089  s->orig_buffer_size =
1090  s->buffer_size = buf_size;
1091  s->buf_ptr = s->buf_ptr_max = buffer;
1092  url_resetbuf(s, s->write_flag ? AVIO_FLAG_WRITE : AVIO_FLAG_READ);
1093  return 0;
1094 }
1095 
1096 static int url_resetbuf(AVIOContext *s, int flags)
1097 {
1099 
1100  if (flags & AVIO_FLAG_WRITE) {
1101  s->buf_end = s->buffer + s->buffer_size;
1102  s->write_flag = 1;
1103  } else {
1104  s->buf_end = s->buffer;
1105  s->write_flag = 0;
1106  }
1107  return 0;
1108 }
1109 
1110 int ffio_rewind_with_probe_data(AVIOContext *s, unsigned char **bufp, int buf_size)
1111 {
1112  int64_t buffer_start;
1113  int buffer_size;
1114  int overlap, new_size, alloc_size;
1115  uint8_t *buf = *bufp;
1116 
1117  if (s->write_flag) {
1118  av_freep(bufp);
1119  return AVERROR(EINVAL);
1120  }
1121 
1122  buffer_size = s->buf_end - s->buffer;
1123 
1124  /* the buffers must touch or overlap */
1125  if ((buffer_start = s->pos - buffer_size) > buf_size) {
1126  av_freep(bufp);
1127  return AVERROR(EINVAL);
1128  }
1129 
1130  overlap = buf_size - buffer_start;
1131  new_size = buf_size + buffer_size - overlap;
1132 
1133  alloc_size = FFMAX(s->buffer_size, new_size);
1134  if (alloc_size > buf_size)
1135  if (!(buf = (*bufp) = av_realloc_f(buf, 1, alloc_size)))
1136  return AVERROR(ENOMEM);
1137 
1138  if (new_size > buf_size) {
1139  memcpy(buf + buf_size, s->buffer + overlap, buffer_size - overlap);
1140  buf_size = new_size;
1141  }
1142 
1143  av_free(s->buffer);
1144  s->buf_ptr = s->buffer = buf;
1145  s->buffer_size = alloc_size;
1146  s->pos = buf_size;
1147  s->buf_end = s->buf_ptr + buf_size;
1148  s->eof_reached = 0;
1149 
1150  return 0;
1151 }
1152 
1153 int avio_open(AVIOContext **s, const char *filename, int flags)
1154 {
1155  return avio_open2(s, filename, flags, NULL, NULL);
1156 }
1157 
1158 int ffio_open_whitelist(AVIOContext **s, const char *filename, int flags,
1160  const char *whitelist, const char *blacklist
1161  )
1162 {
1163  URLContext *h;
1164  int err;
1165 
1166  *s = NULL;
1167 
1168  err = ffurl_open_whitelist(&h, filename, flags, int_cb, options, whitelist, blacklist, NULL);
1169  if (err < 0)
1170  return err;
1171  err = ffio_fdopen(s, h);
1172  if (err < 0) {
1173  ffurl_close(h);
1174  return err;
1175  }
1176  return 0;
1177 }
1178 
1179 int avio_open2(AVIOContext **s, const char *filename, int flags,
1181 {
1182  return ffio_open_whitelist(s, filename, flags, int_cb, options, NULL, NULL);
1183 }
1184 
1186 {
1187  AVIOInternal *internal;
1188  URLContext *h;
1189 
1190  if (!s)
1191  return 0;
1192 
1193  avio_flush(s);
1194  internal = s->opaque;
1195  h = internal->h;
1196 
1197  av_freep(&s->opaque);
1198  av_freep(&s->buffer);
1199  if (s->write_flag)
1200  av_log(s, AV_LOG_VERBOSE, "Statistics: %d seeks, %d writeouts\n", s->seek_count, s->writeout_count);
1201  else
1202  av_log(s, AV_LOG_VERBOSE, "Statistics: %"PRId64" bytes read, %d seeks\n", s->bytes_read, s->seek_count);
1203  av_opt_free(s);
1204 
1205  avio_context_free(&s);
1206 
1207  return ffurl_close(h);
1208 }
1209 
1211 {
1212  int ret = avio_close(*s);
1213  *s = NULL;
1214  return ret;
1215 }
1216 
1217 int avio_printf(AVIOContext *s, const char *fmt, ...)
1218 {
1219  va_list ap;
1220  char buf[4096]; /* update doc entry in avio.h if changed */
1221  int ret;
1222 
1223  va_start(ap, fmt);
1224  ret = vsnprintf(buf, sizeof(buf), fmt, ap);
1225  va_end(ap);
1226  avio_write(s, buf, strlen(buf));
1227  return ret;
1228 }
1229 
1230 int avio_pause(AVIOContext *s, int pause)
1231 {
1232  if (!s->read_pause)
1233  return AVERROR(ENOSYS);
1234  return s->read_pause(s->opaque, pause);
1235 }
1236 
1237 int64_t avio_seek_time(AVIOContext *s, int stream_index,
1238  int64_t timestamp, int flags)
1239 {
1240  int64_t ret;
1241  if (!s->read_seek)
1242  return AVERROR(ENOSYS);
1243  ret = s->read_seek(s->opaque, stream_index, timestamp, flags);
1244  if (ret >= 0) {
1245  int64_t pos;
1246  s->buf_ptr = s->buf_end; // Flush buffer
1247  pos = s->seek(s->opaque, 0, SEEK_CUR);
1248  if (pos >= 0)
1249  s->pos = pos;
1250  else if (pos != AVERROR(ENOSYS))
1251  ret = pos;
1252  }
1253  return ret;
1254 }
1255 
1256 int avio_read_to_bprint(AVIOContext *h, AVBPrint *pb, size_t max_size)
1257 {
1258  int ret;
1259  char buf[1024];
1260  while (max_size) {
1261  ret = avio_read(h, buf, FFMIN(max_size, sizeof(buf)));
1262  if (ret == AVERROR_EOF)
1263  return 0;
1264  if (ret <= 0)
1265  return ret;
1267  if (!av_bprint_is_complete(pb))
1268  return AVERROR(ENOMEM);
1269  max_size -= ret;
1270  }
1271  return 0;
1272 }
1273 
1275 {
1276  int ret;
1277  AVIOInternal *internal = s->opaque;
1278  URLContext *sc = internal->h;
1279  URLContext *cc = NULL;
1280  ret = ffurl_accept(sc, &cc);
1281  if (ret < 0)
1282  return ret;
1283  return ffio_fdopen(c, cc);
1284 }
1285 
1287 {
1288  AVIOInternal *internal = c->opaque;
1289  URLContext *cc = internal->h;
1290  return ffurl_handshake(cc);
1291 }
1292 
1293 /* output in a dynamic buffer */
1294 
1295 typedef struct DynBuffer {
1300 } DynBuffer;
1301 
1302 static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
1303 {
1304  DynBuffer *d = opaque;
1305  unsigned new_size, new_allocated_size;
1306 
1307  /* reallocate buffer if needed */
1308  new_size = (unsigned)d->pos + buf_size;
1309  new_allocated_size = d->allocated_size;
1310  if (new_size < d->pos || new_size > INT_MAX/2)
1311  return -1;
1312  while (new_size > new_allocated_size) {
1313  if (!new_allocated_size)
1314  new_allocated_size = new_size;
1315  else
1316  new_allocated_size += new_allocated_size / 2 + 1;
1317  }
1318 
1319  if (new_allocated_size > d->allocated_size) {
1320  int err;
1321  if ((err = av_reallocp(&d->buffer, new_allocated_size)) < 0) {
1322  d->allocated_size = 0;
1323  d->size = 0;
1324  return err;
1325  }
1326  d->allocated_size = new_allocated_size;
1327  }
1328  memcpy(d->buffer + d->pos, buf, buf_size);
1329  d->pos = new_size;
1330  if (d->pos > d->size)
1331  d->size = d->pos;
1332  return buf_size;
1333 }
1334 
1335 static int dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
1336 {
1337  unsigned char buf1[4];
1338  int ret;
1339 
1340  /* packetized write: output the header */
1341  AV_WB32(buf1, buf_size);
1342  ret = dyn_buf_write(opaque, buf1, 4);
1343  if (ret < 0)
1344  return ret;
1345 
1346  /* then the data */
1347  return dyn_buf_write(opaque, buf, buf_size);
1348 }
1349 
1350 static int64_t dyn_buf_seek(void *opaque, int64_t offset, int whence)
1351 {
1352  DynBuffer *d = opaque;
1353 
1354  if (whence == SEEK_CUR)
1355  offset += d->pos;
1356  else if (whence == SEEK_END)
1357  offset += d->size;
1358  if (offset < 0 || offset > 0x7fffffffLL)
1359  return -1;
1360  d->pos = offset;
1361  return 0;
1362 }
1363 
1364 static int url_open_dyn_buf_internal(AVIOContext **s, int max_packet_size)
1365 {
1366  DynBuffer *d;
1367  unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
1368 
1369  if (sizeof(DynBuffer) + io_buffer_size < io_buffer_size)
1370  return -1;
1371  d = av_mallocz(sizeof(DynBuffer) + io_buffer_size);
1372  if (!d)
1373  return AVERROR(ENOMEM);
1374  d->io_buffer_size = io_buffer_size;
1376  max_packet_size ? dyn_packet_buf_write : dyn_buf_write,
1377  max_packet_size ? NULL : dyn_buf_seek);
1378  if(!*s) {
1379  av_free(d);
1380  return AVERROR(ENOMEM);
1381  }
1382  (*s)->max_packet_size = max_packet_size;
1383  return 0;
1384 }
1385 
1387 {
1388  return url_open_dyn_buf_internal(s, 0);
1389 }
1390 
1391 int ffio_open_dyn_packet_buf(AVIOContext **s, int max_packet_size)
1392 {
1393  if (max_packet_size <= 0)
1394  return -1;
1395  return url_open_dyn_buf_internal(s, max_packet_size);
1396 }
1397 
1399 {
1400  DynBuffer *d;
1401 
1402  if (!s) {
1403  *pbuffer = NULL;
1404  return 0;
1405  }
1406 
1407  avio_flush(s);
1408 
1409  d = s->opaque;
1410  *pbuffer = d->buffer;
1411 
1412  return d->size;
1413 }
1414 
1416 {
1417  DynBuffer *d;
1418  int size;
1419  static const char padbuf[AV_INPUT_BUFFER_PADDING_SIZE] = {0};
1420  int padding = 0;
1421 
1422  if (!s) {
1423  *pbuffer = NULL;
1424  return 0;
1425  }
1426 
1427  /* don't attempt to pad fixed-size packet buffers */
1428  if (!s->max_packet_size) {
1429  avio_write(s, padbuf, sizeof(padbuf));
1430  padding = AV_INPUT_BUFFER_PADDING_SIZE;
1431  }
1432 
1433  avio_flush(s);
1434 
1435  d = s->opaque;
1436  *pbuffer = d->buffer;
1437  size = d->size;
1438  av_free(d);
1439 
1440  avio_context_free(&s);
1441 
1442  return size - padding;
1443 }
1444 
1446 {
1447  uint8_t *tmp;
1448  if (!*s)
1449  return;
1450  avio_close_dyn_buf(*s, &tmp);
1451  av_free(tmp);
1452  *s = NULL;
1453 }
1454 
1455 static int null_buf_write(void *opaque, uint8_t *buf, int buf_size)
1456 {
1457  DynBuffer *d = opaque;
1458 
1459  d->pos += buf_size;
1460  if (d->pos > d->size)
1461  d->size = d->pos;
1462  return buf_size;
1463 }
1464 
1466 {
1467  int ret = url_open_dyn_buf_internal(s, 0);
1468  if (ret >= 0) {
1469  AVIOContext *pb = *s;
1471  }
1472  return ret;
1473 }
1474 
1476 {
1477  DynBuffer *d = s->opaque;
1478  int size;
1479 
1480  avio_flush(s);
1481 
1482  size = d->size;
1483  av_free(d);
1484 
1485  avio_context_free(&s);
1486 
1487  return size;
1488 }
ff_get_chomp_line
int ff_get_chomp_line(AVIOContext *s, char *buf, int maxlen)
Same as ff_get_line but strip the white-space characters in the text tail.
Definition: aviobuf.c:825
be
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it be(in the first position) for now. Options ------- Then comes the options array. This is what will define the user accessible options. For example
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
put_str16
static int put_str16(AVIOContext *s, const char *str, const int be)
Definition: aviobuf.c:396
ff_put_v
void ff_put_v(AVIOContext *bc, uint64_t val)
Put val using a variable number of bytes.
Definition: aviobuf.c:447
avio_feof
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition: aviobuf.c:358
AVIO_DATA_MARKER_BOUNDARY_POINT
@ AVIO_DATA_MARKER_BOUNDARY_POINT
A point in the output bytestream where a demuxer can start parsing (for non self synchronizing bytest...
Definition: avio.h:128
null_buf_write
static int null_buf_write(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:1455
ffurl_context_class
const AVClass ffurl_context_class
Definition: avio.c:63
D
#define D
Definition: aviobuf.c:63
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
avio_get_dyn_buf
int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1398
url_open_dyn_buf_internal
static int url_open_dyn_buf_internal(AVIOContext **s, int max_packet_size)
Definition: aviobuf.c:1364
ffurl_seek
int64_t ffurl_seek(URLContext *h, int64_t pos, int whence)
Change the position that will be used by the next read/write operation on the resource accessed by h.
Definition: avio.c:437
avio_rl24
unsigned int avio_rl24(AVIOContext *s)
Definition: aviobuf.c:761
dyn_buf_seek
static int64_t dyn_buf_seek(void *opaque, int64_t offset, int whence)
Definition: aviobuf.c:1350
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:55
ch
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(INT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){ in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);} ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map) { switch(av_get_bytes_per_sample(in_fmt)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } if(HAVE_X86ASM &&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
avio_wl24
void avio_wl24(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:481
io_read_pause
static int io_read_pause(void *opaque, int pause)
Definition: aviobuf.c:964
count
void INT64 INT64 count
Definition: avisynth_c.h:767
av_isspace
static av_const int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
Definition: avstring.h:222
io_read_seek
static int64_t io_read_seek(void *opaque, int stream_index, int64_t timestamp, int flags)
Definition: aviobuf.c:972
end
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:26
ffio_get_checksum
unsigned long ffio_get_checksum(AVIOContext *s)
Definition: aviobuf.c:618
DynBuffer::buffer
uint8_t * buffer
Definition: aviobuf.c:1297
ffio_open_null_buf
int ffio_open_null_buf(AVIOContext **s)
Open a write-only fake memory stream.
Definition: aviobuf.c:1465
ffio_geturlcontext
URLContext * ffio_geturlcontext(AVIOContext *s)
Return the URLContext associated with the AVIOContext.
Definition: aviobuf.c:1038
AVOption
AVOption.
Definition: opt.h:246
b
#define b
Definition: input.c:41
AVSEEK_SIZE
#define AVSEEK_SIZE
ORing this as the "whence" parameter to a seek function causes it to return the filesize without seek...
Definition: avio.h:531
IO_BUFFER_SIZE
#define IO_BUFFER_SIZE
Definition: aviobuf.c:36
data
const char data[16]
Definition: mxf.c:91
avio_seek_time
int64_t avio_seek_time(AVIOContext *s, int stream_index, int64_t timestamp, int flags)
Seek to a given timestamp relative to some component stream.
Definition: aviobuf.c:1237
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
avio_accept
int avio_accept(AVIOContext *s, AVIOContext **c)
Accept and allocate a client context on a server context.
Definition: aviobuf.c:1274
ffurl_close
int ffurl_close(URLContext *h)
Definition: avio.c:470
DynBuffer::io_buffer
uint8_t io_buffer[1]
Definition: aviobuf.c:1299
avio_put_str
int avio_put_str(AVIOContext *s, const char *str)
Write a NULL-terminated string.
Definition: aviobuf.c:385
ffio_fill
void ffio_fill(AVIOContext *s, int b, int count)
Definition: aviobuf.c:204
AVDictionary
Definition: dict.c:30
avio_wl32
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:369
av_bprint_append_data
void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size)
Append data to a print buffer.
Definition: bprint.c:158
avio_read_to_bprint
int avio_read_to_bprint(AVIOContext *h, AVBPrint *pb, size_t max_size)
Read contents of h into print buffer, up to max_size bytes, or up to EOF.
Definition: aviobuf.c:1256
ff_crcEDB88320_update
unsigned long ff_crcEDB88320_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:606
AVIODataMarkerType
AVIODataMarkerType
Different data types that can be returned via the AVIO write_data_type callback.
Definition: avio.h:111
avio_w8
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:196
fill_buffer
static void fill_buffer(AVIOContext *s)
Definition: aviobuf.c:549
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
AVIOInterruptCB
Callback for checking whether to abort blocking functions.
Definition: avio.h:58
crc.h
fmt
const char * fmt
Definition: avisynth_c.h:861
ff_avio_child_class_next
static const AVClass * ff_avio_child_class_next(const AVClass *prev)
Definition: aviobuf.c:56
fail
#define fail()
Definition: checkasm.h:120
AV_CRC_16_ANSI_LE
@ AV_CRC_16_ANSI_LE
Definition: crc.h:55
avio_wb24
void avio_wb24(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:487
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
avio_wl16
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:469
ffio_open_whitelist
int ffio_open_whitelist(AVIOContext **s, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char *blacklist)
Definition: aviobuf.c:1158
OFFSET
#define OFFSET(x)
Definition: aviobuf.c:61
ff_avio_child_next
static void * ff_avio_child_next(void *obj, void *prev)
Definition: aviobuf.c:49
GET_UTF8
#define GET_UTF8(val, GET_BYTE, ERROR)
Convert a UTF-8 character (up to 4 bytes) to its 32-bit UCS-4 encoded form.
Definition: common.h:385
flush_buffer
static void flush_buffer(AVIOContext *s)
Definition: aviobuf.c:180
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
buf
void * buf
Definition: avisynth_c.h:766
avio_write_marker
void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type)
Mark the written bytestream as a specific type.
Definition: aviobuf.c:493
avio_flush
void avio_flush(AVIOContext *s)
Force flushing of buffered data.
Definition: aviobuf.c:238
ffurl_open_whitelist
int ffurl_open_whitelist(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char *blacklist, URLContext *parent)
Create an URLContext for accessing to the resource indicated by url, and open it.
Definition: avio.c:307
avio_wb32
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:377
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:257
ffio_read_size
int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:696
ff_avio_class
const AVClass ff_avio_class
Definition: aviobuf.c:69
avio_close_dyn_buf
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:1415
io_read_packet
static int io_read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:940
DynBuffer::pos
int pos
Definition: aviobuf.c:1296
ffio_set_buf_size
int ffio_set_buf_size(AVIOContext *s, int buf_size)
Definition: aviobuf.c:1080
ffio_read_indirect
int ffio_read_indirect(AVIOContext *s, unsigned char *buf, int size, const unsigned char **data)
Read size bytes from AVIOContext, returning a pointer.
Definition: aviobuf.c:704
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AVIO_FLAG_WRITE
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:655
avio_context_free
void avio_context_free(AVIOContext **ps)
Free the supplied IO context and everything associated with it.
Definition: aviobuf.c:148
if
if(ret)
Definition: filter_design.txt:179
ffurl_accept
int ffurl_accept(URLContext *s, URLContext **c)
Accept an URLContext c on an URLContext s.
Definition: avio.c:226
AVIOInternal::h
URLContext * h
Definition: aviobuf.c:46
av_realloc_f
#define av_realloc_f(p, o, n)
Definition: tableprint_vlc.h:33
ffio_init_context
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
internal.h
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
avio_read
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:647
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
ff_avio_options
static const AVOption ff_avio_options[]
Definition: aviobuf.c:64
NULL
#define NULL
Definition: coverity.c:32
DynBuffer
Definition: aviobuf.c:1295
AVIO_DATA_MARKER_TRAILER
@ AVIO_DATA_MARKER_TRAILER
Trailer data, which doesn't contain actual content, but only for finalizing the output file.
Definition: avio.h:140
PUT_UTF16
#define PUT_UTF16(val, tmp, PUT_16BIT)
Definition: common.h:472
avio_printf
int avio_printf(AVIOContext *s, const char *fmt,...)
Definition: aviobuf.c:1217
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
av_opt_free
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1558
SHORT_SEEK_THRESHOLD
#define SHORT_SEEK_THRESHOLD
Do seeks within this distance ahead of the current buffer by skipping data instead of calling the pro...
Definition: aviobuf.c:43
read_packet_wrapper
static int read_packet_wrapper(AVIOContext *s, uint8_t *buf, int size)
Definition: aviobuf.c:529
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
avio_pause
int avio_pause(AVIOContext *s, int pause)
Pause and resume playing - only meaningful if using a network streaming protocol (e....
Definition: aviobuf.c:1230
av_bprint_is_complete
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
Definition: bprint.h:185
AV_WB32
#define AV_WB32(p, v)
Definition: intreadwrite.h:419
avio_rb24
unsigned int avio_rb24(AVIOContext *s)
Definition: aviobuf.c:793
dyn_packet_buf_write
static int dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:1335
options
const OptionDef options[]
avio_rb16
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:785
AVIOContext
Bytestream IO Context.
Definition: avio.h:161
ff_read_line_to_bprint_overwrite
int64_t ff_read_line_to_bprint_overwrite(AVIOContext *s, AVBPrint *bp)
Read a whole line of text from AVIOContext to an AVBPrint buffer overwriting its contents.
Definition: aviobuf.c:864
FFMAX
#define FFMAX(a, b)
Definition: common.h:94
ffio_free_dyn_buf
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
Definition: aviobuf.c:1445
size
int size
Definition: twinvq_data.h:11134
avio.h
ffio_ensure_seekback
int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
Ensures that the requested seekback buffer size will be available.
Definition: aviobuf.c:1051
av_reallocp
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
Definition: mem.c:163
avio_open
int avio_open(AVIOContext **s, const char *filename, int flags)
Create and initialize a AVIOContext for accessing the resource indicated by url.
Definition: aviobuf.c:1153
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
AVIO_SEEKABLE_TIME
#define AVIO_SEEKABLE_TIME
Seeking by timestamp with avio_seek_time() is possible.
Definition: avio.h:45
dyn_buf_write
static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:1302
avio_rl16
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:753
avio_rl64
uint64_t avio_rl64(AVIOContext *s)
Definition: aviobuf.c:777
ffio_rewind_with_probe_data
int ffio_rewind_with_probe_data(AVIOContext *s, unsigned char **bufp, int buf_size)
Rewind the AVIOContext using the specified buffer containing the first buf_size bytes of the file.
Definition: aviobuf.c:1110
val
const char const char void * val
Definition: avisynth_c.h:863
AVIO_DATA_MARKER_SYNC_POINT
@ AVIO_DATA_MARKER_SYNC_POINT
A point in the output bytestream where a decoder can start decoding (i.e.
Definition: avio.h:122
avio_close
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: aviobuf.c:1185
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
AVIOContext::write_packet
int(* write_packet)(void *opaque, uint8_t *buf, int buf_size)
Definition: avio.h:236
av_crc_get_table
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
Definition: crc.c:374
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
avio_open2
int avio_open2(AVIOContext **s, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create and initialize a AVIOContext for accessing the resource indicated by url.
Definition: aviobuf.c:1179
avio_rl32
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:769
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:218
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:246
ffurl_get_short_seek
int ffurl_get_short_seek(URLContext *h)
Return the current short seek threshold value for this URL.
Definition: avio.c:653
write_packet
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
Definition: ffmpeg.c:690
ffio_init_checksum
void ffio_init_checksum(AVIOContext *s, unsigned long(*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum)
Definition: aviobuf.c:626
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:64
ffio_open_dyn_packet_buf
int ffio_open_dyn_packet_buf(AVIOContext **s, int max_packet_size)
Open a write only packetized memory stream with a maximum packet size of 'max_packet_size'.
Definition: aviobuf.c:1391
bprint.h
URLContext
Definition: url.h:38
log.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
avio_internal.h
PUT_STR16
#define PUT_STR16(type, big_endian)
Definition: aviobuf.c:426
ffio_read_varlen
uint64_t ffio_read_varlen(AVIOContext *bc)
Definition: aviobuf.c:929
ff_read_line_to_bprint
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:833
vsnprintf
#define vsnprintf
Definition: snprintf.h:36
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
url.h
uint8_t
uint8_t
Definition: audio_convert.c:194
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:236
ff_get_line
int ff_get_line(AVIOContext *s, char *buf, int maxlen)
Read a whole line of text from AVIOContext.
Definition: aviobuf.c:808
GET_STR16
#define GET_STR16(type, read)
Definition: aviobuf.c:897
len
int len
Definition: vorbis_enc_data.h:452
AVIOInternal
Definition: aviobuf.c:45
int_cb
const AVIOInterruptCB int_cb
Definition: ffmpeg.c:481
AV_CRC_32_IEEE
@ AV_CRC_32_IEEE
Definition: crc.h:53
DynBuffer::io_buffer_size
int io_buffer_size
Definition: aviobuf.c:1298
avio_wb64
void avio_wb64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:463
AVIO_DATA_MARKER_UNKNOWN
@ AVIO_DATA_MARKER_UNKNOWN
This is any, unlabelled data.
Definition: avio.h:135
avio_get_str
int avio_get_str(AVIOContext *s, int maxlen, char *buf, int buflen)
Read a string from pb into buf.
Definition: aviobuf.c:879
ret
ret
Definition: filter_design.txt:187
read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
avformat.h
checksum
static volatile int checksum
Definition: adler32.c:30
dict.h
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: avcodec.h:790
io_short_seek
static int io_short_seek(void *opaque)
Definition: aviobuf.c:958
av_bprint_clear
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
Definition: bprint.c:227
ff_crc04C11DB7_update
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:600
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:638
AVIO_SEEKABLE_NORMAL
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:40
ffurl_read
int ffurl_read(URLContext *h, unsigned char *buf, int size)
Read up to size bytes from the resource accessed by h, and store the read bytes in buf.
Definition: avio.c:410
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
av_crc
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
Definition: crc.c:392
url_resetbuf
static int url_resetbuf(AVIOContext *s, int flags)
Definition: aviobuf.c:1096
io_seek
static int64_t io_seek(void *opaque, int64_t offset, int whence)
Definition: aviobuf.c:952
io_write_packet
static int io_write_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:946
AVIO_DATA_MARKER_HEADER
@ AVIO_DATA_MARKER_HEADER
Header data; this needs to be present for the stream to be decodeable.
Definition: avio.h:115
ffurl_write
int ffurl_write(URLContext *h, const unsigned char *buf, int size)
Write size bytes from buf to the resource accessed by h.
Definition: avio.c:424
ff_crcA001_update
unsigned long ff_crcA001_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:612
DynBuffer::size
int size
Definition: aviobuf.c:1296
AVSEEK_FORCE
#define AVSEEK_FORCE
Passing this flag as the "whence" parameter to a seek function causes it to seek by any means (like r...
Definition: avio.h:539
AVIO_FLAG_DIRECT
#define AVIO_FLAG_DIRECT
Use direct mode.
Definition: avio.h:681
AV_CRC_32_IEEE_LE
@ AV_CRC_32_IEEE_LE
Definition: crc.h:54
AVIO_FLAG_READ
#define AVIO_FLAG_READ
read-only
Definition: avio.h:654
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:251
avio_alloc_context
AVIOContext * avio_alloc_context(unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
Allocate and initialize an AVIOContext for buffered I/O.
Definition: aviobuf.c:131
ffio_fdopen
int ffio_fdopen(AVIOContext **s, URLContext *h)
Create and initialize a AVIOContext for accessing the resource referenced by the URLContext h.
Definition: aviobuf.c:980
avio_open_dyn_buf
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1386
avio_wb16
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:475
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
ffurl_handshake
int ffurl_handshake(URLContext *c)
Perform one step of the protocol handshake to accept a new client.
Definition: avio.c:234
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
DynBuffer::allocated_size
int allocated_size
Definition: aviobuf.c:1296
avio_rb32
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:800
ff_get_v_length
int ff_get_v_length(uint64_t val)
Get the length in bytes which is needed to store val as v.
Definition: aviobuf.c:437
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
ffio_close_null_buf
int ffio_close_null_buf(AVIOContext *s)
Close a null buffer.
Definition: aviobuf.c:1475
h
h
Definition: vp9dsp_template.c:2038
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:227
avio_handshake
int avio_handshake(AVIOContext *c)
Perform one step of the protocol handshake to accept a new client.
Definition: aviobuf.c:1286
writeout
static void writeout(AVIOContext *s, const uint8_t *data, int len)
Definition: aviobuf.c:153
avio_size
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:336
avio_read_partial
int avio_read_partial(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:716
avio_wl64
void avio_wl64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:457
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:331
avio_rb64
uint64_t avio_rb64(AVIOContext *s)
Definition: aviobuf.c:921
avio_closep
int avio_closep(AVIOContext **s)
Close the resource accessed by the AVIOContext *s, free it and set the pointer pointing to it to NULL...
Definition: aviobuf.c:1210
AVIO_DATA_MARKER_FLUSH_POINT
@ AVIO_DATA_MARKER_FLUSH_POINT
A point in the output bytestream where the underlying AVIOContext might flush the buffer depending on...
Definition: avio.h:146