36 #define IO_BUFFER_SIZE 32768
43 #define SHORT_SEEK_THRESHOLD 4096
79 int64_t (*seek)(
void *opaque, int64_t
offset,
int whence))
102 s->
pos = buffer_size;
112 unsigned char *buffer,
118 int64_t (*seek)(
void *opaque, int64_t
offset,
int whence))
209 whence &= ~AVSEEK_FORCE;
217 if (whence != SEEK_CUR && whence != SEEK_SET)
220 if (whence == SEEK_CUR) {
229 offset1 = offset - pos;
231 offset1 >= 0 && offset1 <= buffer_size - s->write_flag) {
238 (whence != SEEK_END || force)) {
244 }
else if(!s->
write_flag && offset1 < 0 && -offset1 < buffer_size>>1 && s->
seek && offset > 0) {
247 pos -=
FFMIN(buffer_size>>1, pos);
248 if ((res = s->
seek(s->
opaque, pos, SEEK_SET)) < 0)
255 return avio_seek(s, offset, SEEK_SET | force);
264 if ((res = s->
seek(s->
opaque, offset, SEEK_SET)) < 0)
292 if ((size = s->
seek(s->
opaque, -1, SEEK_END)) < 0)
339 avio_write(s, (
const unsigned char *) str, len);
360 av_log(s,
AV_LOG_ERROR,
"Invaid UTF8 sequence in avio_put_str16%s\n", be ?
"be" :
"le");
373 #define PUT_STR16(type, big_endian) \
374 int avio_put_str16 ## type(AVIOContext *s, const char *str) \
376 return put_str16(s, str, big_endian); \
406 avio_wl32(s, (uint32_t)(val & 0xffffffff));
413 avio_wb32(s, (uint32_t)(val & 0xffffffff));
515 unsigned long (*update_checksum)(
unsigned long c,
const uint8_t *p,
unsigned int len),
516 unsigned long checksum)
694 if (c && i < maxlen-1)
696 }
while (c !=
'\n' && c !=
'\r' && c);
711 buflen =
FFMIN(buflen - 1, maxlen);
712 for (i = 0; i < buflen; i++)
716 for (; i < maxlen; i++)
722 #define GET_STR16(type, read) \
723 int avio_get_str16 ##type(AVIOContext *pb, int maxlen, char *buf, int buflen)\
728 return AVERROR(EINVAL); \
729 while (ret + 1 < maxlen) {\
732 GET_UTF16(ch, (ret += 2) <= maxlen ? read(pb) : 0, break;)\
735 PUT_UTF8(ch, tmp, if (q - buf < buflen - 1) *q++ = tmp;)\
760 val= (val<<7) + (tmp&127);
768 int buffer_size, max_packet_size;
771 if (max_packet_size) {
772 buffer_size = max_packet_size;
788 (*s)->max_packet_size = max_packet_size;
791 (*s)->read_seek = (int64_t (*)(
void *, int, int64_t, int))h->
prot->
url_read_seek;
806 if (buf_size < filled || s->seekable)
814 memcpy(buffer, s->
buffer, filled);
855 int64_t buffer_start;
857 int overlap, new_size, alloc_size;
868 if ((buffer_start = s->
pos - buffer_size) > buf_size) {
873 overlap = buf_size - buffer_start;
874 new_size = buf_size + buffer_size - overlap;
877 if (alloc_size > buf_size)
878 if (!(buf = (*bufp) =
av_realloc_f(buf, 1, alloc_size)))
881 if (new_size > buf_size) {
882 memcpy(buf + buf_size, s->
buffer + overlap, buffer_size - overlap);
908 err =
ffurl_open(&h, filename, flags, int_cb, options);
951 ret =
vsnprintf(buf,
sizeof(buf), fmt, ap);
965 int64_t timestamp,
int flags)
971 ret = s->
read_seek(h, stream_index, timestamp, flags);
975 pos = s->
seek(h, 0, SEEK_CUR);
978 else if (pos !=
AVERROR(ENOSYS))
1014 unsigned new_size, new_allocated_size;
1017 new_size = d->
pos + buf_size;
1019 if (new_size < d->pos || new_size > INT_MAX/2)
1021 while (new_size > new_allocated_size) {
1022 if (!new_allocated_size)
1023 new_allocated_size = new_size;
1025 new_allocated_size += new_allocated_size / 2 + 1;
1037 memcpy(d->
buffer + d->
pos, buf, buf_size);
1046 unsigned char buf1[4];
1063 if (whence == SEEK_CUR)
1065 else if (whence == SEEK_END)
1067 if (offset < 0 || offset > 0x7fffffffLL)
1076 unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
1078 if (
sizeof(
DynBuffer) + io_buffer_size < io_buffer_size)
1091 (*s)->max_packet_size = max_packet_size;
1102 if (max_packet_size <= 0)
1132 return size - padding;