static void dyn_buf_write(void *opaque, UINT8 *buf, int buf_size)

{

    DynBuffer *d = opaque;

    int new_size, new_allocated_size;

    UINT8 *new_buffer;

    

    /* reallocate buffer if needed */

    new_size = d->pos + buf_size;

    new_allocated_size = d->allocated_size;

    while (new_size > new_allocated_size) {

        if (!new_allocated_size)

            new_allocated_size = new_size;

        else

            new_allocated_size = (new_allocated_size * 3) / 2;

    }

    

    if (new_allocated_size > d->allocated_size) {

        new_buffer = av_malloc(new_allocated_size);

        if (!new_buffer)

            return;

        memcpy(new_buffer, d->buffer, d->size);

        av_free(d->buffer);

        d->buffer = new_buffer;

        d->allocated_size = new_allocated_size;

    }

    memcpy(d->buffer + d->pos, buf, buf_size);

    d->pos = new_size;

    if (d->pos > d->size)

        d->size = d->pos;

}

static void dyn_buf_write(void *opaque, UINT8 *buf, int buf_size)

{

    DynBuffer *d = opaque;

    int new_size, new_allocated_size;

    UINT8 *new_buffer;

    

    

    new_size = d->pos + buf_size;

    new_allocated_size = d->allocated_size;

    while (new_size > new_allocated_size) {

        if (!new_allocated_size)

            new_allocated_size = new_size;

        else

            new_allocated_size = (new_allocated_size * 3) / 2;

    }

    

    if (new_allocated_size > d->allocated_size) {

        new_buffer = av_malloc(new_allocated_size);

        if (!new_buffer)

            return;

        memcpy(new_buffer, d->buffer, d->size);

        av_free(d->buffer);

        d->buffer = new_buffer;

        d->allocated_size = new_allocated_size;

    }

    memcpy(d->buffer + d->pos, buf, buf_size);

    d->pos = new_size;

    if (d->pos > d->size)

        d->size = d->pos;

}

static void FUNC_0(void *VAR_0, UINT8 *VAR_1, int VAR_2)

{

    DynBuffer *d = VAR_0;

    int VAR_3, VAR_4;

    UINT8 *new_buffer;

    

    

    VAR_3 = d->pos + VAR_2;

    VAR_4 = d->allocated_size;

    while (VAR_3 > VAR_4) {

        if (!VAR_4)

            VAR_4 = VAR_3;

        else

            VAR_4 = (VAR_4 * 3) / 2;

    }

    

    if (VAR_4 > d->allocated_size) {

        new_buffer = av_malloc(VAR_4);

        if (!new_buffer)

            return;

        memcpy(new_buffer, d->buffer, d->size);

        av_free(d->buffer);

        d->buffer = new_buffer;

        d->allocated_size = VAR_4;

    }

    memcpy(d->buffer + d->pos, VAR_1, VAR_2);

    d->pos = VAR_3;

    if (d->pos > d->size)

        d->size = d->pos;

}

static void FUNC_0(void *VAR_0, UINT8 *VAR_1, int VAR_2)
{ DynBuffer *d = VAR_0; int VAR_3, VAR_4; UINT8 *new_buffer; VAR_3 = d->pos + VAR_2; VAR_4 = d->allocated_size; while (VAR_3 > VAR_4) { if (!VAR_4)
VAR_4 = VAR_3; else
VAR_4 = (VAR_4 * 3) / 2; } if (VAR_4 > d->allocated_size) { new_buffer = av_malloc(VAR_4); if (!new_buffer)
return; memcpy(new_buffer, d->buffer, d->size); av_free(d->buffer); d->buffer = new_buffer; d->allocated_size = VAR_4; } memcpy(d->buffer + d->pos, VAR_1, VAR_2); d->pos = VAR_3; if (d->pos > d->size)
d->size = d->pos; }