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