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  if (offset > INT64_MAX - offset1)
255  return AVERROR(EINVAL);
256  offset += offset1;
257  }
258  if (offset < 0)
259  return AVERROR(EINVAL);
260 
261  if (s->short_seek_get) {
262  short_seek = s->short_seek_get(s->opaque);
263  /* fallback to default short seek */
264  if (short_seek <= 0)
265  short_seek = s->short_seek_threshold;
266  } else
267  short_seek = s->short_seek_threshold;
268 
269  offset1 = offset - pos; // "offset1" is the relative offset from the beginning of s->buffer
270  if (!s->must_flush && (!s->direct || !s->seek) &&
271  offset1 >= 0 && offset1 <= buffer_size - s->write_flag) {
272  /* can do the seek inside the buffer */
273  s->buf_ptr = s->buffer + offset1;
274  } else if ((!(s->seekable & AVIO_SEEKABLE_NORMAL) ||
275  offset1 <= buffer_size + short_seek) &&
276  !s->write_flag && offset1 >= 0 &&
277  (!s->direct || !s->seek) &&
278  (whence != SEEK_END || force)) {
279  while(s->pos < offset && !s->eof_reached)
280  fill_buffer(s);
281  if (s->eof_reached)
282  return AVERROR_EOF;
283  s->buf_ptr = s->buf_end - (s->pos - offset);
284  } else if(!s->write_flag && offset1 < 0 && -offset1 < buffer_size>>1 && s->seek && offset > 0) {
285  int64_t res;
286 
287  pos -= FFMIN(buffer_size>>1, pos);
288  if ((res = s->seek(s->opaque, pos, SEEK_SET)) < 0)
289  return res;
290  s->buf_end =
291  s->buf_ptr = s->buffer;
292  s->pos = pos;
293  s->eof_reached = 0;
294  fill_buffer(s);
295  return avio_seek(s, offset, SEEK_SET | force);
296  } else {
297  int64_t res;
298  if (s->write_flag) {
299  flush_buffer(s);
300  s->must_flush = 1;
301  }
302  if (!s->seek)
303  return AVERROR(EPIPE);
304  if ((res = s->seek(s->opaque, offset, SEEK_SET)) < 0)
305  return res;
306  s->seek_count ++;
307  if (!s->write_flag)
308  s->buf_end = s->buffer;
309  s->buf_ptr = s->buffer;
310  s->pos = offset;
311  }
312  s->eof_reached = 0;
313  return offset;
314 }
315 
316 int64_t avio_skip(AVIOContext *s, int64_t offset)
317 {
318  return avio_seek(s, offset, SEEK_CUR);
319 }
320 
322 {
323  int64_t size;
324 
325  if (!s)
326  return AVERROR(EINVAL);
327 
328  if (!s->seek)
329  return AVERROR(ENOSYS);
330  size = s->seek(s->opaque, 0, AVSEEK_SIZE);
331  if (size < 0) {
332  if ((size = s->seek(s->opaque, -1, SEEK_END)) < 0)
333  return size;
334  size++;
335  s->seek(s->opaque, s->pos, SEEK_SET);
336  }
337  return size;
338 }
339 
341 {
342  if(!s)
343  return 0;
344  if(s->eof_reached){
345  s->eof_reached=0;
346  fill_buffer(s);
347  }
348  return s->eof_reached;
349 }
350 
351 #if FF_API_URL_FEOF
352 int url_feof(AVIOContext *s)
353 {
354  return avio_feof(s);
355 }
356 #endif
357 
358 void avio_wl32(AVIOContext *s, unsigned int val)
359 {
360  avio_w8(s, (uint8_t) val );
361  avio_w8(s, (uint8_t)(val >> 8 ));
362  avio_w8(s, (uint8_t)(val >> 16));
363  avio_w8(s, val >> 24 );
364 }
365 
366 void avio_wb32(AVIOContext *s, unsigned int val)
367 {
368  avio_w8(s, val >> 24 );
369  avio_w8(s, (uint8_t)(val >> 16));
370  avio_w8(s, (uint8_t)(val >> 8 ));
371  avio_w8(s, (uint8_t) val );
372 }
373 
374 int avio_put_str(AVIOContext *s, const char *str)
375 {
376  int len = 1;
377  if (str) {
378  len += strlen(str);
379  avio_write(s, (const unsigned char *) str, len);
380  } else
381  avio_w8(s, 0);
382  return len;
383 }
384 
385 static inline int put_str16(AVIOContext *s, const char *str, const int be)
386 {
387  const uint8_t *q = str;
388  int ret = 0;
389  int err = 0;
390 
391  while (*q) {
392  uint32_t ch;
393  uint16_t tmp;
394 
395  GET_UTF8(ch, *q++, goto invalid;)
396  PUT_UTF16(ch, tmp, be ? avio_wb16(s, tmp) : avio_wl16(s, tmp);
397  ret += 2;)
398  continue;
399 invalid:
400  av_log(s, AV_LOG_ERROR, "Invalid UTF8 sequence in avio_put_str16%s\n", be ? "be" : "le");
401  err = AVERROR(EINVAL);
402  if (!*(q-1))
403  break;
404  }
405  if (be)
406  avio_wb16(s, 0);
407  else
408  avio_wl16(s, 0);
409  if (err)
410  return err;
411  ret += 2;
412  return ret;
413 }
414 
415 #define PUT_STR16(type, big_endian) \
416 int avio_put_str16 ## type(AVIOContext *s, const char *str) \
417 { \
418 return put_str16(s, str, big_endian); \
419 }
420 
421 PUT_STR16(le, 0)
422 PUT_STR16(be, 1)
423 
424 #undef PUT_STR16
425 
426 int ff_get_v_length(uint64_t val)
427 {
428  int i = 1;
429 
430  while (val >>= 7)
431  i++;
432 
433  return i;
434 }
435 
436 void ff_put_v(AVIOContext *bc, uint64_t val)
437 {
438  int i = ff_get_v_length(val);
439 
440  while (--i > 0)
441  avio_w8(bc, 128 | (uint8_t)(val >> (7*i)));
442 
443  avio_w8(bc, val & 127);
444 }
445 
446 void avio_wl64(AVIOContext *s, uint64_t val)
447 {
448  avio_wl32(s, (uint32_t)(val & 0xffffffff));
449  avio_wl32(s, (uint32_t)(val >> 32));
450 }
451 
452 void avio_wb64(AVIOContext *s, uint64_t val)
453 {
454  avio_wb32(s, (uint32_t)(val >> 32));
455  avio_wb32(s, (uint32_t)(val & 0xffffffff));
456 }
457 
458 void avio_wl16(AVIOContext *s, unsigned int val)
459 {
460  avio_w8(s, (uint8_t)val);
461  avio_w8(s, (int)val >> 8);
462 }
463 
464 void avio_wb16(AVIOContext *s, unsigned int val)
465 {
466  avio_w8(s, (int)val >> 8);
467  avio_w8(s, (uint8_t)val);
468 }
469 
470 void avio_wl24(AVIOContext *s, unsigned int val)
471 {
472  avio_wl16(s, val & 0xffff);
473  avio_w8(s, (int)val >> 16);
474 }
475 
476 void avio_wb24(AVIOContext *s, unsigned int val)
477 {
478  avio_wb16(s, (int)val >> 8);
479  avio_w8(s, (uint8_t)val);
480 }
481 
483 {
484  if (!s->write_data_type)
485  return;
486  // If ignoring boundary points, just treat it as unknown
489  // Avoid unnecessary flushes if we are already in non-header/trailer
490  // data and setting the type to unknown
491  if (type == AVIO_DATA_MARKER_UNKNOWN &&
494  return;
495 
496  switch (type) {
499  // For header/trailer, ignore a new marker of the same type;
500  // consecutive header/trailer markers can be merged.
501  if (type == s->current_type)
502  return;
503  break;
504  }
505 
506  // If we've reached here, we have a new, noteworthy marker.
507  // Flush the previous data and mark the start of the new data.
508  avio_flush(s);
509  s->current_type = type;
510  s->last_time = time;
511 }
512 
513 /* Input stream */
514 
515 static void fill_buffer(AVIOContext *s)
516 {
517  int max_buffer_size = s->max_packet_size ?
519  uint8_t *dst = s->buf_end - s->buffer + max_buffer_size < s->buffer_size ?
520  s->buf_end : s->buffer;
521  int len = s->buffer_size - (dst - s->buffer);
522 
523  /* can't fill the buffer without read_packet, just set EOF if appropriate */
524  if (!s->read_packet && s->buf_ptr >= s->buf_end)
525  s->eof_reached = 1;
526 
527  /* no need to do anything if EOF already reached */
528  if (s->eof_reached)
529  return;
530 
531  if (s->update_checksum && dst == s->buffer) {
532  if (s->buf_end > s->checksum_ptr)
534  s->buf_end - s->checksum_ptr);
535  s->checksum_ptr = s->buffer;
536  }
537 
538  /* make buffer smaller in case it ended up large after probing */
539  if (s->read_packet && s->orig_buffer_size && s->buffer_size > s->orig_buffer_size) {
540  if (dst == s->buffer) {
541  int ret = ffio_set_buf_size(s, s->orig_buffer_size);
542  if (ret < 0)
543  av_log(s, AV_LOG_WARNING, "Failed to decrease buffer size\n");
544 
545  s->checksum_ptr = dst = s->buffer;
546  }
547  av_assert0(len >= s->orig_buffer_size);
548  len = s->orig_buffer_size;
549  }
550 
551  if (s->read_packet)
552  len = s->read_packet(s->opaque, dst, len);
553  else
554  len = 0;
555  if (len <= 0) {
556  /* do not modify buffer if EOF reached so that a seek back can
557  be done without rereading data */
558  s->eof_reached = 1;
559  if (len < 0)
560  s->error = len;
561  } else {
562  s->pos += len;
563  s->buf_ptr = dst;
564  s->buf_end = dst + len;
565  s->bytes_read += len;
566  }
567 }
568 
569 unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf,
570  unsigned int len)
571 {
572  return av_crc(av_crc_get_table(AV_CRC_32_IEEE), checksum, buf, len);
573 }
574 
575 unsigned long ff_crcEDB88320_update(unsigned long checksum, const uint8_t *buf,
576  unsigned int len)
577 {
578  return av_crc(av_crc_get_table(AV_CRC_32_IEEE_LE), checksum, buf, len);
579 }
580 
581 unsigned long ff_crcA001_update(unsigned long checksum, const uint8_t *buf,
582  unsigned int len)
583 {
584  return av_crc(av_crc_get_table(AV_CRC_16_ANSI_LE), checksum, buf, len);
585 }
586 
588 {
590  s->buf_ptr - s->checksum_ptr);
591  s->update_checksum = NULL;
592  return s->checksum;
593 }
594 
596  unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len),
597  unsigned long checksum)
598 {
599  s->update_checksum = update_checksum;
600  if (s->update_checksum) {
601  s->checksum = checksum;
602  s->checksum_ptr = s->buf_ptr;
603  }
604 }
605 
606 /* XXX: put an inline version */
608 {
609  if (s->buf_ptr >= s->buf_end)
610  fill_buffer(s);
611  if (s->buf_ptr < s->buf_end)
612  return *s->buf_ptr++;
613  return 0;
614 }
615 
616 int avio_read(AVIOContext *s, unsigned char *buf, int size)
617 {
618  int len, size1;
619 
620  size1 = size;
621  while (size > 0) {
622  len = FFMIN(s->buf_end - s->buf_ptr, size);
623  if (len == 0 || s->write_flag) {
624  if((s->direct || size > s->buffer_size) && !s->update_checksum) {
625  // bypass the buffer and read data directly into buf
626  if(s->read_packet)
627  len = s->read_packet(s->opaque, buf, size);
628 
629  if (len <= 0) {
630  /* do not modify buffer if EOF reached so that a seek back can
631  be done without rereading data */
632  s->eof_reached = 1;
633  if(len<0)
634  s->error= len;
635  break;
636  } else {
637  s->pos += len;
638  s->bytes_read += len;
639  size -= len;
640  buf += len;
641  // reset the buffer
642  s->buf_ptr = s->buffer;
643  s->buf_end = s->buffer/* + len*/;
644  }
645  } else {
646  fill_buffer(s);
647  len = s->buf_end - s->buf_ptr;
648  if (len == 0)
649  break;
650  }
651  } else {
652  memcpy(buf, s->buf_ptr, len);
653  buf += len;
654  s->buf_ptr += len;
655  size -= len;
656  }
657  }
658  if (size1 == size) {
659  if (s->error) return s->error;
660  if (avio_feof(s)) return AVERROR_EOF;
661  }
662  return size1 - size;
663 }
664 
665 int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
666 {
667  int ret = avio_read(s, buf, size);
668  if (ret != size)
669  return AVERROR_INVALIDDATA;
670  return ret;
671 }
672 
673 int ffio_read_indirect(AVIOContext *s, unsigned char *buf, int size, const unsigned char **data)
674 {
675  if (s->buf_end - s->buf_ptr >= size && !s->write_flag) {
676  *data = s->buf_ptr;
677  s->buf_ptr += size;
678  return size;
679  } else {
680  *data = buf;
681  return avio_read(s, buf, size);
682  }
683 }
684 
685 int ffio_read_partial(AVIOContext *s, unsigned char *buf, int size)
686 {
687  int len;
688 
689  if (size < 0)
690  return -1;
691 
692  if (s->read_packet && s->write_flag) {
693  len = s->read_packet(s->opaque, buf, size);
694  if (len > 0)
695  s->pos += len;
696  return len;
697  }
698 
699  len = s->buf_end - s->buf_ptr;
700  if (len == 0) {
701  /* Reset the buf_end pointer to the start of the buffer, to make sure
702  * the fill_buffer call tries to read as much data as fits into the
703  * full buffer, instead of just what space is left after buf_end.
704  * This avoids returning partial packets at the end of the buffer,
705  * for packet based inputs.
706  */
707  s->buf_end = s->buf_ptr = s->buffer;
708  fill_buffer(s);
709  len = s->buf_end - s->buf_ptr;
710  }
711  if (len > size)
712  len = size;
713  memcpy(buf, s->buf_ptr, len);
714  s->buf_ptr += len;
715  if (!len) {
716  if (s->error) return s->error;
717  if (avio_feof(s)) return AVERROR_EOF;
718  }
719  return len;
720 }
721 
722 unsigned int avio_rl16(AVIOContext *s)
723 {
724  unsigned int val;
725  val = avio_r8(s);
726  val |= avio_r8(s) << 8;
727  return val;
728 }
729 
730 unsigned int avio_rl24(AVIOContext *s)
731 {
732  unsigned int val;
733  val = avio_rl16(s);
734  val |= avio_r8(s) << 16;
735  return val;
736 }
737 
738 unsigned int avio_rl32(AVIOContext *s)
739 {
740  unsigned int val;
741  val = avio_rl16(s);
742  val |= avio_rl16(s) << 16;
743  return val;
744 }
745 
746 uint64_t avio_rl64(AVIOContext *s)
747 {
748  uint64_t val;
749  val = (uint64_t)avio_rl32(s);
750  val |= (uint64_t)avio_rl32(s) << 32;
751  return val;
752 }
753 
754 unsigned int avio_rb16(AVIOContext *s)
755 {
756  unsigned int val;
757  val = avio_r8(s) << 8;
758  val |= avio_r8(s);
759  return val;
760 }
761 
762 unsigned int avio_rb24(AVIOContext *s)
763 {
764  unsigned int val;
765  val = avio_rb16(s) << 8;
766  val |= avio_r8(s);
767  return val;
768 }
769 unsigned int avio_rb32(AVIOContext *s)
770 {
771  unsigned int val;
772  val = avio_rb16(s) << 16;
773  val |= avio_rb16(s);
774  return val;
775 }
776 
777 int ff_get_line(AVIOContext *s, char *buf, int maxlen)
778 {
779  int i = 0;
780  char c;
781 
782  do {
783  c = avio_r8(s);
784  if (c && i < maxlen-1)
785  buf[i++] = c;
786  } while (c != '\n' && c != '\r' && c);
787  if (c == '\r' && avio_r8(s) != '\n' && !avio_feof(s))
788  avio_skip(s, -1);
789 
790  buf[i] = 0;
791  return i;
792 }
793 
794 int avio_get_str(AVIOContext *s, int maxlen, char *buf, int buflen)
795 {
796  int i;
797 
798  if (buflen <= 0)
799  return AVERROR(EINVAL);
800  // reserve 1 byte for terminating 0
801  buflen = FFMIN(buflen - 1, maxlen);
802  for (i = 0; i < buflen; i++)
803  if (!(buf[i] = avio_r8(s)))
804  return i + 1;
805  buf[i] = 0;
806  for (; i < maxlen; i++)
807  if (!avio_r8(s))
808  return i + 1;
809  return maxlen;
810 }
811 
812 #define GET_STR16(type, read) \
813  int avio_get_str16 ##type(AVIOContext *pb, int maxlen, char *buf, int buflen)\
814 {\
815  char* q = buf;\
816  int ret = 0;\
817  if (buflen <= 0) \
818  return AVERROR(EINVAL); \
819  while (ret + 1 < maxlen) {\
820  uint8_t tmp;\
821  uint32_t ch;\
822  GET_UTF16(ch, (ret += 2) <= maxlen ? read(pb) : 0, break;)\
823  if (!ch)\
824  break;\
825  PUT_UTF8(ch, tmp, if (q - buf < buflen - 1) *q++ = tmp;)\
826  }\
827  *q = 0;\
828  return ret;\
829 }\
830 
832 GET_STR16(be, avio_rb16)
833 
834 #undef GET_STR16
835 
836 uint64_t avio_rb64(AVIOContext *s)
837 {
838  uint64_t val;
839  val = (uint64_t)avio_rb32(s) << 32;
840  val |= (uint64_t)avio_rb32(s);
841  return val;
842 }
843 
845  uint64_t val = 0;
846  int tmp;
847 
848  do{
849  tmp = avio_r8(bc);
850  val= (val<<7) + (tmp&127);
851  }while(tmp&128);
852  return val;
853 }
854 
855 static int io_read_packet(void *opaque, uint8_t *buf, int buf_size)
856 {
857  AVIOInternal *internal = opaque;
858  return ffurl_read(internal->h, buf, buf_size);
859 }
860 
861 static int io_write_packet(void *opaque, uint8_t *buf, int buf_size)
862 {
863  AVIOInternal *internal = opaque;
864  return ffurl_write(internal->h, buf, buf_size);
865 }
866 
867 static int64_t io_seek(void *opaque, int64_t offset, int whence)
868 {
869  AVIOInternal *internal = opaque;
870  return ffurl_seek(internal->h, offset, whence);
871 }
872 
873 static int io_short_seek(void *opaque)
874 {
875  AVIOInternal *internal = opaque;
876  return ffurl_get_short_seek(internal->h);
877 }
878 
879 static int io_read_pause(void *opaque, int pause)
880 {
881  AVIOInternal *internal = opaque;
882  if (!internal->h->prot->url_read_pause)
883  return AVERROR(ENOSYS);
884  return internal->h->prot->url_read_pause(internal->h, pause);
885 }
886 
887 static int64_t io_read_seek(void *opaque, int stream_index, int64_t timestamp, int flags)
888 {
889  AVIOInternal *internal = opaque;
890  if (!internal->h->prot->url_read_seek)
891  return AVERROR(ENOSYS);
892  return internal->h->prot->url_read_seek(internal->h, stream_index, timestamp, flags);
893 }
894 
896 {
897  AVIOInternal *internal = NULL;
898  uint8_t *buffer = NULL;
899  int buffer_size, max_packet_size;
900 
901  max_packet_size = h->max_packet_size;
902  if (max_packet_size) {
903  buffer_size = max_packet_size; /* no need to bufferize more than one packet */
904  } else {
905  buffer_size = IO_BUFFER_SIZE;
906  }
907  buffer = av_malloc(buffer_size);
908  if (!buffer)
909  return AVERROR(ENOMEM);
910 
911  internal = av_mallocz(sizeof(*internal));
912  if (!internal)
913  goto fail;
914 
915  internal->h = h;
916 
917  *s = avio_alloc_context(buffer, buffer_size, h->flags & AVIO_FLAG_WRITE,
919  if (!*s)
920  goto fail;
921 
922  (*s)->protocol_whitelist = av_strdup(h->protocol_whitelist);
923  if (!(*s)->protocol_whitelist && h->protocol_whitelist) {
924  avio_closep(s);
925  goto fail;
926  }
927  (*s)->protocol_blacklist = av_strdup(h->protocol_blacklist);
928  if (!(*s)->protocol_blacklist && h->protocol_blacklist) {
929  avio_closep(s);
930  goto fail;
931  }
932  (*s)->direct = h->flags & AVIO_FLAG_DIRECT;
933 
934  (*s)->seekable = h->is_streamed ? 0 : AVIO_SEEKABLE_NORMAL;
935  (*s)->max_packet_size = max_packet_size;
936  if(h->prot) {
937  (*s)->read_pause = io_read_pause;
938  (*s)->read_seek = io_read_seek;
939 
940  if (h->prot->url_read_seek)
941  (*s)->seekable |= AVIO_SEEKABLE_TIME;
942  }
943  (*s)->short_seek_get = io_short_seek;
944  (*s)->av_class = &ff_avio_class;
945  return 0;
946 fail:
947  av_freep(&internal);
948  av_freep(&buffer);
949  return AVERROR(ENOMEM);
950 }
951 
952 int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
953 {
954  uint8_t *buffer;
955  int max_buffer_size = s->max_packet_size ?
957  int filled = s->buf_end - s->buffer;
958  ptrdiff_t checksum_ptr_offset = s->checksum_ptr ? s->checksum_ptr - s->buffer : -1;
959 
960  buf_size += s->buf_ptr - s->buffer + max_buffer_size;
961 
962  if (buf_size < filled || s->seekable || !s->read_packet)
963  return 0;
964  av_assert0(!s->write_flag);
965 
966  buffer = av_malloc(buf_size);
967  if (!buffer)
968  return AVERROR(ENOMEM);
969 
970  memcpy(buffer, s->buffer, filled);
971  av_free(s->buffer);
972  s->buf_ptr = buffer + (s->buf_ptr - s->buffer);
973  s->buf_end = buffer + (s->buf_end - s->buffer);
974  s->buffer = buffer;
975  s->buffer_size = buf_size;
976  if (checksum_ptr_offset >= 0)
977  s->checksum_ptr = s->buffer + checksum_ptr_offset;
978  return 0;
979 }
980 
981 int ffio_set_buf_size(AVIOContext *s, int buf_size)
982 {
983  uint8_t *buffer;
984  buffer = av_malloc(buf_size);
985  if (!buffer)
986  return AVERROR(ENOMEM);
987 
988  av_free(s->buffer);
989  s->buffer = buffer;
990  s->orig_buffer_size =
991  s->buffer_size = buf_size;
992  s->buf_ptr = buffer;
994  return 0;
995 }
996 
997 static int url_resetbuf(AVIOContext *s, int flags)
998 {
999  av_assert1(flags == AVIO_FLAG_WRITE || flags == AVIO_FLAG_READ);
1000 
1001  if (flags & AVIO_FLAG_WRITE) {
1002  s->buf_end = s->buffer + s->buffer_size;
1003  s->write_flag = 1;
1004  } else {
1005  s->buf_end = s->buffer;
1006  s->write_flag = 0;
1007  }
1008  return 0;
1009 }
1010 
1011 int ffio_rewind_with_probe_data(AVIOContext *s, unsigned char **bufp, int buf_size)
1012 {
1013  int64_t buffer_start;
1014  int buffer_size;
1015  int overlap, new_size, alloc_size;
1016  uint8_t *buf = *bufp;
1017 
1018  if (s->write_flag) {
1019  av_freep(bufp);
1020  return AVERROR(EINVAL);
1021  }
1022 
1023  buffer_size = s->buf_end - s->buffer;
1024 
1025  /* the buffers must touch or overlap */
1026  if ((buffer_start = s->pos - buffer_size) > buf_size) {
1027  av_freep(bufp);
1028  return AVERROR(EINVAL);
1029  }
1030 
1031  overlap = buf_size - buffer_start;
1032  new_size = buf_size + buffer_size - overlap;
1033 
1034  alloc_size = FFMAX(s->buffer_size, new_size);
1035  if (alloc_size > buf_size)
1036  if (!(buf = (*bufp) = av_realloc_f(buf, 1, alloc_size)))
1037  return AVERROR(ENOMEM);
1038 
1039  if (new_size > buf_size) {
1040  memcpy(buf + buf_size, s->buffer + overlap, buffer_size - overlap);
1041  buf_size = new_size;
1042  }
1043 
1044  av_free(s->buffer);
1045  s->buf_ptr = s->buffer = buf;
1046  s->buffer_size = alloc_size;
1047  s->pos = buf_size;
1048  s->buf_end = s->buf_ptr + buf_size;
1049  s->eof_reached = 0;
1050  s->must_flush = 0;
1051 
1052  return 0;
1053 }
1054 
1055 int avio_open(AVIOContext **s, const char *filename, int flags)
1056 {
1057  return avio_open2(s, filename, flags, NULL, NULL);
1058 }
1059 
1060 int ffio_open_whitelist(AVIOContext **s, const char *filename, int flags,
1062  const char *whitelist, const char *blacklist
1063  )
1064 {
1065  URLContext *h;
1066  int err;
1067 
1068  err = ffurl_open_whitelist(&h, filename, flags, int_cb, options, whitelist, blacklist, NULL);
1069  if (err < 0)
1070  return err;
1071  err = ffio_fdopen(s, h);
1072  if (err < 0) {
1073  ffurl_close(h);
1074  return err;
1075  }
1076  return 0;
1077 }
1078 
1079 int avio_open2(AVIOContext **s, const char *filename, int flags,
1081 {
1082  return ffio_open_whitelist(s, filename, flags, int_cb, options, NULL, NULL);
1083 }
1084 
1085 int ffio_open2_wrapper(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags,
1087 {
1088  return ffio_open_whitelist(pb, url, flags, int_cb, options, s->protocol_whitelist, s->protocol_blacklist);
1089 }
1090 
1092 {
1093  AVIOInternal *internal;
1094  URLContext *h;
1095 
1096  if (!s)
1097  return 0;
1098 
1099  avio_flush(s);
1100  internal = s->opaque;
1101  h = internal->h;
1102 
1103  av_freep(&s->opaque);
1104  av_freep(&s->buffer);
1105  if (s->write_flag)
1106  av_log(s, AV_LOG_DEBUG, "Statistics: %d seeks, %d writeouts\n", s->seek_count, s->writeout_count);
1107  else
1108  av_log(s, AV_LOG_DEBUG, "Statistics: %"PRId64" bytes read, %d seeks\n", s->bytes_read, s->seek_count);
1109  av_opt_free(s);
1110  av_free(s);
1111  return ffurl_close(h);
1112 }
1113 
1115 {
1116  int ret = avio_close(*s);
1117  *s = NULL;
1118  return ret;
1119 }
1120 
1121 int avio_printf(AVIOContext *s, const char *fmt, ...)
1122 {
1123  va_list ap;
1124  char buf[4096]; /* update doc entry in avio.h if changed */
1125  int ret;
1126 
1127  va_start(ap, fmt);
1128  ret = vsnprintf(buf, sizeof(buf), fmt, ap);
1129  va_end(ap);
1130  avio_write(s, buf, strlen(buf));
1131  return ret;
1132 }
1133 
1134 int avio_pause(AVIOContext *s, int pause)
1135 {
1136  if (!s->read_pause)
1137  return AVERROR(ENOSYS);
1138  return s->read_pause(s->opaque, pause);
1139 }
1140 
1141 int64_t avio_seek_time(AVIOContext *s, int stream_index,
1142  int64_t timestamp, int flags)
1143 {
1144  int64_t ret;
1145  if (!s->read_seek)
1146  return AVERROR(ENOSYS);
1147  ret = s->read_seek(s->opaque, stream_index, timestamp, flags);
1148  if (ret >= 0) {
1149  int64_t pos;
1150  s->buf_ptr = s->buf_end; // Flush buffer
1151  pos = s->seek(s->opaque, 0, SEEK_CUR);
1152  if (pos >= 0)
1153  s->pos = pos;
1154  else if (pos != AVERROR(ENOSYS))
1155  ret = pos;
1156  }
1157  return ret;
1158 }
1159 
1160 int avio_read_to_bprint(AVIOContext *h, AVBPrint *pb, size_t max_size)
1161 {
1162  int ret;
1163  char buf[1024];
1164  while (max_size) {
1165  ret = avio_read(h, buf, FFMIN(max_size, sizeof(buf)));
1166  if (ret == AVERROR_EOF)
1167  return 0;
1168  if (ret <= 0)
1169  return ret;
1170  av_bprint_append_data(pb, buf, ret);
1171  if (!av_bprint_is_complete(pb))
1172  return AVERROR(ENOMEM);
1173  max_size -= ret;
1174  }
1175  return 0;
1176 }
1177 
1179 {
1180  int ret;
1181  AVIOInternal *internal = s->opaque;
1182  URLContext *sc = internal->h;
1183  URLContext *cc = NULL;
1184  ret = ffurl_accept(sc, &cc);
1185  if (ret < 0)
1186  return ret;
1187  return ffio_fdopen(c, cc);
1188 }
1189 
1191 {
1192  AVIOInternal *internal = c->opaque;
1193  URLContext *cc = internal->h;
1194  return ffurl_handshake(cc);
1195 }
1196 
1197 /* output in a dynamic buffer */
1198 
1199 typedef struct DynBuffer {
1204 } DynBuffer;
1205 
1206 static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
1207 {
1208  DynBuffer *d = opaque;
1209  unsigned new_size, new_allocated_size;
1210 
1211  /* reallocate buffer if needed */
1212  new_size = d->pos + buf_size;
1213  new_allocated_size = d->allocated_size;
1214  if (new_size < d->pos || new_size > INT_MAX/2)
1215  return -1;
1216  while (new_size > new_allocated_size) {
1217  if (!new_allocated_size)
1218  new_allocated_size = new_size;
1219  else
1220  new_allocated_size += new_allocated_size / 2 + 1;
1221  }
1222 
1223  if (new_allocated_size > d->allocated_size) {
1224  int err;
1225  if ((err = av_reallocp(&d->buffer, new_allocated_size)) < 0) {
1226  d->allocated_size = 0;
1227  d->size = 0;
1228  return err;
1229  }
1230  d->allocated_size = new_allocated_size;
1231  }
1232  memcpy(d->buffer + d->pos, buf, buf_size);
1233  d->pos = new_size;
1234  if (d->pos > d->size)
1235  d->size = d->pos;
1236  return buf_size;
1237 }
1238 
1239 static int dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
1240 {
1241  unsigned char buf1[4];
1242  int ret;
1243 
1244  /* packetized write: output the header */
1245  AV_WB32(buf1, buf_size);
1246  ret = dyn_buf_write(opaque, buf1, 4);
1247  if (ret < 0)
1248  return ret;
1249 
1250  /* then the data */
1251  return dyn_buf_write(opaque, buf, buf_size);
1252 }
1253 
1254 static int64_t dyn_buf_seek(void *opaque, int64_t offset, int whence)
1255 {
1256  DynBuffer *d = opaque;
1257 
1258  if (whence == SEEK_CUR)
1259  offset += d->pos;
1260  else if (whence == SEEK_END)
1261  offset += d->size;
1262  if (offset < 0 || offset > 0x7fffffffLL)
1263  return -1;
1264  d->pos = offset;
1265  return 0;
1266 }
1267 
1268 static int url_open_dyn_buf_internal(AVIOContext **s, int max_packet_size)
1269 {
1270  DynBuffer *d;
1271  unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
1272 
1273  if (sizeof(DynBuffer) + io_buffer_size < io_buffer_size)
1274  return -1;
1275  d = av_mallocz(sizeof(DynBuffer) + io_buffer_size);
1276  if (!d)
1277  return AVERROR(ENOMEM);
1278  d->io_buffer_size = io_buffer_size;
1279  *s = avio_alloc_context(d->io_buffer, d->io_buffer_size, 1, d, NULL,
1280  max_packet_size ? dyn_packet_buf_write : dyn_buf_write,
1281  max_packet_size ? NULL : dyn_buf_seek);
1282  if(!*s) {
1283  av_free(d);
1284  return AVERROR(ENOMEM);
1285  }
1286  (*s)->max_packet_size = max_packet_size;
1287  return 0;
1288 }
1289 
1291 {
1292  return url_open_dyn_buf_internal(s, 0);
1293 }
1294 
1295 int ffio_open_dyn_packet_buf(AVIOContext **s, int max_packet_size)
1296 {
1297  if (max_packet_size <= 0)
1298  return -1;
1299  return url_open_dyn_buf_internal(s, max_packet_size);
1300 }
1301 
1303 {
1304  DynBuffer *d;
1305 
1306  if (!s) {
1307  *pbuffer = NULL;
1308  return 0;
1309  }
1310 
1311  avio_flush(s);
1312 
1313  d = s->opaque;
1314  *pbuffer = d->buffer;
1315 
1316  return d->size;
1317 }
1318 
1320 {
1321  DynBuffer *d;
1322  int size;
1323  static const char padbuf[AV_INPUT_BUFFER_PADDING_SIZE] = {0};
1324  int padding = 0;
1325 
1326  if (!s) {
1327  *pbuffer = NULL;
1328  return 0;
1329  }
1330 
1331  /* don't attempt to pad fixed-size packet buffers */
1332  if (!s->max_packet_size) {
1333  avio_write(s, padbuf, sizeof(padbuf));
1334  padding = AV_INPUT_BUFFER_PADDING_SIZE;
1335  }
1336 
1337  avio_flush(s);
1338 
1339  d = s->opaque;
1340  *pbuffer = d->buffer;
1341  size = d->size;
1342  av_free(d);
1343  av_free(s);
1344  return size - padding;
1345 }
1346 
1348 {
1349  uint8_t *tmp;
1350  if (!*s)
1351  return;
1352  avio_close_dyn_buf(*s, &tmp);
1353  av_free(tmp);
1354  *s = NULL;
1355 }
1356 
1357 static int null_buf_write(void *opaque, uint8_t *buf, int buf_size)
1358 {
1359  DynBuffer *d = opaque;
1360 
1361  d->pos += buf_size;
1362  if (d->pos > d->size)
1363  d->size = d->pos;
1364  return buf_size;
1365 }
1366 
1368 {
1369  int ret = url_open_dyn_buf_internal(s, 0);
1370  if (ret >= 0) {
1371  AVIOContext *pb = *s;
1373  }
1374  return ret;
1375 }
1376 
1378 {
1379  DynBuffer *d = s->opaque;
1380  int size;
1381 
1382  avio_flush(s);
1383 
1384  size = d->size;
1385  av_free(d);
1386  av_free(s);
1387  return size;
1388 }
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
Definition: ffmpeg.c:672
void avio_wl64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:446
#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:1254
const char * s
Definition: avisynth_c.h:768
Bytestream IO Context.
Definition: avio.h:155
#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:836
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:246
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:1290
#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:1203
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:464
AVOption.
Definition: opt.h:246
static int64_t io_read_seek(void *opaque, int stream_index, int64_t timestamp, int flags)
Definition: aviobuf.c:887
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:329
const char * fmt
Definition: avisynth_c.h:769
int64_t last_time
Definition: avio.h:323
#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:340
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
unsigned char * buf_ptr
Current position in the buffer.
Definition: avio.h:218
int writeout_count
writeout statistic This field is internal to libavformat and access from outside is not allowed...
Definition: avio.h:282
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:219
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:231
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:1302
#define AVIO_SEEKABLE_TIME
Seeking by timestamp with avio_seek_time() is possible.
Definition: avio.h:45
#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:685
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:620
unsigned int avio_rl24(AVIOContext *s)
Definition: aviobuf.c:730
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:1160
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:621
unsigned char * buffer
Start of the buffer.
Definition: avio.h:216
#define OFFSET(x)
Definition: aviobuf.c:61
void avio_wl24(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:470
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:1114
int64_t(* seek)(void *opaque, int64_t offset, int whence)
Definition: avio.h:227
void * opaque
A private pointer, passed to the read/write/seek/...
Definition: avio.h:223
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:222
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:366
#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:855
Trailer data, which doesn't contain actual content, but only for finalizing the output file...
Definition: avio.h:140
Format I/O context.
Definition: avformat.h:1349
int avio_accept(AVIOContext *s, AVIOContext **c)
Accept and allocate a client context on a server context.
Definition: aviobuf.c:1178
URLContext * h
Definition: aviobuf.c:46
int avio_put_str(AVIOContext *s, const char *str)
Write a NULL-terminated string.
Definition: aviobuf.c:374
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:358
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:515
static int io_read_pause(void *opaque, int pause)
Definition: aviobuf.c:879
unsigned long ffio_get_checksum(AVIOContext *s)
Definition: aviobuf.c:587
void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType type)
Mark the written bytestream as a specific type.
Definition: aviobuf.c:482
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:1367
int ffio_init_context(AVIOContext *s, unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
Definition: aviobuf.c:81
A point in the output bytestream where a demuxer can start parsing (for non self synchronizing bytest...
Definition: avio.h:128
void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size)
Append data to a print buffer.
Definition: bprint.c:158
Public header for CRC hash function implementation.
int64_t bytes_read
Bytes read statistic This field is internal to libavformat and access from outside is not allowed...
Definition: avio.h:270
char * protocol_whitelist
',' separated list of allowed protocols.
Definition: avformat.h:1887
static int flags
Definition: log.c:57
#define AVERROR_EOF
End of file.
Definition: error.h:55
int ffio_set_buf_size(AVIOContext *s, int buf_size)
Definition: aviobuf.c:981
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:673
ptrdiff_t size
Definition: opengl_enc.c:101
void avio_wb24(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:476
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:458
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:1060
unsigned long ff_crcEDB88320_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:575
const OptionDef options[]
Definition: ffserver.c:3948
#define av_log(a,...)
static void flush_buffer(AVIOContext *s)
Definition: aviobuf.c:168
int max_packet_size
Definition: avio.h:232
Callback for checking whether to abort blocking functions.
Definition: avio.h:58
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int io_buffer_size
Definition: aviobuf.c:1202
int(* write_packet)(void *opaque, uint8_t *buf, int buf_size)
Definition: avio.h:226
unsigned int avio_rb24(AVIOContext *s)
Definition: aviobuf.c:762
const AVIOInterruptCB int_cb
Definition: ffmpeg.c:464
static int dyn_packet_buf_write(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:1239
const char * protocol_whitelist
Definition: url.h:49
int(* read_packet)(void *opaque, uint8_t *buf, int buf_size)
Definition: avio.h:225
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:233
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:264
#define fail()
Definition: checkasm.h:89
unsigned int avio_rl16(AVIOContext *s)
Definition: aviobuf.c:722
int seek_count
seek statistic This field is internal to libavformat and access from outside is not allowed...
Definition: avio.h:276
int avio_pause(AVIOContext *s, int pause)
Pause and resume playing - only meaningful if using a network streaming protocol (e.g.
Definition: aviobuf.c:1134
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:310
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:738
This is any, unlabelled data.
Definition: avio.h:135
int size
Definition: aviobuf.c:1200
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:251
int ffio_read_size(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:665
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:1319
unsigned char * checksum_ptr
Definition: avio.h:234
int avio_printf(AVIOContext *s, const char *fmt,...)
Definition: aviobuf.c:1121
AVIODataMarkerType
Different data types that can be returned via the AVIO write_data_type callback.
Definition: avio.h:111
int ffio_open2_wrapper(struct AVFormatContext *s, AVIOContext **pb, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Definition: aviobuf.c:1085
int allocated_size
Definition: aviobuf.c:1200
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:229
static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:1206
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:777
#define GET_STR16(type, read)
Definition: aviobuf.c:812
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:235
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:217
void avio_wb64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:452
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:616
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:40
int ffio_open_dyn_packet_buf(AVIOContext **s, int max_packet_size)
Open a write only packetized memory stream with a maximum packet size of 'max_packet_size'.
Definition: aviobuf.c:1295
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
Definition: mem.c:163
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:237
const char * protocol_blacklist
Definition: url.h:50
#define PUT_STR16(type, big_endian)
Definition: aviobuf.c:415
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:1055
static int io_short_seek(void *opaque)
Definition: aviobuf.c:873
int64_t(* url_read_seek)(URLContext *h, int stream_index, int64_t timestamp, int flags)
Definition: url.h:82
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:1011
static int url_resetbuf(AVIOContext *s, int flags)
Definition: aviobuf.c:997
uint64_t avio_rl64(AVIOContext *s)
Definition: aviobuf.c:746
int avio_close(AVIOContext *s)
Close the resource accessed by the AVIOContext s and free it.
Definition: aviobuf.c:1091
void * buf
Definition: avisynth_c.h:690
Definition: url.h:38
GLint GLenum type
Definition: opengl_enc.c:105
Describe the class of an AVClass context structure.
Definition: log.h:67
#define AV_WB32(p, v)
Definition: intreadwrite.h:424
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c: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:507
#define AVIO_FLAG_DIRECT
Use direct mode.
Definition: avio.h:647
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:754
int pos
Definition: aviobuf.c:1200
int short_seek_threshold
Threshold to favor readahead over seek.
Definition: avio.h:295
#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:317
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
Definition: aviobuf.c:1347
int error
contains the error code or 0 if no error happened
Definition: avio.h:236
int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
Ensures that the requested seekback buffer size will be available.
Definition: aviobuf.c:952
int(* read_pause)(void *opaque, int pause)
Pause or resume playback for network streaming protocols - e.g.
Definition: avio.h:240
int ff_get_v_length(uint64_t val)
Get the length in bytes which is needed to store val as v.
Definition: aviobuf.c:426
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:289
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:322
int avio_handshake(AVIOContext *c)
Perform one step of the protocol handshake to accept a new client.
Definition: aviobuf.c:1190
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:1079
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:321
Main libavformat public API header.
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1544
int avio_get_str(AVIOContext *s, int maxlen, char *buf, int buflen)
Read a string from pb into buf.
Definition: aviobuf.c:794
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:895
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:595
static double c[64]
int64_t pos
position in the file of the current buffer
Definition: avio.h:228
#define AVSEEK_SIZE
ORing this as the "whence" parameter to a seek function causes it to return the filesize without seek...
Definition: avio.h:499
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:769
uint64_t ffio_read_varlen(AVIOContext *bc)
Definition: aviobuf.c:844
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:769
A point in the output bytestream where a decoder can start decoding (i.e.
Definition: avio.h:122
#define av_free(p)
uint8_t * buffer
Definition: aviobuf.c:1201
static int put_str16(AVIOContext *s, const char *str, const int be)
Definition: aviobuf.c:385
int eof_reached
true if eof reached
Definition: avio.h:230
static int io_write_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:861
void ff_put_v(AVIOContext *bc, uint64_t val)
Put val using a variable number of bytes.
Definition: aviobuf.c:436
int len
int ffio_close_null_buf(AVIOContext *s)
Close a null buffer.
Definition: aviobuf.c:1377
static int null_buf_write(void *opaque, uint8_t *buf, int buf_size)
Definition: aviobuf.c:1357
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:1268
char * protocol_blacklist
',' separated list of disallowed protocols.
Definition: avformat.h:1922
int max_packet_size
if non zero, the stream is packetized with this max packet size
Definition: url.h:44
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:316
#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:569
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:607
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:867
Header data; this needs to be present for the stream to be decodeable.
Definition: avio.h:115
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
int64_t avio_seek_time(AVIOContext *s, int stream_index, int64_t timestamp, int flags)
Seek to a given timestamp relative to some component stream.
Definition: aviobuf.c:1141
unsigned long ff_crcA001_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:581
GLuint buffer
Definition: opengl_enc.c:102
static uint8_t tmp[11]
Definition: aes_ctr.c:26