static int compat_decode(AVCodecContext *avctx, AVFrame *frame,
                         int *got_frame, AVPacket *pkt)
{
    AVCodecInternal *avci = avctx->internal;
    int ret;
    av_assert0(avci->compat_decode_consumed == 0);
    *got_frame = 0;
    avci->compat_decode = 1;
    if (avci->compat_decode_partial_size > 0 &&
        avci->compat_decode_partial_size != pkt->size) {
        av_log(avctx, AV_LOG_ERROR,
               "Got unexpected packet size after a partial decode\n");
        ret = AVERROR(EINVAL);
        goto finish;
    }
    if (!avci->compat_decode_partial_size) {
        ret = avcodec_send_packet(avctx, pkt);
        if (ret == AVERROR_EOF)
            ret = 0;
        else if (ret == AVERROR(EAGAIN)) {
            ret = AVERROR_BUG;
            goto finish;
        } else if (ret < 0)
            goto finish;
    }
    while (ret >= 0) {
        ret = avcodec_receive_frame(avctx, frame);
        if (ret < 0) {
            if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
                ret = 0;
            goto finish;
        }
        if (frame != avci->compat_decode_frame) {
            if (!avctx->refcounted_frames) {
                ret = unrefcount_frame(avci, frame);
                if (ret < 0)
                    goto finish;
            }
            *got_frame = 1;
            frame = avci->compat_decode_frame;
        } else {
            if (!avci->compat_decode_warned) {
                av_log(avctx, AV_LOG_WARNING, "The deprecated avcodec_decode_* "
                       "API cannot return all the frames for this decoder. "
                       "Some frames will be dropped. Update your code to the "
                       "new decoding API to fix this.\n");
                avci->compat_decode_warned = 1;
            }
        }
        if (avci->draining || (!avctx->codec->bsfs && avci->compat_decode_consumed < pkt->size))
            break;
    }
finish:
    if (ret == 0) {
        if (avctx->codec->bsfs)
            ret = pkt->size;
        else
            ret = FFMIN(avci->compat_decode_consumed, pkt->size);
    }
    avci->compat_decode_consumed = 0;
    avci->compat_decode_partial_size = (ret >= 0) ? pkt->size - ret : 0;
    return ret;
}
['static int compat_decode(AVCodecContext *avctx, AVFrame *frame,\n                         int *got_frame, AVPacket *pkt)\n{\n    AVCodecInternal *avci = avctx->internal;\n    int ret;\n    av_assert0(avci->compat_decode_consumed == 0);\n    *got_frame = 0;\n    avci->compat_decode = 1;\n    if (avci->compat_decode_partial_size > 0 &&\n        avci->compat_decode_partial_size != pkt->size) {\n        av_log(avctx, AV_LOG_ERROR,\n               "Got unexpected packet size after a partial decode\\n");\n        ret = AVERROR(EINVAL);\n        goto finish;\n    }\n    if (!avci->compat_decode_partial_size) {\n        ret = avcodec_send_packet(avctx, pkt);\n        if (ret == AVERROR_EOF)\n            ret = 0;\n        else if (ret == AVERROR(EAGAIN)) {\n            ret = AVERROR_BUG;\n            goto finish;\n        } else if (ret < 0)\n            goto finish;\n    }\n    while (ret >= 0) {\n        ret = avcodec_receive_frame(avctx, frame);\n        if (ret < 0) {\n            if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)\n                ret = 0;\n            goto finish;\n        }\n        if (frame != avci->compat_decode_frame) {\n            if (!avctx->refcounted_frames) {\n                ret = unrefcount_frame(avci, frame);\n                if (ret < 0)\n                    goto finish;\n            }\n            *got_frame = 1;\n            frame = avci->compat_decode_frame;\n        } else {\n            if (!avci->compat_decode_warned) {\n                av_log(avctx, AV_LOG_WARNING, "The deprecated avcodec_decode_* "\n                       "API cannot return all the frames for this decoder. "\n                       "Some frames will be dropped. Update your code to the "\n                       "new decoding API to fix this.\\n");\n                avci->compat_decode_warned = 1;\n            }\n        }\n        if (avci->draining || (!avctx->codec->bsfs && avci->compat_decode_consumed < pkt->size))\n            break;\n    }\nfinish:\n    if (ret == 0) {\n        if (avctx->codec->bsfs)\n            ret = pkt->size;\n        else\n            ret = FFMIN(avci->compat_decode_consumed, pkt->size);\n    }\n    avci->compat_decode_consumed = 0;\n    avci->compat_decode_partial_size = (ret >= 0) ? pkt->size - ret : 0;\n    return ret;\n}']