Revision 01d91b9b libavformat/aviobuf.c

View differences:

libavformat/aviobuf.c
295 295
{
296 296
    uint8_t *dst= !s->max_packet_size && s->buf_end - s->buffer < s->buffer_size ? s->buf_ptr : s->buffer;
297 297
    int len= s->buffer_size - (dst - s->buffer);
298
    int max_buffer_size = s->max_packet_size ? s->max_packet_size : IO_BUFFER_SIZE;
298 299

  
299 300
    assert(s->buf_ptr == s->buf_end);
300 301

  
......
308 309
        s->checksum_ptr= s->buffer;
309 310
    }
310 311

  
312
    /* make buffer smaller in case it ended up large after probing */
313
    if (s->buffer_size > max_buffer_size) {
314
        url_setbufsize(s, max_buffer_size);
315

  
316
        s->checksum_ptr = dst = s->buffer;
317
        len = s->buffer_size;
318
    }
319

  
311 320
    if(s->read_packet)
312 321
        len = s->read_packet(s->opaque, dst, len);
313 322
    else
......
611 620
    return 0;
612 621
}
613 622

  
623
int ff_rewind_with_probe_data(ByteIOContext *s, unsigned char *buf, int buf_size)
624
{
625
    int64_t buffer_start;
626
    int buffer_size;
627
    int overlap, new_size;
628

  
629
    if (s->write_flag)
630
        return AVERROR(EINVAL);
631

  
632
    buffer_size = s->buf_end - s->buffer;
633

  
634
    /* the buffers must touch or overlap */
635
    if ((buffer_start = s->pos - buffer_size) > buf_size)
636
        return AVERROR(EINVAL);
637

  
638
    overlap = buf_size - buffer_start;
639
    new_size = buf_size + buffer_size - overlap;
640

  
641
    if (new_size > buf_size) {
642
        if (!(buf = av_realloc(buf, new_size)))
643
            return AVERROR(ENOMEM);
644

  
645
        memcpy(buf + buf_size, s->buffer + overlap, buffer_size - overlap);
646
        buf_size = new_size;
647
    }
648

  
649
    av_free(s->buffer);
650
    s->buf_ptr = s->buffer = buf;
651
    s->pos = s->buffer_size = buf_size;
652
    s->buf_end = s->buf_ptr + buf_size;
653
    s->eof_reached = 0;
654
    s->must_flush = 0;
655

  
656
    return 0;
657
}
658

  
614 659
int url_fopen(ByteIOContext **s, const char *filename, int flags)
615 660
{
616 661
    URLContext *h;

Also available in: Unified diff