2011-10-05 12:26:00 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <limits.h>
|
2013-05-08 23:12:37 +02:00
|
|
|
|
2013-09-24 22:47:29 +02:00
|
|
|
#include "vpx_mem/vpx_mem.h"
|
|
|
|
#include "vp9/encoder/vp9_rdopt.h"
|
|
|
|
#include "vp9/encoder/vp9_segmentation.h"
|
|
|
|
#include "vp9/encoder/vp9_mcomp.h"
|
|
|
|
#include "vp9/common/vp9_blockd.h"
|
|
|
|
#include "vp9/common/vp9_reconinter.h"
|
|
|
|
#include "vp9/common/vp9_reconintra.h"
|
|
|
|
#include "vp9/common/vp9_systemdependent.h"
|
|
|
|
|
|
|
|
|
2011-10-05 12:26:00 +02:00
|
|
|
|
2012-11-01 00:09:17 +01:00
|
|
|
static unsigned int do_16x16_motion_iteration(VP9_COMP *cpi,
|
2014-01-03 20:48:07 +01:00
|
|
|
const MV *ref_mv,
|
2014-01-13 20:21:07 +01:00
|
|
|
MV *dst_mv,
|
Spatial resamping of ZEROMV predictors
This patch allows coding frames using references of different
resolution, in ZEROMV mode. For compound prediction, either
reference may be scaled.
To test, I use the resize_test and enable WRITE_RECON_BUFFER
in vp9_onyxd_if.c. It's also useful to apply this patch to
test/i420_video_source.h:
--- a/test/i420_video_source.h
+++ b/test/i420_video_source.h
@@ -93,6 +93,7 @@ class I420VideoSource : public VideoSource {
virtual void FillFrame() {
// Read a frame from input_file.
+ if (frame_ != 3)
if (fread(img_->img_data, raw_sz_, 1, input_file_) == 0) {
limit_ = frame_;
}
This forces the frame that the resolution changes on to be coded
with no motion, only scaling, and improves the quality of the
result.
Change-Id: I1ee75d19a437ff801192f767fd02a36bcbd1d496
2013-02-25 05:55:14 +01:00
|
|
|
int mb_row,
|
|
|
|
int mb_col) {
|
2012-07-14 00:21:29 +02:00
|
|
|
MACROBLOCK *const x = &cpi->mb;
|
|
|
|
MACROBLOCKD *const xd = &x->e_mbd;
|
2012-10-31 22:40:53 +01:00
|
|
|
vp9_variance_fn_ptr_t v_fn_ptr = cpi->fn_ptr[BLOCK_16X16];
|
2013-02-28 22:18:02 +01:00
|
|
|
|
2013-05-08 23:12:37 +02:00
|
|
|
const int tmp_col_min = x->mv_col_min;
|
|
|
|
const int tmp_col_max = x->mv_col_max;
|
|
|
|
const int tmp_row_min = x->mv_row_min;
|
|
|
|
const int tmp_row_max = x->mv_row_max;
|
2014-01-13 20:21:07 +01:00
|
|
|
MV ref_full;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// Further step/diamond searches as necessary
|
2013-06-24 16:19:16 +02:00
|
|
|
int step_param = cpi->sf.reduce_first_step_size +
|
2014-04-17 03:31:42 +02:00
|
|
|
(cpi->oxcf.speed > 5 ? 1 : 0);
|
|
|
|
step_param = MIN(step_param, cpi->sf.max_step_search_steps - 2);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2014-01-03 20:48:07 +01:00
|
|
|
vp9_set_mv_search_range(x, ref_mv);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2014-01-13 20:21:07 +01:00
|
|
|
ref_full.col = ref_mv->col >> 3;
|
|
|
|
ref_full.row = ref_mv->row >> 3;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
/*cpi->sf.search_method == HEX*/
|
2014-02-13 15:43:44 +01:00
|
|
|
vp9_hex_search(x, &ref_full, step_param, x->errorperbit, 0, &v_fn_ptr, 0,
|
|
|
|
ref_mv, dst_mv);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// Try sub-pixel MC
|
|
|
|
// if (bestsme > error_thresh && bestsme < INT_MAX)
|
|
|
|
{
|
|
|
|
int distortion;
|
|
|
|
unsigned int sse;
|
2014-02-13 15:43:44 +01:00
|
|
|
cpi->find_fractional_mv_step(
|
|
|
|
x, dst_mv, ref_mv, cpi->common.allow_high_precision_mv, x->errorperbit,
|
|
|
|
&v_fn_ptr, 0, cpi->sf.subpel_iters_per_step, NULL, NULL, &distortion,
|
|
|
|
&sse);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2011-10-05 12:26:00 +02:00
|
|
|
|
2014-04-02 01:18:47 +02:00
|
|
|
xd->mi[0]->mbmi.mode = NEWMV;
|
|
|
|
xd->mi[0]->mbmi.mv[0].as_mv = *dst_mv;
|
2014-03-05 20:22:09 +01:00
|
|
|
|
2013-08-02 20:45:21 +02:00
|
|
|
vp9_build_inter_predictors_sby(xd, mb_row, mb_col, BLOCK_16X16);
|
2011-10-05 12:26:00 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
/* restore UMV window */
|
|
|
|
x->mv_col_min = tmp_col_min;
|
|
|
|
x->mv_col_max = tmp_col_max;
|
|
|
|
x->mv_row_min = tmp_row_min;
|
|
|
|
x->mv_row_max = tmp_row_max;
|
2011-11-28 21:39:38 +01:00
|
|
|
|
2014-02-13 15:43:44 +01:00
|
|
|
return vp9_sad16x16(x->plane[0].src.buf, x->plane[0].src.stride,
|
|
|
|
xd->plane[0].dst.buf, xd->plane[0].dst.stride,
|
|
|
|
INT_MAX);
|
2011-10-05 12:26:00 +02:00
|
|
|
}
|
|
|
|
|
2014-04-14 20:42:56 +02:00
|
|
|
static int do_16x16_motion_search(VP9_COMP *cpi, const MV *ref_mv,
|
2014-01-03 20:48:07 +01:00
|
|
|
int_mv *dst_mv, int mb_row, int mb_col) {
|
2013-05-08 23:12:37 +02:00
|
|
|
MACROBLOCK *const x = &cpi->mb;
|
2012-07-14 00:21:29 +02:00
|
|
|
MACROBLOCKD *const xd = &x->e_mbd;
|
|
|
|
unsigned int err, tmp_err;
|
2014-04-14 20:42:56 +02:00
|
|
|
MV tmp_mv;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// Try zero MV first
|
|
|
|
// FIXME should really use something like near/nearest MV and/or MV prediction
|
2013-04-24 01:22:47 +02:00
|
|
|
err = vp9_sad16x16(x->plane[0].src.buf, x->plane[0].src.stride,
|
2013-04-20 04:16:14 +02:00
|
|
|
xd->plane[0].pre[0].buf, xd->plane[0].pre[0].stride,
|
|
|
|
INT_MAX);
|
2012-07-14 00:21:29 +02:00
|
|
|
dst_mv->as_int = 0;
|
|
|
|
|
|
|
|
// Test last reference frame using the previous best mv as the
|
|
|
|
// starting point (best reference) for the search
|
2014-04-14 20:42:56 +02:00
|
|
|
tmp_err = do_16x16_motion_iteration(cpi, ref_mv, &tmp_mv, mb_row, mb_col);
|
2012-07-14 00:21:29 +02:00
|
|
|
if (tmp_err < err) {
|
2013-05-08 23:12:37 +02:00
|
|
|
err = tmp_err;
|
2014-04-14 20:42:56 +02:00
|
|
|
dst_mv->as_mv = tmp_mv;
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
|
2013-10-04 20:22:22 +02:00
|
|
|
// If the current best reference mv is not centered on 0,0 then do a 0,0
|
|
|
|
// based search as well.
|
2014-04-14 20:42:56 +02:00
|
|
|
if (ref_mv->row != 0 || ref_mv->col != 0) {
|
2012-11-05 23:22:59 +01:00
|
|
|
unsigned int tmp_err;
|
2014-04-14 20:42:56 +02:00
|
|
|
MV zero_ref_mv = {0, 0}, tmp_mv;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
2014-04-14 20:42:56 +02:00
|
|
|
tmp_err = do_16x16_motion_iteration(cpi, &zero_ref_mv, &tmp_mv,
|
Spatial resamping of ZEROMV predictors
This patch allows coding frames using references of different
resolution, in ZEROMV mode. For compound prediction, either
reference may be scaled.
To test, I use the resize_test and enable WRITE_RECON_BUFFER
in vp9_onyxd_if.c. It's also useful to apply this patch to
test/i420_video_source.h:
--- a/test/i420_video_source.h
+++ b/test/i420_video_source.h
@@ -93,6 +93,7 @@ class I420VideoSource : public VideoSource {
virtual void FillFrame() {
// Read a frame from input_file.
+ if (frame_ != 3)
if (fread(img_->img_data, raw_sz_, 1, input_file_) == 0) {
limit_ = frame_;
}
This forces the frame that the resolution changes on to be coded
with no motion, only scaling, and improves the quality of the
result.
Change-Id: I1ee75d19a437ff801192f767fd02a36bcbd1d496
2013-02-25 05:55:14 +01:00
|
|
|
mb_row, mb_col);
|
2012-07-14 00:21:29 +02:00
|
|
|
if (tmp_err < err) {
|
2014-04-14 20:42:56 +02:00
|
|
|
dst_mv->as_mv = tmp_mv;
|
2012-07-14 00:21:29 +02:00
|
|
|
err = tmp_err;
|
2011-10-05 12:26:00 +02:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2011-10-05 12:26:00 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
return err;
|
2011-10-05 12:26:00 +02:00
|
|
|
}
|
|
|
|
|
2013-08-01 01:59:15 +02:00
|
|
|
static int do_16x16_zerozero_search(VP9_COMP *cpi, int_mv *dst_mv) {
|
2013-05-08 23:12:37 +02:00
|
|
|
MACROBLOCK *const x = &cpi->mb;
|
2012-07-14 00:21:29 +02:00
|
|
|
MACROBLOCKD *const xd = &x->e_mbd;
|
|
|
|
unsigned int err;
|
|
|
|
|
|
|
|
// Try zero MV first
|
|
|
|
// FIXME should really use something like near/nearest MV and/or MV prediction
|
2013-04-24 01:22:47 +02:00
|
|
|
err = vp9_sad16x16(x->plane[0].src.buf, x->plane[0].src.stride,
|
2013-04-20 04:16:14 +02:00
|
|
|
xd->plane[0].pre[0].buf, xd->plane[0].pre[0].stride,
|
|
|
|
INT_MAX);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
dst_mv->as_int = 0;
|
|
|
|
|
|
|
|
return err;
|
2011-10-07 17:58:28 +02:00
|
|
|
}
|
2014-04-12 00:26:24 +02:00
|
|
|
static int find_best_16x16_intra(VP9_COMP *cpi, PREDICTION_MODE *pbest_mode) {
|
2012-07-14 00:21:29 +02:00
|
|
|
MACROBLOCK *const x = &cpi->mb;
|
|
|
|
MACROBLOCKD *const xd = &x->e_mbd;
|
2014-04-12 00:26:24 +02:00
|
|
|
PREDICTION_MODE best_mode = -1, mode;
|
2012-11-05 23:22:59 +01:00
|
|
|
unsigned int best_err = INT_MAX;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// calculate SATD for each intra prediction mode;
|
|
|
|
// we're intentionally not doing 4x4, we just want a rough estimate
|
|
|
|
for (mode = DC_PRED; mode <= TM_PRED; mode++) {
|
|
|
|
unsigned int err;
|
|
|
|
|
2014-04-02 01:18:47 +02:00
|
|
|
xd->mi[0]->mbmi.mode = mode;
|
2013-07-09 02:25:51 +02:00
|
|
|
vp9_predict_intra_block(xd, 0, 2, TX_16X16, mode,
|
|
|
|
x->plane[0].src.buf, x->plane[0].src.stride,
|
2013-12-13 05:33:06 +01:00
|
|
|
xd->plane[0].dst.buf, xd->plane[0].dst.stride,
|
|
|
|
0, 0, 0);
|
2013-04-24 01:22:47 +02:00
|
|
|
err = vp9_sad16x16(x->plane[0].src.buf, x->plane[0].src.stride,
|
2013-04-20 00:52:17 +02:00
|
|
|
xd->plane[0].dst.buf, xd->plane[0].dst.stride, best_err);
|
2013-04-15 18:31:27 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// find best
|
|
|
|
if (err < best_err) {
|
|
|
|
best_err = err;
|
|
|
|
best_mode = mode;
|
2011-10-05 12:26:00 +02:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2011-10-05 12:26:00 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (pbest_mode)
|
|
|
|
*pbest_mode = best_mode;
|
2011-10-05 12:26:00 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
return best_err;
|
2011-10-05 12:26:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void update_mbgraph_mb_stats
|
|
|
|
(
|
2012-10-31 01:53:32 +01:00
|
|
|
VP9_COMP *cpi,
|
2012-07-14 00:21:29 +02:00
|
|
|
MBGRAPH_MB_STATS *stats,
|
|
|
|
YV12_BUFFER_CONFIG *buf,
|
|
|
|
int mb_y_offset,
|
|
|
|
YV12_BUFFER_CONFIG *golden_ref,
|
2014-04-14 20:42:56 +02:00
|
|
|
const MV *prev_golden_ref_mv,
|
2012-07-14 00:21:29 +02:00
|
|
|
YV12_BUFFER_CONFIG *alt_ref,
|
Spatial resamping of ZEROMV predictors
This patch allows coding frames using references of different
resolution, in ZEROMV mode. For compound prediction, either
reference may be scaled.
To test, I use the resize_test and enable WRITE_RECON_BUFFER
in vp9_onyxd_if.c. It's also useful to apply this patch to
test/i420_video_source.h:
--- a/test/i420_video_source.h
+++ b/test/i420_video_source.h
@@ -93,6 +93,7 @@ class I420VideoSource : public VideoSource {
virtual void FillFrame() {
// Read a frame from input_file.
+ if (frame_ != 3)
if (fread(img_->img_data, raw_sz_, 1, input_file_) == 0) {
limit_ = frame_;
}
This forces the frame that the resolution changes on to be coded
with no motion, only scaling, and improves the quality of the
result.
Change-Id: I1ee75d19a437ff801192f767fd02a36bcbd1d496
2013-02-25 05:55:14 +01:00
|
|
|
int mb_row,
|
|
|
|
int mb_col
|
2012-07-14 00:21:29 +02:00
|
|
|
) {
|
2013-05-08 23:12:37 +02:00
|
|
|
MACROBLOCK *const x = &cpi->mb;
|
2012-07-14 00:21:29 +02:00
|
|
|
MACROBLOCKD *const xd = &x->e_mbd;
|
|
|
|
int intra_error;
|
2013-04-15 18:31:27 +02:00
|
|
|
VP9_COMMON *cm = &cpi->common;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// FIXME in practice we're completely ignoring chroma here
|
2013-04-24 01:22:47 +02:00
|
|
|
x->plane[0].src.buf = buf->y_buffer + mb_y_offset;
|
|
|
|
x->plane[0].src.stride = buf->y_stride;
|
2013-04-15 18:31:27 +02:00
|
|
|
|
2013-10-24 21:20:35 +02:00
|
|
|
xd->plane[0].dst.buf = get_frame_new_buffer(cm)->y_buffer + mb_y_offset;
|
|
|
|
xd->plane[0].dst.stride = get_frame_new_buffer(cm)->y_stride;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// do intra 16x16 prediction
|
2014-03-03 05:48:54 +01:00
|
|
|
intra_error = find_best_16x16_intra(cpi,
|
2013-04-15 18:31:27 +02:00
|
|
|
&stats->ref[INTRA_FRAME].m.mode);
|
2012-07-14 00:21:29 +02:00
|
|
|
if (intra_error <= 0)
|
|
|
|
intra_error = 1;
|
|
|
|
stats->ref[INTRA_FRAME].err = intra_error;
|
|
|
|
|
|
|
|
// Golden frame MV search, if it exists and is different than last frame
|
|
|
|
if (golden_ref) {
|
2013-04-15 18:31:27 +02:00
|
|
|
int g_motion_error;
|
2013-04-20 04:16:14 +02:00
|
|
|
xd->plane[0].pre[0].buf = golden_ref->y_buffer + mb_y_offset;
|
|
|
|
xd->plane[0].pre[0].stride = golden_ref->y_stride;
|
2013-05-08 23:12:37 +02:00
|
|
|
g_motion_error = do_16x16_motion_search(cpi,
|
|
|
|
prev_golden_ref_mv,
|
2013-04-15 18:31:27 +02:00
|
|
|
&stats->ref[GOLDEN_FRAME].m.mv,
|
|
|
|
mb_row, mb_col);
|
2012-07-14 00:21:29 +02:00
|
|
|
stats->ref[GOLDEN_FRAME].err = g_motion_error;
|
|
|
|
} else {
|
|
|
|
stats->ref[GOLDEN_FRAME].err = INT_MAX;
|
|
|
|
stats->ref[GOLDEN_FRAME].m.mv.as_int = 0;
|
|
|
|
}
|
|
|
|
|
2013-10-04 20:22:22 +02:00
|
|
|
// Do an Alt-ref frame MV search, if it exists and is different than
|
|
|
|
// last/golden frame.
|
2012-07-14 00:21:29 +02:00
|
|
|
if (alt_ref) {
|
2013-04-15 18:31:27 +02:00
|
|
|
int a_motion_error;
|
2013-04-20 04:16:14 +02:00
|
|
|
xd->plane[0].pre[0].buf = alt_ref->y_buffer + mb_y_offset;
|
|
|
|
xd->plane[0].pre[0].stride = alt_ref->y_stride;
|
2013-04-15 18:31:27 +02:00
|
|
|
a_motion_error = do_16x16_zerozero_search(cpi,
|
2013-08-01 01:59:15 +02:00
|
|
|
&stats->ref[ALTREF_FRAME].m.mv);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
stats->ref[ALTREF_FRAME].err = a_motion_error;
|
|
|
|
} else {
|
|
|
|
stats->ref[ALTREF_FRAME].err = INT_MAX;
|
|
|
|
stats->ref[ALTREF_FRAME].m.mv.as_int = 0;
|
|
|
|
}
|
2011-10-05 12:26:00 +02:00
|
|
|
}
|
|
|
|
|
2013-05-08 23:12:37 +02:00
|
|
|
static void update_mbgraph_frame_stats(VP9_COMP *cpi,
|
|
|
|
MBGRAPH_FRAME_STATS *stats,
|
|
|
|
YV12_BUFFER_CONFIG *buf,
|
|
|
|
YV12_BUFFER_CONFIG *golden_ref,
|
|
|
|
YV12_BUFFER_CONFIG *alt_ref) {
|
|
|
|
MACROBLOCK *const x = &cpi->mb;
|
2012-07-14 00:21:29 +02:00
|
|
|
MACROBLOCKD *const xd = &x->e_mbd;
|
2013-05-08 23:12:37 +02:00
|
|
|
VP9_COMMON *const cm = &cpi->common;
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
int mb_col, mb_row, offset = 0;
|
|
|
|
int mb_y_offset = 0, arf_y_offset = 0, gld_y_offset = 0;
|
2014-04-14 20:42:56 +02:00
|
|
|
MV arf_top_mv = {0, 0}, gld_top_mv = {0, 0};
|
2013-08-15 20:37:56 +02:00
|
|
|
MODE_INFO mi_local = { { 0 } };
|
2013-02-09 02:49:44 +01:00
|
|
|
|
2013-10-04 20:22:22 +02:00
|
|
|
// Set up limit values for motion vectors to prevent them extending outside
|
|
|
|
// the UMV borders.
|
2013-09-24 22:47:29 +02:00
|
|
|
x->mv_row_min = -BORDER_MV_PIXELS_B16;
|
|
|
|
x->mv_row_max = (cm->mb_rows - 1) * 8 + BORDER_MV_PIXELS_B16;
|
2012-07-14 00:21:29 +02:00
|
|
|
xd->up_available = 0;
|
2013-04-20 00:52:17 +02:00
|
|
|
xd->plane[0].dst.stride = buf->y_stride;
|
2013-04-20 04:16:14 +02:00
|
|
|
xd->plane[0].pre[0].stride = buf->y_stride;
|
2013-04-20 00:52:17 +02:00
|
|
|
xd->plane[1].dst.stride = buf->uv_stride;
|
2014-04-02 01:18:47 +02:00
|
|
|
xd->mi[0] = &mi_local;
|
2013-08-02 20:45:21 +02:00
|
|
|
mi_local.mbmi.sb_type = BLOCK_16X16;
|
2013-06-07 19:20:03 +02:00
|
|
|
mi_local.mbmi.ref_frame[0] = LAST_FRAME;
|
|
|
|
mi_local.mbmi.ref_frame[1] = NONE;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
for (mb_row = 0; mb_row < cm->mb_rows; mb_row++) {
|
2014-04-14 20:42:56 +02:00
|
|
|
MV arf_left_mv = arf_top_mv, gld_left_mv = gld_top_mv;
|
2012-07-14 00:21:29 +02:00
|
|
|
int mb_y_in_offset = mb_y_offset;
|
|
|
|
int arf_y_in_offset = arf_y_offset;
|
|
|
|
int gld_y_in_offset = gld_y_offset;
|
2011-10-05 12:26:00 +02:00
|
|
|
|
2013-10-04 20:22:22 +02:00
|
|
|
// Set up limit values for motion vectors to prevent them extending outside
|
|
|
|
// the UMV borders.
|
2013-09-24 22:47:29 +02:00
|
|
|
x->mv_col_min = -BORDER_MV_PIXELS_B16;
|
|
|
|
x->mv_col_max = (cm->mb_cols - 1) * 8 + BORDER_MV_PIXELS_B16;
|
2012-07-14 00:21:29 +02:00
|
|
|
xd->left_available = 0;
|
|
|
|
|
|
|
|
for (mb_col = 0; mb_col < cm->mb_cols; mb_col++) {
|
|
|
|
MBGRAPH_MB_STATS *mb_stats = &stats->mb_stats[offset + mb_col];
|
|
|
|
|
|
|
|
update_mbgraph_mb_stats(cpi, mb_stats, buf, mb_y_in_offset,
|
2014-03-03 05:48:54 +01:00
|
|
|
golden_ref, &gld_left_mv, alt_ref,
|
Spatial resamping of ZEROMV predictors
This patch allows coding frames using references of different
resolution, in ZEROMV mode. For compound prediction, either
reference may be scaled.
To test, I use the resize_test and enable WRITE_RECON_BUFFER
in vp9_onyxd_if.c. It's also useful to apply this patch to
test/i420_video_source.h:
--- a/test/i420_video_source.h
+++ b/test/i420_video_source.h
@@ -93,6 +93,7 @@ class I420VideoSource : public VideoSource {
virtual void FillFrame() {
// Read a frame from input_file.
+ if (frame_ != 3)
if (fread(img_->img_data, raw_sz_, 1, input_file_) == 0) {
limit_ = frame_;
}
This forces the frame that the resolution changes on to be coded
with no motion, only scaling, and improves the quality of the
result.
Change-Id: I1ee75d19a437ff801192f767fd02a36bcbd1d496
2013-02-25 05:55:14 +01:00
|
|
|
mb_row, mb_col);
|
2014-04-14 20:42:56 +02:00
|
|
|
arf_left_mv = mb_stats->ref[ALTREF_FRAME].m.mv.as_mv;
|
|
|
|
gld_left_mv = mb_stats->ref[GOLDEN_FRAME].m.mv.as_mv;
|
2012-07-14 00:21:29 +02:00
|
|
|
if (mb_col == 0) {
|
2014-04-14 20:42:56 +02:00
|
|
|
arf_top_mv = arf_left_mv;
|
|
|
|
gld_top_mv = gld_left_mv;
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
xd->left_available = 1;
|
|
|
|
mb_y_in_offset += 16;
|
|
|
|
gld_y_in_offset += 16;
|
|
|
|
arf_y_in_offset += 16;
|
|
|
|
x->mv_col_min -= 16;
|
|
|
|
x->mv_col_max -= 16;
|
2011-10-05 12:26:00 +02:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
xd->up_available = 1;
|
|
|
|
mb_y_offset += buf->y_stride * 16;
|
|
|
|
gld_y_offset += golden_ref->y_stride * 16;
|
|
|
|
if (alt_ref)
|
|
|
|
arf_y_offset += alt_ref->y_stride * 16;
|
|
|
|
x->mv_row_min -= 16;
|
|
|
|
x->mv_row_max -= 16;
|
|
|
|
offset += cm->mb_cols;
|
|
|
|
}
|
2011-10-05 12:26:00 +02:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// void separate_arf_mbs_byzz
|
2012-10-31 01:53:32 +01:00
|
|
|
static void separate_arf_mbs(VP9_COMP *cpi) {
|
|
|
|
VP9_COMMON *const cm = &cpi->common;
|
2012-07-14 00:21:29 +02:00
|
|
|
int mb_col, mb_row, offset, i;
|
2013-10-10 20:03:36 +02:00
|
|
|
int mi_row, mi_col;
|
2013-08-15 20:37:56 +02:00
|
|
|
int ncnt[4] = { 0 };
|
2012-07-14 00:21:29 +02:00
|
|
|
int n_frames = cpi->mbgraph_n_frames;
|
|
|
|
|
|
|
|
int *arf_not_zz;
|
|
|
|
|
2013-06-28 19:36:20 +02:00
|
|
|
CHECK_MEM_ERROR(cm, arf_not_zz,
|
|
|
|
vpx_calloc(cm->mb_rows * cm->mb_cols * sizeof(*arf_not_zz),
|
|
|
|
1));
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// We are not interested in results beyond the alt ref itself.
|
2013-11-06 22:13:59 +01:00
|
|
|
if (n_frames > cpi->rc.frames_till_gf_update_due)
|
|
|
|
n_frames = cpi->rc.frames_till_gf_update_due;
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// defer cost to reference frames
|
|
|
|
for (i = n_frames - 1; i >= 0; i--) {
|
|
|
|
MBGRAPH_FRAME_STATS *frame_stats = &cpi->mbgraph_stats[i];
|
2011-10-05 12:26:00 +02:00
|
|
|
|
|
|
|
for (offset = 0, mb_row = 0; mb_row < cm->mb_rows;
|
2012-07-14 00:21:29 +02:00
|
|
|
offset += cm->mb_cols, mb_row++) {
|
|
|
|
for (mb_col = 0; mb_col < cm->mb_cols; mb_col++) {
|
2013-05-08 23:12:37 +02:00
|
|
|
MBGRAPH_MB_STATS *mb_stats = &frame_stats->mb_stats[offset + mb_col];
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
int altref_err = mb_stats->ref[ALTREF_FRAME].err;
|
|
|
|
int intra_err = mb_stats->ref[INTRA_FRAME ].err;
|
|
|
|
int golden_err = mb_stats->ref[GOLDEN_FRAME].err;
|
|
|
|
|
|
|
|
// Test for altref vs intra and gf and that its mv was 0,0.
|
2013-05-08 23:12:37 +02:00
|
|
|
if (altref_err > 1000 ||
|
|
|
|
altref_err > intra_err ||
|
|
|
|
altref_err > golden_err) {
|
2012-07-14 00:21:29 +02:00
|
|
|
arf_not_zz[offset + mb_col]++;
|
2011-10-05 12:26:00 +02:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2011-10-05 12:26:00 +02:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
|
2013-10-10 20:03:36 +02:00
|
|
|
// arf_not_zz is indexed by MB, but this loop is indexed by MI to avoid out
|
|
|
|
// of bound access in segmentation_map
|
|
|
|
for (mi_row = 0; mi_row < cm->mi_rows; mi_row++) {
|
|
|
|
for (mi_col = 0; mi_col < cm->mi_cols; mi_col++) {
|
2012-07-14 00:21:29 +02:00
|
|
|
// If any of the blocks in the sequence failed then the MB
|
|
|
|
// goes in segment 0
|
2014-02-13 15:43:44 +01:00
|
|
|
if (arf_not_zz[mi_row / 2 * cm->mb_cols + mi_col / 2]) {
|
2012-07-14 00:21:29 +02:00
|
|
|
ncnt[0]++;
|
2013-10-10 20:03:36 +02:00
|
|
|
cpi->segmentation_map[mi_row * cm->mi_cols + mi_col] = 0;
|
2013-04-26 20:57:17 +02:00
|
|
|
} else {
|
2013-10-10 20:03:36 +02:00
|
|
|
cpi->segmentation_map[mi_row * cm->mi_cols + mi_col] = 1;
|
2013-04-26 20:57:17 +02:00
|
|
|
ncnt[1]++;
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2011-10-05 12:26:00 +02:00
|
|
|
}
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Only bother with segmentation if over 10% of the MBs in static segment
|
|
|
|
// if ( ncnt[1] && (ncnt[0] / ncnt[1] < 10) )
|
|
|
|
if (1) {
|
|
|
|
// Note % of blocks that are marked as static
|
|
|
|
if (cm->MBs)
|
2013-10-10 20:03:36 +02:00
|
|
|
cpi->static_mb_pct = (ncnt[1] * 100) / (cm->mi_rows * cm->mi_cols);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// This error case should not be reachable as this function should
|
2013-03-06 21:02:15 +01:00
|
|
|
// never be called with the common data structure uninitialized.
|
2011-10-05 12:26:00 +02:00
|
|
|
else
|
2012-07-14 00:21:29 +02:00
|
|
|
cpi->static_mb_pct = 0;
|
|
|
|
|
2014-02-28 20:59:50 +01:00
|
|
|
vp9_enable_segmentation(&cm->seg);
|
2012-07-14 00:21:29 +02:00
|
|
|
} else {
|
|
|
|
cpi->static_mb_pct = 0;
|
2014-02-28 20:59:50 +01:00
|
|
|
vp9_disable_segmentation(&cm->seg);
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
2011-10-05 12:26:00 +02:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
// Free localy allocated storage
|
|
|
|
vpx_free(arf_not_zz);
|
2011-10-05 12:26:00 +02:00
|
|
|
}
|
|
|
|
|
2013-02-28 22:18:02 +01:00
|
|
|
void vp9_update_mbgraph_stats(VP9_COMP *cpi) {
|
2012-10-31 01:53:32 +01:00
|
|
|
VP9_COMMON *const cm = &cpi->common;
|
2012-10-30 20:58:42 +01:00
|
|
|
int i, n_frames = vp9_lookahead_depth(cpi->lookahead);
|
2014-01-06 23:50:54 +01:00
|
|
|
YV12_BUFFER_CONFIG *golden_ref = get_ref_frame_buffer(cpi, GOLDEN_FRAME);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
// we need to look ahead beyond where the ARF transitions into
|
|
|
|
// being a GF - so exit if we don't look ahead beyond that
|
2013-11-06 22:13:59 +01:00
|
|
|
if (n_frames <= cpi->rc.frames_till_gf_update_due)
|
2012-07-14 00:21:29 +02:00
|
|
|
return;
|
2013-12-13 18:32:05 +01:00
|
|
|
|
2012-07-14 00:21:29 +02:00
|
|
|
if (n_frames > MAX_LAG_BUFFERS)
|
|
|
|
n_frames = MAX_LAG_BUFFERS;
|
|
|
|
|
|
|
|
cpi->mbgraph_n_frames = n_frames;
|
|
|
|
for (i = 0; i < n_frames; i++) {
|
|
|
|
MBGRAPH_FRAME_STATS *frame_stats = &cpi->mbgraph_stats[i];
|
|
|
|
vpx_memset(frame_stats->mb_stats, 0,
|
2013-10-04 20:22:22 +02:00
|
|
|
cm->mb_rows * cm->mb_cols *
|
|
|
|
sizeof(*cpi->mbgraph_stats[i].mb_stats));
|
2012-07-14 00:21:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// do motion search to find contribution of each reference to data
|
|
|
|
// later on in this GF group
|
|
|
|
// FIXME really, the GF/last MC search should be done forward, and
|
|
|
|
// the ARF MC search backwards, to get optimal results for MV caching
|
|
|
|
for (i = 0; i < n_frames; i++) {
|
|
|
|
MBGRAPH_FRAME_STATS *frame_stats = &cpi->mbgraph_stats[i];
|
2013-05-08 23:12:37 +02:00
|
|
|
struct lookahead_entry *q_cur = vp9_lookahead_peek(cpi->lookahead, i);
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
assert(q_cur != NULL);
|
|
|
|
|
|
|
|
update_mbgraph_frame_stats(cpi, frame_stats, &q_cur->img,
|
|
|
|
golden_ref, cpi->Source);
|
|
|
|
}
|
|
|
|
|
2014-02-14 00:49:21 +01:00
|
|
|
vp9_clear_system_state();
|
2012-07-14 00:21:29 +02:00
|
|
|
|
|
|
|
separate_arf_mbs(cpi);
|
2011-10-05 12:26:00 +02:00
|
|
|
}
|