]> granicus.if.org Git - libvpx/commitdiff
Merge "Moving costs from MACROBLOCK to VP9_COMP."
authorDmitry Kovalev <dkovalev@google.com>
Tue, 6 May 2014 02:10:25 +0000 (19:10 -0700)
committerGerrit Code Review <gerrit@gerrit.golo.chromium.org>
Tue, 6 May 2014 02:10:25 +0000 (19:10 -0700)
1  2 
vp9/encoder/vp9_encoder.h
vp9/encoder/vp9_rdopt.c

index 364ea3a9ef64b6e1a605f4ab727d87a1efb6fbce,3cd0fc1ac994d173811a80c6472b910a053a61c6..87320952d477a234a6eb7dda1a2a7a0c722ce565
@@@ -276,7 -276,6 +276,7 @@@ typedef struct VP9EncoderConfig 
  
    int arnr_max_frames;
    int arnr_strength;
 +  int arnr_type;
  
    int tile_columns;
    int tile_rows;
@@@ -444,6 -443,7 +444,6 @@@ typedef struct VP9_COMP 
  
    YV12_BUFFER_CONFIG alt_ref_buffer;
    YV12_BUFFER_CONFIG *frames[MAX_LAG_BUFFERS];
 -  int fixed_divide[512];
  
  #if CONFIG_INTERNAL_STATS
    unsigned int mode_chosen_counts[MAX_MODES];
  
    search_site_config ss_cfg;
  
+   int mbmode_cost[INTRA_MODES];
+   unsigned inter_mode_cost[INTER_MODE_CONTEXTS][INTER_MODES];
+   int intra_uv_mode_cost[FRAME_TYPES][INTRA_MODES];
+   int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES];
+   int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS];
  #if CONFIG_MULTIPLE_ARF
    // ARF tracking variables.
    int multi_arf_enabled;
diff --combined vp9/encoder/vp9_rdopt.c
index f854356b9ff3bb96e4c2fe9d6af91ddc75461f4c,6c6c1d7ee3a7223718c45d963eeeb32fb9fb3d80..857015e51749423ed67b20cdbb7e07cdc6a439b0
@@@ -152,24 -152,23 +152,23 @@@ static int16_t* raster_block_offset_int
  }
  
  static void fill_mode_costs(VP9_COMP *cpi) {
-   MACROBLOCK *const x = &cpi->mb;
    const FRAME_CONTEXT *const fc = &cpi->common.fc;
    int i, j;
  
    for (i = 0; i < INTRA_MODES; i++)
      for (j = 0; j < INTRA_MODES; j++)
-       vp9_cost_tokens((int *)x->y_mode_costs[i][j], vp9_kf_y_mode_prob[i][j],
+       vp9_cost_tokens(cpi->y_mode_costs[i][j], vp9_kf_y_mode_prob[i][j],
                        vp9_intra_mode_tree);
  
    // TODO(rbultje) separate tables for superblock costing?
-   vp9_cost_tokens(x->mbmode_cost, fc->y_mode_prob[1], vp9_intra_mode_tree);
-   vp9_cost_tokens(x->intra_uv_mode_cost[KEY_FRAME],
+   vp9_cost_tokens(cpi->mbmode_cost, fc->y_mode_prob[1], vp9_intra_mode_tree);
+   vp9_cost_tokens(cpi->intra_uv_mode_cost[KEY_FRAME],
                    vp9_kf_uv_mode_prob[TM_PRED], vp9_intra_mode_tree);
-   vp9_cost_tokens(x->intra_uv_mode_cost[INTER_FRAME],
+   vp9_cost_tokens(cpi->intra_uv_mode_cost[INTER_FRAME],
                    fc->uv_mode_prob[TM_PRED], vp9_intra_mode_tree);
  
    for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i)
-     vp9_cost_tokens((int *)x->switchable_interp_costs[i],
+     vp9_cost_tokens(cpi->switchable_interp_costs[i],
                      fc->switchable_interp_prob[i], vp9_switchable_interp_tree);
  }
  
@@@ -313,7 -312,7 +312,7 @@@ void vp9_initialize_rd_consts(VP9_COMP 
                                 &cm->fc.nmvc, cm->allow_high_precision_mv);
  
        for (i = 0; i < INTER_MODE_CONTEXTS; ++i)
-         vp9_cost_tokens((int *)x->inter_mode_cost[i],
+         vp9_cost_tokens((int *)cpi->inter_mode_cost[i],
                          cm->fc.inter_mode_probs[i], vp9_inter_mode_tree);
      }
    }
@@@ -1187,7 -1186,7 +1186,7 @@@ static int64_t rd_pick_intra_sub_8x8_y_
    int tot_rate_y = 0;
    int64_t total_rd = 0;
    ENTROPY_CONTEXT t_above[4], t_left[4];
-   const int *bmode_costs = mb->mbmode_cost;
+   const int *bmode_costs = cpi->mbmode_cost;
  
    vpx_memcpy(t_above, xd->plane[0].above_context, sizeof(t_above));
    vpx_memcpy(t_left, xd->plane[0].left_context, sizeof(t_left));
          const PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, i);
          const PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, i);
  
-         bmode_costs  = mb->y_mode_costs[A][L];
+         bmode_costs  = cpi->y_mode_costs[A][L];
        }
  
        this_rd = rd_pick_intra4x4block(cpi, mb, i, &best_mode, bmode_costs,
@@@ -1250,7 -1249,7 +1249,7 @@@ static int64_t rd_pick_intra_sby_mode(V
    int64_t this_distortion, this_rd;
    TX_SIZE best_tx = TX_4X4;
    int i;
-   int *bmode_costs = x->mbmode_cost;
+   int *bmode_costs = cpi->mbmode_cost;
  
    if (cpi->sf.tx_size_search_method == USE_FULL_RD)
      for (i = 0; i < TX_MODES; i++)
        const PREDICTION_MODE A = vp9_above_block_mode(mic, above_mi, 0);
        const PREDICTION_MODE L = vp9_left_block_mode(mic, left_mi, 0);
  
-       bmode_costs = x->y_mode_costs[A][L];
+       bmode_costs = cpi->y_mode_costs[A][L];
      }
      mic->mbmi.mode = mode;
  
@@@ -1378,7 -1377,7 +1377,7 @@@ static int64_t rd_pick_intra_sbuv_mode(
      if (this_rate_tokenonly == INT_MAX)
        continue;
      this_rate = this_rate_tokenonly +
-                 x->intra_uv_mode_cost[cpi->common.frame_type][mode];
+                 cpi->intra_uv_mode_cost[cpi->common.frame_type][mode];
      this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion);
  
      if (this_rd < best_rd) {
@@@ -1426,7 -1425,7 +1425,7 @@@ static int64_t rd_sbuv_dcpred(const VP9
    x->e_mbd.mi[0]->mbmi.uv_mode = DC_PRED;
    super_block_uvrd(cpi, x, rate_tokenonly, distortion,
                     skippable, &unused, bsize, INT64_MAX);
-   *rate = *rate_tokenonly + x->intra_uv_mode_cost[cm->frame_type][DC_PRED];
+   *rate = *rate_tokenonly + cpi->intra_uv_mode_cost[cm->frame_type][DC_PRED];
    return RDCOST(x->rdmult, x->rddiv, *rate, *distortion);
  }
  
@@@ -1460,7 -1459,7 +1459,7 @@@ static int cost_mv_ref(const VP9_COMP *
    // Don't account for mode here if segment skip is enabled.
    if (!vp9_segfeature_active(&cpi->common.seg, segment_id, SEG_LVL_SKIP)) {
      assert(is_inter_mode(mode));
-     return x->inter_mode_cost[mode_context][INTER_OFFSET(mode)];
+     return cpi->inter_mode_cost[mode_context][INTER_OFFSET(mode)];
    } else {
      return 0;
    }
@@@ -1806,7 -1805,7 +1805,7 @@@ static int64_t rd_pick_best_sub8x8_mode
          // motion search for newmv (single predictor case only)
          if (!has_second_rf && this_mode == NEWMV &&
              seg_mvs[i][mbmi->ref_frame[0]].as_int == INVALID_MV) {
 -          int_mv *const new_mv = &mode_mv[NEWMV][0];
 +          MV *const new_mv = &mode_mv[NEWMV][0].as_mv;
            int step_param = 0;
            int further_steps;
            int thissme, bestsme = INT_MAX;
                                       step_param,
                                       sadpb, 1, v_fn_ptr, 1,
                                       &bsi->ref_mv[0]->as_mv,
 -                                     &new_mv->as_mv);
 +                                     new_mv);
              if (bestsme < INT_MAX)
 -              bestsme = vp9_get_mvpred_var(x, &new_mv->as_mv,
 +              bestsme = vp9_get_mvpred_var(x, new_mv,
                                             &bsi->ref_mv[0]->as_mv,
                                             v_fn_ptr, 1);
            } else if (cpi->sf.search_method == SQUARE) {
                                          step_param,
                                          sadpb, 1, v_fn_ptr, 1,
                                          &bsi->ref_mv[0]->as_mv,
 -                                        &new_mv->as_mv);
 +                                        new_mv);
              if (bestsme < INT_MAX)
 -              bestsme = vp9_get_mvpred_var(x, &new_mv->as_mv,
 +              bestsme = vp9_get_mvpred_var(x, new_mv,
                                             &bsi->ref_mv[0]->as_mv,
                                             v_fn_ptr, 1);
            } else if (cpi->sf.search_method == BIGDIA) {
                                          step_param,
                                          sadpb, 1, v_fn_ptr, 1,
                                          &bsi->ref_mv[0]->as_mv,
 -                                        &new_mv->as_mv);
 +                                        new_mv);
              if (bestsme < INT_MAX)
 -              bestsme = vp9_get_mvpred_var(x, &new_mv->as_mv,
 +              bestsme = vp9_get_mvpred_var(x, new_mv,
                                             &bsi->ref_mv[0]->as_mv,
                                             v_fn_ptr, 1);
            } else {
              bestsme = vp9_full_pixel_diamond(cpi, x, &mvp_full, step_param,
                                               sadpb, further_steps, 0, v_fn_ptr,
                                               &bsi->ref_mv[0]->as_mv,
 -                                             &new_mv->as_mv);
 +                                             new_mv);
            }
  
            // Should we do a full search (best quality only)
                                             &best_mv->as_mv);
              if (thissme < bestsme) {
                bestsme = thissme;
 -              new_mv->as_int = best_mv->as_int;
 +              *new_mv = best_mv->as_mv;
              } else {
                // The full search result is actually worse so re-instate the
                // previous best vector
 -              best_mv->as_int = new_mv->as_int;
 +              best_mv->as_mv = *new_mv;
              }
            }
  
            if (bestsme < INT_MAX) {
              int distortion;
              cpi->find_fractional_mv_step(x,
 -                                         &new_mv->as_mv,
 +                                         new_mv,
                                           &bsi->ref_mv[0]->as_mv,
                                           cm->allow_high_precision_mv,
                                           x->errorperbit, v_fn_ptr,
                                           &x->pred_sse[mbmi->ref_frame[0]]);
  
              // save motion search result for use in compound prediction
 -            seg_mvs[i][mbmi->ref_frame[0]].as_int = new_mv->as_int;
 +            seg_mvs[i][mbmi->ref_frame[0]].as_mv = *new_mv;
            }
  
            if (cpi->sf.adaptive_motion_search)
 -            x->pred_mv[mbmi->ref_frame[0]].as_int = new_mv->as_int;
 +            x->pred_mv[mbmi->ref_frame[0]].as_mv = *new_mv;
  
            // restore src pointers
            mi_buf_restore(x, orig_src, orig_pre);
@@@ -2334,12 -2333,12 +2333,12 @@@ const YV12_BUFFER_CONFIG *vp9_get_scale
    return (scaled_idx != ref_idx) ? &cm->frame_bufs[scaled_idx].buf : NULL;
  }
  
- int vp9_get_switchable_rate(const MACROBLOCK *x) {
-   const MACROBLOCKD *const xd = &x->e_mbd;
+ int vp9_get_switchable_rate(const VP9_COMP *cpi) {
+   const MACROBLOCKD *const xd = &cpi->mb.e_mbd;
    const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
    const int ctx = vp9_get_pred_context_switchable_interp(xd);
    return SWITCHABLE_INTERP_RATE_FACTOR *
-              x->switchable_interp_costs[ctx][mbmi->interp_filter];
+              cpi->switchable_interp_costs[ctx][mbmi->interp_filter];
  }
  
  static void single_motion_search(VP9_COMP *cpi, MACROBLOCK *x,
@@@ -2788,7 -2787,7 +2787,7 @@@ static int64_t handle_inter_mode(VP9_CO
          int j;
          int64_t rs_rd;
          mbmi->interp_filter = i;
-         rs = vp9_get_switchable_rate(x);
+         rs = vp9_get_switchable_rate(cpi);
          rs_rd = RDCOST(x->rdmult, x->rddiv, rs, 0);
  
          if (i > 0 && intpel_mv) {
    // Set the appropriate filter
    mbmi->interp_filter = cm->interp_filter != SWITCHABLE ?
        cm->interp_filter : *best_filter;
-   rs = cm->interp_filter == SWITCHABLE ? vp9_get_switchable_rate(x) : 0;
+   rs = cm->interp_filter == SWITCHABLE ? vp9_get_switchable_rate(cpi) : 0;
  
    if (pred_exists) {
      if (best_needs_copy) {
    }
  
    if (cm->interp_filter == SWITCHABLE)
-     *rate2 += vp9_get_switchable_rate(x);
+     *rate2 += vp9_get_switchable_rate(cpi);
  
    if (!is_comp_pred) {
      if (!x->in_active_map) {
@@@ -3250,8 -3249,9 +3249,8 @@@ int64_t vp9_rd_pick_inter_mode_sb(VP9_C
      // an unfiltered alternative. We allow near/nearest as well
      // because they may result in zero-zero MVs but be cheaper.
      if (cpi->rc.is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0)) {
 -      const int altref_zero_mask =
 +      mode_skip_mask =
            ~((1 << THR_NEARESTA) | (1 << THR_NEARA) | (1 << THR_ZEROA));
 -      mode_skip_mask |= altref_zero_mask;
        if (frame_mv[NEARMV][ALTREF_FRAME].as_int != 0)
          mode_skip_mask |= (1 << THR_NEARA);
        if (frame_mv[NEARESTMV][ALTREF_FRAME].as_int != 0)
        skippable = skippable && skip_uv[uv_tx];
        mbmi->uv_mode = mode_uv[uv_tx];
  
-       rate2 = rate_y + x->mbmode_cost[mbmi->mode] + rate_uv_intra[uv_tx];
+       rate2 = rate_y + cpi->mbmode_cost[mbmi->mode] + rate_uv_intra[uv_tx];
        if (this_mode != DC_PRED && this_mode != TM_PRED)
          rate2 += intra_cost_penalty;
        distortion2 = distortion_y + distortion_uv;
@@@ -4034,7 -4034,7 +4033,7 @@@ int64_t vp9_rd_pick_inter_mode_sub8x8(V
  
              if (tmp_rd == INT64_MAX)
                continue;
-             rs = vp9_get_switchable_rate(x);
+             rs = vp9_get_switchable_rate(cpi);
              rs_rd = RDCOST(x->rdmult, x->rddiv, rs, 0);
              rd_opt->filter_cache[switchable_filter_index] = tmp_rd;
              rd_opt->filter_cache[SWITCHABLE_FILTERS] =
        distortion2 += distortion;
  
        if (cm->interp_filter == SWITCHABLE)
-         rate2 += vp9_get_switchable_rate(x);
+         rate2 += vp9_get_switchable_rate(cpi);
  
        if (!mode_excluded)
          mode_excluded = comp_pred ? cm->reference_mode == SINGLE_REFERENCE