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 /*****************************************************************************/
22 /* File Name         : irc_rd_model.h                                        */
23 /*                                                                           */
24 /* Description       : Implements all the Functions to Model the             */
25 /*                     Rate Distortion Behaviour of the Codec over the Last  */
26 /*                     Few Frames.                                           */
27 /*                                                                           */
28 /* List of Functions : irc_update_frame_rd_model                             */
29 /*                     estimate_mpeg2_qp_for_resbits                         */
30 /*                     update_mb_rd_model                                    */
31 /*                     find_model_coeffs                                     */
32 /*                     refine_set_of_points                                  */
33 /*                     init_mb_rd_model                                      */
34 /*                     irc_add_frame_to_rd_model                             */
35 /*                     irc_find_qp_for_target_bits                           */
36 /*                                                                           */
37 /*                                                                           */
38 /* Issues / Problems : None                                                  */
39 /*                                                                           */
40 /* Revision History  :                                                       */
41 /*        DD MM YYYY   Author(s)       Changes (Describe the changes made)   */
42 /*        21 06 2006   Sarat           Initial Version                       */
43 /*****************************************************************************/
44 
45 #ifndef RC_RD_MODEL
46 #define RC_RD_MODEL
47 
48 #define MAX_FRAMES_MODELLED 16
49 
50 typedef float model_coeff;
51 typedef struct rc_rd_model_t *rc_rd_model_handle;
52 
53 WORD32 irc_rd_model_num_fill_use_free_memtab(rc_rd_model_handle *pps_rc_rd_model,
54                                              itt_memtab_t *ps_memtab,
55                                              ITT_FUNC_TYPE_E e_func_type);
56 /* Interface Functions */
57 /* Initialise the rate distortion model */
58 void irc_init_frm_rc_rd_model(rc_rd_model_handle ps_rd_model,
59                               UWORD8 u1_max_frames_modelled);
60 
61 /* Reset the rate distortion model */
62 void irc_reset_frm_rc_rd_model(rc_rd_model_handle ps_rd_model);
63 
64 /* Returns the Qp to be used for the given bits and SAD */
65 UWORD8 irc_find_qp_for_target_bits(rc_rd_model_handle ps_rd_model,
66                                    UWORD32 u4_target_res_bits,
67                                    UWORD32 u4_estimated_sad,
68                                    UWORD8 u1_max_qp,
69                                    UWORD8 u1_min_qp);
70 
71 /* Updates the frame level statistics after encoding a frame */
72 void irc_add_frame_to_rd_model(rc_rd_model_handle ps_rd_model,
73                                UWORD32 i4_res_bits,
74                                UWORD8 u1_avg_mp2qp,
75                                UWORD32 i4_sad_h264,
76                                UWORD8 u1_num_skips);
77 
78 UWORD32 irc_estimate_bits_for_qp(rc_rd_model_handle ps_rd_model,
79                                  UWORD32 u4_estimated_sad,
80                                  UWORD8 u1_avg_qp);
81 
82 /* Get the Linear model coefficient */
83 model_coeff irc_get_linear_coefficient(rc_rd_model_handle ps_rd_model);
84 
85 WORD32 irc_calc_per_frm_bits(rc_rd_model_handle ps_rd_model,
86                              UWORD16 *pu2_num_pics_of_a_pic_type,
87                              UWORD8 *pu1_update_pic_type_model,
88                              UWORD8 u1_num_pic_types,
89                              UWORD32 *pu4_num_skip_of_a_pic_type,
90                              UWORD8 u1_base_pic_type,
91                              float *pfl_gamma,
92                              float *pfl_eta,
93                              UWORD8 u1_curr_pic_type,
94                              UWORD32 u4_bits_for_sub_gop,
95                              UWORD32 u4_curr_estimated_sad,
96                              UWORD8 *pu1_curr_pic_type_qp);
97 #endif
98 
99