#include "vp8/common/entropy.h"
#include "vpx_ports/mem.h"
+#define MAX_MODES 20
+
/* motion search site */
typedef struct
{
int64_t prediction_error;
int64_t intra_error;
+ int rd_thresh_mult[MAX_MODES];
+ int rd_threshes[MAX_MODES];
+
void (*short_fdct4x4)(short *input, short *output, int pitch);
void (*short_fdct8x4)(short *input, short *output, int pitch);
extern void vp8cx_init_mbrthread_data(VP8_COMP *cpi,
MACROBLOCK *x,
MB_ROW_COMP *mbr_ei,
- int mb_row,
int count);
static void adjust_act_zbin( VP8_COMP *cpi, MACROBLOCK *x );
vp8cx_frame_init_quantizer(cpi);
- vp8_initialize_rd_consts(cpi,
+ vp8_initialize_rd_consts(cpi, x,
vp8_dc_quant(cm->base_qindex, cm->y1dc_delta_q));
vp8cx_initialize_me_consts(cpi, cm->base_qindex);
{
int i;
- vp8cx_init_mbrthread_data(cpi, x, cpi->mb_row_ei, 1, cpi->encoding_thread_count);
+ vp8cx_init_mbrthread_data(cpi, x, cpi->mb_row_ei,
+ cpi->encoding_thread_count);
for (i = 0; i < cm->mb_rows; i++)
cpi->mt_current_mb_col[i] = -1;
zd->block[i].dequant = zd->dequant_uv;
zd->block[24].dequant = zd->dequant_y2;
#endif
+
+
+ vpx_memcpy(z->rd_threshes, x->rd_threshes, sizeof(x->rd_threshes));
+ vpx_memcpy(z->rd_thresh_mult, x->rd_thresh_mult,
+ sizeof(x->rd_thresh_mult));
}
}
void vp8cx_init_mbrthread_data(VP8_COMP *cpi,
MACROBLOCK *x,
MB_ROW_COMP *mbr_ei,
- int mb_row,
int count
)
{
VP8_COMMON *const cm = & cpi->common;
MACROBLOCKD *const xd = & x->e_mbd;
int i;
- (void) mb_row;
for (i = 0; i < count; i++)
{
/* Initialise the MV cost table to the defaults */
{
int flag[2] = {1, 1};
- vp8_initialize_rd_consts(cpi, vp8_dc_quant(cm->base_qindex, cm->y1dc_delta_q));
+ vp8_initialize_rd_consts(cpi, x, vp8_dc_quant(cm->base_qindex, cm->y1dc_delta_q));
vpx_memcpy(cm->fc.mvc, vp8_default_mv_context, sizeof(vp8_default_mv_context));
vp8_build_component_cost_table(cpi->mb.mvcost, (const MV_CONTEXT *) cm->fc.mvc, flag);
}
/* Set starting values of RD threshold multipliers (128 = *1) */
for (i = 0; i < MAX_MODES; i++)
{
- cpi->rd_thresh_mult[i] = 128;
+ cpi->mb.rd_thresh_mult[i] = 128;
}
#ifdef ENTROPY_STATS
/* Reset the RD threshold multipliers to default of * 1 (128) */
for (i = 0; i < MAX_MODES; i++)
{
- cpi->rd_thresh_mult[i] = 128;
+ cpi->mb.rd_thresh_mult[i] = 128;
}
}
#define AF_THRESH 25
#define AF_THRESH2 100
#define ARF_DECAY_THRESH 12
-#define MAX_MODES 20
+
#define MIN_THRESHMULT 32
#define MAX_THRESHMULT 512
unsigned int mode_chosen_counts[MAX_MODES];
unsigned int mbs_tested_so_far;
- int rd_thresh_mult[MAX_MODES];
int rd_baseline_thresh[MAX_MODES];
- int rd_threshes[MAX_MODES];
int RDMULT;
int RDDIV ;
int this_rd = INT_MAX;
int this_ref_frame = ref_frame_map[vp8_ref_frame_order[mode_index]];
- if (best_rd <= cpi->rd_threshes[mode_index])
+ if (best_rd <= x->rd_threshes[mode_index])
continue;
if (this_ref_frame < 0)
{
/* Increase the threshold for coding this mode to make it less
* likely to be chosen */
- cpi->rd_thresh_mult[mode_index] += 4;
+ x->rd_thresh_mult[mode_index] += 4;
- if (cpi->rd_thresh_mult[mode_index] > MAX_THRESHMULT)
- cpi->rd_thresh_mult[mode_index] = MAX_THRESHMULT;
+ if (x->rd_thresh_mult[mode_index] > MAX_THRESHMULT)
+ x->rd_thresh_mult[mode_index] = MAX_THRESHMULT;
- cpi->rd_threshes[mode_index] =
+ x->rd_threshes[mode_index] =
(cpi->rd_baseline_thresh[mode_index] >> 7) *
- cpi->rd_thresh_mult[mode_index];
+ x->rd_thresh_mult[mode_index];
continue;
}
}
/* Testing this mode gave rise to an improvement in best error
* score. Lower threshold a bit for next time
*/
- cpi->rd_thresh_mult[mode_index] =
- (cpi->rd_thresh_mult[mode_index] >= (MIN_THRESHMULT + 2)) ?
- cpi->rd_thresh_mult[mode_index] - 2 : MIN_THRESHMULT;
- cpi->rd_threshes[mode_index] =
+ x->rd_thresh_mult[mode_index] =
+ (x->rd_thresh_mult[mode_index] >= (MIN_THRESHMULT + 2)) ?
+ x->rd_thresh_mult[mode_index] - 2 : MIN_THRESHMULT;
+ x->rd_threshes[mode_index] =
(cpi->rd_baseline_thresh[mode_index] >> 7) *
- cpi->rd_thresh_mult[mode_index];
+ x->rd_thresh_mult[mode_index];
}
/* If the mode did not help improve the best error case then raise the
*/
else
{
- cpi->rd_thresh_mult[mode_index] += 4;
+ x->rd_thresh_mult[mode_index] += 4;
- if (cpi->rd_thresh_mult[mode_index] > MAX_THRESHMULT)
- cpi->rd_thresh_mult[mode_index] = MAX_THRESHMULT;
+ if (x->rd_thresh_mult[mode_index] > MAX_THRESHMULT)
+ x->rd_thresh_mult[mode_index] = MAX_THRESHMULT;
- cpi->rd_threshes[mode_index] =
+ x->rd_threshes[mode_index] =
(cpi->rd_baseline_thresh[mode_index] >> 7) *
- cpi->rd_thresh_mult[mode_index];
+ x->rd_thresh_mult[mode_index];
}
if (x->skip)
/* Reduce the activation RD thresholds for the best choice mode */
if ((cpi->rd_baseline_thresh[best_mode_index] > 0) && (cpi->rd_baseline_thresh[best_mode_index] < (INT_MAX >> 2)))
{
- int best_adjustment = (cpi->rd_thresh_mult[best_mode_index] >> 3);
+ int best_adjustment = (x->rd_thresh_mult[best_mode_index] >> 3);
- cpi->rd_thresh_mult[best_mode_index] =
- (cpi->rd_thresh_mult[best_mode_index]
+ x->rd_thresh_mult[best_mode_index] =
+ (x->rd_thresh_mult[best_mode_index]
>= (MIN_THRESHMULT + best_adjustment)) ?
- cpi->rd_thresh_mult[best_mode_index] - best_adjustment :
+ x->rd_thresh_mult[best_mode_index] - best_adjustment :
MIN_THRESHMULT;
- cpi->rd_threshes[best_mode_index] =
+ x->rd_threshes[best_mode_index] =
(cpi->rd_baseline_thresh[best_mode_index] >> 7) *
- cpi->rd_thresh_mult[best_mode_index];
+ x->rd_thresh_mult[best_mode_index];
}
cpi->mb.sadperbit4 = sad_per_bit4lut[QIndex];
}
-void vp8_initialize_rd_consts(VP8_COMP *cpi, int Qvalue)
+void vp8_initialize_rd_consts(VP8_COMP *cpi, MACROBLOCK *x, int Qvalue)
{
int q;
int i;
{
if (cpi->sf.thresh_mult[i] < INT_MAX)
{
- cpi->rd_threshes[i] = cpi->sf.thresh_mult[i] * q / 100;
+ x->rd_threshes[i] = cpi->sf.thresh_mult[i] * q / 100;
}
else
{
- cpi->rd_threshes[i] = INT_MAX;
+ x->rd_threshes[i] = INT_MAX;
}
- cpi->rd_baseline_thresh[i] = cpi->rd_threshes[i];
+ cpi->rd_baseline_thresh[i] = x->rd_threshes[i];
}
}
else
{
if (cpi->sf.thresh_mult[i] < (INT_MAX / q))
{
- cpi->rd_threshes[i] = cpi->sf.thresh_mult[i] * q;
+ x->rd_threshes[i] = cpi->sf.thresh_mult[i] * q;
}
else
{
- cpi->rd_threshes[i] = INT_MAX;
+ x->rd_threshes[i] = INT_MAX;
}
- cpi->rd_baseline_thresh[i] = cpi->rd_threshes[i];
+ cpi->rd_baseline_thresh[i] = x->rd_threshes[i];
}
}
int this_ref_frame = ref_frame_map[vp8_ref_frame_order[mode_index]];
/* Test best rd so far against threshold for trying this mode. */
- if (best_mode.rd <= cpi->rd_threshes[mode_index])
+ if (best_mode.rd <= x->rd_threshes[mode_index])
continue;
if (this_ref_frame < 0)
/* Increase the threshold for coding this mode to make it
* less likely to be chosen
*/
- cpi->rd_thresh_mult[mode_index] += 4;
+ x->rd_thresh_mult[mode_index] += 4;
- if (cpi->rd_thresh_mult[mode_index] > MAX_THRESHMULT)
- cpi->rd_thresh_mult[mode_index] = MAX_THRESHMULT;
+ if (x->rd_thresh_mult[mode_index] > MAX_THRESHMULT)
+ x->rd_thresh_mult[mode_index] = MAX_THRESHMULT;
- cpi->rd_threshes[mode_index] = (cpi->rd_baseline_thresh[mode_index] >> 7) * cpi->rd_thresh_mult[mode_index];
+ x->rd_threshes[mode_index] =
+ (cpi->rd_baseline_thresh[mode_index] >> 7) *
+ x->rd_thresh_mult[mode_index];
continue;
}
int this_rd_thresh;
int distortion;
- this_rd_thresh = (vp8_ref_frame_order[mode_index] == 1) ? cpi->rd_threshes[THR_NEW1] : cpi->rd_threshes[THR_NEW3];
- this_rd_thresh = (vp8_ref_frame_order[mode_index] == 2) ? cpi->rd_threshes[THR_NEW2] : this_rd_thresh;
+ this_rd_thresh = (vp8_ref_frame_order[mode_index] == 1) ?
+ x->rd_threshes[THR_NEW1] : x->rd_threshes[THR_NEW3];
+ this_rd_thresh = (vp8_ref_frame_order[mode_index] == 2) ?
+ x->rd_threshes[THR_NEW2] : this_rd_thresh;
tmp_rd = vp8_rd_pick_best_mbsegmentation(cpi, x, &best_ref_mv,
best_mode.yrd, mdcounts,
/* Testing this mode gave rise to an improvement in best error
* score. Lower threshold a bit for next time
*/
- cpi->rd_thresh_mult[mode_index] = (cpi->rd_thresh_mult[mode_index] >= (MIN_THRESHMULT + 2)) ? cpi->rd_thresh_mult[mode_index] - 2 : MIN_THRESHMULT;
- cpi->rd_threshes[mode_index] = (cpi->rd_baseline_thresh[mode_index] >> 7) * cpi->rd_thresh_mult[mode_index];
+ x->rd_thresh_mult[mode_index] =
+ (x->rd_thresh_mult[mode_index] >= (MIN_THRESHMULT + 2)) ?
+ x->rd_thresh_mult[mode_index] - 2 : MIN_THRESHMULT;
}
/* If the mode did not help improve the best error case then raise
*/
else
{
- cpi->rd_thresh_mult[mode_index] += 4;
+ x->rd_thresh_mult[mode_index] += 4;
- if (cpi->rd_thresh_mult[mode_index] > MAX_THRESHMULT)
- cpi->rd_thresh_mult[mode_index] = MAX_THRESHMULT;
-
- cpi->rd_threshes[mode_index] = (cpi->rd_baseline_thresh[mode_index] >> 7) * cpi->rd_thresh_mult[mode_index];
+ if (x->rd_thresh_mult[mode_index] > MAX_THRESHMULT)
+ x->rd_thresh_mult[mode_index] = MAX_THRESHMULT;
}
+ x->rd_threshes[mode_index] =
+ (cpi->rd_baseline_thresh[mode_index] >> 7) *
+ x->rd_thresh_mult[mode_index];
if (x->skip)
break;
/* Reduce the activation RD thresholds for the best choice mode */
if ((cpi->rd_baseline_thresh[best_mode_index] > 0) && (cpi->rd_baseline_thresh[best_mode_index] < (INT_MAX >> 2)))
{
- int best_adjustment = (cpi->rd_thresh_mult[best_mode_index] >> 2);
-
- cpi->rd_thresh_mult[best_mode_index] = (cpi->rd_thresh_mult[best_mode_index] >= (MIN_THRESHMULT + best_adjustment)) ? cpi->rd_thresh_mult[best_mode_index] - best_adjustment : MIN_THRESHMULT;
- cpi->rd_threshes[best_mode_index] = (cpi->rd_baseline_thresh[best_mode_index] >> 7) * cpi->rd_thresh_mult[best_mode_index];
+ int best_adjustment = (x->rd_thresh_mult[best_mode_index] >> 2);
+
+ x->rd_thresh_mult[best_mode_index] =
+ (x->rd_thresh_mult[best_mode_index] >=
+ (MIN_THRESHMULT + best_adjustment)) ?
+ x->rd_thresh_mult[best_mode_index] - best_adjustment :
+ MIN_THRESHMULT;
+ x->rd_threshes[best_mode_index] =
+ (cpi->rd_baseline_thresh[best_mode_index] >> 7) *
+ x->rd_thresh_mult[best_mode_index];
}
/* Note how often each mode chosen as best */
}
}
-extern void vp8_initialize_rd_consts(VP8_COMP *cpi, int Qvalue);
+extern void vp8_initialize_rd_consts(VP8_COMP *cpi, MACROBLOCK *x, int Qvalue);
extern void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int recon_uvoffset, int *returnrate, int *returndistortion, int *returnintra);
extern void vp8_rd_pick_intra_mode(MACROBLOCK *x, int *rate);