1 /* 2 * Copyright (c) 2021 Rockchip Electronics Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef __MPP_RC_DEFS_H__ 17 #define __MPP_RC_DEFS_H__ 18 19 #include "rk_venc_ref.h" 20 21 #define MAX_CPB_REFS (8) 22 23 /* 24 * EncFrmStatus controls record the encoding frame status and also control 25 * work flow of encoder. It is the communicat channel between encoder implement 26 * module, rate control module and hardware module. 27 * 28 * bit 0 ~ 31 frame status 29 * 0 ~ 15 current frame status 30 * 16 ~ 31 reference frame status 31 * bit 32 ~ 63 encoding flow control 32 */ 33 typedef union EncFrmStatus_u { 34 struct { 35 /* 36 * bit 0 ~ 31 frame status 37 */ 38 /* status flag */ 39 unsigned int valid : 1; 40 /* 41 * 0 - write the reconstructed frame pixel to memory 42 * 1 - do not write the reconstructed frame pixel to memory 43 */ 44 unsigned int non_recn : 1; 45 unsigned int reserved0 : 2; 46 47 /* reference status flag */ 48 /* 49 * 0 - inter frame 50 * 1 - intra frame 51 */ 52 unsigned int is_intra : 1; 53 54 /* 55 * Valid when is_intra is true 56 * 0 - normal intra frame 57 * 1 - IDR frame 58 */ 59 unsigned int is_idr : 1; 60 61 /* 62 * 0 - mark as reference frame 63 * 1 - mark as non-refernce frame 64 */ 65 unsigned int is_non_ref : 1; 66 67 /* 68 * Valid when is_non_ref is false 69 * 0 - mark as short-term reference frame 70 * 1 - mark as long-term refernce frame 71 */ 72 unsigned int is_lt_ref : 1; 73 74 /* bit 8 - 15 */ 75 unsigned int lt_idx : 4; 76 unsigned int temporal_id : 4; 77 78 /* distance between current frame and reference frame */ 79 MppEncRefMode ref_mode : 6; 80 signed int ref_arg : 8; 81 signed int ref_dist : 2; 82 83 /* 84 * bit 32 ~ 63 encoder flow control flags 85 */ 86 /* 87 * 0 - normal frame encoding 88 * 1 - current frame will be dropped 89 */ 90 unsigned int drop : 1; 91 92 /* 93 * 0 - rate control module does not change frame type parameter 94 * 1 - rate control module changes frame type parameter reencode is needed 95 * to reprocess the dpb process. Also this means dpb module will follow 96 * the frame status parameter provided by rate control module. 97 */ 98 unsigned int re_dpb_proc : 1; 99 100 /* 101 * 0 - current frame encoding is in normal flow 102 * 1 - current frame encoding is in reencode flow 103 */ 104 unsigned int reencode : 1; 105 106 /* 107 * When true current frame size is super large then the frame should be reencoded. 108 */ 109 unsigned int super_frame : 1; 110 111 /* 112 * When true currnet frame is force to encoded as software skip frame 113 */ 114 unsigned int force_pskip : 1; 115 unsigned int reserved1 : 3; 116 117 /* reencode times */ 118 unsigned int reencode_times : 8; 119 120 /* sequential index for each frame */ 121 unsigned int seq_idx : 16; 122 }; 123 RK_U64 val; 124 } EncFrmStatus; 125 126 typedef struct EncCpbStatus_t { 127 signed int seq_idx; 128 129 EncFrmStatus curr; 130 EncFrmStatus refr; 131 132 /* initial cpb status for current frame encoding */ 133 EncFrmStatus init[MAX_CPB_REFS]; 134 /* final cpb status after current frame encoding */ 135 EncFrmStatus final[MAX_CPB_REFS]; 136 } EncCpbStatus; 137 138 #define ENC_RC_FORCE_QP (0x00000001) 139 140 typedef struct EncRcForceCfg_t { 141 unsigned int force_flag; 142 signed int force_qp; 143 unsigned int reserve[6]; 144 } EncRcForceCfg; 145 146 /* 147 * communication channel between rc / hal / hardware 148 * 149 * rc -> hal bit_target / bit_max / bit_min 150 * hal -> hw quality_target / quality_max / quality_min 151 * hw -> rc / hal bit_real / quality_real / madi / madp 152 */ 153 typedef struct EncRcCommonInfo_t { 154 /* rc to hal */ 155 signed int bit_target; 156 signed int bit_max; 157 signed int bit_min; 158 159 signed int quality_target; 160 signed int quality_max; 161 signed int quality_min; 162 163 /* rc from hardware */ 164 signed int bit_real; 165 signed int quality_real; 166 signed int madi; 167 signed int madp; 168 169 unsigned int iblk4_prop; // scale 256 170 signed int reserve[15]; 171 } EncRcTaskInfo; 172 173 typedef struct EncRcTask_s { 174 EncCpbStatus cpb; 175 EncFrmStatus frm; 176 EncRcTaskInfo info; 177 EncRcForceCfg force; 178 MppFrame frame; 179 } EncRcTask; 180 181 #endif /* __MPP_RC_DEFS_H__ */