1 /****************************************************************************** 2 * 3 * Copyright (C) 2022 The Android Open Source Project 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 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore 19 */ 20 21 /** 22 ******************************************************************************* 23 * @file 24 * isvce_rate_control.h 25 * 26 * @brief 27 * This file contains function declarations of api functions for h264 rate 28 * control 29 * 30 * @author 31 * ittiam 32 * 33 * @remarks 34 * None 35 * 36 ******************************************************************************* 37 */ 38 39 #ifndef _ISVCE_RATE_CONTROL_H_ 40 #define _ISVCE_RATE_CONTROL_H_ 41 42 #if ENABLE_RE_ENC_AS_SKIP 43 #include "isvce_structs.h" 44 #endif 45 46 /*****************************************************************************/ 47 /* Function Declarations */ 48 /*****************************************************************************/ 49 50 /** 51 ******************************************************************************* 52 * 53 * @brief 54 * This function initializes rate control context and variables 55 * 56 * @par Description 57 * This function initializes rate control type, source and target frame rate, 58 * average and peak bitrate, intra-inter frame interval and initial 59 * quantization parameter 60 * 61 * @param[in] pv_rc_api 62 * Handle to rate control api 63 * 64 * @param[in] pv_frame_time 65 * Handle to frame time context 66 * 67 * @param[in] pv_time_stamp 68 * Handle to time stamp context 69 * 70 * @param[in] pv_pd_frm_rate 71 * Handle to pull down frame time context 72 * 73 * @param[in] u4_max_frm_rate 74 * Maximum frame rate 75 * 76 * @param[in] u4_src_frm_rate 77 * Source frame rate 78 * 79 * @param[in] u4_tgt_frm_rate 80 * Target frame rate 81 * 82 * @param[in] e_rate_control_type 83 * Rate control type 84 * 85 * @param[in] u4_avg_bit_rate 86 * Average bit rate 87 * 88 * @param[in] u4_peak_bit_rate 89 * Peak bit rate 90 * 91 * @param[in] u4_max_delay 92 * Maximum delay between frames 93 * 94 * @param[in] u4_intra_frame_interval 95 * Intra frame interval 96 * 97 * @param[in] i4_inter_frm_int 98 * Inter frame interval 99 * 100 * @param[in] pu1_init_qp 101 * Initial qp 102 * 103 * @param[in] i4_max_inter_frm_int 104 * Maximum inter frame interval 105 * 106 * @param[in] pu1_min_max_qp 107 * Array of min/max qp 108 * 109 * @param[in] u1_profile_level 110 * Encoder profile level 111 * 112 * @returns none 113 * 114 * @remarks 115 * 116 ******************************************************************************* 117 */ 118 void isvce_rc_init(void *pv_rc_api, void *pv_frame_time, void *pv_time_stamp, void *pv_pd_frm_rate, 119 UWORD32 u4_max_frm_rate, UWORD32 u4_src_frm_rate, UWORD32 u4_tgt_frm_rate, 120 rc_type_e e_rate_control_type, UWORD32 u4_avg_bit_rate, UWORD32 u4_peak_bit_rate, 121 UWORD32 u4_max_delay, UWORD32 u4_intra_frame_interval, WORD32 i4_inter_frm_int, 122 UWORD8 *pu1_init_qp, WORD32 i4_max_inter_frm_int, UWORD8 *pu1_min_max_qp, 123 UWORD8 u1_profile_level); 124 125 /** 126 ******************************************************************************* 127 * 128 * @brief Function to get picture details 129 * 130 * @par Description 131 * This function returns the Picture type(I/P/B) 132 * 133 * @param[in] pv_rc_api 134 * Handle to Rate control api 135 * 136 * @returns 137 * Picture type 138 * 139 * @remarks none 140 * 141 ******************************************************************************* 142 */ 143 picture_type_e isvce_rc_get_picture_details(void *pv_rc_api, WORD32 *pi4_pic_id, 144 WORD32 *pi4_pic_disp_order_no); 145 146 /** 147 ******************************************************************************* 148 * 149 * @brief Function to set frame rate inside RC. 150 * 151 * @par Description 152 * This function is called before encoding the current frame and gets the qp 153 * for the current frame from rate control module 154 * 155 * @param[in] ps_rate_control_api 156 * Handle to rate control api 157 * 158 * @param[in] ps_pd_frm_rate 159 * Handle to pull down frm rate context 160 * 161 * @param[in] ps_time_stamp 162 * Handle to time stamp context 163 * 164 * @param[in] ps_frame_time 165 * Handle to frame time context 166 * 167 * @returns 168 * Skip or encode the current frame 169 * 170 * @remarks 171 * 172 ******************************************************************************* 173 */ 174 WORD32 isvce_update_rc_framerates(void *ps_rate_control_api, void *ps_pd_frm_rate, 175 void *ps_time_stamp, void *ps_frame_time); 176 177 /** 178 ******************************************************************************* 179 * 180 * @brief Function to update mb info for rate control context 181 * 182 * @par Description 183 * After encoding a mb, information such as mb type, qp used, mb distortion 184 * resulted in encoding the block and so on needs to be preserved for modelling 185 * RC. This is preserved via this function call. 186 * 187 * @param[in] ps_frame_info 188 * Handle Frame info context 189 * 190 * @param[in] ps_proc 191 * Process context 192 * 193 * @returns 194 * 195 * @remarks 196 * 197 ******************************************************************************* 198 */ 199 void isvce_update_rc_mb_info(frame_info_t *ps_frame_info, void *pv_proc); 200 201 /** 202 ******************************************************************************* 203 * 204 * @brief Function to get rate control buffer status 205 * 206 * @par Description 207 * This function is used to get buffer status(underflow/overflow) by rate 208 * control module 209 * 210 * @param[in] pv_rc_api 211 * Handle to rate control api context 212 * 213 * @param[in] i4_total_frame_bits 214 * Total frame bits 215 * 216 * @param[in] u1_pic_type 217 * Picture type 218 * 219 * @param[in] pi4_num_bits_to_prevent_vbv_underflow 220 * Number of bits to prevent underflow 221 * 222 * @param[out] pu1_is_enc_buf_overflow 223 * Buffer overflow indication flag 224 * 225 * @param[out] pu1_is_enc_buf_underflow 226 * Buffer underflow indication flag 227 * 228 * @returns 229 * 230 * @remarks 231 * 232 ******************************************************************************* 233 */ 234 void isvce_rc_get_buffer_status(void *pv_rc_api, WORD32 i4_total_frame_bits, 235 picture_type_e e_pic_type, 236 WORD32 *pi4_num_bits_to_prevent_vbv_underflow, 237 UWORD8 *pu1_is_enc_buf_overflow, UWORD8 *pu1_is_enc_buf_underflow); 238 239 /** 240 ******************************************************************************* 241 * 242 * @brief Function to update rate control module after encoding 243 * 244 * @par Description 245 * This function is used to update the rate control module after the current 246 * frame encoding is done with details such as bits consumed, SAD for I/P/B, 247 * intra cost ,mb type and other 248 * 249 * @param[in] ps_rate_control_api 250 * Handle to rate control api context 251 * 252 * @param[in] ps_frame_info 253 * Handle to frame info context 254 * 255 * @param[in] ps_pd_frm_rate 256 * Handle to pull down frame rate context 257 * 258 * @param[in] ps_time_stamp 259 * Handle to time stamp context 260 * 261 * @param[in] ps_frame_time 262 * Handle to frame time context 263 * 264 * @param[in] i4_total_mb_in_frame 265 * Total mb in frame 266 * 267 * @param[in] pe_vop_coding_type 268 * Picture coding type 269 * 270 * @param[in] i4_is_first_frame 271 * Is first frame 272 * 273 * @param[in] pi4_is_post_encode_skip 274 * Post encoding skip flag 275 * 276 * @param[in] u1_frame_qp 277 * Frame qp 278 * 279 * @param[in] pi4_num_intra_in_prev_frame 280 * Number of intra mbs in previous frame 281 * 282 * @param[in] pi4_avg_activity 283 * Average activity 284 * 285 * @returns 286 * 287 * @remarks 288 * 289 ******************************************************************************* 290 */ 291 #if ENABLE_RE_ENC_AS_SKIP 292 WORD32 isvce_rc_post_enc(void *ps_rate_control_api, frame_info_t *ps_frame_info, 293 void *ps_pd_frm_rate, void *ps_time_stamp, void *ps_frame_time, 294 WORD32 i4_total_mb_in_frame, picture_type_e *pe_vop_coding_type, 295 WORD32 i4_is_first_frame, WORD32 *pi4_is_post_encode_skip, 296 UWORD8 u1_frame_qp, WORD32 *pi4_num_intra_in_prev_frame, 297 WORD32 *pi4_avg_activity, UWORD8 *u1_is_post_enc_skip); 298 #else 299 WORD32 isvce_rc_post_enc(void *ps_rate_control_api, frame_info_t *ps_frame_info, 300 void *ps_pd_frm_rate, void *ps_time_stamp, void *ps_frame_time, 301 WORD32 i4_total_mb_in_frame, picture_type_e *pe_vop_coding_type, 302 WORD32 i4_is_first_frame, WORD32 *pi4_is_post_encode_skip, 303 UWORD8 u1_frame_qp, WORD32 *pi4_num_intra_in_prev_frame, 304 WORD32 *pi4_avg_activity); 305 306 #endif 307 /** 308 ******************************************************************************* 309 * 310 * @brief Function to update bits consumed info to rate control context 311 * 312 * @par Description 313 * Function to update bits consume info to rate control context 314 * 315 * @param[in] ps_frame_info 316 * Frame info context 317 * 318 * @param[in] ps_entropy 319 * Entropy context 320 * 321 * @returns 322 * total bits consumed by the frame 323 * 324 * @remarks 325 * 326 ******************************************************************************* 327 */ 328 void isvce_update_rc_bits_info(frame_info_t *ps_frame_info, void *pv_entropy); 329 330 #endif 331