Coverage Report

Created: 2024-07-27 06:35

/src/libavc/decoder/svc/isvcd_cabac.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_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
76
void isvcd_init_cabac_contexts(UWORD8 u1_slice_type, dec_struct_t *ps_dec)
77
6.04k
{
78
6.04k
    bin_ctxt_model_t *p_cabac_ctxt_table_t = ps_dec->p_cabac_ctxt_table_t;
79
6.04k
    UWORD8 u1_qp_y = ps_dec->ps_cur_slice->u1_slice_qp;
80
6.04k
    UWORD8 u1_cabac_init_Idc = 0;
81
82
6.04k
    if(I_SLICE != u1_slice_type)
83
4.86k
    {
84
4.86k
        u1_cabac_init_Idc = ps_dec->ps_cur_slice->u1_cabac_init_idc;
85
4.86k
    }
86
87
6.04k
    {
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
6.04k
        ctxt_inc_mb_info_t *p_DefCtxt = ps_dec->p_ctxt_inc_mb_map - 1;
92
6.04k
        UWORD8 *pu1_temp;
93
6.04k
        WORD8 i;
94
6.04k
        p_DefCtxt->u1_mb_type = CAB_SKIP;
95
6.04k
        p_DefCtxt->u1_cbp = 0x0f;
96
6.04k
        p_DefCtxt->u1_intra_chroma_pred_mode = 0;
97
6.04k
        p_DefCtxt->u1_yuv_dc_csbp = 0x7;
98
6.04k
        p_DefCtxt->u1_transform8x8_ctxt = 0;
99
100
6.04k
        pu1_temp = (UWORD8 *) p_DefCtxt->i1_ref_idx;
101
30.2k
        for(i = 0; i < 4; i++, pu1_temp++) (*pu1_temp) = 0;
102
6.04k
        pu1_temp = (UWORD8 *) p_DefCtxt->u1_mv;
103
102k
        for(i = 0; i < 16; i++, pu1_temp++) (*pu1_temp) = 0;
104
6.04k
        ps_dec->ps_def_ctxt_mb_info = p_DefCtxt;
105
6.04k
    }
106
107
6.04k
    if(u1_slice_type == I_SLICE)
108
1.18k
    {
109
1.18k
        u1_cabac_init_Idc = 3;
110
1.18k
        ps_dec->p_mb_type_t = p_cabac_ctxt_table_t + MB_TYPE_I_SLICE;
111
1.18k
    }
112
4.86k
    else if(u1_slice_type == P_SLICE)
113
2.30k
    {
114
2.30k
        ps_dec->p_mb_type_t = p_cabac_ctxt_table_t + MB_TYPE_P_SLICE;
115
2.30k
        ps_dec->p_mb_skip_flag_t = p_cabac_ctxt_table_t + MB_SKIP_FLAG_P_SLICE;
116
2.30k
        ps_dec->p_sub_mb_type_t = p_cabac_ctxt_table_t + SUB_MB_TYPE_P_SLICE;
117
2.30k
    }
118
2.56k
    else if(u1_slice_type == B_SLICE)
119
2.56k
    {
120
2.56k
        ps_dec->p_mb_type_t = p_cabac_ctxt_table_t + MB_TYPE_B_SLICE;
121
2.56k
        ps_dec->p_mb_skip_flag_t = p_cabac_ctxt_table_t + MB_SKIP_FLAG_B_SLICE;
122
2.56k
        ps_dec->p_sub_mb_type_t = p_cabac_ctxt_table_t + SUB_MB_TYPE_B_SLICE;
123
2.56k
    }
124
6.04k
    {
125
6.04k
        bin_ctxt_model_t *p_cabac_ctxt_table_t_tmp = p_cabac_ctxt_table_t;
126
6.04k
        if(ps_dec->ps_cur_slice->u1_field_pic_flag)
127
0
        {
128
0
            p_cabac_ctxt_table_t_tmp += SIGNIFICANT_COEFF_FLAG_FLD;
129
0
        }
130
6.04k
        else
131
6.04k
        {
132
6.04k
            p_cabac_ctxt_table_t_tmp += SIGNIFICANT_COEFF_FLAG_FRAME;
133
6.04k
        }
134
6.04k
        {
135
6.04k
            bin_ctxt_model_t **p_significant_coeff_flag_t = ps_dec->p_significant_coeff_flag_t;
136
6.04k
            p_significant_coeff_flag_t[0] = p_cabac_ctxt_table_t_tmp + SIG_COEFF_CTXT_CAT_0_OFFSET;
137
6.04k
            p_significant_coeff_flag_t[1] = p_cabac_ctxt_table_t_tmp + SIG_COEFF_CTXT_CAT_1_OFFSET;
138
6.04k
            p_significant_coeff_flag_t[2] = p_cabac_ctxt_table_t_tmp + SIG_COEFF_CTXT_CAT_2_OFFSET;
139
6.04k
            p_significant_coeff_flag_t[3] = p_cabac_ctxt_table_t_tmp + SIG_COEFF_CTXT_CAT_3_OFFSET;
140
6.04k
            p_significant_coeff_flag_t[4] = p_cabac_ctxt_table_t_tmp + SIG_COEFF_CTXT_CAT_4_OFFSET;
141
142
6.04k
            p_significant_coeff_flag_t[5] = p_cabac_ctxt_table_t_tmp + SIG_COEFF_CTXT_CAT_5_OFFSET;
143
6.04k
        }
144
6.04k
    }
145
146
6.04k
    memcpy(p_cabac_ctxt_table_t, gau1_isvcd_cabac_ctxt_init_table[u1_cabac_init_Idc][u1_qp_y],
147
6.04k
           NUM_CABAC_CTXTS_SVC * sizeof(bin_ctxt_model_t));
148
6.04k
}