xref: /aosp_15_r20/external/libaom/av1/encoder/mcomp_structs.h (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1 /*
2  * Copyright (c) 2022, 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_MCOMP_STRUCTS_H_
13 #define AOM_AV1_ENCODER_MCOMP_STRUCTS_H_
14 
15 #include "av1/common/mv.h"
16 
17 // The maximum number of steps in a step search given the largest
18 // allowed initial step
19 #define MAX_MVSEARCH_STEPS 11
20 // Max full pel mv specified in the unit of full pixel
21 // Enable the use of motion vector in range [-1023, 1023].
22 #define MAX_FULL_PEL_VAL ((1 << (MAX_MVSEARCH_STEPS - 1)) - 1)
23 // Maximum size of the first step in full pel units
24 #define MAX_FIRST_STEP (1 << (MAX_MVSEARCH_STEPS - 1))
25 // Maximum number of neighbors to scan per iteration during
26 // WARPED_CAUSAL refinement
27 // Note: The elements of warp_search_config.neighbor_mask must be at least
28 // MAX_WARP_SEARCH_NEIGHBORS many bits wide. So the type may need to be
29 // widened if this value is increased.
30 #define MAX_WARP_SEARCH_NEIGHBORS 8
31 
32 #define SEARCH_RANGE_8P 3
33 #define SEARCH_GRID_STRIDE_8P (2 * SEARCH_RANGE_8P + 1)
34 #define SEARCH_GRID_CENTER_8P \
35   (SEARCH_RANGE_8P * SEARCH_GRID_STRIDE_8P + SEARCH_RANGE_8P)
36 
37 typedef struct {
38   FULLPEL_MV coord;
39   int coord_offset;
40 } search_neighbors;
41 // motion search site
42 typedef struct search_site {
43   FULLPEL_MV mv;
44   int offset;
45 } search_site;
46 
47 typedef struct search_site_config {
48   search_site site[MAX_MVSEARCH_STEPS * 2][16 + 1];
49   // Number of search steps.
50   int num_search_steps;
51   int searches_per_step[MAX_MVSEARCH_STEPS * 2];
52   int radius[MAX_MVSEARCH_STEPS * 2];
53   int stride;
54 } search_site_config;
55 
56 enum {
57   // Search 8-points in the radius grid around center, up to 11 search stages.
58   DIAMOND = 0,
59   // Search 12-points in the radius/tan_radius grid around center,
60   // up to 15 search stages.
61   NSTEP = 1,
62   // Search 8-points in the radius grid around center, up to 16 search stages.
63   NSTEP_8PT = 2,
64   // Search 8-points in the radius grid around center, upto 11 search stages
65   // with clamping of search radius.
66   CLAMPED_DIAMOND = 3,
67   // Search maximum 8-points in the radius grid around center,
68   // up to 11 search stages. First stage consists of 8 search points
69   // and the rest with 6 search points each in hex shape.
70   HEX = 4,
71   // Search maximum 8-points in the radius grid around center,
72   // up to 11 search stages. First stage consists of 4 search
73   // points and the rest with 8 search points each.
74   BIGDIA = 5,
75   // Search 8-points in the square grid around center, up to 11 search stages.
76   SQUARE = 6,
77   // HEX search with up to 2 stages.
78   FAST_HEX = 7,
79   // BIGDIA search with up to 2 stages.
80   FAST_DIAMOND = 8,
81   // BIGDIA search with up to 3 stages.
82   FAST_BIGDIA = 9,
83   // BIGDIA search with up to 1 stage.
84   VFAST_DIAMOND = 10,
85   // Total number of search methods.
86   NUM_SEARCH_METHODS,
87   // Number of distinct search methods.
88   NUM_DISTINCT_SEARCH_METHODS = SQUARE + 1,
89 } UENUM1BYTE(SEARCH_METHODS);
90 
91 typedef struct warp_search_config {
92   int num_neighbors;
93   MV neighbors[MAX_WARP_SEARCH_NEIGHBORS];
94   // Bitmask which is used to prune the search neighbors at one iteration
95   // based on which direction we chose in the previous iteration.
96   // See comments in av1_refine_warped_mv for details.
97   uint8_t neighbor_mask[MAX_WARP_SEARCH_NEIGHBORS];
98 } warp_search_config;
99 
100 // Methods for refining WARPED_CAUSAL motion vectors
101 enum {
102   // Search 4 adjacent points in a diamond shape at each iteration
103   WARP_SEARCH_DIAMOND,
104   // Search 8 adjacent points in a square at each iteration
105   WARP_SEARCH_SQUARE,
106   WARP_SEARCH_METHODS
107 } UENUM1BYTE(WARP_SEARCH_METHOD);
108 
109 #endif  // AOM_AV1_ENCODER_MCOMP_STRUCTS_H_
110