int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int size)

{

    if (size < 0 || avpkt->size < 0 || size > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE) {

        av_log(avctx, AV_LOG_ERROR, "Size %d invalid\n", size);

        return AVERROR(EINVAL);

    }



    if (avctx) {

        av_assert0(!avpkt->data || avpkt->data != avctx->internal->byte_buffer);

        if (!avpkt->data || avpkt->size < size) {

            av_fast_padded_malloc(&avctx->internal->byte_buffer, &avctx->internal->byte_buffer_size, size);

            avpkt->data = avctx->internal->byte_buffer;

            avpkt->size = avctx->internal->byte_buffer_size;

            avpkt->destruct = NULL;

        }

    }



    if (avpkt->data) {

        AVBufferRef *buf = avpkt->buf;

#if FF_API_DESTRUCT_PACKET

        void *destruct = avpkt->destruct;

#endif



        if (avpkt->size < size) {

            av_log(avctx, AV_LOG_ERROR, "User packet is too small (%d < %d)\n", avpkt->size, size);

            return AVERROR(EINVAL);

        }



        av_init_packet(avpkt);

#if FF_API_DESTRUCT_PACKET

        avpkt->destruct = destruct;

#endif

        avpkt->buf      = buf;

        avpkt->size     = size;

        return 0;

    } else {

        int ret = av_new_packet(avpkt, size);

        if (ret < 0)

            av_log(avctx, AV_LOG_ERROR, "Failed to allocate packet of size %d\n", size);

        return ret;

    }

}

int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int size)

{

    if (size < 0 || avpkt->size < 0 || size > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE) {

        av_log(avctx, AV_LOG_ERROR, "Size %d invalid\n", size);

        return AVERROR(EINVAL);

    }



    if (avctx) {

        av_assert0(!avpkt->data || avpkt->data != avctx->internal->byte_buffer);

        if (!avpkt->data || avpkt->size < size) {

            av_fast_padded_malloc(&avctx->internal->byte_buffer, &avctx->internal->byte_buffer_size, size);

            avpkt->data = avctx->internal->byte_buffer;

            avpkt->size = avctx->internal->byte_buffer_size;

            avpkt->destruct = NULL;

        }

    }



    if (avpkt->data) {

        AVBufferRef *buf = avpkt->buf;

#if FF_API_DESTRUCT_PACKET

        void *destruct = avpkt->destruct;

#endif



        if (avpkt->size < size) {

            av_log(avctx, AV_LOG_ERROR, "User packet is too small (%d < %d)\n", avpkt->size, size);

            return AVERROR(EINVAL);

        }



        av_init_packet(avpkt);

#if FF_API_DESTRUCT_PACKET

        avpkt->destruct = destruct;

#endif

        avpkt->buf      = buf;

        avpkt->size     = size;

        return 0;

    } else {

        int ret = av_new_packet(avpkt, size);

        if (ret < 0)

            av_log(avctx, AV_LOG_ERROR, "Failed to allocate packet of size %d\n", size);

        return ret;

    }

}

int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1, int VAR_2)

{

    if (VAR_2 < 0 || VAR_1->VAR_2 < 0 || VAR_2 > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE) {

        av_log(VAR_0, AV_LOG_ERROR, "Size %d invalid\n", VAR_2);

        return AVERROR(EINVAL);

    }



    if (VAR_0) {

        av_assert0(!VAR_1->data || VAR_1->data != VAR_0->internal->byte_buffer);

        if (!VAR_1->data || VAR_1->VAR_2 < VAR_2) {

            av_fast_padded_malloc(&VAR_0->internal->byte_buffer, &VAR_0->internal->byte_buffer_size, VAR_2);

            VAR_1->data = VAR_0->internal->byte_buffer;

            VAR_1->VAR_2 = VAR_0->internal->byte_buffer_size;

            VAR_1->destruct = NULL;

        }

    }



    if (VAR_1->data) {

        AVBufferRef *buf = VAR_1->buf;

#if FF_API_DESTRUCT_PACKET

        void *destruct = VAR_1->destruct;

#endif



        if (VAR_1->VAR_2 < VAR_2) {

            av_log(VAR_0, AV_LOG_ERROR, "User packet is too small (%d < %d)\n", VAR_1->VAR_2, VAR_2);

            return AVERROR(EINVAL);

        }



        av_init_packet(VAR_1);

#if FF_API_DESTRUCT_PACKET

        VAR_1->destruct = destruct;

#endif

        VAR_1->buf      = buf;

        VAR_1->VAR_2     = VAR_2;

        return 0;

    } else {

        int VAR_3 = av_new_packet(VAR_1, VAR_2);

        if (VAR_3 < 0)

            av_log(VAR_0, AV_LOG_ERROR, "Failed to allocate packet of VAR_2 %d\n", VAR_2);

        return VAR_3;

    }

}

int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1, int VAR_2)
{ if (VAR_2 < 0 || VAR_1->VAR_2 < 0 || VAR_2 > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE) { av_log(VAR_0, AV_LOG_ERROR, "Size %d invalid\n", VAR_2); return AVERROR(EINVAL); } if (VAR_0) { av_assert0(!VAR_1->data || VAR_1->data != VAR_0->internal->byte_buffer); if (!VAR_1->data || VAR_1->VAR_2 < VAR_2) { av_fast_padded_malloc(&VAR_0->internal->byte_buffer, &VAR_0->internal->byte_buffer_size, VAR_2); VAR_1->data = VAR_0->internal->byte_buffer; VAR_1->VAR_2 = VAR_0->internal->byte_buffer_size; VAR_1->destruct = NULL; } } if (VAR_1->data) { AVBufferRef *buf = VAR_1->buf; #if FF_API_DESTRUCT_PACKET
void *destruct = VAR_1->destruct; #endif
if (VAR_1->VAR_2 < VAR_2) { av_log(VAR_0, AV_LOG_ERROR, "User packet is too small (%d < %d)\n", VAR_1->VAR_2, VAR_2); return AVERROR(EINVAL); } av_init_packet(VAR_1); #if FF_API_DESTRUCT_PACKET
VAR_1->destruct = destruct; #endif
VAR_1->buf      = buf; VAR_1->VAR_2     = VAR_2; return 0; } else { int VAR_3 = av_new_packet(VAR_1, VAR_2); if (VAR_3 < 0)
av_log(VAR_0, AV_LOG_ERROR, "Failed to allocate packet of VAR_2 %d\n", VAR_2); return VAR_3; } }