35 #define IO_BUFFER_SIZE 32768
42 #define SHORT_SEEK_THRESHOLD 4096
47 return prev ? NULL : s->
opaque;
78 int64_t (*seek)(
void *opaque, int64_t
offset,
int whence))
100 s->
pos = buffer_size;
110 unsigned char *buffer,
116 int64_t (*seek)(
void *opaque, int64_t
offset,
int whence))
204 whence &= ~AVSEEK_FORCE;
211 if (whence != SEEK_CUR && whence != SEEK_SET)
214 if (whence == SEEK_CUR) {
220 offset1 = offset - pos;
229 (whence != SEEK_END || force)) {
244 if ((res = s->
seek(s->
opaque, offset, SEEK_SET)) < 0)
272 if ((size = s->
seek(s->
opaque, -1, SEEK_END)) < 0)
312 avio_write(s, (
const unsigned char *) str, len);
357 avio_wl32(s, (uint32_t)(val & 0xffffffff));
364 avio_wb32(s, (uint32_t)(val & 0xffffffff));
424 len = max_buffer_size;
460 unsigned long (*update_checksum)(
unsigned long c,
const uint8_t *p,
unsigned int len),
461 unsigned long checksum)
639 if (c && i < maxlen-1)
641 }
while (c !=
'\n' && c);
654 buflen =
FFMIN(buflen - 1, maxlen);
655 for (i = 0; i < buflen; i++)
659 for (; i < maxlen; i++)
665 #define GET_STR16(type, read) \
666 int avio_get_str16 ##type(AVIOContext *pb, int maxlen, char *buf, int buflen)\
671 return AVERROR(EINVAL); \
672 while (ret + 1 < maxlen) {\
675 GET_UTF16(ch, (ret += 2) <= maxlen ? read(pb) : 0, break;)\
678 PUT_UTF8(ch, tmp, if (q - buf < buflen - 1) *q++ = tmp;)\
703 val= (val<<7) + (tmp&127);
711 int buffer_size, max_packet_size;
714 if (max_packet_size) {
715 buffer_size = max_packet_size;
731 (*s)->max_packet_size = max_packet_size;
734 (*s)->read_seek = (int64_t (*)(
void *, int, int64_t, int))h->
prot->
url_read_seek;
748 if (buf_size < s->buffer_size || s->
seekable)
796 int64_t buffer_start;
798 int overlap, new_size, alloc_size;
809 if ((buffer_start = s->
pos - buffer_size) > buf_size) {
814 overlap = buf_size - buffer_start;
815 new_size = buf_size + buffer_size - overlap;
818 if (alloc_size > buf_size)
819 if (!(buf = (*bufp) =
av_realloc_f(buf, 1, alloc_size)))
822 if (new_size > buf_size) {
823 memcpy(buf + buf_size, s->
buffer + overlap, buffer_size - overlap);
840 return avio_open2(s, filename, flags, NULL, NULL);
849 err =
ffurl_open(&h, filename, flags, int_cb, options);
892 ret =
vsnprintf(buf,
sizeof(buf), fmt, ap);
906 int64_t timestamp,
int flags)
912 ret = s->
read_seek(h, stream_index, timestamp, flags);
916 pos = s->
seek(h, 0, SEEK_CUR);
919 else if (pos !=
AVERROR(ENOSYS))
937 unsigned new_size, new_allocated_size;
940 new_size = d->
pos + buf_size;
942 if (new_size < d->pos || new_size > INT_MAX/2)
944 while (new_size > new_allocated_size) {
945 if (!new_allocated_size)
946 new_allocated_size = new_size;
948 new_allocated_size += new_allocated_size / 2 + 1;
960 memcpy(d->
buffer + d->
pos, buf, buf_size);
969 unsigned char buf1[4];
986 if (whence == SEEK_CUR)
988 else if (whence == SEEK_END)
990 if (offset < 0 || offset > 0x7fffffffLL)
999 unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
1001 if (
sizeof(
DynBuffer) + io_buffer_size < io_buffer_size)
1014 (*s)->max_packet_size = max_packet_size;
1025 if (max_packet_size <= 0)
1049 return size - padding;