Commit ff52bf36 authored by Paul Wilkins's avatar Paul Wilkins

Restructure of activity masking code.

This commit restructures the mb activity masking code
to better facilitate experimentation using different metrics
etc. and also allows for adjustment of the zero bin either
for encode only or both the encode and mode selection
stages

It also uses information from the current frame rather than
the previous frame and the default strength has been
reduced.

Change-Id: Id39b19eace37574dc429f25aae810c203709629b
parent ba6f60db
......@@ -82,7 +82,9 @@ typedef struct
int errthresh;
int rddiv;
int rdmult;
INT64 activity_sum;
unsigned int * mb_activity_ptr;
int * mb_norm_activity_ptr;
signed int act_zbin_adj;
int mvcosts[2][MVvals+1];
int *mvcost[2];
......
This diff is collapsed.
......@@ -91,8 +91,8 @@ THREAD_FUNCTION thread_encoding_proc(void *p_data)
int dst_fb_idx = cm->new_fb_idx;
int recon_y_stride = cm->yv12_fb[ref_fb_idx].y_stride;
int recon_uv_stride = cm->yv12_fb[ref_fb_idx].uv_stride;
int map_index = (mb_row * cm->mb_cols);
volatile int *last_row_current_mb_col;
INT64 activity_sum = 0;
tp = cpi->tok + (mb_row * (cm->mb_cols * 16 * 24));
......@@ -112,6 +112,11 @@ THREAD_FUNCTION thread_encoding_proc(void *p_data)
//printf("Thread mb_row = %d\n", mb_row);
// Set the mb activity pointer to the start of the row.
x->mb_activity_ptr = &cpi->mb_activity_map[map_index];
x->mb_norm_activity_ptr =
&cpi->mb_norm_activity_map[map_index];
// for each macroblock col in image
for (mb_col = 0; mb_col < cm->mb_cols; mb_col++)
{
......@@ -148,15 +153,15 @@ THREAD_FUNCTION thread_encoding_proc(void *p_data)
x->rdmult = cpi->RDMULT;
if (cpi->oxcf.tuning == VP8_TUNE_SSIM)
activity_sum += vp8_activity_masking(cpi, x);
vp8_activity_masking(cpi, x);
// Is segmentation enabled
// MB level adjutment to quantizer
if (xd->segmentation_enabled)
{
// Code to set segment id in xd->mbmi.segment_id for current MB (with range checking)
if (cpi->segmentation_map[seg_map_index + mb_col] <= 3)
xd->mode_info_context->mbmi.segment_id = cpi->segmentation_map[seg_map_index + mb_col];
if (cpi->segmentation_map[map_index + mb_col] <= 3)
xd->mode_info_context->mbmi.segment_id = cpi->segmentation_map[map_index + mb_col];
else
xd->mode_info_context->mbmi.segment_id = 0;
......@@ -165,7 +170,7 @@ THREAD_FUNCTION thread_encoding_proc(void *p_data)
else
xd->mode_info_context->mbmi.segment_id = 0; // Set to Segment 0 by default
x->active_ptr = cpi->active_map + seg_map_index + mb_col;
x->active_ptr = cpi->active_map + map_index + mb_col;
if (cm->frame_type == KEY_FRAME)
{
......@@ -203,26 +208,31 @@ THREAD_FUNCTION thread_encoding_proc(void *p_data)
if (cpi->cyclic_refresh_mode_enabled && xd->segmentation_enabled)
{
const MB_MODE_INFO * mbmi = &xd->mode_info_context->mbmi;
cpi->segmentation_map[seg_map_index + mb_col] = mbmi->segment_id;
cpi->segmentation_map[map_index + mb_col] = mbmi->segment_id;
// If the block has been refreshed mark it as clean (the magnitude of the -ve influences how long it will be before we consider another refresh):
// Else if it was coded (last frame 0,0) and has not already been refreshed then mark it as a candidate for cleanup next time (marked 0)
// else mark it as dirty (1).
if (mbmi->segment_id)
cpi->cyclic_refresh_map[seg_map_index + mb_col] = -1;
cpi->cyclic_refresh_map[map_index + mb_col] = -1;
else if ((mbmi->mode == ZEROMV) && (mbmi->ref_frame == LAST_FRAME))
{
if (cpi->cyclic_refresh_map[seg_map_index + mb_col] == 1)
cpi->cyclic_refresh_map[seg_map_index + mb_col] = 0;
if (cpi->cyclic_refresh_map[map_index + mb_col] == 1)
cpi->cyclic_refresh_map[map_index + mb_col] = 0;
}
else
cpi->cyclic_refresh_map[seg_map_index + mb_col] = 1;
cpi->cyclic_refresh_map[map_index + mb_col] = 1;
}
}
cpi->tplist[mb_row].stop = tp;
x->gf_active_ptr++; // Increment pointer into gf useage flags structure for next mb
// Increment pointer into gf useage flags structure.
x->gf_active_ptr++;
// Increment the activity mask pointers.
x->mb_activity_ptr++;
x->mb_norm_activity_ptr++;
for (i = 0; i < 16; i++)
vpx_memcpy(&xd->mode_info_context->bmi[i], &xd->block[i].bmi, sizeof(xd->block[i].bmi));
......@@ -256,7 +266,6 @@ THREAD_FUNCTION thread_encoding_proc(void *p_data)
// this is to account for the border
xd->mode_info_context++;
x->partition_info++;
x->activity_sum += activity_sum;
x->src.y_buffer += 16 * x->src.y_stride * (cpi->encoding_thread_count + 1) - 16 * cm->mb_cols;
x->src.u_buffer += 8 * x->src.uv_stride * (cpi->encoding_thread_count + 1) - 8 * cm->mb_cols;
......@@ -444,8 +453,6 @@ void vp8cx_init_mbrthread_data(VP8_COMP *cpi,
vp8_setup_block_ptrs(mb);
mb->activity_sum = 0;
mbd->left_context = &cm->left_context;
mb->mvc = cm->fc.mvc;
......
......@@ -298,6 +298,12 @@ static void dealloc_compressor_data(VP8_COMP *cpi)
vpx_free(cpi->gf_active_flags);
cpi->gf_active_flags = 0;
// Activity mask based per mb zbin adjustments
vpx_free(cpi->mb_activity_map);
cpi->mb_activity_map = 0;
vpx_free(cpi->mb_norm_activity_map);
cpi->mb_norm_activity_map = 0;
vpx_free(cpi->mb.pip);
cpi->mb.pip = 0;
......@@ -1324,11 +1330,20 @@ void vp8_alloc_compressor_data(VP8_COMP *cpi)
// Structures used to minitor GF usage
vpx_free(cpi->gf_active_flags);
vpx_free(cpi->gf_active_flags);
CHECK_MEM_ERROR(cpi->gf_active_flags,
vpx_calloc(1, cm->mb_rows * cm->mb_cols));
cpi->gf_active_count = cm->mb_rows * cm->mb_cols;
CHECK_MEM_ERROR(cpi->gf_active_flags, vpx_calloc(1, cm->mb_rows * cm->mb_cols));
vpx_free(cpi->mb_activity_map);
CHECK_MEM_ERROR(cpi->mb_activity_map,
vpx_calloc(sizeof(unsigned int),
cm->mb_rows * cm->mb_cols));
cpi->gf_active_count = cm->mb_rows * cm->mb_cols;
vpx_free(cpi->mb_norm_activity_map);
CHECK_MEM_ERROR(cpi->mb_norm_activity_map,
vpx_calloc(sizeof(unsigned int),
cm->mb_rows * cm->mb_cols));
#if !(CONFIG_REALTIME_ONLY)
vpx_free(cpi->total_stats);
......
......@@ -317,7 +317,6 @@ typedef struct
int mvcostmultiplier;
int subseqblockweight;
int errthresh;
unsigned int activity_avg;
int RDMULT;
int RDDIV ;
......@@ -648,8 +647,14 @@ typedef struct
#endif
int b_calculate_psnr;
// Per MB activity measurement
unsigned int activity_avg;
unsigned int * mb_activity_map;
int * mb_norm_activity_map;
unsigned char *gf_active_flags; // Record of which MBs still refer to last golden frame either directly or through 0,0
// Record of which MBs still refer to last golden frame either
// directly or through 0,0
unsigned char *gf_active_flags;
int gf_active_count;
//Store last frame's MV info for next frame MV prediction
......@@ -668,7 +673,7 @@ void vp8_encode_frame(VP8_COMP *cpi);
void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, unsigned long *size);
unsigned int vp8_activity_masking(VP8_COMP *cpi, MACROBLOCK *x);
void vp8_activity_masking(VP8_COMP *cpi, MACROBLOCK *x);
int rd_cost_intra_mb(MACROBLOCKD *x);
......
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