ih264e_me.h revision 3749f6f435e79624f72841e866245d84195551cd
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 *******************************************************************************
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/*****************************************************************************/
41/* Function Macros                                                           */
42/*****************************************************************************/
43
44/**
45 ******************************************************************************
46 *  @brief      compute median of 3 elements (a, b, c) and store the output
47 *  in to result. This is used for mv prediction
48 ******************************************************************************
49 */
50
51#define MEDIAN(a, b, c, result) if (a > b){\
52                                    if (b > c)\
53                                        result = b;\
54                                    else {\
55                                        if (a > c)\
56                                            result = c;\
57                                        else \
58                                            result = a;\
59                                    }\
60                                }\
61                                else {\
62                                    if (c > b)\
63                                        result = b;\
64                                    else {\
65                                        if (c > a)\
66                                            result = c;\
67                                        else \
68                                            result = a;\
69                                    }\
70                                }
71
72/*****************************************************************************/
73/* Extern Function Declarations                                              */
74/*****************************************************************************/
75
76/**
77 *******************************************************************************
78 *
79 * @brief
80 *  This function populates the length of the codewords for motion vectors in the
81 *  range (-search range, search range) in pixels
82 *
83 * @param[in] ps_me
84 *  Pointer to me ctxt
85 *
86 * @param[out] pu1_mv_bits
87 *  length of the codeword for all mv's
88 *
89 * @remarks The length of the code words are derived from signed exponential
90 * goloumb codes.
91 *
92 *******************************************************************************
93 */
94void ih264e_init_mv_bits(me_ctxt_t *ps_me);
95
96/**
97 *******************************************************************************
98 *
99 * @brief The function computes the parameters for a P skip MB
100 *
101 * @par Description:
102 *  The function computes the parameters for a P skip MB
103 *
104 * @param[in] ps_proc
105 *  Process context
106 *
107 * @param[in] u4_for_me
108 *  Flag to indicate the purpose of computing skip
109 *
110 * @param[out] ps_pred_mv
111 *  Flag to indicate the current active refernce list
112 *
113 * @returns
114 *       1) Updates skip MV in proc
115 *       2) Returns if the current MB can be coded as skip or not
116 *
117 * @remarks The code implements the logic as described in sec 8.4.1.1 in H264
118 *   specification.
119 *
120 *******************************************************************************
121*/
122ih264e_skip_params_ft  ih264e_find_pskip_params;
123
124/**
125 *******************************************************************************
126 *
127 * @brief The function computes the parameters for a P skip MB
128 *
129 * @par Description:
130 *  The function computes the parameters for a P skip MB
131 *
132 * @param[in] ps_proc
133 *  Process context
134 *
135 * @param[in] u4_for_me
136 *  Flag to indicate the purpose of computing skip
137 *
138 * @param[out] ps_pred_mv
139 *  Flag to indicate the current active refernce list
140 *
141 * @returns
142 *       1) Updates skip MV in proc
143 *       2) Returns if the current MB can be coded as skip or not
144 *
145 * @remarks The code implements the logic as described in sec 8.4.1.1 in H264
146 *   specification.
147 *
148 *******************************************************************************
149*/
150ih264e_skip_params_ft  ih264e_find_pskip_params_me;
151
152/**
153 *******************************************************************************
154 *
155 * @brief The function computes the parameters for a B skip MB
156 *
157 * @par Description:
158 *  The function computes the parameters for a B skip MB
159 *
160 * @param[in] ps_proc
161 *  Process context
162 *
163 * @param[in] u4_for_me
164 *  Flag to indicate the purpose of computing skip
165 *
166 * @param[out] ps_pred_mv
167 *  Flag to indicate the current active refernce list
168 *
169 * @returns
170 *       1) Updates skip MV in proc
171 *       2) Returns if the current MB can be coded as skip or not
172 *
173 * @remarks The code implements the logic as described in sec 8.4.1.1 in H264
174 *   specification.
175 *
176 *******************************************************************************
177*/
178ih264e_skip_params_ft  ih264e_find_bskip_params;
179
180/**
181 *******************************************************************************
182 *
183 * @brief The function computes the parameters for a B skip MB
184 *
185 * @par Description:
186 *  The function computes the parameters for a B skip MB
187 *
188 * @param[in] ps_proc
189 *  Process context
190 *
191 * @param[in] u4_for_me
192 *  Flag to indicate the purpose of computing skip
193 *
194 * @param[out] ps_pred_mv
195 *  Flag to indicate the current active refernce list
196 *
197 * @returns
198 *       1) Updates skip MV in proc
199 *       2) The type of SKIP [L0/L1/BI]
200 *
201 * @remarks
202 *******************************************************************************
203*/
204ih264e_skip_params_ft  ih264e_find_bskip_params_me;
205
206/**
207 *******************************************************************************
208 *
209 * @brief motion vector predictor
210 *
211 * @par Description:
212 *  The routine calculates the motion vector predictor for a given block,
213 *  given the candidate MV predictors.
214 *
215 * @param[in] ps_left_mb_pu
216 *  pointer to left mb motion vector info
217 *
218 * @param[in] ps_top_row_pu
219 *  pointer to top & top right mb motion vector info
220 *
221 * @param[out] ps_pred_mv
222 *  pointer to candidate predictors for the current block
223 *
224 * @returns  The x & y components of the MV predictor.
225 *
226 * @remarks The code implements the logic as described in sec 8.4.1.3 in H264
227 *   specification.
228 *   Assumptions : 1. Assumes Only partition of size 16x16
229 *
230 *******************************************************************************
231 */
232void ih264e_get_mv_predictor(enc_pu_t *ps_left_mb_pu, enc_pu_t *ps_top_row_pu,
233                             enc_pu_mv_t *ps_pred_mv, WORD32 i4_ref_list);
234
235/**
236 *******************************************************************************
237 *
238 * @brief This fucntion evalues ME for 2 reference lists
239 *
240 * @par Description:
241 *  It evaluates skip, full-pel an half-pel and assigns the correct MV in proc
242 *
243 * @param[in] ps_proc
244 *  Process context corresponding to the job
245 *
246 * @returns  none
247 *
248 * @remarks none
249 *
250 *******************************************************************************
251 */
252ih264e_compute_me_ft  ih264e_compute_me_multi_reflist;
253
254/**
255 *******************************************************************************
256 *
257 * @brief This fucntion evalues ME for single reflist [Pred L0]
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_single_reflist;
272
273/**
274 *******************************************************************************
275 *
276 * @brief This function initializes me ctxt
277 *
278 * @par Description:
279 *  Before dispatching the current job to me thread, the me context associated
280 *  with the job is initialized.
281 *
282 * @param[in] ps_proc
283 *  Process context corresponding to the job
284 *
285 * @returns  none
286 *
287 * @remarks none
288 *
289 *******************************************************************************
290 */
291void ih264e_init_me(process_ctxt_t *ps_proc);
292
293/**
294 *******************************************************************************
295 *
296 * @brief This function performs motion estimation for the current NMB
297 *
298 * @par Description:
299 *  Intializes input and output pointers required by the function ih264e_compute_me
300 *  and calls the function ih264e_compute_me in a loop to process NMBs.
301 *
302 * @param[in] ps_proc
303 *  Process context corresponding to the job
304 *
305 * @returns
306 *
307 * @remarks none
308 *
309 *******************************************************************************
310 */
311void ih264e_compute_me_nmb(process_ctxt_t *ps_proc, UWORD32 u4_nmb_count);
312
313/**
314 *******************************************************************************
315 *
316 * @brief This function performs MV prediction
317 *
318 * @par Description:
319 *
320 * @param[in] ps_proc
321 *  Process context corresponding to the job
322 *
323 * @returns  none
324 *
325 * @remarks none
326 *  This function will update the MB availability since intra inter decision
327 *  should be done before the call
328 *
329 *******************************************************************************
330 */
331void ih264e_mv_pred(process_ctxt_t *ps_proc, WORD32 i4_reflist);
332
333/**
334 *******************************************************************************
335 *
336 * @brief This function approximates Pred. MV
337 *
338 * @par Description:
339 *
340 * @param[in] ps_proc
341 *  Process context corresponding to the job
342 *
343 * @returns  none
344 *
345 * @remarks none
346 *  Motion estimation happens at nmb level. For cost calculations, mv is appro
347 *  ximated using this function
348 *
349 *******************************************************************************
350 */
351void ih264e_mv_pred_me(process_ctxt_t *ps_proc, WORD32 i4_ref_list);
352
353#endif /* IH264E_ME_H_ */
354