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