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_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 * - isvce_init_function_ptr_generic 34 * 35 * @remarks 36 * None 37 * 38 ******************************************************************************* 39 */ 40 41 /*****************************************************************************/ 42 /* File Includes */ 43 /*****************************************************************************/ 44 45 /* System Include files */ 46 #include <stdio.h> 47 #include <stddef.h> 48 #include <stdlib.h> 49 #include <string.h> 50 51 /* User Include files */ 52 #include "ih264_typedefs.h" 53 #include "iv2.h" 54 #include "ive2.h" 55 #include "isvc_defs.h" 56 #include "ih264_size_defs.h" 57 #include "isvce_defs.h" 58 #include "ih264e_error.h" 59 #include "ih264e_bitstream.h" 60 #include "ime_distortion_metrics.h" 61 #include "ime_defs.h" 62 #include "ime_structs.h" 63 #include "ih264_error.h" 64 #include "isvc_structs.h" 65 #include "isvc_trans_quant_itrans_iquant.h" 66 #include "ih264_inter_pred_filters.h" 67 #include "isvc_mem_fns.h" 68 #include "ih264_padding.h" 69 #include "ih264_intra_pred_filters.h" 70 #include "ih264_deblk_edge_filters.h" 71 #include "isvc_cabac_tables.h" 72 #include "irc_cntrl_param.h" 73 #include "irc_frame_info_collector.h" 74 #include "isvce_rate_control.h" 75 #include "isvce_cabac_structs.h" 76 #include "isvce_structs.h" 77 #include "ih264e_platform_macros.h" 78 #include "isvce_cabac.h" 79 #include "isvce_core_coding.h" 80 #include "ih264_cavlc_tables.h" 81 #include "isvce_cavlc.h" 82 #include "ih264e_intra_modes_eval.h" 83 #include "ih264e_fmt_conv.h" 84 #include "ih264e_half_pel.h" 85 #include "isvce_me.h" 86 87 /*****************************************************************************/ 88 /* Function Definitions */ 89 /*****************************************************************************/ 90 91 /** 92 ******************************************************************************* 93 * 94 * @brief Initialize the intra/inter/transform/deblk function pointers of 95 * codec context 96 * 97 * @par Description: the current routine initializes the function pointers of 98 * codec context basing on the architecture in use 99 * 100 * @param[in] ps_codec 101 * Codec context pointer 102 * 103 * @returns none 104 * 105 * @remarks none 106 * 107 ******************************************************************************* 108 */ isvce_init_function_ptr_generic(isvce_codec_t * ps_codec)109void isvce_init_function_ptr_generic(isvce_codec_t *ps_codec) 110 { 111 WORD32 i = 0; 112 113 /* curr proc ctxt */ 114 isvce_process_ctxt_t *ps_proc = NULL; 115 isvce_me_ctxt_t *ps_me_ctxt = NULL; 116 isa_dependent_fxns_t *ps_isa_dependent_fxns = &ps_codec->s_isa_dependent_fxns; 117 enc_loop_fxns_t *ps_enc_loop_fxns = &ps_isa_dependent_fxns->s_enc_loop_fxns; 118 inter_pred_fxns_t *ps_inter_pred_fxns = &ps_isa_dependent_fxns->s_inter_pred_fxns; 119 mem_fxns_t *ps_mem_fxns = &ps_isa_dependent_fxns->s_mem_fxns; 120 121 /* Init function pointers for intra pred leaf level functions luma 122 * Intra 16x16 */ 123 ps_codec->apf_intra_pred_16_l[0] = ih264_intra_pred_luma_16x16_mode_vert; 124 ps_codec->apf_intra_pred_16_l[1] = ih264_intra_pred_luma_16x16_mode_horz; 125 ps_codec->apf_intra_pred_16_l[2] = ih264_intra_pred_luma_16x16_mode_dc; 126 ps_codec->apf_intra_pred_16_l[3] = ih264_intra_pred_luma_16x16_mode_plane; 127 128 /* Init function pointers for intra pred leaf level functions luma 129 * Intra 4x4 */ 130 ps_codec->apf_intra_pred_4_l[0] = ih264_intra_pred_luma_4x4_mode_vert; 131 ps_codec->apf_intra_pred_4_l[1] = ih264_intra_pred_luma_4x4_mode_horz; 132 ps_codec->apf_intra_pred_4_l[2] = ih264_intra_pred_luma_4x4_mode_dc; 133 ps_codec->apf_intra_pred_4_l[3] = ih264_intra_pred_luma_4x4_mode_diag_dl; 134 ps_codec->apf_intra_pred_4_l[4] = ih264_intra_pred_luma_4x4_mode_diag_dr; 135 ps_codec->apf_intra_pred_4_l[5] = ih264_intra_pred_luma_4x4_mode_vert_r; 136 ps_codec->apf_intra_pred_4_l[6] = ih264_intra_pred_luma_4x4_mode_horz_d; 137 ps_codec->apf_intra_pred_4_l[7] = ih264_intra_pred_luma_4x4_mode_vert_l; 138 ps_codec->apf_intra_pred_4_l[8] = ih264_intra_pred_luma_4x4_mode_horz_u; 139 140 /* Init function pointers for intra pred leaf level functions luma 141 * Intra 8x8 */ 142 ps_codec->apf_intra_pred_8_l[0] = ih264_intra_pred_luma_8x8_mode_vert; 143 ps_codec->apf_intra_pred_8_l[2] = ih264_intra_pred_luma_8x8_mode_dc; 144 ps_codec->apf_intra_pred_8_l[3] = ih264_intra_pred_luma_8x8_mode_diag_dl; 145 ps_codec->apf_intra_pred_8_l[4] = ih264_intra_pred_luma_8x8_mode_diag_dr; 146 ps_codec->apf_intra_pred_8_l[5] = ih264_intra_pred_luma_8x8_mode_vert_r; 147 ps_codec->apf_intra_pred_8_l[6] = ih264_intra_pred_luma_8x8_mode_horz_d; 148 ps_codec->apf_intra_pred_8_l[7] = ih264_intra_pred_luma_8x8_mode_vert_l; 149 ps_codec->apf_intra_pred_8_l[8] = ih264_intra_pred_luma_8x8_mode_horz_u; 150 151 /* Init function pointers for intra pred leaf level functions chroma 152 * Intra 8x8 */ 153 ps_codec->apf_intra_pred_c[0] = ih264_intra_pred_chroma_8x8_mode_dc; 154 ps_codec->apf_intra_pred_c[1] = ih264_intra_pred_chroma_8x8_mode_horz; 155 ps_codec->apf_intra_pred_c[2] = ih264_intra_pred_chroma_8x8_mode_vert; 156 ps_codec->apf_intra_pred_c[3] = ih264_intra_pred_chroma_8x8_mode_plane; 157 158 /* Init luma forward transform fn ptr */ 159 ASSERT((sizeof(ps_enc_loop_fxns->apf_resi_trans_quant_8x8) / 160 sizeof(ps_enc_loop_fxns->apf_resi_trans_quant_8x8[0])) == 161 NUM_RESI_TRANS_QUANT_VARIANTS); 162 ASSERT((sizeof(ps_enc_loop_fxns->apf_resi_trans_quant_4x4) / 163 sizeof(ps_enc_loop_fxns->apf_resi_trans_quant_4x4[0])) == 164 NUM_RESI_TRANS_QUANT_VARIANTS); 165 ASSERT((sizeof(ps_enc_loop_fxns->apf_resi_trans_quant_chroma_4x4) / 166 sizeof(ps_enc_loop_fxns->apf_resi_trans_quant_chroma_4x4[0])) == 167 NUM_RESI_TRANS_QUANT_VARIANTS); 168 169 ps_enc_loop_fxns->apf_resi_trans_quant_8x8[0] = isvc_resi_trans_quant_8x8; 170 ps_enc_loop_fxns->apf_resi_trans_quant_4x4[0] = isvc_resi_trans_quant_4x4; 171 ps_enc_loop_fxns->apf_resi_trans_quant_chroma_4x4[0] = isvc_resi_trans_quant_chroma_4x4; 172 ps_enc_loop_fxns->apf_resi_trans_quant_8x8[1] = isvc_resi_trans_quant_8x8; 173 ps_enc_loop_fxns->apf_resi_trans_quant_4x4[1] = isvc_resi_trans_quant_4x4; 174 ps_enc_loop_fxns->apf_resi_trans_quant_chroma_4x4[1] = isvc_resi_trans_quant_chroma_4x4; 175 ps_enc_loop_fxns->pf_hadamard_quant_4x4 = isvc_hadamard_quant_4x4; 176 ps_enc_loop_fxns->pf_hadamard_quant_2x2_uv = isvc_hadamard_quant_2x2_uv; 177 178 /* Init inverse transform fn ptr */ 179 ASSERT((sizeof(ps_enc_loop_fxns->apf_iquant_itrans_recon_8x8) / 180 sizeof(ps_enc_loop_fxns->apf_iquant_itrans_recon_8x8[0])) == NUM_IQ_IT_RECON_VARIANTS); 181 ASSERT((sizeof(ps_enc_loop_fxns->apf_iquant_itrans_recon_4x4) / 182 sizeof(ps_enc_loop_fxns->apf_iquant_itrans_recon_4x4[0])) == NUM_IQ_IT_RECON_VARIANTS); 183 ASSERT((sizeof(ps_enc_loop_fxns->apf_iquant_itrans_recon_4x4_dc) / 184 sizeof(ps_enc_loop_fxns->apf_iquant_itrans_recon_4x4_dc[0])) == 185 NUM_IQ_IT_RECON_VARIANTS); 186 ASSERT((sizeof(ps_enc_loop_fxns->apf_iquant_itrans_recon_chroma_4x4) / 187 sizeof(ps_enc_loop_fxns->apf_iquant_itrans_recon_chroma_4x4[0])) == 188 NUM_IQ_IT_RECON_VARIANTS); 189 ASSERT((sizeof(ps_enc_loop_fxns->apf_iquant_itrans_recon_chroma_4x4_dc) / 190 sizeof(ps_enc_loop_fxns->apf_iquant_itrans_recon_chroma_4x4_dc[0])) == 191 NUM_IQ_IT_RECON_VARIANTS); 192 193 ps_enc_loop_fxns->apf_iquant_itrans_recon_8x8[0] = isvc_iquant_itrans_recon_8x8; 194 ps_enc_loop_fxns->apf_iquant_itrans_recon_4x4[0] = isvc_iquant_itrans_recon_4x4; 195 ps_enc_loop_fxns->apf_iquant_itrans_recon_4x4_dc[0] = isvc_iquant_itrans_recon_4x4_dc; 196 ps_enc_loop_fxns->apf_iquant_itrans_recon_chroma_4x4[0] = isvc_iquant_itrans_recon_chroma_4x4; 197 ps_enc_loop_fxns->apf_iquant_itrans_recon_chroma_4x4_dc[0] = 198 isvc_iquant_itrans_recon_chroma_4x4_dc; 199 ps_enc_loop_fxns->apf_iquant_itrans_recon_8x8[1] = isvc_iquant_itrans_recon_8x8; 200 ps_enc_loop_fxns->apf_iquant_itrans_recon_4x4[1] = isvc_iquant_itrans_recon_4x4; 201 ps_enc_loop_fxns->apf_iquant_itrans_recon_4x4_dc[1] = isvc_iquant_itrans_recon_4x4_dc; 202 ps_enc_loop_fxns->apf_iquant_itrans_recon_chroma_4x4[1] = isvc_iquant_itrans_recon_chroma_4x4; 203 ps_enc_loop_fxns->apf_iquant_itrans_recon_chroma_4x4_dc[1] = 204 isvc_iquant_itrans_recon_chroma_4x4_dc; 205 ps_enc_loop_fxns->apf_iquant_itrans_recon_8x8[2] = isvc_iquant_itrans_recon_8x8; 206 ps_enc_loop_fxns->apf_iquant_itrans_recon_4x4[2] = isvc_iquant_itrans_recon_4x4; 207 ps_enc_loop_fxns->apf_iquant_itrans_recon_4x4_dc[2] = isvc_iquant_itrans_recon_4x4_dc; 208 ps_enc_loop_fxns->apf_iquant_itrans_recon_chroma_4x4[2] = isvc_iquant_itrans_recon_chroma_4x4; 209 ps_enc_loop_fxns->apf_iquant_itrans_recon_chroma_4x4_dc[2] = 210 isvc_iquant_itrans_recon_chroma_4x4_dc; 211 ps_enc_loop_fxns->pf_zcbf_iquant_itrans_recon_4x4 = isvc_zcbf_iquant_itrans_recon_4x4; 212 ps_enc_loop_fxns->pf_chroma_zcbf_iquant_itrans_recon_4x4 = 213 isvc_chroma_zcbf_iquant_itrans_recon_4x4; 214 215 ps_enc_loop_fxns->pf_ihadamard_scaling_4x4 = ih264_ihadamard_scaling_4x4; 216 ps_enc_loop_fxns->pf_ihadamard_scaling_2x2_uv = ih264_ihadamard_scaling_2x2_uv; 217 218 /* Init fn ptr luma core coding */ 219 ps_enc_loop_fxns->apf_luma_energy_compaction[0] = isvce_code_luma_intra_macroblock_16x16; 220 ps_enc_loop_fxns->apf_luma_energy_compaction[1] = isvce_code_luma_intra_macroblock_4x4; 221 ps_enc_loop_fxns->apf_luma_energy_compaction[3] = isvce_code_luma_inter_macroblock_16x16; 222 223 /* Init fn ptr chroma core coding */ 224 ps_enc_loop_fxns->apf_chroma_energy_compaction[0] = isvce_code_chroma_intra_macroblock_8x8; 225 ps_enc_loop_fxns->apf_chroma_energy_compaction[1] = isvce_code_chroma_inter_macroblock_8x8; 226 227 /* Init fn ptr luma deblocking */ 228 ps_codec->pf_deblk_luma_vert_bs4 = ih264_deblk_luma_vert_bs4; 229 ps_codec->pf_deblk_luma_vert_bslt4 = ih264_deblk_luma_vert_bslt4; 230 ps_codec->pf_deblk_luma_horz_bs4 = ih264_deblk_luma_horz_bs4; 231 ps_codec->pf_deblk_luma_horz_bslt4 = ih264_deblk_luma_horz_bslt4; 232 233 /* Init fn ptr chroma deblocking */ 234 ps_codec->pf_deblk_chroma_vert_bs4 = ih264_deblk_chroma_vert_bs4; 235 ps_codec->pf_deblk_chroma_vert_bslt4 = ih264_deblk_chroma_vert_bslt4; 236 ps_codec->pf_deblk_chroma_horz_bs4 = ih264_deblk_chroma_horz_bs4; 237 ps_codec->pf_deblk_chroma_horz_bslt4 = ih264_deblk_chroma_horz_bslt4; 238 239 /* write mb syntax layer */ 240 ps_codec->pf_write_mb_syntax_layer[CAVLC][ISLICE] = isvce_write_islice_mb_cavlc; 241 ps_codec->pf_write_mb_syntax_layer[CAVLC][PSLICE] = isvce_write_pslice_mb_cavlc; 242 ps_codec->pf_write_mb_syntax_layer[CAVLC][BSLICE] = isvce_write_bslice_mb_cavlc; 243 ps_codec->pf_write_mb_syntax_layer[CABAC][ISLICE] = isvce_write_islice_mb_cabac; 244 ps_codec->pf_write_mb_syntax_layer[CABAC][PSLICE] = isvce_write_pslice_mb_cabac; 245 ps_codec->pf_write_mb_syntax_layer[CABAC][BSLICE] = isvce_write_bslice_mb_cabac; 246 247 /* Padding Functions */ 248 ps_codec->pf_pad_top = ih264_pad_top; 249 ps_codec->pf_pad_bottom = ih264_pad_bottom; 250 ps_codec->pf_pad_left_luma = ih264_pad_left_luma; 251 ps_codec->pf_pad_left_chroma = ih264_pad_left_chroma; 252 ps_codec->pf_pad_right_luma = ih264_pad_right_luma; 253 ps_codec->pf_pad_right_chroma = ih264_pad_right_chroma; 254 255 /* Inter pred leaf level functions */ 256 ps_inter_pred_fxns->pf_inter_pred_luma_copy = ih264_inter_pred_luma_copy; 257 ps_inter_pred_fxns->pf_inter_pred_luma_horz = ih264_inter_pred_luma_horz; 258 ps_inter_pred_fxns->pf_inter_pred_luma_vert = ih264_inter_pred_luma_vert; 259 ps_inter_pred_fxns->pf_inter_pred_luma_bilinear = ih264_inter_pred_luma_bilinear; 260 ps_inter_pred_fxns->pf_inter_pred_chroma = ih264_inter_pred_chroma; 261 262 /* sad me level functions */ 263 ps_codec->apf_compute_sad_16x16[0] = ime_compute_sad_16x16; 264 ps_codec->apf_compute_sad_16x16[1] = ime_compute_sad_16x16_fast; 265 ps_codec->pf_compute_sad_16x8 = ime_compute_sad_16x8; 266 267 /* memory handling operations */ 268 ps_mem_fxns->pf_mem_cpy_mul8 = ih264_memcpy_mul_8; 269 ps_mem_fxns->pf_mem_set_mul8 = ih264_memset_mul_8; 270 ps_mem_fxns->pf_copy_2d = isvc_copy_2d; 271 ps_mem_fxns->pf_memset_2d = isvc_memset_2d; 272 ps_mem_fxns->pf_nonzero_checker = isvc_is_nonzero_blk; 273 274 /* sad me level functions */ 275 for(i = 0; i < (MAX_PROCESS_CTXT); i++) 276 { 277 ps_proc = &ps_codec->as_process[i]; 278 279 ps_me_ctxt = &ps_proc->s_me_ctxt; 280 ps_me_ctxt->pf_ime_compute_sad_16x16[0] = ime_compute_sad_16x16; 281 ps_me_ctxt->pf_ime_compute_sad_16x16[1] = ime_compute_sad_16x16_fast; 282 ps_me_ctxt->pf_ime_compute_sad_16x8 = ime_compute_sad_16x8; 283 ps_me_ctxt->pf_ime_compute_sad4_diamond = ime_calculate_sad4_prog; 284 ps_me_ctxt->pf_ime_compute_sad3_diamond = ime_calculate_sad3_prog; 285 ps_me_ctxt->pf_ime_compute_sad2_diamond = ime_calculate_sad2_prog; 286 ps_me_ctxt->pf_ime_sub_pel_compute_sad_16x16 = ime_sub_pel_compute_sad_16x16; 287 ps_me_ctxt->pf_ime_compute_sad_stat_luma_16x16 = ime_compute_satqd_16x16_lumainter; 288 } 289 290 /* intra mode eval -encoder level function */ 291 ps_codec->pf_ih264e_evaluate_intra16x16_modes = ih264e_evaluate_intra16x16_modes; 292 ps_codec->pf_ih264e_evaluate_intra_chroma_modes = ih264e_evaluate_intra_chroma_modes; 293 ps_codec->pf_ih264e_evaluate_intra_4x4_modes = ih264e_evaluate_intra_4x4_modes; 294 295 /* csc */ 296 ps_codec->pf_ih264e_conv_420p_to_420sp = ih264e_fmt_conv_420p_to_420sp; 297 ps_codec->pf_ih264e_fmt_conv_422i_to_420sp = ih264e_fmt_conv_422i_to_420sp; 298 299 /* Halp pel generation function - encoder level*/ 300 ps_codec->pf_ih264e_sixtapfilter_horz = ih264e_sixtapfilter_horz; 301 ps_codec->pf_ih264e_sixtap_filter_2dvh_vert = ih264e_sixtap_filter_2dvh_vert; 302 303 /* ME compute */ 304 ps_codec->apf_compute_me[PSLICE] = &isvce_compute_me_single_reflist; 305 ps_codec->apf_compute_me[BSLICE] = &isvce_compute_me_multi_reflist; 306 307 /* skip decision */ 308 ps_codec->apf_find_skip_params_me[PSLICE] = &isvce_find_pskip_params_me; 309 ps_codec->apf_find_skip_params_me[BSLICE] = &isvce_find_bskip_params_me; 310 } 311