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 __H265E_DPB_H__ 18 #define __H265E_DPB_H__ 19 20 #include "mpp_buffer.h" 21 #include "h265e_slice.h" 22 #include "h265_syntax.h" 23 #include "mpp_enc_cfg.h" 24 25 /* 26 * H.265 encoder dpb structure info 27 * 28 * +----------+ DPB +-> build list +-> REF_LIST 29 * | + + 30 * v v v 31 * FRM_BUF_GRP DPB_FRM +------+------> RPS 32 * + + 33 * | v 34 * +--------> FRM_BUF 35 * 36 * H265eDpb is overall structure contain the whole dpb info. 37 * It is composed H265eDpbFrm and H265eRpsList. 38 * 39 */ 40 41 #define H265E_MAX_BUF_CNT 8 42 #define H265_MAX_GOP 64 ///< max. value of hierarchical GOP size 43 #define H265_MAX_GOP_CNT (H265_MAX_GOP + 1) 44 45 #define RPSLIST_MAX (H265_MAX_GOP * 3) 46 47 typedef struct H265eDpb_t H265eDpb; 48 typedef struct H265eReferencePictureSet_e H265eReferencePictureSet; 49 typedef struct H265eRefPicListModification_e H265eRefPicListModification; 50 typedef struct H265eSlice_e H265eSlice; 51 52 53 typedef struct H265eDpb_t H265eDpb; 54 55 /* 56 * Split reference frame configure to two parts 57 * The first part is slice depended info like poc / frame_num, and frame 58 * type and flags. 59 * The other part is gop structure depended info like gop index, ref_status 60 * and ref_frm_index. This part is inited from dpb gop hierarchy info. 61 */ 62 63 typedef struct H265eDpbFrm_t { 64 H265eDpb *dpb; 65 66 RK_S32 slot_idx; 67 RK_S32 seq_idx; 68 RK_S32 gop_idx; 69 RK_S32 gop_cnt; 70 RK_S32 prev_ref_idx; 71 EncFrmStatus status; 72 73 union { 74 RK_U32 on_used; 75 struct { 76 RK_U32 dpb_used : 8; 77 RK_U32 hal_used : 8; 78 }; 79 }; 80 RK_U32 inited; 81 82 RK_U32 is_long_term; 83 RK_U32 used_by_cur; 84 RK_U32 check_lt_msb; 85 RK_S32 poc; 86 87 H265eSlice *slice; 88 89 RK_S64 pts; 90 RK_S64 dts; 91 92 RK_U32 is_key_frame; 93 } H265eDpbFrm; 94 95 typedef struct H265eRpsList_e { 96 RK_S32 lt_num; 97 RK_S32 st_num; 98 RK_S32 poc_cur_list; 99 100 RK_S32 poc[RPSLIST_MAX]; 101 102 RK_U32 used_by_cur[MAX_REFS]; 103 104 H265eRefPicListModification *m_RefPicListModification; 105 } H265eRpsList; 106 107 108 /* 109 * dpb frame arrangement 110 * 111 * If dpb size is 3 then dpb frame will be total 4 frames. 112 * Then the frame 3 is always current frame and frame 0~2 is reference frame 113 * in the gop structure. 114 * 115 * When one frame is encoded all it info will be moved to its gop position for 116 * next frame encoding. 117 */ 118 typedef struct H265eDpb_t { 119 RK_S32 seq_idx; 120 RK_S32 gop_idx; 121 122 // status and count for one gop structure 123 RK_S32 last_idr; 124 RK_S32 poc_cra; 125 RK_U32 refresh_pending; 126 RK_S32 max_ref_l0; 127 RK_S32 max_ref_l1; 128 129 H265eRpsList RpsList; 130 H265eDpbFrm *curr; 131 H265eDpbFrm frame_list[MAX_REFS + 1]; 132 } H265eDpb; 133 134 #ifdef __cplusplus 135 extern "C" { 136 #endif 137 138 void h265e_set_ref_list(H265eRpsList *RpsList, H265eReferencePictureSet *m_pRps); 139 MPP_RET h265e_dpb_init(H265eDpb **dpb); 140 MPP_RET h265e_dpb_deinit(H265eDpb *dpb); 141 MPP_RET h265e_dpb_setup_buf_size(H265eDpb *dpb, RK_U32 size[], RK_U32 count); 142 MPP_RET h265e_dpb_get_curr(H265eDpb *dpb); 143 void h265e_dpb_build_list(H265eDpb *dpb, EncCpbStatus *cpb); 144 void h265e_dpb_proc_cpb(H265eDpb *dpb, EncCpbStatus *cpb); 145 146 /* 147 * hal usage flag mark / unmark function 148 */ 149 MPP_RET h265e_dpb_hal_start(H265eDpb *dpb, RK_S32 slot_idx); 150 MPP_RET h265e_dpb_hal_end(H265eDpb *dpb, RK_S32 slot_idx); 151 152 #define h265e_dpb_dump_frms(dpb) h265e_dpb_dump_frm(dpb, __FUNCTION__) 153 154 void h265e_dpb_dump_frm(H265eDpb *dpb, const char *caller); 155 156 #ifdef __cplusplus 157 } 158 #endif 159 160 #endif /* __H265E_DPB_H__ */ 161