• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  * Copyright (C) 2018 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 rc_common.h
23 *
24 * \brief
25 *    This file contains common macro used by rate control module
26 *
27 * \date
28 *
29 * \author
30 *    ittiam
31 *
32 ******************************************************************************
33 */
34 #ifndef _RC_COMMON_H_
35 #define _RC_COMMON_H_
36 
37 /*****************************************************************************/
38 /* Constant Macros                                                           */
39 /*****************************************************************************/
40 /****************************************************************************
41    NOTE : Put only those things into this file which are common across many
42           files, say I_TO_P_BIT_RATIO macro is used across bit_allocation.c
43           and rate_control_api.c.If anything is exclusive only to one file,
44           define it in the same file
45 
46           This file is an RC private file. It should not be exported to Codec
47  ****************************************************************************/
48 
49 /* Defines the maximum and the minimum quantizer allowed in the stream.*/
50 #define MAX_MPEG2_QP (4095) /*255*/ /* 127*/
51 #define ERR_2PASS_DISTR_GOP 5
52 
53 #define ENABLE_SSD_CALC_RC 0
54 
55 #ifdef ARM9
56 /* Mem tab alignment to 4 bytes  */
57 #define MEM_TAB_ALIGNMENT 32 /*ALIGN_WORD32*/
58 #else /* ARM968 */
59 /* Mem tab alignment to 128 bytes  */
60 #define MEM_TAB_ALIGNMENT ALIGN_128_BYTE
61 #endif /* ARM968 */
62 
63 #define COMP_TO_BITS_MAP(X, factor)                                                                \
64     ((-1.7561f * (X * X * X * X) + (2.5547f * X * X * X) - 0.3408f * (X * X) + (0.5343f * X) -     \
65       0.003f) *                                                                                    \
66      factor)
67 
68 #define COMP_TO_BITS_MAP_2_PASS(X, factor)                                                         \
69     ((-1.7561f * (X * X * X * X) + (2.5547f * X * X * X) - 0.3408f * (X * X) + (0.5343f * X) -     \
70       0.003f) *                                                                                    \
71      factor)
72 /* Calculates P = (X*Y/Z) (Assuming all the four are in integers)*/
73 #define X_PROD_Y_DIV_Z(X1, Y1, Z1, P1)                                                             \
74     {                                                                                              \
75         number_t vq_a, vq_b, vq_c;                                                                 \
76         SET_VAR_Q(vq_a, (X1), 0);                                                                  \
77         SET_VAR_Q(vq_b, (Y1), 0);                                                                  \
78         SET_VAR_Q(vq_c, (Z1), 0);                                                                  \
79         mult32_var_q(vq_a, vq_b, &vq_a);                                                           \
80         div32_var_q(vq_a, vq_c, &vq_a);                                                            \
81         number_t_to_word32(vq_a, &(P1));                                                           \
82     }
83 
84 /* Maximum number of drain-rates supported. Currently a maximum of only 2
85    drain-rates supported. One for
86    I pictures and the other for P & B pictures */
87 #define MAX_NUM_DRAIN_RATES 2
88 
89 /* The ratios between I to P and P to B Qp is specified here */
90 #define K_Q 4
91 #define I_TO_P_RATIO (18) /*(16)*/ /* In K_Q Q factor */
92 #define P_TO_B_RATIO (18) /* In K_Q Q factor */
93 #define B_TO_B1_RATIO (18)
94 #define B1_TO_B2_RATIO (18)
95 #define P_TO_I_RATIO (14)
96 #define I_TO_B_RATIO ((P_TO_B_RATIO * I_TO_P_RATIO) >> K_Q)
97 #define I_TO_B1_RATIO ((B_TO_B1_RATIO * P_TO_B_RATIO * I_TO_P_RATIO) >> (K_Q + K_Q))
98 #define I_TO_B2_RATIO                                                                              \
99     ((B1_TO_B2_RATIO * B_TO_B1_RATIO * P_TO_B_RATIO * I_TO_P_RATIO) >> (K_Q + K_Q + K_Q))
100 
101 #define P_TO_B_RATIO_HBR (16)
102 #define I_TO_P_RATIO_LOW_MOTION (20)
103 #define I_TO_P_RATIO_VLOW_MOTION (23)
104 #define I_TO_P_RATIO_VVLOW_MOTION (26)
105 
106 /* #define I_TO_P_RATIO (16)  In K_Q Q factor */
107 /* #define P_TO_B_RATIO (16)  In K_Q Q factor */
108 
109 /*Ratio of I frame bit consumptin vs average bit consumption for rest of the GOP
110  * This is based on experimaental runs over different seqience(same resolution scaled)*/
111 #define I_TO_AVG_REST_GOP_BIT (8)
112 #define MINIMUM_VISIBILITY_B4_STATIC_I                                                             \
113     (18)  //assumes this minimum lap window for bit allocation of static frame
114 #define MINIMUM_FRM_I_TO_REST_LAP_ENABLED (8)
115 #define I_TO_AVG_REST_GOP_BIT_MIN (1)
116 #define I_TO_AVG_REST_GOP_BIT_MAX (20)
117 #define I_TO_AVG_REST_GOP_BIT_MAX_INFINITE (80)
118 #define I_TO_AVG_REST_GOP_BIT_MAX_2_PASS (40)
119 #define I_TO_AVG_REST_GOP_BIT_MIN_2_PASS (0.5f)
120 
121 #define UPPER_THRESHOLD_EBF_Q4 (15)
122 #define STATIC_I_TO_REST_MULTIPLIER (6)
123 
124 /*also present in encoder herader file with same name*/
125 #define MAX_LAP_COMPLEXITY_Q7 (90)
126 #define DEFAULT_TEX_PERCENTAGE_Q5 24
127 
128 #ifdef DISABLE_NON_STEADY_STATE_CODE
129 #define NON_STEADSTATE_CODE (0)
130 #else
131 #define NON_STEADSTATE_CODE (1)
132 #endif
133 
134 /*HEVC_hierarchy*/
135 #define I_TO_P_BIT_RATIO (6)
136 #define P_TO_B_BIT_RATIO (2)
137 #define B_TO_B1_BIT_RATO0 (2)
138 #define B1_TO_B2_BIT_RATIO (2)
139 
140 /*define static I_TO_P ratio for all pic types*/
141 /* Trying to detect a static content and fixing the quality for that content. The trigger for such a
142 content is if the ratio between the estimated I frame to that of P is more than 18 times. If such
143 a simple content is detected then the bit ditribution is fixed to a ration of 36:2:1 (I:P:B) */
144 #define STATIC_I_TO_B2_RATIO (100)  //(24)
145 #define STATIC_P_TO_B2_RATIO (2)
146 #define STATIC_B_TO_B2_RATIO (1)
147 #define STATIC_B1_TO_B2_RATIO (1)
148 
149 /*Fsim limits*/
150 #define RC_FSIM_LOW_THR_SCD 64
151 
152 #define RC_FSIM_HIGH_THR_STATIC 115
153 
154 #endif /* _RC_COMMON_H_ */
155