Commit e55974bf authored by John Koleszar's avatar John Koleszar

Speed selection support for disabled reference frames

There was an implicit reference frame test order (typically LAST,
GOLD, ARF) in the mode selection logic, but this doesn't provide the
expected results when some reference frames are disabled. For
instance, in real-time mode, the speed selection logic often disables
the ARF modes. So if the user disables the LAST and GOLD frames, the
encoder was always choosing INTRA, when in reality searching the ARF
in this case has the same speed penalty as searching LAST would have
had.

Instead, introduce the notion of a reference frame search order. This
patch preserves the former priorities, so if a frame is disabled, the
other frames bump up a slot to take its place. This patch lays the
groundwork for doing something smarter in the frame test order, for
example considering temporal distance or looking at the frames used by
nearby blocks.

Change-Id: I1199149f8662a408537c653d2c021c7f1d29a700
parent 3c755577
This diff is collapsed.
......@@ -133,32 +133,32 @@ typedef struct
typedef enum
{
THR_ZEROMV = 0,
THR_ZERO1 = 0,
THR_DC = 1,
THR_NEARESTMV = 2,
THR_NEARMV = 3,
THR_NEAREST1 = 2,
THR_NEAR1 = 3,
THR_ZEROG = 4,
THR_NEARESTG = 5,
THR_ZERO2 = 4,
THR_NEAREST2 = 5,
THR_ZEROA = 6,
THR_NEARESTA = 7,
THR_ZERO3 = 6,
THR_NEAREST3 = 7,
THR_NEARG = 8,
THR_NEARA = 9,
THR_NEAR2 = 8,
THR_NEAR3 = 9,
THR_V_PRED = 10,
THR_H_PRED = 11,
THR_TM = 12,
THR_NEWMV = 13,
THR_NEWG = 14,
THR_NEWA = 15,
THR_NEW1 = 13,
THR_NEW2 = 14,
THR_NEW3 = 15,
THR_SPLITMV = 16,
THR_SPLITG = 17,
THR_SPLITA = 18,
THR_SPLIT1 = 16,
THR_SPLIT2 = 17,
THR_SPLIT3 = 18,
THR_B_PRED = 19,
}
......
......@@ -39,7 +39,7 @@ extern int VP8_UVSSE(MACROBLOCK *x, const vp8_variance_rtcd_vtable_t *rtcd);
extern unsigned int cnt_pm;
#endif
extern const MV_REFERENCE_FRAME vp8_ref_frame_order[MAX_MODES];
extern const int vp8_ref_frame_order[MAX_MODES];
extern const MB_PREDICTION_MODE vp8_mode_order[MAX_MODES];
extern unsigned int (*vp8_get4x4sse_cs)(unsigned char *src_ptr, int source_stride, unsigned char *ref_ptr, int recon_stride);
......@@ -439,8 +439,9 @@ void vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset,
unsigned char *y_buffer[4];
unsigned char *u_buffer[4];
unsigned char *v_buffer[4];
int i;
int ref_frame_map[4];
int skip_mode[4] = {0, 0, 0, 0};
int found_near_mvs[4] = {0, 0, 0, 0};
int have_subp_search = cpi->sf.half_pixel_search; /* In real-time mode, when Speed >= 15, no sub-pixel search. */
......@@ -450,6 +451,17 @@ void vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset,
vpx_memset(near_mv, 0, sizeof(near_mv));
vpx_memset(&best_mbmode, 0, sizeof(best_mbmode));
/* Setup search priorities */
i=0;
ref_frame_map[i++] = INTRA_FRAME;
if (cpi->ref_frame_flags & VP8_LAST_FLAG)
ref_frame_map[i++] = LAST_FRAME;
if (cpi->ref_frame_flags & VP8_GOLD_FLAG)
ref_frame_map[i++] = GOLDEN_FRAME;
if (cpi->ref_frame_flags & VP8_ALT_FLAG) // &&(cpi->source_alt_ref_active || cpi->oxcf.number_of_layers > 1)
ref_frame_map[i++] = ALTREF_FRAME;
for(; i<4; i++)
ref_frame_map[i] = -1;
// set up all the refframe dependent pointers.
if (cpi->ref_frame_flags & VP8_LAST_FLAG)
......@@ -459,8 +471,6 @@ void vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset,
u_buffer[LAST_FRAME] = lst_yv12->u_buffer + recon_uvoffset;
v_buffer[LAST_FRAME] = lst_yv12->v_buffer + recon_uvoffset;
}
else
skip_mode[LAST_FRAME] = 1;
if (cpi->ref_frame_flags & VP8_GOLD_FLAG)
{
......@@ -469,19 +479,14 @@ void vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset,
u_buffer[GOLDEN_FRAME] = gld_yv12->u_buffer + recon_uvoffset;
v_buffer[GOLDEN_FRAME] = gld_yv12->v_buffer + recon_uvoffset;
}
else
skip_mode[GOLDEN_FRAME] = 1;
if ((cpi->ref_frame_flags & VP8_ALT_FLAG) &&
(cpi->source_alt_ref_active || cpi->oxcf.number_of_layers > 1))
if (cpi->ref_frame_flags & VP8_ALT_FLAG)
{
YV12_BUFFER_CONFIG *alt_yv12 = &cpi->common.yv12_fb[cpi->common.alt_fb_idx];
y_buffer[ALTREF_FRAME] = alt_yv12->y_buffer + recon_yoffset;
u_buffer[ALTREF_FRAME] = alt_yv12->u_buffer + recon_uvoffset;
v_buffer[ALTREF_FRAME] = alt_yv12->v_buffer + recon_uvoffset;
}
else
skip_mode[ALTREF_FRAME] = 1;
cpi->mbs_tested_so_far++; // Count of the number of MBs tested so far this frame
......@@ -496,15 +501,17 @@ void vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset,
{
int frame_cost;
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])
continue;
x->e_mbd.mode_info_context->mbmi.ref_frame = vp8_ref_frame_order[mode_index];
if (skip_mode[x->e_mbd.mode_info_context->mbmi.ref_frame])
if (this_ref_frame < 0)
continue;
x->e_mbd.mode_info_context->mbmi.ref_frame = this_ref_frame;
// Check to see if the testing frequency for this mode is at its max
// If so then prevent it from being tested and increase the threshold for its testing
if (cpi->mode_test_hit_counts[mode_index] && (cpi->mode_check_freq[mode_index] > 1))
......
......@@ -28,7 +28,6 @@
#define MAX_BPB_FACTOR 50
extern const MB_PREDICTION_MODE vp8_mode_order[MAX_MODES];
extern const MV_REFERENCE_FRAME vp8_ref_frame_order[MAX_MODES];
......
......@@ -100,36 +100,39 @@ const MB_PREDICTION_MODE vp8_mode_order[MAX_MODES] =
B_PRED,
};
const MV_REFERENCE_FRAME vp8_ref_frame_order[MAX_MODES] =
/* This table determines the search order in reference frame priority order,
* which may not necessarily match INTRA,LAST,GOLDEN,ARF
*/
const int vp8_ref_frame_order[MAX_MODES] =
{
LAST_FRAME,
INTRA_FRAME,
1,
0,
LAST_FRAME,
LAST_FRAME,
1,
1,
GOLDEN_FRAME,
GOLDEN_FRAME,
2,
2,
ALTREF_FRAME,
ALTREF_FRAME,
3,
3,
GOLDEN_FRAME,
ALTREF_FRAME,
2,
3,
INTRA_FRAME,
INTRA_FRAME,
INTRA_FRAME,
0,
0,
0,
LAST_FRAME,
GOLDEN_FRAME,
ALTREF_FRAME,
1,
2,
3,
LAST_FRAME,
GOLDEN_FRAME,
ALTREF_FRAME,
1,
2,
3,
INTRA_FRAME,
0,
};
static void fill_token_costs(
......@@ -1789,10 +1792,23 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
unsigned char *y_buffer[4];
unsigned char *u_buffer[4];
unsigned char *v_buffer[4];
int ref_frame_map[4];
vpx_memset(&best_mbmode, 0, sizeof(best_mbmode));
vpx_memset(&best_bmodes, 0, sizeof(best_bmodes));
/* Setup search priorities */
i=0;
ref_frame_map[i++] = INTRA_FRAME;
if (cpi->ref_frame_flags & VP8_LAST_FLAG)
ref_frame_map[i++] = LAST_FRAME;
if (cpi->ref_frame_flags & VP8_GOLD_FLAG)
ref_frame_map[i++] = GOLDEN_FRAME;
if (cpi->ref_frame_flags & VP8_ALT_FLAG)
ref_frame_map[i++] = ALTREF_FRAME;
for(; i<4; i++)
ref_frame_map[i] = -1;
if (cpi->ref_frame_flags & VP8_LAST_FLAG)
{
YV12_BUFFER_CONFIG *lst_yv12 = &cpi->common.yv12_fb[cpi->common.lst_fb_idx];
......@@ -1852,6 +1868,7 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
int lf_or_gf = 0; // Lat Frame (01) or gf/arf (1)
int disable_skip = 0;
int other_cost = 0;
int this_ref_frame = ref_frame_map[vp8_ref_frame_order[mode_index]];
// Experimental debug code.
// Record of rd values recorded for this MB. -1 indicates not measured
......@@ -1864,6 +1881,9 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
if (best_rd <= cpi->rd_threshes[mode_index])
continue;
if (this_ref_frame < 0)
continue;
// These variables hold are rolling total cost and distortion for this mode
rate2 = 0;
distortion2 = 0;
......@@ -1872,7 +1892,7 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
x->e_mbd.mode_info_context->mbmi.mode = this_mode;
x->e_mbd.mode_info_context->mbmi.uv_mode = DC_PRED;
x->e_mbd.mode_info_context->mbmi.ref_frame = vp8_ref_frame_order[mode_index];
x->e_mbd.mode_info_context->mbmi.ref_frame = this_ref_frame;
// Only consider ZEROMV/ALTREF_FRAME for alt ref frame,
// unless ARNR filtering is enabled in which case we want
......@@ -1920,13 +1940,13 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
// Experimental code. Special case for gf and arf zeromv modes. Increase zbin size to supress noise
if (cpi->zbin_mode_boost_enabled)
{
if ( vp8_ref_frame_order[mode_index] == INTRA_FRAME )
if ( this_ref_frame == INTRA_FRAME )
cpi->zbin_mode_boost = 0;
else
{
if (vp8_mode_order[mode_index] == ZEROMV)
{
if (vp8_ref_frame_order[mode_index] != LAST_FRAME)
if (this_ref_frame != LAST_FRAME)
cpi->zbin_mode_boost = GF_ZEROMV_ZBIN_BOOST;
else
cpi->zbin_mode_boost = LF_ZEROMV_ZBIN_BOOST;
......@@ -1971,8 +1991,8 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int
int tmp_rd;
int this_rd_thresh;
this_rd_thresh = (x->e_mbd.mode_info_context->mbmi.ref_frame == LAST_FRAME) ? cpi->rd_threshes[THR_NEWMV] : cpi->rd_threshes[THR_NEWA];
this_rd_thresh = (x->e_mbd.mode_info_context->mbmi.ref_frame == GOLDEN_FRAME) ? cpi->rd_threshes[THR_NEWG]: this_rd_thresh;
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;
tmp_rd = vp8_rd_pick_best_mbsegmentation(cpi, x, &best_ref_mv,
best_yrd, mdcounts,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment