static int ffmmal_add_packet(AVCodecContext *avctx, AVPacket *avpkt,

                             int is_extradata)

{

    MMALDecodeContext *ctx = avctx->priv_data;

    AVBufferRef *buf = NULL;

    int size = 0;

    uint8_t *data = (uint8_t *)"";

    uint8_t *start;

    int ret = 0;



    if (avpkt->size) {

        if (avpkt->buf) {

            buf = av_buffer_ref(avpkt->buf);

            size = avpkt->size;

            data = avpkt->data;

        } else {

            buf = av_buffer_alloc(avpkt->size);

            if (buf) {

                memcpy(buf->data, avpkt->data, avpkt->size);

                size = buf->size;

                data = buf->data;

            }

        }

        if (!buf) {

            ret = AVERROR(ENOMEM);

            goto done;

        }

        if (!is_extradata)

            ctx->packets_sent++;

    } else {

        if (!ctx->packets_sent) {

            // Short-cut the flush logic to avoid upsetting MMAL.

            ctx->eos_sent = 1;

            ctx->eos_received = 1;

            goto done;

        }

    }



    start = data;



    do {

        FFBufferEntry *buffer = av_mallocz(sizeof(*buffer));

        if (!buffer) {

            ret = AVERROR(ENOMEM);

            goto done;

        }



        buffer->data = data;

        buffer->length = FFMIN(size, ctx->decoder->input[0]->buffer_size);



        if (is_extradata)

            buffer->flags |= MMAL_BUFFER_HEADER_FLAG_CONFIG;



        if (data == start)

            buffer->flags |= MMAL_BUFFER_HEADER_FLAG_FRAME_START;



        data += buffer->length;

        size -= buffer->length;



        buffer->pts = avpkt->pts == AV_NOPTS_VALUE ? MMAL_TIME_UNKNOWN : avpkt->pts;

        buffer->dts = avpkt->dts == AV_NOPTS_VALUE ? MMAL_TIME_UNKNOWN : avpkt->dts;



        if (!size)

            buffer->flags |= MMAL_BUFFER_HEADER_FLAG_FRAME_END;



        if (!buffer->length) {

            buffer->flags |= MMAL_BUFFER_HEADER_FLAG_EOS;

            ctx->eos_sent = 1;

        }



        if (buf) {

            buffer->ref = av_buffer_ref(buf);

            if (!buffer->ref) {

                av_free(buffer);

                ret = AVERROR(ENOMEM);

                goto done;

            }

        }



        // Insert at end of the list

        if (!ctx->waiting_buffers)

            ctx->waiting_buffers = buffer;

        if (ctx->waiting_buffers_tail)

            ctx->waiting_buffers_tail->next = buffer;

        ctx->waiting_buffers_tail = buffer;

    } while (size);



done:

    av_buffer_unref(&buf);

    return ret;

}

static int ffmmal_add_packet(AVCodecContext *avctx, AVPacket *avpkt,

                             int is_extradata)

{

    MMALDecodeContext *ctx = avctx->priv_data;

    AVBufferRef *buf = NULL;

    int size = 0;

    uint8_t *data = (uint8_t *)"";

    uint8_t *start;

    int ret = 0;



    if (avpkt->size) {

        if (avpkt->buf) {

            buf = av_buffer_ref(avpkt->buf);

            size = avpkt->size;

            data = avpkt->data;

        } else {

            buf = av_buffer_alloc(avpkt->size);

            if (buf) {

                memcpy(buf->data, avpkt->data, avpkt->size);

                size = buf->size;

                data = buf->data;

            }

        }

        if (!buf) {

            ret = AVERROR(ENOMEM);

            goto done;

        }

        if (!is_extradata)

            ctx->packets_sent++;

    } else {

        if (!ctx->packets_sent) {

            

            ctx->eos_sent = 1;

            ctx->eos_received = 1;

            goto done;

        }

    }



    start = data;



    do {

        FFBufferEntry *buffer = av_mallocz(sizeof(*buffer));

        if (!buffer) {

            ret = AVERROR(ENOMEM);

            goto done;

        }



        buffer->data = data;

        buffer->length = FFMIN(size, ctx->decoder->input[0]->buffer_size);



        if (is_extradata)

            buffer->flags |= MMAL_BUFFER_HEADER_FLAG_CONFIG;



        if (data == start)

            buffer->flags |= MMAL_BUFFER_HEADER_FLAG_FRAME_START;



        data += buffer->length;

        size -= buffer->length;



        buffer->pts = avpkt->pts == AV_NOPTS_VALUE ? MMAL_TIME_UNKNOWN : avpkt->pts;

        buffer->dts = avpkt->dts == AV_NOPTS_VALUE ? MMAL_TIME_UNKNOWN : avpkt->dts;



        if (!size)

            buffer->flags |= MMAL_BUFFER_HEADER_FLAG_FRAME_END;



        if (!buffer->length) {

            buffer->flags |= MMAL_BUFFER_HEADER_FLAG_EOS;

            ctx->eos_sent = 1;

        }



        if (buf) {

            buffer->ref = av_buffer_ref(buf);

            if (!buffer->ref) {

                av_free(buffer);

                ret = AVERROR(ENOMEM);

                goto done;

            }

        }



        

        if (!ctx->waiting_buffers)

            ctx->waiting_buffers = buffer;

        if (ctx->waiting_buffers_tail)

            ctx->waiting_buffers_tail->next = buffer;

        ctx->waiting_buffers_tail = buffer;

    } while (size);



done:

    av_buffer_unref(&buf);

    return ret;

}

        if (!size)
static int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1,

                             int VAR_2)

{

    MMALDecodeContext *ctx = VAR_0->priv_data;

    AVBufferRef *buf = NULL;

    int VAR_3 = 0;

    uint8_t *data = (uint8_t *)"";

    uint8_t *start;

    int VAR_4 = 0;



    if (VAR_1->VAR_3) {

        if (VAR_1->buf) {

            buf = av_buffer_ref(VAR_1->buf);

            VAR_3 = VAR_1->VAR_3;

            data = VAR_1->data;

        } else {

            buf = av_buffer_alloc(VAR_1->VAR_3);

            if (buf) {

                memcpy(buf->data, VAR_1->data, VAR_1->VAR_3);

                VAR_3 = buf->VAR_3;

                data = buf->data;

            }

        }

        if (!buf) {

            VAR_4 = AVERROR(ENOMEM);

            goto done;

        }

        if (!VAR_2)

            ctx->packets_sent++;

    } else {

        if (!ctx->packets_sent) {

            

            ctx->eos_sent = 1;

            ctx->eos_received = 1;

            goto done;

        }

    }



    start = data;



    do {

        FFBufferEntry *buffer = av_mallocz(sizeof(*buffer));

        if (!buffer) {

            VAR_4 = AVERROR(ENOMEM);

            goto done;

        }



        buffer->data = data;

        buffer->length = FFMIN(VAR_3, ctx->decoder->input[0]->buffer_size);



        if (VAR_2)

            buffer->flags |= MMAL_BUFFER_HEADER_FLAG_CONFIG;



        if (data == start)

            buffer->flags |= MMAL_BUFFER_HEADER_FLAG_FRAME_START;



        data += buffer->length;

        VAR_3 -= buffer->length;



        buffer->pts = VAR_1->pts == AV_NOPTS_VALUE ? MMAL_TIME_UNKNOWN : VAR_1->pts;

        buffer->dts = VAR_1->dts == AV_NOPTS_VALUE ? MMAL_TIME_UNKNOWN : VAR_1->dts;



        if (!VAR_3)

            buffer->flags |= MMAL_BUFFER_HEADER_FLAG_FRAME_END;



        if (!buffer->length) {

            buffer->flags |= MMAL_BUFFER_HEADER_FLAG_EOS;

            ctx->eos_sent = 1;

        }



        if (buf) {

            buffer->ref = av_buffer_ref(buf);

            if (!buffer->ref) {

                av_free(buffer);

                VAR_4 = AVERROR(ENOMEM);

                goto done;

            }

        }



        

        if (!ctx->waiting_buffers)

            ctx->waiting_buffers = buffer;

        if (ctx->waiting_buffers_tail)

            ctx->waiting_buffers_tail->next = buffer;

        ctx->waiting_buffers_tail = buffer;

    } while (VAR_3);



done:

    av_buffer_unref(&buf);

    return VAR_4;

}

static int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1,
int VAR_2)
{ MMALDecodeContext *ctx = VAR_0->priv_data; AVBufferRef *buf = NULL; int VAR_3 = 0; uint8_t *data = (uint8_t *)""; uint8_t *start; int VAR_4 = 0; if (VAR_1->VAR_3) { if (VAR_1->buf) { buf = av_buffer_ref(VAR_1->buf); VAR_3 = VAR_1->VAR_3; data = VAR_1->data; } else { buf = av_buffer_alloc(VAR_1->VAR_3); if (buf) { memcpy(buf->data, VAR_1->data, VAR_1->VAR_3); VAR_3 = buf->VAR_3; data = buf->data; } } if (!buf) { VAR_4 = AVERROR(ENOMEM); goto done; } if (!VAR_2)
ctx->packets_sent++; } else { if (!ctx->packets_sent) { ctx->eos_sent = 1; ctx->eos_received = 1; goto done; } } start = data; do { FFBufferEntry *buffer = av_mallocz(sizeof(*buffer)); if (!buffer) { VAR_4 = AVERROR(ENOMEM); goto done; } buffer->data = data; buffer->length = FFMIN(VAR_3, ctx->decoder->input[0]->buffer_size); if (VAR_2)
buffer->flags |= MMAL_BUFFER_HEADER_FLAG_CONFIG; if (data == start)
buffer->flags |= MMAL_BUFFER_HEADER_FLAG_FRAME_START; data += buffer->length; VAR_3 -= buffer->length; buffer->pts = VAR_1->pts == AV_NOPTS_VALUE ? MMAL_TIME_UNKNOWN : VAR_1->pts; buffer->dts = VAR_1->dts == AV_NOPTS_VALUE ? MMAL_TIME_UNKNOWN : VAR_1->dts; if (!VAR_3)
buffer->flags |= MMAL_BUFFER_HEADER_FLAG_FRAME_END; if (!buffer->length) { buffer->flags |= MMAL_BUFFER_HEADER_FLAG_EOS; ctx->eos_sent = 1; } if (buf) { buffer->ref = av_buffer_ref(buf); if (!buffer->ref) { av_free(buffer); VAR_4 = AVERROR(ENOMEM); goto done; } } if (!ctx->waiting_buffers)
ctx->waiting_buffers = buffer; if (ctx->waiting_buffers_tail)
ctx->waiting_buffers_tail->next = buffer; ctx->waiting_buffers_tail = buffer; } while (VAR_3); done:
av_buffer_unref(&buf); return VAR_4; }