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