34 #define IO_BUFFER_SIZE 32768
41 #define SHORT_SEEK_THRESHOLD 4096
77 int64_t (*seek)(
void *opaque, int64_t offset,
int whence))
108 unsigned char *buffer,
114 int64_t (*seek)(
void *opaque, int64_t offset,
int whence))
191 whence &= ~AVSEEK_FORCE;
198 if (whence != SEEK_CUR && whence != SEEK_SET)
201 if (whence == SEEK_CUR) {
207 offset1 = offset - pos;
215 (whence != SEEK_END || force)) {
230 if ((res = s->
seek(s->
opaque, offset, SEEK_SET)) < 0)
252 if ((size = s->
seek(s->
opaque, -1, SEEK_END)) < 0)
281 avio_write(s, (
const unsigned char *) str, len);
319 avio_w8(bc, 128 | (val >> (7 * i)));
326 avio_wl32(s, (uint32_t)(val & 0xffffffff));
333 avio_wb32(s, (uint32_t)(val & 0xffffffff));
426 unsigned long (*update_checksum)(
unsigned long c,
const uint8_t *p,
unsigned int len),
427 unsigned long checksum)
592 if (c && i < maxlen-1)
594 }
while (c !=
'\n' && c);
607 buflen =
FFMIN(buflen - 1, maxlen);
608 for (i = 0; i < buflen; i++)
612 for (; i < maxlen; i++)
618 #define GET_STR16(type, read) \
619 int avio_get_str16 ##type(AVIOContext *pb, int maxlen, char *buf, int buflen)\
624 return AVERROR(EINVAL); \
625 while (ret + 1 < maxlen) {\
628 GET_UTF16(ch, (ret += 2) <= maxlen ? read(pb) : 0, break;)\
631 PUT_UTF8(ch, tmp, if (q - buf < buflen - 1) *q++ = tmp;)\
656 val= (val<<7) + (tmp&127);
664 int buffer_size, max_packet_size;
667 if (max_packet_size) {
668 buffer_size = max_packet_size;
683 (*s)->max_packet_size = max_packet_size;
686 (*s)->read_seek = (int64_t (*)(
void *, int, int64_t, int))h->
prot->
url_read_seek;
723 int64_t buffer_start;
725 int overlap, new_size, alloc_size;
733 if ((buffer_start = s->
pos - buffer_size) > buf_size)
736 overlap = buf_size - buffer_start;
737 new_size = buf_size + buffer_size - overlap;
740 if (alloc_size > buf_size)
744 if (new_size > buf_size) {
745 memcpy(buf + buf_size, s->
buffer + overlap, buffer_size - overlap);
771 err =
ffurl_open(&h, filename, flags, int_cb, options);
810 ret = vsnprintf(buf,
sizeof(buf), fmt, ap);
824 int64_t timestamp,
int flags)
830 ret = s->
read_seek(h, stream_index, timestamp, flags);
834 pos = s->
seek(h, 0, SEEK_CUR);
837 else if (pos !=
AVERROR(ENOSYS))
855 unsigned new_size, new_allocated_size;
858 new_size = d->
pos + buf_size;
860 if (new_size < d->pos || new_size > INT_MAX/2)
862 while (new_size > new_allocated_size) {
863 if (!new_allocated_size)
864 new_allocated_size = new_size;
866 new_allocated_size += new_allocated_size / 2 + 1;
875 memcpy(d->
buffer + d->
pos, buf, buf_size);
884 unsigned char buf1[4];
901 if (whence == SEEK_CUR)
903 else if (whence == SEEK_END)
905 if (offset < 0 || offset > 0x7fffffffLL)
914 unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
916 if (
sizeof(
DynBuffer) + io_buffer_size < io_buffer_size)
929 (*s)->max_packet_size = max_packet_size;
940 if (max_packet_size <= 0)
964 return size - padding;