int ff_h264_decode_ref_pic_marking(H264Context *h, GetBitContext *gb,

                                   int first_slice)

{

    MpegEncContext * const s = &h->s;

    int i, ret;

    MMCO mmco_temp[MAX_MMCO_COUNT], *mmco = first_slice ? h->mmco : mmco_temp;

    int mmco_index = 0;



    if (h->nal_unit_type == NAL_IDR_SLICE){ // FIXME fields

        s->broken_link = get_bits1(gb) - 1;

        if (get_bits1(gb)){

            mmco[0].opcode = MMCO_LONG;

            mmco[0].long_arg = 0;

            mmco_index = 1;

        }

    } else {

        if (get_bits1(gb)) { // adaptive_ref_pic_marking_mode_flag

            for (i = 0; i < MAX_MMCO_COUNT; i++) {

                MMCOOpcode opcode = get_ue_golomb_31(gb);



                mmco[i].opcode = opcode;

                if (opcode == MMCO_SHORT2UNUSED || opcode == MMCO_SHORT2LONG){

                    mmco[i].short_pic_num =

                        (h->curr_pic_num - get_ue_golomb(gb) - 1) &

                            (h->max_pic_num - 1);

#if 0

                    if (mmco[i].short_pic_num >= h->short_ref_count ||

                        h->short_ref[ mmco[i].short_pic_num ] == NULL){

                        av_log(s->avctx, AV_LOG_ERROR,

                               "illegal short ref in memory management control "

                               "operation %d\n", mmco);

                        return -1;

                    }

#endif

                }

                if (opcode == MMCO_SHORT2LONG || opcode == MMCO_LONG2UNUSED ||

                    opcode == MMCO_LONG || opcode == MMCO_SET_MAX_LONG) {

                    unsigned int long_arg = get_ue_golomb_31(gb);

                    if (long_arg >= 32 ||

                        (long_arg >= 16 && !(opcode == MMCO_SET_MAX_LONG &&

                                             long_arg == 16) &&

                         !(opcode == MMCO_LONG2UNUSED && FIELD_PICTURE))){

                        av_log(h->s.avctx, AV_LOG_ERROR,

                               "illegal long ref in memory management control "

                               "operation %d\n", opcode);

                        return -1;

                    }

                    mmco[i].long_arg = long_arg;

                }



                if (opcode > (unsigned) MMCO_LONG){

                    av_log(h->s.avctx, AV_LOG_ERROR,

                           "illegal memory management control operation %d\n",

                           opcode);

                    return -1;

                }

                if (opcode == MMCO_END)

                    break;

            }

            mmco_index = i;

        } else {

            if (first_slice) {

                ret = ff_generate_sliding_window_mmcos(h, first_slice);

                if (ret < 0 && s->avctx->err_recognition & AV_EF_EXPLODE)

                    return ret;

            }

            mmco_index = -1;

        }

    }



    if (first_slice && mmco_index != -1) {

        h->mmco_index = mmco_index;

    } else if (!first_slice && mmco_index >= 0 &&

               (mmco_index != h->mmco_index ||

                (i = check_opcodes(h->mmco, mmco_temp, mmco_index)))) {

        av_log(h->s.avctx, AV_LOG_ERROR,

               "Inconsistent MMCO state between slices [%d, %d, %d]\n",

               mmco_index, h->mmco_index, i);

        return AVERROR_INVALIDDATA;

    }



    return 0;

}

int ff_h264_decode_ref_pic_marking(H264Context *h, GetBitContext *gb,

                                   int first_slice)

{

    MpegEncContext * const s = &h->s;

    int i, ret;

    MMCO mmco_temp[MAX_MMCO_COUNT], *mmco = first_slice ? h->mmco : mmco_temp;

    int mmco_index = 0;



    if (h->nal_unit_type == NAL_IDR_SLICE){ 

        s->broken_link = get_bits1(gb) - 1;

        if (get_bits1(gb)){

            mmco[0].opcode = MMCO_LONG;

            mmco[0].long_arg = 0;

            mmco_index = 1;

        }

    } else {

        if (get_bits1(gb)) { 

            for (i = 0; i < MAX_MMCO_COUNT; i++) {

                MMCOOpcode opcode = get_ue_golomb_31(gb);



                mmco[i].opcode = opcode;

                if (opcode == MMCO_SHORT2UNUSED || opcode == MMCO_SHORT2LONG){

                    mmco[i].short_pic_num =

                        (h->curr_pic_num - get_ue_golomb(gb) - 1) &

                            (h->max_pic_num - 1);

#if 0

                    if (mmco[i].short_pic_num >= h->short_ref_count ||

                        h->short_ref[ mmco[i].short_pic_num ] == NULL){

                        av_log(s->avctx, AV_LOG_ERROR,

                               "illegal short ref in memory management control "

                               "operation %d\n", mmco);

                        return -1;

                    }

#endif

                }

                if (opcode == MMCO_SHORT2LONG || opcode == MMCO_LONG2UNUSED ||

                    opcode == MMCO_LONG || opcode == MMCO_SET_MAX_LONG) {

                    unsigned int long_arg = get_ue_golomb_31(gb);

                    if (long_arg >= 32 ||

                        (long_arg >= 16 && !(opcode == MMCO_SET_MAX_LONG &&

                                             long_arg == 16) &&

                         !(opcode == MMCO_LONG2UNUSED && FIELD_PICTURE))){

                        av_log(h->s.avctx, AV_LOG_ERROR,

                               "illegal long ref in memory management control "

                               "operation %d\n", opcode);

                        return -1;

                    }

                    mmco[i].long_arg = long_arg;

                }



                if (opcode > (unsigned) MMCO_LONG){

                    av_log(h->s.avctx, AV_LOG_ERROR,

                           "illegal memory management control operation %d\n",

                           opcode);

                    return -1;

                }

                if (opcode == MMCO_END)

                    break;

            }

            mmco_index = i;

        } else {

            if (first_slice) {

                ret = ff_generate_sliding_window_mmcos(h, first_slice);

                if (ret < 0 && s->avctx->err_recognition & AV_EF_EXPLODE)

                    return ret;

            }

            mmco_index = -1;

        }

    }



    if (first_slice && mmco_index != -1) {

        h->mmco_index = mmco_index;

    } else if (!first_slice && mmco_index >= 0 &&

               (mmco_index != h->mmco_index ||

                (i = check_opcodes(h->mmco, mmco_temp, mmco_index)))) {

        av_log(h->s.avctx, AV_LOG_ERROR,

               "Inconsistent MMCO state between slices [%d, %d, %d]\n",

               mmco_index, h->mmco_index, i);

        return AVERROR_INVALIDDATA;

    }



    return 0;

}

               "Inconsistent MMCO state between slices [%d, %d, %d]\n",                mmco_index, h->mmco_index, i);
int FUNC_0(H264Context *VAR_0, GetBitContext *VAR_1,

                                   int VAR_2)

{

    MpegEncContext * const s = &VAR_0->s;

    int VAR_3, VAR_4;

    MMCO mmco_temp[MAX_MMCO_COUNT], *mmco = VAR_2 ? VAR_0->mmco : mmco_temp;

    int VAR_5 = 0;



    if (VAR_0->nal_unit_type == NAL_IDR_SLICE){ 

        s->broken_link = get_bits1(VAR_1) - 1;

        if (get_bits1(VAR_1)){

            mmco[0].opcode = MMCO_LONG;

            mmco[0].long_arg = 0;

            VAR_5 = 1;

        }

    } else {

        if (get_bits1(VAR_1)) { 

            for (VAR_3 = 0; VAR_3 < MAX_MMCO_COUNT; VAR_3++) {

                MMCOOpcode opcode = get_ue_golomb_31(VAR_1);



                mmco[VAR_3].opcode = opcode;

                if (opcode == MMCO_SHORT2UNUSED || opcode == MMCO_SHORT2LONG){

                    mmco[VAR_3].short_pic_num =

                        (VAR_0->curr_pic_num - get_ue_golomb(VAR_1) - 1) &

                            (VAR_0->max_pic_num - 1);

#if 0

                    if (mmco[VAR_3].short_pic_num >= VAR_0->short_ref_count ||

                        VAR_0->short_ref[ mmco[VAR_3].short_pic_num ] == NULL){

                        av_log(s->avctx, AV_LOG_ERROR,

                               "illegal short ref in memory management control "

                               "operation %d\n", mmco);

                        return -1;

                    }

#endif

                }

                if (opcode == MMCO_SHORT2LONG || opcode == MMCO_LONG2UNUSED ||

                    opcode == MMCO_LONG || opcode == MMCO_SET_MAX_LONG) {

                    unsigned int long_arg = get_ue_golomb_31(VAR_1);

                    if (long_arg >= 32 ||

                        (long_arg >= 16 && !(opcode == MMCO_SET_MAX_LONG &&

                                             long_arg == 16) &&

                         !(opcode == MMCO_LONG2UNUSED && FIELD_PICTURE))){

                        av_log(VAR_0->s.avctx, AV_LOG_ERROR,

                               "illegal long ref in memory management control "

                               "operation %d\n", opcode);

                        return -1;

                    }

                    mmco[VAR_3].long_arg = long_arg;

                }



                if (opcode > (unsigned) MMCO_LONG){

                    av_log(VAR_0->s.avctx, AV_LOG_ERROR,

                           "illegal memory management control operation %d\n",

                           opcode);

                    return -1;

                }

                if (opcode == MMCO_END)

                    break;

            }

            VAR_5 = VAR_3;

        } else {

            if (VAR_2) {

                VAR_4 = ff_generate_sliding_window_mmcos(VAR_0, VAR_2);

                if (VAR_4 < 0 && s->avctx->err_recognition & AV_EF_EXPLODE)

                    return VAR_4;

            }

            VAR_5 = -1;

        }

    }



    if (VAR_2 && VAR_5 != -1) {

        VAR_0->VAR_5 = VAR_5;

    } else if (!VAR_2 && VAR_5 >= 0 &&

               (VAR_5 != VAR_0->VAR_5 ||

                (VAR_3 = check_opcodes(VAR_0->mmco, mmco_temp, VAR_5)))) {

        av_log(VAR_0->s.avctx, AV_LOG_ERROR,

               "Inconsistent MMCO state between slices [%d, %d, %d]\n",

               VAR_5, VAR_0->VAR_5, VAR_3);

        return AVERROR_INVALIDDATA;

    }



    return 0;

}

int FUNC_0(H264Context *VAR_0, GetBitContext *VAR_1,
int VAR_2)
{ MpegEncContext * const s = &VAR_0->s; int VAR_3, VAR_4; MMCO mmco_temp[MAX_MMCO_COUNT], *mmco = VAR_2 ? VAR_0->mmco : mmco_temp; int VAR_5 = 0; if (VAR_0->nal_unit_type == NAL_IDR_SLICE){ s->broken_link = get_bits1(VAR_1) - 1; if (get_bits1(VAR_1)){ mmco[0].opcode = MMCO_LONG; mmco[0].long_arg = 0; VAR_5 = 1; } } else { if (get_bits1(VAR_1)) { for (VAR_3 = 0; VAR_3 < MAX_MMCO_COUNT; VAR_3++) { MMCOOpcode opcode = get_ue_golomb_31(VAR_1); mmco[VAR_3].opcode = opcode; if (opcode == MMCO_SHORT2UNUSED || opcode == MMCO_SHORT2LONG){ mmco[VAR_3].short_pic_num =
(VAR_0->curr_pic_num - get_ue_golomb(VAR_1) - 1) &
(VAR_0->max_pic_num - 1); #if 0
if (mmco[VAR_3].short_pic_num >= VAR_0->short_ref_count ||
VAR_0->short_ref[ mmco[VAR_3].short_pic_num ] == NULL){ av_log(s->avctx, AV_LOG_ERROR,
"illegal short ref in memory management control "
"operation %d\n", mmco); return -1; } #endif
} if (opcode == MMCO_SHORT2LONG || opcode == MMCO_LONG2UNUSED ||
opcode == MMCO_LONG || opcode == MMCO_SET_MAX_LONG) { unsigned int long_arg = get_ue_golomb_31(VAR_1); if (long_arg >= 32 ||
(long_arg >= 16 && !(opcode == MMCO_SET_MAX_LONG &&
long_arg == 16) &&
!(opcode == MMCO_LONG2UNUSED && FIELD_PICTURE))){ av_log(VAR_0->s.avctx, AV_LOG_ERROR,
"illegal long ref in memory management control "
"operation %d\n", opcode); return -1; } mmco[VAR_3].long_arg = long_arg; } if (opcode > (unsigned) MMCO_LONG){ av_log(VAR_0->s.avctx, AV_LOG_ERROR,
"illegal memory management control operation %d\n",
opcode); return -1; } if (opcode == MMCO_END)
break; } VAR_5 = VAR_3; } else { if (VAR_2) { VAR_4 = ff_generate_sliding_window_mmcos(VAR_0, VAR_2); if (VAR_4 < 0 && s->avctx->err_recognition & AV_EF_EXPLODE)
return VAR_4; } VAR_5 = -1; } } if (VAR_2 && VAR_5 != -1) { VAR_0->VAR_5 = VAR_5; } else if (!VAR_2 && VAR_5 >= 0 && (VAR_5 != VAR_0->VAR_5 ||
(VAR_3 = check_opcodes(VAR_0->mmco, mmco_temp, VAR_5)))) { av_log(VAR_0->s.avctx, AV_LOG_ERROR,
"Inconsistent MMCO state between slices [%d, %d, %d]\n",
VAR_5, VAR_0->VAR_5, VAR_3); return AVERROR_INVALIDDATA; } return 0; }