xref: /aosp_15_r20/external/libavc/encoder/irc_bit_allocation.h (revision 495ae853bb871d1e5a258cb02c2cc13cde8ddb9a)
1*495ae853SAndroid Build Coastguard Worker /******************************************************************************
2*495ae853SAndroid Build Coastguard Worker  *
3*495ae853SAndroid Build Coastguard Worker  * Copyright (C) 2015 The Android Open Source Project
4*495ae853SAndroid Build Coastguard Worker  *
5*495ae853SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
6*495ae853SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
7*495ae853SAndroid Build Coastguard Worker  * You may obtain a copy of the License at:
8*495ae853SAndroid Build Coastguard Worker  *
9*495ae853SAndroid Build Coastguard Worker  * http://www.apache.org/licenses/LICENSE-2.0
10*495ae853SAndroid Build Coastguard Worker  *
11*495ae853SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
12*495ae853SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
13*495ae853SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*495ae853SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
15*495ae853SAndroid Build Coastguard Worker  * limitations under the License.
16*495ae853SAndroid Build Coastguard Worker  *
17*495ae853SAndroid Build Coastguard Worker  *****************************************************************************
18*495ae853SAndroid Build Coastguard Worker  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19*495ae853SAndroid Build Coastguard Worker */
20*495ae853SAndroid Build Coastguard Worker 
21*495ae853SAndroid Build Coastguard Worker #ifndef _BIT_ALLOCATION_H_
22*495ae853SAndroid Build Coastguard Worker #define _BIT_ALLOCATION_H_
23*495ae853SAndroid Build Coastguard Worker 
24*495ae853SAndroid Build Coastguard Worker typedef struct bit_allocation_t *bit_allocation_handle;
25*495ae853SAndroid Build Coastguard Worker 
26*495ae853SAndroid Build Coastguard Worker WORD32 irc_ba_num_fill_use_free_memtab(bit_allocation_handle *pps_bit_allocation,
27*495ae853SAndroid Build Coastguard Worker                                        itt_memtab_t *ps_memtab,
28*495ae853SAndroid Build Coastguard Worker                                        ITT_FUNC_TYPE_E e_func_type);
29*495ae853SAndroid Build Coastguard Worker 
30*495ae853SAndroid Build Coastguard Worker void irc_ba_init_bit_allocation(bit_allocation_handle ps_bit_allocation,
31*495ae853SAndroid Build Coastguard Worker                                 pic_handling_handle ps_pic_handling,
32*495ae853SAndroid Build Coastguard Worker                                 WORD32 i4_num_intra_frm_interval,
33*495ae853SAndroid Build Coastguard Worker                                 WORD32 i4_bit_rate,
34*495ae853SAndroid Build Coastguard Worker                                 WORD32 i4_frm_rate,
35*495ae853SAndroid Build Coastguard Worker                                 WORD32 *u4_peak_bit_rate,
36*495ae853SAndroid Build Coastguard Worker                                 WORD32 i4_min_bitrate);
37*495ae853SAndroid Build Coastguard Worker 
38*495ae853SAndroid Build Coastguard Worker /* Estimates the number of texture bits required by the current frame */
39*495ae853SAndroid Build Coastguard Worker WORD32 irc_ba_get_cur_frm_est_texture_bits(bit_allocation_handle ps_bit_allocation,
40*495ae853SAndroid Build Coastguard Worker                                            rc_rd_model_handle *pps_rd_model,
41*495ae853SAndroid Build Coastguard Worker                                            est_sad_handle ps_est_sad,
42*495ae853SAndroid Build Coastguard Worker                                            pic_handling_handle ps_pic_handling,
43*495ae853SAndroid Build Coastguard Worker                                            picture_type_e e_pic_type);
44*495ae853SAndroid Build Coastguard Worker 
45*495ae853SAndroid Build Coastguard Worker /* Estimate the number of header bits required by the current frame */
46*495ae853SAndroid Build Coastguard Worker WORD32 irc_ba_get_cur_frm_est_header_bits(bit_allocation_handle ps_bit_allocation,
47*495ae853SAndroid Build Coastguard Worker                                           picture_type_e e_pic_type);
48*495ae853SAndroid Build Coastguard Worker 
49*495ae853SAndroid Build Coastguard Worker /* Get the remaining bits allocated in the period */
50*495ae853SAndroid Build Coastguard Worker WORD32 irc_ba_get_rem_bits_in_period(bit_allocation_handle ps_bit_allocation,
51*495ae853SAndroid Build Coastguard Worker                                      pic_handling_handle ps_pic_handling);
52*495ae853SAndroid Build Coastguard Worker 
53*495ae853SAndroid Build Coastguard Worker WORD32 irc_ba_get_frame_rate(bit_allocation_handle ps_bit_allocation);
54*495ae853SAndroid Build Coastguard Worker 
55*495ae853SAndroid Build Coastguard Worker WORD32 irc_ba_get_bit_rate(bit_allocation_handle ps_bit_allocation);
56*495ae853SAndroid Build Coastguard Worker void irc_ba_get_peak_bit_rate(bit_allocation_handle ps_bit_allocation,
57*495ae853SAndroid Build Coastguard Worker                               WORD32 *pi4_peak_bit_rate);
58*495ae853SAndroid Build Coastguard Worker 
59*495ae853SAndroid Build Coastguard Worker /* Updates the bit allocation module with the actual encoded values */
60*495ae853SAndroid Build Coastguard Worker void irc_ba_update_cur_frm_consumed_bits(bit_allocation_handle ps_bit_allocation,
61*495ae853SAndroid Build Coastguard Worker                                          pic_handling_handle ps_pic_handling,
62*495ae853SAndroid Build Coastguard Worker                                          WORD32 i4_total_frame_bits,
63*495ae853SAndroid Build Coastguard Worker                                          WORD32 i4_model_updation_hdr_bits,
64*495ae853SAndroid Build Coastguard Worker                                          picture_type_e e_pic_type,
65*495ae853SAndroid Build Coastguard Worker                                          UWORD8 u1_is_scd,
66*495ae853SAndroid Build Coastguard Worker                                          WORD32 i4_last_frm_in_gop);
67*495ae853SAndroid Build Coastguard Worker 
68*495ae853SAndroid Build Coastguard Worker void irc_ba_check_and_update_bit_allocation(bit_allocation_handle ps_bit_allocation,
69*495ae853SAndroid Build Coastguard Worker                                             pic_handling_handle ps_pic_handling,
70*495ae853SAndroid Build Coastguard Worker                                             WORD32 i4_cur_buf_size,
71*495ae853SAndroid Build Coastguard Worker                                             WORD32 i4_max_buf_size,
72*495ae853SAndroid Build Coastguard Worker                                             WORD32 i4_max_bits_inflow_per_frm,
73*495ae853SAndroid Build Coastguard Worker                                             WORD32 i4_tot_frame_bits);
74*495ae853SAndroid Build Coastguard Worker 
75*495ae853SAndroid Build Coastguard Worker /* Based on the change in frame/bit rate update the remaining bits in period */
76*495ae853SAndroid Build Coastguard Worker void irc_ba_change_remaining_bits_in_period(bit_allocation_handle ps_bit_allocation,
77*495ae853SAndroid Build Coastguard Worker                                             pic_handling_handle ps_pic_handling,
78*495ae853SAndroid Build Coastguard Worker                                             WORD32 i4_bit_rate,
79*495ae853SAndroid Build Coastguard Worker                                             WORD32 i4_frame_rate,
80*495ae853SAndroid Build Coastguard Worker                                             WORD32 *i4_peak_bit_rate);
81*495ae853SAndroid Build Coastguard Worker 
82*495ae853SAndroid Build Coastguard Worker /* Change the gop size in the middle of a current gop */
83*495ae853SAndroid Build Coastguard Worker void change_gop_size(bit_allocation_handle ps_bit_allocation,
84*495ae853SAndroid Build Coastguard Worker                      WORD32 i4_intra_frm_interval,
85*495ae853SAndroid Build Coastguard Worker                      WORD32 i4_inter_frm_interval,
86*495ae853SAndroid Build Coastguard Worker                      WORD32 i4_num_intra_frm_interval);
87*495ae853SAndroid Build Coastguard Worker 
88*495ae853SAndroid Build Coastguard Worker void update_rem_frms_in_period(bit_allocation_handle ps_bit_allocation,
89*495ae853SAndroid Build Coastguard Worker                                picture_type_e e_pic_type,
90*495ae853SAndroid Build Coastguard Worker                                UWORD8 u1_is_first_frm,
91*495ae853SAndroid Build Coastguard Worker                                WORD32 i4_intra_frm_interval,
92*495ae853SAndroid Build Coastguard Worker                                WORD32 i4_num_intra_frm_interval);
93*495ae853SAndroid Build Coastguard Worker 
94*495ae853SAndroid Build Coastguard Worker void irc_ba_change_rem_bits_in_prd_at_force_I_frame(bit_allocation_handle ps_bit_allocation,
95*495ae853SAndroid Build Coastguard Worker                                                     pic_handling_handle ps_pic_handling);
96*495ae853SAndroid Build Coastguard Worker 
97*495ae853SAndroid Build Coastguard Worker void irc_ba_change_ba_peak_bit_rate(bit_allocation_handle ps_bit_allocation,
98*495ae853SAndroid Build Coastguard Worker                                     WORD32 *ai4_peak_bit_rate);
99*495ae853SAndroid Build Coastguard Worker #endif
100