1 /*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3 *
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.
10 */
11
12 #ifndef AOM_AV1_ENCODER_ENCODEMV_H_
13 #define AOM_AV1_ENCODER_ENCODEMV_H_
14
15 #include "av1/encoder/encoder.h"
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 void av1_encode_mv(AV1_COMP *cpi, aom_writer *w, const MV *mv, const MV *ref,
22 nmv_context *mvctx, int usehp);
23
24 void av1_update_mv_stats(const MV *mv, const MV *ref, nmv_context *mvctx,
25 MvSubpelPrecision precision);
26
27 void av1_build_nmv_cost_table(int *mvjoint, int *mvcost[2],
28 const nmv_context *mvctx,
29 MvSubpelPrecision precision);
30
31 void av1_update_mv_count(ThreadData *td);
32
33 void av1_encode_dv(aom_writer *w, const MV *mv, const MV *ref,
34 nmv_context *mvctx);
35 int_mv av1_get_ref_mv(const MACROBLOCK *x, int ref_idx);
36 int_mv av1_get_ref_mv_from_stack(int ref_idx,
37 const MV_REFERENCE_FRAME *ref_frame,
38 int ref_mv_idx,
39 const MB_MODE_INFO_EXT *mbmi_ext);
40 void av1_find_best_ref_mvs_from_stack(int allow_hp,
41 const MB_MODE_INFO_EXT *mbmi_ext,
42 MV_REFERENCE_FRAME ref_frame,
43 int_mv *nearest_mv, int_mv *near_mv,
44 int is_integer);
45
av1_get_mv_joint(const MV * mv)46 static INLINE MV_JOINT_TYPE av1_get_mv_joint(const MV *mv) {
47 // row: Z col: Z | MV_JOINT_ZERO (0)
48 // row: Z col: NZ | MV_JOINT_HNZVZ (1)
49 // row: NZ col: Z | MV_JOINT_HZVNZ (2)
50 // row: NZ col: NZ | MV_JOINT_HNZVNZ (3)
51 return (!!mv->col) | ((!!mv->row) << 1);
52 }
53
av1_mv_class_base(MV_CLASS_TYPE c)54 static INLINE int av1_mv_class_base(MV_CLASS_TYPE c) {
55 return c ? CLASS0_SIZE << (c + 2) : 0;
56 }
57
58 // 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)59 static INLINE uint8_t av1_log_in_base_2(unsigned int n) {
60 // get_msb() is only valid when n != 0.
61 return n == 0 ? 0 : get_msb(n);
62 }
63
av1_get_mv_class(int z,int * offset)64 static INLINE MV_CLASS_TYPE av1_get_mv_class(int z, int *offset) {
65 const MV_CLASS_TYPE c = (z >= CLASS0_SIZE * 4096)
66 ? MV_CLASS_10
67 : (MV_CLASS_TYPE)av1_log_in_base_2(z >> 3);
68 if (offset) *offset = z - av1_mv_class_base(c);
69 return c;
70 }
71
72 #ifdef __cplusplus
73 } // extern "C"
74 #endif
75
76 #endif // AOM_AV1_ENCODER_ENCODEMV_H_
77