encodeframe.c 50.5 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
    {
        struct vpx_usec_timer  emr_timer;
        vpx_usec_timer_start(&emr_timer);

#if CONFIG_MULTITHREAD
        if (cpi->b_multi_threaded)
        {
John Koleszar's avatar
John Koleszar committed
            vp8cx_init_mbrthread_data(cpi, x, cpi->mb_row_ei, 1,  cpi->encoding_thread_count);

Attila Nagy's avatar
Attila Nagy committed
            for (i = 0; i < cm->mb_rows; i++)
                cpi->mt_current_mb_col[i] = -1;
Attila Nagy's avatar
Attila Nagy committed
            for (i = 0; i < cpi->encoding_thread_count; i++)
            {
                sem_post(&cpi->h_event_start_encoding[i]);
            }
Attila Nagy's avatar
Attila Nagy committed
            for (mb_row = 0; mb_row < cm->mb_rows; mb_row += (cpi->encoding_thread_count + 1))
            {
John Koleszar's avatar
John Koleszar committed
                vp8_zero(cm->left_context)

                tp = cpi->tok + mb_row * (cm->mb_cols * 16 * 24);

                encode_mb_row(cpi, cm, mb_row, x, xd, &tp, segment_counts, &totalrate);

                // adjust to the next row of mbs
                x->src.y_buffer += 16 * x->src.y_stride * (cpi->encoding_thread_count + 1) - 16 * cm->mb_cols;
                x->src.u_buffer +=  8 * x->src.uv_stride * (cpi->encoding_thread_count + 1) - 8 * cm->mb_cols;
                x->src.v_buffer +=  8 * x->src.uv_stride * (cpi->encoding_thread_count + 1) - 8 * cm->mb_cols;

                xd->mode_info_context += xd->mode_info_stride * cpi->encoding_thread_count;
                x->partition_info  += xd->mode_info_stride * cpi->encoding_thread_count;
                x->gf_active_ptr   += cm->mb_cols * cpi->encoding_thread_count;
Attila Nagy's avatar
Attila Nagy committed
            sem_wait(&cpi->h_event_end_encoding); /* wait for other threads to finish */
John Koleszar's avatar
John Koleszar committed

            cpi->tok_count = 0;

            for (mb_row = 0; mb_row < cm->mb_rows; mb_row ++)
            {
                cpi->tok_count += cpi->tplist[mb_row].stop - cpi->tplist[mb_row].start;
            }

            if (xd->segmentation_enabled)
            {
                int i, j;

Paul Wilkins's avatar
Paul Wilkins committed
                for (i = 0; i < cpi->encoding_thread_count; i++)
John Koleszar's avatar
John Koleszar committed
                {
Paul Wilkins's avatar
Paul Wilkins committed
                    for (j = 0; j < 4; j++)
                        segment_counts[j] += cpi->mb_row_ei[i].segment_counts[j];
John Koleszar's avatar
John Koleszar committed
                }
            }

            for (i = 0; i < cpi->encoding_thread_count; i++)
            {
                totalrate += cpi->mb_row_ei[i].totalrate;
            }

John Koleszar's avatar
John Koleszar committed
#endif
        {
            // for each macroblock row in image
            for (mb_row = 0; mb_row < cm->mb_rows; mb_row++)
            {

                vp8_zero(cm->left_context)

                encode_mb_row(cpi, cm, mb_row, x, xd, &tp, segment_counts, &totalrate);

                // adjust to the next row of mbs
                x->src.y_buffer += 16 * x->src.y_stride - 16 * cm->mb_cols;
                x->src.u_buffer += 8 * x->src.uv_stride - 8 * cm->mb_cols;
                x->src.v_buffer += 8 * x->src.uv_stride - 8 * cm->mb_cols;
            }

            cpi->tok_count = tp - cpi->tok;
John Koleszar's avatar
John Koleszar committed

        }

        vpx_usec_timer_mark(&emr_timer);
        cpi->time_encode_mb_row += vpx_usec_timer_elapsed(&emr_timer);

    }

Paul Wilkins's avatar
Paul Wilkins committed
    // Work out the segment probabilites if segmentation is enabled and
    // the map is due to be updated
    if (xd->segmentation_enabled && xd->update_mb_segmentation_map)
John Koleszar's avatar
John Koleszar committed
    {
        int tot_count;
        int count1,count2,count3,count4;
John Koleszar's avatar
John Koleszar committed

        // Set to defaults
Paul Wilkins's avatar
Paul Wilkins committed
        vpx_memset(xd->mb_segment_tree_probs, 255, sizeof(xd->mb_segment_tree_probs));
Paul Wilkins's avatar
Paul Wilkins committed
#if CONFIG_SEGMENTATION
        // Select the coding strategy for the segment map (temporal or spatial)
        choose_segmap_coding_method( cpi );
John Koleszar's avatar
John Koleszar committed
        tot_count = segment_counts[0] + segment_counts[1] + segment_counts[2] + segment_counts[3];
        count1 = segment_counts[0] + segment_counts[1];
        count2 = segment_counts[2] + segment_counts[3];
John Koleszar's avatar
John Koleszar committed

        if (tot_count)
            xd->mb_segment_tree_probs[0] = (count1 * 255) / tot_count;
        if (count1 > 0)
            xd->mb_segment_tree_probs[1] = (segment_counts[0] * 255) /count1;
        if (count2 > 0)
            xd->mb_segment_tree_probs[2] = (segment_counts[2] * 255) /count2;
        // Zero probabilities not allowed
        for (i = 0; i < MB_FEATURE_TREE_PROBS; i++)

        {
            if (xd->mb_segment_tree_probs[i] == 0)
                xd->mb_segment_tree_probs[i] = 1;
        }
John Koleszar's avatar
John Koleszar committed
    }

    // 256 rate units to the bit
    cpi->projected_frame_size = totalrate >> 8;   // projected_frame_size in units of BYTES

    // Make a note of the percentage MBs coded Intra.
    if (cm->frame_type == KEY_FRAME)
    {
        cpi->this_frame_percent_intra = 100;
    }
    else
    {
        int tot_modes;

        tot_modes = cpi->count_mb_ref_frame_usage[INTRA_FRAME]
                    + cpi->count_mb_ref_frame_usage[LAST_FRAME]
                    + cpi->count_mb_ref_frame_usage[GOLDEN_FRAME]
                    + cpi->count_mb_ref_frame_usage[ALTREF_FRAME];

        if (tot_modes)
            cpi->this_frame_percent_intra = cpi->count_mb_ref_frame_usage[INTRA_FRAME] * 100 / tot_modes;

    }

#if 0
    {
        int cnt = 0;
        int flag[2] = {0, 0};

        for (cnt = 0; cnt < MVPcount; cnt++)
        {
            if (cm->fc.pre_mvc[0][cnt] != cm->fc.mvc[0][cnt])
            {
                flag[0] = 1;
                vpx_memcpy(cm->fc.pre_mvc[0], cm->fc.mvc[0], MVPcount);
                break;
            }
        }

        for (cnt = 0; cnt < MVPcount; cnt++)
        {
            if (cm->fc.pre_mvc[1][cnt] != cm->fc.mvc[1][cnt])
            {
                flag[1] = 1;
                vpx_memcpy(cm->fc.pre_mvc[1], cm->fc.mvc[1], MVPcount);
                break;
            }
        }

        if (flag[0] || flag[1])
            vp8_build_component_cost_table(cpi->mb.mvcost, (const MV_CONTEXT *) cm->fc.mvc, flag);
    // Adjust the projected reference frame usage probability numbers to reflect
John Koleszar's avatar
John Koleszar committed
    // what we have just seen. This may be usefull when we make multiple itterations
    // of the recode loop rather than continuing to use values from the previous frame.
    if ((cm->frame_type != KEY_FRAME) && !cm->refresh_alt_ref_frame && !cm->refresh_golden_frame)
    {
        const int *const rfct = cpi->count_mb_ref_frame_usage;
        const int rf_intra = rfct[INTRA_FRAME];
        const int rf_inter = rfct[LAST_FRAME] + rfct[GOLDEN_FRAME] + rfct[ALTREF_FRAME];

        if ((rf_intra + rf_inter) > 0)
        {
            cpi->prob_intra_coded = (rf_intra * 255) / (rf_intra + rf_inter);

            if (cpi->prob_intra_coded < 1)
                cpi->prob_intra_coded = 1;

            if ((cm->frames_since_golden > 0) || cpi->source_alt_ref_active)
            {
                cpi->prob_last_coded = rf_inter ? (rfct[LAST_FRAME] * 255) / rf_inter : 128;

                if (cpi->prob_last_coded < 1)
                    cpi->prob_last_coded = 1;

                cpi->prob_gf_coded = (rfct[GOLDEN_FRAME] + rfct[ALTREF_FRAME])
                                     ? (rfct[GOLDEN_FRAME] * 255) / (rfct[GOLDEN_FRAME] + rfct[ALTREF_FRAME]) : 128;

                if (cpi->prob_gf_coded < 1)
                    cpi->prob_gf_coded = 1;
            }
        }
//#if CONFIG_SEGFEATURES
        else
        {
            // Trap case where cpi->count_mb_ref_frame_usage[] blank.
            cpi->prob_intra_coded = 63;
            cpi->prob_last_coded  = 128;
            cpi->prob_gf_coded    = 128;
        }
John Koleszar's avatar
John Koleszar committed
    }
#if 0
    // Keep record of the total distortion this time around for future use
    cpi->last_frame_distortion = cpi->frame_distortion;
#endif

}
void vp8_setup_block_ptrs(MACROBLOCK *x)
{
    int r, c;
    int i;

    for (r = 0; r < 4; r++)
    {
        for (c = 0; c < 4; c++)
        {
            x->block[r*4+c].src_diff = x->src_diff + r * 4 * 16 + c * 4;
        }
    }

    for (r = 0; r < 2; r++)
    {
        for (c = 0; c < 2; c++)
        {
            x->block[16 + r*2+c].src_diff = x->src_diff + 256 + r * 4 * 8 + c * 4;
        }
    }


    for (r = 0; r < 2; r++)
    {
        for (c = 0; c < 2; c++)
        {
            x->block[20 + r*2+c].src_diff = x->src_diff + 320 + r * 4 * 8 + c * 4;
        }
    }

    x->block[24].src_diff = x->src_diff + 384;


    for (i = 0; i < 25; i++)
    {
        x->block[i].coeff = x->coeff + i * 16;
    }
}

void vp8_build_block_offsets(MACROBLOCK *x)
{
    int block = 0;
    int br, bc;

    vp8_build_block_doffsets(&x->e_mbd);

    // y blocks
    x->thismb_ptr = &x->thismb[0];
John Koleszar's avatar
John Koleszar committed
    for (br = 0; br < 4; br++)
    {
        for (bc = 0; bc < 4; bc++)
        {
            BLOCK *this_block = &x->block[block];
            //this_block->base_src = &x->src.y_buffer;
            //this_block->src_stride = x->src.y_stride;
            //this_block->src = 4 * br * this_block->src_stride + 4 * bc;
            this_block->base_src = &x->thismb_ptr;
            this_block->src_stride = 16;
            this_block->src = 4 * br * 16 + 4 * bc;
John Koleszar's avatar
John Koleszar committed
            ++block;
        }
    }

    // u blocks
    for (br = 0; br < 2; br++)
    {
        for (bc = 0; bc < 2; bc++)
        {
            BLOCK *this_block = &x->block[block];
            this_block->base_src = &x->src.u_buffer;
            this_block->src_stride = x->src.uv_stride;
            this_block->src = 4 * br * this_block->src_stride + 4 * bc;
            ++block;
        }
    }

    // v blocks
    for (br = 0; br < 2; br++)
    {
        for (bc = 0; bc < 2; bc++)
        {
            BLOCK *this_block = &x->block[block];
            this_block->base_src = &x->src.v_buffer;
            this_block->src_stride = x->src.uv_stride;
            this_block->src = 4 * br * this_block->src_stride + 4 * bc;
            ++block;
        }
    }
}

static void sum_intra_stats(VP8_COMP *cpi, MACROBLOCK *x)
{
    const MACROBLOCKD *xd = & x->e_mbd;
    const MB_PREDICTION_MODE m = xd->mode_info_context->mbmi.mode;
    const MB_PREDICTION_MODE uvm = xd->mode_info_context->mbmi.uv_mode;
John Koleszar's avatar
John Koleszar committed

#ifdef MODE_STATS
    const int is_key = cpi->common.frame_type == KEY_FRAME;

    ++ (is_key ? uv_modes : inter_uv_modes)[uvm];
    ++ uv_modes_y[m][uvm];
John Koleszar's avatar
John Koleszar committed

    if (m == B_PRED)
    {
        unsigned int *const bct = is_key ? b_modes : inter_b_modes;

        int b = 0;

        do
        {
            ++ bct[xd->block[b].bmi.as_mode];
John Koleszar's avatar
John Koleszar committed
        }
        while (++b < 16);
    }
Yaowu Xu's avatar
Yaowu Xu committed
#if CONFIG_I8X8
    if(m==I8X8_PRED)
    {
        i8x8_modes[xd->block[0].bmi.as_mode]++;
        i8x8_modes[xd->block[2].bmi.as_mode]++;
        i8x8_modes[xd->block[8].bmi.as_mode]++;
        i8x8_modes[xd->block[10].bmi.as_mode]++;
    }
#endif
John Koleszar's avatar
John Koleszar committed
#endif

    ++cpi->ymode_count[m];
    ++cpi->uv_mode_count[uvm];

}

// Experimental stub function to create a per MB zbin adjustment based on
// some previously calculated measure of MB activity.
static void adjust_act_zbin( VP8_COMP *cpi, MACROBLOCK *x )
#if USE_ACT_INDEX
    x->act_zbin_adj = *(x->mb_activity_ptr);
#else
    int64_t a;
    int64_t b;
    int64_t act = *(x->mb_activity_ptr);
    // Apply the masking to the RD multiplier.
    a = act + 4*cpi->activity_avg;
    b = 4*act + cpi->activity_avg;

    if ( act > cpi->activity_avg )
        x->act_zbin_adj = (int)(((int64_t)b + (a>>1))/a) - 1;
        x->act_zbin_adj = 1 - (int)(((int64_t)a + (b>>1))/b);
John Koleszar's avatar
John Koleszar committed
int vp8cx_encode_intra_macro_block(VP8_COMP *cpi, MACROBLOCK *x, TOKENEXTRA **t)
{
    if (cpi->sf.RD && cpi->compressor_speed != 2)
        vp8_rd_pick_intra_mode(cpi, x, &rate);
John Koleszar's avatar
John Koleszar committed
    else
        vp8_pick_intra_mode(cpi, x, &rate);
    if(cpi->oxcf.tuning == VP8_TUNE_SSIM)
    {
        adjust_act_zbin( cpi, x );
        vp8_update_zbin_extra(cpi, x);
Yaowu Xu's avatar
Yaowu Xu committed
#if CONFIG_I8X8
    if(x->e_mbd.mode_info_context->mbmi.mode == I8X8_PRED)
    {
        vp8_encode_intra8x8mby(IF_RTCD(&cpi->rtcd), x);
        vp8_encode_intra8x8mbuv(IF_RTCD(&cpi->rtcd), x);
    }
    else
#endif
    if (x->e_mbd.mode_info_context->mbmi.mode == B_PRED)
        vp8_encode_intra4x4mby(IF_RTCD(&cpi->rtcd), x);
    else
        vp8_encode_intra16x16mby(IF_RTCD(&cpi->rtcd), x);
Yaowu Xu's avatar
Yaowu Xu committed
    }
Yaowu Xu's avatar
Yaowu Xu committed
#if CONFIG_I8X8
        if(x->e_mbd.mode_info_context->mbmi.mode != I8X8_PRED)
#endif
Yaowu Xu's avatar
Yaowu Xu committed
    vp8_encode_intra16x16mbuv(IF_RTCD(&cpi->rtcd), x);
    sum_intra_stats(cpi, x);
    vp8_tokenize_mb(cpi, &x->e_mbd, t);
#if CONFIG_T8X8
        if ( get_seg_tx_type(&x->e_mbd,
                             x->e_mbd.mode_info_context->mbmi.segment_id) )
        {
            cpi->t8x8_count++;
        else
            cpi->t4x4_count++;
#endif
John Koleszar's avatar
John Koleszar committed
    return rate;
}
#ifdef SPEEDSTATS
extern int cnt_pm;
#endif

extern void vp8_fix_contexts(MACROBLOCKD *x);
John Koleszar's avatar
John Koleszar committed

int vp8cx_encode_inter_macroblock
(
    VP8_COMP *cpi, MACROBLOCK *x, TOKENEXTRA **t,
    int recon_yoffset, int recon_uvoffset
)
{
    MACROBLOCKD *const xd = &x->e_mbd;
    int intra_error = 0;
    int rate;
    int distortion;
    unsigned char *segment_id = &xd->mode_info_context->mbmi.segment_id;
John Koleszar's avatar
John Koleszar committed

    x->skip = 0;

    if (xd->segmentation_enabled)
        x->encode_breakout = cpi->segment_encode_breakout[*segment_id];
John Koleszar's avatar
John Koleszar committed
    else
        x->encode_breakout = cpi->oxcf.encode_breakout;

    if (cpi->sf.RD)
    {
        int zbin_mode_boost_enabled = cpi->zbin_mode_boost_enabled;

        /* Are we using the fast quantizer for the mode selection? */
        if(cpi->sf.use_fastquant_for_pick)
            cpi->mb.quantize_b      = QUANTIZE_INVOKE(&cpi->rtcd.quantize,
                                                      fastquantb);
            cpi->mb.quantize_b_pair = QUANTIZE_INVOKE(&cpi->rtcd.quantize,
                                                      fastquantb_pair);
            /* the fast quantizer does not use zbin_extra, so
             * do not recalculate */
            cpi->zbin_mode_boost_enabled = 0;
        }
        vp8_rd_pick_inter_mode(cpi, x, recon_yoffset, recon_uvoffset, &rate,
                               &distortion, &intra_error);

        /* switch back to the regular quantizer for the encode */
        if (cpi->sf.improved_quant)
        {
            cpi->mb.quantize_b      = QUANTIZE_INVOKE(&cpi->rtcd.quantize,
                                                      quantb);
            cpi->mb.quantize_b_pair = QUANTIZE_INVOKE(&cpi->rtcd.quantize,
                                                      quantb_pair);
        /* restore cpi->zbin_mode_boost_enabled */
        cpi->zbin_mode_boost_enabled = zbin_mode_boost_enabled;

John Koleszar's avatar
John Koleszar committed
    }
    else
        vp8_pick_inter_mode(cpi, x, recon_yoffset, recon_uvoffset, &rate,
                            &distortion, &intra_error);
    cpi->prediction_error += distortion;
John Koleszar's avatar
John Koleszar committed
    cpi->intra_error += intra_error;

    if(cpi->oxcf.tuning == VP8_TUNE_SSIM)
    {
        // Adjust the zbin based on this MB rate.
        adjust_act_zbin( cpi, x );
John Koleszar's avatar
John Koleszar committed
#if 0
    // Experimental RD code
    cpi->frame_distortion += distortion;
    cpi->last_mb_distortion = distortion;
#endif

Yaowu Xu's avatar
Yaowu Xu committed
    // MB level adjutment to quantizer setup
    if (xd->segmentation_enabled)
John Koleszar's avatar
John Koleszar committed
    {
        // If cyclic update enabled
        if (cpi->cyclic_refresh_mode_enabled)
        {
            // Clear segment_id back to 0 if not coded (last frame 0,0)
            if ( (*segment_id == 1) &&
                 ( (xd->mode_info_context->mbmi.ref_frame != LAST_FRAME) ||
                   (xd->mode_info_context->mbmi.mode != ZEROMV) ) )
John Koleszar's avatar
John Koleszar committed
            {
                *segment_id = 0;

                /* segment_id changed, so update */
                vp8cx_mb_init_quantizer(cpi, x);
//#if CONFIG_SEGFEATURES
            //segfeature_test_function(cpi, xd);
#if DBG_PRNT_SEGMAP
            // Debug output
            {
                FILE *statsfile;
                statsfile = fopen("segmap2.stt", "a");

                fprintf(statsfile, "%2d%2d%2d   ",
                    *segment_id,
                    xd->mode_info_context->mbmi.ref_frame,
                    xd->mode_info_context->mbmi.mode );

                fclose(statsfile);
            }
#endif
        }
        // Experimental code. Special case for gf and arf zeromv modes.
        // Increase zbin size to supress noise
        cpi->zbin_mode_boost = 0;
John Koleszar's avatar
John Koleszar committed
        if (cpi->zbin_mode_boost_enabled)
        {
            if ( xd->mode_info_context->mbmi.ref_frame != INTRA_FRAME )
            {
                if (xd->mode_info_context->mbmi.mode == ZEROMV)
                {
                    if (xd->mode_info_context->mbmi.ref_frame != LAST_FRAME)
                        cpi->zbin_mode_boost = GF_ZEROMV_ZBIN_BOOST;
                    else
                        cpi->zbin_mode_boost = LF_ZEROMV_ZBIN_BOOST;
                }
                else if (xd->mode_info_context->mbmi.mode == SPLITMV)
                    cpi->zbin_mode_boost = 0;
                else
                    cpi->zbin_mode_boost = MV_ZBIN_BOOST;
            }
John Koleszar's avatar
John Koleszar committed
        }

        /* The fast quantizer doesn't use zbin_extra, only do so with
         * the regular quantizer. */
        if (cpi->sf.improved_quant)
            vp8_update_zbin_extra(cpi, x);
//#if CONFIG_SEGFEATURES
    // If we have just a single reference frame coded for a segment then
    // exclude from the reference frame counts used to work out
    // probabilities. NOTE: At the moment we dont support custom trees
    // for the reference frame coding for each segment but this is a
    // possible future action.
    if ( !segfeature_active( xd, *segment_id, SEG_LVL_REF_FRAME ) ||
         ( ( check_segref( xd, *segment_id, INTRA_FRAME ) +
             check_segref( xd, *segment_id, LAST_FRAME ) +
             check_segref( xd, *segment_id, GOLDEN_FRAME ) +
             check_segref( xd, *segment_id, ALTREF_FRAME ) ) > 1 ) )
        cpi->count_mb_ref_frame_usage[xd->mode_info_context->mbmi.ref_frame]++;
    if (xd->mode_info_context->mbmi.ref_frame == INTRA_FRAME)
John Koleszar's avatar
John Koleszar committed
    {
        if (xd->mode_info_context->mbmi.mode == B_PRED)
John Koleszar's avatar
John Koleszar committed
        {
            vp8_encode_intra16x16mbuv(IF_RTCD(&cpi->rtcd), x);
John Koleszar's avatar
John Koleszar committed
            vp8_encode_intra4x4mby(IF_RTCD(&cpi->rtcd), x);
        }
        else
        {
            vp8_encode_intra16x16mbuv(IF_RTCD(&cpi->rtcd), x);
John Koleszar's avatar
John Koleszar committed
            vp8_encode_intra16x16mby(IF_RTCD(&cpi->rtcd), x);
        }

        sum_intra_stats(cpi, x);
    }
    else
    {
        if (xd->mode_info_context->mbmi.ref_frame == LAST_FRAME)
            ref_fb_idx = cpi->common.lst_fb_idx;
        else if (xd->mode_info_context->mbmi.ref_frame == GOLDEN_FRAME)
            ref_fb_idx = cpi->common.gld_fb_idx;
John Koleszar's avatar
John Koleszar committed
        else
            ref_fb_idx = cpi->common.alt_fb_idx;

        xd->pre.y_buffer = cpi->common.yv12_fb[ref_fb_idx].y_buffer + recon_yoffset;
        xd->pre.u_buffer = cpi->common.yv12_fb[ref_fb_idx].u_buffer + recon_uvoffset;
        xd->pre.v_buffer = cpi->common.yv12_fb[ref_fb_idx].v_buffer + recon_uvoffset;
Scott LaVarnway's avatar
Scott LaVarnway committed
        if (!x->skip)
John Koleszar's avatar
John Koleszar committed
        {
            vp8_encode_inter16x16(IF_RTCD(&cpi->rtcd), x);

            // Clear mb_skip_coeff if mb_no_coeff_skip is not set
            if (!cpi->common.mb_no_coeff_skip)
                xd->mode_info_context->mbmi.mb_skip_coeff = 0;
            vp8_build_inter16x16_predictors_mb(xd, xd->dst.y_buffer,
                                           xd->dst.u_buffer, xd->dst.v_buffer,
                                           xd->dst.y_stride, xd->dst.uv_stride);

John Koleszar's avatar
John Koleszar committed
    }
#if CONFIG_T8X8
    if ( get_seg_tx_type( xd, *segment_id ) == TX_8X8 )
    {
        cpi->t8x8_count++;
    else
        cpi->t4x4_count++;
#endif
John Koleszar's avatar
John Koleszar committed

    if (!x->skip)
    {
#ifdef ENC_DEBUG
        if (enc_debug)
        {
          int i;
            printf("Segment=%d [%d, %d]: %d %d:\n", x->e_mbd.mode_info_context->mbmi.segment_id, mb_col_debug, mb_row_debug, xd->mb_to_left_edge, xd->mb_to_top_edge);
            for (i =0; i<400; i++) {
              printf("%3d ", xd->qcoeff[i]);
              if (i%16 == 15) printf("\n");
            }
            printf("\n");
            printf("eobs = ");
            for (i=0;i<25;i++)
              printf("%d:%d ", i, xd->block[i].eob);
            printf("\n");
            fflush(stdout);
        }
#endif
John Koleszar's avatar
John Koleszar committed
        vp8_tokenize_mb(cpi, xd, t);
#ifdef ENC_DEBUG
        if (enc_debug) {
          printf("Tokenized\n");
          fflush(stdout);
        }
#endif
    }
John Koleszar's avatar
John Koleszar committed
    else
    {
        if (cpi->common.mb_no_coeff_skip)
        {
            xd->mode_info_context->mbmi.mb_skip_coeff = 1;
John Koleszar's avatar
John Koleszar committed
            cpi->skip_true_count ++;
            vp8_fix_contexts(xd);
John Koleszar's avatar
John Koleszar committed
        }
        else
        {
            vp8_stuff_mb(cpi, xd, t);
            xd->mode_info_context->mbmi.mb_skip_coeff = 0;
John Koleszar's avatar
John Koleszar committed
            cpi->skip_false_count ++;
        }
    }

    return rate;
}