Index: source/libvpx/vp9/encoder/vp9_encodeframe.c |
diff --git a/source/libvpx/vp9/encoder/vp9_encodeframe.c b/source/libvpx/vp9/encoder/vp9_encodeframe.c |
index 0e74784e9b6101c5e5559af87ec49823deeab38a..a8adca9ecf166ca65a2f88b702c8928223c6423d 100644 |
--- a/source/libvpx/vp9/encoder/vp9_encodeframe.c |
+++ b/source/libvpx/vp9/encoder/vp9_encodeframe.c |
@@ -13,8 +13,10 @@ |
#include <stdio.h> |
#include "./vp9_rtcd.h" |
+#include "./vpx_dsp_rtcd.h" |
#include "./vpx_config.h" |
+#include "vpx_ports/mem.h" |
#include "vpx_ports/vpx_timer.h" |
#include "vp9/common/vp9_common.h" |
@@ -360,7 +362,7 @@ static void get_variance(var *v) { |
((v->sum_error * v->sum_error) >> v->log2_count)) >> v->log2_count); |
} |
-void sum_2_variances(const var *a, const var *b, var *r) { |
+static void sum_2_variances(const var *a, const var *b, var *r) { |
assert(a->log2_count == b->log2_count); |
fill_variance(a->sum_square_error + b->sum_square_error, |
a->sum_error + b->sum_error, a->log2_count + 1, r); |
@@ -462,46 +464,55 @@ static int set_vt_partitioning(VP9_COMP *cpi, |
return 0; |
} |
-void vp9_set_vbp_thresholds(VP9_COMP *cpi, int q) { |
+// Set the variance split thresholds for following the block sizes: |
+// 0 - threshold_64x64, 1 - threshold_32x32, 2 - threshold_16x16, |
+// 3 - vbp_threshold_8x8. vbp_threshold_8x8 (to split to 4x4 partition) is |
+// currently only used on key frame. |
+static void set_vbp_thresholds(VP9_COMP *cpi, int64_t thresholds[], int q) { |
+ VP9_COMMON *const cm = &cpi->common; |
+ const int is_key_frame = (cm->frame_type == KEY_FRAME); |
+ const int threshold_multiplier = is_key_frame ? 20 : 1; |
+ const int64_t threshold_base = (int64_t)(threshold_multiplier * |
+ cpi->y_dequant[q][1]); |
+ if (is_key_frame) { |
+ thresholds[0] = threshold_base; |
+ thresholds[1] = threshold_base >> 2; |
+ thresholds[2] = threshold_base >> 2; |
+ thresholds[3] = threshold_base << 2; |
+ } else { |
+ thresholds[1] = threshold_base; |
+ if (cm->width <= 352 && cm->height <= 288) { |
+ thresholds[0] = threshold_base >> 2; |
+ thresholds[2] = threshold_base << 3; |
+ } else { |
+ thresholds[0] = threshold_base; |
+ thresholds[1] = (5 * threshold_base) >> 2; |
+ if (cm->width >= 1920 && cm->height >= 1080) |
+ thresholds[1] = (7 * threshold_base) >> 2; |
+ thresholds[2] = threshold_base << cpi->oxcf.speed; |
+ } |
+ } |
+} |
+ |
+void vp9_set_variance_partition_thresholds(VP9_COMP *cpi, int q) { |
+ VP9_COMMON *const cm = &cpi->common; |
SPEED_FEATURES *const sf = &cpi->sf; |
+ const int is_key_frame = (cm->frame_type == KEY_FRAME); |
if (sf->partition_search_type != VAR_BASED_PARTITION && |
sf->partition_search_type != REFERENCE_PARTITION) { |
return; |
} else { |
- VP9_COMMON *const cm = &cpi->common; |
- const int is_key_frame = (cm->frame_type == KEY_FRAME); |
- const int threshold_multiplier = is_key_frame ? 20 : 1; |
- const int64_t threshold_base = (int64_t)(threshold_multiplier * |
- cpi->y_dequant[q][1]); |
- |
- // TODO(marpan): Allow 4x4 partitions for inter-frames. |
- // use_4x4_partition = (variance4x4downsample[i2 + j] == 1); |
- // If 4x4 partition is not used, then 8x8 partition will be selected |
- // if variance of 16x16 block is very high, so use larger threshold |
- // for 16x16 (threshold_bsize_min) in that case. |
- |
- // Array index: 0 - threshold_64x64; 1 - threshold_32x32; |
- // 2 - threshold_16x16; 3 - vbp_threshold_8x8; |
+ set_vbp_thresholds(cpi, cpi->vbp_thresholds, q); |
+ // The thresholds below are not changed locally. |
if (is_key_frame) { |
- cpi->vbp_thresholds[0] = threshold_base; |
- cpi->vbp_thresholds[1] = threshold_base >> 2; |
- cpi->vbp_thresholds[2] = threshold_base >> 2; |
- cpi->vbp_thresholds[3] = threshold_base << 2; |
cpi->vbp_threshold_sad = 0; |
cpi->vbp_bsize_min = BLOCK_8X8; |
} else { |
- cpi->vbp_thresholds[1] = threshold_base; |
- if (cm->width <= 352 && cm->height <= 288) { |
- cpi->vbp_thresholds[0] = threshold_base >> 2; |
- cpi->vbp_thresholds[2] = threshold_base << 3; |
+ if (cm->width <= 352 && cm->height <= 288) |
cpi->vbp_threshold_sad = 100; |
- } else { |
- cpi->vbp_thresholds[0] = threshold_base; |
- cpi->vbp_thresholds[1] = (5 * threshold_base) >> 2; |
- cpi->vbp_thresholds[2] = threshold_base << cpi->oxcf.speed; |
+ else |
cpi->vbp_threshold_sad = (cpi->y_dequant[q][1] << 1) > 1000 ? |
(cpi->y_dequant[q][1] << 1) : 1000; |
- } |
cpi->vbp_bsize_min = BLOCK_16X16; |
} |
cpi->vbp_threshold_minmax = 15 + (q >> 3); |
@@ -550,23 +561,6 @@ static int compute_minmax_8x8(const uint8_t *s, int sp, const uint8_t *d, |
return (minmax_max - minmax_min); |
} |
-static void modify_vbp_thresholds(VP9_COMP *cpi, int64_t thresholds[], int q) { |
- VP9_COMMON *const cm = &cpi->common; |
- const int64_t threshold_base = (int64_t)(cpi->y_dequant[q][1]); |
- |
- // Array index: 0 - threshold_64x64; 1 - threshold_32x32; |
- // 2 - threshold_16x16; 3 - vbp_threshold_8x8; |
- thresholds[1] = threshold_base; |
- if (cm->width <= 352 && cm->height <= 288) { |
- thresholds[0] = threshold_base >> 2; |
- thresholds[2] = threshold_base << 3; |
- } else { |
- thresholds[0] = threshold_base; |
- thresholds[1] = (5 * threshold_base) >> 2; |
- thresholds[2] = threshold_base << cpi->oxcf.speed; |
- } |
-} |
- |
static void fill_variance_4x4avg(const uint8_t *s, int sp, const uint8_t *d, |
int dp, int x8_idx, int y8_idx, v8x8 *vst, |
#if CONFIG_VP9_HIGHBITDEPTH |
@@ -679,7 +673,7 @@ static int choose_partitioning(VP9_COMP *cpi, |
if (cyclic_refresh_segment_id_boosted(segment_id)) { |
int q = vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex); |
- modify_vbp_thresholds(cpi, thresholds, q); |
+ set_vbp_thresholds(cpi, thresholds, q); |
} |
} |
@@ -723,7 +717,7 @@ static int choose_partitioning(VP9_COMP *cpi, |
mbmi->mv[0].as_int = 0; |
mbmi->interp_filter = BILINEAR; |
- y_sad = vp9_int_pro_motion_estimation(cpi, x, bsize); |
+ y_sad = vp9_int_pro_motion_estimation(cpi, x, bsize, mi_row, mi_col); |
if (y_sad_g < y_sad) { |
vp9_setup_pre_planes(xd, 0, yv12_g, mi_row, mi_col, |
&cm->frame_refs[GOLDEN_FRAME - 1].sf); |
@@ -3671,15 +3665,15 @@ static int set_var_thresh_from_histogram(VP9_COMP *cpi) { |
if (cm->use_highbitdepth) { |
switch (cm->bit_depth) { |
case VPX_BITS_8: |
- vp9_highbd_get16x16var(src, src_stride, last_src, last_stride, |
+ vpx_highbd_8_get16x16var(src, src_stride, last_src, last_stride, |
&var16->sse, &var16->sum); |
break; |
case VPX_BITS_10: |
- vp9_highbd_10_get16x16var(src, src_stride, last_src, last_stride, |
+ vpx_highbd_10_get16x16var(src, src_stride, last_src, last_stride, |
&var16->sse, &var16->sum); |
break; |
case VPX_BITS_12: |
- vp9_highbd_12_get16x16var(src, src_stride, last_src, last_stride, |
+ vpx_highbd_12_get16x16var(src, src_stride, last_src, last_stride, |
&var16->sse, &var16->sum); |
break; |
default: |
@@ -3688,11 +3682,11 @@ static int set_var_thresh_from_histogram(VP9_COMP *cpi) { |
return -1; |
} |
} else { |
- vp9_get16x16var(src, src_stride, last_src, last_stride, |
+ vpx_get16x16var(src, src_stride, last_src, last_stride, |
&var16->sse, &var16->sum); |
} |
#else |
- vp9_get16x16var(src, src_stride, last_src, last_stride, |
+ vpx_get16x16var(src, src_stride, last_src, last_stride, |
&var16->sse, &var16->sum); |
#endif // CONFIG_VP9_HIGHBITDEPTH |
var16->var = var16->sse - |