static void execute_decode_slices(H264Context *h, int context_count){
    MpegEncContext * const s = &h->s;
    AVCodecContext * const avctx= s->avctx;
    H264Context *hx;
    int i;
    if(context_count == 1) {
        decode_slice(avctx, h);
    } else {
        for(i = 1; i < context_count; i++) {
            hx = h->thread_context[i];
            hx->s.error_resilience = avctx->error_resilience;
            hx->s.error_count = 0;
        }
        avctx->execute(avctx, (void *)decode_slice,
                       (void **)h->thread_context, NULL, context_count);
        hx = h->thread_context[context_count - 1];
        s->mb_x = hx->s.mb_x;
        s->mb_y = hx->s.mb_y;
        s->dropable = hx->s.dropable;
        s->picture_structure = hx->s.picture_structure;
        for(i = 1; i < context_count; i++)
            h->s.error_count += h->thread_context[i]->s.error_count;
    }
}
['static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){\n    MpegEncContext * const s = &h->s;\n    AVCodecContext * const avctx= s->avctx;\n    int buf_index=0;\n    H264Context *hx;\n    int context_count = 0;\n    h->max_contexts = avctx->thread_count;\n#if 0\n    int i;\n    for(i=0; i<50; i++){\n        av_log(NULL, AV_LOG_ERROR,"%02X ", buf[i]);\n    }\n#endif\n    if(!(s->flags2 & CODEC_FLAG2_CHUNKS)){\n        h->current_slice = 0;\n        if (!s->first_field)\n            s->current_picture_ptr= NULL;\n    }\n    for(;;){\n        int consumed;\n        int dst_length;\n        int bit_length;\n        const uint8_t *ptr;\n        int i, nalsize = 0;\n        int err;\n        if(h->is_avc) {\n            if(buf_index >= buf_size) break;\n            nalsize = 0;\n            for(i = 0; i < h->nal_length_size; i++)\n                nalsize = (nalsize << 8) | buf[buf_index++];\n            if(nalsize <= 1 || (nalsize+buf_index > buf_size)){\n                if(nalsize == 1){\n                    buf_index++;\n                    continue;\n                }else{\n                    av_log(h->s.avctx, AV_LOG_ERROR, "AVC: nal size %d\\n", nalsize);\n                    break;\n                }\n            }\n        } else {\n            for(; buf_index + 3 < buf_size; buf_index++){\n                if(buf[buf_index] == 0 && buf[buf_index+1] == 0 && buf[buf_index+2] == 1)\n                    break;\n            }\n            if(buf_index+3 >= buf_size) break;\n            buf_index+=3;\n        }\n        hx = h->thread_context[context_count];\n        ptr= decode_nal(hx, buf + buf_index, &dst_length, &consumed, h->is_avc ? nalsize : buf_size - buf_index);\n        if (ptr==NULL || dst_length < 0){\n            return -1;\n        }\n        while(ptr[dst_length - 1] == 0 && dst_length > 0)\n            dst_length--;\n        bit_length= !dst_length ? 0 : (8*dst_length - decode_rbsp_trailing(h, ptr + dst_length - 1));\n        if(s->avctx->debug&FF_DEBUG_STARTCODE){\n            av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d at %d/%d length %d\\n", hx->nal_unit_type, buf_index, buf_size, dst_length);\n        }\n        if (h->is_avc && (nalsize != consumed)){\n            av_log(h->s.avctx, AV_LOG_ERROR, "AVC: Consumed only %d bytes instead of %d\\n", consumed, nalsize);\n            consumed= nalsize;\n        }\n        buf_index += consumed;\n        if(  (s->hurry_up == 1 && h->nal_ref_idc  == 0)\n           ||(avctx->skip_frame >= AVDISCARD_NONREF && h->nal_ref_idc  == 0))\n            continue;\n      again:\n        err = 0;\n        switch(hx->nal_unit_type){\n        case NAL_IDR_SLICE:\n            if (h->nal_unit_type != NAL_IDR_SLICE) {\n                av_log(h->s.avctx, AV_LOG_ERROR, "Invalid mix of idr and non-idr slices");\n                return -1;\n            }\n            idr(h);\n        case NAL_SLICE:\n            init_get_bits(&hx->s.gb, ptr, bit_length);\n            hx->intra_gb_ptr=\n            hx->inter_gb_ptr= &hx->s.gb;\n            hx->s.data_partitioning = 0;\n            if((err = decode_slice_header(hx, h)))\n               break;\n            s->current_picture_ptr->key_frame|= (hx->nal_unit_type == NAL_IDR_SLICE);\n            if(hx->redundant_pic_count==0 && hx->s.hurry_up < 5\n               && (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc)\n               && (avctx->skip_frame < AVDISCARD_BIDIR  || hx->slice_type!=FF_B_TYPE)\n               && (avctx->skip_frame < AVDISCARD_NONKEY || hx->slice_type==FF_I_TYPE)\n               && avctx->skip_frame < AVDISCARD_ALL)\n                context_count++;\n            break;\n        case NAL_DPA:\n            init_get_bits(&hx->s.gb, ptr, bit_length);\n            hx->intra_gb_ptr=\n            hx->inter_gb_ptr= NULL;\n            hx->s.data_partitioning = 1;\n            err = decode_slice_header(hx, h);\n            break;\n        case NAL_DPB:\n            init_get_bits(&hx->intra_gb, ptr, bit_length);\n            hx->intra_gb_ptr= &hx->intra_gb;\n            break;\n        case NAL_DPC:\n            init_get_bits(&hx->inter_gb, ptr, bit_length);\n            hx->inter_gb_ptr= &hx->inter_gb;\n            if(hx->redundant_pic_count==0 && hx->intra_gb_ptr && hx->s.data_partitioning\n               && s->context_initialized\n               && s->hurry_up < 5\n               && (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc)\n               && (avctx->skip_frame < AVDISCARD_BIDIR  || hx->slice_type!=FF_B_TYPE)\n               && (avctx->skip_frame < AVDISCARD_NONKEY || hx->slice_type==FF_I_TYPE)\n               && avctx->skip_frame < AVDISCARD_ALL)\n                context_count++;\n            break;\n        case NAL_SEI:\n            init_get_bits(&s->gb, ptr, bit_length);\n            decode_sei(h);\n            break;\n        case NAL_SPS:\n            init_get_bits(&s->gb, ptr, bit_length);\n            decode_seq_parameter_set(h);\n            if(s->flags& CODEC_FLAG_LOW_DELAY)\n                s->low_delay=1;\n            if(avctx->has_b_frames < 2)\n                avctx->has_b_frames= !s->low_delay;\n            break;\n        case NAL_PPS:\n            init_get_bits(&s->gb, ptr, bit_length);\n            decode_picture_parameter_set(h, bit_length);\n            break;\n        case NAL_AUD:\n        case NAL_END_SEQUENCE:\n        case NAL_END_STREAM:\n        case NAL_FILLER_DATA:\n        case NAL_SPS_EXT:\n        case NAL_AUXILIARY_SLICE:\n            break;\n        default:\n            av_log(avctx, AV_LOG_DEBUG, "Unknown NAL code: %d (%d bits)\\n", h->nal_unit_type, bit_length);\n        }\n        if(context_count == h->max_contexts) {\n            execute_decode_slices(h, context_count);\n            context_count = 0;\n        }\n        if (err < 0)\n            av_log(h->s.avctx, AV_LOG_ERROR, "decode_slice_header error\\n");\n        else if(err == 1) {\n            h->nal_unit_type = hx->nal_unit_type;\n            h->nal_ref_idc   = hx->nal_ref_idc;\n            hx = h;\n            goto again;\n        }\n    }\n    if(context_count)\n        execute_decode_slices(h, context_count);\n    return buf_index;\n}', 'static void execute_decode_slices(H264Context *h, int context_count){\n    MpegEncContext * const s = &h->s;\n    AVCodecContext * const avctx= s->avctx;\n    H264Context *hx;\n    int i;\n    if(context_count == 1) {\n        decode_slice(avctx, h);\n    } else {\n        for(i = 1; i < context_count; i++) {\n            hx = h->thread_context[i];\n            hx->s.error_resilience = avctx->error_resilience;\n            hx->s.error_count = 0;\n        }\n        avctx->execute(avctx, (void *)decode_slice,\n                       (void **)h->thread_context, NULL, context_count);\n        hx = h->thread_context[context_count - 1];\n        s->mb_x = hx->s.mb_x;\n        s->mb_y = hx->s.mb_y;\n        s->dropable = hx->s.dropable;\n        s->picture_structure = hx->s.picture_structure;\n        for(i = 1; i < context_count; i++)\n            h->s.error_count += h->thread_context[i]->s.error_count;\n    }\n}']