Coverage Report

Created: 2024-07-27 06:35

/src/libavc/decoder/svc/isvcd_thread_compute_bs.c
Line
Count
Source (jump to first uncovered line)
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
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
526k
{
92
526k
    dec_struct_t *ps_dec = &ps_svc_lyr_dec->s_dec;
93
    /* Mvpred and Nnz for top and Courrent */
94
526k
    mv_pred_t *ps_cur_mv_pred, *ps_top_mv_pred = NULL, *ps_left_mv_pred;
95
    /* deblk_mb_t Params */
96
526k
    deblk_mb_t *ps_cur_mb_params; /*< Parameters of current MacroBlock */
97
526k
    deblkmb_neighbour_t *ps_deblk_top_mb;
98
99
    /* Reference Index to POC mapping*/
100
526k
    void **apv_map_ref_idx_to_poc;
101
526k
    UWORD32 u4_leftmbtype;
102
103
526k
    UWORD16 u2_left_csbp, u2_top_csbp, u2_cur_csbp;
104
105
    /* Set of flags */
106
526k
    UWORD32 u4_cur_mb_intra, u1_top_mb_typ, u4_cur_mb_fld;
107
526k
    UWORD32 u4_cur_mb_ibl;
108
526k
    UWORD32 u1_cur_mb_type;
109
526k
    UWORD32 *pu4_bs_table;
110
111
526k
    UWORD16 *pu2_curr_res_luma_csbp;
112
526k
    UWORD16 *pu2_left_res_luma_csbp;
113
526k
    UWORD16 *pu2_top_res_luma_csbp;
114
115
    /* Neighbour availability */
116
    /* Initialization */
117
526k
    const UWORD32 u2_mbx = ps_cur_mb_info->u2_mbx;
118
526k
    const UWORD32 u2_mby = ps_cur_mb_info->u2_mby;
119
526k
    const UWORD32 u1_pingpong = u2_mbx & 0x01;
120
121
526k
    PROFILE_DISABLE_BOUNDARY_STRENGTH()
122
526k
    ps_deblk_top_mb = ps_dec->ps_deblk_top_mb + u2_mbx;
123
124
    /* Pointer assignment for Current DeblkMB, Current Mv Pred  */
125
526k
    ps_cur_mb_params = ps_dec->ps_deblk_pic + u4_mb_num;
126
526k
    ps_cur_mv_pred = ps_dec->s_cur_pic.ps_mv + (u4_mb_num << 4);
127
128
    /*Pointer assignment for Residual NNZ */
129
526k
    pu2_curr_res_luma_csbp = ps_svc_lyr_dec->pu2_frm_res_luma_csbp + ps_cur_mb_info->u2_mbx;
130
526k
    pu2_curr_res_luma_csbp += ps_cur_mb_info->u2_mby * ps_svc_lyr_dec->i4_frm_res_luma_csbp_stride;
131
132
526k
    pu2_left_res_luma_csbp = pu2_curr_res_luma_csbp - (ps_cur_mb_info->u2_mbx != 0);
133
526k
    pu2_top_res_luma_csbp = pu2_curr_res_luma_csbp - ((ps_cur_mb_info->u2_mby != 0) *
134
526k
                                                      ps_svc_lyr_dec->i4_frm_res_luma_csbp_stride);
135
136
526k
    apv_map_ref_idx_to_poc = (void **) ps_dec->ps_computebs_cur_slice->ppv_map_ref_idx_to_poc + 1;
137
526k
    u1_cur_mb_type = ps_cur_mb_params->u1_mb_type;
138
526k
    u1_top_mb_typ = ps_deblk_top_mb->u1_mb_type;
139
526k
    ps_deblk_top_mb->u1_mb_type = u1_cur_mb_type;
140
141
526k
    ps_cur_mb_params->u1_topmb_qp = ps_deblk_top_mb->u1_mb_qp;
142
526k
    ps_deblk_top_mb->u1_mb_qp = ps_cur_mb_params->u1_mb_qp;
143
526k
    ps_cur_mb_params->u1_left_mb_qp = ps_dec->deblk_left_mb[1].u1_mb_qp;
144
526k
    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
526k
    if(ps_cur_mb_params->u1_deblocking_mode & MB_DISABLE_FILTERING)
149
35.7k
    {
150
35.7k
        void **pu4_map_ref_idx_to_poc_l1 = apv_map_ref_idx_to_poc + POC_LIST_L0_TO_L1_DIFF;
151
35.7k
        {
152
            /* Store Parameter for Top MvPred refernce frame Address */
153
35.7k
            void **ppv_top_mv_pred_addr = ps_cur_mb_info->ps_curmb->u4_pic_addrress;
154
35.7k
            WORD8 *p1_refTop0 = (ps_cur_mv_pred + 12)->i1_ref_frame;
155
35.7k
            WORD8 *p1_refTop1 = (ps_cur_mv_pred + 14)->i1_ref_frame;
156
157
            /* Store Left addresses for Next Mb   */
158
35.7k
            void **ppv_left_mv_pred_addr = ps_dec->ps_left_mvpred_addr[!u1_pingpong][1].u4_add;
159
35.7k
            WORD8 *p1_refleft0 = (ps_cur_mv_pred + 3)->i1_ref_frame;
160
161
35.7k
            ppv_top_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refTop0[0]];
162
35.7k
            ppv_top_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refTop0[1]];
163
164
35.7k
            ppv_left_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
165
35.7k
            ppv_top_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
166
35.7k
            ppv_left_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
167
35.7k
            ppv_top_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
168
169
35.7k
            ppv_left_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refleft0[0]];
170
35.7k
            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
35.7k
            ps_dec->deblk_left_mb[1].u1_mb_type = ps_cur_mb_params->u1_mb_type;
174
35.7k
        }
175
176
35.7k
        return;
177
35.7k
    }
178
179
    /* Flag for extra left Edge */
180
490k
    ps_cur_mb_params->u1_single_call = 1;
181
182
    /* Update the Left deblk_mb_t and Left MvPred Parameters */
183
490k
    if(!u2_mbx)
184
74.8k
    {
185
74.8k
        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
74.8k
        ps_left_mv_pred = ps_cur_mv_pred + 3;
191
74.8k
    }
192
415k
    else
193
415k
    {
194
415k
        u4_leftmbtype = ps_dec->deblk_left_mb[1].u1_mb_type;
195
196
        /* Come to Left Most Edge of the MB */
197
415k
        ps_left_mv_pred = ps_cur_mv_pred - (1 << 4) + 3;
198
415k
    }
199
200
490k
    if(!u2_mby) u1_top_mb_typ = 0;
201
202
    /* MvPred Pointer Calculation */
203
490k
    ps_top_mv_pred = ps_cur_mv_pred - (ps_dec->u2_frm_wd_in_mbs << 4) + 12;
204
490k
    u4_cur_mb_intra = u1_cur_mb_type & D_INTRA_MB;
205
490k
    u4_cur_mb_ibl = u1_cur_mb_type & D_INTRA_IBL;
206
490k
    u4_cur_mb_fld = !!(u1_cur_mb_type & D_FLD_MB);
207
    /* Compute BS function */
208
490k
    pu4_bs_table = ps_cur_mb_params->u4_bs_table;
209
210
490k
    u2_cur_csbp = ps_cur_mb_info->ps_curmb->u2_luma_csbp;
211
490k
    u2_left_csbp = ps_cur_mb_info->ps_left_mb->u2_luma_csbp;
212
490k
    u2_top_csbp = ps_cur_mb_info->ps_top_mb->u2_luma_csbp;
213
214
    /* Compute BS function */
215
490k
    if((ps_dec->ps_cur_sps->u1_profile_idc == HIGH_PROFILE_IDC) ||
216
490k
       (ps_dec->ps_cur_sps->u1_profile_idc == HIGH_PROFILE_IDC) ||
217
490k
       (ps_dec->ps_cur_sps->u1_profile_idc == SCALABLE_HIGH_PROFILE_IDC) ||
218
490k
       (ps_dec->ps_cur_sps->u1_profile_idc == SCALABLE_BASELINE_PROFILE_IDC))
219
47.1k
    {
220
47.1k
        if(ps_cur_mb_info->u1_tran_form8x8 == 1)
221
5.41k
        {
222
5.41k
            u2_cur_csbp = ih264d_update_csbp_8x8(ps_cur_mb_info->ps_curmb->u2_luma_csbp);
223
5.41k
            ps_cur_mb_info->ps_curmb->u2_luma_csbp = u2_cur_csbp;
224
5.41k
        }
225
47.1k
    }
226
490k
    u2_cur_csbp |= *pu2_curr_res_luma_csbp;
227
490k
    u2_left_csbp |= *pu2_left_res_luma_csbp;
228
490k
    u2_top_csbp |= *pu2_top_res_luma_csbp;
229
230
490k
    if(u4_cur_mb_intra)
231
13.5k
    {
232
13.5k
        pu4_bs_table[4] = 0x04040404;
233
13.5k
        pu4_bs_table[0] = u4_cur_mb_fld ? 0x03030303 : 0x04040404;
234
13.5k
        pu4_bs_table[1] = 0x03030303;
235
13.5k
        pu4_bs_table[2] = 0x03030303;
236
13.5k
        pu4_bs_table[3] = 0x03030303;
237
13.5k
        pu4_bs_table[5] = 0x03030303;
238
13.5k
        pu4_bs_table[6] = 0x03030303;
239
13.5k
        pu4_bs_table[7] = 0x03030303;
240
13.5k
    }
241
476k
    else
242
476k
    {
243
476k
        isvcd_fill_bs_ibl(ps_cur_mb_params, u1_top_mb_typ, u4_leftmbtype, ps_cur_mb_info,
244
476k
                          pu2_curr_res_luma_csbp, pu2_left_res_luma_csbp, pu2_top_res_luma_csbp);
245
246
476k
        if(!u4_cur_mb_ibl)
247
452k
        {
248
452k
            UWORD32 u4_is_non16x16 = !!(u1_cur_mb_type & D_PRED_NON_16x16);
249
452k
            UWORD32 u4_is_b = (ps_dec->ps_computebs_cur_slice->slice_type == B_SLICE);
250
452k
            UWORD32 u4_bs_0, u4_bs_4;
251
252
452k
            u4_bs_0 = pu4_bs_table[0];
253
452k
            u4_bs_4 = pu4_bs_table[4];
254
255
452k
            ih264d_fill_bs2_horz_vert(pu4_bs_table, u2_left_csbp, u2_top_csbp, u2_cur_csbp,
256
452k
                                      gau4_ih264d_packed_bs2, gau2_ih264d_4x4_v2h_reorder);
257
258
452k
            if(u4_leftmbtype & D_INTRA_MB)
259
1.71k
            {
260
1.71k
                pu4_bs_table[4] = 0x04040404;
261
1.71k
            }
262
451k
            else if(u4_leftmbtype & D_INTRA_IBL)
263
2.19k
            {
264
2.19k
                pu4_bs_table[4] = u4_bs_4;
265
2.19k
            }
266
267
452k
            if(u1_top_mb_typ & D_INTRA_MB)
268
1.75k
            {
269
1.75k
                pu4_bs_table[0] = u4_cur_mb_fld ? 0x03030303 : 0x04040404;
270
1.75k
            }
271
451k
            else if(u1_top_mb_typ & D_INTRA_IBL)
272
3.51k
            {
273
3.51k
                pu4_bs_table[0] = u4_bs_0;
274
3.51k
            }
275
276
452k
            ps_dec->pf_fill_bs1[u4_is_b][u4_is_non16x16](
277
452k
                ps_cur_mv_pred, ps_top_mv_pred, apv_map_ref_idx_to_poc, pu4_bs_table,
278
452k
                ps_left_mv_pred, &(ps_dec->ps_left_mvpred_addr[u1_pingpong][1]),
279
452k
                ps_cur_mb_info->ps_top_mb->u4_pic_addrress, (4 >> u4_cur_mb_fld));
280
452k
        }
281
476k
    }
282
283
490k
    {
284
490k
        void **pu4_map_ref_idx_to_poc_l1 = apv_map_ref_idx_to_poc + POC_LIST_L0_TO_L1_DIFF;
285
490k
        {
286
            /* Store Parameter for Top MvPred refernce frame Address */
287
490k
            void **ppv_top_mv_pred_addr = ps_cur_mb_info->ps_curmb->u4_pic_addrress;
288
490k
            WORD8 *p1_refTop0 = (ps_cur_mv_pred + 12)->i1_ref_frame;
289
490k
            WORD8 *p1_refTop1 = (ps_cur_mv_pred + 14)->i1_ref_frame;
290
291
            /* Store Left addresses for Next Mb   */
292
490k
            void **ppv_left_mv_pred_addr = ps_dec->ps_left_mvpred_addr[!u1_pingpong][1].u4_add;
293
490k
            WORD8 *p1_refleft0 = (ps_cur_mv_pred + 3)->i1_ref_frame;
294
295
490k
            ppv_top_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refTop0[0]];
296
490k
            ppv_top_mv_pred_addr[1] = pu4_map_ref_idx_to_poc_l1[p1_refTop0[1]];
297
298
490k
            ppv_left_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
299
490k
            ppv_top_mv_pred_addr[2] = apv_map_ref_idx_to_poc[p1_refTop1[0]];
300
490k
            ppv_left_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
301
490k
            ppv_top_mv_pred_addr[3] = pu4_map_ref_idx_to_poc_l1[p1_refTop1[1]];
302
303
490k
            ppv_left_mv_pred_addr[0] = apv_map_ref_idx_to_poc[p1_refleft0[0]];
304
490k
            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
490k
            ps_dec->deblk_left_mb[1].u1_mb_type = ps_cur_mb_params->u1_mb_type;
308
490k
        }
309
490k
    }
310
311
    /* For transform 8x8 disable deblocking of the intrernal edges of a 8x8 block */
312
490k
    if(ps_cur_mb_info->u1_tran_form8x8)
313
9.09k
    {
314
9.09k
        pu4_bs_table[1] = 0;
315
9.09k
        pu4_bs_table[3] = 0;
316
9.09k
        pu4_bs_table[5] = 0;
317
9.09k
        pu4_bs_table[7] = 0;
318
9.09k
    }
319
490k
}