1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker *
4*77c1e3ccSAndroid Build Coastguard Worker * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker */
11*77c1e3ccSAndroid Build Coastguard Worker
12*77c1e3ccSAndroid Build Coastguard Worker #ifndef AOM_AV1_ENCODER_ENCODEMV_H_
13*77c1e3ccSAndroid Build Coastguard Worker #define AOM_AV1_ENCODER_ENCODEMV_H_
14*77c1e3ccSAndroid Build Coastguard Worker
15*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/encoder.h"
16*77c1e3ccSAndroid Build Coastguard Worker
17*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
18*77c1e3ccSAndroid Build Coastguard Worker extern "C" {
19*77c1e3ccSAndroid Build Coastguard Worker #endif
20*77c1e3ccSAndroid Build Coastguard Worker
21*77c1e3ccSAndroid Build Coastguard Worker void av1_encode_mv(AV1_COMP *cpi, aom_writer *w, ThreadData *td, const MV *mv,
22*77c1e3ccSAndroid Build Coastguard Worker const MV *ref, nmv_context *mvctx, int usehp);
23*77c1e3ccSAndroid Build Coastguard Worker
24*77c1e3ccSAndroid Build Coastguard Worker void av1_update_mv_stats(const MV *mv, const MV *ref, nmv_context *mvctx,
25*77c1e3ccSAndroid Build Coastguard Worker MvSubpelPrecision precision);
26*77c1e3ccSAndroid Build Coastguard Worker
27*77c1e3ccSAndroid Build Coastguard Worker void av1_build_nmv_cost_table(int *mvjoint, int *mvcost[2],
28*77c1e3ccSAndroid Build Coastguard Worker const nmv_context *mvctx,
29*77c1e3ccSAndroid Build Coastguard Worker MvSubpelPrecision precision);
30*77c1e3ccSAndroid Build Coastguard Worker void av1_build_nmv_component_cost_table(int *mvcost,
31*77c1e3ccSAndroid Build Coastguard Worker const nmv_component *const mvcomp,
32*77c1e3ccSAndroid Build Coastguard Worker MvSubpelPrecision precision);
33*77c1e3ccSAndroid Build Coastguard Worker
34*77c1e3ccSAndroid Build Coastguard Worker void av1_update_mv_count(ThreadData *td);
35*77c1e3ccSAndroid Build Coastguard Worker
36*77c1e3ccSAndroid Build Coastguard Worker void av1_encode_dv(aom_writer *w, const MV *mv, const MV *ref,
37*77c1e3ccSAndroid Build Coastguard Worker nmv_context *mvctx);
38*77c1e3ccSAndroid Build Coastguard Worker int_mv av1_get_ref_mv(const MACROBLOCK *x, int ref_idx);
39*77c1e3ccSAndroid Build Coastguard Worker int_mv av1_get_ref_mv_from_stack(int ref_idx,
40*77c1e3ccSAndroid Build Coastguard Worker const MV_REFERENCE_FRAME *ref_frame,
41*77c1e3ccSAndroid Build Coastguard Worker int ref_mv_idx,
42*77c1e3ccSAndroid Build Coastguard Worker const MB_MODE_INFO_EXT *mbmi_ext);
43*77c1e3ccSAndroid Build Coastguard Worker void av1_find_best_ref_mvs_from_stack(int allow_hp,
44*77c1e3ccSAndroid Build Coastguard Worker const MB_MODE_INFO_EXT *mbmi_ext,
45*77c1e3ccSAndroid Build Coastguard Worker MV_REFERENCE_FRAME ref_frame,
46*77c1e3ccSAndroid Build Coastguard Worker int_mv *nearest_mv, int_mv *near_mv,
47*77c1e3ccSAndroid Build Coastguard Worker int is_integer);
48*77c1e3ccSAndroid Build Coastguard Worker
av1_get_mv_joint(const MV * mv)49*77c1e3ccSAndroid Build Coastguard Worker static inline MV_JOINT_TYPE av1_get_mv_joint(const MV *mv) {
50*77c1e3ccSAndroid Build Coastguard Worker // row: Z col: Z | MV_JOINT_ZERO (0)
51*77c1e3ccSAndroid Build Coastguard Worker // row: Z col: NZ | MV_JOINT_HNZVZ (1)
52*77c1e3ccSAndroid Build Coastguard Worker // row: NZ col: Z | MV_JOINT_HZVNZ (2)
53*77c1e3ccSAndroid Build Coastguard Worker // row: NZ col: NZ | MV_JOINT_HNZVNZ (3)
54*77c1e3ccSAndroid Build Coastguard Worker return (!!mv->col) | ((!!mv->row) << 1);
55*77c1e3ccSAndroid Build Coastguard Worker }
56*77c1e3ccSAndroid Build Coastguard Worker
av1_mv_class_base(MV_CLASS_TYPE c)57*77c1e3ccSAndroid Build Coastguard Worker static inline int av1_mv_class_base(MV_CLASS_TYPE c) {
58*77c1e3ccSAndroid Build Coastguard Worker return c ? CLASS0_SIZE << (c + 2) : 0;
59*77c1e3ccSAndroid Build Coastguard Worker }
60*77c1e3ccSAndroid Build Coastguard Worker
61*77c1e3ccSAndroid Build Coastguard Worker // If n != 0, returns the floor of log base 2 of n. If n == 0, returns 0.
av1_log_in_base_2(unsigned int n)62*77c1e3ccSAndroid Build Coastguard Worker static inline uint8_t av1_log_in_base_2(unsigned int n) {
63*77c1e3ccSAndroid Build Coastguard Worker // get_msb() is only valid when n != 0.
64*77c1e3ccSAndroid Build Coastguard Worker return n == 0 ? 0 : get_msb(n);
65*77c1e3ccSAndroid Build Coastguard Worker }
66*77c1e3ccSAndroid Build Coastguard Worker
av1_get_mv_class(int z,int * offset)67*77c1e3ccSAndroid Build Coastguard Worker static inline MV_CLASS_TYPE av1_get_mv_class(int z, int *offset) {
68*77c1e3ccSAndroid Build Coastguard Worker assert(z >= 0);
69*77c1e3ccSAndroid Build Coastguard Worker const MV_CLASS_TYPE c = (MV_CLASS_TYPE)av1_log_in_base_2(z >> 3);
70*77c1e3ccSAndroid Build Coastguard Worker assert(c <= MV_CLASS_10);
71*77c1e3ccSAndroid Build Coastguard Worker if (offset) *offset = z - av1_mv_class_base(c);
72*77c1e3ccSAndroid Build Coastguard Worker return c;
73*77c1e3ccSAndroid Build Coastguard Worker }
74*77c1e3ccSAndroid Build Coastguard Worker
av1_check_newmv_joint_nonzero(const AV1_COMMON * cm,MACROBLOCK * const x)75*77c1e3ccSAndroid Build Coastguard Worker static inline int av1_check_newmv_joint_nonzero(const AV1_COMMON *cm,
76*77c1e3ccSAndroid Build Coastguard Worker MACROBLOCK *const x) {
77*77c1e3ccSAndroid Build Coastguard Worker (void)cm;
78*77c1e3ccSAndroid Build Coastguard Worker MACROBLOCKD *xd = &x->e_mbd;
79*77c1e3ccSAndroid Build Coastguard Worker MB_MODE_INFO *mbmi = xd->mi[0];
80*77c1e3ccSAndroid Build Coastguard Worker const PREDICTION_MODE this_mode = mbmi->mode;
81*77c1e3ccSAndroid Build Coastguard Worker if (this_mode == NEW_NEWMV) {
82*77c1e3ccSAndroid Build Coastguard Worker const int_mv ref_mv_0 = av1_get_ref_mv(x, 0);
83*77c1e3ccSAndroid Build Coastguard Worker const int_mv ref_mv_1 = av1_get_ref_mv(x, 1);
84*77c1e3ccSAndroid Build Coastguard Worker if (mbmi->mv[0].as_int == ref_mv_0.as_int ||
85*77c1e3ccSAndroid Build Coastguard Worker mbmi->mv[1].as_int == ref_mv_1.as_int) {
86*77c1e3ccSAndroid Build Coastguard Worker return 0;
87*77c1e3ccSAndroid Build Coastguard Worker }
88*77c1e3ccSAndroid Build Coastguard Worker } else if (this_mode == NEAREST_NEWMV || this_mode == NEAR_NEWMV) {
89*77c1e3ccSAndroid Build Coastguard Worker const int_mv ref_mv_1 = av1_get_ref_mv(x, 1);
90*77c1e3ccSAndroid Build Coastguard Worker if (mbmi->mv[1].as_int == ref_mv_1.as_int) {
91*77c1e3ccSAndroid Build Coastguard Worker return 0;
92*77c1e3ccSAndroid Build Coastguard Worker }
93*77c1e3ccSAndroid Build Coastguard Worker } else if (this_mode == NEW_NEARESTMV || this_mode == NEW_NEARMV) {
94*77c1e3ccSAndroid Build Coastguard Worker const int_mv ref_mv_0 = av1_get_ref_mv(x, 0);
95*77c1e3ccSAndroid Build Coastguard Worker if (mbmi->mv[0].as_int == ref_mv_0.as_int) {
96*77c1e3ccSAndroid Build Coastguard Worker return 0;
97*77c1e3ccSAndroid Build Coastguard Worker }
98*77c1e3ccSAndroid Build Coastguard Worker } else if (this_mode == NEWMV) {
99*77c1e3ccSAndroid Build Coastguard Worker const int_mv ref_mv_0 = av1_get_ref_mv(x, 0);
100*77c1e3ccSAndroid Build Coastguard Worker if (mbmi->mv[0].as_int == ref_mv_0.as_int) {
101*77c1e3ccSAndroid Build Coastguard Worker return 0;
102*77c1e3ccSAndroid Build Coastguard Worker }
103*77c1e3ccSAndroid Build Coastguard Worker }
104*77c1e3ccSAndroid Build Coastguard Worker return 1;
105*77c1e3ccSAndroid Build Coastguard Worker }
106*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
107*77c1e3ccSAndroid Build Coastguard Worker } // extern "C"
108*77c1e3ccSAndroid Build Coastguard Worker #endif
109*77c1e3ccSAndroid Build Coastguard Worker
110*77c1e3ccSAndroid Build Coastguard Worker #endif // AOM_AV1_ENCODER_ENCODEMV_H_
111