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)
            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 < 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)\n{\n    int got_frame;\n    int ret;\n    av_assert0(!avctx->internal->buffer_frame->buf[0]);\n    if (!pkt)\n        pkt = avctx->internal->buffer_pkt;\n    avctx->refcounted_frames = 1;\n    if (avctx->internal->draining_done)\n        return AVERROR_EOF;\n    if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {\n        ret = avcodec_decode_video2(avctx, avctx->internal->buffer_frame,\n                                    &got_frame, pkt);\n        if (ret >= 0)\n            ret = pkt->size;\n    } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {\n        ret = avcodec_decode_audio4(avctx, avctx->internal->buffer_frame,\n                                    &got_frame, pkt);\n    } else {\n        ret = AVERROR(EINVAL);\n    }\n    if (ret < 0)\n        return ret;\n    if (avctx->internal->draining && !got_frame)\n        avctx->internal->draining_done = 1;\n    if (ret >= pkt->size) {\n        av_packet_unref(avctx->internal->buffer_pkt);\n    } else {\n        int consumed = ret;\n        if (pkt != avctx->internal->buffer_pkt) {\n            av_packet_unref(avctx->internal->buffer_pkt);\n            if ((ret = av_packet_ref(avctx->internal->buffer_pkt, pkt)) < 0)\n                return ret;\n        }\n        avctx->internal->buffer_pkt->data += consumed;\n        avctx->internal->buffer_pkt->size -= consumed;\n        avctx->internal->buffer_pkt->pts   = AV_NOPTS_VALUE;\n        avctx->internal->buffer_pkt->dts   = AV_NOPTS_VALUE;\n    }\n    if (got_frame)\n        av_assert0(avctx->internal->buffer_frame->buf[0]);\n    return 0;\n}', 'void av_packet_unref(AVPacket *pkt)\n{\n    av_packet_free_side_data(pkt);\n    av_buffer_unref(&pkt->buf);\n    av_init_packet(pkt);\n    pkt->data = NULL;\n    pkt->size = 0;\n}', 'void av_packet_free_side_data(AVPacket *pkt)\n{\n    int i;\n    for (i = 0; i < pkt->side_data_elems; i++)\n        av_free(pkt->side_data[i].data);\n    av_freep(&pkt->side_data);\n    pkt->side_data_elems = 0;\n}', 'void av_buffer_unref(AVBufferRef **buf)\n{\n    AVBuffer *b;\n    if (!buf || !*buf)\n        return;\n    b = (*buf)->buffer;\n    av_freep(buf);\n    if (atomic_fetch_add_explicit(&b->refcount, -1, memory_order_acq_rel) == 1) {\n        b->free(b->opaque, b->data);\n        av_freep(&b);\n    }\n}', 'void av_init_packet(AVPacket *pkt)\n{\n    pkt->pts                  = AV_NOPTS_VALUE;\n    pkt->dts                  = AV_NOPTS_VALUE;\n    pkt->pos                  = -1;\n    pkt->duration             = 0;\n#if FF_API_CONVERGENCE_DURATION\nFF_DISABLE_DEPRECATION_WARNINGS\n    pkt->convergence_duration = 0;\nFF_ENABLE_DEPRECATION_WARNINGS\n#endif\n    pkt->flags                = 0;\n    pkt->stream_index         = 0;\n    pkt->buf                  = NULL;\n    pkt->side_data            = NULL;\n    pkt->side_data_elems      = 0;\n}', 'int av_packet_ref(AVPacket *dst, const AVPacket *src)\n{\n    int ret;\n    ret = av_packet_copy_props(dst, src);\n    if (ret < 0)\n        return ret;\n    if (!src->buf) {\n        ret = packet_alloc(&dst->buf, src->size);\n        if (ret < 0)\n            goto fail;\n        memcpy(dst->buf->data, src->data, src->size);\n        dst->data = dst->buf->data;\n    } else {\n        dst->buf = av_buffer_ref(src->buf);\n        if (!dst->buf) {\n            ret = AVERROR(ENOMEM);\n            goto fail;\n        }\n        dst->data = src->data;\n    }\n    dst->size = src->size;\n    return 0;\nfail:\n    av_packet_free_side_data(dst);\n    return ret;\n}', 'int av_packet_copy_props(AVPacket *dst, const AVPacket *src)\n{\n    int i;\n    dst->pts                  = src->pts;\n    dst->dts                  = src->dts;\n    dst->pos                  = src->pos;\n    dst->duration             = src->duration;\n#if FF_API_CONVERGENCE_DURATION\nFF_DISABLE_DEPRECATION_WARNINGS\n    dst->convergence_duration = src->convergence_duration;\nFF_ENABLE_DEPRECATION_WARNINGS\n#endif\n    dst->flags                = src->flags;\n    dst->stream_index         = src->stream_index;\n    for (i = 0; i < src->side_data_elems; i++) {\n         enum AVPacketSideDataType type = src->side_data[i].type;\n         int size          = src->side_data[i].size;\n         uint8_t *src_data = src->side_data[i].data;\n         uint8_t *dst_data = av_packet_new_side_data(dst, type, size);\n        if (!dst_data) {\n            av_packet_free_side_data(dst);\n            return AVERROR(ENOMEM);\n        }\n        memcpy(dst_data, src_data, size);\n    }\n    return 0;\n}', 'uint8_t *av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,\n                                 int size)\n{\n    int ret;\n    uint8_t *data;\n    if (!size || (unsigned)size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)\n        return NULL;\n    data = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE);\n    if (!data)\n        return NULL;\n    ret = av_packet_add_side_data(pkt, type, data, size);\n    if (ret < 0) {\n        av_freep(&data);\n        return NULL;\n    }\n    return data;\n}', 'void *av_malloc(size_t size)\n{\n    void *ptr = NULL;\n    if (size > (INT_MAX - 32) || !size)\n        return NULL;\n#if HAVE_POSIX_MEMALIGN\n    if (posix_memalign(&ptr, 32, size))\n        ptr = NULL;\n#elif HAVE_ALIGNED_MALLOC\n    ptr = _aligned_malloc(size, 32);\n#elif HAVE_MEMALIGN\n    ptr = memalign(32, size);\n#else\n    ptr = malloc(size);\n#endif\n    return ptr;\n}']