static int do_decode(AVCodecContext *avctx, AVPacket *pkt)

{

    int got_frame;

    int ret;



    av_assert0(!avctx->internal->buffer_frame->buf[0]);



    if (!pkt)

        pkt = avctx->internal->buffer_pkt;



    // This is the lesser evil. The field is for compatibility with legacy users

    // of the legacy API, and users using the new API should not be forced to

    // even know about this field.

    avctx->refcounted_frames = 1;



    // Some codecs (at least wma lossless) will crash when feeding drain packets

    // after EOF was signaled.

    if (avctx->internal->draining_done)

        return AVERROR_EOF;



    if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {

        ret = avcodec_decode_video2(avctx, avctx->internal->buffer_frame,

                                    &got_frame, pkt);

        if (ret >= 0 && !(avctx->flags & AV_CODEC_FLAG_TRUNCATED))

            ret = pkt->size;

    } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {

        ret = avcodec_decode_audio4(avctx, avctx->internal->buffer_frame,

                                    &got_frame, pkt);

    } else {

        ret = AVERROR(EINVAL);

    }



    if (ret == AVERROR(EAGAIN))

        ret = pkt->size;



    if (ret < 0)

        return ret;



    if (avctx->internal->draining && !got_frame)

        avctx->internal->draining_done = 1;



    if (ret >= pkt->size) {

        av_packet_unref(avctx->internal->buffer_pkt);

    } else {

        int consumed = ret;



        if (pkt != avctx->internal->buffer_pkt) {

            av_packet_unref(avctx->internal->buffer_pkt);

            if ((ret = av_packet_ref(avctx->internal->buffer_pkt, pkt)) < 0)

                return ret;

        }



        avctx->internal->buffer_pkt->data += consumed;

        avctx->internal->buffer_pkt->size -= consumed;

        avctx->internal->buffer_pkt->pts   = AV_NOPTS_VALUE;

        avctx->internal->buffer_pkt->dts   = AV_NOPTS_VALUE;

    }



    if (got_frame)

        av_assert0(avctx->internal->buffer_frame->buf[0]);



    return 0;

}

static int do_decode(AVCodecContext *avctx, AVPacket *pkt)

{

    int got_frame;

    int ret;



    av_assert0(!avctx->internal->buffer_frame->buf[0]);



    if (!pkt)

        pkt = avctx->internal->buffer_pkt;



    

    

    

    avctx->refcounted_frames = 1;



    

    

    if (avctx->internal->draining_done)

        return AVERROR_EOF;



    if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {

        ret = avcodec_decode_video2(avctx, avctx->internal->buffer_frame,

                                    &got_frame, pkt);

        if (ret >= 0 && !(avctx->flags & AV_CODEC_FLAG_TRUNCATED))

            ret = pkt->size;

    } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {

        ret = avcodec_decode_audio4(avctx, avctx->internal->buffer_frame,

                                    &got_frame, pkt);

    } else {

        ret = AVERROR(EINVAL);

    }



    if (ret == AVERROR(EAGAIN))

        ret = pkt->size;



    if (ret < 0)

        return ret;



    if (avctx->internal->draining && !got_frame)

        avctx->internal->draining_done = 1;



    if (ret >= pkt->size) {

        av_packet_unref(avctx->internal->buffer_pkt);

    } else {

        int consumed = ret;



        if (pkt != avctx->internal->buffer_pkt) {

            av_packet_unref(avctx->internal->buffer_pkt);

            if ((ret = av_packet_ref(avctx->internal->buffer_pkt, pkt)) < 0)

                return ret;

        }



        avctx->internal->buffer_pkt->data += consumed;

        avctx->internal->buffer_pkt->size -= consumed;

        avctx->internal->buffer_pkt->pts   = AV_NOPTS_VALUE;

        avctx->internal->buffer_pkt->dts   = AV_NOPTS_VALUE;

    }



    if (got_frame)

        av_assert0(avctx->internal->buffer_frame->buf[0]);



    return 0;

}

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

{

    int VAR_2;

    int VAR_3;



    av_assert0(!VAR_0->internal->buffer_frame->buf[0]);



    if (!VAR_1)

        VAR_1 = VAR_0->internal->buffer_pkt;



    

    

    

    VAR_0->refcounted_frames = 1;



    

    

    if (VAR_0->internal->draining_done)

        return AVERROR_EOF;



    if (VAR_0->codec_type == AVMEDIA_TYPE_VIDEO) {

        VAR_3 = avcodec_decode_video2(VAR_0, VAR_0->internal->buffer_frame,

                                    &VAR_2, VAR_1);

        if (VAR_3 >= 0 && !(VAR_0->flags & AV_CODEC_FLAG_TRUNCATED))

            VAR_3 = VAR_1->size;

    } else if (VAR_0->codec_type == AVMEDIA_TYPE_AUDIO) {

        VAR_3 = avcodec_decode_audio4(VAR_0, VAR_0->internal->buffer_frame,

                                    &VAR_2, VAR_1);

    } else {

        VAR_3 = AVERROR(EINVAL);

    }



    if (VAR_3 == AVERROR(EAGAIN))

        VAR_3 = VAR_1->size;



    if (VAR_3 < 0)

        return VAR_3;



    if (VAR_0->internal->draining && !VAR_2)

        VAR_0->internal->draining_done = 1;



    if (VAR_3 >= VAR_1->size) {

        av_packet_unref(VAR_0->internal->buffer_pkt);

    } else {

        int VAR_4 = VAR_3;



        if (VAR_1 != VAR_0->internal->buffer_pkt) {

            av_packet_unref(VAR_0->internal->buffer_pkt);

            if ((VAR_3 = av_packet_ref(VAR_0->internal->buffer_pkt, VAR_1)) < 0)

                return VAR_3;

        }



        VAR_0->internal->buffer_pkt->data += VAR_4;

        VAR_0->internal->buffer_pkt->size -= VAR_4;

        VAR_0->internal->buffer_pkt->pts   = AV_NOPTS_VALUE;

        VAR_0->internal->buffer_pkt->dts   = AV_NOPTS_VALUE;

    }



    if (VAR_2)

        av_assert0(VAR_0->internal->buffer_frame->buf[0]);



    return 0;

}

static int FUNC_0(AVCodecContext *VAR_0, AVPacket *VAR_1)
{ int VAR_2; int VAR_3; av_assert0(!VAR_0->internal->buffer_frame->buf[0]); if (!VAR_1)
VAR_1 = VAR_0->internal->buffer_pkt; VAR_0->refcounted_frames = 1; if (VAR_0->internal->draining_done)
return AVERROR_EOF; if (VAR_0->codec_type == AVMEDIA_TYPE_VIDEO) { VAR_3 = avcodec_decode_video2(VAR_0, VAR_0->internal->buffer_frame,
&VAR_2, VAR_1); if (VAR_3 >= 0 && !(VAR_0->flags & AV_CODEC_FLAG_TRUNCATED))
VAR_3 = VAR_1->size; } else if (VAR_0->codec_type == AVMEDIA_TYPE_AUDIO) { VAR_3 = avcodec_decode_audio4(VAR_0, VAR_0->internal->buffer_frame,
&VAR_2, VAR_1); } else { VAR_3 = AVERROR(EINVAL); } if (VAR_3 == AVERROR(EAGAIN))
VAR_3 = VAR_1->size; if (VAR_3 < 0)
return VAR_3; if (VAR_0->internal->draining && !VAR_2)
VAR_0->internal->draining_done = 1; if (VAR_3 >= VAR_1->size) { av_packet_unref(VAR_0->internal->buffer_pkt); } else { int VAR_4 = VAR_3; if (VAR_1 != VAR_0->internal->buffer_pkt) { av_packet_unref(VAR_0->internal->buffer_pkt); if ((VAR_3 = av_packet_ref(VAR_0->internal->buffer_pkt, VAR_1)) < 0)
return VAR_3; } VAR_0->internal->buffer_pkt->data += VAR_4; VAR_0->internal->buffer_pkt->size -= VAR_4; VAR_0->internal->buffer_pkt->pts   = AV_NOPTS_VALUE; VAR_0->internal->buffer_pkt->dts   = AV_NOPTS_VALUE; } if (VAR_2)
av_assert0(VAR_0->internal->buffer_frame->buf[0]); return 0; }