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 EncFrmStatus status; 71 72 RK_U32 on_used; 73 RK_U32 inited; 74 75 RK_U32 is_long_term; 76 RK_U32 used_by_cur; 77 RK_U32 check_lt_msb; 78 RK_S32 poc; 79 80 H265eSlice *slice; 81 82 RK_S64 pts; 83 RK_S64 dts; 84 85 RK_U32 is_key_frame; 86 } H265eDpbFrm; 87 88 typedef struct H265eRpsList_e { 89 RK_S32 lt_num; 90 RK_S32 st_num; 91 RK_S32 poc_cur_list; 92 93 RK_S32 poc[RPSLIST_MAX]; 94 95 RK_U32 used_by_cur[MAX_REFS]; 96 97 H265eRefPicListModification *m_RefPicListModification; 98 } H265eRpsList; 99 100 101 /* 102 * dpb frame arrangement 103 * 104 * If dpb size is 3 then dpb frame will be total 4 frames. 105 * Then the frame 3 is always current frame and frame 0~2 is reference frame 106 * in the gop structure. 107 * 108 * When one frame is encoded all it info will be moved to its gop position for 109 * next frame encoding. 110 */ 111 typedef struct H265eDpb_t { 112 RK_S32 seq_idx; 113 RK_S32 gop_idx; 114 // status and count for one gop structure 115 116 RK_S32 last_idr; 117 RK_S32 poc_cra; 118 RK_U32 refresh_pending; 119 RK_S32 max_ref_l0; 120 RK_S32 max_ref_l1; 121 122 H265eRpsList RpsList; 123 H265eDpbFrm *curr; 124 H265eDpbFrm frame_list[MAX_REFS + 1]; 125 } H265eDpb; 126 127 #ifdef __cplusplus 128 extern "C" { 129 #endif 130 131 void h265e_set_ref_list(H265eRpsList *RpsList, H265eReferencePictureSet *m_pRps); 132 MPP_RET h265e_dpb_init(H265eDpb **dpb); 133 MPP_RET h265e_dpb_deinit(H265eDpb *dpb); 134 MPP_RET h265e_dpb_setup_buf_size(H265eDpb *dpb, RK_U32 size[], RK_U32 count); 135 MPP_RET h265e_dpb_get_curr(H265eDpb *dpb); 136 void h265e_dpb_build_list(H265eDpb *dpb, EncCpbStatus *cpb); 137 void h265e_dpb_proc_cpb(H265eDpb *dpb, EncCpbStatus *cpb); 138 139 #define h265e_dpb_dump_frms(dpb) h265e_dpb_dump_frm(dpb, __FUNCTION__) 140 141 void h265e_dpb_dump_frm(H265eDpb *dpb, const char *caller); 142 143 #ifdef __cplusplus 144 } 145 #endif 146 147 #endif /* __H265E_DPB_H__ */ 148