static int gif_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
{
    GifState *s = avctx->priv_data;
    AVFrame *picture = data;
    int ret;
    bytestream2_init(&s->gb, avpkt->data, avpkt->size);
    s->picture.pts          = avpkt->pts;
    s->picture.pkt_pts      = avpkt->pts;
    s->picture.pkt_dts      = avpkt->dts;
    s->picture.pkt_duration = avpkt->duration;
    if (avpkt->size >= 6) {
        s->keyframe = memcmp(avpkt->data, gif87a_sig, 6) == 0 ||
                      memcmp(avpkt->data, gif89a_sig, 6) == 0;
    } else {
        s->keyframe = 0;
    if (s->keyframe) {
        s->keyframe_ok = 0;
        if ((ret = gif_read_header1(s)) < 0)
            return ret;
        if ((ret = av_image_check_size(s->screen_width, s->screen_height, 0, avctx)) < 0)
            return ret;
        avcodec_set_dimensions(avctx, s->screen_width, s->screen_height);
        if (s->picture.data[0])
            avctx->release_buffer(avctx, &s->picture);
        if ((ret = ff_get_buffer(avctx, &s->picture)) < 0) {
            av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
            return ret;
        s->picture.pict_type = AV_PICTURE_TYPE_I;
        s->picture.key_frame = 1;
    } else {
        if ((ret = avctx->reget_buffer(avctx, &s->picture)) < 0) {
            av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
            return ret;
        s->picture.pict_type = AV_PICTURE_TYPE_P;
        s->picture.key_frame = 0;
    ret = gif_parse_next_image(s, got_frame);
    if (ret < 0)
        return ret;
    else if (*got_frame)
        *picture = s->picture;
    return avpkt->size;
static int gif_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
{
    GifState *s = avctx->priv_data;
    AVFrame *picture = data;
    int ret;
    bytestream2_init(&s->gb, avpkt->data, avpkt->size);
    s->picture.pts          = avpkt->pts;
    s->picture.pkt_pts      = avpkt->pts;
    s->picture.pkt_dts      = avpkt->dts;
    s->picture.pkt_duration = avpkt->duration;
    if (avpkt->size >= 6) {
        s->keyframe = memcmp(avpkt->data, gif87a_sig, 6) == 0 ||
                      memcmp(avpkt->data, gif89a_sig, 6) == 0;
    } else {
        s->keyframe = 0;
    if (s->keyframe) {
        s->keyframe_ok = 0;
        if ((ret = gif_read_header1(s)) < 0)
            return ret;
        if ((ret = av_image_check_size(s->screen_width, s->screen_height, 0, avctx)) < 0)
            return ret;
        avcodec_set_dimensions(avctx, s->screen_width, s->screen_height);
        if (s->picture.data[0])
            avctx->release_buffer(avctx, &s->picture);
        if ((ret = ff_get_buffer(avctx, &s->picture)) < 0) {
            av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
            return ret;
        s->picture.pict_type = AV_PICTURE_TYPE_I;
        s->picture.key_frame = 1;
    } else {
        if ((ret = avctx->reget_buffer(avctx, &s->picture)) < 0) {
            av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
            return ret;
        s->picture.pict_type = AV_PICTURE_TYPE_P;
        s->picture.key_frame = 0;
    ret = gif_parse_next_image(s, got_frame);
    if (ret < 0)
        return ret;
    else if (*got_frame)
        *picture = s->picture;
    return avpkt->size;
static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1, int *VAR_2, AVPacket *VAR_3)
{
    GifState *s = VAR_0->priv_data;
    AVFrame *picture = VAR_1;
    int VAR_4;
    bytestream2_init(&s->gb, VAR_3->VAR_1, VAR_3->size);
    s->picture.pts          = VAR_3->pts;
    s->picture.pkt_pts      = VAR_3->pts;
    s->picture.pkt_dts      = VAR_3->dts;
    s->picture.pkt_duration = VAR_3->duration;
    if (VAR_3->size >= 6) {
        s->keyframe = memcmp(VAR_3->VAR_1, gif87a_sig, 6) == 0 ||
                      memcmp(VAR_3->VAR_1, gif89a_sig, 6) == 0;
    } else {
        s->keyframe = 0;
    if (s->keyframe) {
        s->keyframe_ok = 0;
        if ((VAR_4 = gif_read_header1(s)) < 0)
            return VAR_4;
        if ((VAR_4 = av_image_check_size(s->screen_width, s->screen_height, 0, VAR_0)) < 0)
            return VAR_4;
        avcodec_set_dimensions(VAR_0, s->screen_width, s->screen_height);
        if (s->picture.VAR_1[0])
            VAR_0->release_buffer(VAR_0, &s->picture);
        if ((VAR_4 = ff_get_buffer(VAR_0, &s->picture)) < 0) {
            av_log(VAR_0, AV_LOG_ERROR, "get_buffer() failed\n");
            return VAR_4;
        s->picture.pict_type = AV_PICTURE_TYPE_I;
        s->picture.key_frame = 1;
    } else {
        if ((VAR_4 = VAR_0->reget_buffer(VAR_0, &s->picture)) < 0) {
            av_log(VAR_0, AV_LOG_ERROR, "reget_buffer() failed\n");
            return VAR_4;
        s->picture.pict_type = AV_PICTURE_TYPE_P;
        s->picture.key_frame = 0;
    VAR_4 = gif_parse_next_image(s, VAR_2);
    if (VAR_4 < 0)
        return VAR_4;
    else if (*VAR_2)
        *picture = s->picture;
    return VAR_3->size;
static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1, int *VAR_2, AVPacket *VAR_3)
{ GifState *s = VAR_0->priv_data; AVFrame *picture = VAR_1; int VAR_4; bytestream2_init(&s->gb, VAR_3->VAR_1, VAR_3->size); s->picture.pts          = VAR_3->pts; s->picture.pkt_pts      = VAR_3->pts; s->picture.pkt_dts      = VAR_3->dts; s->picture.pkt_duration = VAR_3->duration; if (VAR_3->size >= 6) { s->keyframe = memcmp(VAR_3->VAR_1, gif87a_sig, 6) == 0 ||
memcmp(VAR_3->VAR_1, gif89a_sig, 6) == 0; } else { s->keyframe = 0; if (s->keyframe) { s->keyframe_ok = 0; if ((VAR_4 = gif_read_header1(s)) < 0)
return VAR_4; if ((VAR_4 = av_image_check_size(s->screen_width, s->screen_height, 0, VAR_0)) < 0)
return VAR_4; avcodec_set_dimensions(VAR_0, s->screen_width, s->screen_height); if (s->picture.VAR_1[0])
VAR_0->release_buffer(VAR_0, &s->picture); if ((VAR_4 = ff_get_buffer(VAR_0, &s->picture)) < 0) { av_log(VAR_0, AV_LOG_ERROR, "get_buffer() failed\n"); return VAR_4; s->picture.pict_type = AV_PICTURE_TYPE_I; s->picture.key_frame = 1; } else { if ((VAR_4 = VAR_0->reget_buffer(VAR_0, &s->picture)) < 0) { av_log(VAR_0, AV_LOG_ERROR, "reget_buffer() failed\n"); return VAR_4; s->picture.pict_type = AV_PICTURE_TYPE_P; s->picture.key_frame = 0; VAR_4 = gif_parse_next_image(s, VAR_2); if (VAR_4 < 0)
return VAR_4; else if (*VAR_2)
*picture = s->picture; return VAR_3->size;