int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)

{

    uint8_t *buffer;

    int max_buffer_size = s->max_packet_size ?

                          s->max_packet_size : IO_BUFFER_SIZE;

    int filled = s->buf_end - s->buffer;

    ptrdiff_t checksum_ptr_offset = s->checksum_ptr ? s->checksum_ptr - s->buffer : -1;



    buf_size += s->buf_ptr - s->buffer + max_buffer_size;



    if (buf_size < filled || s->seekable || !s->read_packet)

        return 0;

    av_assert0(!s->write_flag);



    buffer = av_malloc(buf_size);

    if (!buffer)

        return AVERROR(ENOMEM);



    memcpy(buffer, s->buffer, filled);

    av_free(s->buffer);

    s->buf_ptr = buffer + (s->buf_ptr - s->buffer);

    s->buf_end = buffer + (s->buf_end - s->buffer);

    s->buffer = buffer;

    s->buffer_size = buf_size;



    return 0;

}
int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)

{

    uint8_t *buffer;

    int max_buffer_size = s->max_packet_size ?

                          s->max_packet_size : IO_BUFFER_SIZE;

    int filled = s->buf_end - s->buffer;

    ptrdiff_t checksum_ptr_offset = s->checksum_ptr ? s->checksum_ptr - s->buffer : -1;



    buf_size += s->buf_ptr - s->buffer + max_buffer_size;



    if (buf_size < filled || s->seekable || !s->read_packet)

        return 0;

    av_assert0(!s->write_flag);



    buffer = av_malloc(buf_size);

    if (!buffer)

        return AVERROR(ENOMEM);



    memcpy(buffer, s->buffer, filled);

    av_free(s->buffer);

    s->buf_ptr = buffer + (s->buf_ptr - s->buffer);

    s->buf_end = buffer + (s->buf_end - s->buffer);

    s->buffer = buffer;

    s->buffer_size = buf_size;



    return 0;

}
int FUNC_0(AVIOContext *VAR_0, int64_t VAR_1)

{

    uint8_t *buffer;

    int VAR_2 = VAR_0->max_packet_size ?

                          VAR_0->max_packet_size : IO_BUFFER_SIZE;

    int VAR_3 = VAR_0->buf_end - VAR_0->buffer;

    ptrdiff_t checksum_ptr_offset = VAR_0->checksum_ptr ? VAR_0->checksum_ptr - VAR_0->buffer : -1;



    VAR_1 += VAR_0->buf_ptr - VAR_0->buffer + VAR_2;



    if (VAR_1 < VAR_3 || VAR_0->seekable || !VAR_0->read_packet)

        return 0;

    av_assert0(!VAR_0->write_flag);



    buffer = av_malloc(VAR_1);

    if (!buffer)

        return AVERROR(ENOMEM);



    memcpy(buffer, VAR_0->buffer, VAR_3);

    av_free(VAR_0->buffer);

    VAR_0->buf_ptr = buffer + (VAR_0->buf_ptr - VAR_0->buffer);

    VAR_0->buf_end = buffer + (VAR_0->buf_end - VAR_0->buffer);

    VAR_0->buffer = buffer;

    VAR_0->buffer_size = VAR_1;



    return 0;

}
int FUNC_0(AVIOContext *VAR_0, int64_t VAR_1)
{ uint8_t *buffer; int VAR_2 = VAR_0->max_packet_size ?
VAR_0->max_packet_size : IO_BUFFER_SIZE; int VAR_3 = VAR_0->buf_end - VAR_0->buffer; ptrdiff_t checksum_ptr_offset = VAR_0->checksum_ptr ? VAR_0->checksum_ptr - VAR_0->buffer : -1; VAR_1 += VAR_0->buf_ptr - VAR_0->buffer + VAR_2; if (VAR_1 < VAR_3 || VAR_0->seekable || !VAR_0->read_packet)
return 0; av_assert0(!VAR_0->write_flag); buffer = av_malloc(VAR_1); if (!buffer)
return AVERROR(ENOMEM); memcpy(buffer, VAR_0->buffer, VAR_3); av_free(VAR_0->buffer); VAR_0->buf_ptr = buffer + (VAR_0->buf_ptr - VAR_0->buffer); VAR_0->buf_end = buffer + (VAR_0->buf_end - VAR_0->buffer); VAR_0->buffer = buffer; VAR_0->buffer_size = VAR_1; return 0; }