• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  * Copyright (C) 2015 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 #ifndef _RATE_CONTROL_API_H_
22 #define _RATE_CONTROL_API_H_
23 
24 #define RC_OK            0
25 #define RC_FAIL         -1
26 #define RC_BENIGN_ERR   -2
27 
28 /* This file should only contain RC API function declarations */
29 
30 typedef struct rate_control_api_t *rate_control_handle;
31 
32 WORD32 irc_rate_control_num_fill_use_free_memtab(rate_control_handle *pps_rate_control_api,
33                                                  itt_memtab_t *ps_memtab,
34                                                  ITT_FUNC_TYPE_E e_func_type);
35 
36 void irc_initialise_rate_control(rate_control_handle ps_rate_control_api,
37                                  rc_type_e e_rate_control_type,
38                                  UWORD8 u1_is_mb_level_rc_on,
39                                  UWORD32 u4_avg_bit_rate,
40                                  UWORD32 *pu4_peak_bit_rate,
41                                  UWORD32 u4_min_bit_rate,
42                                  UWORD32 u4_frame_rate,
43                                  UWORD32 u4_max_delay,
44                                  UWORD32 u4_intra_frame_interval,
45                                  WORD32 i4_inter_frm_int,
46                                  UWORD8 *pu1_init_qp,
47                                  UWORD32 u4_max_vbv_buff_size,
48                                  WORD32 i4_max_inter_frm_int,
49                                  WORD32 i4_is_gop_closed,
50                                  UWORD8 *pu1_min_max_qp,
51                                  WORD32 i4_use_est_intra_sad,
52                                  UWORD32 u4_src_ticks,
53                                  UWORD32 u4_tgt_ticks);
54 
55 /*****************************************************************************
56  Process level API fuctions (FRAME LEVEL)
57  *****************************************************************************/
58 void irc_flush_buf_frames(rate_control_handle ps_rate_control_api);
59 
60 void irc_post_encode_frame_skip(rate_control_handle ps_rate_control_api,
61                                 picture_type_e e_pic_type);
62 
63 void irc_add_picture_to_stack(rate_control_handle rate_control_api,
64                               WORD32 i4_enc_pic_id);
65 
66 void irc_add_picture_to_stack_re_enc(rate_control_handle rate_control_api,
67                                      WORD32 i4_enc_pic_id,
68                                      picture_type_e e_pic_type);
69 
70 void irc_get_picture_details(rate_control_handle rate_control_api,
71                              WORD32 *pi4_pic_id,
72                              WORD32 *pi4_pic_disp_order_no,
73                              picture_type_e *pe_pic_type);
74 
75 /* Gets the frame level Qp */
76 UWORD8 irc_get_frame_level_qp(rate_control_handle rate_control_api,
77                               picture_type_e pic_type,
78                               WORD32 i4_max_frm_bits);
79 
80 vbv_buf_status_e irc_get_buffer_status(rate_control_handle rate_control_api,
81                                        WORD32 i4_total_frame_bits,
82                                        picture_type_e e_pic_type,
83                                        WORD32 *pi4_num_bits_to_prevent_vbv_underflow);
84 
85 WORD32 irc_get_prev_frm_est_bits(rate_control_handle ps_rate_control_api);
86 
87 void irc_update_pic_handling_state(rate_control_handle ps_rate_control_api,
88                                    picture_type_e e_pic_type);
89 
90 void irc_update_frame_level_info(rate_control_handle ps_rate_control_api,
91                                  picture_type_e e_pic_type,
92                                  WORD32 *pi4_mb_type_sad,
93                                  WORD32 i4_total_frame_bits,
94                                  WORD32 i4_model_updation_hdr_bits,
95                                  WORD32 *pi4_mb_type_tex_bits,
96                                  WORD32 *pi4_tot_mb_type_qp,
97                                  WORD32 *pi4_tot_mb_in_type,
98                                  WORD32 i4_avg_activity,
99                                  UWORD8 u1_is_scd,
100                                  WORD32 i4_is_it_a_skip,
101                                  WORD32 i4_intra_frm_cost,
102                                  WORD32 i4_is_pic_handling_done);
103 
104 /*****************************************************************************
105  MB LEVEL API (just wrapper fucntions)
106  *****************************************************************************/
107 
108 void irc_init_mb_rc_frame_level(rate_control_handle ps_rate_control_api,
109                                 UWORD8 u1_frame_qp);/* Current frame qp*/
110 
111 void irc_get_mb_level_qp(rate_control_handle ps_rate_control_api,
112                          WORD32 i4_cur_mb_activity,
113                          WORD32 *pi4_mb_qp,
114                          picture_type_e e_pic_type);
115 
116 WORD32 irc_get_bits_to_stuff(rate_control_handle ps_rate_control_api,
117                              WORD32 i4_tot_consumed_bits,
118                              picture_type_e e_pic_type);
119 
120 /******************************************************************************
121  Control Level API functions
122  Logic: The control call sets the state structure of the rate control api
123  accordingly such that the next process call would implement the same.
124  ******************************************************************************/
125 
126 void irc_change_inter_frm_int_call(rate_control_handle ps_rate_control_api,
127                                    WORD32 i4_inter_frm_int);
128 
129 void irc_change_intra_frm_int_call(rate_control_handle ps_rate_control_api,
130                                    WORD32 i4_intra_frm_int);
131 
132 void irc_change_avg_bit_rate(rate_control_handle ps_rate_control_api,
133                              UWORD32 u4_average_bit_rate);
134 
135 void irc_change_frame_rate(rate_control_handle ps_rate_control_api,
136                            UWORD32 u4_frame_rate,
137                            UWORD32 u4_src_ticks,
138                            UWORD32 u4_target_ticks);
139 
140 void irc_change_frm_rate_for_bit_alloc(rate_control_handle ps_rate_control_api,
141                                        UWORD32 u4_frame_rate);
142 
143 void irc_change_init_qp(rate_control_handle ps_rate_control_api,
144                         UWORD8 *init_qp);
145 
146 WORD32 irc_change_peak_bit_rate(rate_control_handle ps_rate_control_api,
147                                 UWORD32 *u4_peak_bit_rate);
148 
149 void irc_change_buffer_delay(rate_control_handle ps_rate_control_api,
150                              UWORD32 u4_buffer_delay);
151 
152 void irc_force_I_frame(rate_control_handle ps_rate_control_api);
153 
154 void irc_change_min_max_qp(rate_control_handle ps_rate_control_api,
155                            UWORD8 *u1_min_max_qp);
156 
157 /********************************************************************************
158  Getter functions
159  For getting the current state of the rate control structures
160  ********************************************************************************/
161 
162 UWORD32 irc_get_frame_rate(rate_control_handle ps_rate_control_api);
163 
164 UWORD32 irc_get_bit_rate(rate_control_handle ps_rate_control_api);
165 
166 UWORD32 irc_get_intra_frame_interval(rate_control_handle ps_rate_control_api);
167 
168 UWORD32 irc_get_inter_frame_interval(rate_control_handle ps_rate_control_api);
169 
170 rc_type_e irc_get_rc_type(rate_control_handle ps_rate_control_api);
171 
172 WORD32 irc_get_bits_per_frame(rate_control_handle ps_rate_control_api);
173 
174 UWORD32 irc_get_peak_bit_rate(rate_control_handle ps_rate_control_api,
175                               WORD32 i4_index);
176 
177 UWORD32 irc_get_max_delay(rate_control_handle ps_rate_control_api);
178 
179 UWORD32 irc_get_seq_no(rate_control_handle ps_rate_control_api);
180 
181 WORD32 irc_get_rem_bits_in_period(rate_control_handle ps_rate_control_api);
182 
183 WORD32 irc_get_vbv_buf_fullness(rate_control_handle ps_rate_control_api);
184 
185 WORD32 irc_get_vbv_buf_size(rate_control_handle ps_rate_control_api);
186 
187 WORD32 irc_get_vbv_fulness_with_cur_bits(rate_control_handle ps_rate_control_api,
188                                          UWORD32 u4_bits);
189 #endif
190