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