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 * @file
23 * isvcd_cabac.c
24 *
25 * @brief
26 * This file contains Binary decoding routines.
27 *
28 * @author
29 * Kishore
30 *
31 * @par List of Functions:
32 * - isvcd_init_cabac_contexts()
33 *
34 * @remarks
35 * None
36 *
37 *******************************************************************************
38 */
39
40 #include <string.h>
41 #include "ih264_typedefs.h"
42 #include "ih264_macros.h"
43 #include "ih264_platform_macros.h"
44 #include "isvcd_structs.h"
45 #include "ih264d_cabac.h"
46 #include "isvcd_cabac.h"
47 #include "ih264d_bitstrm.h"
48 #include "ih264d_error_handler.h"
49 #include "ih264d_defs.h"
50 #include "ih264d_debug.h"
51 #include "ih264d_tables.h"
52 #include "isvcd_tables.h"
53 #include "ih264d_parse_cabac.h"
54 #include "ih264d_tables.h"
55
56 /*****************************************************************************/
57 /* */
58 /* Function Name : isvcd_init_cabac_contexts */
59 /* */
60 /* Description : This function initializes the cabac contexts */
61 /* depending upon slice type and Init_Idc value. */
62 /* Inputs : ps_dec, slice type */
63 /* Globals : <Does it use any global variables?> */
64 /* Outputs : */
65 /* Returns : void */
66 /* */
67 /* Issues : none */
68 /* */
69 /* Revision History: */
70 /* */
71 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
72 /* 06 09 2021 Kishore Draft */
73 /* */
74 /*****************************************************************************/
75
isvcd_init_cabac_contexts(UWORD8 u1_slice_type,dec_struct_t * ps_dec)76 void isvcd_init_cabac_contexts(UWORD8 u1_slice_type, dec_struct_t *ps_dec)
77 {
78 bin_ctxt_model_t *p_cabac_ctxt_table_t = ps_dec->p_cabac_ctxt_table_t;
79 UWORD8 u1_qp_y = ps_dec->ps_cur_slice->u1_slice_qp;
80 UWORD8 u1_cabac_init_Idc = 0;
81
82 if(I_SLICE != u1_slice_type)
83 {
84 u1_cabac_init_Idc = ps_dec->ps_cur_slice->u1_cabac_init_idc;
85 }
86
87 {
88 /* MAKING ps_dec->p_ctxt_inc_mb_map a scratch buffer */
89 /* 0th entry of CtxtIncMbMap will be always be containing default values
90 for CABAC context representing MB not available */
91 ctxt_inc_mb_info_t *p_DefCtxt = ps_dec->p_ctxt_inc_mb_map - 1;
92 UWORD8 *pu1_temp;
93 WORD8 i;
94 p_DefCtxt->u1_mb_type = CAB_SKIP;
95 p_DefCtxt->u1_cbp = 0x0f;
96 p_DefCtxt->u1_intra_chroma_pred_mode = 0;
97 p_DefCtxt->u1_yuv_dc_csbp = 0x7;
98 p_DefCtxt->u1_transform8x8_ctxt = 0;
99
100 pu1_temp = (UWORD8 *) p_DefCtxt->i1_ref_idx;
101 for(i = 0; i < 4; i++, pu1_temp++) (*pu1_temp) = 0;
102 pu1_temp = (UWORD8 *) p_DefCtxt->u1_mv;
103 for(i = 0; i < 16; i++, pu1_temp++) (*pu1_temp) = 0;
104 ps_dec->ps_def_ctxt_mb_info = p_DefCtxt;
105 }
106
107 if(u1_slice_type == I_SLICE)
108 {
109 u1_cabac_init_Idc = 3;
110 ps_dec->p_mb_type_t = p_cabac_ctxt_table_t + MB_TYPE_I_SLICE;
111 }
112 else if(u1_slice_type == P_SLICE)
113 {
114 ps_dec->p_mb_type_t = p_cabac_ctxt_table_t + MB_TYPE_P_SLICE;
115 ps_dec->p_mb_skip_flag_t = p_cabac_ctxt_table_t + MB_SKIP_FLAG_P_SLICE;
116 ps_dec->p_sub_mb_type_t = p_cabac_ctxt_table_t + SUB_MB_TYPE_P_SLICE;
117 }
118 else if(u1_slice_type == B_SLICE)
119 {
120 ps_dec->p_mb_type_t = p_cabac_ctxt_table_t + MB_TYPE_B_SLICE;
121 ps_dec->p_mb_skip_flag_t = p_cabac_ctxt_table_t + MB_SKIP_FLAG_B_SLICE;
122 ps_dec->p_sub_mb_type_t = p_cabac_ctxt_table_t + SUB_MB_TYPE_B_SLICE;
123 }
124 {
125 bin_ctxt_model_t *p_cabac_ctxt_table_t_tmp = p_cabac_ctxt_table_t;
126 if(ps_dec->ps_cur_slice->u1_field_pic_flag)
127 {
128 p_cabac_ctxt_table_t_tmp += SIGNIFICANT_COEFF_FLAG_FLD;
129 }
130 else
131 {
132 p_cabac_ctxt_table_t_tmp += SIGNIFICANT_COEFF_FLAG_FRAME;
133 }
134 {
135 bin_ctxt_model_t **p_significant_coeff_flag_t = ps_dec->p_significant_coeff_flag_t;
136 p_significant_coeff_flag_t[0] = p_cabac_ctxt_table_t_tmp + SIG_COEFF_CTXT_CAT_0_OFFSET;
137 p_significant_coeff_flag_t[1] = p_cabac_ctxt_table_t_tmp + SIG_COEFF_CTXT_CAT_1_OFFSET;
138 p_significant_coeff_flag_t[2] = p_cabac_ctxt_table_t_tmp + SIG_COEFF_CTXT_CAT_2_OFFSET;
139 p_significant_coeff_flag_t[3] = p_cabac_ctxt_table_t_tmp + SIG_COEFF_CTXT_CAT_3_OFFSET;
140 p_significant_coeff_flag_t[4] = p_cabac_ctxt_table_t_tmp + SIG_COEFF_CTXT_CAT_4_OFFSET;
141
142 p_significant_coeff_flag_t[5] = p_cabac_ctxt_table_t_tmp + SIG_COEFF_CTXT_CAT_5_OFFSET;
143 }
144 }
145
146 memcpy(p_cabac_ctxt_table_t, gau1_isvcd_cabac_ctxt_init_table[u1_cabac_init_Idc][u1_qp_y],
147 NUM_CABAC_CTXTS_SVC * sizeof(bin_ctxt_model_t));
148 }
149