blob: 2266e5a13d72e494f15a24ddab4bc02c5d3c6e57 [file] [log] [blame]
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301/******************************************************************************
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 *******************************************************************************
23 * @file
24 * ih264e_me.h
25 *
26 * @brief
27 * Contains declarations of global variables for H264 encoder
28 *
29 * @author
30 * ittiam
31 *
32 * @remarks
33 *
34 *******************************************************************************
35 */
36
37#ifndef IH264E_ME_H_
38#define IH264E_ME_H_
39
40/*****************************************************************************/
Ram Mohan11b4a7b2017-11-23 17:41:50 +053041/* Constant Macros */
42/*****************************************************************************/
43
44/**
45******************************************************************************
46 * @brief Skip Bias value for P slice
47******************************************************************************
48 */
Ram Mohan6ecdf602017-11-23 17:43:35 +053049#define SKIP_BIAS_P 0
Ram Mohan11b4a7b2017-11-23 17:41:50 +053050
51/**
52******************************************************************************
53 * @brief Skip Bias value for B slice
54******************************************************************************
55 */
Ram Mohan6ecdf602017-11-23 17:43:35 +053056#define SKIP_BIAS_B 0
Ram Mohan11b4a7b2017-11-23 17:41:50 +053057
58
59/*****************************************************************************/
Hamsalekha S8d3d3032015-03-13 21:24:58 +053060/* Function Macros */
61/*****************************************************************************/
62
63/**
Harinarayanan K K134291e2015-06-18 16:03:38 +053064 ******************************************************************************
Hamsalekha S8d3d3032015-03-13 21:24:58 +053065 * @brief compute median of 3 elements (a, b, c) and store the output
66 * in to result. This is used for mv prediction
Harinarayanan K K134291e2015-06-18 16:03:38 +053067 ******************************************************************************
Hamsalekha S8d3d3032015-03-13 21:24:58 +053068 */
69
70#define MEDIAN(a, b, c, result) if (a > b){\
71 if (b > c)\
72 result = b;\
73 else {\
74 if (a > c)\
75 result = c;\
76 else \
77 result = a;\
78 }\
79 }\
80 else {\
81 if (c > b)\
82 result = b;\
83 else {\
84 if (c > a)\
85 result = c;\
86 else \
87 result = a;\
88 }\
89 }
90
Hamsalekha S8d3d3032015-03-13 21:24:58 +053091/*****************************************************************************/
92/* Extern Function Declarations */
93/*****************************************************************************/
94
95/**
Harinarayanan K K134291e2015-06-18 16:03:38 +053096 *******************************************************************************
97 *
98 * @brief
99 * This function populates the length of the codewords for motion vectors in the
100 * range (-search range, search range) in pixels
101 *
102 * @param[in] ps_me
103 * Pointer to me ctxt
104 *
105 * @param[out] pu1_mv_bits
106 * length of the codeword for all mv's
107 *
108 * @remarks The length of the code words are derived from signed exponential
109 * goloumb codes.
110 *
111 *******************************************************************************
112 */
113void ih264e_init_mv_bits(me_ctxt_t *ps_me);
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530114
115/**
Harinarayanan K K134291e2015-06-18 16:03:38 +0530116 *******************************************************************************
117 *
118 * @brief The function computes the parameters for a P skip MB
119 *
120 * @par Description:
121 * The function computes the parameters for a P skip MB
122 *
123 * @param[in] ps_proc
124 * Process context
125 *
126 * @param[in] u4_for_me
127 * Flag to indicate the purpose of computing skip
128 *
129 * @param[out] ps_pred_mv
130 * Flag to indicate the current active refernce list
131 *
132 * @returns
133 * 1) Updates skip MV in proc
134 * 2) Returns if the current MB can be coded as skip or not
135 *
136 * @remarks The code implements the logic as described in sec 8.4.1.1 in H264
137 * specification.
138 *
139 *******************************************************************************
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530140*/
Harinarayanan K K134291e2015-06-18 16:03:38 +0530141ih264e_skip_params_ft ih264e_find_pskip_params;
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530142
143/**
Harinarayanan K K134291e2015-06-18 16:03:38 +0530144 *******************************************************************************
145 *
146 * @brief The function computes the parameters for a P skip MB
147 *
148 * @par Description:
149 * The function computes the parameters for a P skip MB
150 *
151 * @param[in] ps_proc
152 * Process context
153 *
154 * @param[in] u4_for_me
155 * Flag to indicate the purpose of computing skip
156 *
157 * @param[out] ps_pred_mv
158 * Flag to indicate the current active refernce list
159 *
160 * @returns
161 * 1) Updates skip MV in proc
162 * 2) Returns if the current MB can be coded as skip or not
163 *
164 * @remarks The code implements the logic as described in sec 8.4.1.1 in H264
165 * specification.
166 *
167 *******************************************************************************
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530168*/
Harinarayanan K K134291e2015-06-18 16:03:38 +0530169ih264e_skip_params_ft ih264e_find_pskip_params_me;
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530170
171/**
Harinarayanan K K134291e2015-06-18 16:03:38 +0530172 *******************************************************************************
173 *
174 * @brief The function computes the parameters for a B skip MB
175 *
176 * @par Description:
177 * The function computes the parameters for a B skip MB
178 *
179 * @param[in] ps_proc
180 * Process context
181 *
182 * @param[in] u4_for_me
183 * Flag to indicate the purpose of computing skip
184 *
185 * @param[out] ps_pred_mv
186 * Flag to indicate the current active refernce list
187 *
188 * @returns
189 * 1) Updates skip MV in proc
190 * 2) Returns if the current MB can be coded as skip or not
191 *
192 * @remarks The code implements the logic as described in sec 8.4.1.1 in H264
193 * specification.
194 *
195 *******************************************************************************
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530196*/
Harinarayanan K K134291e2015-06-18 16:03:38 +0530197ih264e_skip_params_ft ih264e_find_bskip_params;
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530198
199/**
Harinarayanan K K134291e2015-06-18 16:03:38 +0530200 *******************************************************************************
201 *
202 * @brief The function computes the parameters for a B skip MB
203 *
204 * @par Description:
205 * The function computes the parameters for a B skip MB
206 *
207 * @param[in] ps_proc
208 * Process context
209 *
210 * @param[in] u4_for_me
211 * Flag to indicate the purpose of computing skip
212 *
213 * @param[out] ps_pred_mv
214 * Flag to indicate the current active refernce list
215 *
216 * @returns
217 * 1) Updates skip MV in proc
218 * 2) The type of SKIP [L0/L1/BI]
219 *
220 * @remarks
221 *******************************************************************************
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530222*/
Harinarayanan K K134291e2015-06-18 16:03:38 +0530223ih264e_skip_params_ft ih264e_find_bskip_params_me;
224
225/**
226 *******************************************************************************
227 *
228 * @brief motion vector predictor
229 *
230 * @par Description:
231 * The routine calculates the motion vector predictor for a given block,
232 * given the candidate MV predictors.
233 *
234 * @param[in] ps_left_mb_pu
235 * pointer to left mb motion vector info
236 *
237 * @param[in] ps_top_row_pu
238 * pointer to top & top right mb motion vector info
239 *
240 * @param[out] ps_pred_mv
241 * pointer to candidate predictors for the current block
242 *
243 * @returns The x & y components of the MV predictor.
244 *
245 * @remarks The code implements the logic as described in sec 8.4.1.3 in H264
246 * specification.
247 * Assumptions : 1. Assumes Only partition of size 16x16
248 *
249 *******************************************************************************
250 */
251void ih264e_get_mv_predictor(enc_pu_t *ps_left_mb_pu, enc_pu_t *ps_top_row_pu,
252 enc_pu_mv_t *ps_pred_mv, WORD32 i4_ref_list);
253
254/**
255 *******************************************************************************
256 *
257 * @brief This fucntion evalues ME for 2 reference lists
258 *
259 * @par Description:
260 * It evaluates skip, full-pel an half-pel and assigns the correct MV in proc
261 *
262 * @param[in] ps_proc
263 * Process context corresponding to the job
264 *
265 * @returns none
266 *
267 * @remarks none
268 *
269 *******************************************************************************
270 */
271ih264e_compute_me_ft ih264e_compute_me_multi_reflist;
272
273/**
274 *******************************************************************************
275 *
276 * @brief This fucntion evalues ME for single reflist [Pred L0]
277 *
278 * @par Description:
279 * It evaluates skip, full-pel an half-pel and assigns the correct MV in proc
280 *
281 * @param[in] ps_proc
282 * Process context corresponding to the job
283 *
284 * @returns none
285 *
286 * @remarks none
287 *
288 *******************************************************************************
289 */
290ih264e_compute_me_ft ih264e_compute_me_single_reflist;
291
292/**
293 *******************************************************************************
294 *
295 * @brief This function initializes me ctxt
296 *
297 * @par Description:
298 * Before dispatching the current job to me thread, the me context associated
299 * with the job is initialized.
300 *
301 * @param[in] ps_proc
302 * Process context corresponding to the job
303 *
304 * @returns none
305 *
306 * @remarks none
307 *
308 *******************************************************************************
309 */
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530310void ih264e_init_me(process_ctxt_t *ps_proc);
311
312/**
Harinarayanan K K134291e2015-06-18 16:03:38 +0530313 *******************************************************************************
314 *
315 * @brief This function performs motion estimation for the current NMB
316 *
317 * @par Description:
318 * Intializes input and output pointers required by the function ih264e_compute_me
319 * and calls the function ih264e_compute_me in a loop to process NMBs.
320 *
321 * @param[in] ps_proc
322 * Process context corresponding to the job
323 *
324 * @returns
325 *
326 * @remarks none
327 *
328 *******************************************************************************
329 */
330void ih264e_compute_me_nmb(process_ctxt_t *ps_proc, UWORD32 u4_nmb_count);
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530331
332/**
Harinarayanan K K134291e2015-06-18 16:03:38 +0530333 *******************************************************************************
334 *
335 * @brief This function performs MV prediction
336 *
337 * @par Description:
338 *
339 * @param[in] ps_proc
340 * Process context corresponding to the job
341 *
342 * @returns none
343 *
344 * @remarks none
345 * This function will update the MB availability since intra inter decision
346 * should be done before the call
347 *
348 *******************************************************************************
349 */
350void ih264e_mv_pred(process_ctxt_t *ps_proc, WORD32 i4_reflist);
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530351
352/**
Harinarayanan K K134291e2015-06-18 16:03:38 +0530353 *******************************************************************************
354 *
355 * @brief This function approximates Pred. MV
356 *
357 * @par Description:
358 *
359 * @param[in] ps_proc
360 * Process context corresponding to the job
361 *
362 * @returns none
363 *
364 * @remarks none
365 * Motion estimation happens at nmb level. For cost calculations, mv is appro
366 * ximated using this function
367 *
368 *******************************************************************************
369 */
370void ih264e_mv_pred_me(process_ctxt_t *ps_proc, WORD32 i4_ref_list);
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530371
372#endif /* IH264E_ME_H_ */