Commit 9c9300f5 authored by Paul Wilkins's avatar Paul Wilkins

Merged NEWNEAR experiment

This commit merges the NEWNEAR experiment such that it
is effectively always on.

The fact that there were changes in the threading code again
highlights the need to strip out such features during the
bitstream development phase as trying to maintain this code
(especially as it is not being tested) slows the development cycle.

Change-Id: I8b34950a1333231ced9928aa11cd6d6459984b65
parent 82b865da
......@@ -136,7 +136,7 @@ int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height)
oci->mi = oci->mip + oci->mode_info_stride + 1;
/* allocate memory for last frame MODE_INFO array */
#if CONFIG_ERROR_CONCEALMENT || CONFIG_NEWNEAR
oci->prev_mip = vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO));
if (!oci->prev_mip)
......@@ -146,10 +146,6 @@ int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height)
}
oci->prev_mi = oci->prev_mip + oci->mode_info_stride + 1;
#else
oci->prev_mip = NULL;
oci->prev_mi = NULL;
#endif
oci->above_context = vpx_calloc(sizeof(ENTROPY_CONTEXT_PLANES) * oci->mb_cols, 1);
......
......@@ -253,9 +253,7 @@ typedef struct MacroBlockD
#endif /* CONFIG_DUALPRED */
YV12_BUFFER_CONFIG dst;
#if CONFIG_NEWNEAR
MODE_INFO *prev_mode_info_context;
#endif
MODE_INFO *mode_info_context;
int mode_info_stride;
......
......@@ -359,7 +359,6 @@ void vp8_entropy_mode_init()
vp8_tokens_from_tree(vp8_small_mvencodings, vp8_small_mvtree);
}
#if CONFIG_NEWNEAR
void vp8_init_mode_contexts(VP8_COMMON *pc)
{
vpx_memset(pc->mv_ref_ct, 0, sizeof(pc->mv_ref_ct));
......@@ -491,6 +490,3 @@ void print_mv_ref_cts(VP8_COMMON *pc)
}
}
#endif
......@@ -21,7 +21,6 @@ const unsigned char vp8_mbsplit_offset[4][16] = {
/* Predict motion vectors using those from already-decoded nearby blocks.
Note that we only consider one 4x4 subblock from each candidate 16x16
macroblock. */
#if CONFIG_NEWNEAR
void vp8_find_near_mvs
(
MACROBLOCKD *xd,
......@@ -122,9 +121,7 @@ void vp8_find_near_mvs
cnt[CNT_SPLITMV] = ((above->mbmi.mode == SPLITMV)
+ (left->mbmi.mode == SPLITMV)) * 2
+ (
#if CONFIG_NEWNEAR
lf_here->mbmi.mode == SPLITMV ||
#endif
aboveleft->mbmi.mode == SPLITMV);
/* Swap near and nearest if necessary */
......@@ -154,130 +151,6 @@ void vp8_find_near_mvs
vp8_clamp_mv2(best_mv, xd);
}
#else
void vp8_find_near_mvs
(
MACROBLOCKD *xd,
const MODE_INFO *here,
int_mv *nearest,
int_mv *nearby,
int_mv *best_mv,
int cnt[4],
int refframe,
int *ref_frame_sign_bias
)
{
const MODE_INFO *above = here - xd->mode_info_stride;
const MODE_INFO *left = here - 1;
const MODE_INFO *aboveleft = above - 1;
int_mv near_mvs[4];
int_mv *mv = near_mvs;
int *cntx = cnt;
enum {CNT_ZEROMV, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV};
/* Zero accumulators */
mv[0].as_int = mv[1].as_int = mv[2].as_int = 0;
cnt[0] = cnt[1] = cnt[2] = cnt[3] = 0;
/* Process above */
if (above->mbmi.ref_frame != INTRA_FRAME)
{
if (above->mbmi.mv.as_int)
{
(++mv)->as_int = above->mbmi.mv.as_int;
mv_bias(ref_frame_sign_bias[above->mbmi.ref_frame],
refframe, mv, ref_frame_sign_bias);
++cntx;
}
*cntx += 2;
}
/* Process left */
if (left->mbmi.ref_frame != INTRA_FRAME)
{
if (left->mbmi.mv.as_int)
{
int_mv this_mv;
this_mv.as_int = left->mbmi.mv.as_int;
mv_bias(ref_frame_sign_bias[left->mbmi.ref_frame],
refframe, &this_mv, ref_frame_sign_bias);
if (this_mv.as_int != mv->as_int)
{
(++mv)->as_int = this_mv.as_int;
++cntx;
}
*cntx += 2;
}
else
cnt[CNT_ZEROMV] += 2;
}
/* Process above left */
if (aboveleft->mbmi.ref_frame != INTRA_FRAME)
{
if (aboveleft->mbmi.mv.as_int)
{
int_mv this_mv;
this_mv.as_int = aboveleft->mbmi.mv.as_int;
mv_bias(ref_frame_sign_bias[aboveleft->mbmi.ref_frame],
refframe, &this_mv, ref_frame_sign_bias);
if (this_mv.as_int != mv->as_int)
{
(++mv)->as_int = this_mv.as_int;
++cntx;
}
*cntx += 1;
}
else
cnt[CNT_ZEROMV] += 1;
}
/* If we have three distinct MV's ... */
if (cnt[CNT_SPLITMV])
{
/* See if above-left MV can be merged with NEAREST */
if (mv->as_int == near_mvs[CNT_NEAREST].as_int)
cnt[CNT_NEAREST] += 1;
}
cnt[CNT_SPLITMV] = ((above->mbmi.mode == SPLITMV)
+ (left->mbmi.mode == SPLITMV)) * 2
+ (aboveleft->mbmi.mode == SPLITMV);
/* Swap near and nearest if necessary */
if (cnt[CNT_NEAR] > cnt[CNT_NEAREST])
{
int tmp;
tmp = cnt[CNT_NEAREST];
cnt[CNT_NEAREST] = cnt[CNT_NEAR];
cnt[CNT_NEAR] = tmp;
tmp = near_mvs[CNT_NEAREST].as_int;
near_mvs[CNT_NEAREST].as_int = near_mvs[CNT_NEAR].as_int;
near_mvs[CNT_NEAR].as_int = tmp;
}
/* Use near_mvs[0] to store the "best" MV */
if (cnt[CNT_NEAREST] >= cnt[CNT_ZEROMV])
near_mvs[CNT_ZEROMV] = near_mvs[CNT_NEAREST];
/* Set up return values */
best_mv->as_int = near_mvs[0].as_int;
nearest->as_int = near_mvs[CNT_NEAREST].as_int;
nearby->as_int = near_mvs[CNT_NEAR].as_int;
//TODO: move clamp outside findnearmv
vp8_clamp_mv2(nearest, xd);
vp8_clamp_mv2(nearby, xd);
vp8_clamp_mv2(best_mv, xd);
}
#endif
vp8_prob *vp8_mv_ref_probs(VP8_COMMON *pc,
vp8_prob p[VP8_MVREFS-1], const int near_mv_ref_ct[4]
)
......
......@@ -76,9 +76,7 @@ void vp8_find_near_mvs
(
MACROBLOCKD *xd,
const MODE_INFO *here,
#if CONFIG_NEWNEAR
const MODE_INFO *lfhere,
#endif
int_mv *nearest, int_mv *nearby, int_mv *best,
int near_mv_ref_cts[4],
int refframe,
......
......@@ -10,7 +10,6 @@
#include "entropy.h"
#if CONFIG_NEWNEAR
const int default_vp8_mode_contexts[6][4] =
{
{ /* 0 */
......@@ -41,32 +40,3 @@ const int default_vp8_mode_contexts_a[6][4] =
{ /* 5 */
234, 94, 128, 28},
};
#else
const int default_vp8_mode_contexts[6][4] =
{
{
/* 0 */
7, 1, 1, 143,
},
{
/* 1 */
14, 18, 14, 107,
},
{
/* 2 */
135, 64, 57, 68,
},
{
/* 3 */
60, 56, 128, 65,
},
{
/* 4 */
159, 134, 128, 34,
},
{
/* 5 */
234, 188, 128, 28,
},
};
#endif
\ No newline at end of file
......@@ -13,7 +13,5 @@
#define __INC_MODECONT_H
extern const int default_vp8_mode_contexts[6][4];
#if CONFIG_NEWNEAR
extern const int default_vp8_mode_contexts_a[6][4];
#endif
#endif
......@@ -249,13 +249,10 @@ typedef struct VP8Common
FRAME_CONTEXT lfc; /* last frame entropy */
FRAME_CONTEXT fc; /* this frame entropy */
#if CONFIG_NEWNEAR
int mv_ref_ct[6][4][2];
int mode_context[6][4];
int mv_ref_ct_a[6][4][2];
int mode_context_a[6][4];
#endif
int vp8_mode_contexts[6][4];
unsigned int current_video_frame;
......
......@@ -618,10 +618,8 @@ static void read_mb_segment_id ( VP8D_COMP *pbi,
}
static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
#if CONFIG_NEWNEAR
MODE_INFO *prev_mi,
#endif
int mb_row, int mb_col)
int mb_row, int mb_col)
{
VP8_COMMON *const cm = & pbi->common;
vp8_reader *const bc = & pbi->bc;
......@@ -697,9 +695,7 @@ static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
vp8_prob mv_ref_p [VP8_MVREFS-1];
vp8_find_near_mvs(xd, mi,
#if CONFIG_NEWNEAR
prev_mi,
#endif
&nearest, &nearby, &best_mv, rct,
mbmi->ref_frame, pbi->common.ref_frame_sign_bias);
vp8_mv_ref_probs(&pbi->common, mv_ref_p, rct);
......@@ -715,9 +711,7 @@ static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
{
mbmi->mode = read_mv_ref(bc, mv_ref_p);
#if CONFIG_NEWNEAR
vp8_accum_mv_refs(&pbi->common, mbmi->mode, rct);
#endif
}
mbmi->uv_mode = DC_PRED;
......@@ -857,9 +851,7 @@ static void read_mb_modes_mv(VP8D_COMP *pbi, MODE_INFO *mi, MB_MODE_INFO *mbmi,
if (mbmi->second_ref_frame)
{
vp8_find_near_mvs(xd, mi,
#if CONFIG_NEWNEAR
prev_mi,
#endif
&nearest, &nearby, &best_mv, rct,
(int)mbmi->second_ref_frame,
pbi->common.ref_frame_sign_bias);
......@@ -985,9 +977,7 @@ void vp8_decode_mode_mvs(VP8D_COMP *pbi)
int row_delta[4] = {-1, 0, +1, 0};
int col_delta[4] = {+1, +1, -1, +1};
#if CONFIG_NEWNEAR
MODE_INFO *prev_mi = cm->prev_mi;
#endif
mb_mode_mv_init(pbi);
......@@ -1023,9 +1013,7 @@ void vp8_decode_mode_mvs(VP8D_COMP *pbi)
if ((mb_row >= cm->mb_rows) || (mb_col >= cm->mb_cols))
{
#if CONFIG_NEWNEAR
prev_mi += offset_extended;
#endif
mi += offset_extended; /* next macroblock */
continue;
}
......@@ -1046,9 +1034,7 @@ void vp8_decode_mode_mvs(VP8D_COMP *pbi)
vp8_kfread_modes(pbi, mi, mb_row, mb_col);
else
read_mb_modes_mv(pbi, mi, &mi->mbmi,
#if CONFIG_NEWNEAR
prev_mi,
#endif
mb_row, mb_col);
#if CONFIG_ERROR_CONCEALMENT
......@@ -1064,9 +1050,7 @@ void vp8_decode_mode_mvs(VP8D_COMP *pbi)
}
#endif
#if CONFIG_NEWNEAR
prev_mi += offset_extended;
#endif
mi += offset_extended; /* next macroblock */
}
}
......@@ -1079,9 +1063,7 @@ void vp8_decode_mode_mvs(VP8D_COMP *pbi)
{
MODE_INFO *mi = pbi->common.mi;
#if CONFIG_NEWNEAR
MODE_INFO *prev_mi = pbi->common.prev_mi;
#endif
int mb_row = -1;
......@@ -1130,9 +1112,7 @@ void vp8_decode_mode_mvs(VP8D_COMP *pbi)
vp8_kfread_modes(pbi, mi, mb_row, mb_col);
else
read_mb_modes_mv(pbi, mi, &mi->mbmi,
#if CONFIG_NEWNEAR
prev_mi,
#endif
mb_row, mb_col);
//printf("%3d", mi->mbmi.mode);
......@@ -1169,15 +1149,11 @@ void vp8_decode_mode_mvs(VP8D_COMP *pbi)
fprintf(statsfile, "%2d%2d%2d ",
mi->mbmi.segment_id, mi->mbmi.ref_frame, mi->mbmi.mode );
#endif
#if CONFIG_NEWNEAR
prev_mi++;
#endif
mi++; /* next macroblock */
}
// printf("\n");
#if CONFIG_NEWNEAR
prev_mi++;
#endif
mi++; /* skip left predictor each row */
}
......
......@@ -947,17 +947,10 @@ static void init_frame(VP8D_COMP *pbi)
vpx_memcpy(&pc->lfc, &pc->fc, sizeof(pc->fc));
vpx_memcpy(&pc->lfc_a, &pc->fc, sizeof(pc->fc));
#if CONFIG_NEWNEAR
vp8_init_mode_contexts(&pbi->common);
vpx_memcpy( pbi->common.vp8_mode_contexts,
pbi->common.mode_context,
sizeof(pbi->common.mode_context));
#else
vpx_memcpy( pbi->common.vp8_mode_contexts,
default_vp8_mode_contexts,
sizeof(default_vp8_mode_contexts));
#endif /* CONFIG_NEWNEAR */
}
else
{
......@@ -1366,20 +1359,16 @@ int vp8_decode_frame(VP8D_COMP *pbi)
if(pc->refresh_alt_ref_frame)
{
vpx_memcpy(&pc->fc, &pc->lfc_a, sizeof(pc->fc));
#if CONFIG_NEWNEAR
vpx_memcpy( pc->vp8_mode_contexts,
pc->mode_context_a,
sizeof(pc->vp8_mode_contexts));
#endif
}
else
{
vpx_memcpy(&pc->fc, &pc->lfc, sizeof(pc->fc));
#if CONFIG_NEWNEAR
vpx_memcpy( pc->vp8_mode_contexts,
pc->mode_context,
sizeof(pc->vp8_mode_contexts));
#endif
}
/* Buffer to buffer copy flags. */
......@@ -1493,13 +1482,10 @@ int vp8_decode_frame(VP8D_COMP *pbi)
pc->mb_no_coeff_skip = (int)vp8_read_bit(bc);
vp8_decode_mode_mvs(pbi);
#if CONFIG_NEWNEAR
if(pbi->common.frame_type != KEY_FRAME)
{
vp8_update_mode_context(&pbi->common);
}
#endif
#if CONFIG_ERROR_CONCEALMENT
if (pbi->ec_active &&
......
......@@ -624,7 +624,6 @@ int vp8dx_receive_compressed_data(VP8D_PTR ptr, unsigned long size, const unsign
}
#endif
#if CONFIG_NEWNEAR
if(cm->show_frame)
{
vpx_memcpy(cm->prev_mip, cm->mip,
......@@ -635,7 +634,6 @@ int vp8dx_receive_compressed_data(VP8D_PTR ptr, unsigned long size, const unsign
vpx_memset(cm->prev_mip, 0,
(cm->mb_cols + 1) * (cm->mb_rows + 1)* sizeof(MODE_INFO));
}
#endif
/*vp8_print_modes_and_motion_vectors( cm->mi, cm->mb_rows,cm->mb_cols, cm->current_video_frame);*/
......
......@@ -1050,9 +1050,7 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
int pred_context;
MODE_INFO *m = pc->mi;
#if CONFIG_NEWNEAR
MODE_INFO *prev_m = pc->prev_mi;
#endif
const int mis = pc->mode_info_stride;
int mb_row, mb_col;
......@@ -1186,9 +1184,7 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
// Make sure the MacroBlockD mode info pointer is set correctly
xd->mode_info_context = m;
#if CONFIG_NEWNEAR
xd->prev_mode_info_context = prev_m;
#endif
#ifdef ENTROPY_STATS
active_section = 9;
......@@ -1280,9 +1276,7 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
int ct[4];
vp8_find_near_mvs(xd, m,
#if CONFIG_NEWNEAR
prev_m,
#endif
&n1, &n2, &best_mv, ct, rf,
cpi->common.ref_frame_sign_bias);
vp8_mv_ref_probs(&cpi->common, mv_ref_p, ct);
......@@ -1301,9 +1295,7 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
if ( !segfeature_active( xd, segment_id, SEG_LVL_MODE ) )
{
write_mv_ref(w, mode, mv_ref_p);
#if CONFIG_NEWNEAR
vp8_accum_mv_refs(&cpi->common, mode, ct);
#endif
}
......@@ -1338,9 +1330,7 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
int_mv n1, n2;
int ct[4];
vp8_find_near_mvs(xd, m,
#if CONFIG_NEWNEAR
prev_m,
#endif
&n1, &n2, &best_mv,
ct, second_rf,
cpi->common.ref_frame_sign_bias);
......@@ -1416,11 +1406,9 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
}
}
#if CONFIG_NEWNEAR
prev_m += offset_extended;
assert((prev_m-cpi->common.prev_mip)==(m-cpi->common.mip));
assert((prev_m-cpi->common.prev_mi)==(m-cpi->common.mi));
#endif
// skip to next MB
mb_row += dy;
......@@ -1461,9 +1449,7 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
MODE_INFO *m = pc->mi;
#if CONFIG_NEWNEAR
MODE_INFO *prev_m = pc->prev_mi;
#endif
const int mis = pc->mode_info_stride;
int mb_row = -1;
......@@ -1575,9 +1561,7 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
// Make sure the MacroBlockD mode info pointer is set correctly
xd->mode_info_context = m;
#if CONFIG_NEWNEAR
xd->prev_mode_info_context = prev_m;
#endif
#ifdef ENTROPY_STATS
active_section = 9;
......@@ -1670,9 +1654,7 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
int_mv n1, n2;
vp8_find_near_mvs(xd, m,
#if CONFIG_NEWNEAR
prev_m,
#endif
&n1, &n2, &best_mv, ct, rf, cpi->common.ref_frame_sign_bias);
vp8_mv_ref_probs(&cpi->common, mv_ref_p, ct);
......@@ -1691,9 +1673,7 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
if ( !segfeature_active( xd, segment_id, SEG_LVL_MODE ) )
{
write_mv_ref(w, mode, mv_ref_p);
#if CONFIG_NEWNEAR
vp8_accum_mv_refs(&cpi->common, mode, ct);
#endif
}
{
......@@ -1725,9 +1705,7 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
int_mv n1, n2;
int ct[4];
vp8_find_near_mvs(xd, m,
#if CONFIG_NEWNEAR
prev_m,
#endif
&n1, &n2, &best_mv,
ct, second_rf,
cpi->common.ref_frame_sign_bias);
......@@ -1802,19 +1780,14 @@ static void pack_inter_mode_mvs(VP8_COMP *const cpi)
}
++m;
#if CONFIG_NEWNEAR
++prev_m;
assert((prev_m-cpi->common.prev_mip)==(m-cpi->common.mip));
assert((prev_m-cpi->common.prev_mi)==(m-cpi->common.mi));
#endif
cpi->mb.partition_info++;
}
++m; /* skip L prediction border */
#if CONFIG_NEWNEAR
++prev_m;
#endif
cpi->mb.partition_info++;
}
......@@ -3020,9 +2993,7 @@ void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, unsigned long *size)
{
pack_inter_mode_mvs(cpi);
#if CONFIG_NEWNEAR
vp8_update_mode_context(&cpi->common);
#endif
#ifdef ENTROPY_STATS
active_section = 1;
......
......@@ -624,12 +624,10 @@ void encode_sb_row (VP8_COMP *cpi,
x->partition_info += offset_extended;
xd->mode_info_context += offset_extended;
#if CONFIG_NEWNEAR
xd->prev_mode_info_context += offset_extended;
assert((xd->prev_mode_info_context - cpi->common.prev_mip)
==(xd->mode_info_context - cpi->common.mip));
#endif
continue;
}
......@@ -787,12 +785,10 @@ void encode_sb_row (VP8_COMP *cpi,
x->partition_info += offset_extended;
xd->mode_info_context += offset_extended;
#if CONFIG_NEWNEAR
xd->prev_mode_info_context += offset_extended;
assert((xd->prev_mode_info_context - cpi->common.prev_mip)
==(xd->mode_info_context - cpi->common.mip));
#endif
}
}
......@@ -806,9 +802,7 @@ void encode_sb_row (VP8_COMP *cpi,
xd->dst.v_buffer + 8);*/
// this is to account for the border
#if CONFIG_NEWNEAR
xd->prev_mode_info_context += 1 - (cm->mb_cols & 0x1) + xd->mode_info_stride;
#endif
xd->mode_info_context += 1 - (cm->mb_cols & 0x1) + xd->mode_info_stride;
x->partition_info += 1 - (cm->mb_cols & 0x1) + xd->mode_info_stride;
x->gf_active_ptr += cm->mb_cols - (cm->mb_cols & 0x1);
......@@ -1033,11 +1027,9 @@ void encode_mb_row(VP8_COMP *cpi,
// skip to next mb
xd->mode_info_context++;