xref: /aosp_15_r20/external/libavc/encoder/svc/isvce_intra_modes_eval.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_intra_modes_eval.h
25 *
26 * @brief
27 *  This file contains declarations of routines that perform rate distortion
28 *  analysis on a macroblock if coded as intra.
29 *
30 * @author
31 *  ittiam
32 *
33 * @remarks
34 *  none
35 *
36 *******************************************************************************
37 */
38 
39 #ifndef _ISVCE_INTRA_MODES_EVAL_H_
40 #define _ISVCE_INTRA_MODES_EVAL_H_
41 
42 /**
43 ******************************************************************************
44 *
45 * @brief
46 *  derivation process for subblock/partition availability
47 *
48 * @par   Description
49 *  Calculates the availability of the left, top, topright and topleft subblock
50 *  or partitions.
51 *
52 * @param[in]    ps_proc_ctxt
53 *  pointer to macroblock context (handle)
54 *
55 * @param[in]    i1_pel_pos_x
56 *  column position of the pel wrt the current block
57 *
58 * @param[in]    i1_pel_pos_y
59 *  row position of the pel in wrt current block
60 *
61 * @remarks     Assumptions: before calling this function it is assumed that
62 *   the neighbor availability of the current macroblock is already derived.
63 *   Based on table 6-3 of H264 specification
64 *
65 * @return      availability status (yes or no)
66 *
67 ******************************************************************************
68 */
69 UWORD8 isvce_derive_ngbr_avbl_of_mb_partitions(block_neighbors_t *s_ngbr_avbl, WORD8 i1_pel_pos_x,
70                                                WORD8 i1_pel_pos_y);
71 
72 /**
73 ******************************************************************************
74 *
75 * @brief
76 *  evaluate best intra 16x16 mode (rate distortion opt off)
77 *
78 * @par Description
79 *  This function evaluates all the possible intra 16x16 modes and finds the mode
80 *  that best represents the macro-block (least distortion) and occupies fewer
81 *  bits in the bit-stream.
82 *
83 * @param[in]   ps_proc_ctxt
84 *  pointer to process context (handle)
85 *
86 * @remarks
87 *  Ideally the cost of encoding a macroblock is calculated as
88 *  (distortion + lambda*rate). Where distortion is SAD/SATD,... between the
89 *  input block and the reconstructed block and rate is the number of bits taken
90 *  to place the macroblock in the bit-stream. In this routine the rate does not
91 *  exactly point to the total number of bits it takes, rather it points to header
92 *  bits necessary for encoding the macroblock. Assuming the deltaQP, cbp bits
93 *  and residual bits fall in to texture bits the number of bits taken to encoding
94 *  mbtype is considered as rate, we compute cost. Further we will approximate
95 *  the distortion as the deviation b/w input and the predicted block as opposed
96 *  to input and reconstructed block.
97 *
98 *  NOTE: As per the Document JVT-O079, for intra 16x16 macroblock,
99 *  the SAD and cost are one and the same.
100 *
101 * @return     none
102 *
103 ******************************************************************************
104 */
105 void isvce_evaluate_intra16x16_modes_for_least_cost_rdoptoff(isvce_process_ctxt_t *ps_proc_ctxt);
106 
107 /**
108 ******************************************************************************
109 *
110 * @brief
111 *  evaluate best intra 8x8 mode (rate distortion opt on)
112 *
113 * @par Description
114 *  This function evaluates all the possible intra 8x8 modes and finds the mode
115 *  that best represents the macro-block (least distortion) and occupies fewer
116 *  bits in the bit-stream.
117 *
118 * @param[in]    ps_proc_ctxt
119 *  pointer to proc ctxt
120 *
121 * @remarks Ideally the cost of encoding a macroblock is calculated as
122 *  (distortion + lambda*rate). Where distortion is SAD/SATD,... between the
123 *  input block and the reconstructed block and rate is the number of bits taken
124 *  to place the macroblock in the bit-stream. In this routine the rate does not
125 *  exactly point to the total number of bits it takes, rather it points to header
126 *  bits necessary for encoding the macroblock. Assuming the deltaQP, cbp bits
127 *  and residual bits fall in to texture bits the number of bits taken to encoding
128 *  mbtype is considered as rate, we compute cost. Further we will approximate
129 *  the distortion as the deviation b/w input and the predicted block as opposed
130 *  to input and reconstructed block.
131 *
132 *  NOTE: TODO: This function needs to be tested
133 *
134 *  @return      none
135 *
136 ******************************************************************************
137 */
138 void isvce_evaluate_intra8x8_modes_for_least_cost_rdoptoff(isvce_process_ctxt_t *ps_proc_ctxt);
139 
140 /**
141 ******************************************************************************
142 *
143 * @brief
144 *  evaluate best intra 4x4 mode (rate distortion opt on)
145 *
146 * @par Description
147 *  This function evaluates all the possible intra 4x4 modes and finds the mode
148 *  that best represents the macro-block (least distortion) and occupies fewer
149 *  bits in the bit-stream.
150 *
151 * @param[in]    ps_proc_ctxt
152 *  pointer to proc ctxt
153 *
154 * @remarks
155 *  Ideally the cost of encoding a macroblock is calculated as
156 *  (distortion + lambda*rate). Where distortion is SAD/SATD,... between the
157 *  input block and the reconstructed block and rate is the number of bits taken
158 *  to place the macroblock in the bit-stream. In this routine the rate does not
159 *  exactly point to the total number of bits it takes, rather it points to header
160 *  bits necessary for encoding the macroblock. Assuming the deltaQP, cbp bits
161 *  and residual bits fall in to texture bits the number of bits taken to encoding
162 *  mbtype is considered as rate, we compute cost. Further we will approximate
163 *  the distortion as the deviation b/w input and the predicted block as opposed
164 *  to input and reconstructed block.
165 *
166 *  NOTE: As per the Document JVT-O079, for the whole intra 4x4 macroblock,
167 *  24*lambda is added to the SAD before comparison with the best SAD for
168 *  inter prediction. This is an empirical value to prevent using too many intra
169 *  blocks.
170 *
171 * @return      none
172 *
173 ******************************************************************************
174 */
175 void isvce_evaluate_intra4x4_modes_for_least_cost_rdopton(isvce_process_ctxt_t *ps_proc_ctxt);
176 
177 /**
178 ******************************************************************************
179 *
180 * @brief
181 *  evaluate best intra 4x4 mode (rate distortion opt off)
182 *
183 * @par Description
184 *  This function evaluates all the possible intra 4x4 modes and finds the mode
185 *  that best represents the macro-block (least distortion) and occupies fewer
186 *  bits in the bit-stream.
187 *
188 * @param[in]    ps_proc_ctxt
189 *  pointer to proc ctxt
190 *
191 * @remarks
192 *  Ideally the cost of encoding a macroblock is calculated as
193 *  (distortion + lambda*rate). Where distortion is SAD/SATD,... between the
194 *  input block and the reconstructed block and rate is the number of bits taken
195 *  to place the macroblock in the bit-stream. In this routine the rate does not
196 *  exactly point to the total number of bits it takes, rather it points to header
197 *  bits necessary for encoding the macroblock. Assuming the deltaQP, cbp bits
198 *  and residual bits fall in to texture bits the number of bits taken to encoding
199 *  mbtype is considered as rate, we compute cost. Further we will approximate
200 *  the distortion as the deviation b/w input and the predicted block as opposed
201 *  to input and reconstructed block.
202 *
203 *  NOTE: As per the Document JVT-O079, for the whole intra 4x4 macroblock,
204 *  24*lambda is added to the SAD before comparison with the best SAD for
205 *  inter prediction. This is an empirical value to prevent using too many intra
206 *  blocks.
207 *
208 * @return      none
209 *
210 ******************************************************************************
211 */
212 void isvce_evaluate_intra4x4_modes_for_least_cost_rdoptoff(isvce_process_ctxt_t *ps_proc_ctxt);
213 
214 /**
215 ******************************************************************************
216 *
217 * @brief
218 *  evaluate best chroma intra 8x8 mode (rate distortion opt off)
219 *
220 * @par Description
221 *  This function evaluates all the possible chroma intra 8x8 modes and finds
222 *  the mode that best represents the macroblock (least distortion) and occupies
223 *  fewer bits in the bitstream.
224 *
225 * @param[in] ps_proc_ctxt
226 *  pointer to macroblock context (handle)
227 *
228 * @remarks
229 *  For chroma best intra pred mode is calculated based only on SAD
230 *
231 * @returns none
232 *
233 ******************************************************************************
234 */
235 void isvce_evaluate_chroma_intra8x8_modes_for_least_cost_rdoptoff(
236     isvce_process_ctxt_t *ps_proc_ctxt);
237 
238 /**
239 ******************************************************************************
240 *
241 * @brief
242 *  Evaluate best intra 16x16 mode (among VERT, HORZ and DC) and do the
243 *  prediction.
244 *
245 * @par Description
246 *  This function evaluates first three 16x16 modes and compute corresponding sad
247 *  and return the buffer predicted with best mode.
248 *
249 * @param[in] pu1_src
250 *  UWORD8 pointer to the source
251 *
252 * @param[in] pu1_ngbr_pels_i16
253 *  UWORD8 pointer to neighbouring pels
254 *
255 * @param[out] pu1_dst
256 *  UWORD8 pointer to the destination
257 *
258 * @param[in] src_strd
259 *  integer source stride
260 *
261 * @param[in] dst_strd
262 *  integer destination stride
263 *
264 * @param[in] u4_n_avblty
265 *  availability of neighbouring pixels
266 *
267 * @param[in] u4_intra_mode
268 *  Pointer to the variable in which best mode is returned
269 *
270 * @param[in] pu4_sadmin
271 *  Pointer to the variable in which minimum sad is returned
272 *
273 * @param[in] u4_valid_intra_modes
274 *  Says what all modes are valid
275 *
276 * @returns      none
277 *
278 ******************************************************************************
279 */
280 typedef void isvce_evaluate_intra_modes_ft(UWORD8 *pu1_src, UWORD8 *pu1_ngbr_pels_i16,
281                                            UWORD8 *pu1_dst, UWORD32 src_strd, UWORD32 dst_strd,
282                                            WORD32 u4_n_avblty, UWORD32 *u4_intra_mode,
283                                            WORD32 *pu4_sadmin, UWORD32 u4_valid_intra_modes);
284 
285 isvce_evaluate_intra_modes_ft isvce_evaluate_intra16x16_modes;
286 isvce_evaluate_intra_modes_ft isvce_evaluate_intra_chroma_modes;
287 
288 /* assembly */
289 isvce_evaluate_intra_modes_ft isvce_evaluate_intra16x16_modes_a9q;
290 isvce_evaluate_intra_modes_ft isvce_evaluate_intra_chroma_modes_a9q;
291 
292 isvce_evaluate_intra_modes_ft isvce_evaluate_intra16x16_modes_av8;
293 isvce_evaluate_intra_modes_ft isvce_evaluate_intra_chroma_modes_av8;
294 
295 /* x86 intrinsics */
296 isvce_evaluate_intra_modes_ft isvce_evaluate_intra16x16_modes_ssse3;
297 isvce_evaluate_intra_modes_ft isvce_evaluate_intra_chroma_modes_ssse3;
298 
299 /**
300 ******************************************************************************
301 *
302 * @brief
303 *  Evaluate best intra 4x4 mode and perform prediction.
304 *
305 * @par Description
306 *  This function evaluates  4x4 modes and compute corresponding sad
307 *  and return the buffer predicted with best mode.
308 *
309 * @param[in] pu1_src
310 *  UWORD8 pointer to the source
311 *
312 * @param[in] pu1_ngbr_pels
313 *  UWORD8 pointer to neighbouring pels
314 *
315 * @param[out] pu1_dst
316 *  UWORD8 pointer to the destination
317 *
318 * @param[in] src_strd
319 *  integer source stride
320 *
321 * @param[in] dst_strd
322 *  integer destination stride
323 *
324 * @param[in] u4_n_avblty
325 *  availability of neighbouring pixels
326 *
327 * @param[in] u4_intra_mode
328 *  Pointer to the variable in which best mode is returned
329 *
330 * @param[in] pu4_sadmin
331 *  Pointer to the variable in which minimum cost is returned
332 *
333 * @param[in] u4_valid_intra_modes
334 *  Says what all modes are valid
335 *
336 * @param[in] u4_lambda
337 *  Lamda value for computing cost from SAD
338 *
339 * @param[in] u4_predictd_mode
340 *  Predicted mode for cost computation
341 *
342 * @returns      none
343 *
344 ******************************************************************************
345 */
346 typedef void isvce_evaluate_intra_4x4_modes_ft(UWORD8 *pu1_src, UWORD8 *pu1_ngbr_pels,
347                                                UWORD8 *pu1_dst, UWORD32 src_strd, UWORD32 dst_strd,
348                                                WORD32 u4_n_avblty, UWORD32 *u4_intra_mode,
349                                                WORD32 *pu4_sadmin, UWORD32 u4_valid_intra_modes,
350                                                UWORD32 u4_lambda, UWORD32 u4_predictd_mode);
351 
352 isvce_evaluate_intra_4x4_modes_ft isvce_evaluate_intra_4x4_modes;
353 
354 /* x86 intrinsics */
355 isvce_evaluate_intra_4x4_modes_ft isvce_evaluate_intra_4x4_modes_ssse3;
356 
357 /* assembly */
358 isvce_evaluate_intra_4x4_modes_ft isvce_evaluate_intra_4x4_modes_a9q;
359 isvce_evaluate_intra_4x4_modes_ft isvce_evaluate_intra_4x4_modes_av8;
360 
361 #endif
362