From d616a5cee46ea4439c2e3fd6dc8d9a872b96977f Mon Sep 17 00:00:00 2001 From: Sarah Parker Date: Mon, 8 Aug 2016 18:11:05 -0700 Subject: [PATCH] Add interface to compute gm parameters in encodeframe This patch just creates the interface for global motion computation and calls it from encodeframe. Currently, the function compute_global_motion_feature_based is empty and the work to do the actual parameter calculation will be added in a future patch. Change-Id: Ife142742140079e1c1743b66f180aeb2ecea29ae --- vp10/encoder/encodeframe.c | 43 ++++++++++++++++++++++++++++++++++-- vp10/encoder/global_motion.c | 34 ++++++++++++++++++++++++++++ vp10/encoder/global_motion.h | 30 +++++++++++++++++++++++++ vp10/vp10cx.mk | 2 ++ 4 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 vp10/encoder/global_motion.c create mode 100644 vp10/encoder/global_motion.h diff --git a/vp10/encoder/encodeframe.c b/vp10/encoder/encodeframe.c index 2e92f0d61..88200c863 100644 --- a/vp10/encoder/encodeframe.c +++ b/vp10/encoder/encodeframe.c @@ -39,6 +39,9 @@ #if CONFIG_SUPERTX #include "vp10/encoder/cost.h" #endif +#if CONFIG_GLOBAL_MOTION +#include "vp10/encoder/global_motion.h" +#endif #include "vp10/encoder/encodeframe.h" #include "vp10/encoder/encodemb.h" #include "vp10/encoder/encodemv.h" @@ -1084,6 +1087,17 @@ static void update_filter_type_count(FRAME_COUNTS *counts, } } #endif +#if CONFIG_GLOBAL_MOTION +static void update_global_motion_used(PREDICTION_MODE mode, + const MB_MODE_INFO *mbmi, + VP10_COMP *cpi) { + if (mode == ZEROMV) { + ++cpi->global_motion_used[mbmi->ref_frame[0]]; + if (has_second_ref(mbmi)) + ++cpi->global_motion_used[mbmi->ref_frame[1]]; + } +} +#endif // CONFIG_GLOBAL_MOTION static void update_state(VP10_COMP *cpi, ThreadData *td, PICK_MODE_CONTEXT *ctx, @@ -1231,6 +1245,21 @@ static void update_state(VP10_COMP *cpi, ThreadData *td, if (!frame_is_intra_only(cm)) { if (is_inter_block(mbmi)) { vp10_update_mv_count(td); +#if CONFIG_GLOBAL_MOTION + if (bsize >= BLOCK_8X8) { + update_global_motion_used(mbmi->mode, mbmi, cpi); + } else { + const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize]; + const int num_4x4_h = num_4x4_blocks_high_lookup[bsize]; + int idx, idy; + for (idy = 0; idy < 2; idy += num_4x4_h) { + for (idx = 0; idx < 2; idx += num_4x4_w) { + const int j = idy * 2 + idx; + update_global_motion_used(mi->bmi[j].as_mode, mbmi, cpi); + } + } + } +#endif // CONFIG_GLOBAL_MOTION if (cm->interp_filter == SWITCHABLE #if CONFIG_EXT_INTERP && vp10_is_interp_needed(xd) @@ -4538,6 +4567,7 @@ static int input_fpmb_stats(FIRSTPASS_MB_STATS *firstpass_mb_stats, #if CONFIG_GLOBAL_MOTION #define MIN_TRANS_THRESH 8 +#define GLOBAL_MOTION_MODEL ROTZOOM static void convert_to_params(double *H, TransformationType type, Global_Motion_Params *model) { int i; @@ -4610,10 +4640,19 @@ static void encode_frame_internal(VP10_COMP *cpi) { vpx_clear_system_state(); vp10_zero(cpi->global_motion_used); if (cpi->common.frame_type == INTER_FRAME && cpi->Source) { + YV12_BUFFER_CONFIG *ref_buf; int frame; double H[9] = {0, 0, 0, 0, 0, 0, 0, 0, 1}; - for (frame = LAST_FRAME; frame <= ALTREF_FRAME; ++frame) - convert_model_to_params(H, AFFINE, &cm->global_motion[frame]); + for (frame = LAST_FRAME; frame <= ALTREF_FRAME; ++frame) { + ref_buf = get_ref_frame_buffer(cpi, frame); + if (ref_buf) { + if (compute_global_motion_feature_based( + cpi, GLOBAL_MOTION_MODEL, cpi->Source, ref_buf, + 0.5, H)) + convert_model_to_params(H, GLOBAL_MOTION_MODEL, + &cm->global_motion[frame]); + } + } } #endif // CONFIG_GLOBAL_MOTION diff --git a/vp10/encoder/global_motion.c b/vp10/encoder/global_motion.c new file mode 100644 index 000000000..387a40b7e --- /dev/null +++ b/vp10/encoder/global_motion.c @@ -0,0 +1,34 @@ +/* + * 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 +#include +#include +#include +#include + +#include "vp10/common/warped_motion.h" + +#include "vp10/encoder/segmentation.h" +#include "vp10/encoder/global_motion.h" + +int compute_global_motion_feature_based(struct VP10_COMP *cpi, + TransformationType type, + YV12_BUFFER_CONFIG *frm, + YV12_BUFFER_CONFIG *ref, + double inlier_prob, double *H) { + (void) cpi; + (void) type; + (void) frm; + (void) ref; + (void) inlier_prob; + (void) H; + return 0; +} diff --git a/vp10/encoder/global_motion.h b/vp10/encoder/global_motion.h new file mode 100644 index 000000000..35deb1361 --- /dev/null +++ b/vp10/encoder/global_motion.h @@ -0,0 +1,30 @@ +/* + * 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. + */ + + +#ifndef VP10_ENCODER_GLOBAL_MOTION_H_ +#define VP10_ENCODER_GLOBAL_MOTION_H_ + +#include "vpx/vpx_integer.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int compute_global_motion_feature_based(struct VP10_COMP *cpi, + TransformationType type, + YV12_BUFFER_CONFIG *frm, + YV12_BUFFER_CONFIG *ref, + double inlier_prob, double *H); +#ifdef __cplusplus +} // extern "C" +#endif +#endif // VP10_ENCODER_GLOBAL_MOTION_H_ + diff --git a/vp10/vp10cx.mk b/vp10/vp10cx.mk index 735ec5b6c..3a6d1040c 100644 --- a/vp10/vp10cx.mk +++ b/vp10/vp10cx.mk @@ -36,6 +36,8 @@ VP10_CX_SRCS-yes += encoder/ethread.h VP10_CX_SRCS-yes += encoder/ethread.c VP10_CX_SRCS-yes += encoder/extend.c VP10_CX_SRCS-yes += encoder/firstpass.c +VP10_CX_SRCS-$(CONFIG_GLOBAL_MOTION) += encoder/global_motion.c +VP10_CX_SRCS-$(CONFIG_GLOBAL_MOTION) += encoder/global_motion.h VP10_CX_SRCS-yes += encoder/block.h VP10_CX_SRCS-yes += encoder/bitstream.h VP10_CX_SRCS-yes += encoder/encodemb.h -- 2.50.1