int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples,
                               enum AVSampleFormat sample_fmt, int align)
{
    int line_size;
    int sample_size = av_get_bytes_per_sample(sample_fmt);
    int planar      = av_sample_fmt_is_planar(sample_fmt);
    if (!sample_size || nb_samples <= 0 || nb_channels <= 0)
        return AVERROR(EINVAL);
    if (!align) {
        if (nb_samples > INT_MAX - 31)
            return AVERROR(EINVAL);
        align = 1;
        nb_samples = FFALIGN(nb_samples, 32);
    }
    if (nb_channels > INT_MAX / align ||
        (int64_t)nb_channels * nb_samples > (INT_MAX - (align * nb_channels)) / sample_size)
        return AVERROR(EINVAL);
    line_size = planar ? FFALIGN(nb_samples * sample_size,               align) :
                         FFALIGN(nb_samples * sample_size * nb_channels, align);
    if (linesize)
        *linesize = line_size;
    return planar ? line_size * nb_channels : line_size;
}
['int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,\n                         AVPacket *avpkt)\n{\n    const uint8_t *buf = avpkt->data;\n    int buf_size       = avpkt->size;\n    MpegEncContext *s  = avctx->priv_data;\n    int ret;\n    AVFrame *pict = data;\n    s->flags  = avctx->flags;\n    s->flags2 = avctx->flags2;\n    if (buf_size == 0) {\n        if (s->low_delay == 0 && s->next_picture_ptr) {\n            if ((ret = av_frame_ref(pict, &s->next_picture_ptr->f)) < 0)\n                return ret;\n            s->next_picture_ptr = NULL;\n            *got_frame = 1;\n        }\n        return 0;\n    }\n    if (s->flags & CODEC_FLAG_TRUNCATED) {\n        int next;\n        if (CONFIG_MPEG4_DECODER && s->codec_id == AV_CODEC_ID_MPEG4) {\n            next = ff_mpeg4_find_frame_end(&s->parse_context, buf, buf_size);\n        } else if (CONFIG_H263_DECODER && s->codec_id == AV_CODEC_ID_H263) {\n            next = ff_h263_find_frame_end(&s->parse_context, buf, buf_size);\n        } else {\n            av_log(s->avctx, AV_LOG_ERROR,\n                   "this codec does not support truncated bitstreams\\n");\n            return AVERROR(ENOSYS);\n        }\n        if (ff_combine_frame(&s->parse_context, next, (const uint8_t **)&buf,\n                             &buf_size) < 0)\n            return buf_size;\n    }\n    if (s->bitstream_buffer_size && (s->divx_packed || buf_size < 20))\n        ret = init_get_bits8(&s->gb, s->bitstream_buffer,\n                             s->bitstream_buffer_size);\n    else\n        ret = init_get_bits8(&s->gb, buf, buf_size);\n    s->bitstream_buffer_size = 0;\n    if (ret < 0)\n        return ret;\n    if (!s->context_initialized)\n        if ((ret = ff_MPV_common_init(s)) < 0)\n            return ret;\n    if (s->current_picture_ptr == NULL || s->current_picture_ptr->f.data[0]) {\n        int i = ff_find_unused_picture(s, 0);\n        if (i < 0)\n            return i;\n        s->current_picture_ptr = &s->picture[i];\n    }\n    if (CONFIG_WMV2_DECODER && s->msmpeg4_version == 5) {\n        ret = ff_wmv2_decode_picture_header(s);\n    } else if (CONFIG_MSMPEG4_DECODER && s->msmpeg4_version) {\n        ret = ff_msmpeg4_decode_picture_header(s);\n    } else if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) {\n        if (s->avctx->extradata_size && s->picture_number == 0) {\n            GetBitContext gb;\n            ret = init_get_bits8(&gb, s->avctx->extradata,\n                                 s->avctx->extradata_size);\n            if (ret < 0)\n                return ret;\n            ff_mpeg4_decode_picture_header(avctx->priv_data, &gb);\n        }\n        ret = ff_mpeg4_decode_picture_header(avctx->priv_data, &s->gb);\n    } else if (CONFIG_H263I_DECODER && s->codec_id == AV_CODEC_ID_H263I) {\n        ret = ff_intel_h263_decode_picture_header(s);\n    } else if (CONFIG_FLV_DECODER && s->h263_flv) {\n        ret = ff_flv_decode_picture_header(s);\n    } else {\n        ret = ff_h263_decode_picture_header(s);\n    }\n    if (ret == FRAME_SKIPPED)\n        return get_consumed_bytes(s, buf_size);\n    if (ret < 0) {\n        av_log(s->avctx, AV_LOG_ERROR, "header damaged\\n");\n        return ret;\n    }\n    avctx->has_b_frames = !s->low_delay;\n#define SET_QPEL_FUNC(postfix1, postfix2)                           \\\n    s->dsp.put_        ## postfix1 = ff_put_        ## postfix2;    \\\n    s->dsp.put_no_rnd_ ## postfix1 = ff_put_no_rnd_ ## postfix2;    \\\n    s->dsp.avg_        ## postfix1 = ff_avg_        ## postfix2;\n    if (s->workaround_bugs & FF_BUG_STD_QPEL) {\n        SET_QPEL_FUNC(qpel_pixels_tab[0][5], qpel16_mc11_old_c)\n        SET_QPEL_FUNC(qpel_pixels_tab[0][7], qpel16_mc31_old_c)\n        SET_QPEL_FUNC(qpel_pixels_tab[0][9], qpel16_mc12_old_c)\n        SET_QPEL_FUNC(qpel_pixels_tab[0][11], qpel16_mc32_old_c)\n        SET_QPEL_FUNC(qpel_pixels_tab[0][13], qpel16_mc13_old_c)\n        SET_QPEL_FUNC(qpel_pixels_tab[0][15], qpel16_mc33_old_c)\n        SET_QPEL_FUNC(qpel_pixels_tab[1][5], qpel8_mc11_old_c)\n        SET_QPEL_FUNC(qpel_pixels_tab[1][7], qpel8_mc31_old_c)\n        SET_QPEL_FUNC(qpel_pixels_tab[1][9], qpel8_mc12_old_c)\n        SET_QPEL_FUNC(qpel_pixels_tab[1][11], qpel8_mc32_old_c)\n        SET_QPEL_FUNC(qpel_pixels_tab[1][13], qpel8_mc13_old_c)\n        SET_QPEL_FUNC(qpel_pixels_tab[1][15], qpel8_mc33_old_c)\n    }\n    if (s->width  != avctx->coded_width  ||\n        s->height != avctx->coded_height ||\n        s->context_reinit) {\n        s->context_reinit = 0;\n        ret = ff_set_dimensions(avctx, s->width, s->height);\n        if (ret < 0)\n            return ret;\n        if ((ret = ff_MPV_common_frame_size_change(s)))\n            return ret;\n    }\n    if (s->codec_id == AV_CODEC_ID_H263  ||\n        s->codec_id == AV_CODEC_ID_H263P ||\n        s->codec_id == AV_CODEC_ID_H263I)\n        s->gob_index = ff_h263_get_gob_height(s);\n    s->current_picture.f.pict_type = s->pict_type;\n    s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I;\n    if (s->last_picture_ptr == NULL &&\n        (s->pict_type == AV_PICTURE_TYPE_B || s->droppable))\n        return get_consumed_bytes(s, buf_size);\n    if ((avctx->skip_frame >= AVDISCARD_NONREF &&\n         s->pict_type == AV_PICTURE_TYPE_B)    ||\n        (avctx->skip_frame >= AVDISCARD_NONKEY &&\n         s->pict_type != AV_PICTURE_TYPE_I)    ||\n        avctx->skip_frame >= AVDISCARD_ALL)\n        return get_consumed_bytes(s, buf_size);\n    if (s->next_p_frame_damaged) {\n        if (s->pict_type == AV_PICTURE_TYPE_B)\n            return get_consumed_bytes(s, buf_size);\n        else\n            s->next_p_frame_damaged = 0;\n    }\n    if ((!s->no_rounding) || s->pict_type == AV_PICTURE_TYPE_B) {\n        s->me.qpel_put = s->dsp.put_qpel_pixels_tab;\n        s->me.qpel_avg = s->dsp.avg_qpel_pixels_tab;\n    } else {\n        s->me.qpel_put = s->dsp.put_no_rnd_qpel_pixels_tab;\n        s->me.qpel_avg = s->dsp.avg_qpel_pixels_tab;\n    }\n    if ((ret = ff_MPV_frame_start(s, avctx)) < 0)\n        return ret;\n    if (!s->divx_packed && !avctx->hwaccel)\n        ff_thread_finish_setup(avctx);\n    if (avctx->hwaccel) {\n        ret = avctx->hwaccel->start_frame(avctx, s->gb.buffer,\n                                          s->gb.buffer_end - s->gb.buffer);\n        if (ret < 0 )\n            return ret;\n    }\n    ff_mpeg_er_frame_start(s);\n    if (CONFIG_WMV2_DECODER && s->msmpeg4_version == 5) {\n        ret = ff_wmv2_decode_secondary_picture_header(s);\n        if (ret < 0)\n            return ret;\n        if (ret == 1)\n            goto intrax8_decoded;\n    }\n    s->mb_x = 0;\n    s->mb_y = 0;\n    ret = decode_slice(s);\n    while (s->mb_y < s->mb_height) {\n        if (s->msmpeg4_version) {\n            if (s->slice_height == 0 || s->mb_x != 0 ||\n                (s->mb_y % s->slice_height) != 0 || get_bits_left(&s->gb) < 0)\n                break;\n        } else {\n            int prev_x = s->mb_x, prev_y = s->mb_y;\n            if (ff_h263_resync(s) < 0)\n                break;\n            if (prev_y * s->mb_width + prev_x < s->mb_y * s->mb_width + s->mb_x)\n                s->er.error_occurred = 1;\n        }\n        if (s->msmpeg4_version < 4 && s->h263_pred)\n            ff_mpeg4_clean_buffers(s);\n        if (decode_slice(s) < 0)\n            ret = AVERROR_INVALIDDATA;\n    }\n    if (s->msmpeg4_version && s->msmpeg4_version < 4 &&\n        s->pict_type == AV_PICTURE_TYPE_I)\n        if (!CONFIG_MSMPEG4_DECODER ||\n            ff_msmpeg4_decode_ext_header(s, buf_size) < 0)\n            s->er.error_status_table[s->mb_num - 1] = ER_MB_ERROR;\n    assert(s->bitstream_buffer_size == 0);\n    if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4)\n        ff_mpeg4_frame_end(avctx, buf, buf_size);\nintrax8_decoded:\n    ff_er_frame_end(&s->er);\n    if (avctx->hwaccel) {\n        ret = avctx->hwaccel->end_frame(avctx);\n        if (ret < 0)\n            return ret;\n    }\n    ff_MPV_frame_end(s);\n    if (!s->divx_packed && avctx->hwaccel)\n        ff_thread_finish_setup(avctx);\n    assert(s->current_picture.f.pict_type ==\n           s->current_picture_ptr->f.pict_type);\n    assert(s->current_picture.f.pict_type == s->pict_type);\n    if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {\n        if ((ret = av_frame_ref(pict, &s->current_picture_ptr->f)) < 0)\n            return ret;\n        ff_print_debug_info(s, s->current_picture_ptr);\n    } else if (s->last_picture_ptr != NULL) {\n        if ((ret = av_frame_ref(pict, &s->last_picture_ptr->f)) < 0)\n            return ret;\n        ff_print_debug_info(s, s->last_picture_ptr);\n    }\n    if (s->last_picture_ptr || s->low_delay)\n        *got_frame = 1;\n    if (ret && (avctx->err_recognition & AV_EF_EXPLODE))\n        return ret;\n    else\n        return get_consumed_bytes(s, buf_size);\n}', 'int av_frame_ref(AVFrame *dst, const AVFrame *src)\n{\n    int i, ret = 0;\n    dst->format         = src->format;\n    dst->width          = src->width;\n    dst->height         = src->height;\n    dst->channel_layout = src->channel_layout;\n    dst->nb_samples     = src->nb_samples;\n    ret = av_frame_copy_props(dst, src);\n    if (ret < 0)\n        return ret;\n    if (!src->buf[0]) {\n        ret = av_frame_get_buffer(dst, 32);\n        if (ret < 0)\n            return ret;\n        if (src->nb_samples) {\n            int ch = av_get_channel_layout_nb_channels(src->channel_layout);\n            av_samples_copy(dst->extended_data, src->extended_data, 0, 0,\n                            dst->nb_samples, ch, dst->format);\n        } else {\n            av_image_copy(dst->data, dst->linesize, src->data, src->linesize,\n                          dst->format, dst->width, dst->height);\n        }\n        return 0;\n    }\n    for (i = 0; i < FF_ARRAY_ELEMS(src->buf) && src->buf[i]; i++) {\n        dst->buf[i] = av_buffer_ref(src->buf[i]);\n        if (!dst->buf[i]) {\n            ret = AVERROR(ENOMEM);\n            goto fail;\n        }\n    }\n    if (src->extended_buf) {\n        dst->extended_buf = av_mallocz(sizeof(*dst->extended_buf) *\n                                       src->nb_extended_buf);\n        if (!dst->extended_buf) {\n            ret = AVERROR(ENOMEM);\n            goto fail;\n        }\n        dst->nb_extended_buf = src->nb_extended_buf;\n        for (i = 0; i < src->nb_extended_buf; i++) {\n            dst->extended_buf[i] = av_buffer_ref(src->extended_buf[i]);\n            if (!dst->extended_buf[i]) {\n                ret = AVERROR(ENOMEM);\n                goto fail;\n            }\n        }\n    }\n    if (src->extended_data != src->data) {\n        int ch = av_get_channel_layout_nb_channels(src->channel_layout);\n        if (!ch) {\n            ret = AVERROR(EINVAL);\n            goto fail;\n        }\n        dst->extended_data = av_malloc(sizeof(*dst->extended_data) * ch);\n        if (!dst->extended_data) {\n            ret = AVERROR(ENOMEM);\n            goto fail;\n        }\n        memcpy(dst->extended_data, src->extended_data, sizeof(*src->extended_data) * ch);\n    } else\n        dst->extended_data = dst->data;\n    memcpy(dst->data,     src->data,     sizeof(src->data));\n    memcpy(dst->linesize, src->linesize, sizeof(src->linesize));\n    return 0;\nfail:\n    av_frame_unref(dst);\n    return ret;\n}', 'int av_frame_get_buffer(AVFrame *frame, int align)\n{\n    if (frame->format < 0)\n        return AVERROR(EINVAL);\n    if (frame->width > 0 && frame->height > 0)\n        return get_video_buffer(frame, align);\n    else if (frame->nb_samples > 0 && frame->channel_layout)\n        return get_audio_buffer(frame, align);\n    return AVERROR(EINVAL);\n}', 'static int get_audio_buffer(AVFrame *frame, int align)\n{\n    int channels = av_get_channel_layout_nb_channels(frame->channel_layout);\n    int planar   = av_sample_fmt_is_planar(frame->format);\n    int planes   = planar ? channels : 1;\n    int ret, i;\n    if (!frame->linesize[0]) {\n        ret = av_samples_get_buffer_size(&frame->linesize[0], channels,\n                                         frame->nb_samples, frame->format,\n                                         align);\n        if (ret < 0)\n            return ret;\n    }\n    if (planes > AV_NUM_DATA_POINTERS) {\n        frame->extended_data = av_mallocz(planes *\n                                          sizeof(*frame->extended_data));\n        frame->extended_buf  = av_mallocz((planes - AV_NUM_DATA_POINTERS) *\n                                          sizeof(*frame->extended_buf));\n        if (!frame->extended_data || !frame->extended_buf) {\n            av_freep(&frame->extended_data);\n            av_freep(&frame->extended_buf);\n            return AVERROR(ENOMEM);\n        }\n        frame->nb_extended_buf = planes - AV_NUM_DATA_POINTERS;\n    } else\n        frame->extended_data = frame->data;\n    for (i = 0; i < FFMIN(planes, AV_NUM_DATA_POINTERS); i++) {\n        frame->buf[i] = av_buffer_alloc(frame->linesize[0]);\n        if (!frame->buf[i]) {\n            av_frame_unref(frame);\n            return AVERROR(ENOMEM);\n        }\n        frame->extended_data[i] = frame->data[i] = frame->buf[i]->data;\n    }\n    for (i = 0; i < planes - AV_NUM_DATA_POINTERS; i++) {\n        frame->extended_buf[i] = av_buffer_alloc(frame->linesize[0]);\n        if (!frame->extended_buf[i]) {\n            av_frame_unref(frame);\n            return AVERROR(ENOMEM);\n        }\n        frame->extended_data[i + AV_NUM_DATA_POINTERS] = frame->extended_buf[i]->data;\n    }\n    return 0;\n}', 'int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples,\n                               enum AVSampleFormat sample_fmt, int align)\n{\n    int line_size;\n    int sample_size = av_get_bytes_per_sample(sample_fmt);\n    int planar      = av_sample_fmt_is_planar(sample_fmt);\n    if (!sample_size || nb_samples <= 0 || nb_channels <= 0)\n        return AVERROR(EINVAL);\n    if (!align) {\n        if (nb_samples > INT_MAX - 31)\n            return AVERROR(EINVAL);\n        align = 1;\n        nb_samples = FFALIGN(nb_samples, 32);\n    }\n    if (nb_channels > INT_MAX / align ||\n        (int64_t)nb_channels * nb_samples > (INT_MAX - (align * nb_channels)) / sample_size)\n        return AVERROR(EINVAL);\n    line_size = planar ? FFALIGN(nb_samples * sample_size,               align) :\n                         FFALIGN(nb_samples * sample_size * nb_channels, align);\n    if (linesize)\n        *linesize = line_size;\n    return planar ? line_size * nb_channels : line_size;\n}']