Commit 1af28f02 authored by Zoe Liu's avatar Zoe Liu

Code refactoring on Macros related to ref frame numbers

We have renamed following Macros to avoid name confusion:

REFS_PER_FRAME --> INTER_REFS_PER_FRAME
(= ALTREF_FRAME - LAST_FRAME + 1)
MAX_REF_FRAMES --> TOTAL_REFS_PER_FRAME
(= ALTREF_FRAME - INTRA_FRAME + 1)

INTER_REFS_PER_FRAME specifies the maximum number of reference frames
that each Inter frame may use.
TOTAL_REFS_PER_FRAME is equal to INTER_REFS_PER_FRAME + 1, which
counts the INTRA_FRAME.

Further, at the encoder side, since REF_FRAMES specifies the maximum
number of the reference frames that the encoder may store, REF_FRAMES
is usually larger than INTER_REFS_PER_FRAME. For example, in the
ext-refs experiment, REF_FRAMES == 8, which allows the encoder to
store maximum 8 reference frames in the buffer, but
INTER_REFS_PER_FRAME equals to 6, which allows each Inter frame may
use up to 6 frames out of the 8 buffered frames as its references.
Hence, in order to explore the possibility to store more reference
frames in future patches, we modified a couple of array sizes to
accomodate the case that the number of buffered reference frames is
not always equal to the number of the references that are being used
by each Inter frame.

Change-Id: I19e42ef608946cc76ebfd3e965a05f4b9b93a0b3
parent 108df24d
......@@ -394,22 +394,20 @@ typedef TX_SIZE TXFM_CONTEXT;
#define LAST_FRAME 1
#if CONFIG_EXT_REFS
#define LAST2_FRAME 2
#define LAST3_FRAME 3
#define GOLDEN_FRAME 4
#define BWDREF_FRAME 5
#define ALTREF_FRAME 6
#define MAX_REF_FRAMES 7
#define LAST_REF_FRAMES (LAST3_FRAME - LAST_FRAME + 1)
#else
#define GOLDEN_FRAME 2
#define ALTREF_FRAME 3
#define MAX_REF_FRAMES 4
#endif // CONFIG_EXT_REFS
#define INTER_REFS_PER_FRAME (ALTREF_FRAME - LAST_FRAME + 1)
#define TOTAL_REFS_PER_FRAME (ALTREF_FRAME - INTRA_FRAME + 1)
#define FWD_REFS (GOLDEN_FRAME - LAST_FRAME + 1)
#define FWD_RF_OFFSET(ref) (ref - LAST_FRAME)
#if CONFIG_EXT_REFS
......@@ -418,15 +416,15 @@ typedef TX_SIZE TXFM_CONTEXT;
#else
#define BWD_REFS 1
#define BWD_RF_OFFSET(ref) (ref - ALTREF_FRAME)
#endif
#endif // CONFIG_EXT_REFS
#define SINGLE_REFS (FWD_REFS + BWD_REFS)
#define COMP_REFS (FWD_REFS * BWD_REFS)
#if CONFIG_REF_MV
#define MODE_CTX_REF_FRAMES (MAX_REF_FRAMES + COMP_REFS)
#define MODE_CTX_REF_FRAMES (TOTAL_REFS_PER_FRAME + COMP_REFS)
#else
#define MODE_CTX_REF_FRAMES MAX_REF_FRAMES
#define MODE_CTX_REF_FRAMES TOTAL_REFS_PER_FRAME
#endif
#if CONFIG_SUPERTX
......
......@@ -300,7 +300,7 @@ void vp10_loop_filter_frame_init(VP10_COMMON *cm, int default_filt_lvl) {
const int intra_lvl = lvl_seg + lf->ref_deltas[INTRA_FRAME] * scale;
lfi->lvl[seg_id][INTRA_FRAME][0] = clamp(intra_lvl, 0, MAX_LOOP_FILTER);
for (ref = LAST_FRAME; ref < MAX_REF_FRAMES; ++ref) {
for (ref = LAST_FRAME; ref < TOTAL_REFS_PER_FRAME; ++ref) {
for (mode = 0; mode < MAX_MODE_LF_DELTAS; ++mode) {
const int inter_lvl = lvl_seg + lf->ref_deltas[ref] * scale
+ lf->mode_deltas[mode] * scale;
......
......@@ -46,8 +46,8 @@ struct loopfilter {
// 0 = Intra, Last, Last2+Last3(CONFIG_EXT_REFS),
// GF, BRF(CONFIG_EXT_REFS), ARF
signed char ref_deltas[MAX_REF_FRAMES];
signed char last_ref_deltas[MAX_REF_FRAMES];
signed char ref_deltas[TOTAL_REFS_PER_FRAME];
signed char last_ref_deltas[TOTAL_REFS_PER_FRAME];
// 0 = ZERO_MV, MV
signed char mode_deltas[MAX_MODE_LF_DELTAS];
......@@ -64,7 +64,7 @@ typedef struct {
typedef struct {
loop_filter_thresh lfthr[MAX_LOOP_FILTER + 1];
uint8_t lvl[MAX_SEGMENTS][MAX_REF_FRAMES][MAX_MODE_LF_DELTAS];
uint8_t lvl[MAX_SEGMENTS][TOTAL_REFS_PER_FRAME][MAX_MODE_LF_DELTAS];
} loop_filter_info_n;
// This structure holds bit masks for all 8x8 blocks in a 64x64 region.
......
......@@ -262,7 +262,7 @@ static INLINE int vp10_nmv_ctx(const uint8_t ref_mv_count,
static INLINE int8_t vp10_ref_frame_type(const MV_REFERENCE_FRAME *const rf) {
if (rf[1] > INTRA_FRAME) {
return MAX_REF_FRAMES + FWD_RF_OFFSET(rf[0]) +
return TOTAL_REFS_PER_FRAME + FWD_RF_OFFSET(rf[0]) +
BWD_RF_OFFSET(rf[1]) * FWD_REFS;
}
......@@ -288,13 +288,14 @@ static MV_REFERENCE_FRAME ref_frame_map[COMP_REFS][2] = {
static INLINE void vp10_set_ref_frame(MV_REFERENCE_FRAME *rf,
int8_t ref_frame_type) {
if (ref_frame_type >= MAX_REF_FRAMES) {
rf[0] = ref_frame_map[ref_frame_type - MAX_REF_FRAMES][0];
rf[1] = ref_frame_map[ref_frame_type - MAX_REF_FRAMES][1];
if (ref_frame_type >= TOTAL_REFS_PER_FRAME) {
rf[0] = ref_frame_map[ref_frame_type - TOTAL_REFS_PER_FRAME][0];
rf[1] = ref_frame_map[ref_frame_type - TOTAL_REFS_PER_FRAME][1];
} else {
rf[0] = ref_frame_type;
rf[1] = NONE;
assert(ref_frame_type > INTRA_FRAME && ref_frame_type < MAX_REF_FRAMES);
assert(ref_frame_type > INTRA_FRAME &&
ref_frame_type < TOTAL_REFS_PER_FRAME);
}
}
......
......@@ -30,8 +30,6 @@
extern "C" {
#endif
#define REFS_PER_FRAME (ALTREF_FRAME - LAST_FRAME + 1)
#define REF_FRAMES_LOG2 3
#define REF_FRAMES (1 << REF_FRAMES_LOG2)
......@@ -162,8 +160,8 @@ typedef struct VP10Common {
// TODO(jkoleszar): could expand active_ref_idx to 4, with 0 as intra, and
// roll new_fb_idx into it.
// Each frame can reference REFS_PER_FRAME buffers
RefBuffer frame_refs[REFS_PER_FRAME];
// Each Inter frame can reference INTER_REFS_PER_FRAME buffers
RefBuffer frame_refs[INTER_REFS_PER_FRAME];
int new_fb_idx;
......@@ -268,7 +266,7 @@ typedef struct VP10Common {
// a frame decode
REFRESH_FRAME_CONTEXT_MODE refresh_frame_context;
int ref_frame_sign_bias[MAX_REF_FRAMES]; /* Two state 0, 1 */
int ref_frame_sign_bias[TOTAL_REFS_PER_FRAME]; /* Two state 0, 1 */
struct loopfilter lf;
struct segmentation seg;
......@@ -344,7 +342,7 @@ typedef struct VP10Common {
// each keyframe and not used afterwards
vpx_prob kf_y_prob[INTRA_MODES][INTRA_MODES][INTRA_MODES - 1];
#if CONFIG_GLOBAL_MOTION
Global_Motion_Params global_motion[MAX_REF_FRAMES];
Global_Motion_Params global_motion[TOTAL_REFS_PER_FRAME];
#endif
BLOCK_SIZE sb_size; // Size of the superblock used for this frame
......
......@@ -49,7 +49,7 @@ static int is_compound_reference_allowed(const VP10_COMMON *cm) {
int i;
if (frame_is_intra_only(cm))
return 0;
for (i = 1; i < REFS_PER_FRAME; ++i)
for (i = 1; i < INTER_REFS_PER_FRAME; ++i)
if (cm->ref_frame_sign_bias[i + 1] != cm->ref_frame_sign_bias[1])
return 1;
......@@ -2066,7 +2066,7 @@ static void setup_loopfilter(VP10_COMMON *cm,
if (lf->mode_ref_delta_update) {
int i;
for (i = 0; i < MAX_REF_FRAMES; i++)
for (i = 0; i < TOTAL_REFS_PER_FRAME; i++)
if (vpx_rb_read_bit(rb))
lf->ref_deltas[i] = vpx_rb_read_inv_signed_literal(rb, 6);
......@@ -2247,7 +2247,7 @@ static void setup_frame_size_with_refs(VP10_COMMON *cm,
int found = 0, i;
int has_valid_ref_frame = 0;
BufferPool *const pool = cm->buffer_pool;
for (i = 0; i < REFS_PER_FRAME; ++i) {
for (i = 0; i < INTER_REFS_PER_FRAME; ++i) {
if (vpx_rb_read_bit(rb)) {
YV12_BUFFER_CONFIG *const buf = cm->frame_refs[i].buf;
width = buf->y_crop_width;
......@@ -2270,7 +2270,7 @@ static void setup_frame_size_with_refs(VP10_COMMON *cm,
// Check to make sure at least one of frames that this frame references
// has valid dimensions.
for (i = 0; i < REFS_PER_FRAME; ++i) {
for (i = 0; i < INTER_REFS_PER_FRAME; ++i) {
RefBuffer *const ref_frame = &cm->frame_refs[i];
has_valid_ref_frame |= valid_ref_frame_size(ref_frame->buf->y_crop_width,
ref_frame->buf->y_crop_height,
......@@ -2279,7 +2279,7 @@ static void setup_frame_size_with_refs(VP10_COMMON *cm,
if (!has_valid_ref_frame)
vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
"Referenced frame has invalid size");
for (i = 0; i < REFS_PER_FRAME; ++i) {
for (i = 0; i < INTER_REFS_PER_FRAME; ++i) {
RefBuffer *const ref_frame = &cm->frame_refs[i];
if (!valid_ref_frame_img_fmt(
ref_frame->buf->bit_depth,
......@@ -3199,7 +3199,7 @@ static size_t read_uncompressed_header(VP10Decoder *pbi,
read_bitdepth_colorspace_sampling(cm, rb);
pbi->refresh_frame_flags = (1 << REF_FRAMES) - 1;
for (i = 0; i < REFS_PER_FRAME; ++i) {
for (i = 0; i < INTER_REFS_PER_FRAME; ++i) {
cm->frame_refs[i].idx = INVALID_IDX;
cm->frame_refs[i].buf = NULL;
}
......@@ -3256,7 +3256,7 @@ static size_t read_uncompressed_header(VP10Decoder *pbi,
}
#endif // CONFIG_EXT_REFS
for (i = 0; i < REFS_PER_FRAME; ++i) {
for (i = 0; i < INTER_REFS_PER_FRAME; ++i) {
const int ref = vpx_rb_read_literal(rb, REF_FRAMES_LOG2);
const int idx = cm->ref_frame_map[ref];
RefBuffer *const ref_frame = &cm->frame_refs[i];
......@@ -3270,7 +3270,7 @@ static size_t read_uncompressed_header(VP10Decoder *pbi,
cm->allow_high_precision_mv = vpx_rb_read_bit(rb);
cm->interp_filter = read_interp_filter(rb);
for (i = 0; i < REFS_PER_FRAME; ++i) {
for (i = 0; i < INTER_REFS_PER_FRAME; ++i) {
RefBuffer *const ref_buf = &cm->frame_refs[i];
#if CONFIG_VP9_HIGHBITDEPTH
vp10_setup_scale_factors_for_frame(&ref_buf->sf,
......
......@@ -301,7 +301,7 @@ static void swap_frame_buffers(VP10Decoder *pbi) {
}
// Invalidate these references until the next frame starts.
for (ref_index = 0; ref_index < REFS_PER_FRAME; ref_index++) {
for (ref_index = 0; ref_index < INTER_REFS_PER_FRAME; ref_index++) {
cm->frame_refs[ref_index].idx = INVALID_IDX;
cm->frame_refs[ref_index].buf = NULL;
}
......
......@@ -155,13 +155,13 @@ static INLINE int dec_is_ref_frame_buf(VP10Decoder *const pbi,
RefCntBuffer *frame_buf) {
VP10_COMMON *const cm = &pbi->common;
int i;
for (i = 0; i < REFS_PER_FRAME; ++i) {
for (i = 0; i < INTER_REFS_PER_FRAME; ++i) {
RefBuffer *const ref_frame = &cm->frame_refs[i];
if (ref_frame->idx == INVALID_IDX) continue;
if (frame_buf == &cm->buffer_pool->frame_bufs[ref_frame->idx])
break;
}
return (i < REFS_PER_FRAME);
return (i < INTER_REFS_PER_FRAME);
}
#endif // CONFIG_EXT_REFS
......
......@@ -180,7 +180,7 @@ void vp10_frameworker_copy_context(VPxWorker *const dst_worker,
(MAX_LOOP_FILTER + 1) * sizeof(loop_filter_thresh));
dst_cm->lf.last_sharpness_level = src_cm->lf.sharpness_level;
dst_cm->lf.filter_level = src_cm->lf.filter_level;
memcpy(dst_cm->lf.ref_deltas, src_cm->lf.ref_deltas, MAX_REF_FRAMES);
memcpy(dst_cm->lf.ref_deltas, src_cm->lf.ref_deltas, TOTAL_REFS_PER_FRAME);
memcpy(dst_cm->lf.mode_deltas, src_cm->lf.mode_deltas, MAX_MODE_LF_DELTAS);
dst_cm->seg = src_cm->seg;
memcpy(dst_cm->frame_contexts, src_cm->frame_contexts,
......
......@@ -2473,7 +2473,7 @@ static void encode_loopfilter(VP10_COMMON *cm,
if (lf->mode_ref_delta_enabled) {
vpx_wb_write_bit(wb, lf->mode_ref_delta_update);
if (lf->mode_ref_delta_update) {
for (i = 0; i < MAX_REF_FRAMES; i++) {
for (i = 0; i < TOTAL_REFS_PER_FRAME; i++) {
const int delta = lf->ref_deltas[i];
const int changed = delta != lf->last_ref_deltas[i];
vpx_wb_write_bit(wb, changed);
......
......@@ -103,12 +103,12 @@ struct macroblock {
BLOCK_SIZE min_partition_size;
BLOCK_SIZE max_partition_size;
int mv_best_ref_index[MAX_REF_FRAMES];
unsigned int max_mv_context[MAX_REF_FRAMES];
int mv_best_ref_index[TOTAL_REFS_PER_FRAME];
unsigned int max_mv_context[TOTAL_REFS_PER_FRAME];
unsigned int source_variance;
unsigned int recon_variance;
unsigned int pred_sse[MAX_REF_FRAMES];
int pred_mv_sad[MAX_REF_FRAMES];
unsigned int pred_sse[TOTAL_REFS_PER_FRAME];
int pred_mv_sad[TOTAL_REFS_PER_FRAME];
#if CONFIG_REF_MV
int *nmvjointcost;
......@@ -160,7 +160,7 @@ struct macroblock {
int use_lp32x32fdct;
// Used to store sub partition's choices.
MV pred_mv[MAX_REF_FRAMES];
MV pred_mv[TOTAL_REFS_PER_FRAME];
// Store the best motion vector during motion search
int_mv best_mv;
......
......@@ -60,7 +60,7 @@ typedef struct {
// motion vector cache for adaptive motion search control in partition
// search loop
MV pred_mv[MAX_REF_FRAMES];
MV pred_mv[TOTAL_REFS_PER_FRAME];
INTERP_FILTER pred_interp_filter;
#if CONFIG_EXT_PARTITION_TYPES
PARTITION_TYPE partition;
......
......@@ -451,7 +451,7 @@ static void dealloc_compressor_data(VP10_COMP *cpi) {
cpi->active_map.map = NULL;
// Free up-sampled reference buffers.
for (i = 0; i < MAX_REF_FRAMES; i++)
for (i = 0; i < (REF_FRAMES + 1); i++)
vpx_free_frame_buffer(&cpi->upsampled_ref_bufs[i].buf);
vp10_free_ref_frame_buffers(cm->buffer_pool);
......@@ -2377,7 +2377,7 @@ static void cal_nmvsadcosts_hp(int *mvsadcost[2]) {
static INLINE void init_upsampled_ref_frame_bufs(VP10_COMP *cpi) {
int i;
for (i = 0; i < MAX_REF_FRAMES; ++i) {
for (i = 0; i < (REF_FRAMES + 1); ++i) {
cpi->upsampled_ref_bufs[i].ref_count = 0;
cpi->upsampled_ref_idx[i] = INVALID_IDX;
}
......@@ -2953,7 +2953,7 @@ static void generate_psnr_packet(VP10_COMP *cpi) {
}
int vp10_use_as_reference(VP10_COMP *cpi, int ref_frame_flags) {
if (ref_frame_flags > ((1 << REFS_PER_FRAME) - 1))
if (ref_frame_flags > ((1 << INTER_REFS_PER_FRAME) - 1))
return -1;
cpi->ref_frame_flags = ref_frame_flags;
......@@ -3297,7 +3297,7 @@ static int recode_loop_test(VP10_COMP *cpi,
static INLINE int get_free_upsampled_ref_buf(EncRefCntBuffer *ubufs) {
int i;
for (i = 0; i < MAX_REF_FRAMES; i++) {
for (i = 0; i < (REF_FRAMES + 1); i++) {
if (!ubufs[i].ref_count) {
return i;
}
......@@ -3710,7 +3710,7 @@ static INLINE void alloc_frame_mvs(VP10_COMMON *const cm,
void vp10_scale_references(VP10_COMP *cpi) {
VP10_COMMON *cm = &cpi->common;
MV_REFERENCE_FRAME ref_frame;
const VPX_REFFRAME ref_mask[REFS_PER_FRAME] = {
const VPX_REFFRAME ref_mask[INTER_REFS_PER_FRAME] = {
VPX_LAST_FLAG,
#if CONFIG_EXT_REFS
VPX_LAST2_FLAG,
......@@ -3835,7 +3835,7 @@ static void release_scaled_references(VP10_COMP *cpi) {
if (cpi->oxcf.pass == 0) {
// Only release scaled references under certain conditions:
// if reference will be updated, or if scaled reference has same resolution.
int refresh[REFS_PER_FRAME];
int refresh[INTER_REFS_PER_FRAME];
refresh[0] = (cpi->refresh_last_frame) ? 1 : 0;
#if CONFIG_EXT_REFS
refresh[1] = refresh[2] = 0;
......@@ -3860,7 +3860,7 @@ static void release_scaled_references(VP10_COMP *cpi) {
}
}
} else {
for (i = 0; i < MAX_REF_FRAMES; ++i) {
for (i = 0; i < TOTAL_REFS_PER_FRAME; ++i) {
const int idx = cpi->scaled_ref_idx[i];
RefCntBuffer *const buf = idx != INVALID_IDX ?
&cm->buffer_pool->frame_bufs[idx] : NULL;
......@@ -4669,7 +4669,7 @@ static void set_arf_sign_bias(VP10_COMP *cpi) {
static int setup_interp_filter_search_mask(VP10_COMP *cpi) {
INTERP_FILTER ifilter;
int ref_total[MAX_REF_FRAMES] = {0};
int ref_total[TOTAL_REFS_PER_FRAME] = {0};
MV_REFERENCE_FRAME ref;
int mask = 0;
if (cpi->common.last_frame_type == KEY_FRAME ||
......@@ -5642,7 +5642,7 @@ int vp10_get_compressed_data(VP10_COMP *cpi, unsigned int *frame_flags,
}
if (cpi->oxcf.pass != 0 || frame_is_intra_only(cm) == 1) {
for (i = 0; i < MAX_REF_FRAMES; ++i)
for (i = 0; i < TOTAL_REFS_PER_FRAME; ++i)
cpi->scaled_ref_idx[i] = INVALID_IDX;
}
......
......@@ -62,7 +62,7 @@ typedef struct {
unsigned char *last_frame_seg_map_copy;
// 0 = Intra, Last, GF, ARF
signed char last_ref_lf_deltas[MAX_REF_FRAMES];
signed char last_ref_lf_deltas[TOTAL_REFS_PER_FRAME];
// 0 = ZERO_MV, MV
signed char last_mode_lf_deltas[MAX_MODE_LF_DELTAS];
......@@ -360,13 +360,16 @@ typedef struct VP10_COMP {
YV12_BUFFER_CONFIG scaled_last_source;
// Up-sampled reference buffers
EncRefCntBuffer upsampled_ref_bufs[MAX_REF_FRAMES];
int upsampled_ref_idx[MAX_REF_FRAMES];
// NOTE(zoeliu): It is needed to allocate sufficient space to the up-sampled
// reference buffers, which should include the up-sampled version of all the
// possibly stored references plus the currently coded frame itself.
EncRefCntBuffer upsampled_ref_bufs[REF_FRAMES + 1];
int upsampled_ref_idx[REF_FRAMES + 1];
// For a still frame, this flag is set to 1 to skip partition search.
int partition_search_skippable_frame;
int scaled_ref_idx[MAX_REF_FRAMES];
int scaled_ref_idx[TOTAL_REFS_PER_FRAME];
#if CONFIG_EXT_REFS
int lst_fb_idxes[LAST_REF_FRAMES];
#else
......@@ -424,7 +427,10 @@ typedef struct VP10_COMP {
RATE_CONTROL rc;
double framerate;
int interp_filter_selected[MAX_REF_FRAMES][SWITCHABLE];
// NOTE(zoeliu): Any inter frame allows maximum of REF_FRAMES inter
// references; Plus the currently coded frame itself, it is needed to allocate
// sufficient space to the size of the maximum possible number of frames.
int interp_filter_selected[REF_FRAMES + 1][SWITCHABLE];
struct vpx_codec_pkt_list *output_pkt_list;
......@@ -622,7 +628,7 @@ typedef struct VP10_COMP {
int is_arf_filter_off;
#endif // CONFIG_EXT_REFS
#if CONFIG_GLOBAL_MOTION
int global_motion_used[MAX_REF_FRAMES];
int global_motion_used[TOTAL_REFS_PER_FRAME];
#endif
} VP10_COMP;
......
......@@ -22,7 +22,7 @@ typedef struct {
int_mv mv;
PREDICTION_MODE mode;
} m;
} ref[MAX_REF_FRAMES];
} ref[TOTAL_REFS_PER_FRAME];
} MBGRAPH_MB_STATS;
typedef struct {
......
......@@ -365,7 +365,7 @@ typedef struct RD_OPT {
int threshes[MAX_SEGMENTS][BLOCK_SIZES][MAX_MODES];
int64_t prediction_type_threshes[MAX_REF_FRAMES][REFERENCE_MODES];
int64_t prediction_type_threshes[TOTAL_REFS_PER_FRAME][REFERENCE_MODES];
int RDMULT;
int RDDIV;
......
This diff is collapsed.
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