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_thread_compute_bs.c
24 *
25 * @brief
26 * Contains routines that for multi-thread decoder
27 *
28 * @author
29 * Kishore
30 *
31 * @remarks
32 * None
33 *
34 *******************************************************************************
35 */
36
37 #include <string.h>
38 #include "ih264d_error_handler.h"
39 #include "ih264d_debug.h"
40 #include "ih264d_defs.h"
41 #include "ih264d_debug.h"
42 #include "ih264d_tables.h"
43 #include "isvcd_structs.h"
44 #include "ih264d_defs.h"
45 #include "ih264d_mb_utils.h"
46 #include "ih264d_thread_compute_bs.h"
47 #include "isvcd_thread_compute_bs.h"
48 #include "ithread.h"
49 #include "ih264d_deblocking.h"
50 #include "ih264d_process_pslice.h"
51 #include "isvcd_process_epslice.h"
52 #include "ih264d_process_intra_mb.h"
53 #include "ih264d_mb_utils.h"
54 #include "ih264d_tables.h"
55 #include "ih264d_format_conv.h"
56 #include "ih264d_defs.h"
57
58 UWORD16 ih264d_update_csbp_8x8(UWORD16 u2_luma_csbp);
59 void ih264d_fill_bs2_horz_vert(UWORD32 *pu4_bs, /* Base pointer of BS table */
60 WORD32 u4_left_mb_csbp, /* csbp of left mb */
61 WORD32 u4_top_mb_csbp, /* csbp of top mb */
62 WORD32 u4_cur_mb_csbp, /* csbp of current mb */
63 const UWORD32 *pu4_packed_bs2, const UWORD16 *pu2_4x4_v2h_reorder);
64 void isvcd_fill_bs_ibl(deblk_mb_t *ps_deblk_mb, UWORD8 u1_top_mb_type, UWORD8 u1_left_mb_type,
65 dec_mb_info_t *ps_cur_mb_info, UWORD16 *pu2_curr_res_luma_csbp,
66 UWORD16 *pu2_left_res_luma_csbp, UWORD16 *pu2_top_res_luma_csbp);
67
68 /*****************************************************************************/
69 /* */
70 /* Function Name : isvcd_compute_bs_non_mbaff_thread */
71 /* */
72 /* Description : This function computes the pointers of left,top & current*/
73 /* : Nnz, MvPred & deblk_mb_t and supplies to FillBs function
74 * for*/
75 /* : Boundary Strength Calculation .this function is used */
76 /* : BS being calculated in separate thread */
77 /* Inputs : pointer to decoder context,cur_mb_info,u4_mb_num */
78 /* Processing : */
79 /* */
80 /* Outputs : Produces the Boundary Strength for Current Mb */
81 /* Returns : None */
82 /* */
83 /* Revision History: */
84 /* */
85 /* DD MM YYYY Author(s) Changes (Describe the changes made) */
86 /* ITTIAM */
87 /*****************************************************************************/
88
isvcd_compute_bs_non_mbaff_thread(svc_dec_lyr_struct_t * ps_svc_lyr_dec,dec_mb_info_t * ps_cur_mb_info,UWORD32 u4_mb_num)89 void isvcd_compute_bs_non_mbaff_thread(svc_dec_lyr_struct_t *ps_svc_lyr_dec,
90 dec_mb_info_t *ps_cur_mb_info, UWORD32 u4_mb_num)
91 {
92 dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
93 /* Mvpred and Nnz for top and Courrent */
94 mv_pred_t *ps_cur_mv_pred, *ps_top_mv_pred = NULL, *ps_left_mv_pred;
95 /* deblk_mb_t Params */
96 deblk_mb_t *ps_cur_mb_params; /*< Parameters of current MacroBlock */
97 deblkmb_neighbour_t *ps_deblk_top_mb;
98
99 /* Reference Index to POC mapping*/
100 void **apv_map_ref_idx_to_poc;
101 UWORD32 u4_leftmbtype;
102
103 UWORD16 u2_left_csbp, u2_top_csbp, u2_cur_csbp;
104
105 /* Set of flags */
106 UWORD32 u4_cur_mb_intra, u1_top_mb_typ, u4_cur_mb_fld;
107 UWORD32 u4_cur_mb_ibl;
108 UWORD32 u1_cur_mb_type;
109 UWORD32 *pu4_bs_table;
110
111 UWORD16 *pu2_curr_res_luma_csbp;
112 UWORD16 *pu2_left_res_luma_csbp;
113 UWORD16 *pu2_top_res_luma_csbp;
114
115 /* Neighbour availability */
116 /* Initialization */
117 const UWORD32 u2_mbx = ps_cur_mb_info->u2_mbx;
118 const UWORD32 u2_mby = ps_cur_mb_info->u2_mby;
119 const UWORD32 u1_pingpong = u2_mbx & 0x01;
120
121 PROFILE_DISABLE_BOUNDARY_STRENGTH()
122 ps_deblk_top_mb = ps_dec->ps_deblk_top_mb + u2_mbx;
123
124 /* Pointer assignment for Current DeblkMB, Current Mv Pred */
125 ps_cur_mb_params = ps_dec->ps_deblk_pic + u4_mb_num;
126 ps_cur_mv_pred = ps_dec->s_cur_pic.ps_mv + (u4_mb_num << 4);
127
128 /*Pointer assignment for Residual NNZ */
129 pu2_curr_res_luma_csbp = ps_svc_lyr_dec->pu2_frm_res_luma_csbp + ps_cur_mb_info->u2_mbx;
130 pu2_curr_res_luma_csbp += ps_cur_mb_info->u2_mby * ps_svc_lyr_dec->i4_frm_res_luma_csbp_stride;
131
132 pu2_left_res_luma_csbp = pu2_curr_res_luma_csbp - (ps_cur_mb_info->u2_mbx != 0);
133 pu2_top_res_luma_csbp = pu2_curr_res_luma_csbp - ((ps_cur_mb_info->u2_mby != 0) *
134 ps_svc_lyr_dec->i4_frm_res_luma_csbp_stride);
135
136 apv_map_ref_idx_to_poc = (void **) ps_dec->ps_computebs_cur_slice->ppv_map_ref_idx_to_poc + 1;
137 u1_cur_mb_type = ps_cur_mb_params->u1_mb_type;
138 u1_top_mb_typ = ps_deblk_top_mb->u1_mb_type;
139 ps_deblk_top_mb->u1_mb_type = u1_cur_mb_type;
140
141 ps_cur_mb_params->u1_topmb_qp = ps_deblk_top_mb->u1_mb_qp;
142 ps_deblk_top_mb->u1_mb_qp = ps_cur_mb_params->u1_mb_qp;
143 ps_cur_mb_params->u1_left_mb_qp = ps_dec->deblk_left_mb[1].u1_mb_qp;
144 ps_dec->deblk_left_mb[1].u1_mb_qp = ps_cur_mb_params->u1_mb_qp;
145
146 /* if no deblocking required for current Mb then continue */
147 /* Check next Mbs in Mb group */
148 if(ps_cur_mb_params->u1_deblocking_mode & MB_DISABLE_FILTERING)
149 {
150 void **pu4_map_ref_idx_to_poc_l1 = apv_map_ref_idx_to_poc + POC_LIST_L0_TO_L1_DIFF;
151 {
152 /* Store Parameter for Top MvPred refernce frame Address */
153 void **ppv_top_mv_pred_addr = ps_cur_mb_info->ps_curmb->u4_pic_addrress;
154 WORD8 *p1_refTop0 = (ps_cur_mv_pred + 12)->i1_ref_frame;
155 WORD8 *p1_refTop1 = (ps_cur_mv_pred + 14)->i1_ref_frame;
156
157 /* Store Left addresses for Next Mb */
158 void **ppv_left_mv_pred_addr = ps_dec->ps_left_mvpred_addr[!u1_pingpong][1].u4_add;
159 WORD8 *p1_refleft0 = (ps_cur_mv_pred + 3)->i1_ref_frame;
160
161 ppv_top_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refTop0[0]];
162 ppv_top_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refTop0[1]];
163
164 ppv_left_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
165 ppv_top_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
166 ppv_left_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
167 ppv_top_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
168
169 ppv_left_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refleft0[0]];
170 ppv_left_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refleft0[1]];
171
172 /* Storing the leftMbtype for next Mb */
173 ps_dec->deblk_left_mb[1].u1_mb_type = ps_cur_mb_params->u1_mb_type;
174 }
175
176 return;
177 }
178
179 /* Flag for extra left Edge */
180 ps_cur_mb_params->u1_single_call = 1;
181
182 /* Update the Left deblk_mb_t and Left MvPred Parameters */
183 if(!u2_mbx)
184 {
185 u4_leftmbtype = 0;
186
187 /* Initialize the ps_left_mv_pred with Junk but Valid Location */
188 /* to avoid invalid memory access */
189 /* this is read only pointer */
190 ps_left_mv_pred = ps_cur_mv_pred + 3;
191 }
192 else
193 {
194 u4_leftmbtype = ps_dec->deblk_left_mb[1].u1_mb_type;
195
196 /* Come to Left Most Edge of the MB */
197 ps_left_mv_pred = ps_cur_mv_pred - (1 << 4) + 3;
198 }
199
200 if(!u2_mby) u1_top_mb_typ = 0;
201
202 /* MvPred Pointer Calculation */
203 ps_top_mv_pred = ps_cur_mv_pred - (ps_dec->u2_frm_wd_in_mbs << 4) + 12;
204 u4_cur_mb_intra = u1_cur_mb_type & D_INTRA_MB;
205 u4_cur_mb_ibl = u1_cur_mb_type & D_INTRA_IBL;
206 u4_cur_mb_fld = !!(u1_cur_mb_type & D_FLD_MB);
207 /* Compute BS function */
208 pu4_bs_table = ps_cur_mb_params->u4_bs_table;
209
210 u2_cur_csbp = ps_cur_mb_info->ps_curmb->u2_luma_csbp;
211 u2_left_csbp = ps_cur_mb_info->ps_left_mb->u2_luma_csbp;
212 u2_top_csbp = ps_cur_mb_info->ps_top_mb->u2_luma_csbp;
213
214 /* Compute BS function */
215 if((ps_dec->ps_cur_sps->u1_profile_idc == HIGH_PROFILE_IDC) ||
216 (ps_dec->ps_cur_sps->u1_profile_idc == HIGH_PROFILE_IDC) ||
217 (ps_dec->ps_cur_sps->u1_profile_idc == SCALABLE_HIGH_PROFILE_IDC) ||
218 (ps_dec->ps_cur_sps->u1_profile_idc == SCALABLE_BASELINE_PROFILE_IDC))
219 {
220 if(ps_cur_mb_info->u1_tran_form8x8 == 1)
221 {
222 u2_cur_csbp = ih264d_update_csbp_8x8(ps_cur_mb_info->ps_curmb->u2_luma_csbp);
223 ps_cur_mb_info->ps_curmb->u2_luma_csbp = u2_cur_csbp;
224 }
225 }
226 u2_cur_csbp |= *pu2_curr_res_luma_csbp;
227 u2_left_csbp |= *pu2_left_res_luma_csbp;
228 u2_top_csbp |= *pu2_top_res_luma_csbp;
229
230 if(u4_cur_mb_intra)
231 {
232 pu4_bs_table[4] = 0x04040404;
233 pu4_bs_table[0] = u4_cur_mb_fld ? 0x03030303 : 0x04040404;
234 pu4_bs_table[1] = 0x03030303;
235 pu4_bs_table[2] = 0x03030303;
236 pu4_bs_table[3] = 0x03030303;
237 pu4_bs_table[5] = 0x03030303;
238 pu4_bs_table[6] = 0x03030303;
239 pu4_bs_table[7] = 0x03030303;
240 }
241 else
242 {
243 isvcd_fill_bs_ibl(ps_cur_mb_params, u1_top_mb_typ, u4_leftmbtype, ps_cur_mb_info,
244 pu2_curr_res_luma_csbp, pu2_left_res_luma_csbp, pu2_top_res_luma_csbp);
245
246 if(!u4_cur_mb_ibl)
247 {
248 UWORD32 u4_is_non16x16 = !!(u1_cur_mb_type & D_PRED_NON_16x16);
249 UWORD32 u4_is_b = (ps_dec->ps_computebs_cur_slice->slice_type == B_SLICE);
250 UWORD32 u4_bs_0, u4_bs_4;
251
252 u4_bs_0 = pu4_bs_table[0];
253 u4_bs_4 = pu4_bs_table[4];
254
255 ih264d_fill_bs2_horz_vert(pu4_bs_table, u2_left_csbp, u2_top_csbp, u2_cur_csbp,
256 gau4_ih264d_packed_bs2, gau2_ih264d_4x4_v2h_reorder);
257
258 if(u4_leftmbtype & D_INTRA_MB)
259 {
260 pu4_bs_table[4] = 0x04040404;
261 }
262 else if(u4_leftmbtype & D_INTRA_IBL)
263 {
264 pu4_bs_table[4] = u4_bs_4;
265 }
266
267 if(u1_top_mb_typ & D_INTRA_MB)
268 {
269 pu4_bs_table[0] = u4_cur_mb_fld ? 0x03030303 : 0x04040404;
270 }
271 else if(u1_top_mb_typ & D_INTRA_IBL)
272 {
273 pu4_bs_table[0] = u4_bs_0;
274 }
275
276 ps_dec->pf_fill_bs1[u4_is_b][u4_is_non16x16](
277 ps_cur_mv_pred, ps_top_mv_pred, apv_map_ref_idx_to_poc, pu4_bs_table,
278 ps_left_mv_pred, &(ps_dec->ps_left_mvpred_addr[u1_pingpong][1]),
279 ps_cur_mb_info->ps_top_mb->u4_pic_addrress, (4 >> u4_cur_mb_fld));
280 }
281 }
282
283 {
284 void **pu4_map_ref_idx_to_poc_l1 = apv_map_ref_idx_to_poc + POC_LIST_L0_TO_L1_DIFF;
285 {
286 /* Store Parameter for Top MvPred refernce frame Address */
287 void **ppv_top_mv_pred_addr = ps_cur_mb_info->ps_curmb->u4_pic_addrress;
288 WORD8 *p1_refTop0 = (ps_cur_mv_pred + 12)->i1_ref_frame;
289 WORD8 *p1_refTop1 = (ps_cur_mv_pred + 14)->i1_ref_frame;
290
291 /* Store Left addresses for Next Mb */
292 void **ppv_left_mv_pred_addr = ps_dec->ps_left_mvpred_addr[!u1_pingpong][1].u4_add;
293 WORD8 *p1_refleft0 = (ps_cur_mv_pred + 3)->i1_ref_frame;
294
295 ppv_top_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refTop0[0]];
296 ppv_top_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refTop0[1]];
297
298 ppv_left_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
299 ppv_top_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
300 ppv_left_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
301 ppv_top_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
302
303 ppv_left_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refleft0[0]];
304 ppv_left_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refleft0[1]];
305
306 /* Storing the leftMbtype for next Mb */
307 ps_dec->deblk_left_mb[1].u1_mb_type = ps_cur_mb_params->u1_mb_type;
308 }
309 }
310
311 /* For transform 8x8 disable deblocking of the intrernal edges of a 8x8 block */
312 if(ps_cur_mb_info->u1_tran_form8x8)
313 {
314 pu4_bs_table[1] = 0;
315 pu4_bs_table[3] = 0;
316 pu4_bs_table[5] = 0;
317 pu4_bs_table[7] = 0;
318 }
319 }
320