1 /****************************************************************************** 2 * 3 * Copyright (C) 2018 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 * \file cbr_buffer_control.h 23 * 24 * \brief 25 * This file contains all the necessary declarations for 26 * cbr_buffer_control functions 27 * 28 * \date 29 * 06/05/2008 30 * 31 * \author 32 * ittiam 33 * 34 ****************************************************************************** 35 */ 36 #ifndef CBR_BUFFER_CONTROL_H 37 #define CBR_BUFFER_CONTROL_H 38 39 /*****************************************************************************/ 40 /* Macros */ 41 /*****************************************************************************/ 42 /* Macro for clipping a number between to extremes */ 43 #define CLIP(Number, Max, Min) \ 44 if((Number) > (Max)) \ 45 (Number) = (Max); \ 46 else if((Number) < (Min)) \ 47 (Number) = (Min); 48 /*****************************************************************************/ 49 /* Structure */ 50 /*****************************************************************************/ 51 typedef struct cbr_buffer_t *cbr_buffer_handle; 52 53 /*****************************************************************************/ 54 /* Function Declarations */ 55 /*****************************************************************************/ 56 WORD32 cbr_buffer_num_fill_use_free_memtab( 57 cbr_buffer_handle *pps_cbr_buffer, itt_memtab_t *ps_memtab, ITT_FUNC_TYPE_E e_func_type); 58 /* Initialize the cbr Buffer*/ 59 void init_cbr_buffer( 60 cbr_buffer_handle ps_cbr_buffer, 61 WORD32 i4_buffer_delay, 62 WORD32 i4_tgt_frm_rate, 63 UWORD32 u4_bit_rate, 64 UWORD32 *u4_num_pics_in_delay_prd, 65 UWORD32 u4_vbv_buf_size, 66 UWORD32 u4_intra_frm_int, 67 rc_type_e u4_rc_type, 68 UWORD32 u4_peak_bit_rate, 69 UWORD32 u4_num_frames_in_delay, 70 float f_max_peak_rate_dur, 71 LWORD64 i8_num_frames_to_encode, 72 WORD32 i4_inter_frm_int, 73 WORD32 i4_cbr_rc_pass, 74 WORD32 i4_capped_vbr_flag); 75 76 /* Check for tgt bits with in CBR buffer*/ 77 WORD32 cbr_buffer_constraint_check( 78 cbr_buffer_handle ps_cbr_buffer, 79 WORD32 i4_tgt_bits, 80 picture_type_e e_pic_type, 81 WORD32 *pi4_max_tgt_bits, 82 WORD32 *pi4_min_tgt_bits); 83 84 /* Get the buffer status with the current consumed bits*/ 85 vbv_buf_status_e get_cbr_buffer_status( 86 cbr_buffer_handle ps_cbr_buffer, 87 WORD32 i4_tot_consumed_bits, 88 WORD32 *pi4_num_bits_to_prevent_overflow, 89 picture_type_e e_pic_type, 90 rc_type_e e_rc_type); 91 92 /* Update the CBR buffer at the end of the VOP*/ 93 void update_cbr_buffer( 94 cbr_buffer_handle ps_cbr_buffer, WORD32 i4_tot_consumed_bits, picture_type_e e_pic_type); 95 96 /*Get the bits needed to stuff in case of Underflow*/ 97 WORD32 get_cbr_bits_to_stuff( 98 cbr_buffer_handle ps_cbr_buffer, WORD32 i4_tot_consumed_bits, picture_type_e e_pic_type); 99 WORD32 get_cbr_buffer_delay(cbr_buffer_handle ps_cbr_buffer); 100 WORD32 get_cbr_buffer_size(cbr_buffer_handle ps_cbr_buffer); 101 WORD32 get_cbr_ebf(cbr_buffer_handle ps_cbr_buffer); 102 WORD32 get_cbr_max_ebf(cbr_buffer_handle ps_cbr_buffer); 103 void update_cbr_buf_mismatch_bit(cbr_buffer_handle ps_cbr_buffer, WORD32 i4_error_bits); 104 105 WORD32 get_error_bits_for_desired_buf( 106 cbr_buffer_handle ps_cbr_buffer, WORD32 i4_lap_complexity_q7, WORD32 i4_bit_alloc_period); 107 108 WORD32 get_buf_max_drain_rate(cbr_buffer_handle ps_cbr_buffer); 109 110 WORD32 vbr_stream_buffer_constraint_check( 111 cbr_buffer_handle ps_cbr_buffer, 112 WORD32 i4_tgt_bits, 113 picture_type_e e_pic_type, 114 WORD32 *pi4_max_tgt_bits, 115 WORD32 *pi4_min_tgt_bits); 116 117 void change_cbr_vbv_bit_rate( 118 cbr_buffer_handle ps_cbr_buffer, WORD32 *i4_bit_rate, WORD32 i4_peak_bitrate); 119 void change_cbr_vbv_tgt_frame_rate(cbr_buffer_handle ps_cbr_buffer, WORD32 i4_tgt_frm_rate); 120 void change_cbr_vbv_num_pics_in_delay_period( 121 cbr_buffer_handle ps_cbr_buffer, UWORD32 *u4_num_pics_in_delay_prd); 122 void change_cbr_buffer_delay(cbr_buffer_handle ps_cbr_buffer, WORD32 i4_buffer_delay); 123 void set_cbr_ebf(cbr_buffer_handle ps_cbr_buffer, WORD32 i32_init_ebf); 124 LWORD64 get_num_frms_encoded(cbr_buffer_handle ps_cbr_buffer); 125 126 LWORD64 get_num_frms_to_encode(cbr_buffer_handle ps_cbr_buffer); 127 128 WORD32 get_vbv_buffer_based_excess( 129 cbr_buffer_handle ps_cbr_buffer, 130 float f_complexity_peak_rate, 131 float f_cur_bits_complexity, 132 WORD32 bit_alloc_period, 133 WORD32 i4_num_gops_for_excess); 134 135 rc_type_e get_rc_type(cbr_buffer_handle ps_cbr_buffer); 136 137 void cbr_modify_ebf_estimate(cbr_buffer_handle ps_cbr_buffer, WORD32 i4_bit_error); 138 139 UWORD32 cbr_get_delay_frames(cbr_buffer_handle ps_cbr_buffer); 140 #endif /* CBR_BUFFER_CONTROL_H */ 141