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))
205 whence &= ~AVSEEK_FORCE;
213 if (whence != SEEK_CUR && whence != SEEK_SET)
216 if (whence == SEEK_CUR) {
222 offset1 = offset - pos;
224 offset1 >= 0 && offset1 <= buffer_size) {
231 (whence != SEEK_END || force)) {
237 }
else if(!s->
write_flag && offset1 < 0 && -offset1 < buffer_size>>1 && s->
seek && offset > 0) {
240 pos -=
FFMIN(buffer_size>>1, pos);
241 if ((res = s->
seek(s->
opaque, pos, SEEK_SET)) < 0)
248 return avio_seek(s, offset, SEEK_SET | force);
257 if ((res = s->
seek(s->
opaque, offset, SEEK_SET)) < 0)
285 if ((size = s->
seek(s->
opaque, -1, SEEK_END)) < 0)
325 avio_write(s, (
const unsigned char *) str, len);
377 avio_wl32(s, (uint32_t)(val & 0xffffffff));
384 avio_wb32(s, (uint32_t)(val & 0xffffffff));
444 len = max_buffer_size;
480 unsigned long (*update_checksum)(
unsigned long c,
const uint8_t *p,
unsigned int len),
481 unsigned long checksum)
659 if (c && i < maxlen-1)
661 }
while (c !=
'\n' && c);
674 buflen =
FFMIN(buflen - 1, maxlen);
675 for (i = 0; i < buflen; i++)
679 for (; i < maxlen; i++)
685 #define GET_STR16(type, read) \
686 int avio_get_str16 ##type(AVIOContext *pb, int maxlen, char *buf, int buflen)\
691 return AVERROR(EINVAL); \
692 while (ret + 1 < maxlen) {\
695 GET_UTF16(ch, (ret += 2) <= maxlen ? read(pb) : 0, break;)\
698 PUT_UTF8(ch, tmp, if (q - buf < buflen - 1) *q++ = tmp;)\
723 val= (val<<7) + (tmp&127);
731 int buffer_size, max_packet_size;
734 if (max_packet_size) {
735 buffer_size = max_packet_size;
751 (*s)->max_packet_size = max_packet_size;
754 (*s)->read_seek = (int64_t (*)(
void *, int, int64_t, int))h->
prot->
url_read_seek;
768 if (buf_size < s->buffer_size || s->
seekable)
816 int64_t buffer_start;
818 int overlap, new_size, alloc_size;
829 if ((buffer_start = s->
pos - buffer_size) > buf_size) {
834 overlap = buf_size - buffer_start;
835 new_size = buf_size + buffer_size - overlap;
838 if (alloc_size > buf_size)
839 if (!(buf = (*bufp) =
av_realloc_f(buf, 1, alloc_size)))
842 if (new_size > buf_size) {
843 memcpy(buf + buf_size, s->
buffer + overlap, buffer_size - overlap);
860 return avio_open2(s, filename, flags, NULL, NULL);
869 err =
ffurl_open(&h, filename, flags, int_cb, options);
912 ret =
vsnprintf(buf,
sizeof(buf), fmt, ap);
926 int64_t timestamp,
int flags)
932 ret = s->
read_seek(h, stream_index, timestamp, flags);
936 pos = s->
seek(h, 0, SEEK_CUR);
939 else if (pos !=
AVERROR(ENOSYS))
957 unsigned new_size, new_allocated_size;
960 new_size = d->
pos + buf_size;
962 if (new_size < d->pos || new_size > INT_MAX/2)
964 while (new_size > new_allocated_size) {
965 if (!new_allocated_size)
966 new_allocated_size = new_size;
968 new_allocated_size += new_allocated_size / 2 + 1;
980 memcpy(d->
buffer + d->
pos, buf, buf_size);
989 unsigned char buf1[4];
1006 if (whence == SEEK_CUR)
1008 else if (whence == SEEK_END)
1010 if (offset < 0 || offset > 0x7fffffffLL)
1019 unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
1021 if (
sizeof(
DynBuffer) + io_buffer_size < io_buffer_size)
1034 (*s)->max_packet_size = max_packet_size;
1045 if (max_packet_size <= 0)
1075 return size - padding;