static int video_get_buffer(AVCodecContext *s, AVFrame *pic)
{
    int i;
    int w = s->width;
    int h = s->height;
    InternalBuffer *buf;
    AVCodecInternal *avci = s->internal;
    if (pic->data[0] != NULL) {
        av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n");
        return -1;
    }
    if (avci->buffer_count >= INTERNAL_BUFFER_SIZE) {
        av_log(s, AV_LOG_ERROR, "buffer_count overflow (missing release_buffer?)\n");
        return -1;
    }
    if (av_image_check_size(w, h, 0, s))
        return -1;
    if (!avci->buffer) {
        avci->buffer = av_mallocz((INTERNAL_BUFFER_SIZE + 1) *
                                  sizeof(InternalBuffer));
    }
    buf = &avci->buffer[avci->buffer_count];
    if (buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)) {
        for (i = 0; i < AV_NUM_DATA_POINTERS; i++) {
            av_freep(&buf->base[i]);
            buf->data[i] = NULL;
        }
    }
    if (!buf->base[0]) {
        int h_chroma_shift, v_chroma_shift;
        int size[4] = { 0 };
        int tmpsize;
        int unaligned;
        AVPicture picture;
        int stride_align[AV_NUM_DATA_POINTERS];
        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->pix_fmt);
        const int pixel_size = desc->comp[0].step_minus1 + 1;
        avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
        avcodec_align_dimensions2(s, &w, &h, stride_align);
        if (!(s->flags & CODEC_FLAG_EMU_EDGE)) {
            w += EDGE_WIDTH * 2;
            h += EDGE_WIDTH * 2;
        }
        do {
            av_image_fill_linesizes(picture.linesize, s->pix_fmt, w);
            w += w & ~(w - 1);
            unaligned = 0;
            for (i = 0; i < 4; i++)
                unaligned |= picture.linesize[i] % stride_align[i];
        } while (unaligned);
        tmpsize = av_image_fill_pointers(picture.data, s->pix_fmt, h, NULL, picture.linesize);
        if (tmpsize < 0)
            return -1;
        for (i = 0; i < 3 && picture.data[i + 1]; i++)
            size[i] = picture.data[i + 1] - picture.data[i];
        size[i] = tmpsize - (picture.data[i] - picture.data[0]);
        memset(buf->base, 0, sizeof(buf->base));
        memset(buf->data, 0, sizeof(buf->data));
        for (i = 0; i < 4 && size[i]; i++) {
            const int h_shift = i == 0 ? 0 : h_chroma_shift;
            const int v_shift = i == 0 ? 0 : v_chroma_shift;
            buf->linesize[i] = picture.linesize[i];
            buf->base[i] = av_malloc(size[i] + 16);
            if (buf->base[i] == NULL)
                return -1;
            memset(buf->base[i], 128, size[i]);
            if ((s->flags & CODEC_FLAG_EMU_EDGE) || !size[2])
                buf->data[i] = buf->base[i];
            else
                buf->data[i] = buf->base[i] + FFALIGN((buf->linesize[i] * EDGE_WIDTH >> v_shift) + (pixel_size * EDGE_WIDTH >> h_shift), stride_align[i]);
        }
        for (; i < AV_NUM_DATA_POINTERS; i++) {
            buf->base[i]     = buf->data[i] = NULL;
            buf->linesize[i] = 0;
        }
        if (size[1] && !size[2])
            avpriv_set_systematic_pal2((uint32_t *)buf->data[1], s->pix_fmt);
        buf->width   = s->width;
        buf->height  = s->height;
        buf->pix_fmt = s->pix_fmt;
    }
    pic->type = FF_BUFFER_TYPE_INTERNAL;
    for (i = 0; i < AV_NUM_DATA_POINTERS; i++) {
        pic->base[i]     = buf->base[i];
        pic->data[i]     = buf->data[i];
        pic->linesize[i] = buf->linesize[i];
    }
    pic->extended_data = pic->data;
    avci->buffer_count++;
    pic->width               = buf->width;
    pic->height              = buf->height;
    pic->format              = buf->pix_fmt;
    pic->sample_aspect_ratio = s->sample_aspect_ratio;
    if (s->pkt)
        pic->pkt_pts = s->pkt->pts;
    else
        pic->pkt_pts = AV_NOPTS_VALUE;
    pic->reordered_opaque = s->reordered_opaque;
    if (s->debug & FF_DEBUG_BUFFERS)
        av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p, %d "
                                "buffers used\n", pic, avci->buffer_count);
    return 0;
}
['static int video_get_buffer(AVCodecContext *s, AVFrame *pic)\n{\n    int i;\n    int w = s->width;\n    int h = s->height;\n    InternalBuffer *buf;\n    AVCodecInternal *avci = s->internal;\n    if (pic->data[0] != NULL) {\n        av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\\n");\n        return -1;\n    }\n    if (avci->buffer_count >= INTERNAL_BUFFER_SIZE) {\n        av_log(s, AV_LOG_ERROR, "buffer_count overflow (missing release_buffer?)\\n");\n        return -1;\n    }\n    if (av_image_check_size(w, h, 0, s))\n        return -1;\n    if (!avci->buffer) {\n        avci->buffer = av_mallocz((INTERNAL_BUFFER_SIZE + 1) *\n                                  sizeof(InternalBuffer));\n    }\n    buf = &avci->buffer[avci->buffer_count];\n    if (buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)) {\n        for (i = 0; i < AV_NUM_DATA_POINTERS; i++) {\n            av_freep(&buf->base[i]);\n            buf->data[i] = NULL;\n        }\n    }\n    if (!buf->base[0]) {\n        int h_chroma_shift, v_chroma_shift;\n        int size[4] = { 0 };\n        int tmpsize;\n        int unaligned;\n        AVPicture picture;\n        int stride_align[AV_NUM_DATA_POINTERS];\n        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->pix_fmt);\n        const int pixel_size = desc->comp[0].step_minus1 + 1;\n        avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);\n        avcodec_align_dimensions2(s, &w, &h, stride_align);\n        if (!(s->flags & CODEC_FLAG_EMU_EDGE)) {\n            w += EDGE_WIDTH * 2;\n            h += EDGE_WIDTH * 2;\n        }\n        do {\n            av_image_fill_linesizes(picture.linesize, s->pix_fmt, w);\n            w += w & ~(w - 1);\n            unaligned = 0;\n            for (i = 0; i < 4; i++)\n                unaligned |= picture.linesize[i] % stride_align[i];\n        } while (unaligned);\n        tmpsize = av_image_fill_pointers(picture.data, s->pix_fmt, h, NULL, picture.linesize);\n        if (tmpsize < 0)\n            return -1;\n        for (i = 0; i < 3 && picture.data[i + 1]; i++)\n            size[i] = picture.data[i + 1] - picture.data[i];\n        size[i] = tmpsize - (picture.data[i] - picture.data[0]);\n        memset(buf->base, 0, sizeof(buf->base));\n        memset(buf->data, 0, sizeof(buf->data));\n        for (i = 0; i < 4 && size[i]; i++) {\n            const int h_shift = i == 0 ? 0 : h_chroma_shift;\n            const int v_shift = i == 0 ? 0 : v_chroma_shift;\n            buf->linesize[i] = picture.linesize[i];\n            buf->base[i] = av_malloc(size[i] + 16);\n            if (buf->base[i] == NULL)\n                return -1;\n            memset(buf->base[i], 128, size[i]);\n            if ((s->flags & CODEC_FLAG_EMU_EDGE) || !size[2])\n                buf->data[i] = buf->base[i];\n            else\n                buf->data[i] = buf->base[i] + FFALIGN((buf->linesize[i] * EDGE_WIDTH >> v_shift) + (pixel_size * EDGE_WIDTH >> h_shift), stride_align[i]);\n        }\n        for (; i < AV_NUM_DATA_POINTERS; i++) {\n            buf->base[i]     = buf->data[i] = NULL;\n            buf->linesize[i] = 0;\n        }\n        if (size[1] && !size[2])\n            avpriv_set_systematic_pal2((uint32_t *)buf->data[1], s->pix_fmt);\n        buf->width   = s->width;\n        buf->height  = s->height;\n        buf->pix_fmt = s->pix_fmt;\n    }\n    pic->type = FF_BUFFER_TYPE_INTERNAL;\n    for (i = 0; i < AV_NUM_DATA_POINTERS; i++) {\n        pic->base[i]     = buf->base[i];\n        pic->data[i]     = buf->data[i];\n        pic->linesize[i] = buf->linesize[i];\n    }\n    pic->extended_data = pic->data;\n    avci->buffer_count++;\n    pic->width               = buf->width;\n    pic->height              = buf->height;\n    pic->format              = buf->pix_fmt;\n    pic->sample_aspect_ratio = s->sample_aspect_ratio;\n    if (s->pkt)\n        pic->pkt_pts = s->pkt->pts;\n    else\n        pic->pkt_pts = AV_NOPTS_VALUE;\n    pic->reordered_opaque = s->reordered_opaque;\n    if (s->debug & FF_DEBUG_BUFFERS)\n        av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p, %d "\n                                "buffers used\\n", pic, avci->buffer_count);\n    return 0;\n}', 'int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)\n{\n    ImgUtils imgutils = { &imgutils_class, log_offset, log_ctx };\n    if ((int)w>0 && (int)h>0 && (w+128)*(uint64_t)(h+128) < INT_MAX/8)\n        return 0;\n    av_log(&imgutils, AV_LOG_ERROR, "Picture size %ux%u is invalid\\n", w, h);\n    return AVERROR(EINVAL);\n}', 'void av_freep(void *arg)\n{\n    void **ptr = (void **)arg;\n    av_free(*ptr);\n    *ptr = NULL;\n}', 'void av_free(void *ptr)\n{\n#if CONFIG_MEMALIGN_HACK\n    if (ptr)\n        free((char *)ptr - ((char *)ptr)[-1]);\n#elif HAVE_ALIGNED_MALLOC\n    _aligned_free(ptr);\n#else\n    free(ptr);\n#endif\n}', 'const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)\n{\n    if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB)\n        return NULL;\n    return &av_pix_fmt_descriptors[pix_fmt];\n}']