summaryrefslogtreecommitdiffstats
path: root/encoder/ih264e_rate_control.h
blob: cca9ad3bdc73eba1c46becf79be435113d58b7ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/******************************************************************************
 *
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *****************************************************************************
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
*/

/**
*******************************************************************************
* @file
*  ih264e_rate_control.h
*
* @brief
*  This file contains function declarations of api functions for h264 rate
*  control
*
* @author
*  ittiam
*
* @remarks
*  None
*
*******************************************************************************
*/

#ifndef IH264E_RATE_CONTROL_H_
#define IH264E_RATE_CONTROL_H_

/*****************************************************************************/
/* Function Declarations                                                     */
/*****************************************************************************/

/**
*******************************************************************************
*
* @brief
*  This function initializes rate control context and variables
*
* @par Description
*  This function initializes rate control type, source and target frame rate,
*  average and peak bitrate, intra-inter frame interval and initial
*  quantization parameter
*
* @param[in] pv_rc_api
*  Handle to rate control api
*
* @param[in] pv_frame_time
*  Handle to frame time context
*
* @param[in] pv_time_stamp
*  Handle to time stamp context
*
* @param[in] pv_pd_frm_rate
*  Handle to pull down frame time context
*
* @param[in] u4_max_frm_rate
*  Maximum frame rate
*
* @param[in] u4_src_frm_rate
*  Source frame rate
*
* @param[in] u4_tgt_frm_rate
*  Target frame rate
*
* @param[in] e_rate_control_type
*  Rate control type
*
* @param[in] u4_avg_bit_rate
*  Average bit rate
*
* @param[in] u4_peak_bit_rate
*  Peak bit rate
*
* @param[in] u4_max_delay
*  Maximum delay between frames
*
* @param[in] u4_intra_frame_interval
*  Intra frame interval
*
* @param[in] i4_inter_frm_int
*  Inter frame interval
*
* @param[in] pu1_init_qp
*  Initial qp
*
* @param[in] i4_max_inter_frm_int
*  Maximum inter frame interval
*
* @param[in] pu1_min_max_qp
*  Array of min/max qp
*
* @param[in] u1_profile_level
*  Encoder profile level
*
* @returns none
*
* @remarks
*
*******************************************************************************
*/
void ih264e_rc_init(void *pv_rc_api,
                    void *pv_frame_time,
                    void *pv_time_stamp,
                    void *pv_pd_frm_rate,
                    UWORD32 u4_max_frm_rate,
                    UWORD32 u4_src_frm_rate,
                    UWORD32 u4_tgt_frm_rate,
                    rc_type_e e_rate_control_type,
                    UWORD32 u4_avg_bit_rate,
                    UWORD32 u4_peak_bit_rate,
                    UWORD32 u4_max_delay,
                    UWORD32 u4_intra_frame_interval,
                    WORD32  i4_inter_frm_int,
                    UWORD8 *pu1_init_qp,
                    WORD32 i4_max_inter_frm_int,
                    UWORD8 *pu1_min_max_qp,
                    UWORD8 u1_profile_level);

/**
*******************************************************************************
*
* @brief Function to get picture details
*
* @par   Description
*  This function returns the Picture type(I/P/B)
*
* @param[in] pv_rc_api
*  Handle to Rate control api
*
* @returns
*  Picture type
*
* @remarks none
*
*******************************************************************************
*/
picture_type_e ih264e_rc_get_picture_details(void *pv_rc_api,
                                             WORD32 *pi4_pic_id,
                                             WORD32 *pi4_pic_disp_order_no);


/**
*******************************************************************************
*
* @brief  Function to set frame rate inside RC.
*
* @par Description
*  This function is called before encoding the current frame and gets the qp
*  for the current frame from rate control module
*
* @param[in] ps_rate_control_api
*  Handle to rate control api
*
* @param[in] ps_pd_frm_rate
*  Handle to pull down frm rate context
*
* @param[in] ps_time_stamp
*  Handle to time stamp context
*
* @param[in] ps_frame_time
*  Handle to frame time context
*
* @returns
*  Skip or encode the current frame
*
* @remarks
*
*******************************************************************************
*/
WORD32 ih264e_update_rc_framerates(void *ps_rate_control_api,
                         void *ps_pd_frm_rate,
                         void *ps_time_stamp,
                         void *ps_frame_time
                         );

/**
*******************************************************************************
*
* @brief Function to update mb info for rate control context
*
* @par   Description
*  After encoding a mb, information such as mb type, qp used, mb distortion
*  resulted in encoding the block and so on needs to be preserved for modelling
*  RC. This is preserved via this function call.
*
* @param[in] ps_frame_info
*  Handle Frame info context
*
* @param[in] ps_proc
*  Process context
*
* @returns
*
* @remarks
*
*******************************************************************************
*/
void ih264e_update_rc_mb_info(frame_info_t *ps_frame_info, void *pv_proc);

/**
*******************************************************************************
*
* @brief Function to get rate control buffer status
*
* @par Description
*  This function is used to get buffer status(underflow/overflow) by rate
*  control module
*
* @param[in] pv_rc_api
*  Handle to rate control api context
*
* @param[in] i4_total_frame_bits
*  Total frame bits
*
* @param[in] u1_pic_type
*  Picture type
*
* @param[in] pi4_num_bits_to_prevent_vbv_underflow
*  Number of bits to prevent underflow
*
* @param[out] pu1_is_enc_buf_overflow
*  Buffer overflow indication flag
*
* @param[out] pu1_is_enc_buf_underflow
*  Buffer underflow indication flag
*
* @returns
*
* @remarks
*
*******************************************************************************
*/
void ih264e_rc_get_buffer_status(void *pv_rc_api,
                                 WORD32 i4_total_frame_bits,
                                 picture_type_e e_pic_type,
                                 WORD32 *pi4_num_bits_to_prevent_vbv_underflow,
                                 UWORD8 *pu1_is_enc_buf_overflow,
                                 UWORD8 *pu1_is_enc_buf_underflow);

/**
*******************************************************************************
*
* @brief Function to update rate control module after encoding
*
* @par Description
*  This function is used to update the rate control module after the current
*  frame encoding is done with details such as bits consumed, SAD for I/P/B,
*  intra cost ,mb type and other
*
* @param[in] ps_rate_control_api
*  Handle to rate control api context
*
* @param[in] ps_frame_info
*  Handle to frame info context
*
* @param[in] ps_pd_frm_rate
*  Handle to pull down frame rate context
*
* @param[in] ps_time_stamp
*  Handle to time stamp context
*
* @param[in] ps_frame_time
*  Handle to frame time context
*
* @param[in] i4_total_mb_in_frame
*  Total mb in frame
*
* @param[in] pe_vop_coding_type
*  Picture coding type
*
* @param[in] i4_is_first_frame
*  Is first frame
*
* @param[in] pi4_is_post_encode_skip
*  Post encoding skip flag
*
* @param[in] u1_frame_qp
*  Frame qp
*
* @param[in] pi4_num_intra_in_prev_frame
*  Number of intra mbs in previous frame
*
* @param[in] pi4_avg_activity
*  Average activity
*
* @returns
*
* @remarks
*
*******************************************************************************
*/
WORD32 ih264e_rc_post_enc(void *ps_rate_control_api,
                         frame_info_t *ps_frame_info,
                         void *ps_pd_frm_rate,
                         void *ps_time_stamp,
                         void *ps_frame_time,
                         WORD32 i4_total_mb_in_frame,
                         picture_type_e *pe_vop_coding_type,
                         WORD32 i4_is_first_frame,
                         WORD32 *pi4_is_post_encode_skip,
                         UWORD8 u1_frame_qp,
                         WORD32 *pi4_num_intra_in_prev_frame,
                         WORD32 *pi4_avg_activity);

/**
*******************************************************************************
*
* @brief Function to update bits consumed info to rate control context
*
* @par Description
*  Function to update bits consume info to rate control context
*
* @param[in] ps_frame_info
*  Frame info context
*
* @param[in] ps_entropy
*  Entropy context
*
* @returns
*  total bits consumed by the frame
*
* @remarks
*
*******************************************************************************
*/
void ih264e_update_rc_bits_info(frame_info_t *ps_frame_info, void *pv_entropy);

#endif /* IH264E_RATE_CONTROL_H */