Merge "Simplify rd_pick_intra_sby_mode()"
authorYaowu Xu <yaowu@google.com>
Tue, 23 Sep 2014 00:13:55 +0000 (17:13 -0700)
committerGerrit Code Review <gerrit@gerrit.golo.chromium.org>
Tue, 23 Sep 2014 00:13:55 +0000 (17:13 -0700)
1  2 
vp9/encoder/vp9_rdopt.c

diff --combined vp9/encoder/vp9_rdopt.c
@@@ -91,12 -91,6 +91,12 @@@ static const MODE_DEFINITION vp9_mode_o
  
    {NEARMV,    {LAST_FRAME,   NONE}},
    {NEARMV,    {ALTREF_FRAME, NONE}},
 +  {NEARMV,    {GOLDEN_FRAME, NONE}},
 +
 +  {ZEROMV,    {LAST_FRAME,   NONE}},
 +  {ZEROMV,    {GOLDEN_FRAME, NONE}},
 +  {ZEROMV,    {ALTREF_FRAME, NONE}},
 +
    {NEARESTMV, {LAST_FRAME,   ALTREF_FRAME}},
    {NEARESTMV, {GOLDEN_FRAME, ALTREF_FRAME}},
  
  
    {NEARMV,    {LAST_FRAME,   ALTREF_FRAME}},
    {NEWMV,     {LAST_FRAME,   ALTREF_FRAME}},
 -  {NEARMV,    {GOLDEN_FRAME, NONE}},
    {NEARMV,    {GOLDEN_FRAME, ALTREF_FRAME}},
    {NEWMV,     {GOLDEN_FRAME, ALTREF_FRAME}},
  
 -  {ZEROMV,    {LAST_FRAME,   NONE}},
 -  {ZEROMV,    {GOLDEN_FRAME, NONE}},
 -  {ZEROMV,    {ALTREF_FRAME, NONE}},
    {ZEROMV,    {LAST_FRAME,   ALTREF_FRAME}},
    {ZEROMV,    {GOLDEN_FRAME, ALTREF_FRAME}},
  
@@@ -827,6 -825,7 +827,7 @@@ static int64_t rd_pick_intra_sub_8x8_y_
    return RDCOST(mb->rdmult, mb->rddiv, cost, total_distortion);
  }
  
+ // This function is used only for intra_only frames
  static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x,
                                        int *rate, int *rate_tokenonly,
                                        int64_t *distortion, int *skippable,
    int64_t this_distortion, this_rd;
    TX_SIZE best_tx = TX_4X4;
    int i;
-   int *bmode_costs = cpi->mbmode_cost;
+   int *bmode_costs;
+   const MODE_INFO *above_mi = xd->mi[-xd->mi_stride].src_mi;
+   const MODE_INFO *left_mi = xd->left_available ? xd->mi[-1].src_mi : NULL;
+   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 = cpi->y_mode_costs[A][L];
  
    if (cpi->sf.tx_size_search_method == USE_FULL_RD)
      for (i = 0; i < TX_MODES; i++)
    /* Y Search for intra prediction mode */
    for (mode = DC_PRED; mode <= TM_PRED; mode++) {
      int64_t local_tx_cache[TX_MODES];
-     MODE_INFO *above_mi = xd->mi[-xd->mi_stride].src_mi;
-     MODE_INFO *left_mi = xd->left_available ? xd->mi[-1].src_mi : NULL;
-     if (cpi->common.frame_type == KEY_FRAME) {
-       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 = cpi->y_mode_costs[A][L];
-     }
      mic->mbmi.mode = mode;
  
      super_block_yrd(cpi, x, &this_rate_tokenonly, &this_distortion,
@@@ -2574,7 -2569,7 +2571,7 @@@ int64_t vp9_rd_pick_inter_mode_sb(VP9_C
    int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS];
    MB_MODE_INFO best_mbmode;
    int best_mode_skippable = 0;
 -  int mode_index, best_mode_index = -1;
 +  int midx, best_mode_index = -1;
    unsigned int ref_costs_single[MAX_REF_FRAMES], ref_costs_comp[MAX_REF_FRAMES];
    vp9_prob comp_mode_p;
    int64_t best_intra_rd = INT64_MAX;
    int mode_skip_start = cpi->sf.mode_skip_start + 1;
    const int *const rd_threshes = rd_opt->threshes[segment_id][bsize];
    const int *const rd_thresh_freq_fact = rd_opt->thresh_freq_fact[bsize];
 +  int mode_threshold[MAX_MODES];
 +  int *mode_map = rd_opt->mode_map[bsize];
    const int mode_search_skip_flags = cpi->sf.mode_search_skip_flags;
    vp9_zero(best_mbmode);
 +
    x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH;
  
    estimate_ref_frame_costs(cm, xd, segment_id, ref_costs_single, ref_costs_comp,
    mode_skip_mask[INTRA_FRAME] |=
        ~(cpi->sf.intra_y_mode_mask[max_txsize_lookup[bsize]]);
  
 -  for (mode_index = 0; mode_index < MAX_MODES; ++mode_index) {
 +  for (i = 0; i < MAX_MODES; ++i)
 +    mode_threshold[i] = ((int64_t)rd_threshes[i] * rd_thresh_freq_fact[i]) >> 5;
 +
 +  midx =  cpi->sf.schedule_mode_search ? mode_skip_start : 0;
 +  while (midx > 4) {
 +    uint8_t end_pos = 0;
 +    for (i = 5; i < midx; ++i) {
 +      if (mode_threshold[mode_map[i - 1]] > mode_threshold[mode_map[i]]) {
 +        uint8_t tmp = mode_map[i];
 +        mode_map[i] = mode_map[i - 1];
 +        mode_map[i - 1] = tmp;
 +        end_pos = i;
 +      }
 +    }
 +    midx = end_pos;
 +  }
 +
 +  for (midx = 0; midx < MAX_MODES; ++midx) {
 +    int mode_index = mode_map[midx];
      int mode_excluded = 0;
      int64_t this_rd = INT64_MAX;
      int disable_skip = 0;
      int64_t distortion2 = 0, distortion_y = 0, distortion_uv = 0;
      int skippable = 0;
      int64_t tx_cache[TX_MODES];
 -    int i;
      int this_skip2 = 0;
      int64_t total_sse = INT64_MAX;
      int early_term = 0;
  
      // Look at the reference frame of the best mode so far and set the
      // skip mask to look at a subset of the remaining modes.
 -    if (mode_index == mode_skip_start && best_mode_index >= 0) {
 +    if (midx == mode_skip_start && best_mode_index >= 0) {
        switch (best_mbmode.ref_frame[0]) {
          case INTRA_FRAME:
            break;
        continue;
  
      // Test best rd so far against threshold for trying this mode.
 -    if (rd_less_than_thresh(best_rd, rd_threshes[mode_index],
 -                            rd_thresh_freq_fact[mode_index]))
 +    if (best_mode_skippable && cpi->sf.schedule_mode_search)
 +      mode_threshold[mode_index] <<= 1;
 +
 +    if (best_rd < mode_threshold[mode_index])
        continue;
  
      if (cpi->sf.motion_field_mode_search) {
           (cm->interp_filter == best_mbmode.interp_filter) ||
           !is_inter_block(&best_mbmode));
  
 -  update_rd_thresh_fact(cpi, bsize, best_mode_index);
 +  if (!cpi->rc.is_src_frame_alt_ref)
 +    update_rd_thresh_fact(cpi, bsize, best_mode_index);
  
    // macroblock modes
    *mbmi = best_mbmode;