1 /******************************************************************************
2  *
3  * Copyright (C) 2015 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************
18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20 /**
21  *******************************************************************************
22  * @file
23  *  ime.h
24  *
25  * @brief
26  *  Contains declarations of global variables for H264 encoder
27  *
28  * @author
29  *  Ittiam
30  *
31  * @remarks
32  *
33  *******************************************************************************
34  */
35 
36 #ifndef IME_H_
37 #define IME_H_
38 
39 /*****************************************************************************/
40 /* Constant Macros                                                           */
41 /*****************************************************************************/
42 
43 /**
44 ******************************************************************************
45  *  @brief      Number of iterations before exiting during diamond search
46 ******************************************************************************
47  */
48 #define NUM_LAYERS 16
49 
50 /**
51 ******************************************************************************
52  *  @brief     Skip Bias value for P slice
53 ******************************************************************************
54  */
55 #define SKIP_BIAS_P 2
56 
57 /**
58 ******************************************************************************
59  *  @brief     Skip Bias value for B slice
60 ******************************************************************************
61  */
62 #define SKIP_BIAS_B 16
63 
64 /*****************************************************************************/
65 /* Extern Function Declarations                                              */
66 /*****************************************************************************/
67 
68 
69 /**
70 *******************************************************************************
71 *
72 * @brief Diamond Search
73 *
74 * @par Description:
75 *  This function computes the sad at vertices of several layers of diamond grid
76 *  at a time. The number of layers of diamond grid that would be evaluated is
77 *  configurable.The function computes the sad at vertices of a diamond grid. If
78 *  the sad at the center of the diamond grid is lesser than the sad at any other
79 *  point of the diamond grid, the function marks the candidate Mb partition as
80 *  mv.
81 *
82 * @param[in] ps_mb_part
83 *  pointer to current mb partition ctxt with respect to ME
84 *
85 * @param[in] ps_me_ctxt
86 *  pointer to me context
87 *
88 * @param[in] u4_lambda
89 *  lambda motion
90 *
91 * @param[in] u4_fast_flag
92 *  enable/disable fast sad computation
93 *
94 * @returns  mv pair & corresponding distortion and cost
95 *
96 * @remarks This module cannot be part of the final product due to its lack of
97 * computational feasibility. This is only for quality eval purposes.
98 *
99 *******************************************************************************
100  */
101 extern void ime_diamond_search_16x16(me_ctxt_t *ps_me_ctxt, WORD32 i4_reflist);
102 
103 
104 /**
105 *******************************************************************************
106 *
107 * @brief This function computes the best motion vector among the tentative mv
108 * candidates chosen.
109 *
110 * @par Description:
111 *  This function determines the position in the search window at which the motion
112 *  estimation should begin in order to minimise the number of search iterations.
113 *
114 * @param[in] ps_mb_part
115 *  pointer to current mb partition ctxt with respect to ME
116 *
117 * @param[in] u4_lambda_motion
118 *  lambda motion
119 *
120 * @param[in] u4_fast_flag
121 *  enable/disable fast sad computation
122 *
123 * @returns  mv pair & corresponding distortion and cost
124 *
125 * @remarks none
126 *
127 *******************************************************************************
128 */
129 extern void ime_evaluate_init_srchposn_16x16(me_ctxt_t *ps_me_ctxt,
130                                              WORD32 i4_reflist);
131 
132 /**
133 *******************************************************************************
134 *
135 * @brief Searches for the best matching full pixel predictor within the search
136 * range
137 *
138 * @par Description:
139 *  This function begins by computing the mv predict vector for the current mb.
140 *  This is used for cost computations. Further basing on the algo. chosen, it
141 *  looks through a set of candidate vectors that best represent the mb a least
142 *  cost and returns this information.
143 *
144 * @param[in] ps_proc
145 *  pointer to current proc ctxt
146 *
147 * @param[in] ps_me_ctxt
148 *  pointer to me context
149 *
150 * @returns  mv pair & corresponding distortion and cost
151 *
152 * @remarks none
153 *
154 *******************************************************************************
155 */
156 extern void ime_full_pel_motion_estimation_16x16(me_ctxt_t *ps_me_ctxt,
157                                                  WORD32 i4_ref_list);
158 
159 /**
160 *******************************************************************************
161 *
162 * @brief Searches for the best matching sub pixel predictor within the search
163 * range
164 *
165 * @par Description:
166 *  This function begins by searching across all sub pixel sample points
167 *  around the full pel motion vector. The vector with least cost is chosen as
168 *  the mv for the current mb. If the skip mode is not evaluated while analysing
169 *  the initial search candidates then analyse it here and update the mv.
170 *
171 * @param[in] ps_proc
172 *  pointer to current proc ctxt
173 *
174 * @param[in] ps_me_ctxt
175 *  pointer to me context
176 *
177 * @returns none
178 *
179 * @remarks none
180 *
181 *******************************************************************************
182 */
183 extern void ime_sub_pel_motion_estimation_16x16(me_ctxt_t *ps_me_ctxt,
184                                                 WORD32 i4_reflist);
185 
186 /**
187 *******************************************************************************
188 *
189 * @brief This function computes cost of skip macroblocks
190 *
191 * @par Description:
192 *
193 * @param[in] ps_me_ctxt
194 *  pointer to me ctxt
195 *
196 * @param[in] ps_skip_mv
197 *  pointer to skip mv
198 *
199   @param[in] is_slice_type_b
200 *  Whether slice type is BSLICE or not
201 
202 * @returns  none
203 *
204 * @remarks
205 * NOTE: while computing the skip cost, do not enable early exit from compute
206 * sad function because, a negative bias gets added later
207 *
208 *******************************************************************************
209 */
210 extern void ime_compute_skip_cost(me_ctxt_t *ps_me_ctxt,
211                                   ime_mv_t *ps_skip_mv,
212                                   mb_part_ctxt *ps_smb_part_info,
213                                   UWORD32 u4_use_stat_sad,
214                                   WORD32 i4_reflist,
215                                   WORD32 is_slice_type_b);
216 
217 
218 #endif /* IME_H_ */
219