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