libavcodec/h264dec.c:717: error: Integer Overflow L2
  ([8, 2147483648] + [8, 2147483648]):signed32 by call to `decode_nal_units`.

libavcodec/h264dec.c:717:17: Call
715.     }
716. 
717.     buf_index = decode_nal_units(h, buf, buf_size);
                     ^
718.     if (buf_index < 0)
719.         return AVERROR_INVALIDDATA;

libavcodec/h264dec.c:521:11: Call
  519.     }
  520. 
  521.     ret = ff_h2645_packet_split(&h->pkt, buf, buf_size, avctx, h->is_avc,
                 ^
  522.                                 h->nal_length_size, avctx->codec_id);
  523.     if (ret < 0) {

libavcodec/h2645_parse.c:301:15: Call
    299.         nal->size_bits = get_bit_length(nal, skip_trailing_zeros);
    300. 
    301.         ret = init_get_bits(&nal->gb, nal->data, nal->size_bits);
                       ^
    302.         if (ret < 0)
    303.             return ret;

libavcodec/get_bits.h:362:1: Parameter `bit_size`
      360.  * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow.
      361.  */
      362. static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,
           ^
      363.                                 int bit_size)
      364. {

libavcodec/get_bits.h:379:5: Assignment
      377.     s->size_in_bits       = bit_size;
      378. #if !UNCHECKED_BITSTREAM_READER
      379.     s->size_in_bits_plus8 = bit_size + 8;
               ^
      380. #endif
      381.     s->buffer_end         = buffer + buffer_size;

libavcodec/h264dec.c:717:17: Call
715.     }
716. 
717.     buf_index = decode_nal_units(h, buf, buf_size);
                     ^
718.     if (buf_index < 0)
719.         return AVERROR_INVALIDDATA;

libavcodec/h264dec.c:508:1: Parameter `*h->cur_pic.qscale_table`
  506. }
  507. 
  508. static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size)
       ^
  509. {
  510.     AVCodecContext *const avctx = h->avctx;

libavcodec/h264dec.c:608:11: Call
  606.     }
  607. 
  608.     ret = ff_h264_execute_decode_slices(h);
                 ^
  609.     if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
  610.         goto end;

libavcodec/h264_slice.c:2488:1: Parameter `*h->cur_pic.qscale_table`
    2486.  * @param h h264 master context
    2487.  */
    2488. int ff_h264_execute_decode_slices(H264Context *h)
          ^
    2489. {
    2490.     AVCodecContext *const avctx = h->avctx;

libavcodec/h264_slice.c:2549:21: Call
    2547.                 for (j = sl->resync_mb_y; j < y_end; j += 1 + FIELD_OR_MBAFF_PICTURE(h)) {
    2548.                     sl->mb_y = j;
    2549.                     loop_filter(h, sl, j > sl->resync_mb_y ? 0 : sl->resync_mb_x,
                              ^
    2550.                                 j == y_end - 1 ? x_end : h->mb_width);
    2551.                 }

libavcodec/h264_slice.c:2165:1: Parameter `*h->cur_pic.qscale_table`
      2163. }
      2164. 
      2165. static void loop_filter(const H264Context *h, H264SliceContext *sl, int start_x, int end_x)
            ^
      2166. {
      2167.     uint8_t *dest_y, *dest_cb, *dest_cr;

libavcodec/h264_slice.c:2223:21: Call
      2221.                                       linesize, uvlinesize);
      2222.                 } else {
      2223.                     ff_h264_filter_mb_fast(h, sl, mb_x, mb_y, dest_y, dest_cb,
                                ^
      2224.                                            dest_cr, linesize, uvlinesize);
      2225.                 }

libavcodec/h264_loopfilter.c:420:1: Parameter `*h->cur_pic.qscale_table`
        418. }
        419. 
        420. void ff_h264_filter_mb_fast(const H264Context *h, H264SliceContext *sl,
             ^
        421.                             int mb_x, int mb_y, uint8_t *img_y,
        422.                             uint8_t *img_cb, uint8_t *img_cr,

libavcodec/h264_loopfilter.c:427:9: Call
        425.     assert(!FRAME_MBAFF(h));
        426.     if(!h->h264dsp.h264_loop_filter_strength || h->ps.pps->chroma_qp_diff) {
        427.         ff_h264_filter_mb(h, sl, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize);
                     ^
        428.         return;
        429.     }

libavcodec/h264_loopfilter.c:716:1: Parameter `*h->cur_pic.qscale_table`
          714. }
          715. 
          716. void ff_h264_filter_mb(const H264Context *h, H264SliceContext *sl,
               ^
          717.                        int mb_x, int mb_y,
          718.                        uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr,

libavcodec/h264_loopfilter.c:844:5: Call
          842.     }
          843. #else
          844.     filter_mb_dir(h, sl, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, first_vertical_edge_done, a, b, chroma, 0);
                   ^
          845.     filter_mb_dir(h, sl, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, 0,                        a, b, chroma, 1);
          846. #endif

libavcodec/h264_loopfilter.c:472:1: <LHS trace>
470. }
471. 
472. static av_always_inline void filter_mb_dir(const H264Context *h, H264SliceContext *sl,
     ^
473.                                            int mb_x, int mb_y,
474.                                            uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr,

libavcodec/h264_loopfilter.c:472:1: Parameter `*h->cur_pic.qscale_table`
            470. }
            471. 
            472. static av_always_inline void filter_mb_dir(const H264Context *h, H264SliceContext *sl,
                 ^
            473.                                            int mb_x, int mb_y,
            474.                                            uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr,

libavcodec/h264_loopfilter.c:472:1: <RHS trace>
470. }
471. 
472. static av_always_inline void filter_mb_dir(const H264Context *h, H264SliceContext *sl,
     ^
473.                                            int mb_x, int mb_y,
474.                                            uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr,

libavcodec/h264_loopfilter.c:472:1: Parameter `*h->cur_pic.qscale_table`
            470. }
            471. 
            472. static av_always_inline void filter_mb_dir(const H264Context *h, H264SliceContext *sl,
                 ^
            473.                                            int mb_x, int mb_y,
            474.                                            uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr,

libavcodec/h264_loopfilter.c:531:17: Binary operation: ([8, 2147483648] + [8, 2147483648]):signed32 by call to `decode_nal_units` 
            529.                 // Do not use s->qscale as luma quantizer because it has not the same
            530.                 // value in IPCM macroblocks.
            531.                 qp = (h->cur_pic.qscale_table[mb_xy] + h->cur_pic.qscale_table[mbn_xy] + 1) >> 1;
                                 ^
            532.                 ff_tlog(h->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, tmp_linesize, tmp_uvlinesize);
            533.                 { int i; for (i = 0; i < 4; i++) ff_tlog(h->avctx, " bS[%d]:%d", i, bS[i]); ff_tlog(h->avctx, "\n"); }

static av_always_inline void filter_mb_dir(const H264Context *h, H264SliceContext *sl,
                                           int mb_x, int mb_y,
                                           uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr,
                                           unsigned int linesize, unsigned int uvlinesize,
                                           int mb_xy, int mb_type, int mvy_limit,
                                           int first_vertical_edge_done, int a, int b,
                                           int chroma, int dir)
{
    int edge;
    int chroma_qp_avg[2];
    int chroma444 = CHROMA444(h);
    int chroma422 = CHROMA422(h);
    const int mbm_xy = dir == 0 ? mb_xy -1 : sl->top_mb_xy;
    const int mbm_type = dir == 0 ? sl->left_type[LTOP] : sl->top_type;
    static const uint8_t mask_edge_tab[2][8]={{0,3,3,3,1,1,1,1},
                                              {0,3,1,1,3,3,3,3}};
    const int mask_edge = mask_edge_tab[dir][(mb_type>>3)&7];
    const int edges = mask_edge== 3 && !(sl->cbp&15) ? 1 : 4;
    const int mask_par0 = mb_type & (MB_TYPE_16x16 | (MB_TYPE_8x16 >> dir));
    if(mbm_type && !first_vertical_edge_done){
        if (FRAME_MBAFF(h) && (dir == 1) && ((mb_y&1) == 0)
            && IS_INTERLACED(mbm_type&~mb_type)
            ) {
            unsigned int tmp_linesize   = 2 *   linesize;
            unsigned int tmp_uvlinesize = 2 * uvlinesize;
            int mbn_xy = mb_xy - 2 * h->mb_stride;
            int j;
            for(j=0; j<2; j++, mbn_xy += h->mb_stride){
                DECLARE_ALIGNED(8, int16_t, bS)[4];
                int qp;
                if (IS_INTRA(mb_type | h->cur_pic.mb_type[mbn_xy])) {
                    AV_WN64A(bS, 0x0003000300030003ULL);
                } else {
                    if (!CABAC(h) && IS_8x8DCT(h->cur_pic.mb_type[mbn_xy])) {
                        bS[0]= 1+((h->cbp_table[mbn_xy] & 0x4000) || sl->non_zero_count_cache[scan8[0]+0]);
                        bS[1]= 1+((h->cbp_table[mbn_xy] & 0x4000) || sl->non_zero_count_cache[scan8[0]+1]);
                        bS[2]= 1+((h->cbp_table[mbn_xy] & 0x8000) || sl->non_zero_count_cache[scan8[0]+2]);
                        bS[3]= 1+((h->cbp_table[mbn_xy] & 0x8000) || sl->non_zero_count_cache[scan8[0]+3]);
                    }else{
                    const uint8_t *mbn_nnz = h->non_zero_count[mbn_xy] + 3*4;
                    int i;
                    for( i = 0; i < 4; i++ ) {
                        bS[i] = 1 + !!(sl->non_zero_count_cache[scan8[0]+i] | mbn_nnz[i]);
                    }
                    }
                }
                qp = (h->cur_pic.qscale_table[mb_xy] + h->cur_pic.qscale_table[mbn_xy] + 1) >> 1;
                ff_tlog(h->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, tmp_linesize, tmp_uvlinesize);
                { int i; for (i = 0; i < 4; i++) ff_tlog(h->avctx, " bS[%d]:%d", i, bS[i]); ff_tlog(h->avctx, "\n"); }
                filter_mb_edgeh( &img_y[j*linesize], tmp_linesize, bS, qp, a, b, h, 0 );
                chroma_qp_avg[0] = (sl->chroma_qp[0] + get_chroma_qp(h->ps.pps, 0, h->cur_pic.qscale_table[mbn_xy]) + 1) >> 1;
                chroma_qp_avg[1] = (sl->chroma_qp[1] + get_chroma_qp(h->ps.pps, 1, h->cur_pic.qscale_table[mbn_xy]) + 1) >> 1;
                if (chroma) {
                    if (chroma444) {
                        filter_mb_edgeh (&img_cb[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[0], a, b, h, 0);
                        filter_mb_edgeh (&img_cr[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[1], a, b, h, 0);
                    } else {
                        filter_mb_edgech(&img_cb[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[0], a, b, h, 0);
                        filter_mb_edgech(&img_cr[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[1], a, b, h, 0);
                    }
                }
            }
        }else{
            DECLARE_ALIGNED(8, int16_t, bS)[4];
            int qp;
            if( IS_INTRA(mb_type|mbm_type)) {
                AV_WN64A(bS, 0x0003000300030003ULL);
                if (   (!IS_INTERLACED(mb_type|mbm_type))
                    || ((FRAME_MBAFF(h) || (h->picture_structure != PICT_FRAME)) && (dir == 0))
                )
                    AV_WN64A(bS, 0x0004000400040004ULL);
            } else {
                int i;
                int mv_done;
                if( dir && FRAME_MBAFF(h) && IS_INTERLACED(mb_type ^ mbm_type)) {
                    AV_WN64A(bS, 0x0001000100010001ULL);
                    mv_done = 1;
                }
                else if( mask_par0 && ((mbm_type & (MB_TYPE_16x16 | (MB_TYPE_8x16 >> dir)))) ) {
                    int b_idx= 8 + 4;
                    int bn_idx= b_idx - (dir ? 8:1);
                    bS[0] = bS[1] = bS[2] = bS[3] = check_mv(sl, 8 + 4, bn_idx, mvy_limit);
                    mv_done = 1;
                }
                else
                    mv_done = 0;
                for( i = 0; i < 4; i++ ) {
                    int x = dir == 0 ? 0 : i;
                    int y = dir == 0 ? i    : 0;
                    int b_idx= 8 + 4 + x + 8*y;
                    int bn_idx= b_idx - (dir ? 8:1);
                    if (sl->non_zero_count_cache[b_idx] |
                        sl->non_zero_count_cache[bn_idx]) {
                        bS[i] = 2;
                    }
                    else if(!mv_done)
                    {
                        bS[i] = check_mv(sl, b_idx, bn_idx, mvy_limit);
                    }
                }
            }
            if(bS[0]+bS[1]+bS[2]+bS[3]){
                qp = (h->cur_pic.qscale_table[mb_xy] + h->cur_pic.qscale_table[mbm_xy] + 1) >> 1;
                ff_tlog(h->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize);
                chroma_qp_avg[0] = (sl->chroma_qp[0] + get_chroma_qp(h->ps.pps, 0, h->cur_pic.qscale_table[mbm_xy]) + 1) >> 1;
                chroma_qp_avg[1] = (sl->chroma_qp[1] + get_chroma_qp(h->ps.pps, 1, h->cur_pic.qscale_table[mbm_xy]) + 1) >> 1;
                if( dir == 0 ) {
                    filter_mb_edgev( &img_y[0], linesize, bS, qp, a, b, h, 1 );
                    if (chroma) {
                        if (chroma444) {
                            filter_mb_edgev ( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], a, b, h, 1);
                            filter_mb_edgev ( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], a, b, h, 1);
                        } else {
                            filter_mb_edgecv( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], a, b, h, 1);
                            filter_mb_edgecv( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], a, b, h, 1);
                        }
                    }
                } else {
                    filter_mb_edgeh( &img_y[0], linesize, bS, qp, a, b, h, 1 );
                    if (chroma) {
                        if (chroma444) {
                            filter_mb_edgeh ( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], a, b, h, 1);
                            filter_mb_edgeh ( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], a, b, h, 1);
                        } else {
                            filter_mb_edgech( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], a, b, h, 1);
                            filter_mb_edgech( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], a, b, h, 1);
                        }
                    }
                }
            }
        }
    }
    for( edge = 1; edge < edges; edge++ ) {
        DECLARE_ALIGNED(8, int16_t, bS)[4];
        int qp;
        const int deblock_edge = !IS_8x8DCT(mb_type & (edge<<24));
        if (!deblock_edge && (!chroma422 || dir == 0))
            continue;
        if( IS_INTRA(mb_type)) {
            AV_WN64A(bS, 0x0003000300030003ULL);
        } else {
            int i;
            int mv_done;
            if( edge & mask_edge ) {
                AV_ZERO64(bS);
                mv_done = 1;
            }
            else if( mask_par0 ) {
                int b_idx= 8 + 4 + edge * (dir ? 8:1);
                int bn_idx= b_idx - (dir ? 8:1);
                bS[0] = bS[1] = bS[2] = bS[3] = check_mv(sl, b_idx, bn_idx, mvy_limit);
                mv_done = 1;
            }
            else
                mv_done = 0;
            for( i = 0; i < 4; i++ ) {
                int x = dir == 0 ? edge : i;
                int y = dir == 0 ? i    : edge;
                int b_idx= 8 + 4 + x + 8*y;
                int bn_idx= b_idx - (dir ? 8:1);
                if (sl->non_zero_count_cache[b_idx] |
                    sl->non_zero_count_cache[bn_idx]) {
                    bS[i] = 2;
                }
                else if(!mv_done)
                {
                    bS[i] = check_mv(sl, b_idx, bn_idx, mvy_limit);
                }
            }
            if(bS[0]+bS[1]+bS[2]+bS[3] == 0)
                continue;
        }
        qp = h->cur_pic.qscale_table[mb_xy];
        ff_tlog(h->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize);
        if( dir == 0 ) {
            filter_mb_edgev( &img_y[4*edge << h->pixel_shift], linesize, bS, qp, a, b, h, 0 );
            if (chroma) {
                if (chroma444) {
                    filter_mb_edgev ( &img_cb[4*edge << h->pixel_shift], uvlinesize, bS, sl->chroma_qp[0], a, b, h, 0);
                    filter_mb_edgev ( &img_cr[4*edge << h->pixel_shift], uvlinesize, bS, sl->chroma_qp[1], a, b, h, 0);
                } else if( (edge&1) == 0 ) {
                    filter_mb_edgecv( &img_cb[2*edge << h->pixel_shift], uvlinesize, bS, sl->chroma_qp[0], a, b, h, 0);
                    filter_mb_edgecv( &img_cr[2*edge << h->pixel_shift], uvlinesize, bS, sl->chroma_qp[1], a, b, h, 0);
                }
            }
        } else {
            if (chroma422) {
                if (deblock_edge)
                    filter_mb_edgeh(&img_y[4*edge*linesize], linesize, bS, qp, a, b, h, 0);
                if (chroma) {
                    filter_mb_edgech(&img_cb[4*edge*uvlinesize], uvlinesize, bS, sl->chroma_qp[0], a, b, h, 0);
                    filter_mb_edgech(&img_cr[4*edge*uvlinesize], uvlinesize, bS, sl->chroma_qp[1], a, b, h, 0);
                }
            } else {
                filter_mb_edgeh(&img_y[4*edge*linesize], linesize, bS, qp, a, b, h, 0);
                if (chroma) {
                    if (chroma444) {
                        filter_mb_edgeh (&img_cb[4*edge*uvlinesize], uvlinesize, bS, sl->chroma_qp[0], a, b, h, 0);
                        filter_mb_edgeh (&img_cr[4*edge*uvlinesize], uvlinesize, bS, sl->chroma_qp[1], a, b, h, 0);
                    } else if ((edge&1) == 0) {
                        filter_mb_edgech(&img_cb[2*edge*uvlinesize], uvlinesize, bS, sl->chroma_qp[0], a, b, h, 0);
                        filter_mb_edgech(&img_cr[2*edge*uvlinesize], uvlinesize, bS, sl->chroma_qp[1], a, b, h, 0);
                    }
                }
            }
        }
    }
}
['static int h264_decode_frame(AVCodecContext *avctx, void *data,\n                             int *got_frame, AVPacket *avpkt)\n{\n    const uint8_t *buf = avpkt->data;\n    int buf_size       = avpkt->size;\n    H264Context *h     = avctx->priv_data;\n    AVFrame *pict      = data;\n    int buf_index      = 0;\n    int ret;\n    const uint8_t *new_extradata;\n    int new_extradata_size;\n    h->flags = avctx->flags;\n    h->setup_finished = 0;\n    h->nb_slice_ctx_queued = 0;\nout:\n    if (buf_size == 0) {\n        H264Picture *out;\n        int i, out_idx;\n        h->cur_pic_ptr = NULL;\n        out     = h->delayed_pic[0];\n        out_idx = 0;\n        for (i = 1;\n             h->delayed_pic[i] &&\n             !h->delayed_pic[i]->f->key_frame &&\n             !h->delayed_pic[i]->mmco_reset;\n             i++)\n            if (h->delayed_pic[i]->poc < out->poc) {\n                out     = h->delayed_pic[i];\n                out_idx = i;\n            }\n        for (i = out_idx; h->delayed_pic[i]; i++)\n            h->delayed_pic[i] = h->delayed_pic[i + 1];\n        if (out) {\n            ret = output_frame(h, pict, out->f);\n            if (ret < 0)\n                return ret;\n            *got_frame = 1;\n        }\n        return buf_index;\n    }\n    new_extradata_size = 0;\n    new_extradata = av_packet_get_side_data(avpkt, AV_PKT_DATA_NEW_EXTRADATA,\n                                            &new_extradata_size);\n    if (new_extradata_size > 0 && new_extradata) {\n        ret = ff_h264_decode_extradata(new_extradata, new_extradata_size,\n                                       &h->ps, &h->is_avc, &h->nal_length_size,\n                                       avctx->err_recognition, avctx);\n        if (ret < 0)\n            return ret;\n    }\n    buf_index = decode_nal_units(h, buf, buf_size);\n    if (buf_index < 0)\n        return AVERROR_INVALIDDATA;\n    if (!h->cur_pic_ptr && h->nal_unit_type == H264_NAL_END_SEQUENCE) {\n        buf_size = 0;\n        goto out;\n    }\n    if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS) && !h->cur_pic_ptr) {\n        if (avctx->skip_frame >= AVDISCARD_NONREF)\n            return 0;\n        av_log(avctx, AV_LOG_ERROR, "no frame!\\n");\n        return AVERROR_INVALIDDATA;\n    }\n    if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS) ||\n        (h->mb_y >= h->mb_height && h->mb_height)) {\n        ff_h264_field_end(h, &h->slice_ctx[0], 0);\n        *got_frame = 0;\n        if (h->output_frame->buf[0]) {\n            ret = output_frame(h, pict, h->output_frame) ;\n            av_frame_unref(h->output_frame);\n            if (ret < 0)\n                return ret;\n            *got_frame = 1;\n        }\n    }\n    assert(pict->buf[0] || !*got_frame);\n    return get_consumed_bytes(buf_index, buf_size);\n}', 'static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size)\n{\n    AVCodecContext *const avctx = h->avctx;\n    int nals_needed = 0;\n    int i, ret = 0;\n    if (!(avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) {\n        h->current_slice = 0;\n        if (!h->first_field)\n            h->cur_pic_ptr = NULL;\n        ff_h264_sei_uninit(&h->sei);\n    }\n    ret = ff_h2645_packet_split(&h->pkt, buf, buf_size, avctx, h->is_avc,\n                                h->nal_length_size, avctx->codec_id);\n    if (ret < 0) {\n        av_log(avctx, AV_LOG_ERROR,\n               "Error splitting the input into NAL units.\\n");\n        return ret;\n    }\n    if (avctx->active_thread_type & FF_THREAD_FRAME)\n        nals_needed = get_last_needed_nal(h);\n    for (i = 0; i < h->pkt.nb_nals; i++) {\n        H2645NAL *nal = &h->pkt.nals[i];\n        int max_slice_ctx, err;\n        if (avctx->skip_frame >= AVDISCARD_NONREF &&\n            nal->ref_idc == 0 && nal->type != H264_NAL_SEI)\n            continue;\n        h->nal_ref_idc   = nal->ref_idc;\n        h->nal_unit_type = nal->type;\n        err = 0;\n        switch (nal->type) {\n        case H264_NAL_IDR_SLICE:\n            idr(h);\n        case H264_NAL_SLICE:\n            if ((err = ff_h264_queue_decode_slice(h, nal)))\n                break;\n            if (avctx->active_thread_type & FF_THREAD_FRAME && !h->avctx->hwaccel &&\n                i >= nals_needed) {\n                ff_thread_finish_setup(avctx);\n                h->setup_finished = 1;\n            }\n            max_slice_ctx = avctx->hwaccel ? 1 : h->nb_slice_ctx;\n            if (h->nb_slice_ctx_queued == max_slice_ctx) {\n                if (avctx->hwaccel)\n                    ret = avctx->hwaccel->decode_slice(avctx, nal->raw_data, nal->raw_size);\n                else\n                    ret = ff_h264_execute_decode_slices(h);\n                if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n                    goto end;\n            }\n            break;\n        case H264_NAL_DPA:\n        case H264_NAL_DPB:\n        case H264_NAL_DPC:\n            avpriv_request_sample(avctx, "data partitioning");\n            ret = AVERROR(ENOSYS);\n            goto end;\n            break;\n        case H264_NAL_SEI:\n            ret = ff_h264_sei_decode(&h->sei, &nal->gb, &h->ps, avctx);\n            if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n                goto end;\n            break;\n        case H264_NAL_SPS:\n            ret = ff_h264_decode_seq_parameter_set(&nal->gb, avctx, &h->ps);\n            if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n                goto end;\n            break;\n        case H264_NAL_PPS:\n            ret = ff_h264_decode_picture_parameter_set(&nal->gb, avctx, &h->ps,\n                                                       nal->size_bits);\n            if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n                goto end;\n            break;\n        case H264_NAL_AUD:\n        case H264_NAL_END_SEQUENCE:\n        case H264_NAL_END_STREAM:\n        case H264_NAL_FILLER_DATA:\n        case H264_NAL_SPS_EXT:\n        case H264_NAL_AUXILIARY_SLICE:\n            break;\n        default:\n            av_log(avctx, AV_LOG_DEBUG, "Unknown NAL code: %d (%d bits)\\n",\n                   nal->type, nal->size_bits);\n        }\n        if (err < 0) {\n            av_log(h->avctx, AV_LOG_ERROR, "decode_slice_header error\\n");\n        }\n    }\n    ret = ff_h264_execute_decode_slices(h);\n    if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))\n        goto end;\n    ret = 0;\nend:\n    if (h->cur_pic_ptr && !h->droppable) {\n        ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,\n                                  h->picture_structure == PICT_BOTTOM_FIELD);\n    }\n    return (ret < 0) ? ret : buf_size;\n}', 'int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length,\n                          void *logctx, int is_nalff, int nal_length_size,\n                          enum AVCodecID codec_id)\n{\n    int consumed, ret = 0;\n    const uint8_t *next_avc = buf + (is_nalff ? 0 : length);\n    pkt->nb_nals = 0;\n    while (length >= 4) {\n        H2645NAL *nal;\n        int extract_length = 0;\n        int skip_trailing_zeros = 1;\n        if (buf == next_avc) {\n            int i;\n            for (i = 0; i < nal_length_size; i++)\n                extract_length = (extract_length << 8) | buf[i];\n            if (extract_length > length) {\n                av_log(logctx, AV_LOG_ERROR,\n                       "Invalid NAL unit size (%d > %d).\\n",\n                       extract_length, length);\n                return AVERROR_INVALIDDATA;\n            }\n            buf     += nal_length_size;\n            length  -= nal_length_size;\n            next_avc = buf + extract_length;\n        } else {\n            int buf_index = find_next_start_code(buf, next_avc);\n            buf    += buf_index;\n            length -= buf_index;\n            if (buf == next_avc)\n                continue;\n            if (length > 0) {\n                extract_length = length;\n            } else if (pkt->nb_nals == 0) {\n                av_log(logctx, AV_LOG_ERROR, "No NAL unit found\\n");\n                return AVERROR_INVALIDDATA;\n            } else {\n                break;\n            }\n        }\n        if (pkt->nals_allocated < pkt->nb_nals + 1) {\n            int new_size = pkt->nals_allocated + 1;\n            H2645NAL *tmp = av_realloc_array(pkt->nals, new_size, sizeof(*tmp));\n            if (!tmp)\n                return AVERROR(ENOMEM);\n            pkt->nals = tmp;\n            memset(pkt->nals + pkt->nals_allocated, 0,\n                   (new_size - pkt->nals_allocated) * sizeof(*tmp));\n            pkt->nals_allocated = new_size;\n        }\n        nal = &pkt->nals[pkt->nb_nals++];\n        consumed = ff_h2645_extract_rbsp(buf, extract_length, nal);\n        if (consumed < 0)\n            return consumed;\n        if (consumed < length - 3 &&\n            buf[consumed]     == 0x00 && buf[consumed + 1] == 0x00 &&\n            buf[consumed + 2] == 0x01 && buf[consumed + 3] == 0xE0)\n            skip_trailing_zeros = 0;\n        nal->size_bits = get_bit_length(nal, skip_trailing_zeros);\n        ret = init_get_bits(&nal->gb, nal->data, nal->size_bits);\n        if (ret < 0)\n            return ret;\n        if (codec_id == AV_CODEC_ID_HEVC)\n            ret = hevc_parse_nal_header(nal, logctx);\n        else\n            ret = h264_parse_nal_header(nal, logctx);\n        if (ret <= 0) {\n            if (ret < 0) {\n                av_log(logctx, AV_LOG_ERROR, "Invalid NAL unit %d, skipping.\\n",\n                       nal->type);\n            }\n            pkt->nb_nals--;\n        }\n        buf    += consumed;\n        length -= consumed;\n    }\n    return 0;\n}', 'static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,\n                                int bit_size)\n{\n    int buffer_size;\n    int ret = 0;\n    if (bit_size > INT_MAX - 7 || bit_size < 0 || !buffer) {\n        bit_size    = 0;\n        buffer      = NULL;\n        ret         = AVERROR_INVALIDDATA;\n    }\n    buffer_size = (bit_size + 7) >> 3;\n    s->buffer             = buffer;\n    s->size_in_bits       = bit_size;\n#if !UNCHECKED_BITSTREAM_READER\n    s->size_in_bits_plus8 = bit_size + 8;\n#endif\n    s->buffer_end         = buffer + buffer_size;\n    s->index              = 0;\n    return ret;\n}', 'int ff_h264_execute_decode_slices(H264Context *h)\n{\n    AVCodecContext *const avctx = h->avctx;\n    H264SliceContext *sl;\n    int context_count = h->nb_slice_ctx_queued;\n    int ret = 0;\n    int i, j;\n    if (h->avctx->hwaccel || context_count < 1)\n        return 0;\n    if (context_count == 1) {\n        h->slice_ctx[0].next_slice_idx = h->mb_width * h->mb_height;\n        h->postpone_filter = 0;\n        ret = decode_slice(avctx, &h->slice_ctx[0]);\n        h->mb_y = h->slice_ctx[0].mb_y;\n        if (ret < 0)\n            goto finish;\n    } else {\n        for (i = 0; i < context_count; i++) {\n            int next_slice_idx = h->mb_width * h->mb_height;\n            int slice_idx;\n            sl                 = &h->slice_ctx[i];\n            sl->er.error_count = 0;\n            slice_idx = sl->mb_y * h->mb_width + sl->mb_x;\n            for (j = 0; j < context_count; j++) {\n                H264SliceContext *sl2 = &h->slice_ctx[j];\n                int        slice_idx2 = sl2->mb_y * h->mb_width + sl2->mb_x;\n                if (i == j || slice_idx2 < slice_idx)\n                    continue;\n                next_slice_idx = FFMIN(next_slice_idx, slice_idx2);\n            }\n            sl->next_slice_idx = next_slice_idx;\n        }\n        avctx->execute(avctx, decode_slice, h->slice_ctx,\n                       NULL, context_count, sizeof(h->slice_ctx[0]));\n        sl                   = &h->slice_ctx[context_count - 1];\n        h->mb_y              = sl->mb_y;\n        for (i = 1; i < context_count; i++)\n            h->slice_ctx[0].er.error_count += h->slice_ctx[i].er.error_count;\n        if (h->postpone_filter) {\n            h->postpone_filter = 0;\n            for (i = 0; i < context_count; i++) {\n                int y_end, x_end;\n                sl = &h->slice_ctx[i];\n                y_end = FFMIN(sl->mb_y + 1, h->mb_height);\n                x_end = (sl->mb_y >= h->mb_height) ? h->mb_width : sl->mb_x;\n                for (j = sl->resync_mb_y; j < y_end; j += 1 + FIELD_OR_MBAFF_PICTURE(h)) {\n                    sl->mb_y = j;\n                    loop_filter(h, sl, j > sl->resync_mb_y ? 0 : sl->resync_mb_x,\n                                j == y_end - 1 ? x_end : h->mb_width);\n                }\n            }\n        }\n    }\nfinish:\n    h->nb_slice_ctx_queued = 0;\n    return ret;\n}', 'static void loop_filter(const H264Context *h, H264SliceContext *sl, int start_x, int end_x)\n{\n    uint8_t *dest_y, *dest_cb, *dest_cr;\n    int linesize, uvlinesize, mb_x, mb_y;\n    const int end_mb_y       = sl->mb_y + FRAME_MBAFF(h);\n    const int old_slice_type = sl->slice_type;\n    const int pixel_shift    = h->pixel_shift;\n    const int block_h        = 16 >> h->chroma_y_shift;\n    if (h->postpone_filter)\n        return;\n    if (sl->deblocking_filter) {\n        for (mb_x = start_x; mb_x < end_x; mb_x++)\n            for (mb_y = end_mb_y - FRAME_MBAFF(h); mb_y <= end_mb_y; mb_y++) {\n                int mb_xy, mb_type;\n                mb_xy         = sl->mb_xy = mb_x + mb_y * h->mb_stride;\n                mb_type       = h->cur_pic.mb_type[mb_xy];\n                if (FRAME_MBAFF(h))\n                    sl->mb_mbaff               =\n                    sl->mb_field_decoding_flag = !!IS_INTERLACED(mb_type);\n                sl->mb_x = mb_x;\n                sl->mb_y = mb_y;\n                dest_y  = h->cur_pic.f->data[0] +\n                          ((mb_x << pixel_shift) + mb_y * sl->linesize) * 16;\n                dest_cb = h->cur_pic.f->data[1] +\n                          (mb_x << pixel_shift) * (8 << CHROMA444(h)) +\n                          mb_y * sl->uvlinesize * block_h;\n                dest_cr = h->cur_pic.f->data[2] +\n                          (mb_x << pixel_shift) * (8 << CHROMA444(h)) +\n                          mb_y * sl->uvlinesize * block_h;\n                if (MB_FIELD(sl)) {\n                    linesize   = sl->mb_linesize   = sl->linesize   * 2;\n                    uvlinesize = sl->mb_uvlinesize = sl->uvlinesize * 2;\n                    if (mb_y & 1) {\n                        dest_y  -= sl->linesize   * 15;\n                        dest_cb -= sl->uvlinesize * (block_h - 1);\n                        dest_cr -= sl->uvlinesize * (block_h - 1);\n                    }\n                } else {\n                    linesize   = sl->mb_linesize   = sl->linesize;\n                    uvlinesize = sl->mb_uvlinesize = sl->uvlinesize;\n                }\n                backup_mb_border(h, sl, dest_y, dest_cb, dest_cr, linesize,\n                                 uvlinesize, 0);\n                if (fill_filter_caches(h, sl, mb_type))\n                    continue;\n                sl->chroma_qp[0] = get_chroma_qp(h->ps.pps, 0, h->cur_pic.qscale_table[mb_xy]);\n                sl->chroma_qp[1] = get_chroma_qp(h->ps.pps, 1, h->cur_pic.qscale_table[mb_xy]);\n                if (FRAME_MBAFF(h)) {\n                    ff_h264_filter_mb(h, sl, mb_x, mb_y, dest_y, dest_cb, dest_cr,\n                                      linesize, uvlinesize);\n                } else {\n                    ff_h264_filter_mb_fast(h, sl, mb_x, mb_y, dest_y, dest_cb,\n                                           dest_cr, linesize, uvlinesize);\n                }\n            }\n    }\n    sl->slice_type  = old_slice_type;\n    sl->mb_x         = end_x;\n    sl->mb_y         = end_mb_y - FRAME_MBAFF(h);\n    sl->chroma_qp[0] = get_chroma_qp(h->ps.pps, 0, sl->qscale);\n    sl->chroma_qp[1] = get_chroma_qp(h->ps.pps, 1, sl->qscale);\n}', 'void ff_h264_filter_mb_fast(const H264Context *h, H264SliceContext *sl,\n                            int mb_x, int mb_y, uint8_t *img_y,\n                            uint8_t *img_cb, uint8_t *img_cr,\n                            unsigned int linesize, unsigned int uvlinesize)\n{\n    assert(!FRAME_MBAFF(h));\n    if(!h->h264dsp.h264_loop_filter_strength || h->ps.pps->chroma_qp_diff) {\n        ff_h264_filter_mb(h, sl, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize);\n        return;\n    }\n#if CONFIG_SMALL\n    h264_filter_mb_fast_internal(h, sl, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, h->pixel_shift);\n#else\n    if(h->pixel_shift){\n        h264_filter_mb_fast_internal(h, sl, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, 1);\n    }else{\n        h264_filter_mb_fast_internal(h, sl, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, 0);\n    }\n#endif\n}', 'void ff_h264_filter_mb(const H264Context *h, H264SliceContext *sl,\n                       int mb_x, int mb_y,\n                       uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr,\n                       unsigned int linesize, unsigned int uvlinesize)\n{\n    const int mb_xy= mb_x + mb_y*h->mb_stride;\n    const int mb_type = h->cur_pic.mb_type[mb_xy];\n    const int mvy_limit = IS_INTERLACED(mb_type) ? 2 : 4;\n    int first_vertical_edge_done = 0;\n    int chroma = !(CONFIG_GRAY && (h->flags & AV_CODEC_FLAG_GRAY));\n    int qp_bd_offset = 6 * (h->ps.sps->bit_depth_luma - 8);\n    int a = 52 + sl->slice_alpha_c0_offset - qp_bd_offset;\n    int b = 52 + sl->slice_beta_offset - qp_bd_offset;\n    if (FRAME_MBAFF(h)\n            && IS_INTERLACED(mb_type ^ sl->left_type[LTOP])\n            && sl->left_type[LTOP]) {\n        DECLARE_ALIGNED(8, int16_t, bS)[8];\n        int qp[2];\n        int bqp[2];\n        int rqp[2];\n        int mb_qp, mbn0_qp, mbn1_qp;\n        int i;\n        first_vertical_edge_done = 1;\n        if( IS_INTRA(mb_type) ) {\n            AV_WN64A(&bS[0], 0x0004000400040004ULL);\n            AV_WN64A(&bS[4], 0x0004000400040004ULL);\n        } else {\n            static const uint8_t offset[2][2][8]={\n                {\n                    {3+4*0, 3+4*0, 3+4*0, 3+4*0, 3+4*1, 3+4*1, 3+4*1, 3+4*1},\n                    {3+4*2, 3+4*2, 3+4*2, 3+4*2, 3+4*3, 3+4*3, 3+4*3, 3+4*3},\n                },{\n                    {3+4*0, 3+4*1, 3+4*2, 3+4*3, 3+4*0, 3+4*1, 3+4*2, 3+4*3},\n                    {3+4*0, 3+4*1, 3+4*2, 3+4*3, 3+4*0, 3+4*1, 3+4*2, 3+4*3},\n                }\n            };\n            const uint8_t *off= offset[MB_FIELD(sl)][mb_y&1];\n            for( i = 0; i < 8; i++ ) {\n                int j= MB_FIELD(sl) ? i>>2 : i&1;\n                int mbn_xy = sl->left_mb_xy[LEFT(j)];\n                int mbn_type = sl->left_type[LEFT(j)];\n                if( IS_INTRA( mbn_type ) )\n                    bS[i] = 4;\n                else{\n                    bS[i] = 1 + !!(sl->non_zero_count_cache[12+8*(i>>1)] |\n                         ((!h->ps.pps->cabac && IS_8x8DCT(mbn_type)) ?\n                            (h->cbp_table[mbn_xy] & (((MB_FIELD(sl) ? (i&2) : (mb_y&1)) ? 8 : 2) << 12))\n                                                                       :\n                            h->non_zero_count[mbn_xy][ off[i] ]));\n                }\n            }\n        }\n        mb_qp   = h->cur_pic.qscale_table[mb_xy];\n        mbn0_qp = h->cur_pic.qscale_table[sl->left_mb_xy[0]];\n        mbn1_qp = h->cur_pic.qscale_table[sl->left_mb_xy[1]];\n        qp[0] = ( mb_qp + mbn0_qp + 1 ) >> 1;\n        bqp[0] = (get_chroma_qp(h->ps.pps, 0, mb_qp) +\n                  get_chroma_qp(h->ps.pps, 0, mbn0_qp) + 1) >> 1;\n        rqp[0] = (get_chroma_qp(h->ps.pps, 1, mb_qp) +\n                  get_chroma_qp(h->ps.pps, 1, mbn0_qp) + 1) >> 1;\n        qp[1] = ( mb_qp + mbn1_qp + 1 ) >> 1;\n        bqp[1] = (get_chroma_qp(h->ps.pps, 0, mb_qp) +\n                  get_chroma_qp(h->ps.pps, 0, mbn1_qp) + 1 ) >> 1;\n        rqp[1] = (get_chroma_qp(h->ps.pps, 1, mb_qp) +\n                  get_chroma_qp(h->ps.pps, 1, mbn1_qp) + 1 ) >> 1;\n        ff_tlog(h->avctx, "filter mb:%d/%d MBAFF, QPy:%d/%d, QPb:%d/%d QPr:%d/%d ls:%d uvls:%d", mb_x, mb_y, qp[0], qp[1], bqp[0], bqp[1], rqp[0], rqp[1], linesize, uvlinesize);\n        { int i; for (i = 0; i < 8; i++) ff_tlog(h->avctx, " bS[%d]:%d", i, bS[i]); ff_tlog(h->avctx, "\\n"); }\n        if (MB_FIELD(sl)) {\n            filter_mb_mbaff_edgev ( h, img_y                ,   linesize, bS  , 1, qp [0], a, b, 1 );\n            filter_mb_mbaff_edgev ( h, img_y  + 8*  linesize,   linesize, bS+4, 1, qp [1], a, b, 1 );\n            if (chroma){\n                if (CHROMA444(h)) {\n                    filter_mb_mbaff_edgev ( h, img_cb,                uvlinesize, bS  , 1, bqp[0], a, b, 1 );\n                    filter_mb_mbaff_edgev ( h, img_cb + 8*uvlinesize, uvlinesize, bS+4, 1, bqp[1], a, b, 1 );\n                    filter_mb_mbaff_edgev ( h, img_cr,                uvlinesize, bS  , 1, rqp[0], a, b, 1 );\n                    filter_mb_mbaff_edgev ( h, img_cr + 8*uvlinesize, uvlinesize, bS+4, 1, rqp[1], a, b, 1 );\n                } else if (CHROMA422(h)) {\n                    filter_mb_mbaff_edgecv(h, img_cb,                uvlinesize, bS  , 1, bqp[0], a, b, 1);\n                    filter_mb_mbaff_edgecv(h, img_cb + 8*uvlinesize, uvlinesize, bS+4, 1, bqp[1], a, b, 1);\n                    filter_mb_mbaff_edgecv(h, img_cr,                uvlinesize, bS  , 1, rqp[0], a, b, 1);\n                    filter_mb_mbaff_edgecv(h, img_cr + 8*uvlinesize, uvlinesize, bS+4, 1, rqp[1], a, b, 1);\n                }else{\n                    filter_mb_mbaff_edgecv( h, img_cb,                uvlinesize, bS  , 1, bqp[0], a, b, 1 );\n                    filter_mb_mbaff_edgecv( h, img_cb + 4*uvlinesize, uvlinesize, bS+4, 1, bqp[1], a, b, 1 );\n                    filter_mb_mbaff_edgecv( h, img_cr,                uvlinesize, bS  , 1, rqp[0], a, b, 1 );\n                    filter_mb_mbaff_edgecv( h, img_cr + 4*uvlinesize, uvlinesize, bS+4, 1, rqp[1], a, b, 1 );\n                }\n            }\n        }else{\n            filter_mb_mbaff_edgev ( h, img_y              , 2*  linesize, bS  , 2, qp [0], a, b, 1 );\n            filter_mb_mbaff_edgev ( h, img_y  +   linesize, 2*  linesize, bS+1, 2, qp [1], a, b, 1 );\n            if (chroma){\n                if (CHROMA444(h)) {\n                    filter_mb_mbaff_edgev ( h, img_cb,              2*uvlinesize, bS  , 2, bqp[0], a, b, 1 );\n                    filter_mb_mbaff_edgev ( h, img_cb + uvlinesize, 2*uvlinesize, bS+1, 2, bqp[1], a, b, 1 );\n                    filter_mb_mbaff_edgev ( h, img_cr,              2*uvlinesize, bS  , 2, rqp[0], a, b, 1 );\n                    filter_mb_mbaff_edgev ( h, img_cr + uvlinesize, 2*uvlinesize, bS+1, 2, rqp[1], a, b, 1 );\n                }else{\n                    filter_mb_mbaff_edgecv( h, img_cb,              2*uvlinesize, bS  , 2, bqp[0], a, b, 1 );\n                    filter_mb_mbaff_edgecv( h, img_cb + uvlinesize, 2*uvlinesize, bS+1, 2, bqp[1], a, b, 1 );\n                    filter_mb_mbaff_edgecv( h, img_cr,              2*uvlinesize, bS  , 2, rqp[0], a, b, 1 );\n                    filter_mb_mbaff_edgecv( h, img_cr + uvlinesize, 2*uvlinesize, bS+1, 2, rqp[1], a, b, 1 );\n                }\n            }\n        }\n    }\n#if CONFIG_SMALL\n    {\n        int dir;\n        for (dir = 0; dir < 2; dir++)\n            filter_mb_dir(h, sl, mb_x, mb_y, img_y, img_cb, img_cr, linesize,\n                          uvlinesize, mb_xy, mb_type, mvy_limit,\n                          dir ? 0 : first_vertical_edge_done, a, b,\n                          chroma, dir);\n    }\n#else\n    filter_mb_dir(h, sl, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, first_vertical_edge_done, a, b, chroma, 0);\n    filter_mb_dir(h, sl, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, 0,                        a, b, chroma, 1);\n#endif\n}', 'static av_always_inline void filter_mb_dir(const H264Context *h, H264SliceContext *sl,\n                                           int mb_x, int mb_y,\n                                           uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr,\n                                           unsigned int linesize, unsigned int uvlinesize,\n                                           int mb_xy, int mb_type, int mvy_limit,\n                                           int first_vertical_edge_done, int a, int b,\n                                           int chroma, int dir)\n{\n    int edge;\n    int chroma_qp_avg[2];\n    int chroma444 = CHROMA444(h);\n    int chroma422 = CHROMA422(h);\n    const int mbm_xy = dir == 0 ? mb_xy -1 : sl->top_mb_xy;\n    const int mbm_type = dir == 0 ? sl->left_type[LTOP] : sl->top_type;\n    static const uint8_t mask_edge_tab[2][8]={{0,3,3,3,1,1,1,1},\n                                              {0,3,1,1,3,3,3,3}};\n    const int mask_edge = mask_edge_tab[dir][(mb_type>>3)&7];\n    const int edges = mask_edge== 3 && !(sl->cbp&15) ? 1 : 4;\n    const int mask_par0 = mb_type & (MB_TYPE_16x16 | (MB_TYPE_8x16 >> dir));\n    if(mbm_type && !first_vertical_edge_done){\n        if (FRAME_MBAFF(h) && (dir == 1) && ((mb_y&1) == 0)\n            && IS_INTERLACED(mbm_type&~mb_type)\n            ) {\n            unsigned int tmp_linesize   = 2 *   linesize;\n            unsigned int tmp_uvlinesize = 2 * uvlinesize;\n            int mbn_xy = mb_xy - 2 * h->mb_stride;\n            int j;\n            for(j=0; j<2; j++, mbn_xy += h->mb_stride){\n                DECLARE_ALIGNED(8, int16_t, bS)[4];\n                int qp;\n                if (IS_INTRA(mb_type | h->cur_pic.mb_type[mbn_xy])) {\n                    AV_WN64A(bS, 0x0003000300030003ULL);\n                } else {\n                    if (!CABAC(h) && IS_8x8DCT(h->cur_pic.mb_type[mbn_xy])) {\n                        bS[0]= 1+((h->cbp_table[mbn_xy] & 0x4000) || sl->non_zero_count_cache[scan8[0]+0]);\n                        bS[1]= 1+((h->cbp_table[mbn_xy] & 0x4000) || sl->non_zero_count_cache[scan8[0]+1]);\n                        bS[2]= 1+((h->cbp_table[mbn_xy] & 0x8000) || sl->non_zero_count_cache[scan8[0]+2]);\n                        bS[3]= 1+((h->cbp_table[mbn_xy] & 0x8000) || sl->non_zero_count_cache[scan8[0]+3]);\n                    }else{\n                    const uint8_t *mbn_nnz = h->non_zero_count[mbn_xy] + 3*4;\n                    int i;\n                    for( i = 0; i < 4; i++ ) {\n                        bS[i] = 1 + !!(sl->non_zero_count_cache[scan8[0]+i] | mbn_nnz[i]);\n                    }\n                    }\n                }\n                qp = (h->cur_pic.qscale_table[mb_xy] + h->cur_pic.qscale_table[mbn_xy] + 1) >> 1;\n                ff_tlog(h->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, tmp_linesize, tmp_uvlinesize);\n                { int i; for (i = 0; i < 4; i++) ff_tlog(h->avctx, " bS[%d]:%d", i, bS[i]); ff_tlog(h->avctx, "\\n"); }\n                filter_mb_edgeh( &img_y[j*linesize], tmp_linesize, bS, qp, a, b, h, 0 );\n                chroma_qp_avg[0] = (sl->chroma_qp[0] + get_chroma_qp(h->ps.pps, 0, h->cur_pic.qscale_table[mbn_xy]) + 1) >> 1;\n                chroma_qp_avg[1] = (sl->chroma_qp[1] + get_chroma_qp(h->ps.pps, 1, h->cur_pic.qscale_table[mbn_xy]) + 1) >> 1;\n                if (chroma) {\n                    if (chroma444) {\n                        filter_mb_edgeh (&img_cb[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[0], a, b, h, 0);\n                        filter_mb_edgeh (&img_cr[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[1], a, b, h, 0);\n                    } else {\n                        filter_mb_edgech(&img_cb[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[0], a, b, h, 0);\n                        filter_mb_edgech(&img_cr[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[1], a, b, h, 0);\n                    }\n                }\n            }\n        }else{\n            DECLARE_ALIGNED(8, int16_t, bS)[4];\n            int qp;\n            if( IS_INTRA(mb_type|mbm_type)) {\n                AV_WN64A(bS, 0x0003000300030003ULL);\n                if (   (!IS_INTERLACED(mb_type|mbm_type))\n                    || ((FRAME_MBAFF(h) || (h->picture_structure != PICT_FRAME)) && (dir == 0))\n                )\n                    AV_WN64A(bS, 0x0004000400040004ULL);\n            } else {\n                int i;\n                int mv_done;\n                if( dir && FRAME_MBAFF(h) && IS_INTERLACED(mb_type ^ mbm_type)) {\n                    AV_WN64A(bS, 0x0001000100010001ULL);\n                    mv_done = 1;\n                }\n                else if( mask_par0 && ((mbm_type & (MB_TYPE_16x16 | (MB_TYPE_8x16 >> dir)))) ) {\n                    int b_idx= 8 + 4;\n                    int bn_idx= b_idx - (dir ? 8:1);\n                    bS[0] = bS[1] = bS[2] = bS[3] = check_mv(sl, 8 + 4, bn_idx, mvy_limit);\n                    mv_done = 1;\n                }\n                else\n                    mv_done = 0;\n                for( i = 0; i < 4; i++ ) {\n                    int x = dir == 0 ? 0 : i;\n                    int y = dir == 0 ? i    : 0;\n                    int b_idx= 8 + 4 + x + 8*y;\n                    int bn_idx= b_idx - (dir ? 8:1);\n                    if (sl->non_zero_count_cache[b_idx] |\n                        sl->non_zero_count_cache[bn_idx]) {\n                        bS[i] = 2;\n                    }\n                    else if(!mv_done)\n                    {\n                        bS[i] = check_mv(sl, b_idx, bn_idx, mvy_limit);\n                    }\n                }\n            }\n            if(bS[0]+bS[1]+bS[2]+bS[3]){\n                qp = (h->cur_pic.qscale_table[mb_xy] + h->cur_pic.qscale_table[mbm_xy] + 1) >> 1;\n                ff_tlog(h->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize);\n                chroma_qp_avg[0] = (sl->chroma_qp[0] + get_chroma_qp(h->ps.pps, 0, h->cur_pic.qscale_table[mbm_xy]) + 1) >> 1;\n                chroma_qp_avg[1] = (sl->chroma_qp[1] + get_chroma_qp(h->ps.pps, 1, h->cur_pic.qscale_table[mbm_xy]) + 1) >> 1;\n                if( dir == 0 ) {\n                    filter_mb_edgev( &img_y[0], linesize, bS, qp, a, b, h, 1 );\n                    if (chroma) {\n                        if (chroma444) {\n                            filter_mb_edgev ( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], a, b, h, 1);\n                            filter_mb_edgev ( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], a, b, h, 1);\n                        } else {\n                            filter_mb_edgecv( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], a, b, h, 1);\n                            filter_mb_edgecv( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], a, b, h, 1);\n                        }\n                    }\n                } else {\n                    filter_mb_edgeh( &img_y[0], linesize, bS, qp, a, b, h, 1 );\n                    if (chroma) {\n                        if (chroma444) {\n                            filter_mb_edgeh ( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], a, b, h, 1);\n                            filter_mb_edgeh ( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], a, b, h, 1);\n                        } else {\n                            filter_mb_edgech( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], a, b, h, 1);\n                            filter_mb_edgech( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], a, b, h, 1);\n                        }\n                    }\n                }\n            }\n        }\n    }\n    for( edge = 1; edge < edges; edge++ ) {\n        DECLARE_ALIGNED(8, int16_t, bS)[4];\n        int qp;\n        const int deblock_edge = !IS_8x8DCT(mb_type & (edge<<24));\n        if (!deblock_edge && (!chroma422 || dir == 0))\n            continue;\n        if( IS_INTRA(mb_type)) {\n            AV_WN64A(bS, 0x0003000300030003ULL);\n        } else {\n            int i;\n            int mv_done;\n            if( edge & mask_edge ) {\n                AV_ZERO64(bS);\n                mv_done = 1;\n            }\n            else if( mask_par0 ) {\n                int b_idx= 8 + 4 + edge * (dir ? 8:1);\n                int bn_idx= b_idx - (dir ? 8:1);\n                bS[0] = bS[1] = bS[2] = bS[3] = check_mv(sl, b_idx, bn_idx, mvy_limit);\n                mv_done = 1;\n            }\n            else\n                mv_done = 0;\n            for( i = 0; i < 4; i++ ) {\n                int x = dir == 0 ? edge : i;\n                int y = dir == 0 ? i    : edge;\n                int b_idx= 8 + 4 + x + 8*y;\n                int bn_idx= b_idx - (dir ? 8:1);\n                if (sl->non_zero_count_cache[b_idx] |\n                    sl->non_zero_count_cache[bn_idx]) {\n                    bS[i] = 2;\n                }\n                else if(!mv_done)\n                {\n                    bS[i] = check_mv(sl, b_idx, bn_idx, mvy_limit);\n                }\n            }\n            if(bS[0]+bS[1]+bS[2]+bS[3] == 0)\n                continue;\n        }\n        qp = h->cur_pic.qscale_table[mb_xy];\n        ff_tlog(h->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize);\n        if( dir == 0 ) {\n            filter_mb_edgev( &img_y[4*edge << h->pixel_shift], linesize, bS, qp, a, b, h, 0 );\n            if (chroma) {\n                if (chroma444) {\n                    filter_mb_edgev ( &img_cb[4*edge << h->pixel_shift], uvlinesize, bS, sl->chroma_qp[0], a, b, h, 0);\n                    filter_mb_edgev ( &img_cr[4*edge << h->pixel_shift], uvlinesize, bS, sl->chroma_qp[1], a, b, h, 0);\n                } else if( (edge&1) == 0 ) {\n                    filter_mb_edgecv( &img_cb[2*edge << h->pixel_shift], uvlinesize, bS, sl->chroma_qp[0], a, b, h, 0);\n                    filter_mb_edgecv( &img_cr[2*edge << h->pixel_shift], uvlinesize, bS, sl->chroma_qp[1], a, b, h, 0);\n                }\n            }\n        } else {\n            if (chroma422) {\n                if (deblock_edge)\n                    filter_mb_edgeh(&img_y[4*edge*linesize], linesize, bS, qp, a, b, h, 0);\n                if (chroma) {\n                    filter_mb_edgech(&img_cb[4*edge*uvlinesize], uvlinesize, bS, sl->chroma_qp[0], a, b, h, 0);\n                    filter_mb_edgech(&img_cr[4*edge*uvlinesize], uvlinesize, bS, sl->chroma_qp[1], a, b, h, 0);\n                }\n            } else {\n                filter_mb_edgeh(&img_y[4*edge*linesize], linesize, bS, qp, a, b, h, 0);\n                if (chroma) {\n                    if (chroma444) {\n                        filter_mb_edgeh (&img_cb[4*edge*uvlinesize], uvlinesize, bS, sl->chroma_qp[0], a, b, h, 0);\n                        filter_mb_edgeh (&img_cr[4*edge*uvlinesize], uvlinesize, bS, sl->chroma_qp[1], a, b, h, 0);\n                    } else if ((edge&1) == 0) {\n                        filter_mb_edgech(&img_cb[2*edge*uvlinesize], uvlinesize, bS, sl->chroma_qp[0], a, b, h, 0);\n                        filter_mb_edgech(&img_cr[2*edge*uvlinesize], uvlinesize, bS, sl->chroma_qp[1], a, b, h, 0);\n                    }\n                }\n            }\n        }\n    }\n}']