xref: /aosp_15_r20/external/libavc/encoder/ih264e_function_selector_generic.c (revision 495ae853bb871d1e5a258cb02c2cc13cde8ddb9a)
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_function_selector_generic.c
25 *
26 * @brief
27 *  Contains functions to initialize function pointers of codec context
28 *
29 * @author
30 *  ittiam
31 *
32 * @par List of Functions:
33 *  - ih264e_init_function_ptr_generic
34 *
35 * @remarks
36 *  none
37 *
38 *******************************************************************************
39 */
40 
41 
42 /*****************************************************************************/
43 /* File Includes                                                             */
44 /*****************************************************************************/
45 
46 /* System Include Files */
47 #include <stdio.h>
48 #include <stddef.h>
49 #include <stdlib.h>
50 #include <string.h>
51 
52 /* User Include Files */
53 #include "ih264_typedefs.h"
54 #include "iv2.h"
55 #include "ive2.h"
56 
57 #include "ih264_error.h"
58 #include "ih264_defs.h"
59 #include "ih264_mem_fns.h"
60 #include "ih264_padding.h"
61 #include "ih264_structs.h"
62 #include "ih264_trans_quant_itrans_iquant.h"
63 #include "ih264_inter_pred_filters.h"
64 #include "ih264_intra_pred_filters.h"
65 #include "ih264_deblk_edge_filters.h"
66 #include "ih264_cavlc_tables.h"
67 #include "ih264_cabac_tables.h"
68 
69 #include "ime_defs.h"
70 #include "ime_distortion_metrics.h"
71 #include "ime_structs.h"
72 
73 #include "irc_cntrl_param.h"
74 #include "irc_frame_info_collector.h"
75 
76 #include "ih264e_error.h"
77 #include "ih264e_defs.h"
78 #include "ih264e_rate_control.h"
79 #include "ih264e_bitstream.h"
80 #include "ih264e_cabac_structs.h"
81 #include "ih264e_structs.h"
82 #include "ih264e_me.h"
83 #include "ih264e_half_pel.h"
84 #include "ih264e_intra_modes_eval.h"
85 #include "ih264e_core_coding.h"
86 #include "ih264e_cavlc.h"
87 #include "ih264e_cabac.h"
88 #include "ih264e_fmt_conv.h"
89 #include "ih264e_platform_macros.h"
90 
91 
92 /*****************************************************************************/
93 /* Function Definitions                                                      */
94 /*****************************************************************************/
95 
96 /**
97 *******************************************************************************
98 *
99 * @brief Initialize the intra/inter/transform/deblk/entropy function pointers
100 *
101 * @par Description: the current routine initializes the function pointers of
102 * codec context basing on the architecture in use
103 *
104 * @param[in] ps_codec
105 *  Codec context pointer
106 *
107 * @returns  none
108 *
109 * @remarks none
110 *
111 *******************************************************************************
112 */
ih264e_init_function_ptr_generic(codec_t * ps_codec)113 void ih264e_init_function_ptr_generic(codec_t *ps_codec)
114 {
115     WORD32 i = 0;
116 
117     /* Init function pointers for intra pred leaf level functions luma
118      * Intra 16x16 */
119     ps_codec->apf_intra_pred_16_l[0] = ih264_intra_pred_luma_16x16_mode_vert;
120     ps_codec->apf_intra_pred_16_l[1] = ih264_intra_pred_luma_16x16_mode_horz;
121     ps_codec->apf_intra_pred_16_l[2] = ih264_intra_pred_luma_16x16_mode_dc;
122     ps_codec->apf_intra_pred_16_l[3] = ih264_intra_pred_luma_16x16_mode_plane;
123 
124     /* Init function pointers for intra pred leaf level functions luma
125      * Intra 4x4 */
126     ps_codec->apf_intra_pred_4_l[0] = ih264_intra_pred_luma_4x4_mode_vert;
127     ps_codec->apf_intra_pred_4_l[1] = ih264_intra_pred_luma_4x4_mode_horz;
128     ps_codec->apf_intra_pred_4_l[2] = ih264_intra_pred_luma_4x4_mode_dc;
129     ps_codec->apf_intra_pred_4_l[3] = ih264_intra_pred_luma_4x4_mode_diag_dl;
130     ps_codec->apf_intra_pred_4_l[4] = ih264_intra_pred_luma_4x4_mode_diag_dr;
131     ps_codec->apf_intra_pred_4_l[5] = ih264_intra_pred_luma_4x4_mode_vert_r;
132     ps_codec->apf_intra_pred_4_l[6] = ih264_intra_pred_luma_4x4_mode_horz_d;
133     ps_codec->apf_intra_pred_4_l[7] = ih264_intra_pred_luma_4x4_mode_vert_l;
134     ps_codec->apf_intra_pred_4_l[8] = ih264_intra_pred_luma_4x4_mode_horz_u;
135 
136     /* Init function pointers for intra pred leaf level functions luma
137      * Intra 8x8 */
138     ps_codec->apf_intra_pred_8_l[0] = ih264_intra_pred_luma_8x8_mode_vert;
139     ps_codec->apf_intra_pred_8_l[2] = ih264_intra_pred_luma_8x8_mode_dc;
140     ps_codec->apf_intra_pred_8_l[3] = ih264_intra_pred_luma_8x8_mode_diag_dl;
141     ps_codec->apf_intra_pred_8_l[4] = ih264_intra_pred_luma_8x8_mode_diag_dr;
142     ps_codec->apf_intra_pred_8_l[5] = ih264_intra_pred_luma_8x8_mode_vert_r;
143     ps_codec->apf_intra_pred_8_l[6] = ih264_intra_pred_luma_8x8_mode_horz_d;
144     ps_codec->apf_intra_pred_8_l[7] = ih264_intra_pred_luma_8x8_mode_vert_l;
145     ps_codec->apf_intra_pred_8_l[8] = ih264_intra_pred_luma_8x8_mode_horz_u;
146 
147     /* Init function pointers for intra pred leaf level functions chroma
148      * Intra 8x8 */
149     ps_codec->apf_intra_pred_c[0] = ih264_intra_pred_chroma_8x8_mode_dc;
150     ps_codec->apf_intra_pred_c[1] = ih264_intra_pred_chroma_8x8_mode_horz;
151     ps_codec->apf_intra_pred_c[2] = ih264_intra_pred_chroma_8x8_mode_vert;
152     ps_codec->apf_intra_pred_c[3] = ih264_intra_pred_chroma_8x8_mode_plane;
153 
154     /* Init luma forward transform fn ptr */
155     ps_codec->pf_resi_trans_quant_8x8 = ih264_resi_trans_quant_8x8;
156     ps_codec->pf_resi_trans_quant_4x4 = ih264_resi_trans_quant_4x4;
157     ps_codec->pf_resi_trans_quant_chroma_4x4 = ih264_resi_trans_quant_chroma_4x4;
158     ps_codec->pf_hadamard_quant_4x4 = ih264_hadamard_quant_4x4;
159     ps_codec->pf_hadamard_quant_2x2_uv = ih264_hadamard_quant_2x2_uv;
160 
161     /* Init inverse transform fn ptr */
162     ps_codec->pf_iquant_itrans_recon_8x8 = ih264_iquant_itrans_recon_8x8;
163     ps_codec->pf_iquant_itrans_recon_4x4 = ih264_iquant_itrans_recon_4x4;
164     ps_codec->pf_iquant_itrans_recon_4x4_dc = ih264_iquant_itrans_recon_4x4_dc;
165     ps_codec->pf_iquant_itrans_recon_chroma_4x4 = ih264_iquant_itrans_recon_chroma_4x4;
166     ps_codec->pf_iquant_itrans_recon_chroma_4x4_dc = ih264_iquant_itrans_recon_chroma_4x4_dc;
167 
168     ps_codec->pf_ihadamard_scaling_4x4 = ih264_ihadamard_scaling_4x4;
169     ps_codec->pf_ihadamard_scaling_2x2_uv = ih264_ihadamard_scaling_2x2_uv;
170     ps_codec->pf_interleave_copy = ih264_interleave_copy;
171 
172     /* Init fn ptr luma core coding */
173     ps_codec->luma_energy_compaction[0] = ih264e_code_luma_intra_macroblock_16x16;
174     ps_codec->luma_energy_compaction[1] = ih264e_code_luma_intra_macroblock_4x4;
175     ps_codec->luma_energy_compaction[3] = ih264e_code_luma_inter_macroblock_16x16;
176 
177     /* Init fn ptr chroma core coding */
178     ps_codec->chroma_energy_compaction[0] = ih264e_code_chroma_intra_macroblock_8x8;
179     ps_codec->chroma_energy_compaction[1] = ih264e_code_chroma_inter_macroblock_8x8;
180 
181     /* Init fn ptr luma deblocking */
182     ps_codec->pf_deblk_luma_vert_bs4 = ih264_deblk_luma_vert_bs4;
183     ps_codec->pf_deblk_luma_vert_bslt4 = ih264_deblk_luma_vert_bslt4;
184     ps_codec->pf_deblk_luma_horz_bs4 = ih264_deblk_luma_horz_bs4;
185     ps_codec->pf_deblk_luma_horz_bslt4 = ih264_deblk_luma_horz_bslt4;
186 
187     /* Init fn ptr chroma deblocking */
188     ps_codec->pf_deblk_chroma_vert_bs4 = ih264_deblk_chroma_vert_bs4;
189     ps_codec->pf_deblk_chroma_vert_bslt4 = ih264_deblk_chroma_vert_bslt4;
190     ps_codec->pf_deblk_chroma_horz_bs4 = ih264_deblk_chroma_horz_bs4;
191     ps_codec->pf_deblk_chroma_horz_bslt4 = ih264_deblk_chroma_horz_bslt4;
192 
193     /* write mb syntax layer */
194     ps_codec->pf_write_mb_syntax_layer[CAVLC][ISLICE] = ih264e_write_islice_mb_cavlc;
195     ps_codec->pf_write_mb_syntax_layer[CAVLC][PSLICE] = ih264e_write_pslice_mb_cavlc;
196     ps_codec->pf_write_mb_syntax_layer[CAVLC][BSLICE] = ih264e_write_bslice_mb_cavlc;
197     ps_codec->pf_write_mb_syntax_layer[CABAC][ISLICE] = ih264e_write_islice_mb_cabac;
198     ps_codec->pf_write_mb_syntax_layer[CABAC][PSLICE] = ih264e_write_pslice_mb_cabac;
199     ps_codec->pf_write_mb_syntax_layer[CABAC][BSLICE] = ih264e_write_bslice_mb_cabac;
200 
201     /* Padding Functions */
202     ps_codec->pf_pad_top = ih264_pad_top;
203     ps_codec->pf_pad_bottom = ih264_pad_bottom;
204     ps_codec->pf_pad_left_luma = ih264_pad_left_luma;
205     ps_codec->pf_pad_left_chroma = ih264_pad_left_chroma;
206     ps_codec->pf_pad_right_luma = ih264_pad_right_luma;
207     ps_codec->pf_pad_right_chroma = ih264_pad_right_chroma;
208 
209     /* Inter pred leaf level functions */
210     ps_codec->pf_inter_pred_luma_copy = ih264_inter_pred_luma_copy;
211     ps_codec->pf_inter_pred_luma_horz = ih264_inter_pred_luma_horz;
212     ps_codec->pf_inter_pred_luma_vert = ih264_inter_pred_luma_vert;
213     ps_codec->pf_inter_pred_luma_bilinear = ih264_inter_pred_luma_bilinear;
214     ps_codec->pf_inter_pred_chroma = ih264_inter_pred_chroma;
215 
216     /* sad me level functions */
217     ps_codec->apf_compute_sad_16x16[0] = ime_compute_sad_16x16;
218     ps_codec->apf_compute_sad_16x16[1] = ime_compute_sad_16x16_fast;
219     ps_codec->pf_compute_sad_16x8 = ime_compute_sad_16x8;
220 
221     /* memory handling operations */
222     ps_codec->pf_mem_cpy = ih264_memcpy;
223     ps_codec->pf_mem_cpy_mul8 = ih264_memcpy_mul_8;
224     ps_codec->pf_mem_set = ih264_memset;
225     ps_codec->pf_mem_set_mul8 = ih264_memset_mul_8;
226 
227     /* sad me level functions */
228     for (i = 0; i < (MAX_PROCESS_CTXT); i++)
229     {
230         process_ctxt_t *ps_proc = &ps_codec->as_process[i];
231         me_ctxt_t *ps_me_ctxt = &ps_proc->s_me_ctxt;
232 
233         ps_me_ctxt->pf_ime_compute_sad_16x16[0] = ime_compute_sad_16x16;
234         ps_me_ctxt->pf_ime_compute_sad_16x16[1] = ime_compute_sad_16x16_fast;
235         ps_me_ctxt->pf_ime_compute_sad_16x8 = ime_compute_sad_16x8;
236         ps_me_ctxt->pf_ime_compute_sad4_diamond = ime_calculate_sad4_prog;
237         ps_me_ctxt->pf_ime_compute_sad3_diamond = ime_calculate_sad3_prog;
238         ps_me_ctxt->pf_ime_compute_sad2_diamond = ime_calculate_sad2_prog;
239         ps_me_ctxt->pf_ime_sub_pel_compute_sad_16x16 = ime_sub_pel_compute_sad_16x16;
240         ps_me_ctxt->pf_ime_compute_sad_stat_luma_16x16 = ime_compute_satqd_16x16_lumainter;
241     }
242 
243     /* intra mode eval -encoder level function */
244     ps_codec->pf_ih264e_evaluate_intra16x16_modes = ih264e_evaluate_intra16x16_modes;
245     ps_codec->pf_ih264e_evaluate_intra_chroma_modes = ih264e_evaluate_intra_chroma_modes;
246     ps_codec->pf_ih264e_evaluate_intra_4x4_modes = ih264e_evaluate_intra_4x4_modes;
247 
248     /* csc */
249     ps_codec->pf_ih264e_conv_420p_to_420sp = ih264e_fmt_conv_420p_to_420sp;
250     ps_codec->pf_ih264e_fmt_conv_422i_to_420sp = ih264e_fmt_conv_422i_to_420sp;
251 
252     /* Halp pel generation function - encoder level*/
253     ps_codec->pf_ih264e_sixtapfilter_horz = ih264e_sixtapfilter_horz;
254     ps_codec->pf_ih264e_sixtap_filter_2dvh_vert = ih264e_sixtap_filter_2dvh_vert;
255 
256     /* ME compute */
257     ps_codec->apf_compute_me[PSLICE] = &ih264e_compute_me_single_reflist;
258     ps_codec->apf_compute_me[BSLICE] = &ih264e_compute_me_multi_reflist;
259 
260     /* skip decision */
261     ps_codec->apf_find_skip_params_me[PSLICE] = &ih264e_find_pskip_params_me;
262     ps_codec->apf_find_skip_params_me[BSLICE] = &ih264e_find_bskip_params_me;
263 }
264