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