diff options
Diffstat (limited to 'vp9/encoder')
-rw-r--r-- | vp9/encoder/vp9_encodeframe.c | 161 | ||||
-rw-r--r-- | vp9/encoder/vp9_encoder.c | 11 | ||||
-rw-r--r-- | vp9/encoder/vp9_encoder.h | 11 | ||||
-rw-r--r-- | vp9/encoder/vp9_firstpass.c | 130 | ||||
-rw-r--r-- | vp9/encoder/vp9_lookahead.c | 2 | ||||
-rw-r--r-- | vp9/encoder/vp9_mcomp.c | 8 | ||||
-rw-r--r-- | vp9/encoder/vp9_pickmode.c | 35 | ||||
-rw-r--r-- | vp9/encoder/vp9_rd.c | 1 | ||||
-rw-r--r-- | vp9/encoder/vp9_rdopt.c | 15 | ||||
-rw-r--r-- | vp9/encoder/vp9_temporal_filter.c | 5 |
10 files changed, 210 insertions, 169 deletions
diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c index f55804c97..f66ed9ed3 100644 --- a/vp9/encoder/vp9_encodeframe.c +++ b/vp9/encoder/vp9_encodeframe.c @@ -729,6 +729,65 @@ static int skin_sb_split(VP9_COMP *cpi, MACROBLOCK *x, const int low_res, } #endif +static void set_low_temp_var_flag(VP9_COMP *cpi, MACROBLOCK *x, + MACROBLOCKD *xd, v64x64 *vt, + int force_split[], int64_t thresholds[], + MV_REFERENCE_FRAME ref_frame_partition, + int mi_col, int mi_row) { + int i, j; + VP9_COMMON * const cm = &cpi->common; + const int mv_thr = cm->width > 640 ? 8 : 4; + // Check temporal variance for bsize >= 16x16, if LAST_FRAME was selected and + // int_pro mv is small. If the temporal variance is small set the flag + // variance_low for the block. The variance threshold can be adjusted, the + // higher the more aggressive. + if (ref_frame_partition == LAST_FRAME && + (cpi->sf.short_circuit_low_temp_var == 1 || + (xd->mi[0]->mv[0].as_mv.col < mv_thr && + xd->mi[0]->mv[0].as_mv.col > -mv_thr && + xd->mi[0]->mv[0].as_mv.row < mv_thr && + xd->mi[0]->mv[0].as_mv.row > -mv_thr))) { + if (xd->mi[0]->sb_type == BLOCK_64X64 && + (vt->part_variances).none.variance < (thresholds[0] >> 1)) { + x->variance_low[0] = 1; + } else if (xd->mi[0]->sb_type == BLOCK_64X32) { + for (i = 0; i < 2; i++) { + if (vt->part_variances.horz[i].variance < (thresholds[0] >> 2)) + x->variance_low[i + 1] = 1; + } + } else if (xd->mi[0]->sb_type == BLOCK_32X64) { + for (i = 0; i < 2; i++) { + if (vt->part_variances.vert[i].variance < (thresholds[0] >> 2)) + x->variance_low[i + 3] = 1; + } + } else { + for (i = 0; i < 4; i++) { + if (!force_split[i + 1]) { + // 32x32 + if (vt->split[i].part_variances.none.variance < + (thresholds[1] >> 1)) + x->variance_low[i + 5] = 1; + } else if (cpi->sf.short_circuit_low_temp_var == 2) { + int idx[4] = {0, 4, xd->mi_stride << 2, (xd->mi_stride << 2) + 4}; + const int idx_str = cm->mi_stride * mi_row + mi_col + idx[i]; + MODE_INFO **this_mi = cm->mi_grid_visible + idx_str; + // For 32x16 and 16x32 blocks, the flag is set on each 16x16 block + // inside. + if ((*this_mi)->sb_type == BLOCK_16X16 || + (*this_mi)->sb_type == BLOCK_32X16 || + (*this_mi)->sb_type == BLOCK_16X32) { + for (j = 0; j < 4; j++) { + if (vt->split[i].split[j].part_variances.none.variance < + (thresholds[2] >> 8)) + x->variance_low[(i << 2) + j + 9] = 1; + } + } + } + } + } + } +} + // This function chooses partitioning based on the variance between source and // reconstructed last, where variance is computed for down-sampled inputs. static int choose_partitioning(VP9_COMP *cpi, @@ -1084,56 +1143,8 @@ static int choose_partitioning(VP9_COMP *cpi, } if (cpi->sf.short_circuit_low_temp_var) { - const int mv_thr = cm->width > 640 ? 8 : 4; - // Check temporal variance for bsize >= 16x16, if LAST_FRAME was selected - // and int_pro mv is small. If the temporal variance is small set the - // variance_low flag for the block. The variance threshold can be adjusted, - // the higher the more aggressive. - if (ref_frame_partition == LAST_FRAME && - (cpi->sf.short_circuit_low_temp_var == 1 || - (xd->mi[0]->mv[0].as_mv.col < mv_thr && - xd->mi[0]->mv[0].as_mv.col > -mv_thr && - xd->mi[0]->mv[0].as_mv.row < mv_thr && - xd->mi[0]->mv[0].as_mv.row > -mv_thr))) { - if (xd->mi[0]->sb_type == BLOCK_64X64 && - vt.part_variances.none.variance < (thresholds[0] >> 1)) { - x->variance_low[0] = 1; - } else if (xd->mi[0]->sb_type == BLOCK_64X32) { - for (j = 0; j < 2; j++) { - if (vt.part_variances.horz[j].variance < (thresholds[0] >> 2)) - x->variance_low[j + 1] = 1; - } - } else if (xd->mi[0]->sb_type == BLOCK_32X64) { - for (j = 0; j < 2; j++) { - if (vt.part_variances.vert[j].variance < (thresholds[0] >> 2)) - x->variance_low[j + 3] = 1; - } - } else { - for (i = 0; i < 4; i++) { - if (!force_split[i + 1]) { - // 32x32 - if (vt.split[i].part_variances.none.variance < - (thresholds[1] >> 1)) - x->variance_low[i + 5] = 1; - } else if (cpi->sf.short_circuit_low_temp_var == 2) { - int idx[4] = {0, 4, xd->mi_stride << 2, (xd->mi_stride << 2) + 4}; - const int idx_str = cm->mi_stride * mi_row + mi_col + idx[i]; - MODE_INFO **this_mi = cm->mi_grid_visible + idx_str; - // For 32x16 and 16x32 blocks, the flag is set on each 16x16 block - // inside. - if ((*this_mi)->sb_type == BLOCK_16X16 || - (*this_mi)->sb_type == BLOCK_32X16 || - (*this_mi)->sb_type == BLOCK_16X32) { - for (j = 0; j < 4; j++) { - if (vt.split[i].split[j].part_variances.none.variance < - (thresholds[2] >> 8)) - x->variance_low[(i << 2) + j + 9] = 1; - } - } - } - } - } - } + set_low_temp_var_flag(cpi, x, xd, &vt, force_split, thresholds, + ref_frame_partition, mi_col, mi_row); } return 0; } @@ -1213,7 +1224,7 @@ static void update_state(VP9_COMP *cpi, ThreadData *td, xd->mi[x_idx + y * mis] = mi_addr; } - if (cpi->oxcf.aq_mode) + if (cpi->oxcf.aq_mode != NO_AQ) vp9_init_plane_quantizers(cpi, x); if (is_inter_block(xdmi) && xdmi->sb_type < BLOCK_8X8) { @@ -1327,8 +1338,7 @@ static int set_segment_rdmult(VP9_COMP *const cpi, VP9_COMMON *const cm = &cpi->common; vp9_init_plane_quantizers(cpi, x); vpx_clear_system_state(); - segment_qindex = vp9_get_qindex(&cm->seg, segment_id, - cm->base_qindex); + segment_qindex = vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex); return vp9_compute_rd_mult(cpi, segment_qindex + cm->y_dc_delta_q); } @@ -1859,12 +1869,10 @@ static void update_state_rt(VP9_COMP *cpi, ThreadData *td, *(xd->mi[0]) = ctx->mic; *(x->mbmi_ext) = ctx->mbmi_ext; - if (seg->enabled && cpi->oxcf.aq_mode) { + if (seg->enabled && cpi->oxcf.aq_mode != NO_AQ) { // For in frame complexity AQ or variance AQ, copy segment_id from // segmentation_map. - if (cpi->oxcf.aq_mode == COMPLEXITY_AQ || - cpi->oxcf.aq_mode == VARIANCE_AQ || - cpi->oxcf.aq_mode == EQUATOR360_AQ) { + if (cpi->oxcf.aq_mode != CYCLIC_REFRESH_AQ) { const uint8_t *const map = seg->update_map ? cpi->segmentation_map : cm->last_frame_seg_map; mi->segment_id = get_segment_id(cm, map, bsize, mi_row, mi_col); @@ -2044,7 +2052,7 @@ static void rd_use_partition(VP9_COMP *cpi, pc_tree->partitioning = partition; save_context(x, mi_row, mi_col, a, l, sa, sl, bsize); - if (bsize == BLOCK_16X16 && cpi->oxcf.aq_mode) { + if (bsize == BLOCK_16X16 && cpi->oxcf.aq_mode != NO_AQ) { set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize); x->mb_energy = vp9_block_energy(cpi, x, bsize); } @@ -2574,7 +2582,7 @@ static void rd_pick_partition(VP9_COMP *cpi, ThreadData *td, set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize); - if (bsize == BLOCK_16X16 && cpi->oxcf.aq_mode) + if (bsize == BLOCK_16X16 && cpi->oxcf.aq_mode != NO_AQ) x->mb_energy = vp9_block_energy(cpi, x, bsize); if (cpi->sf.cb_partition_search && bsize == BLOCK_16X16) { @@ -2729,6 +2737,7 @@ static void rd_pick_partition(VP9_COMP *cpi, ThreadData *td, break; } } + if (skip) { if (src_diff_var == UINT_MAX) { set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize); @@ -2763,12 +2772,13 @@ static void rd_pick_partition(VP9_COMP *cpi, ThreadData *td, ctx->mic.interp_filter; rd_pick_sb_modes(cpi, tile_data, x, mi_row, mi_col, &sum_rdc, subsize, pc_tree->leaf_split[0], best_rdc.rdcost); + if (sum_rdc.rate == INT_MAX) sum_rdc.rdcost = INT64_MAX; } else { for (i = 0; i < 4 && sum_rdc.rdcost < best_rdc.rdcost; ++i) { - const int x_idx = (i & 1) * mi_step; - const int y_idx = (i >> 1) * mi_step; + const int x_idx = (i & 1) * mi_step; + const int y_idx = (i >> 1) * mi_step; if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols) continue; @@ -2872,6 +2882,7 @@ static void rd_pick_partition(VP9_COMP *cpi, ThreadData *td, } restore_context(x, mi_row, mi_col, a, l, sa, sl, bsize); } + // PARTITION_VERT if (partition_vert_allowed && (do_rect || vp9_active_v_edge(cpi, mi_col, mi_step))) { @@ -2954,6 +2965,8 @@ static void encode_rd_sb_row(VP9_COMP *cpi, MACROBLOCK *const x = &td->mb; MACROBLOCKD *const xd = &x->e_mbd; SPEED_FEATURES *const sf = &cpi->sf; + const int mi_col_start = tile_info->mi_col_start; + const int mi_col_end = tile_info->mi_col_end; int mi_col; // Initialize the left context for the new SB row @@ -2961,8 +2974,7 @@ static void encode_rd_sb_row(VP9_COMP *cpi, memset(xd->left_seg_context, 0, sizeof(xd->left_seg_context)); // Code each SB in the row - for (mi_col = tile_info->mi_col_start; mi_col < tile_info->mi_col_end; - mi_col += MI_BLOCK_SIZE) { + for (mi_col = mi_col_start; mi_col < mi_col_end; mi_col += MI_BLOCK_SIZE) { const struct segmentation *const seg = &cm->seg; int dummy_rate; int64_t dummy_dist; @@ -3762,6 +3774,8 @@ static void encode_nonrd_sb_row(VP9_COMP *cpi, TileInfo *const tile_info = &tile_data->tile_info; MACROBLOCK *const x = &td->mb; MACROBLOCKD *const xd = &x->e_mbd; + const int mi_col_start = tile_info->mi_col_start; + const int mi_col_end = tile_info->mi_col_end; int mi_col; // Initialize the left context for the new SB row @@ -3769,8 +3783,7 @@ static void encode_nonrd_sb_row(VP9_COMP *cpi, memset(xd->left_seg_context, 0, sizeof(xd->left_seg_context)); // Code each SB in the row - for (mi_col = tile_info->mi_col_start; mi_col < tile_info->mi_col_end; - mi_col += MI_BLOCK_SIZE) { + for (mi_col = mi_col_start; mi_col < mi_col_end; mi_col += MI_BLOCK_SIZE) { const struct segmentation *const seg = &cm->seg; RD_COST dummy_rdc; const int idx_str = cm->mi_stride * mi_row + mi_col; @@ -3981,8 +3994,7 @@ static int get_skip_encode_frame(const VP9_COMMON *cm, ThreadData *const td) { } return (intra_count << 2) < inter_count && - cm->frame_type != KEY_FRAME && - cm->show_frame; + cm->frame_type != KEY_FRAME && cm->show_frame; } void vp9_init_tile_data(VP9_COMP *cpi) { @@ -4035,14 +4047,15 @@ void vp9_encode_tile(VP9_COMP *cpi, ThreadData *td, &cpi->tile_data[tile_row * tile_cols + tile_col]; const TileInfo * const tile_info = &this_tile->tile_info; TOKENEXTRA *tok = cpi->tile_tok[tile_row][tile_col]; + const int mi_row_start = tile_info->mi_row_start; + const int mi_row_end = tile_info->mi_row_end; int mi_row; // Set up pointers to per thread motion search counters. td->mb.m_search_count_ptr = &td->rd_counts.m_search_count; td->mb.ex_search_count_ptr = &td->rd_counts.ex_search_count; - for (mi_row = tile_info->mi_row_start; mi_row < tile_info->mi_row_end; - mi_row += MI_BLOCK_SIZE) { + for (mi_row = mi_row_start; mi_row < mi_row_end; mi_row += MI_BLOCK_SIZE) { if (cpi->sf.use_nonrd_pick_mode) encode_nonrd_sb_row(cpi, td, this_tile, mi_row, &tok); else @@ -4169,10 +4182,10 @@ static void encode_frame_internal(VP9_COMP *cpi) { vpx_usec_timer_start(&emr_timer); #if CONFIG_FP_MB_STATS - if (cpi->use_fp_mb_stats) { - input_fpmb_stats(&cpi->twopass.firstpass_mb_stats, cm, - &cpi->twopass.this_frame_mb_stats); - } + if (cpi->use_fp_mb_stats) { + input_fpmb_stats(&cpi->twopass.firstpass_mb_stats, cm, + &cpi->twopass.this_frame_mb_stats); + } #endif // If allowed, encoding tiles in parallel with one thread handling one tile. @@ -4490,8 +4503,8 @@ static void encode_superblock(VP9_COMP *cpi, ThreadData *td, } else { mi->tx_size = (bsize >= BLOCK_8X8) ? mi->tx_size : TX_4X4; } - } + ++td->counts->tx.tx_totals[mi->tx_size]; ++td->counts->tx.tx_totals[get_uv_tx_size(mi, &xd->plane[1])]; if (cm->seg.enabled && cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) diff --git a/vp9/encoder/vp9_encoder.c b/vp9/encoder/vp9_encoder.c index 6247e9045..707bceb5b 100644 --- a/vp9/encoder/vp9_encoder.c +++ b/vp9/encoder/vp9_encoder.c @@ -135,11 +135,16 @@ static INLINE void Scale2Ratio(VPX_SCALING mode, int *hr, int *hs) { // so memset cannot be used, instead only inactive blocks should be reset. static void suppress_active_map(VP9_COMP *cpi) { unsigned char *const seg_map = cpi->segmentation_map; - int i; - if (cpi->active_map.enabled || cpi->active_map.update) - for (i = 0; i < cpi->common.mi_rows * cpi->common.mi_cols; ++i) + + if (cpi->active_map.enabled || cpi->active_map.update) { + const int rows = cpi->common.mi_rows; + const int cols = cpi->common.mi_cols; + int i; + + for (i = 0; i < rows * cols; ++i) if (seg_map[i] == AM_SEGMENT_ID_INACTIVE) seg_map[i] = AM_SEGMENT_ID_ACTIVE; + } } static void apply_active_map(VP9_COMP *cpi) { diff --git a/vp9/encoder/vp9_encoder.h b/vp9/encoder/vp9_encoder.h index b65dfa8a6..128b62328 100644 --- a/vp9/encoder/vp9_encoder.h +++ b/vp9/encoder/vp9_encoder.h @@ -408,7 +408,7 @@ typedef struct VP9_COMP { YV12_BUFFER_CONFIG last_frame_uf; TOKENEXTRA *tile_tok[4][1 << 6]; - unsigned int tok_count[4][1 << 6]; + uint32_t tok_count[4][1 << 6]; // Ambient reconstruction err target for force key frames int64_t ambient_err; @@ -440,7 +440,7 @@ typedef struct VP9_COMP { SPEED_FEATURES sf; - unsigned int max_mv_magnitude; + uint32_t max_mv_magnitude; int mv_step_param; int allow_comp_inter_inter; @@ -452,10 +452,10 @@ typedef struct VP9_COMP { // clips, and 300 for < HD clips. int encode_breakout; - unsigned char *segmentation_map; + uint8_t *segmentation_map; // segment threashold for encode breakout - int segment_encode_breakout[MAX_SEGMENTS]; + int segment_encode_breakout[MAX_SEGMENTS]; CYCLIC_REFRESH *cyclic_refresh; ActiveMap active_map; @@ -477,11 +477,10 @@ typedef struct VP9_COMP { YV12_BUFFER_CONFIG alt_ref_buffer; - #if CONFIG_INTERNAL_STATS unsigned int mode_chosen_counts[MAX_MODES]; - int count; + int count; uint64_t total_sq_error; uint64_t total_samples; ImageStat psnr; diff --git a/vp9/encoder/vp9_firstpass.c b/vp9/encoder/vp9_firstpass.c index f6e61b623..53a3ec7de 100644 --- a/vp9/encoder/vp9_firstpass.c +++ b/vp9/encoder/vp9_firstpass.c @@ -153,85 +153,85 @@ static void output_fpmb_stats(uint8_t *this_frame_mb_stats, VP9_COMMON *cm, #endif static void zero_stats(FIRSTPASS_STATS *section) { - section->frame = 0.0; - section->weight = 0.0; - section->intra_error = 0.0; - section->coded_error = 0.0; - section->sr_coded_error = 0.0; - section->pcnt_inter = 0.0; - section->pcnt_motion = 0.0; - section->pcnt_second_ref = 0.0; - section->pcnt_neutral = 0.0; - section->intra_skip_pct = 0.0; - section->intra_smooth_pct = 0.0; + section->frame = 0.0; + section->weight = 0.0; + section->intra_error = 0.0; + section->coded_error = 0.0; + section->sr_coded_error = 0.0; + section->pcnt_inter = 0.0; + section->pcnt_motion = 0.0; + section->pcnt_second_ref = 0.0; + section->pcnt_neutral = 0.0; + section->intra_skip_pct = 0.0; + section->intra_smooth_pct = 0.0; section->inactive_zone_rows = 0.0; section->inactive_zone_cols = 0.0; - section->MVr = 0.0; - section->mvr_abs = 0.0; - section->MVc = 0.0; - section->mvc_abs = 0.0; - section->MVrv = 0.0; - section->MVcv = 0.0; - section->mv_in_out_count = 0.0; - section->new_mv_count = 0.0; - section->count = 0.0; - section->duration = 1.0; - section->spatial_layer_id = 0; + section->MVr = 0.0; + section->mvr_abs = 0.0; + section->MVc = 0.0; + section->mvc_abs = 0.0; + section->MVrv = 0.0; + section->MVcv = 0.0; + section->mv_in_out_count = 0.0; + section->new_mv_count = 0.0; + section->count = 0.0; + section->duration = 1.0; + section->spatial_layer_id = 0; } static void accumulate_stats(FIRSTPASS_STATS *section, const FIRSTPASS_STATS *frame) { - section->frame += frame->frame; - section->weight += frame->weight; - section->spatial_layer_id = frame->spatial_layer_id; - section->intra_error += frame->intra_error; - section->coded_error += frame->coded_error; - section->sr_coded_error += frame->sr_coded_error; - section->pcnt_inter += frame->pcnt_inter; - section->pcnt_motion += frame->pcnt_motion; - section->pcnt_second_ref += frame->pcnt_second_ref; - section->pcnt_neutral += frame->pcnt_neutral; - section->intra_skip_pct += frame->intra_skip_pct; - section->intra_smooth_pct += frame->intra_smooth_pct; + section->frame += frame->frame; + section->weight += frame->weight; + section->spatial_layer_id = frame->spatial_layer_id; + section->intra_error += frame->intra_error; + section->coded_error += frame->coded_error; + section->sr_coded_error += frame->sr_coded_error; + section->pcnt_inter += frame->pcnt_inter; + section->pcnt_motion += frame->pcnt_motion; + section->pcnt_second_ref += frame->pcnt_second_ref; + section->pcnt_neutral += frame->pcnt_neutral; + section->intra_skip_pct += frame->intra_skip_pct; + section->intra_smooth_pct += frame->intra_smooth_pct; section->inactive_zone_rows += frame->inactive_zone_rows; section->inactive_zone_cols += frame->inactive_zone_cols; - section->MVr += frame->MVr; - section->mvr_abs += frame->mvr_abs; - section->MVc += frame->MVc; - section->mvc_abs += frame->mvc_abs; - section->MVrv += frame->MVrv; - section->MVcv += frame->MVcv; - section->mv_in_out_count += frame->mv_in_out_count; - section->new_mv_count += frame->new_mv_count; - section->count += frame->count; - section->duration += frame->duration; + section->MVr += frame->MVr; + section->mvr_abs += frame->mvr_abs; + section->MVc += frame->MVc; + section->mvc_abs += frame->mvc_abs; + section->MVrv += frame->MVrv; + section->MVcv += frame->MVcv; + section->mv_in_out_count += frame->mv_in_out_count; + section->new_mv_count += frame->new_mv_count; + section->count += frame->count; + section->duration += frame->duration; } static void subtract_stats(FIRSTPASS_STATS *section, const FIRSTPASS_STATS *frame) { - section->frame -= frame->frame; - section->weight -= frame->weight; - section->intra_error -= frame->intra_error; - section->coded_error -= frame->coded_error; - section->sr_coded_error -= frame->sr_coded_error; - section->pcnt_inter -= frame->pcnt_inter; - section->pcnt_motion -= frame->pcnt_motion; - section->pcnt_second_ref -= frame->pcnt_second_ref; - section->pcnt_neutral -= frame->pcnt_neutral; - section->intra_skip_pct -= frame->intra_skip_pct; - section->intra_smooth_pct -= frame->intra_smooth_pct; + section->frame -= frame->frame; + section->weight -= frame->weight; + section->intra_error -= frame->intra_error; + section->coded_error -= frame->coded_error; + section->sr_coded_error -= frame->sr_coded_error; + section->pcnt_inter -= frame->pcnt_inter; + section->pcnt_motion -= frame->pcnt_motion; + section->pcnt_second_ref -= frame->pcnt_second_ref; + section->pcnt_neutral -= frame->pcnt_neutral; + section->intra_skip_pct -= frame->intra_skip_pct; + section->intra_smooth_pct -= frame->intra_smooth_pct; section->inactive_zone_rows -= frame->inactive_zone_rows; section->inactive_zone_cols -= frame->inactive_zone_cols; - section->MVr -= frame->MVr; - section->mvr_abs -= frame->mvr_abs; - section->MVc -= frame->MVc; - section->mvc_abs -= frame->mvc_abs; - section->MVrv -= frame->MVrv; - section->MVcv -= frame->MVcv; - section->mv_in_out_count -= frame->mv_in_out_count; - section->new_mv_count -= frame->new_mv_count; - section->count -= frame->count; - section->duration -= frame->duration; + section->MVr -= frame->MVr; + section->mvr_abs -= frame->mvr_abs; + section->MVc -= frame->MVc; + section->mvc_abs -= frame->mvc_abs; + section->MVrv -= frame->MVrv; + section->MVcv -= frame->MVcv; + section->mv_in_out_count -= frame->mv_in_out_count; + section->new_mv_count -= frame->new_mv_count; + section->count -= frame->count; + section->duration -= frame->duration; } // Calculate an active area of the image that discounts formatting diff --git a/vp9/encoder/vp9_lookahead.c b/vp9/encoder/vp9_lookahead.c index 441280cb1..787bcf47e 100644 --- a/vp9/encoder/vp9_lookahead.c +++ b/vp9/encoder/vp9_lookahead.c @@ -89,7 +89,7 @@ struct lookahead_ctx *vp9_lookahead_init(unsigned int width, #define USE_PARTIAL_COPY 0 -int vp9_lookahead_push(struct lookahead_ctx *ctx, YV12_BUFFER_CONFIG *src, +int vp9_lookahead_push(struct lookahead_ctx *ctx, YV12_BUFFER_CONFIG *src, int64_t ts_start, int64_t ts_end, #if CONFIG_VP9_HIGHBITDEPTH int use_highbitdepth, diff --git a/vp9/encoder/vp9_mcomp.c b/vp9/encoder/vp9_mcomp.c index 2ebacc0b8..08333da93 100644 --- a/vp9/encoder/vp9_mcomp.c +++ b/vp9/encoder/vp9_mcomp.c @@ -362,8 +362,8 @@ static unsigned int setup_center_error(const MACROBLOCKD *xd, } *distortion = (uint32_t)besterr; besterr += mv_err_cost(bestmv, ref_mv, mvjcost, mvcost, error_per_bit); - if (besterr >= UINT32_MAX) - return UINT32_MAX; + if (besterr >= UINT_MAX) + return UINT_MAX; return (uint32_t)besterr; #else uint32_t besterr; @@ -448,7 +448,7 @@ uint32_t vp9_skip_sub_pixel_tree( if ((abs(bestmv->col - ref_mv->col) > (MAX_FULL_PEL_VAL << 3)) || (abs(bestmv->row - ref_mv->row) > (MAX_FULL_PEL_VAL << 3))) - return UINT32_MAX; + return UINT_MAX; return besterr; } @@ -602,7 +602,7 @@ uint32_t vp9_find_best_sub_pixel_tree_pruned_more(const MACROBLOCK *x, if ((abs(bestmv->col - ref_mv->col) > (MAX_FULL_PEL_VAL << 3)) || (abs(bestmv->row - ref_mv->row) > (MAX_FULL_PEL_VAL << 3))) - return UINT32_MAX; + return UINT_MAX; return besterr; } diff --git a/vp9/encoder/vp9_pickmode.c b/vp9/encoder/vp9_pickmode.c index 6fcc2a70f..7db6ef2b0 100644 --- a/vp9/encoder/vp9_pickmode.c +++ b/vp9/encoder/vp9_pickmode.c @@ -727,6 +727,13 @@ static void model_rd_for_sb_uv(VP9_COMP *cpi, BLOCK_SIZE plane_bsize, int rate; int64_t dist; int i; +#if CONFIG_VP9_HIGHBITDEPTH + uint64_t tot_var = *var_y; + uint64_t tot_sse = *sse_y; +#else + uint32_t tot_var = *var_y; + uint32_t tot_sse = *sse_y; +#endif this_rdc->rate = 0; this_rdc->dist = 0; @@ -738,14 +745,14 @@ static void model_rd_for_sb_uv(VP9_COMP *cpi, BLOCK_SIZE plane_bsize, const uint32_t ac_quant = pd->dequant[1]; const BLOCK_SIZE bs = plane_bsize; unsigned int var; - if (!x->color_sensitivity[i - 1]) continue; var = cpi->fn_ptr[bs].vf(p->src.buf, p->src.stride, pd->dst.buf, pd->dst.stride, &sse); - *var_y += var; - *sse_y += sse; + assert(sse >= var); + tot_var += var; + tot_sse += sse; #if CONFIG_VP9_HIGHBITDEPTH if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { @@ -779,6 +786,14 @@ static void model_rd_for_sb_uv(VP9_COMP *cpi, BLOCK_SIZE plane_bsize, this_rdc->rate += rate; this_rdc->dist += dist << 4; } + +#if CONFIG_VP9_HIGHBITDEPTH + *var_y = tot_var > UINT32_MAX ? UINT32_MAX : (uint32_t)tot_var; + *sse_y = tot_sse > UINT32_MAX ? UINT32_MAX : (uint32_t)tot_sse; +#else + *var_y = tot_var; + *sse_y = tot_sse; +#endif } static int get_pred_buffer(PRED_BUFFER *p, int len) { @@ -1723,13 +1738,21 @@ void vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, pd->dst.stride = this_mode_pred->stride; } } else { + // TODO(jackychen): the low-bitdepth condition causes a segfault in + // high-bitdepth builds. + // https://bugs.chromium.org/p/webm/issues/detail?id=1250 +#if CONFIG_VP9_HIGHBITDEPTH + const int large_block = bsize > BLOCK_32X32; +#else + const int large_block = bsize >= BLOCK_32X32; +#endif mi->interp_filter = (filter_ref == SWITCHABLE) ? EIGHTTAP : filter_ref; vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize); // For large partition blocks, extra testing is done. - if (cpi->oxcf.rc_mode == VPX_CBR && bsize > BLOCK_32X32 && - !cyclic_refresh_segment_id_boosted(xd->mi[0]->segment_id) && - cm->base_qindex) { + if (cpi->oxcf.rc_mode == VPX_CBR && large_block && + !cyclic_refresh_segment_id_boosted(xd->mi[0]->segment_id) && + cm->base_qindex) { model_rd_for_sb_y_large(cpi, bsize, x, xd, &this_rdc.rate, &this_rdc.dist, &var_y, &sse_y, mi_row, mi_col, &this_early_term); diff --git a/vp9/encoder/vp9_rd.c b/vp9/encoder/vp9_rd.c index fba45adc7..91b291187 100644 --- a/vp9/encoder/vp9_rd.c +++ b/vp9/encoder/vp9_rd.c @@ -349,6 +349,7 @@ static void model_rd_norm(int xsq_q10, int *r_q10, int *d_q10) { 38, 28, 21, 16, 12, 10, 8, 6, 5, 3, 2, 1, 1, 1, 0, 0, }; + // Normalized distortion: // This table models the normalized distortion for a Laplacian source // with given variance when quantized with a uniform quantizer diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c index abbcb2bdd..6e4ffee92 100644 --- a/vp9/encoder/vp9_rdopt.c +++ b/vp9/encoder/vp9_rdopt.c @@ -1594,7 +1594,7 @@ static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, // Do joint motion search in compound mode to get more accurate mv. struct buf_2d backup_yv12[2][MAX_MB_PLANE]; - uint32_t last_besterr[2] = {UINT32_MAX, UINT32_MAX}; + uint32_t last_besterr[2] = {UINT_MAX, UINT_MAX}; const YV12_BUFFER_CONFIG *const scaled_ref_frame[2] = { vp9_get_scaled_ref_frame(cpi, mi->ref_frame[0]), vp9_get_scaled_ref_frame(cpi, mi->ref_frame[1]) @@ -1640,7 +1640,7 @@ static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, // and break out of the search loop if it couldn't find a better mv. for (ite = 0; ite < 4; ite++) { struct buf_2d ref_yv12[2]; - uint32_t bestsme = UINT32_MAX; + uint32_t bestsme = UINT_MAX; int sadpb = x->sadperbit16; MV tmp_mv; int search_range = 3; @@ -1705,7 +1705,7 @@ static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, search_range, &cpi->fn_ptr[bsize], &ref_mv[id].as_mv, second_pred); - if (bestsme < UINT32_MAX) + if (bestsme < UINT_MAX) bestsme = vp9_get_mvpred_av_var(x, &tmp_mv, &ref_mv[id].as_mv, second_pred, &cpi->fn_ptr[bsize], 1); @@ -1714,7 +1714,7 @@ static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, x->mv_row_min = tmp_row_min; x->mv_row_max = tmp_row_max; - if (bestsme < UINT32_MAX) { + if (bestsme < UINT_MAX) { uint32_t dis; /* TODO: use dis in distortion calculation later. */ uint32_t sse; bestsme = cpi->find_fractional_mv_step( @@ -1860,7 +1860,7 @@ static int64_t rd_pick_best_sub8x8_mode(VP9_COMP *cpi, MACROBLOCK *x, seg_mvs[i][mi->ref_frame[0]].as_int == INVALID_MV) { MV *const new_mv = &mode_mv[NEWMV][0].as_mv; int step_param = 0; - uint32_t bestsme = UINT32_MAX; + uint32_t bestsme = UINT_MAX; int sadpb = x->sadperbit4; MV mvp_full; int max_mv; @@ -1915,7 +1915,7 @@ static int64_t rd_pick_best_sub8x8_mode(VP9_COMP *cpi, MACROBLOCK *x, &bsi->ref_mv[0]->as_mv, new_mv, INT_MAX, 1); - if (bestsme < UINT32_MAX) { + if (bestsme < UINT_MAX) { uint32_t distortion; cpi->find_fractional_mv_step( x, @@ -3400,9 +3400,10 @@ void vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, rate2 += skip_cost0; } else { // FIXME(rbultje) make this work for splitmv also + assert(total_sse >= 0); + rate2 += skip_cost1; distortion2 = total_sse; - assert(total_sse >= 0); rate2 -= (rate_y + rate_uv); this_skip2 = 1; } diff --git a/vp9/encoder/vp9_temporal_filter.c b/vp9/encoder/vp9_temporal_filter.c index 02bcf5a24..b6323e048 100644 --- a/vp9/encoder/vp9_temporal_filter.c +++ b/vp9/encoder/vp9_temporal_filter.c @@ -433,9 +433,8 @@ static void temporal_filter_iterate_c(VP9_COMP *cpi, vp9_highbd_temporal_filter_apply_c(f->u_buffer + mb_uv_offset, f->uv_stride, predictor + 256, mb_uv_width, mb_uv_height, - adj_strength, - filter_weight, accumulator + 256, - count + 256); + adj_strength, filter_weight, + accumulator + 256, count + 256); vp9_highbd_temporal_filter_apply_c(f->v_buffer + mb_uv_offset, f->uv_stride, predictor + 512, mb_uv_width, mb_uv_height, |