libavcodec/h264.c:3857: error: Integer Overflow L2
  ([0, +oo] - 1):unsigned32 by call to `decode_slice_header`.

libavcodec/h264.c:3733:1: Parameter `h->s.list_count`
3731. 
3732. 
3733. static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){
      ^
3734.     MpegEncContext * const s = &h->s;
3735.     AVCodecContext * const avctx= s->avctx;

libavcodec/h264.c:3857:23: Call
3855.             hx->s.data_partitioning = 0;
3856. 
3857.             if((err = decode_slice_header(hx, h)))
                            ^
3858.                break;
3859. 

libavcodec/h264.c:2635:1: Parameter `h->s.list_count`
  2633.  * @return 0 if okay, <0 if an error occurred, 1 if decoding must not be multithreaded
  2634.  */
  2635. static int decode_slice_header(H264Context *h, H264Context *h0){
        ^
  2636.     MpegEncContext * const s = &h->s;
  2637.     MpegEncContext * const s0 = &h0->s;

libavcodec/h264.c:2660:13: Call
  2658.     if(first_mb_in_slice == 0){ //FIXME better field boundary detection
  2659.         if(h0->current_slice && FIELD_PICTURE){
  2660.             field_end(h, 1);
                    ^
  2661.         }
  2662. 

libavcodec/h264.c:2518:1: Parameter `h->s.list_count`
    2516. }
    2517. 
    2518. static int field_end(H264Context *h, int in_setup){
          ^
    2519.     MpegEncContext * const s = &h->s;
    2520.     AVCodecContext * const avctx= s->avctx;

libavcodec/h264.c:2563:9: Call
    2561.      */
    2562.     if (!FIELD_PICTURE)
    2563.         ff_er_frame_end(s);
                  ^
    2564. 
    2565.     MPV_frame_end(s);

libavcodec/error_resilience.c:872:1: Parameter `s->list_count`
      870. }
      871. 
      872. void ff_er_frame_end(MpegEncContext *s)
           ^
      873. {
      874.     int i, mb_x, mb_y, error, error_type, dc_error, mv_error, ac_error;

libavcodec/error_resilience.c:1050:23: Call
      1048.            dc_error, ac_error, mv_error);
      1049. 
      1050.     is_intra_likely = is_intra_more_likely(s);
                                  ^
      1051. 
      1052.     /* set unknown mb-type to most likely */

libavcodec/error_resilience.c:708:1: Parameter `s->list_count`
        706. }
        707. 
        708. static int is_intra_more_likely(MpegEncContext *s)
             ^
        709. {
        710.     int is_intra_likely, i, j, undamaged_count, skip_amount, mb_x, mb_y;

libavcodec/error_resilience.c:1110:13: Call
      1108.             s->mb_x = mb_x;
      1109.             s->mb_y = mb_y;
      1110.             decode_mb(s, 0 /* FIXME h264 partitioned slices need this set */);
                        ^
      1111.         }
      1112.     }

libavcodec/error_resilience.c:43:1: Parameter `s->list_count`
        41. #undef mb_intra
        42. 
        43. static void decode_mb(MpegEncContext *s, int ref)
            ^
        44. {
        45.     s->dest[0] = s->current_picture.f.data[0] + (s->mb_y *  16                       * s->linesize)   + s->mb_x *  16;

libavcodec/error_resilience.c:66:9: Call
        64.                        pack16to32(s->mv[0][0][0], s->mv[0][0][1]), 4);
        65.         assert(!FRAME_MBAFF);
        66.         ff_h264_hl_decode_mb(h);
                    ^
        67.     } else {
        68.         assert(ref == 0);

libavcodec/h264.c:2226:1: Parameter `h->list_count`
          2224. }
          2225. 
          2226. void ff_h264_hl_decode_mb(H264Context *h){
                ^
          2227.     MpegEncContext * const s = &h->s;
          2228.     const int mb_xy= h->mb_xy;

libavcodec/h264.c:2234:13: Call
          2232.     if (CHROMA444) {
          2233.         if(is_complex || h->pixel_shift)
          2234.             hl_decode_mb_444_complex(h);
                            ^
          2235.         else
          2236.             hl_decode_mb_444_simple(h);

libavcodec/h264.c:2218:1: Parameter `h->list_count`
            2216. }
            2217. 
            2218. static void av_noinline hl_decode_mb_444_complex(H264Context *h){
                  ^
            2219.     hl_decode_mb_444_internal(h, 0, h->pixel_shift);
            2220. }

libavcodec/h264.c:2219:5: Call
            2217. 
            2218. static void av_noinline hl_decode_mb_444_complex(H264Context *h){
            2219.     hl_decode_mb_444_internal(h, 0, h->pixel_shift);
                      ^
            2220. }
            2221. 

libavcodec/h264.c:2105:1: Parameter `h->list_count`
              2103. }
              2104. 
              2105. static av_always_inline void hl_decode_mb_444_internal(H264Context *h, int simple, int pixel_shift){
                    ^
              2106.     MpegEncContext * const s = &h->s;
              2107.     const int mb_x= s->mb_x;

libavcodec/h264.c:2184:13: Call
              2182.                 xchg_mb_border(h, dest[0], dest[1], dest[2], linesize, linesize, 0, 1, simple, pixel_shift);
              2183.         }else{
              2184.             hl_motion(h, dest[0], dest[1], dest[2],
                                ^
              2185.                       s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab,
              2186.                       s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab,

libavcodec/h264.c:718:1: Parameter `h->list_count`
                716. }
                717. 
                718. static av_always_inline void hl_motion(H264Context *h, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
                     ^
                719.                       qpel_mc_func (*qpix_put)[16], h264_chroma_mc_func (*chroma_put),
                720.                       qpel_mc_func (*qpix_avg)[16], h264_chroma_mc_func (*chroma_avg),

libavcodec/h264.c:731:9: Call
                729. 
                730.     if(HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))
                731.         await_references(h);
                             ^
                732.     prefetch_motion(h, 0, pixel_shift, chroma_idc);
                733. 

libavcodec/h264.c:293:1: <LHS trace>
291.  * @param h the H264 context
292.  */
293. static void await_references(H264Context *h){
     ^
294.     MpegEncContext * const s = &h->s;
295.     const int mb_xy= h->mb_xy;

libavcodec/h264.c:293:1: Parameter `h->list_count`
                  291.  * @param h the H264 context
                  292.  */
                  293. static void await_references(H264Context *h){
                       ^
                  294.     MpegEncContext * const s = &h->s;
                  295.     const int mb_xy= h->mb_xy;

libavcodec/h264.c:351:9: Binary operation: ([0, +oo] - 1):unsigned32 by call to `decode_slice_header` 
                  349.     }
                  350. 
                  351.     for(list=h->list_count-1; list>=0; list--){
                               ^
                  352.         for(ref=0; ref<48 && nrefs[list]; ref++){
                  353.             int row = refs[list][ref];

static void await_references(H264Context *h){
    MpegEncContext * const s = &h->s;
    const int mb_xy= h->mb_xy;
    const int mb_type = s->current_picture.f.mb_type[mb_xy];
    int refs[2][48];
    int nrefs[2] = {0};
    int ref, list;
    memset(refs, -1, sizeof(refs));
    if(IS_16X16(mb_type)){
        get_lowest_part_y(h, refs, 0, 16, 0,
                  IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);
    }else if(IS_16X8(mb_type)){
        get_lowest_part_y(h, refs, 0, 8, 0,
                  IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);
        get_lowest_part_y(h, refs, 8, 8, 8,
                  IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs);
    }else if(IS_8X16(mb_type)){
        get_lowest_part_y(h, refs, 0, 16, 0,
                  IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);
        get_lowest_part_y(h, refs, 4, 16, 0,
                  IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs);
    }else{
        int i;
        assert(IS_8X8(mb_type));
        for(i=0; i<4; i++){
            const int sub_mb_type= h->sub_mb_type[i];
            const int n= 4*i;
            int y_offset= (i&2)<<2;
            if(IS_SUB_8X8(sub_mb_type)){
                get_lowest_part_y(h, refs, n  , 8, y_offset,
                          IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);
            }else if(IS_SUB_8X4(sub_mb_type)){
                get_lowest_part_y(h, refs, n  , 4, y_offset,
                          IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);
                get_lowest_part_y(h, refs, n+2, 4, y_offset+4,
                          IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);
            }else if(IS_SUB_4X8(sub_mb_type)){
                get_lowest_part_y(h, refs, n  , 8, y_offset,
                          IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);
                get_lowest_part_y(h, refs, n+1, 8, y_offset,
                          IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);
            }else{
                int j;
                assert(IS_SUB_4X4(sub_mb_type));
                for(j=0; j<4; j++){
                    int sub_y_offset= y_offset + 2*(j&2);
                    get_lowest_part_y(h, refs, n+j, 4, sub_y_offset,
                              IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);
                }
            }
        }
    }
    for(list=h->list_count-1; list>=0; list--){
        for(ref=0; ref<48 && nrefs[list]; ref++){
            int row = refs[list][ref];
            if(row >= 0){
                Picture *ref_pic = &h->ref_list[list][ref];
                int ref_field = ref_pic->f.reference - 1;
                int ref_field_picture = ref_pic->field_picture;
                int pic_height = 16*s->mb_height >> ref_field_picture;
                row <<= MB_MBAFF;
                nrefs[list]--;
                if(!FIELD_PICTURE && ref_field_picture){
                    ff_thread_await_progress((AVFrame*)ref_pic, FFMIN((row >> 1) - !(row&1), pic_height-1), 1);
                    ff_thread_await_progress((AVFrame*)ref_pic, FFMIN((row >> 1)           , pic_height-1), 0);
                }else if(FIELD_PICTURE && !ref_field_picture){
                    ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row*2 + ref_field    , pic_height-1), 0);
                }else if(FIELD_PICTURE){
                    ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), ref_field);
                }else{
                    ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), 0);
                }
            }
        }
    }
}
['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    H264Context *hx;\n    int buf_index;\n    int context_count;\n    int next_avc;\n    int pass = !(avctx->active_thread_type & FF_THREAD_FRAME);\n    int nals_needed=0;\n    int nal_index;\n    h->max_contexts = s->slice_context_count;\n    if(!(s->flags2 & CODEC_FLAG2_CHUNKS)){\n        h->current_slice = 0;\n        if (!s->first_field)\n            s->current_picture_ptr= NULL;\n        ff_h264_reset_sei(h);\n    }\n    for(;pass <= 1;pass++){\n        buf_index = 0;\n        context_count = 0;\n        next_avc = h->is_avc ? 0 : buf_size;\n        nal_index = 0;\n    for(;;){\n        int consumed;\n        int dst_length;\n        int bit_length;\n        uint8_t *ptr;\n        int i, nalsize = 0;\n        int err;\n        if(buf_index >= next_avc) {\n            if (buf_index >= buf_size - h->nal_length_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 <= 0 || nalsize > buf_size - buf_index){\n                av_log(h->s.avctx, AV_LOG_ERROR, "AVC: nal size %d\\n", nalsize);\n                break;\n            }\n            next_avc= buf_index + nalsize;\n        } else {\n            for(; buf_index + 3 < next_avc; 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            if(buf_index >= next_avc) continue;\n        }\n        hx = h->thread_context[context_count];\n        ptr= ff_h264_decode_nal(hx, buf + buf_index, &dst_length, &consumed, next_avc - buf_index);\n        if (ptr==NULL || dst_length < 0){\n            return -1;\n        }\n        i= buf_index + consumed;\n        if((s->workaround_bugs & FF_BUG_AUTODETECT) && i+3<next_avc &&\n           buf[i]==0x00 && buf[i+1]==0x00 && buf[i+2]==0x01 && buf[i+3]==0xE0)\n            s->workaround_bugs |= FF_BUG_TRUNCATED;\n        if(!(s->workaround_bugs & FF_BUG_TRUNCATED)){\n        while(ptr[dst_length - 1] == 0 && dst_length > 0)\n            dst_length--;\n        }\n        bit_length= !dst_length ? 0 : (8*dst_length - ff_h264_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) && nalsize){\n            if (bit_length & 7)\n                ptr[bit_length >> 3] = ptr[bit_length >> 3] & (0xff << 8 - (bit_length & 7));\n            av_log(h->s.avctx, AV_LOG_DEBUG, "AVC: Consumed only %d bytes instead of %d\\n", consumed, nalsize);\n        }\n        buf_index += consumed;\n        nal_index++;\n        if(pass == 0) {\n            switch (hx->nal_unit_type) {\n                case NAL_SPS:\n                case NAL_PPS:\n                    nals_needed = nal_index;\n                    break;\n                case NAL_IDR_SLICE:\n                case NAL_SLICE:\n                    init_get_bits(&hx->s.gb, ptr, bit_length);\n                    if (!get_ue_golomb(&hx->s.gb))\n                        nals_needed = nal_index;\n            }\n            continue;\n        }\n        if(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->f.key_frame |=\n                    (hx->nal_unit_type == NAL_IDR_SLICE) ||\n                    (h->sei_recovery_frame_cnt >= 0);\n            if (h->current_slice == 1) {\n                if(!(s->flags2 & CODEC_FLAG2_CHUNKS)) {\n                    decode_postinit(h, nal_index >= nals_needed);\n                }\n                if (s->avctx->hwaccel && s->avctx->hwaccel->start_frame(s->avctx, NULL, 0) < 0)\n                    return -1;\n                if(CONFIG_H264_VDPAU_DECODER && s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)\n                    ff_vdpau_h264_picture_start(s);\n            }\n            if(hx->redundant_pic_count==0\n               && (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc)\n               && (avctx->skip_frame < AVDISCARD_BIDIR  || hx->slice_type_nos!=AV_PICTURE_TYPE_B)\n               && (avctx->skip_frame < AVDISCARD_NONKEY || hx->slice_type_nos==AV_PICTURE_TYPE_I)\n               && avctx->skip_frame < AVDISCARD_ALL){\n                if(avctx->hwaccel) {\n                    if (avctx->hwaccel->decode_slice(avctx, &buf[buf_index - consumed], consumed) < 0)\n                        return -1;\n                }else\n                if(CONFIG_H264_VDPAU_DECODER && s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU){\n                    static const uint8_t start_code[] = {0x00, 0x00, 0x01};\n                    ff_vdpau_add_data_chunk(s, start_code, sizeof(start_code));\n                    ff_vdpau_add_data_chunk(s, &buf[buf_index - consumed], consumed );\n                }else\n                    context_count++;\n            }\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            if ((err = decode_slice_header(hx, h)) < 0)\n                break;\n            hx->s.data_partitioning = 1;\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               && (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc)\n               && (avctx->skip_frame < AVDISCARD_BIDIR  || hx->slice_type_nos!=AV_PICTURE_TYPE_B)\n               && (avctx->skip_frame < AVDISCARD_NONKEY || hx->slice_type_nos==AV_PICTURE_TYPE_I)\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            ff_h264_decode_sei(h);\n            break;\n        case NAL_SPS:\n            init_get_bits(&s->gb, ptr, bit_length);\n            ff_h264_decode_seq_parameter_set(h);\n            if (s->flags& CODEC_FLAG_LOW_DELAY ||\n                (h->sps.bitstream_restriction_flag && !h->sps.num_reorder_frames))\n                s->low_delay=1;\n            if(avctx->has_b_frames < 2)\n                avctx->has_b_frames= !s->low_delay;\n            if (avctx->bits_per_raw_sample != h->sps.bit_depth_luma ||\n                h->cur_chroma_format_idc != h->sps.chroma_format_idc) {\n                if (h->sps.bit_depth_luma >= 8 && h->sps.bit_depth_luma <= 10) {\n                    avctx->bits_per_raw_sample = h->sps.bit_depth_luma;\n                    h->cur_chroma_format_idc = h->sps.chroma_format_idc;\n                    h->pixel_shift = h->sps.bit_depth_luma > 8;\n                    ff_h264dsp_init(&h->h264dsp, h->sps.bit_depth_luma, h->sps.chroma_format_idc);\n                    ff_h264_pred_init(&h->hpc, s->codec_id, h->sps.bit_depth_luma, h->sps.chroma_format_idc);\n                    s->dsp.dct_bits = h->sps.bit_depth_luma > 8 ? 32 : 16;\n                    dsputil_init(&s->dsp, s->avctx);\n                } else {\n                    av_log(avctx, AV_LOG_ERROR, "Unsupported bit depth: %d\\n", h->sps.bit_depth_luma);\n                    return -1;\n                }\n            }\n            break;\n        case NAL_PPS:\n            init_get_bits(&s->gb, ptr, bit_length);\n            ff_h264_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", hx->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    }\n    if(context_count)\n        execute_decode_slices(h, context_count);\n    return buf_index;\n}', 'static int decode_slice_header(H264Context *h, H264Context *h0){\n    MpegEncContext * const s = &h->s;\n    MpegEncContext * const s0 = &h0->s;\n    unsigned int first_mb_in_slice;\n    unsigned int pps_id;\n    int num_ref_idx_active_override_flag;\n    unsigned int slice_type, tmp, i, j;\n    int default_ref_list_done = 0;\n    int last_pic_structure;\n    s->dropable= h->nal_ref_idc == 0;\n    if((s->avctx->flags2 & CODEC_FLAG2_FAST) && !h->nal_ref_idc && !h->pixel_shift){\n        s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab;\n        s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab;\n    }else{\n        s->me.qpel_put= s->dsp.put_h264_qpel_pixels_tab;\n        s->me.qpel_avg= s->dsp.avg_h264_qpel_pixels_tab;\n    }\n    first_mb_in_slice= get_ue_golomb(&s->gb);\n    if(first_mb_in_slice == 0){\n        if(h0->current_slice && FIELD_PICTURE){\n            field_end(h, 1);\n        }\n        h0->current_slice = 0;\n        if (!s0->first_field)\n            s->current_picture_ptr= NULL;\n    }\n    slice_type= get_ue_golomb_31(&s->gb);\n    if(slice_type > 9){\n        av_log(h->s.avctx, AV_LOG_ERROR, "slice type too large (%d) at %d %d\\n", h->slice_type, s->mb_x, s->mb_y);\n        return -1;\n    }\n    if(slice_type > 4){\n        slice_type -= 5;\n        h->slice_type_fixed=1;\n    }else\n        h->slice_type_fixed=0;\n    slice_type= golomb_to_pict_type[ slice_type ];\n    if (slice_type == AV_PICTURE_TYPE_I\n        || (h0->current_slice != 0 && slice_type == h0->last_slice_type) ) {\n        default_ref_list_done = 1;\n    }\n    h->slice_type= slice_type;\n    h->slice_type_nos= slice_type & 3;\n    s->pict_type= h->slice_type;\n    pps_id= get_ue_golomb(&s->gb);\n    if(pps_id>=MAX_PPS_COUNT){\n        av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\\n");\n        return -1;\n    }\n    if(!h0->pps_buffers[pps_id]) {\n        av_log(h->s.avctx, AV_LOG_ERROR, "non-existing PPS %u referenced\\n", pps_id);\n        return -1;\n    }\n    h->pps= *h0->pps_buffers[pps_id];\n    if(!h0->sps_buffers[h->pps.sps_id]) {\n        av_log(h->s.avctx, AV_LOG_ERROR, "non-existing SPS %u referenced\\n", h->pps.sps_id);\n        return -1;\n    }\n    h->sps = *h0->sps_buffers[h->pps.sps_id];\n    s->avctx->profile = ff_h264_get_profile(&h->sps);\n    s->avctx->level   = h->sps.level_idc;\n    s->avctx->refs    = h->sps.ref_frame_count;\n    if(h == h0 && h->dequant_coeff_pps != pps_id){\n        h->dequant_coeff_pps = pps_id;\n        init_dequant_tables(h);\n    }\n    s->mb_width= h->sps.mb_width;\n    s->mb_height= h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag);\n    h->b_stride=  s->mb_width*4;\n    s->chroma_y_shift = h->sps.chroma_format_idc <= 1;\n    s->width = 16*s->mb_width - (2>>CHROMA444)*FFMIN(h->sps.crop_right, (8<<CHROMA444)-1);\n    if(h->sps.frame_mbs_only_flag)\n        s->height= 16*s->mb_height - (1<<s->chroma_y_shift)*FFMIN(h->sps.crop_bottom, (16>>s->chroma_y_shift)-1);\n    else\n        s->height= 16*s->mb_height - (2<<s->chroma_y_shift)*FFMIN(h->sps.crop_bottom, (16>>s->chroma_y_shift)-1);\n    if (s->context_initialized\n        && (   s->width != s->avctx->width || s->height != s->avctx->height\n            || av_cmp_q(h->sps.sar, s->avctx->sample_aspect_ratio))) {\n        if(h != h0) {\n            av_log_missing_feature(s->avctx, "Width/height changing with threads is", 0);\n            return -1;\n        }\n        free_tables(h, 0);\n        flush_dpb(s->avctx);\n        MPV_common_end(s);\n    }\n    if (!s->context_initialized) {\n        if (h != h0) {\n            av_log(h->s.avctx, AV_LOG_ERROR, "Cannot (re-)initialize context during parallel decoding.\\n");\n            return -1;\n        }\n        avcodec_set_dimensions(s->avctx, s->width, s->height);\n        s->avctx->sample_aspect_ratio= h->sps.sar;\n        av_assert0(s->avctx->sample_aspect_ratio.den);\n        if(h->sps.video_signal_type_present_flag){\n            s->avctx->color_range = h->sps.full_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;\n            if(h->sps.colour_description_present_flag){\n                s->avctx->color_primaries = h->sps.color_primaries;\n                s->avctx->color_trc       = h->sps.color_trc;\n                s->avctx->colorspace      = h->sps.colorspace;\n            }\n        }\n        if(h->sps.timing_info_present_flag){\n            int64_t den= h->sps.time_scale;\n            if(h->x264_build < 44U)\n                den *= 2;\n            av_reduce(&s->avctx->time_base.num, &s->avctx->time_base.den,\n                      h->sps.num_units_in_tick, den, 1<<30);\n        }\n        switch (h->sps.bit_depth_luma) {\n            case 9 :\n                if (CHROMA444) {\n                    if (s->avctx->colorspace == AVCOL_SPC_RGB) {\n                        s->avctx->pix_fmt = PIX_FMT_GBRP9;\n                    } else\n                        s->avctx->pix_fmt = PIX_FMT_YUV444P9;\n                } else if (CHROMA422)\n                    s->avctx->pix_fmt = PIX_FMT_YUV422P9;\n                else\n                    s->avctx->pix_fmt = PIX_FMT_YUV420P9;\n                break;\n            case 10 :\n                if (CHROMA444) {\n                    if (s->avctx->colorspace == AVCOL_SPC_RGB) {\n                        s->avctx->pix_fmt = PIX_FMT_GBRP10;\n                    } else\n                        s->avctx->pix_fmt = PIX_FMT_YUV444P10;\n                } else if (CHROMA422)\n                    s->avctx->pix_fmt = PIX_FMT_YUV422P10;\n                else\n                    s->avctx->pix_fmt = PIX_FMT_YUV420P10;\n                break;\n            default:\n                if (CHROMA444){\n                    if (s->avctx->colorspace == AVCOL_SPC_RGB) {\n                        s->avctx->pix_fmt = PIX_FMT_GBRP;\n                    } else\n                        s->avctx->pix_fmt = s->avctx->color_range == AVCOL_RANGE_JPEG ? PIX_FMT_YUVJ444P : PIX_FMT_YUV444P;\n                } else if (CHROMA422) {\n                    s->avctx->pix_fmt = s->avctx->color_range == AVCOL_RANGE_JPEG ? PIX_FMT_YUVJ422P : PIX_FMT_YUV422P;\n                }else{\n                    s->avctx->pix_fmt = s->avctx->get_format(s->avctx,\n                                                             s->avctx->codec->pix_fmts ?\n                                                             s->avctx->codec->pix_fmts :\n                                                             s->avctx->color_range == AVCOL_RANGE_JPEG ?\n                                                             hwaccel_pixfmt_list_h264_jpeg_420 :\n                                                             ff_hwaccel_pixfmt_list_420);\n                }\n        }\n        s->avctx->hwaccel = ff_find_hwaccel(s->avctx->codec->id, s->avctx->pix_fmt);\n        if (MPV_common_init(s) < 0) {\n            av_log(h->s.avctx, AV_LOG_ERROR, "MPV_common_init() failed.\\n");\n            return -1;\n        }\n        s->first_field = 0;\n        h->prev_interlaced_frame = 1;\n        init_scan_tables(h);\n        if (ff_h264_alloc_tables(h) < 0) {\n            av_log(h->s.avctx, AV_LOG_ERROR, "Could not allocate memory for h264\\n");\n            return AVERROR(ENOMEM);\n        }\n        if (!HAVE_THREADS || !(s->avctx->active_thread_type&FF_THREAD_SLICE)) {\n            if (context_init(h) < 0) {\n                av_log(h->s.avctx, AV_LOG_ERROR, "context_init() failed.\\n");\n                return -1;\n            }\n        } else {\n            for(i = 1; i < s->slice_context_count; i++) {\n                H264Context *c;\n                c = h->thread_context[i] = av_malloc(sizeof(H264Context));\n                memcpy(c, h->s.thread_context[i], sizeof(MpegEncContext));\n                memset(&c->s + 1, 0, sizeof(H264Context) - sizeof(MpegEncContext));\n                c->h264dsp = h->h264dsp;\n                c->sps = h->sps;\n                c->pps = h->pps;\n                c->pixel_shift = h->pixel_shift;\n                init_scan_tables(c);\n                clone_tables(c, h, i);\n            }\n            for(i = 0; i < s->slice_context_count; i++)\n                if (context_init(h->thread_context[i]) < 0) {\n                    av_log(h->s.avctx, AV_LOG_ERROR, "context_init() failed.\\n");\n                    return -1;\n                }\n        }\n    }\n    h->frame_num= get_bits(&s->gb, h->sps.log2_max_frame_num);\n    h->mb_mbaff = 0;\n    h->mb_aff_frame = 0;\n    last_pic_structure = s0->picture_structure;\n    if(h->sps.frame_mbs_only_flag){\n        s->picture_structure= PICT_FRAME;\n    }else{\n        if(get_bits1(&s->gb)) {\n            s->picture_structure= PICT_TOP_FIELD + get_bits1(&s->gb);\n        } else {\n            s->picture_structure= PICT_FRAME;\n            h->mb_aff_frame = h->sps.mb_aff;\n        }\n    }\n    h->mb_field_decoding_flag= s->picture_structure != PICT_FRAME;\n    if(h0->current_slice == 0){\n        if(h->frame_num != h->prev_frame_num) {\n            int unwrap_prev_frame_num = h->prev_frame_num, max_frame_num = 1<<h->sps.log2_max_frame_num;\n            if (unwrap_prev_frame_num > h->frame_num) unwrap_prev_frame_num -= max_frame_num;\n            if ((h->frame_num - unwrap_prev_frame_num) > h->sps.ref_frame_count) {\n                unwrap_prev_frame_num = (h->frame_num - h->sps.ref_frame_count) - 1;\n                if (unwrap_prev_frame_num < 0)\n                    unwrap_prev_frame_num += max_frame_num;\n                h->prev_frame_num = unwrap_prev_frame_num;\n            }\n        }\n        while(h->frame_num !=  h->prev_frame_num &&\n              h->frame_num != (h->prev_frame_num+1)%(1<<h->sps.log2_max_frame_num)){\n            Picture *prev = h->short_ref_count ? h->short_ref[0] : NULL;\n            av_log(h->s.avctx, AV_LOG_DEBUG, "Frame num gap %d %d\\n", h->frame_num, h->prev_frame_num);\n            if (ff_h264_frame_start(h) < 0)\n                return -1;\n            h->prev_frame_num++;\n            h->prev_frame_num %= 1<<h->sps.log2_max_frame_num;\n            s->current_picture_ptr->frame_num= h->prev_frame_num;\n            ff_thread_report_progress((AVFrame*)s->current_picture_ptr, INT_MAX, 0);\n            ff_thread_report_progress((AVFrame*)s->current_picture_ptr, INT_MAX, 1);\n            ff_generate_sliding_window_mmcos(h);\n            if (ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index) < 0 &&\n                (s->avctx->err_recognition & AV_EF_EXPLODE))\n                return AVERROR_INVALIDDATA;\n            if (h->short_ref_count) {\n                if (prev) {\n                    av_image_copy(h->short_ref[0]->f.data, h->short_ref[0]->f.linesize,\n                                  (const uint8_t**)prev->f.data, prev->f.linesize,\n                                  s->avctx->pix_fmt, s->mb_width*16, s->mb_height*16);\n                    h->short_ref[0]->poc = prev->poc+2;\n                }\n                h->short_ref[0]->frame_num = h->prev_frame_num;\n            }\n        }\n        if (s0->first_field) {\n            assert(s0->current_picture_ptr);\n            assert(s0->current_picture_ptr->f.data[0]);\n            assert(s0->current_picture_ptr->f.reference != DELAYED_PIC_REF);\n            if (!FIELD_PICTURE || s->picture_structure == last_pic_structure) {\n                s0->current_picture_ptr = NULL;\n                s0->first_field = FIELD_PICTURE;\n            } else {\n                if (h->nal_ref_idc &&\n                        s0->current_picture_ptr->f.reference &&\n                        s0->current_picture_ptr->frame_num != h->frame_num) {\n                    s0->first_field = 1;\n                    s0->current_picture_ptr = NULL;\n                } else {\n                    s0->first_field = 0;\n                }\n            }\n        } else {\n            assert(!s0->current_picture_ptr);\n            s0->first_field = FIELD_PICTURE;\n        }\n        if(!FIELD_PICTURE || s0->first_field) {\n            if (ff_h264_frame_start(h) < 0) {\n                s0->first_field = 0;\n                return -1;\n            }\n        } else {\n            ff_release_unused_pictures(s, 0);\n        }\n    }\n    if(h != h0)\n        clone_slice(h, h0);\n    s->current_picture_ptr->frame_num= h->frame_num;\n    assert(s->mb_num == s->mb_width * s->mb_height);\n    if(first_mb_in_slice << FIELD_OR_MBAFF_PICTURE >= s->mb_num ||\n       first_mb_in_slice                    >= s->mb_num){\n        av_log(h->s.avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\\n");\n        return -1;\n    }\n    s->resync_mb_x = s->mb_x = first_mb_in_slice % s->mb_width;\n    s->resync_mb_y = s->mb_y = (first_mb_in_slice / s->mb_width) << FIELD_OR_MBAFF_PICTURE;\n    if (s->picture_structure == PICT_BOTTOM_FIELD)\n        s->resync_mb_y = s->mb_y = s->mb_y + 1;\n    assert(s->mb_y < s->mb_height);\n    if(s->picture_structure==PICT_FRAME){\n        h->curr_pic_num=   h->frame_num;\n        h->max_pic_num= 1<< h->sps.log2_max_frame_num;\n    }else{\n        h->curr_pic_num= 2*h->frame_num + 1;\n        h->max_pic_num= 1<<(h->sps.log2_max_frame_num + 1);\n    }\n    if(h->nal_unit_type == NAL_IDR_SLICE){\n        get_ue_golomb(&s->gb);\n    }\n    if(h->sps.poc_type==0){\n        h->poc_lsb= get_bits(&s->gb, h->sps.log2_max_poc_lsb);\n        if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME){\n            h->delta_poc_bottom= get_se_golomb(&s->gb);\n        }\n    }\n    if(h->sps.poc_type==1 && !h->sps.delta_pic_order_always_zero_flag){\n        h->delta_poc[0]= get_se_golomb(&s->gb);\n        if(h->pps.pic_order_present==1 && s->picture_structure==PICT_FRAME)\n            h->delta_poc[1]= get_se_golomb(&s->gb);\n    }\n    init_poc(h);\n    if(h->pps.redundant_pic_cnt_present){\n        h->redundant_pic_count= get_ue_golomb(&s->gb);\n    }\n    h->ref_count[0]= h->pps.ref_count[0];\n    h->ref_count[1]= h->pps.ref_count[1];\n    if(h->slice_type_nos != AV_PICTURE_TYPE_I){\n        if(h->slice_type_nos == AV_PICTURE_TYPE_B){\n            h->direct_spatial_mv_pred= get_bits1(&s->gb);\n        }\n        num_ref_idx_active_override_flag= get_bits1(&s->gb);\n        if(num_ref_idx_active_override_flag){\n            h->ref_count[0]= get_ue_golomb(&s->gb) + 1;\n            if(h->slice_type_nos==AV_PICTURE_TYPE_B)\n                h->ref_count[1]= get_ue_golomb(&s->gb) + 1;\n            if(h->ref_count[0]-1 > 32-1 || h->ref_count[1]-1 > 32-1){\n                av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\\n");\n                h->ref_count[0]= h->ref_count[1]= 1;\n                return -1;\n            }\n        }\n        if(h->slice_type_nos == AV_PICTURE_TYPE_B)\n            h->list_count= 2;\n        else\n            h->list_count= 1;\n    }else\n        h->list_count= 0;\n    if(!default_ref_list_done){\n        ff_h264_fill_default_ref_list(h);\n    }\n    if(h->slice_type_nos!=AV_PICTURE_TYPE_I && ff_h264_decode_ref_pic_list_reordering(h) < 0) {\n        h->ref_count[1]= h->ref_count[0]= 0;\n        return -1;\n    }\n    if(h->slice_type_nos!=AV_PICTURE_TYPE_I){\n        s->last_picture_ptr= &h->ref_list[0][0];\n        ff_copy_picture(&s->last_picture, s->last_picture_ptr);\n    }\n    if(h->slice_type_nos==AV_PICTURE_TYPE_B){\n        s->next_picture_ptr= &h->ref_list[1][0];\n        ff_copy_picture(&s->next_picture, s->next_picture_ptr);\n    }\n    if(   (h->pps.weighted_pred          && h->slice_type_nos == AV_PICTURE_TYPE_P )\n       ||  (h->pps.weighted_bipred_idc==1 && h->slice_type_nos== AV_PICTURE_TYPE_B ) )\n        pred_weight_table(h);\n    else if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== AV_PICTURE_TYPE_B){\n        implicit_weight_table(h, -1);\n    }else {\n        h->use_weight = 0;\n        for (i = 0; i < 2; i++) {\n            h->luma_weight_flag[i]   = 0;\n            h->chroma_weight_flag[i] = 0;\n        }\n    }\n    if(h->nal_ref_idc && ff_h264_decode_ref_pic_marking(h0, &s->gb) < 0 &&\n       (s->avctx->err_recognition & AV_EF_EXPLODE))\n        return AVERROR_INVALIDDATA;\n    if(FRAME_MBAFF){\n        ff_h264_fill_mbaff_ref_list(h);\n        if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== AV_PICTURE_TYPE_B){\n            implicit_weight_table(h, 0);\n            implicit_weight_table(h, 1);\n        }\n    }\n    if(h->slice_type_nos==AV_PICTURE_TYPE_B && !h->direct_spatial_mv_pred)\n        ff_h264_direct_dist_scale_factor(h);\n    ff_h264_direct_ref_list_init(h);\n    if( h->slice_type_nos != AV_PICTURE_TYPE_I && h->pps.cabac ){\n        tmp = get_ue_golomb_31(&s->gb);\n        if(tmp > 2){\n            av_log(s->avctx, AV_LOG_ERROR, "cabac_init_idc overflow\\n");\n            return -1;\n        }\n        h->cabac_init_idc= tmp;\n    }\n    h->last_qscale_diff = 0;\n    tmp = h->pps.init_qp + get_se_golomb(&s->gb);\n    if(tmp>51+6*(h->sps.bit_depth_luma-8)){\n        av_log(s->avctx, AV_LOG_ERROR, "QP %u out of range\\n", tmp);\n        return -1;\n    }\n    s->qscale= tmp;\n    h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale);\n    h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale);\n    if(h->slice_type == AV_PICTURE_TYPE_SP){\n        get_bits1(&s->gb);\n    }\n    if(h->slice_type==AV_PICTURE_TYPE_SP || h->slice_type == AV_PICTURE_TYPE_SI){\n        get_se_golomb(&s->gb);\n    }\n    h->deblocking_filter = 1;\n    h->slice_alpha_c0_offset = 52;\n    h->slice_beta_offset = 52;\n    if( h->pps.deblocking_filter_parameters_present ) {\n        tmp= get_ue_golomb_31(&s->gb);\n        if(tmp > 2){\n            av_log(s->avctx, AV_LOG_ERROR, "deblocking_filter_idc %u out of range\\n", tmp);\n            return -1;\n        }\n        h->deblocking_filter= tmp;\n        if(h->deblocking_filter < 2)\n            h->deblocking_filter^= 1;\n        if( h->deblocking_filter ) {\n            h->slice_alpha_c0_offset += get_se_golomb(&s->gb) << 1;\n            h->slice_beta_offset     += get_se_golomb(&s->gb) << 1;\n            if(   h->slice_alpha_c0_offset > 104U\n               || h->slice_beta_offset     > 104U){\n                av_log(s->avctx, AV_LOG_ERROR, "deblocking filter parameters %d %d out of range\\n", h->slice_alpha_c0_offset, h->slice_beta_offset);\n                return -1;\n            }\n        }\n    }\n    if(   s->avctx->skip_loop_filter >= AVDISCARD_ALL\n       ||(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY && h->slice_type_nos != AV_PICTURE_TYPE_I)\n       ||(s->avctx->skip_loop_filter >= AVDISCARD_BIDIR  && h->slice_type_nos == AV_PICTURE_TYPE_B)\n       ||(s->avctx->skip_loop_filter >= AVDISCARD_NONREF && h->nal_ref_idc == 0))\n        h->deblocking_filter= 0;\n    if(h->deblocking_filter == 1 && h0->max_contexts > 1) {\n        if(s->avctx->flags2 & CODEC_FLAG2_FAST) {\n            h->deblocking_filter = 2;\n        } else {\n            h0->max_contexts = 1;\n            if(!h0->single_decode_warning) {\n                av_log(s->avctx, AV_LOG_INFO, "Cannot parallelize deblocking type 1, decoding such frames in sequential order\\n");\n                h0->single_decode_warning = 1;\n            }\n            if (h != h0) {\n                av_log(h->s.avctx, AV_LOG_ERROR, "Deblocking switched inside frame.\\n");\n                return 1;\n            }\n        }\n    }\n    h->qp_thresh = 15 + 52 - FFMIN(h->slice_alpha_c0_offset, h->slice_beta_offset)\n                 - FFMAX3(0, h->pps.chroma_qp_index_offset[0], h->pps.chroma_qp_index_offset[1])\n                 + 6 * (h->sps.bit_depth_luma - 8);\n#if 0\n    if( h->pps.num_slice_groups > 1  && h->pps.mb_slice_group_map_type >= 3 && h->pps.mb_slice_group_map_type <= 5)\n        slice_group_change_cycle= get_bits(&s->gb, ?);\n#endif\n    h0->last_slice_type = slice_type;\n    h->slice_num = ++h0->current_slice;\n    if(h->slice_num >= MAX_SLICES){\n        av_log(s->avctx, AV_LOG_ERROR, "Too many slices, increase MAX_SLICES and recompile\\n");\n    }\n    for(j=0; j<2; j++){\n        int id_list[16];\n        int *ref2frm= h->ref2frm[h->slice_num&(MAX_SLICES-1)][j];\n        for(i=0; i<16; i++){\n            id_list[i]= 60;\n            if (h->ref_list[j][i].f.data[0]) {\n                int k;\n                uint8_t *base = h->ref_list[j][i].f.base[0];\n                for(k=0; k<h->short_ref_count; k++)\n                    if (h->short_ref[k]->f.base[0] == base) {\n                        id_list[i]= k;\n                        break;\n                    }\n                for(k=0; k<h->long_ref_count; k++)\n                    if (h->long_ref[k] && h->long_ref[k]->f.base[0] == base) {\n                        id_list[i]= h->short_ref_count + k;\n                        break;\n                    }\n            }\n        }\n        ref2frm[0]=\n        ref2frm[1]= -1;\n        for(i=0; i<16; i++)\n            ref2frm[i+2]= 4*id_list[i]\n                          + (h->ref_list[j][i].f.reference & 3);\n        ref2frm[18+0]=\n        ref2frm[18+1]= -1;\n        for(i=16; i<48; i++)\n            ref2frm[i+4]= 4*id_list[(i-16)>>1]\n                          + (h->ref_list[j][i].f.reference & 3);\n    }\n    h->emu_edge_width= (s->flags&CODEC_FLAG_EMU_EDGE || (!h->sps.frame_mbs_only_flag && s->avctx->active_thread_type)) ? 0 : 16;\n    h->emu_edge_height= (FRAME_MBAFF || FIELD_PICTURE) ? 0 : h->emu_edge_width;\n    if(s->avctx->debug&FF_DEBUG_PICT_INFO){\n        av_log(h->s.avctx, AV_LOG_DEBUG, "slice:%d %s mb:%d %c%s%s pps:%u frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\\n",\n               h->slice_num,\n               (s->picture_structure==PICT_FRAME ? "F" : s->picture_structure==PICT_TOP_FIELD ? "T" : "B"),\n               first_mb_in_slice,\n               av_get_picture_type_char(h->slice_type), h->slice_type_fixed ? " fix" : "", h->nal_unit_type == NAL_IDR_SLICE ? " IDR" : "",\n               pps_id, h->frame_num,\n               s->current_picture_ptr->field_poc[0], s->current_picture_ptr->field_poc[1],\n               h->ref_count[0], h->ref_count[1],\n               s->qscale,\n               h->deblocking_filter, h->slice_alpha_c0_offset/2-26, h->slice_beta_offset/2-26,\n               h->use_weight,\n               h->use_weight==1 && h->use_weight_chroma ? "c" : "",\n               h->slice_type == AV_PICTURE_TYPE_B ? (h->direct_spatial_mv_pred ? "SPAT" : "TEMP") : ""\n               );\n    }\n    return 0;\n}', 'static int field_end(H264Context *h, int in_setup){\n    MpegEncContext * const s = &h->s;\n    AVCodecContext * const avctx= s->avctx;\n    int err = 0;\n    s->mb_y= 0;\n    if (!in_setup && !s->dropable)\n        ff_thread_report_progress((AVFrame*)s->current_picture_ptr, (16*s->mb_height >> FIELD_PICTURE) - 1,\n                                 s->picture_structure==PICT_BOTTOM_FIELD);\n    if (CONFIG_H264_VDPAU_DECODER && s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)\n        ff_vdpau_h264_set_reference_frames(s);\n    if(in_setup || !(avctx->active_thread_type&FF_THREAD_FRAME)){\n        if(!s->dropable) {\n            err = ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index);\n            h->prev_poc_msb= h->poc_msb;\n            h->prev_poc_lsb= h->poc_lsb;\n        }\n        h->prev_frame_num_offset= h->frame_num_offset;\n        h->prev_frame_num= h->frame_num;\n        h->outputed_poc = h->next_outputed_poc;\n    }\n    if (avctx->hwaccel) {\n        if (avctx->hwaccel->end_frame(avctx) < 0)\n            av_log(avctx, AV_LOG_ERROR, "hardware accelerator failed to decode picture\\n");\n    }\n    if (CONFIG_H264_VDPAU_DECODER && s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU)\n        ff_vdpau_h264_picture_complete(s);\n    if (!FIELD_PICTURE)\n        ff_er_frame_end(s);\n    MPV_frame_end(s);\n    h->current_slice=0;\n    return err;\n}', 'void ff_er_frame_end(MpegEncContext *s)\n{\n    int i, mb_x, mb_y, error, error_type, dc_error, mv_error, ac_error;\n    int distance;\n    int threshold_part[4] = { 100, 100, 100 };\n    int threshold = 50;\n    int is_intra_likely;\n    int size = s->b8_stride * 2 * s->mb_height;\n    Picture *pic = s->current_picture_ptr;\n    if (!s->err_recognition || s->error_count == 0 || s->avctx->lowres ||\n        s->avctx->hwaccel                                              ||\n        s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU          ||\n        s->picture_structure != PICT_FRAME                             ||\n        s->error_count == 3 * s->mb_width *\n                          (s->avctx->skip_top + s->avctx->skip_bottom)) {\n        return;\n    };\n    if (s->current_picture.f.motion_val[0] == NULL) {\n        av_log(s->avctx, AV_LOG_ERROR, "Warning MVs not available\\n");\n        for (i = 0; i < 2; i++) {\n            pic->f.ref_index[i]     = av_mallocz(s->mb_stride * s->mb_height * 4 * sizeof(uint8_t));\n            pic->motion_val_base[i] = av_mallocz((size + 4) * 2 * sizeof(uint16_t));\n            pic->f.motion_val[i]    = pic->motion_val_base[i] + 4;\n        }\n        pic->f.motion_subsample_log2 = 3;\n        s->current_picture = *s->current_picture_ptr;\n    }\n    if (s->avctx->debug & FF_DEBUG_ER) {\n        for (mb_y = 0; mb_y < s->mb_height; mb_y++) {\n            for (mb_x = 0; mb_x < s->mb_width; mb_x++) {\n                int status = s->error_status_table[mb_x + mb_y * s->mb_stride];\n                av_log(s->avctx, AV_LOG_DEBUG, "%2X ", status);\n            }\n            av_log(s->avctx, AV_LOG_DEBUG, "\\n");\n        }\n    }\n    for (error_type = 1; error_type <= 3; error_type++) {\n        int end_ok = 0;\n        for (i = s->mb_num - 1; i >= 0; i--) {\n            const int mb_xy = s->mb_index2xy[i];\n            int error       = s->error_status_table[mb_xy];\n            if (error & (1 << error_type))\n                end_ok = 1;\n            if (error & (8 << error_type))\n                end_ok = 1;\n            if (!end_ok)\n                s->error_status_table[mb_xy] |= 1 << error_type;\n            if (error & VP_START)\n                end_ok = 0;\n        }\n    }\n    if (s->partitioned_frame) {\n        int end_ok = 0;\n        for (i = s->mb_num - 1; i >= 0; i--) {\n            const int mb_xy = s->mb_index2xy[i];\n            int error       = s->error_status_table[mb_xy];\n            if (error & ER_AC_END)\n                end_ok = 0;\n            if ((error & ER_MV_END) ||\n                (error & ER_DC_END) ||\n                (error & ER_AC_ERROR))\n                end_ok = 1;\n            if (!end_ok)\n                s->error_status_table[mb_xy]|= ER_AC_ERROR;\n            if (error & VP_START)\n                end_ok = 0;\n        }\n    }\n    if (s->err_recognition & AV_EF_EXPLODE) {\n        int end_ok = 1;\n        for (i = s->mb_num - 2; i >= s->mb_width + 100; i--) {\n            const int mb_xy = s->mb_index2xy[i];\n            int error1 = s->error_status_table[mb_xy];\n            int error2 = s->error_status_table[s->mb_index2xy[i + 1]];\n            if (error1 & VP_START)\n                end_ok = 1;\n            if (error2 == (VP_START | ER_MB_ERROR | ER_MB_END) &&\n                error1 != (VP_START | ER_MB_ERROR | ER_MB_END) &&\n                ((error1 & ER_AC_END) || (error1 & ER_DC_END) ||\n                (error1 & ER_MV_END))) {\n                end_ok = 0;\n            }\n            if (!end_ok)\n                s->error_status_table[mb_xy] |= ER_MB_ERROR;\n        }\n    }\n    distance = 9999999;\n    for (error_type = 1; error_type <= 3; error_type++) {\n        for (i = s->mb_num - 1; i >= 0; i--) {\n            const int mb_xy = s->mb_index2xy[i];\n            int       error = s->error_status_table[mb_xy];\n            if (!s->mbskip_table[mb_xy])\n                distance++;\n            if (error & (1 << error_type))\n                distance = 0;\n            if (s->partitioned_frame) {\n                if (distance < threshold_part[error_type - 1])\n                    s->error_status_table[mb_xy] |= 1 << error_type;\n            } else {\n                if (distance < threshold)\n                    s->error_status_table[mb_xy] |= 1 << error_type;\n            }\n            if (error & VP_START)\n                distance = 9999999;\n        }\n    }\n    error = 0;\n    for (i = 0; i < s->mb_num; i++) {\n        const int mb_xy = s->mb_index2xy[i];\n        int old_error   = s->error_status_table[mb_xy];\n        if (old_error & VP_START) {\n            error = old_error & ER_MB_ERROR;\n        } else {\n            error |= old_error & ER_MB_ERROR;\n            s->error_status_table[mb_xy] |= error;\n        }\n    }\n    if (!s->partitioned_frame) {\n        for (i = 0; i < s->mb_num; i++) {\n            const int mb_xy = s->mb_index2xy[i];\n            error = s->error_status_table[mb_xy];\n            if (error & ER_MB_ERROR)\n                error |= ER_MB_ERROR;\n            s->error_status_table[mb_xy] = error;\n        }\n    }\n    dc_error = ac_error = mv_error = 0;\n    for (i = 0; i < s->mb_num; i++) {\n        const int mb_xy = s->mb_index2xy[i];\n        error = s->error_status_table[mb_xy];\n        if (error & ER_DC_ERROR)\n            dc_error++;\n        if (error & ER_AC_ERROR)\n            ac_error++;\n        if (error & ER_MV_ERROR)\n            mv_error++;\n    }\n    av_log(s->avctx, AV_LOG_INFO, "concealing %d DC, %d AC, %d MV errors\\n",\n           dc_error, ac_error, mv_error);\n    is_intra_likely = is_intra_more_likely(s);\n    for (i = 0; i < s->mb_num; i++) {\n        const int mb_xy = s->mb_index2xy[i];\n        error = s->error_status_table[mb_xy];\n        if (!((error & ER_DC_ERROR) && (error & ER_MV_ERROR)))\n            continue;\n        if (is_intra_likely)\n            s->current_picture.f.mb_type[mb_xy] = MB_TYPE_INTRA4x4;\n        else\n            s->current_picture.f.mb_type[mb_xy] = MB_TYPE_16x16 | MB_TYPE_L0;\n    }\n    if (!s->last_picture.f.data[0] && !s->next_picture.f.data[0])\n        for (i = 0; i < s->mb_num; i++) {\n            const int mb_xy = s->mb_index2xy[i];\n            if (!IS_INTRA(s->current_picture.f.mb_type[mb_xy]))\n                s->current_picture.f.mb_type[mb_xy] = MB_TYPE_INTRA4x4;\n        }\n    for (mb_y = 0; mb_y < s->mb_height; mb_y++) {\n        for (mb_x = 0; mb_x < s->mb_width; mb_x++) {\n            const int mb_xy   = mb_x + mb_y * s->mb_stride;\n            const int mb_type = s->current_picture.f.mb_type[mb_xy];\n            int dir           = !s->last_picture.f.data[0];\n            error = s->error_status_table[mb_xy];\n            if (IS_INTRA(mb_type))\n                continue;\n            if (error & ER_MV_ERROR)\n                continue;\n            if (!(error & ER_AC_ERROR))\n                continue;\n            s->mv_dir     = dir ? MV_DIR_BACKWARD : MV_DIR_FORWARD;\n            s->mb_intra   = 0;\n            s->mb_skipped = 0;\n            if (IS_8X8(mb_type)) {\n                int mb_index = mb_x * 2 + mb_y * 2 * s->b8_stride;\n                int j;\n                s->mv_type = MV_TYPE_8X8;\n                for (j = 0; j < 4; j++) {\n                    s->mv[0][j][0] = s->current_picture.f.motion_val[dir][mb_index + (j & 1) + (j >> 1) * s->b8_stride][0];\n                    s->mv[0][j][1] = s->current_picture.f.motion_val[dir][mb_index + (j & 1) + (j >> 1) * s->b8_stride][1];\n                }\n            } else {\n                s->mv_type     = MV_TYPE_16X16;\n                s->mv[0][0][0] = s->current_picture.f.motion_val[dir][mb_x * 2 + mb_y * 2 * s->b8_stride][0];\n                s->mv[0][0][1] = s->current_picture.f.motion_val[dir][mb_x * 2 + mb_y * 2 * s->b8_stride][1];\n            }\n            s->dsp.clear_blocks(s->block[0]);\n            s->mb_x = mb_x;\n            s->mb_y = mb_y;\n            decode_mb(s, 0  );\n        }\n    }\n    if (s->pict_type == AV_PICTURE_TYPE_B) {\n        for (mb_y = 0; mb_y < s->mb_height; mb_y++) {\n            for (mb_x = 0; mb_x < s->mb_width; mb_x++) {\n                int       xy      = mb_x * 2 + mb_y * 2 * s->b8_stride;\n                const int mb_xy   = mb_x + mb_y * s->mb_stride;\n                const int mb_type = s->current_picture.f.mb_type[mb_xy];\n                error = s->error_status_table[mb_xy];\n                if (IS_INTRA(mb_type))\n                    continue;\n                if (!(error & ER_MV_ERROR))\n                    continue;\n                if (!(error & ER_AC_ERROR))\n                    continue;\n                s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD;\n                if (!s->last_picture.f.data[0])\n                    s->mv_dir &= ~MV_DIR_FORWARD;\n                if (!s->next_picture.f.data[0])\n                    s->mv_dir &= ~MV_DIR_BACKWARD;\n                s->mb_intra   = 0;\n                s->mv_type    = MV_TYPE_16X16;\n                s->mb_skipped = 0;\n                if (s->pp_time) {\n                    int time_pp = s->pp_time;\n                    int time_pb = s->pb_time;\n                    if (s->avctx->codec_id == CODEC_ID_H264) {\n                    } else {\n                        ff_thread_await_progress((AVFrame *) s->next_picture_ptr, mb_y, 0);\n                    }\n                    s->mv[0][0][0] = s->next_picture.f.motion_val[0][xy][0] *  time_pb            / time_pp;\n                    s->mv[0][0][1] = s->next_picture.f.motion_val[0][xy][1] *  time_pb            / time_pp;\n                    s->mv[1][0][0] = s->next_picture.f.motion_val[0][xy][0] * (time_pb - time_pp) / time_pp;\n                    s->mv[1][0][1] = s->next_picture.f.motion_val[0][xy][1] * (time_pb - time_pp) / time_pp;\n                } else {\n                    s->mv[0][0][0] = 0;\n                    s->mv[0][0][1] = 0;\n                    s->mv[1][0][0] = 0;\n                    s->mv[1][0][1] = 0;\n                }\n                s->dsp.clear_blocks(s->block[0]);\n                s->mb_x = mb_x;\n                s->mb_y = mb_y;\n                decode_mb(s, 0);\n            }\n        }\n    } else\n        guess_mv(s);\n    if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration)\n        goto ec_clean;\n    for (mb_y = 0; mb_y < s->mb_height; mb_y++) {\n        for (mb_x = 0; mb_x < s->mb_width; mb_x++) {\n            int dc, dcu, dcv, y, n;\n            int16_t *dc_ptr;\n            uint8_t *dest_y, *dest_cb, *dest_cr;\n            const int mb_xy   = mb_x + mb_y * s->mb_stride;\n            const int mb_type = s->current_picture.f.mb_type[mb_xy];\n            error = s->error_status_table[mb_xy];\n            if (IS_INTRA(mb_type) && s->partitioned_frame)\n                continue;\n            dest_y  = s->current_picture.f.data[0] + mb_x * 16 + mb_y * 16 * s->linesize;\n            dest_cb = s->current_picture.f.data[1] + mb_x *  8 + mb_y *  8 * s->uvlinesize;\n            dest_cr = s->current_picture.f.data[2] + mb_x *  8 + mb_y *  8 * s->uvlinesize;\n            dc_ptr = &s->dc_val[0][mb_x * 2 + mb_y * 2 * s->b8_stride];\n            for (n = 0; n < 4; n++) {\n                dc = 0;\n                for (y = 0; y < 8; y++) {\n                    int x;\n                    for (x = 0; x < 8; x++)\n                       dc += dest_y[x + (n & 1) * 8 +\n                             (y + (n >> 1) * 8) * s->linesize];\n                }\n                dc_ptr[(n & 1) + (n >> 1) * s->b8_stride] = (dc + 4) >> 3;\n            }\n            dcu = dcv = 0;\n            for (y = 0; y < 8; y++) {\n                int x;\n                for (x = 0; x < 8; x++) {\n                    dcu += dest_cb[x + y * s->uvlinesize];\n                    dcv += dest_cr[x + y * s->uvlinesize];\n                }\n            }\n            s->dc_val[1][mb_x + mb_y * s->mb_stride] = (dcu + 4) >> 3;\n            s->dc_val[2][mb_x + mb_y * s->mb_stride] = (dcv + 4) >> 3;\n        }\n    }\n    guess_dc(s, s->dc_val[0], s->mb_width * 2, s->mb_height * 2, s->b8_stride, 1);\n    guess_dc(s, s->dc_val[1], s->mb_width, s->mb_height, s->mb_stride, 0);\n    guess_dc(s, s->dc_val[2], s->mb_width, s->mb_height, s->mb_stride, 0);\n    filter181(s->dc_val[0], s->mb_width * 2, s->mb_height * 2, s->b8_stride);\n    for (mb_y = 0; mb_y < s->mb_height; mb_y++) {\n        for (mb_x = 0; mb_x < s->mb_width; mb_x++) {\n            uint8_t *dest_y, *dest_cb, *dest_cr;\n            const int mb_xy   = mb_x + mb_y * s->mb_stride;\n            const int mb_type = s->current_picture.f.mb_type[mb_xy];\n            error = s->error_status_table[mb_xy];\n            if (IS_INTER(mb_type))\n                continue;\n            if (!(error & ER_AC_ERROR))\n                continue;\n            dest_y  = s->current_picture.f.data[0] + mb_x * 16 + mb_y * 16 * s->linesize;\n            dest_cb = s->current_picture.f.data[1] + mb_x *  8 + mb_y *  8 * s->uvlinesize;\n            dest_cr = s->current_picture.f.data[2] + mb_x *  8 + mb_y *  8 * s->uvlinesize;\n            put_dc(s, dest_y, dest_cb, dest_cr, mb_x, mb_y);\n        }\n    }\n    if (s->avctx->error_concealment & FF_EC_DEBLOCK) {\n        h_block_filter(s, s->current_picture.f.data[0], s->mb_width * 2,\n                       s->mb_height * 2, s->linesize, 1);\n        h_block_filter(s, s->current_picture.f.data[1], s->mb_width,\n                       s->mb_height  , s->uvlinesize, 0);\n        h_block_filter(s, s->current_picture.f.data[2], s->mb_width,\n                       s->mb_height  , s->uvlinesize, 0);\n        v_block_filter(s, s->current_picture.f.data[0], s->mb_width * 2,\n                       s->mb_height * 2, s->linesize, 1);\n        v_block_filter(s, s->current_picture.f.data[1], s->mb_width,\n                       s->mb_height  , s->uvlinesize, 0);\n        v_block_filter(s, s->current_picture.f.data[2], s->mb_width,\n                       s->mb_height  , s->uvlinesize, 0);\n    }\nec_clean:\n    for (i = 0; i < s->mb_num; i++) {\n        const int mb_xy = s->mb_index2xy[i];\n        int       error = s->error_status_table[mb_xy];\n        if (s->pict_type != AV_PICTURE_TYPE_B &&\n            (error & (ER_DC_ERROR | ER_MV_ERROR | ER_AC_ERROR))) {\n            s->mbskip_table[mb_xy] = 0;\n        }\n        s->mbintra_table[mb_xy] = 1;\n    }\n}', 'static int is_intra_more_likely(MpegEncContext *s)\n{\n    int is_intra_likely, i, j, undamaged_count, skip_amount, mb_x, mb_y;\n    if (!s->last_picture_ptr || !s->last_picture_ptr->f.data[0])\n        return 1;\n    undamaged_count = 0;\n    for (i = 0; i < s->mb_num; i++) {\n        const int mb_xy = s->mb_index2xy[i];\n        const int error = s->error_status_table[mb_xy];\n        if (!((error & ER_DC_ERROR) && (error & ER_MV_ERROR)))\n            undamaged_count++;\n    }\n    if (s->codec_id == CODEC_ID_H264) {\n        H264Context *h = (void*) s;\n        if (h->list_count <= 0 || h->ref_count[0] <= 0 ||\n            !h->ref_list[0][0].f.data[0])\n            return 1;\n    }\n    if (undamaged_count < 5)\n        return 0;\n    if (CONFIG_MPEG_XVMC_DECODER    &&\n        s->avctx->xvmc_acceleration &&\n        s->pict_type == AV_PICTURE_TYPE_I)\n        return 1;\n    skip_amount     = FFMAX(undamaged_count / 50, 1);\n    is_intra_likely = 0;\n    j = 0;\n    for (mb_y = 0; mb_y < s->mb_height - 1; mb_y++) {\n        for (mb_x = 0; mb_x < s->mb_width; mb_x++) {\n            int error;\n            const int mb_xy = mb_x + mb_y * s->mb_stride;\n            error = s->error_status_table[mb_xy];\n            if ((error & ER_DC_ERROR) && (error & ER_MV_ERROR))\n                continue;\n            j++;\n            if ((j % skip_amount) != 0)\n                continue;\n            if (s->pict_type == AV_PICTURE_TYPE_I) {\n                uint8_t *mb_ptr      = s->current_picture.f.data[0] +\n                                       mb_x * 16 + mb_y * 16 * s->linesize;\n                uint8_t *last_mb_ptr = s->last_picture.f.data[0] +\n                                       mb_x * 16 + mb_y * 16 * s->linesize;\n                if (s->avctx->codec_id == CODEC_ID_H264) {\n                } else {\n                    ff_thread_await_progress((AVFrame *) s->last_picture_ptr,\n                                             mb_y, 0);\n                }\n                is_intra_likely += s->dsp.sad[0](NULL, last_mb_ptr, mb_ptr,\n                                                 s->linesize, 16);\n                is_intra_likely -= s->dsp.sad[0](NULL, last_mb_ptr,\n                                                 last_mb_ptr + s->linesize * 16,\n                                                 s->linesize, 16);\n            } else {\n                if (IS_INTRA(s->current_picture.f.mb_type[mb_xy]))\n                   is_intra_likely++;\n                else\n                   is_intra_likely--;\n            }\n        }\n    }\n    return is_intra_likely > 0;\n}', 'static void decode_mb(MpegEncContext *s, int ref)\n{\n    s->dest[0] = s->current_picture.f.data[0] + (s->mb_y *  16                       * s->linesize)   + s->mb_x *  16;\n    s->dest[1] = s->current_picture.f.data[1] + (s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16 >> s->chroma_x_shift);\n    s->dest[2] = s->current_picture.f.data[2] + (s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16 >> s->chroma_x_shift);\n    if (CONFIG_H264_DECODER && s->codec_id == CODEC_ID_H264) {\n        H264Context *h = (void*)s;\n        h->mb_xy = s->mb_x + s->mb_y * s->mb_stride;\n        memset(h->non_zero_count_cache, 0, sizeof(h->non_zero_count_cache));\n        assert(ref >= 0);\n        if (ref >= h->ref_count[0])\n            ref = 0;\n        fill_rectangle(&s->current_picture.f.ref_index[0][4 * h->mb_xy],\n                       2, 2, 2, ref, 1);\n        fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1);\n        fill_rectangle(h->mv_cache[0][scan8[0]], 4, 4, 8,\n                       pack16to32(s->mv[0][0][0], s->mv[0][0][1]), 4);\n        assert(!FRAME_MBAFF);\n        ff_h264_hl_decode_mb(h);\n    } else {\n        assert(ref == 0);\n        MPV_decode_mb(s, s->block);\n    }\n}', 'void ff_h264_hl_decode_mb(H264Context *h){\n    MpegEncContext * const s = &h->s;\n    const int mb_xy= h->mb_xy;\n    const int mb_type = s->current_picture.f.mb_type[mb_xy];\n    int is_complex = CONFIG_SMALL || h->is_complex || IS_INTRA_PCM(mb_type) || s->qscale == 0;\n    if (CHROMA444) {\n        if(is_complex || h->pixel_shift)\n            hl_decode_mb_444_complex(h);\n        else\n            hl_decode_mb_444_simple(h);\n    } else if (is_complex) {\n        hl_decode_mb_complex(h);\n    } else if (h->pixel_shift) {\n        hl_decode_mb_simple_16(h);\n    } else\n        hl_decode_mb_simple_8(h);\n}', 'static void av_noinline hl_decode_mb_444_complex(H264Context *h){\n    hl_decode_mb_444_internal(h, 0, h->pixel_shift);\n}', 'static av_always_inline void hl_decode_mb_444_internal(H264Context *h, int simple, int pixel_shift){\n    MpegEncContext * const s = &h->s;\n    const int mb_x= s->mb_x;\n    const int mb_y= s->mb_y;\n    const int mb_xy= h->mb_xy;\n    const int mb_type = s->current_picture.f.mb_type[mb_xy];\n    uint8_t  *dest[3];\n    int linesize;\n    int i, j, p;\n    int *block_offset = &h->block_offset[0];\n    const int transform_bypass = !simple && (s->qscale == 0 && h->sps.transform_bypass);\n    const int plane_count = (simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)) ? 3 : 1;\n    for (p = 0; p < plane_count; p++)\n    {\n        dest[p] = s->current_picture.f.data[p] + ((mb_x << pixel_shift) + mb_y * s->linesize) * 16;\n        s->dsp.prefetch(dest[p] + (s->mb_x&3)*4*s->linesize + (64 << pixel_shift), s->linesize, 4);\n    }\n    h->list_counts[mb_xy]= h->list_count;\n    if (!simple && MB_FIELD) {\n        linesize   = h->mb_linesize = h->mb_uvlinesize = s->linesize * 2;\n        block_offset = &h->block_offset[48];\n        if(mb_y&1)\n            for (p = 0; p < 3; p++)\n                dest[p] -= s->linesize*15;\n        if(FRAME_MBAFF) {\n            int list;\n            for(list=0; list<h->list_count; list++){\n                if(!USES_LIST(mb_type, list))\n                    continue;\n                if(IS_16X16(mb_type)){\n                    int8_t *ref = &h->ref_cache[list][scan8[0]];\n                    fill_rectangle(ref, 4, 4, 8, (16+*ref)^(s->mb_y&1), 1);\n                }else{\n                    for(i=0; i<16; i+=4){\n                        int ref = h->ref_cache[list][scan8[i]];\n                        if(ref >= 0)\n                            fill_rectangle(&h->ref_cache[list][scan8[i]], 2, 2, 8, (16+ref)^(s->mb_y&1), 1);\n                    }\n                }\n            }\n        }\n    } else {\n        linesize   = h->mb_linesize = h->mb_uvlinesize = s->linesize;\n    }\n    if (!simple && IS_INTRA_PCM(mb_type)) {\n        if (pixel_shift) {\n            const int bit_depth = h->sps.bit_depth_luma;\n            GetBitContext gb;\n            init_get_bits(&gb, (uint8_t*)h->mb, 768*bit_depth);\n            for (p = 0; p < plane_count; p++) {\n                for (i = 0; i < 16; i++) {\n                    uint16_t *tmp = (uint16_t*)(dest[p] + i*linesize);\n                    for (j = 0; j < 16; j++)\n                        tmp[j] = get_bits(&gb, bit_depth);\n                }\n            }\n        } else {\n            for (p = 0; p < plane_count; p++) {\n                for (i = 0; i < 16; i++) {\n                    memcpy(dest[p] + i*linesize, h->mb + p*128 + i*8, 16);\n                }\n            }\n        }\n    } else {\n        if(IS_INTRA(mb_type)){\n            if(h->deblocking_filter)\n                xchg_mb_border(h, dest[0], dest[1], dest[2], linesize, linesize, 1, 1, simple, pixel_shift);\n            for (p = 0; p < plane_count; p++)\n                hl_decode_mb_predict_luma(h, mb_type, 1, simple, transform_bypass, pixel_shift, block_offset, linesize, dest[p], p);\n            if(h->deblocking_filter)\n                xchg_mb_border(h, dest[0], dest[1], dest[2], linesize, linesize, 0, 1, simple, pixel_shift);\n        }else{\n            hl_motion(h, dest[0], dest[1], dest[2],\n                      s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab,\n                      s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab,\n                      h->h264dsp.weight_h264_pixels_tab,\n                      h->h264dsp.biweight_h264_pixels_tab, pixel_shift, 3);\n        }\n        for (p = 0; p < plane_count; p++)\n            hl_decode_mb_idct_luma(h, mb_type, 1, simple, transform_bypass, pixel_shift, block_offset, linesize, dest[p], p);\n    }\n    if(h->cbp || IS_INTRA(mb_type))\n    {\n        s->dsp.clear_blocks(h->mb);\n        s->dsp.clear_blocks(h->mb+(24*16<<pixel_shift));\n    }\n}', 'static av_always_inline void hl_motion(H264Context *h, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,\n                      qpel_mc_func (*qpix_put)[16], h264_chroma_mc_func (*chroma_put),\n                      qpel_mc_func (*qpix_avg)[16], h264_chroma_mc_func (*chroma_avg),\n                      h264_weight_func *weight_op, h264_biweight_func *weight_avg,\n                      int pixel_shift, int chroma_idc)\n{\n    MpegEncContext * const s = &h->s;\n    const int mb_xy= h->mb_xy;\n    const int mb_type = s->current_picture.f.mb_type[mb_xy];\n    assert(IS_INTER(mb_type));\n    if(HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))\n        await_references(h);\n    prefetch_motion(h, 0, pixel_shift, chroma_idc);\n    if(IS_16X16(mb_type)){\n        mc_part(h, 0, 1, 16, 0, dest_y, dest_cb, dest_cr, 0, 0,\n                qpix_put[0], chroma_put[0], qpix_avg[0], chroma_avg[0],\n                weight_op, weight_avg,\n                IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1),\n                pixel_shift, chroma_idc);\n    }else if(IS_16X8(mb_type)){\n        mc_part(h, 0, 0, 8, 8 << pixel_shift, dest_y, dest_cb, dest_cr, 0, 0,\n                qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],\n                weight_op, weight_avg,\n                IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1),\n                pixel_shift, chroma_idc);\n        mc_part(h, 8, 0, 8, 8 << pixel_shift, dest_y, dest_cb, dest_cr, 0, 4,\n                qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0],\n                weight_op, weight_avg,\n                IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1),\n                pixel_shift, chroma_idc);\n    }else if(IS_8X16(mb_type)){\n        mc_part(h, 0, 0, 16, 8*h->mb_linesize, dest_y, dest_cb, dest_cr, 0, 0,\n                qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],\n                &weight_op[1], &weight_avg[1],\n                IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1),\n                pixel_shift, chroma_idc);\n        mc_part(h, 4, 0, 16, 8*h->mb_linesize, dest_y, dest_cb, dest_cr, 4, 0,\n                qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],\n                &weight_op[1], &weight_avg[1],\n                IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1),\n                pixel_shift, chroma_idc);\n    }else{\n        int i;\n        assert(IS_8X8(mb_type));\n        for(i=0; i<4; i++){\n            const int sub_mb_type= h->sub_mb_type[i];\n            const int n= 4*i;\n            int x_offset= (i&1)<<2;\n            int y_offset= (i&2)<<1;\n            if(IS_SUB_8X8(sub_mb_type)){\n                mc_part(h, n, 1, 8, 0, dest_y, dest_cb, dest_cr, x_offset, y_offset,\n                    qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1],\n                    &weight_op[1], &weight_avg[1],\n                    IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n                    pixel_shift, chroma_idc);\n            }else if(IS_SUB_8X4(sub_mb_type)){\n                mc_part(h, n  , 0, 4, 4 << pixel_shift, dest_y, dest_cb, dest_cr, x_offset, y_offset,\n                    qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],\n                    &weight_op[1], &weight_avg[1],\n                    IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n                    pixel_shift, chroma_idc);\n                mc_part(h, n+2, 0, 4, 4 << pixel_shift, dest_y, dest_cb, dest_cr, x_offset, y_offset+2,\n                    qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1],\n                    &weight_op[1], &weight_avg[1],\n                    IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n                    pixel_shift, chroma_idc);\n            }else if(IS_SUB_4X8(sub_mb_type)){\n                mc_part(h, n  , 0, 8, 4*h->mb_linesize, dest_y, dest_cb, dest_cr, x_offset, y_offset,\n                    qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],\n                    &weight_op[2], &weight_avg[2],\n                    IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n                    pixel_shift, chroma_idc);\n                mc_part(h, n+1, 0, 8, 4*h->mb_linesize, dest_y, dest_cb, dest_cr, x_offset+2, y_offset,\n                    qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],\n                    &weight_op[2], &weight_avg[2],\n                    IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n                    pixel_shift, chroma_idc);\n            }else{\n                int j;\n                assert(IS_SUB_4X4(sub_mb_type));\n                for(j=0; j<4; j++){\n                    int sub_x_offset= x_offset + 2*(j&1);\n                    int sub_y_offset= y_offset +   (j&2);\n                    mc_part(h, n+j, 1, 4, 0, dest_y, dest_cb, dest_cr, sub_x_offset, sub_y_offset,\n                        qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2],\n                        &weight_op[2], &weight_avg[2],\n                        IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1),\n                        pixel_shift, chroma_idc);\n                }\n            }\n        }\n    }\n    prefetch_motion(h, 1, pixel_shift, chroma_idc);\n}', 'static void await_references(H264Context *h){\n    MpegEncContext * const s = &h->s;\n    const int mb_xy= h->mb_xy;\n    const int mb_type = s->current_picture.f.mb_type[mb_xy];\n    int refs[2][48];\n    int nrefs[2] = {0};\n    int ref, list;\n    memset(refs, -1, sizeof(refs));\n    if(IS_16X16(mb_type)){\n        get_lowest_part_y(h, refs, 0, 16, 0,\n                  IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);\n    }else if(IS_16X8(mb_type)){\n        get_lowest_part_y(h, refs, 0, 8, 0,\n                  IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);\n        get_lowest_part_y(h, refs, 8, 8, 8,\n                  IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs);\n    }else if(IS_8X16(mb_type)){\n        get_lowest_part_y(h, refs, 0, 16, 0,\n                  IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs);\n        get_lowest_part_y(h, refs, 4, 16, 0,\n                  IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs);\n    }else{\n        int i;\n        assert(IS_8X8(mb_type));\n        for(i=0; i<4; i++){\n            const int sub_mb_type= h->sub_mb_type[i];\n            const int n= 4*i;\n            int y_offset= (i&2)<<2;\n            if(IS_SUB_8X8(sub_mb_type)){\n                get_lowest_part_y(h, refs, n  , 8, y_offset,\n                          IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);\n            }else if(IS_SUB_8X4(sub_mb_type)){\n                get_lowest_part_y(h, refs, n  , 4, y_offset,\n                          IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);\n                get_lowest_part_y(h, refs, n+2, 4, y_offset+4,\n                          IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);\n            }else if(IS_SUB_4X8(sub_mb_type)){\n                get_lowest_part_y(h, refs, n  , 8, y_offset,\n                          IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);\n                get_lowest_part_y(h, refs, n+1, 8, y_offset,\n                          IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);\n            }else{\n                int j;\n                assert(IS_SUB_4X4(sub_mb_type));\n                for(j=0; j<4; j++){\n                    int sub_y_offset= y_offset + 2*(j&2);\n                    get_lowest_part_y(h, refs, n+j, 4, sub_y_offset,\n                              IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs);\n                }\n            }\n        }\n    }\n    for(list=h->list_count-1; list>=0; list--){\n        for(ref=0; ref<48 && nrefs[list]; ref++){\n            int row = refs[list][ref];\n            if(row >= 0){\n                Picture *ref_pic = &h->ref_list[list][ref];\n                int ref_field = ref_pic->f.reference - 1;\n                int ref_field_picture = ref_pic->field_picture;\n                int pic_height = 16*s->mb_height >> ref_field_picture;\n                row <<= MB_MBAFF;\n                nrefs[list]--;\n                if(!FIELD_PICTURE && ref_field_picture){\n                    ff_thread_await_progress((AVFrame*)ref_pic, FFMIN((row >> 1) - !(row&1), pic_height-1), 1);\n                    ff_thread_await_progress((AVFrame*)ref_pic, FFMIN((row >> 1)           , pic_height-1), 0);\n                }else if(FIELD_PICTURE && !ref_field_picture){\n                    ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row*2 + ref_field    , pic_height-1), 0);\n                }else if(FIELD_PICTURE){\n                    ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), ref_field);\n                }else{\n                    ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), 0);\n                }\n            }\n        }\n    }\n}']