if( h->ref_cache[l][b_idx] != h->ref_cache[l][bn_idx] ||
if( ref2frm[h->ref_cache[l][b_idx]+2] != ref2frm[h->ref_cache[l][bn_idx]+2] ||
static void filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize) {    MpegEncContext * const s = &h->s;    const int mb_xy= mb_x + mb_y*s->mb_stride;    int first_vertical_edge_done = 0;    int dir;    if (h->mb_aff_frame            // left mb is in picture            && h->slice_table[mb_xy-1] != 255            // and current and left pair do not have the same interlaced type            && (IS_INTERLACED(s->current_picture.mb_type[mb_xy]) != IS_INTERLACED(s->current_picture.mb_type[mb_xy-1]))            // and left mb is in the same slice if deblocking_filter == 2            && (h->deblocking_filter!=2 || h->slice_table[mb_xy-1] == h->slice_table[mb_xy])) {        /* First vertical edge is different in MBAFF frames         * There are 8 differents bS to compute and 2 differents Qp         */        int bS[8];        int qp[2];        int chroma_qp[2];        int i;        first_vertical_edge_done = 1;        for( i = 0; i < 8; i++ ) {            int y = i>>1;            int b_idx= 8 + 4 + 8*y;            int bn_idx= b_idx - 1;            int mbn_xy = h->mb_field_decoding_flag ? h->left_mb_xy[i>>2] : h->left_mb_xy[i&1];            if( IS_INTRA( s->current_picture.mb_type[mb_xy] ) ||                IS_INTRA( s->current_picture.mb_type[mbn_xy] ) ) {                bS[i] = 4;            } else if( h->non_zero_count_cache[b_idx] != 0 ||                h->non_zero_count_cache[bn_idx] != 0 ) {                bS[i] = 2;            } else {                /* FIXME: A given frame may occupy more than one position in                 * the reference list. So we should compare the frame numbers,                 * not the indices in the ref list. */                int l;                bS[i] = 0;                for( l = 0; l < 1 + (h->slice_type == B_TYPE); l++ ) {                    if( h->ref_cache[l][b_idx] != h->ref_cache[l][bn_idx] ||                        ABS( h->mv_cache[l][b_idx][0] - h->mv_cache[l][bn_idx][0] ) >= 4 ||                        ABS( h->mv_cache[l][b_idx][1] - h->mv_cache[l][bn_idx][1] ) >= 4 ) {                        bS[i] = 1;                        break;                    }                }            }        }        if(bS[0]+bS[1]+bS[2]+bS[3] != 0) {            // Do not use s->qscale as luma quantiser because it has not the same            // value in IPCM macroblocks.            qp[0] = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[h->left_mb_xy[0]] + 1 ) >> 1;            chroma_qp[0] = ( get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mb_xy] ) +                             get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[h->left_mb_xy[0]] ) + 1 ) >> 1;            qp[1] = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[h->left_mb_xy[1]] + 1 ) >> 1;            chroma_qp[1] = ( get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mb_xy] ) +                             get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[h->left_mb_xy[1]] ) + 1 ) >> 1;            /* Filter edge */            tprintf("filter mb:%d/%d MBAFF, QPy:%d/%d, QPc:%d/%d ls:%d uvls:%d", mb_x, mb_y, qp[0], qp[1], chroma_qp[0], chroma_qp[1], linesize, uvlinesize);            { int i; for (i = 0; i < 8; i++) tprintf(" bS[%d]:%d", i, bS[i]); tprintf("\n"); }            filter_mb_mbaff_edgev ( h, &img_y [0], linesize,   bS, qp );            filter_mb_mbaff_edgecv( h, &img_cb[0], uvlinesize, bS, chroma_qp );            filter_mb_mbaff_edgecv( h, &img_cr[0], uvlinesize, bS, chroma_qp );        }    }    /* dir : 0 -> vertical edge, 1 -> horizontal edge */    for( dir = 0; dir < 2; dir++ )    {        int edge;        const int mbm_xy = dir == 0 ? mb_xy -1 : h->top_mb_xy;        int start = h->slice_table[mbm_xy] == 255 ? 1 : 0;        if (first_vertical_edge_done) {            start = 1;            first_vertical_edge_done = 0;        }        if (h->deblocking_filter==2 && h->slice_table[mbm_xy] != h->slice_table[mb_xy])            start = 1;        /* Calculate bS */        for( edge = start; edge < 4; edge++ ) {            /* mbn_xy: neighbour macroblock */            int mbn_xy = edge > 0 ? mb_xy : mbm_xy;            int bS[4];            int qp;            if (h->mb_aff_frame && (dir == 1) && (edge == 0) && ((mb_y & 1) == 0)                && !IS_INTERLACED(s->current_picture.mb_type[mb_xy])                && IS_INTERLACED(s->current_picture.mb_type[mbn_xy])                ) {                // This is a special case in the norm where the filtering must                // be done twice (one each of the field) even if we are in a                // frame macroblock.                //                unsigned int tmp_linesize   = 2 *   linesize;                unsigned int tmp_uvlinesize = 2 * uvlinesize;                int mbn_xy = mb_xy - 2 * s->mb_stride;                int qp, chroma_qp;                // first filtering                if( IS_INTRA( s->current_picture.mb_type[mb_xy] ) ||                    IS_INTRA( s->current_picture.mb_type[mbn_xy] ) ) {                    bS[0] = bS[1] = bS[2] = bS[3] = 3;                } else {                    // TODO                    assert(0);                }                /* Filter edge */                // Do not use s->qscale as luma quantiser because it has not the same                // value in IPCM macroblocks.                qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1;                tprintf("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++) tprintf(" bS[%d]:%d", i, bS[i]); tprintf("\n"); }                filter_mb_edgeh( h, &img_y[0], tmp_linesize, bS, qp );                chroma_qp = ( h->chroma_qp +                              get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1;                filter_mb_edgech( h, &img_cb[0], tmp_uvlinesize, bS, chroma_qp );                filter_mb_edgech( h, &img_cr[0], tmp_uvlinesize, bS, chroma_qp );                // second filtering                mbn_xy += s->mb_stride;                if( IS_INTRA( s->current_picture.mb_type[mb_xy] ) ||                    IS_INTRA( s->current_picture.mb_type[mbn_xy] ) ) {                    bS[0] = bS[1] = bS[2] = bS[3] = 3;                } else {                    // TODO                    assert(0);                }                /* Filter edge */                // Do not use s->qscale as luma quantiser because it has not the same                // value in IPCM macroblocks.                qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1;                tprintf("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++) tprintf(" bS[%d]:%d", i, bS[i]); tprintf("\n"); }                filter_mb_edgeh( h, &img_y[linesize], tmp_linesize, bS, qp );                chroma_qp = ( h->chroma_qp +                              get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1;                filter_mb_edgech( h, &img_cb[uvlinesize], tmp_uvlinesize, bS, chroma_qp );                filter_mb_edgech( h, &img_cr[uvlinesize], tmp_uvlinesize, bS, chroma_qp );                continue;            }            if( IS_INTRA( s->current_picture.mb_type[mb_xy] ) ||                IS_INTRA( s->current_picture.mb_type[mbn_xy] ) ) {                int value;                if (edge == 0) {                    if (   (!IS_INTERLACED(s->current_picture.mb_type[mb_xy]) && !IS_INTERLACED(s->current_picture.mb_type[mbm_xy]))                        || ((h->mb_aff_frame || (s->picture_structure != PICT_FRAME)) && (dir == 0))                    ) {                        value = 4;                    } else {                        value = 3;                    }                } else {                    value = 3;                }                bS[0] = bS[1] = bS[2] = bS[3] = value;            } else {                int i;                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( h->non_zero_count_cache[b_idx] != 0 ||                        h->non_zero_count_cache[bn_idx] != 0 ) {                        bS[i] = 2;                    }                    else                    {                        /* FIXME: A given frame may occupy more than one position in                         * the reference list. So we should compare the frame numbers,                         * not the indices in the ref list. */                        int l;                        bS[i] = 0;                        for( l = 0; l < 1 + (h->slice_type == B_TYPE); l++ ) {                            if( h->ref_cache[l][b_idx] != h->ref_cache[l][bn_idx] ||                                ABS( h->mv_cache[l][b_idx][0] - h->mv_cache[l][bn_idx][0] ) >= 4 ||                                ABS( h->mv_cache[l][b_idx][1] - h->mv_cache[l][bn_idx][1] ) >= 4 ) {                                bS[i] = 1;                                break;                            }                        }                    }                }                if(bS[0]+bS[1]+bS[2]+bS[3] == 0)                    continue;            }            /* Filter edge */            // Do not use s->qscale as luma quantiser because it has not the same            // value in IPCM macroblocks.            qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1;            //tprintf("filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp, s->current_picture.qscale_table[mbn_xy]);            tprintf("filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize);            { int i; for (i = 0; i < 4; i++) tprintf(" bS[%d]:%d", i, bS[i]); tprintf("\n"); }            if( dir == 0 ) {                filter_mb_edgev( h, &img_y[4*edge], linesize, bS, qp );                if( (edge&1) == 0 ) {                    int chroma_qp = ( h->chroma_qp +                                      get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1;                    filter_mb_edgecv( h, &img_cb[2*edge], uvlinesize, bS, chroma_qp );                    filter_mb_edgecv( h, &img_cr[2*edge], uvlinesize, bS, chroma_qp );                }            } else {                filter_mb_edgeh( h, &img_y[4*edge*linesize], linesize, bS, qp );                if( (edge&1) == 0 ) {                    int chroma_qp = ( h->chroma_qp +                                      get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1;                    filter_mb_edgech( h, &img_cb[2*edge*uvlinesize], uvlinesize, bS, chroma_qp );                    filter_mb_edgech( h, &img_cr[2*edge*uvlinesize], uvlinesize, bS, chroma_qp );                }            }        }    }}