xref: /rockchip-linux_mpp/mpp/codec/enc/h264/h264e_slice.h (revision 437bfbeb9567cca9cd9080e3f6954aa9d6a94f18)
1 /*
2  * Copyright 2015 Rockchip Electronics Co. LTD
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __H264E_SLICE_H__
18 #define __H264E_SLICE_H__
19 
20 #include "mpp_enc_cfg.h"
21 
22 #include "h264e_syntax.h"
23 #include "h264e_sps.h"
24 #include "h264e_pps.h"
25 
26 /*
27  * For H.264 encoder slice header process.
28  * Remove some syntax that encoder not supported.
29  * Field, mbaff, B slice are not supported yet.
30  *
31  * The reorder and mmco syntax will be create by dpb and attach to slice.
32  * Then slice syntax will be passed to hal to config hardware or modify the
33  * hardware stream.
34  */
35 
36 /* reference picture list modification operation */
37 typedef struct H264eRplmo_t {
38     RK_S32      modification_of_pic_nums_idc;
39     RK_S32      abs_diff_pic_num_minus1;
40     RK_S32      long_term_pic_idx;
41     RK_S32      abs_diff_view_idx_minus1;
42 } H264eRplmo;
43 
44 typedef struct H264eReorderInfo_t {
45     RK_S32      rd_cnt;
46     RK_S32      wr_cnt;
47     RK_S32      size;
48     H264eRplmo  ops[H264E_MAX_REFS_CNT];
49 } H264eReorderInfo;
50 
51 /*
52  * mmco (Memory management control operation) value
53  * 0 - End memory_management_control_operation syntax element loop
54  * 1 - Mark a short-term reference picture as "unused for reference"
55  * 2 - Mark a long-term reference picture as "unused for reference"
56  * 3 - Mark a short-term reference picture as "used for long-term
57  *     reference" and assign a long-term frame index to it
58  * 4 - Specify the maximum long-term frame index and mark all long-term
59  *     reference pictures having long-term frame indices greater than
60  *     the maximum value as "unused for reference"
61  * 5 - Mark all reference pictures as "unused for reference" and set the
62  *     MaxLongTermFrameIdx variable to "no long-term frame indices"
63  * 6 - Mark the current picture as "used for long-term reference" and
64  *     assign a long-term frame index to it
65  */
66 typedef struct H264eMmco_t {
67     RK_S32      mmco;
68     RK_S32      difference_of_pic_nums_minus1;   // for MMCO 1 & 3
69     RK_S32      long_term_pic_num;               // for MMCO 2
70     RK_S32      long_term_frame_idx;             // for MMCO 3 & 6
71     RK_S32      max_long_term_frame_idx_plus1;   // for MMCO 4
72 } H264eMmco;
73 
74 #define MAX_H264E_MMCO_CNT      8
75 
76 typedef struct H264eMarkingInfo_t {
77     RK_S32      idr_flag;
78     /* idr marking flag */
79     RK_S32      no_output_of_prior_pics;
80     RK_S32      long_term_reference_flag;
81     /* non-idr marking flag */
82     RK_S32      adaptive_ref_pic_buffering;
83     RK_S32      rd_cnt;
84     RK_S32      wr_cnt;
85     RK_S32      size;
86     H264eMmco   ops[MAX_H264E_MMCO_CNT];
87 } H264eMarkingInfo;
88 
89 typedef struct H264eSlice_t {
90     /* Copy of sps/pps parameter */
91     RK_S32      mb_w;
92     RK_S32      mb_h;
93     RK_U32      max_num_ref_frames;
94     RK_U32      entropy_coding_mode;
95     RK_S32      log2_max_frame_num;
96     RK_S32      log2_max_poc_lsb;
97     RK_S32      pic_order_cnt_type;
98     RK_S32      qp_init;
99 
100     /* Nal parameters */
101     RK_S32      nal_reference_idc;
102     RK_S32      nalu_type;
103 
104     /* Unchanged parameters  */
105     RK_U32      first_mb_in_slice;
106     RK_U32      slice_type;
107     RK_U32      pic_parameter_set_id;
108     RK_S32      frame_num;
109     RK_S32      num_ref_idx_override;
110     RK_S32      qp_delta;
111     RK_U32      cabac_init_idc;
112     RK_U32      disable_deblocking_filter_idc;
113     RK_S32      slice_alpha_c0_offset_div2;
114     RK_S32      slice_beta_offset_div2;
115 
116     /* reorder parameter */
117     RK_S32      ref_pic_list_modification_flag;
118     H264eReorderInfo    *reorder;
119     H264eMarkingInfo    *marking;
120 
121     RK_S32      idr_flag;
122     RK_U32      idr_pic_id;
123     RK_U32      next_idr_pic_id;
124     /* for poc mode 0 */
125     RK_U32      pic_order_cnt_lsb;
126     RK_S32      num_ref_idx_active;
127     /* idr mmco flag */
128     RK_S32      no_output_of_prior_pics;
129     RK_S32      long_term_reference_flag;
130 
131     /* Changable parameters  */
132     RK_S32      adaptive_ref_pic_buffering;
133 
134     /* for multi-slice writing */
135     RK_S32      is_multi_slice;
136 } H264eSlice;
137 
138 #ifdef  __cplusplus
139 extern "C" {
140 #endif
141 
142 /*
143  * reorder context for both dpb and slice
144  */
145 MPP_RET h264e_reorder_init(H264eReorderInfo *reorder);
146 MPP_RET h264e_reorder_wr_rewind(H264eReorderInfo *info);
147 MPP_RET h264e_reorder_rd_rewind(H264eReorderInfo *info);
148 MPP_RET h264e_reorder_wr_op(H264eReorderInfo *info, H264eRplmo *op);
149 MPP_RET h264e_reorder_rd_op(H264eReorderInfo *info, H264eRplmo *op);
150 
151 /* mmco context for both dpb and slice */
152 MPP_RET h264e_marking_init(H264eMarkingInfo *marking);
153 RK_S32 h264e_marking_is_empty(H264eMarkingInfo *info);
154 MPP_RET h264e_marking_wr_rewind(H264eMarkingInfo *marking);
155 MPP_RET h264e_marking_rd_rewind(H264eMarkingInfo *marking);
156 MPP_RET h264e_marking_wr_op(H264eMarkingInfo *info, H264eMmco *op);
157 MPP_RET h264e_marking_rd_op(H264eMarkingInfo *info, H264eMmco *op);
158 
159 /*
160  * h264e_slice_update is called only on cfg is update.
161  * When cfg has no changes just use slice next to setup
162  */
163 void h264e_slice_init(H264eSlice *slice, H264eReorderInfo *reorder,
164                       H264eMarkingInfo *marking);
165 RK_S32 h264e_slice_update(H264eSlice *slice, MppEncCfgSet *cfg,
166                           H264eSps *sps, H264ePps *pps,
167                           H264eDpbFrm *frm);
168 
169 RK_S32 h264e_slice_read(H264eSlice *slice, void *p, RK_S32 size);
170 RK_S32 h264e_slice_write(H264eSlice *slice, void *p, RK_U32 size);
171 RK_S32 h264e_slice_write_pskip(H264eSlice *slice, void *p, RK_U32 size);
172 RK_S32 h264e_slice_move(RK_U8 *dst, RK_U8 *src, RK_S32 dst_bit, RK_S32 src_bit,
173                         RK_S32 src_size);
174 
175 RK_S32 h264e_slice_write_prefix_nal_unit_svc(H264ePrefixNal *nal, void *p, RK_S32 size);
176 
177 #ifdef __cplusplus
178 }
179 #endif
180 
181 #endif /* __H264E_SLICE_H__ */
182