• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 _RC_COMMON_H_
22 #define _RC_COMMON_H_
23 
24 /****************************************************************************
25  NOTE : Put only those things into this file which are common across many
26  files, say I_TO_P_BIT_RATIO macro is used across irc_bit_allocation.c
27  and irc_rate_control_api.c.If anything is exclusive only to one file,
28  define it in the same file
29 
30  This file is an RC private file. It should not be exported to Codec
31  ****************************************************************************/
32 
33 #define UNUSED(x) ((void)(x))
34 
35 typedef float number_t;
36 
37 #define mult32_var_q(a,b,c) *c = a * b
38 
39 #define div32_var_q(a,b,c) (*c = ((b == 0)? a : (a / b)))
40 
41 #define add32_var_q(a,b,c) *c = a + b
42 
43 #define sub32_var_q(a,b,c) *c = a - b
44 
45 #define sqrt32_var_q(a, c) *c = sqrt(a)
46 
47 #define number_t_to_word32(num_a, a) *a = (WORD32)num_a
48 
49 #define convert_float_to_fix(a_f, a) *a = (WORD32)a_f
50 
51 #define convert_fix_to_float(a, a_f) *a_f = (float) a
52 
53 #define SET_VAR_Q(a,b,c) {a = (float) b;}
54 
55 
56 /* Defines the maximum and the minimum quantizer allowed in the stream.*/
57 #define MAX_MPEG2_QP        255 /* 127*/
58 
59 /* Bits ratio between I and P frame */
60 #define I_TO_P_BIT_RATIO 5
61 
62 /* Calculates P = (X*Y/Z) (Assuming all the four are in integers)*/
63 #define X_PROD_Y_DIV_Z(X1,Y1,Z1,P1)\
64 {\
65     number_t vq_a,vq_b,vq_c;\
66     SET_VAR_Q(vq_a,(X1),0);\
67     SET_VAR_Q(vq_b,(Y1),0);\
68     SET_VAR_Q(vq_c,(Z1),0);\
69     mult32_var_q(vq_a,vq_b,&vq_a);\
70     div32_var_q(vq_a,vq_c,&vq_a);\
71     number_t_to_word32(vq_a,&(P1));\
72 }
73 #define VQ_A_LT_VQ_B(A,B, Z) Z = A < B;
74 #define VQ_A_GT_VQ_B(A,B, Z) Z = A > B;
75 
76 /* Z=MAX(A,B) where A, B  and Z are var_q variables */
77 #define MAX_VARQ(A,B, Z)\
78 {\
79     WORD32 a_gt_b;\
80     VQ_A_GT_VQ_B((A), (B), a_gt_b);\
81     (Z) = (a_gt_b) ? (A) : (B);\
82 }
83 
84 /* Z=MIN(A,B) where A, B  and Z are var_q variables */
85 #define MIN_VARQ(A,B, Z)\
86 {\
87     WORD32 a_lt_b;\
88     VQ_A_LT_VQ_B((A), (B), a_lt_b);\
89     (Z) = (a_lt_b) ? (A) : (B);\
90 }
91 
92 /* Maximum number of drain-rates supported. Currently a maximum of only 2
93  drain-rates supported. One for
94  I pictures and the other for P & B pictures */
95 #define MAX_NUM_DRAIN_RATES 2
96 
97 /* The ratios between I to P and P to B Qp is specified here */
98 #define K_Q 4
99 #define I_TO_P_RATIO (19) /* In K_Q Q factor */
100 #define P_TO_B_RATIO (32) /* In K_Q Q factor */
101 #define P_TO_I_RATIO (13) /* In K_Q Q factor */
102 
103 #endif /* _RC_COMMON_H_ */
104 
105