static int h261_decode_frame(AVCodecContext *avctx, void *data,

                             int *got_frame, AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size       = avpkt->size;

    H261Context *h     = avctx->priv_data;

    MpegEncContext *s  = &h->s;

    int ret;

    AVFrame *pict = data;



    av_dlog(avctx, "*****frame %d size=%d\n", avctx->frame_number, buf_size);

    av_dlog(avctx, "bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]);

    s->flags  = avctx->flags;

    s->flags2 = avctx->flags2;



    h->gob_start_code_skipped = 0;



retry:

    init_get_bits(&s->gb, buf, buf_size * 8);



    if (!s->context_initialized)

        // we need the IDCT permutaton for reading a custom matrix

        if (ff_MPV_common_init(s) < 0)

            return -1;



    ret = h261_decode_picture_header(h);



    /* skip if the header was thrashed */

    if (ret < 0) {

        av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");

        return -1;

    }



    if (s->width != avctx->coded_width || s->height != avctx->coded_height) {

        ParseContext pc = s->parse_context; // FIXME move this demuxing hack to libavformat

        s->parse_context.buffer = 0;

        ff_MPV_common_end(s);

        s->parse_context = pc;

    }

    if (!s->context_initialized) {

        ret = ff_set_dimensions(avctx, s->width, s->height);

        if (ret < 0)

            return ret;



        goto retry;

    }



    // for skipping the frame

    s->current_picture.f.pict_type = s->pict_type;

    s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I;



    if ((avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) ||

        (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I) ||

         avctx->skip_frame >= AVDISCARD_ALL)

        return get_consumed_bytes(s, buf_size);



    if (ff_MPV_frame_start(s, avctx) < 0)

        return -1;



    ff_mpeg_er_frame_start(s);



    /* decode each macroblock */

    s->mb_x = 0;

    s->mb_y = 0;



    while (h->gob_number < (s->mb_height == 18 ? 12 : 5)) {

        if (h261_resync(h) < 0)

            break;

        h261_decode_gob(h);

    }

    ff_MPV_frame_end(s);



    assert(s->current_picture.f.pict_type == s->current_picture_ptr->f.pict_type);

    assert(s->current_picture.f.pict_type == s->pict_type);



    if ((ret = av_frame_ref(pict, &s->current_picture_ptr->f)) < 0)

        return ret;

    ff_print_debug_info(s, s->current_picture_ptr);



    *got_frame = 1;



    return get_consumed_bytes(s, buf_size);

}

static int h261_decode_frame(AVCodecContext *avctx, void *data,

                             int *got_frame, AVPacket *avpkt)

{

    const uint8_t *buf = avpkt->data;

    int buf_size       = avpkt->size;

    H261Context *h     = avctx->priv_data;

    MpegEncContext *s  = &h->s;

    int ret;

    AVFrame *pict = data;



    av_dlog(avctx, "*****frame %d size=%d\n", avctx->frame_number, buf_size);

    av_dlog(avctx, "bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]);

    s->flags  = avctx->flags;

    s->flags2 = avctx->flags2;



    h->gob_start_code_skipped = 0;



retry:

    init_get_bits(&s->gb, buf, buf_size * 8);



    if (!s->context_initialized)

        

        if (ff_MPV_common_init(s) < 0)

            return -1;



    ret = h261_decode_picture_header(h);



    

    if (ret < 0) {

        av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");

        return -1;

    }



    if (s->width != avctx->coded_width || s->height != avctx->coded_height) {

        ParseContext pc = s->parse_context; 

        s->parse_context.buffer = 0;

        ff_MPV_common_end(s);

        s->parse_context = pc;

    }

    if (!s->context_initialized) {

        ret = ff_set_dimensions(avctx, s->width, s->height);

        if (ret < 0)

            return ret;



        goto retry;

    }



    

    s->current_picture.f.pict_type = s->pict_type;

    s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I;



    if ((avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) ||

        (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I) ||

         avctx->skip_frame >= AVDISCARD_ALL)

        return get_consumed_bytes(s, buf_size);



    if (ff_MPV_frame_start(s, avctx) < 0)

        return -1;



    ff_mpeg_er_frame_start(s);



    

    s->mb_x = 0;

    s->mb_y = 0;



    while (h->gob_number < (s->mb_height == 18 ? 12 : 5)) {

        if (h261_resync(h) < 0)

            break;

        h261_decode_gob(h);

    }

    ff_MPV_frame_end(s);



    assert(s->current_picture.f.pict_type == s->current_picture_ptr->f.pict_type);

    assert(s->current_picture.f.pict_type == s->pict_type);



    if ((ret = av_frame_ref(pict, &s->current_picture_ptr->f)) < 0)

        return ret;

    ff_print_debug_info(s, s->current_picture_ptr);



    *got_frame = 1;



    return get_consumed_bytes(s, buf_size);

}

    s->current_picture.f.pict_type = s->pict_type;     s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I;     assert(s->current_picture.f.pict_type == s->current_picture_ptr->f.pict_type);     assert(s->current_picture.f.pict_type == s->pict_type);     if ((ret = av_frame_ref(pict, &s->current_picture_ptr->f)) < 0)     s->current_picture.f.pict_type = s->pict_type;     s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I;     assert(s->current_picture.f.pict_type == s->pict_type);     s->current_picture.f.pict_type = s->pict_type;     s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I;     s->current_picture.f.pict_type = s->pict_type;     s->current_picture.f.pict_type = s->pict_type;     s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I;
static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1,

                             int *VAR_2, AVPacket *VAR_3)

{

    const uint8_t *VAR_4 = VAR_3->VAR_1;

    int VAR_5       = VAR_3->size;

    H261Context *h     = VAR_0->priv_data;

    MpegEncContext *s  = &h->s;

    int VAR_6;

    AVFrame *pict = VAR_1;



    av_dlog(VAR_0, "*****frame %d size=%d\n", VAR_0->frame_number, VAR_5);

    av_dlog(VAR_0, "bytes=%x %x %x %x\n", VAR_4[0], VAR_4[1], VAR_4[2], VAR_4[3]);

    s->flags  = VAR_0->flags;

    s->flags2 = VAR_0->flags2;



    h->gob_start_code_skipped = 0;



retry:

    init_get_bits(&s->gb, VAR_4, VAR_5 * 8);



    if (!s->context_initialized)

        

        if (ff_MPV_common_init(s) < 0)

            return -1;



    VAR_6 = h261_decode_picture_header(h);



    

    if (VAR_6 < 0) {

        av_log(s->VAR_0, AV_LOG_ERROR, "header damaged\n");

        return -1;

    }



    if (s->width != VAR_0->coded_width || s->height != VAR_0->coded_height) {

        ParseContext pc = s->parse_context; 

        s->parse_context.buffer = 0;

        ff_MPV_common_end(s);

        s->parse_context = pc;

    }

    if (!s->context_initialized) {

        VAR_6 = ff_set_dimensions(VAR_0, s->width, s->height);

        if (VAR_6 < 0)

            return VAR_6;



        goto retry;

    }



    

    s->current_picture.f.pict_type = s->pict_type;

    s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I;



    if ((VAR_0->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) ||

        (VAR_0->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I) ||

         VAR_0->skip_frame >= AVDISCARD_ALL)

        return get_consumed_bytes(s, VAR_5);



    if (ff_MPV_frame_start(s, VAR_0) < 0)

        return -1;



    ff_mpeg_er_frame_start(s);



    

    s->mb_x = 0;

    s->mb_y = 0;



    while (h->gob_number < (s->mb_height == 18 ? 12 : 5)) {

        if (h261_resync(h) < 0)

            break;

        h261_decode_gob(h);

    }

    ff_MPV_frame_end(s);



    assert(s->current_picture.f.pict_type == s->current_picture_ptr->f.pict_type);

    assert(s->current_picture.f.pict_type == s->pict_type);



    if ((VAR_6 = av_frame_ref(pict, &s->current_picture_ptr->f)) < 0)

        return VAR_6;

    ff_print_debug_info(s, s->current_picture_ptr);



    *VAR_2 = 1;



    return get_consumed_bytes(s, VAR_5);

}

static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1,
int *VAR_2, AVPacket *VAR_3)
{ const uint8_t *VAR_4 = VAR_3->VAR_1; int VAR_5       = VAR_3->size; H261Context *h     = VAR_0->priv_data; MpegEncContext *s  = &h->s; int VAR_6; AVFrame *pict = VAR_1; av_dlog(VAR_0, "*****frame %d size=%d\n", VAR_0->frame_number, VAR_5); av_dlog(VAR_0, "bytes=%x %x %x %x\n", VAR_4[0], VAR_4[1], VAR_4[2], VAR_4[3]); s->flags  = VAR_0->flags; s->flags2 = VAR_0->flags2; h->gob_start_code_skipped = 0; retry:
init_get_bits(&s->gb, VAR_4, VAR_5 * 8); if (!s->context_initialized)
if (ff_MPV_common_init(s) < 0)
return -1; VAR_6 = h261_decode_picture_header(h); if (VAR_6 < 0) { av_log(s->VAR_0, AV_LOG_ERROR, "header damaged\n"); return -1; } if (s->width != VAR_0->coded_width || s->height != VAR_0->coded_height) { ParseContext pc = s->parse_context; s->parse_context.buffer = 0; ff_MPV_common_end(s); s->parse_context = pc; } if (!s->context_initialized) { VAR_6 = ff_set_dimensions(VAR_0, s->width, s->height); if (VAR_6 < 0)
return VAR_6; goto retry; } s->current_picture.f.pict_type = s->pict_type; s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I; if ((VAR_0->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) ||
(VAR_0->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I) ||
VAR_0->skip_frame >= AVDISCARD_ALL)
return get_consumed_bytes(s, VAR_5); if (ff_MPV_frame_start(s, VAR_0) < 0)
return -1; ff_mpeg_er_frame_start(s); s->mb_x = 0; s->mb_y = 0; while (h->gob_number < (s->mb_height == 18 ? 12 : 5)) { if (h261_resync(h) < 0)
break; h261_decode_gob(h); } ff_MPV_frame_end(s); assert(s->current_picture.f.pict_type == s->current_picture_ptr->f.pict_type); assert(s->current_picture.f.pict_type == s->pict_type); if ((VAR_6 = av_frame_ref(pict, &s->current_picture_ptr->f)) < 0)
return VAR_6; ff_print_debug_info(s, s->current_picture_ptr); *VAR_2 = 1; return get_consumed_bytes(s, VAR_5); }