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