Merge "Reducing size of MODE_INFO struct"

This commit is contained in:
Scott LaVarnway 2015-06-10 13:15:18 +00:00 committed by Gerrit Code Review
commit 97880c3324
9 changed files with 102 additions and 86 deletions

View File

@ -50,16 +50,16 @@ typedef struct {
} b_mode_info; } b_mode_info;
// Note that the rate-distortion optimization loop, bit-stream writer, and // Note that the rate-distortion optimization loop, bit-stream writer, and
// decoder implementation modules critically rely on the enum entry values // decoder implementation modules critically rely on the defined entry values
// specified herein. They should be refactored concurrently. // specified herein. They should be refactored concurrently.
typedef enum {
NONE = -1, #define NONE -1
INTRA_FRAME = 0, #define INTRA_FRAME 0
LAST_FRAME = 1, #define LAST_FRAME 1
GOLDEN_FRAME = 2, #define GOLDEN_FRAME 2
ALTREF_FRAME = 3, #define ALTREF_FRAME 3
MAX_REF_FRAMES = 4 #define MAX_REF_FRAMES 4
} MV_REFERENCE_FRAME; typedef int8_t MV_REFERENCE_FRAME;
// This structure now relates to 8x8 block regions. // This structure now relates to 8x8 block regions.
typedef struct { typedef struct {
@ -75,12 +75,17 @@ typedef struct {
PREDICTION_MODE uv_mode; PREDICTION_MODE uv_mode;
// Only for INTER blocks // Only for INTER blocks
INTERP_FILTER interp_filter;
MV_REFERENCE_FRAME ref_frame[2]; MV_REFERENCE_FRAME ref_frame[2];
// TODO(slavarnway): Delete and use bmi[3].as_mv[] instead.
int_mv mv[2]; int_mv mv[2];
#if CONFIG_VP9_ENCODER
// TODO(slavarnway): Move to encoder
int_mv ref_mvs[MAX_REF_FRAMES][MAX_MV_REF_CANDIDATES]; int_mv ref_mvs[MAX_REF_FRAMES][MAX_MV_REF_CANDIDATES];
uint8_t mode_context[MAX_REF_FRAMES]; uint8_t mode_context[MAX_REF_FRAMES];
INTERP_FILTER interp_filter; #endif
} MB_MODE_INFO; } MB_MODE_INFO;
typedef struct MODE_INFO { typedef struct MODE_INFO {

View File

@ -12,6 +12,7 @@
#define VP9_COMMON_VP9_ENUMS_H_ #define VP9_COMMON_VP9_ENUMS_H_
#include "./vpx_config.h" #include "./vpx_config.h"
#include "vpx/vpx_integer.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -40,23 +41,22 @@ typedef enum BITSTREAM_PROFILE {
MAX_PROFILES MAX_PROFILES
} BITSTREAM_PROFILE; } BITSTREAM_PROFILE;
typedef enum BLOCK_SIZE { #define BLOCK_4X4 0
BLOCK_4X4, #define BLOCK_4X8 1
BLOCK_4X8, #define BLOCK_8X4 2
BLOCK_8X4, #define BLOCK_8X8 3
BLOCK_8X8, #define BLOCK_8X16 4
BLOCK_8X16, #define BLOCK_16X8 5
BLOCK_16X8, #define BLOCK_16X16 6
BLOCK_16X16, #define BLOCK_16X32 7
BLOCK_16X32, #define BLOCK_32X16 8
BLOCK_32X16, #define BLOCK_32X32 9
BLOCK_32X32, #define BLOCK_32X64 10
BLOCK_32X64, #define BLOCK_64X32 11
BLOCK_64X32, #define BLOCK_64X64 12
BLOCK_64X64, #define BLOCK_SIZES 13
BLOCK_SIZES, #define BLOCK_INVALID BLOCK_SIZES
BLOCK_INVALID = BLOCK_SIZES typedef uint8_t BLOCK_SIZE;
} BLOCK_SIZE;
typedef enum PARTITION_TYPE { typedef enum PARTITION_TYPE {
PARTITION_NONE, PARTITION_NONE,
@ -72,13 +72,12 @@ typedef char PARTITION_CONTEXT;
#define PARTITION_CONTEXTS (4 * PARTITION_PLOFFSET) #define PARTITION_CONTEXTS (4 * PARTITION_PLOFFSET)
// block transform size // block transform size
typedef enum { typedef uint8_t TX_SIZE;
TX_4X4 = 0, // 4x4 transform #define TX_4X4 ((TX_SIZE)0) // 4x4 transform
TX_8X8 = 1, // 8x8 transform #define TX_8X8 ((TX_SIZE)1) // 8x8 transform
TX_16X16 = 2, // 16x16 transform #define TX_16X16 ((TX_SIZE)2) // 16x16 transform
TX_32X32 = 3, // 32x32 transform #define TX_32X32 ((TX_SIZE)3) // 32x32 transform
TX_SIZES #define TX_SIZES ((TX_SIZE)4)
} TX_SIZE;
// frame transform mode // frame transform mode
typedef enum { typedef enum {
@ -110,23 +109,22 @@ typedef enum {
PLANE_TYPES PLANE_TYPES
} PLANE_TYPE; } PLANE_TYPE;
typedef enum { #define DC_PRED 0 // Average of above and left pixels
DC_PRED, // Average of above and left pixels #define V_PRED 1 // Vertical
V_PRED, // Vertical #define H_PRED 2 // Horizontal
H_PRED, // Horizontal #define D45_PRED 3 // Directional 45 deg = round(arctan(1/1) * 180/pi)
D45_PRED, // Directional 45 deg = round(arctan(1/1) * 180/pi) #define D135_PRED 4 // Directional 135 deg = 180 - 45
D135_PRED, // Directional 135 deg = 180 - 45 #define D117_PRED 5 // Directional 117 deg = 180 - 63
D117_PRED, // Directional 117 deg = 180 - 63 #define D153_PRED 6 // Directional 153 deg = 180 - 27
D153_PRED, // Directional 153 deg = 180 - 27 #define D207_PRED 7 // Directional 207 deg = 180 + 27
D207_PRED, // Directional 207 deg = 180 + 27 #define D63_PRED 8 // Directional 63 deg = round(arctan(2/1) * 180/pi)
D63_PRED, // Directional 63 deg = round(arctan(2/1) * 180/pi) #define TM_PRED 9 // True-motion
TM_PRED, // True-motion #define NEARESTMV 10
NEARESTMV, #define NEARMV 11
NEARMV, #define ZEROMV 12
ZEROMV, #define NEWMV 13
NEWMV, #define MB_MODE_COUNT 14
MB_MODE_COUNT typedef uint8_t PREDICTION_MODE;
} PREDICTION_MODE;
#define INTRA_MODES (TM_PRED + 1) #define INTRA_MODES (TM_PRED + 1)

View File

@ -27,17 +27,16 @@ extern "C" {
#define SUBPEL_SHIFTS (1 << SUBPEL_BITS) #define SUBPEL_SHIFTS (1 << SUBPEL_BITS)
#define SUBPEL_TAPS 8 #define SUBPEL_TAPS 8
typedef enum { #define EIGHTTAP 0
EIGHTTAP = 0, #define EIGHTTAP_SMOOTH 1
EIGHTTAP_SMOOTH = 1, #define EIGHTTAP_SHARP 2
EIGHTTAP_SHARP = 2, #define SWITCHABLE_FILTERS 3 /* Number of switchable filters */
SWITCHABLE_FILTERS = 3, /* Number of switchable filters */ #define BILINEAR 3
BILINEAR = 3, // The codec can operate in four possible inter prediction filter mode:
// The codec can operate in four possible inter prediction filter mode: // 8-tap, 8-tap-smooth, 8-tap-sharp, and switching between the three.
// 8-tap, 8-tap-smooth, 8-tap-sharp, and switching between the three. #define SWITCHABLE_FILTER_CONTEXTS (SWITCHABLE_FILTERS + 1)
SWITCHABLE_FILTER_CONTEXTS = SWITCHABLE_FILTERS + 1, #define SWITCHABLE 4 /* should be the last one */
SWITCHABLE = 4 /* should be the last one */ typedef uint8_t INTERP_FILTER;
} INTERP_FILTER;
typedef int16_t InterpKernel[SUBPEL_TAPS]; typedef int16_t InterpKernel[SUBPEL_TAPS];

View File

@ -18,7 +18,8 @@ static void find_mv_refs_idx(const VP9_COMMON *cm, const MACROBLOCKD *xd,
MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame, MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame,
int_mv *mv_ref_list, int_mv *mv_ref_list,
int block, int mi_row, int mi_col, int block, int mi_row, int mi_col,
find_mv_refs_sync sync, void *const data) { find_mv_refs_sync sync, void *const data,
uint8_t *mode_context) {
const int *ref_sign_bias = cm->ref_frame_sign_bias; const int *ref_sign_bias = cm->ref_frame_sign_bias;
int i, refmv_count = 0; int i, refmv_count = 0;
const POSITION *const mv_ref_search = mv_ref_blocks[mi->mbmi.sb_type]; const POSITION *const mv_ref_search = mv_ref_blocks[mi->mbmi.sb_type];
@ -138,7 +139,7 @@ static void find_mv_refs_idx(const VP9_COMMON *cm, const MACROBLOCKD *xd,
Done: Done:
mi->mbmi.mode_context[ref_frame] = counter_to_context[context_counter]; mode_context[ref_frame] = counter_to_context[context_counter];
// Clamp vectors // Clamp vectors
for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i)
@ -150,9 +151,10 @@ void vp9_find_mv_refs(const VP9_COMMON *cm, const MACROBLOCKD *xd,
MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame, MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame,
int_mv *mv_ref_list, int_mv *mv_ref_list,
int mi_row, int mi_col, int mi_row, int mi_col,
find_mv_refs_sync sync, void *const data) { find_mv_refs_sync sync, void *const data,
uint8_t *mode_context) {
find_mv_refs_idx(cm, xd, tile, mi, ref_frame, mv_ref_list, -1, find_mv_refs_idx(cm, xd, tile, mi, ref_frame, mv_ref_list, -1,
mi_row, mi_col, sync, data); mi_row, mi_col, sync, data, mode_context);
} }
static void lower_mv_precision(MV *mv, int allow_hp) { static void lower_mv_precision(MV *mv, int allow_hp) {
@ -181,7 +183,8 @@ void vp9_find_best_ref_mvs(MACROBLOCKD *xd, int allow_hp,
void vp9_append_sub8x8_mvs_for_idx(VP9_COMMON *cm, MACROBLOCKD *xd, void vp9_append_sub8x8_mvs_for_idx(VP9_COMMON *cm, MACROBLOCKD *xd,
const TileInfo *const tile, const TileInfo *const tile,
int block, int ref, int mi_row, int mi_col, int block, int ref, int mi_row, int mi_col,
int_mv *nearest_mv, int_mv *near_mv) { int_mv *nearest_mv, int_mv *near_mv,
uint8_t *mode_context) {
int_mv mv_list[MAX_MV_REF_CANDIDATES]; int_mv mv_list[MAX_MV_REF_CANDIDATES];
MODE_INFO *const mi = xd->mi[0]; MODE_INFO *const mi = xd->mi[0];
b_mode_info *bmi = mi->bmi; b_mode_info *bmi = mi->bmi;
@ -190,7 +193,7 @@ void vp9_append_sub8x8_mvs_for_idx(VP9_COMMON *cm, MACROBLOCKD *xd,
assert(MAX_MV_REF_CANDIDATES == 2); assert(MAX_MV_REF_CANDIDATES == 2);
find_mv_refs_idx(cm, xd, tile, mi, mi->mbmi.ref_frame[ref], mv_list, block, find_mv_refs_idx(cm, xd, tile, mi, mi->mbmi.ref_frame[ref], mv_list, block,
mi_row, mi_col, NULL, NULL); mi_row, mi_col, NULL, NULL, mode_context);
near_mv->as_int = 0; near_mv->as_int = 0;
switch (block) { switch (block) {

View File

@ -212,7 +212,8 @@ void vp9_find_mv_refs(const VP9_COMMON *cm, const MACROBLOCKD *xd,
const TileInfo *const tile, const TileInfo *const tile,
MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame, MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame,
int_mv *mv_ref_list, int mi_row, int mi_col, int_mv *mv_ref_list, int mi_row, int mi_col,
find_mv_refs_sync sync, void *const data); find_mv_refs_sync sync, void *const data,
uint8_t *mode_context);
// check a list of motion vectors by sad score using a number rows of pixels // check a list of motion vectors by sad score using a number rows of pixels
// above and a number cols of pixels in the left to select the one with best // above and a number cols of pixels in the left to select the one with best
@ -223,7 +224,8 @@ void vp9_find_best_ref_mvs(MACROBLOCKD *xd, int allow_hp,
void vp9_append_sub8x8_mvs_for_idx(VP9_COMMON *cm, MACROBLOCKD *xd, void vp9_append_sub8x8_mvs_for_idx(VP9_COMMON *cm, MACROBLOCKD *xd,
const TileInfo *const tile, const TileInfo *const tile,
int block, int ref, int mi_row, int mi_col, int block, int ref, int mi_row, int mi_col,
int_mv *nearest_mv, int_mv *near_mv); int_mv *nearest_mv, int_mv *near_mv,
uint8_t *mode_context);
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"

View File

@ -473,7 +473,9 @@ static void read_inter_block_mode_info(VP9Decoder *const pbi,
const BLOCK_SIZE bsize = mbmi->sb_type; const BLOCK_SIZE bsize = mbmi->sb_type;
const int allow_hp = cm->allow_high_precision_mv; const int allow_hp = cm->allow_high_precision_mv;
int_mv nearestmv[2], nearmv[2]; int_mv nearestmv[2], nearmv[2];
int inter_mode_ctx, ref, is_compound; int_mv ref_mvs[MAX_REF_FRAMES][MAX_MV_REF_CANDIDATES];
int ref, is_compound;
uint8_t inter_mode_ctx[MAX_REF_FRAMES];
read_ref_frames(cm, xd, r, mbmi->segment_id, mbmi->ref_frame); read_ref_frames(cm, xd, r, mbmi->segment_id, mbmi->ref_frame);
is_compound = has_second_ref(mbmi); is_compound = has_second_ref(mbmi);
@ -487,12 +489,10 @@ static void read_inter_block_mode_info(VP9Decoder *const pbi,
"Reference frame has invalid dimensions"); "Reference frame has invalid dimensions");
vp9_setup_pre_planes(xd, ref, ref_buf->buf, mi_row, mi_col, vp9_setup_pre_planes(xd, ref, ref_buf->buf, mi_row, mi_col,
&ref_buf->sf); &ref_buf->sf);
vp9_find_mv_refs(cm, xd, tile, mi, frame, mbmi->ref_mvs[frame], vp9_find_mv_refs(cm, xd, tile, mi, frame, ref_mvs[frame],
mi_row, mi_col, fpm_sync, (void *)pbi); mi_row, mi_col, fpm_sync, (void *)pbi, inter_mode_ctx);
} }
inter_mode_ctx = mbmi->mode_context[mbmi->ref_frame[0]];
if (vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { if (vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) {
mbmi->mode = ZEROMV; mbmi->mode = ZEROMV;
if (bsize < BLOCK_8X8) { if (bsize < BLOCK_8X8) {
@ -502,12 +502,13 @@ static void read_inter_block_mode_info(VP9Decoder *const pbi,
} }
} else { } else {
if (bsize >= BLOCK_8X8) if (bsize >= BLOCK_8X8)
mbmi->mode = read_inter_mode(cm, xd, r, inter_mode_ctx); mbmi->mode = read_inter_mode(cm, xd, r,
inter_mode_ctx[mbmi->ref_frame[0]]);
} }
if (bsize < BLOCK_8X8 || mbmi->mode != ZEROMV) { if (bsize < BLOCK_8X8 || mbmi->mode != ZEROMV) {
for (ref = 0; ref < 1 + is_compound; ++ref) { for (ref = 0; ref < 1 + is_compound; ++ref) {
vp9_find_best_ref_mvs(xd, allow_hp, mbmi->ref_mvs[mbmi->ref_frame[ref]], vp9_find_best_ref_mvs(xd, allow_hp, ref_mvs[mbmi->ref_frame[ref]],
&nearestmv[ref], &nearmv[ref]); &nearestmv[ref], &nearmv[ref]);
} }
} }
@ -526,13 +527,16 @@ static void read_inter_block_mode_info(VP9Decoder *const pbi,
for (idx = 0; idx < 2; idx += num_4x4_w) { for (idx = 0; idx < 2; idx += num_4x4_w) {
int_mv block[2]; int_mv block[2];
const int j = idy * 2 + idx; const int j = idy * 2 + idx;
b_mode = read_inter_mode(cm, xd, r, inter_mode_ctx); b_mode = read_inter_mode(cm, xd, r, inter_mode_ctx[mbmi->ref_frame[0]]);
if (b_mode == NEARESTMV || b_mode == NEARMV) if (b_mode == NEARESTMV || b_mode == NEARMV) {
uint8_t dummy_mode_ctx[MAX_REF_FRAMES];
for (ref = 0; ref < 1 + is_compound; ++ref) for (ref = 0; ref < 1 + is_compound; ++ref)
vp9_append_sub8x8_mvs_for_idx(cm, xd, tile, j, ref, mi_row, mi_col, vp9_append_sub8x8_mvs_for_idx(cm, xd, tile, j, ref, mi_row, mi_col,
&nearest_sub8x8[ref], &nearest_sub8x8[ref],
&near_sub8x8[ref]); &near_sub8x8[ref],
dummy_mode_ctx);
}
if (!assign_mv(cm, xd, b_mode, block, nearestmv, if (!assign_mv(cm, xd, b_mode, block, nearestmv,
nearest_sub8x8, near_sub8x8, nearest_sub8x8, near_sub8x8,

View File

@ -370,6 +370,7 @@ static void sum_2_variances(const var *a, const var *b, var *r) {
static void fill_variance_tree(void *data, BLOCK_SIZE bsize) { static void fill_variance_tree(void *data, BLOCK_SIZE bsize) {
variance_node node; variance_node node;
memset(&node, 0, sizeof(node));
tree_to_node(data, bsize, &node); tree_to_node(data, bsize, &node);
sum_2_variances(node.split[0], node.split[1], &node.part_variances->horz[0]); sum_2_variances(node.split[0], node.split[1], &node.part_variances->horz[0]);
sum_2_variances(node.split[2], node.split[3], &node.part_variances->horz[1]); sum_2_variances(node.split[2], node.split[3], &node.part_variances->horz[1]);

View File

@ -1179,7 +1179,8 @@ void vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
if (cm->use_prev_frame_mvs) if (cm->use_prev_frame_mvs)
vp9_find_mv_refs(cm, xd, tile_info, xd->mi[0], ref_frame, vp9_find_mv_refs(cm, xd, tile_info, xd->mi[0], ref_frame,
candidates, mi_row, mi_col, NULL, NULL); candidates, mi_row, mi_col, NULL, NULL,
xd->mi[0]->mbmi.mode_context);
else else
const_motion[ref_frame] = mv_refs_rt(cm, xd, tile_info, const_motion[ref_frame] = mv_refs_rt(cm, xd, tile_info,
xd->mi[0], xd->mi[0],
@ -1658,7 +1659,8 @@ void vp9_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x,
vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col, vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col,
sf, sf); sf, sf);
vp9_find_mv_refs(cm, xd, tile_info, xd->mi[0], ref_frame, vp9_find_mv_refs(cm, xd, tile_info, xd->mi[0], ref_frame,
candidates, mi_row, mi_col, NULL, NULL); candidates, mi_row, mi_col, NULL, NULL,
xd->mi[0]->mbmi.mode_context);
vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates, vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates,
&dummy_mv[0], &dummy_mv[1]); &dummy_mv[0], &dummy_mv[1]);
@ -1732,7 +1734,8 @@ void vp9_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x,
b_mv[NEWMV].as_int = INVALID_MV; b_mv[NEWMV].as_int = INVALID_MV;
vp9_append_sub8x8_mvs_for_idx(cm, xd, tile_info, i, 0, mi_row, mi_col, vp9_append_sub8x8_mvs_for_idx(cm, xd, tile_info, i, 0, mi_row, mi_col,
&b_mv[NEARESTMV], &b_mv[NEARESTMV],
&b_mv[NEARMV]); &b_mv[NEARMV],
xd->mi[0]->mbmi.mode_context);
for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) {
int b_rate = 0; int b_rate = 0;

View File

@ -1804,7 +1804,8 @@ static int64_t rd_pick_best_sub8x8_mode(VP9_COMP *cpi, MACROBLOCK *x,
frame_mv[ZEROMV][frame].as_int = 0; frame_mv[ZEROMV][frame].as_int = 0;
vp9_append_sub8x8_mvs_for_idx(cm, xd, tile, i, ref, mi_row, mi_col, vp9_append_sub8x8_mvs_for_idx(cm, xd, tile, i, ref, mi_row, mi_col,
&frame_mv[NEARESTMV][frame], &frame_mv[NEARESTMV][frame],
&frame_mv[NEARMV][frame]); &frame_mv[NEARMV][frame],
xd->mi[0]->mbmi.mode_context);
} }
// search for the best motion vector on this segment // search for the best motion vector on this segment
@ -2220,7 +2221,7 @@ static void setup_buffer_inter(VP9_COMP *cpi, MACROBLOCK *x,
// Gets an initial list of candidate vectors from neighbours and orders them // Gets an initial list of candidate vectors from neighbours and orders them
vp9_find_mv_refs(cm, xd, tile, mi, ref_frame, candidates, mi_row, mi_col, vp9_find_mv_refs(cm, xd, tile, mi, ref_frame, candidates, mi_row, mi_col,
NULL, NULL); NULL, NULL, xd->mi[0]->mbmi.mode_context);
// Candidate refinement carried out at encoder and decoder // Candidate refinement carried out at encoder and decoder
vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates, vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates,