xref: /OK3568_Linux_fs/external/mpp/mpp/hal/rkdec/h265d/hal_h265d_com.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  *
3  * Copyright 2020 Rockchip Electronics Co. LTD
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 #ifndef __HAL_H265D_COM_H__
19 #define __HAL_H265D_COM_H__
20 
21 #include "rk_type.h"
22 
23 #define SCALING_LIST_SIZE       (81 * 1360)
24 #define RPS_SIZE                (600 * 32)
25 #define SCALING_LIST_SIZE_NUM   4
26 
27 #define L0          0
28 #define L1          1
29 #define MAX_REFS    16
30 
31 #define IS_IDR(nal_type)    (nal_type == 19 || nal_type == 20)
32 #define IS_BLA(nal_type)    (nal_type == 17 || nal_type == 16 || nal_type == 18)
33 #define IS_IRAP(nal_type)   (nal_type >= 16 && nal_type <= 23)
34 
35 enum RPSType {
36     ST_CURR_BEF = 0,
37     ST_CURR_AFT,
38     ST_FOLL,
39     LT_CURR,
40     LT_FOLL,
41     NB_RPS_TYPE,
42 };
43 
44 enum SliceType {
45     B_SLICE = 0,
46     P_SLICE = 1,
47     I_SLICE = 2,
48 };
49 
50 typedef struct slice_ref_map {
51     RK_U8 dpb_index;
52     RK_U8 is_long_term;
53 } slice_ref_map_t;
54 
55 typedef struct ShortTermRPS {
56     RK_U32 num_negative_pics;
57     RK_S32 num_delta_pocs;
58     RK_S32 delta_poc[32];
59     RK_U8  used[32];
60 } ShortTermRPS;
61 
62 typedef struct LongTermRPS {
63     RK_S32  poc[32];
64     RK_U8   used[32];
65     RK_U8   nb_refs;
66 } LongTermRPS;
67 
68 typedef struct RefPicList {
69     RK_U32  dpb_index[MAX_REFS];
70     RK_U32 nb_refs;
71 } RefPicList_t;
72 
73 typedef struct RefPicListTab {
74     RefPicList_t refPicList[2];
75 } RefPicListTab_t;
76 
77 typedef struct SliceHeader {
78     RK_U32 pps_id;
79 
80     ///< address (in raster order) of the first block in the current slice segment
81     RK_U32   slice_segment_addr;
82     ///< address (in raster order) of the first block in the current slice
83     RK_U32   slice_addr;
84 
85     enum SliceType slice_type;
86 
87     RK_S32 pic_order_cnt_lsb;
88 
89     RK_U8 first_slice_in_pic_flag;
90     RK_U8 dependent_slice_segment_flag;
91     RK_U8 pic_output_flag;
92     RK_U8 colour_plane_id;
93 
94     ///< RPS coded in the slice header itself is stored here
95     ShortTermRPS slice_rps;
96     const ShortTermRPS *short_term_rps;
97     LongTermRPS long_term_rps;
98     RK_U32 list_entry_lx[2][32];
99 
100     RK_U8 rpl_modification_flag[2];
101     RK_U8 no_output_of_prior_pics_flag;
102     RK_U8 slice_temporal_mvp_enabled_flag;
103 
104     RK_U32 nb_refs[2];
105 
106     RK_U8 slice_sample_adaptive_offset_flag[3];
107     RK_U8 mvd_l1_zero_flag;
108 
109     RK_U8 cabac_init_flag;
110     RK_U8 disable_deblocking_filter_flag; ///< slice_header_disable_deblocking_filter_flag
111     RK_U8 slice_loop_filter_across_slices_enabled_flag;
112     RK_U8 collocated_list;
113 
114     RK_U32 collocated_ref_idx;
115 
116     RK_S32 slice_qp_delta;
117     RK_S32 slice_cb_qp_offset;
118     RK_S32 slice_cr_qp_offset;
119 
120     RK_S32 beta_offset;    ///< beta_offset_div2 * 2
121     RK_S32 tc_offset;      ///< tc_offset_div2 * 2
122 
123     RK_U32 max_num_merge_cand; ///< 5 - 5_minus_max_num_merge_cand
124 
125     RK_S32 *entry_point_offset;
126     RK_S32 * offset;
127     RK_S32 * size;
128     RK_S32 num_entry_point_offsets;
129 
130     RK_S8 slice_qp;
131 
132     RK_U8 luma_log2_weight_denom;
133     RK_S16 chroma_log2_weight_denom;
134 
135     RK_S32 slice_ctb_addr_rs;
136 } SliceHeader_t;
137 
138 extern RK_U8 hal_hevc_diag_scan4x4_x[16];
139 extern RK_U8 hal_hevc_diag_scan4x4_y[16];
140 extern RK_U8 hal_hevc_diag_scan8x8_x[64];
141 extern RK_U8 hal_hevc_diag_scan8x8_y[64];
142 extern RK_U8 cabac_table[27456];
143 
144 #ifdef __cplusplus
145 extern "C" {
146 #endif
147 
148 RK_U32 hevc_ver_align(RK_U32 val);
149 RK_U32 hevc_hor_align(RK_U32 val);
150 void hal_record_scaling_list(scalingFactor_t *pScalingFactor_out, scalingList_t *pScalingList);
151 RK_S32 hal_h265d_slice_hw_rps(void *dxva, void *rps_buf, void* sw_rps_buf, RK_U32 fast_mode);
152 RK_S32 hal_h265d_slice_output_rps(void *dxva, void *rps_buf);
153 void hal_h265d_output_scalinglist_packet(void *hal, void *ptr, void *dxva);
154 
155 #ifdef __cplusplus
156 }
157 #endif
158 
159 #endif /*__HAL_H265D_COM_H__*/
160