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 Includes */
23 /******************************************************************************/
24
25 /* User include files */
26 #include "irc_datatypes.h"
27 #include "irc_cntrl_param.h"
28 #include "irc_frame_info_collector.h"
29
irc_init_frame_info(frame_info_t * frame_info)30 void irc_init_frame_info(frame_info_t *frame_info)
31 {
32 WORD32 i;
33
34 for(i = 0; i < MAX_MB_TYPE; i++)
35 {
36 frame_info->mb_header_bits[i] = 0;
37 frame_info->tot_mb_sad[i] = 0;
38 frame_info->num_mbs[i] = 0;
39 frame_info->qp_sum[i] = 0;
40 frame_info->mb_texture_bits[i] = 0;
41 }
42
43 frame_info->other_header_bits = 0;
44 frame_info->activity_sum = 0;
45 frame_info->intra_mb_cost_sum = 0;
46 }
47
48 /******************************************************************************
49 * GET Functions: Sending back collected information to the rate control module
50 ******************************************************************************/
irc_fi_get_total_header_bits(frame_info_t * frame_info)51 WORD32 irc_fi_get_total_header_bits(frame_info_t *frame_info)
52 {
53 WORD32 total_header_bits = 0, i;
54
55 for(i = 0; i < MAX_MB_TYPE; i++)
56 {
57 total_header_bits += frame_info->mb_header_bits[i];
58 }
59 total_header_bits += frame_info->other_header_bits;
60
61 return (total_header_bits);
62 }
63
irc_fi_get_total_texture_bits(frame_info_t * frame_info)64 WORD32 irc_fi_get_total_texture_bits(frame_info_t *frame_info)
65 {
66 WORD32 total_texture_bits = 0, i;
67
68 for(i = 0; i < MAX_MB_TYPE; i++)
69 {
70 total_texture_bits += frame_info->mb_texture_bits[i];
71 }
72
73 return (total_texture_bits);
74 }
75
irc_fi_get_total_frame_sad(frame_info_t * frame_info)76 WORD32 irc_fi_get_total_frame_sad(frame_info_t *frame_info)
77 {
78 WORD32 total_sad = 0, i;
79
80 for(i = 0; i < MAX_MB_TYPE; i++)
81 {
82 total_sad += frame_info->tot_mb_sad[i];
83 }
84
85 return (total_sad);
86 }
87
irc_fi_get_average_qp(frame_info_t * frame_info)88 WORD32 irc_fi_get_average_qp(frame_info_t *frame_info)
89 {
90 WORD32 i, total_qp = 0, total_mbs = 0;
91
92 for(i = 0; i < MAX_MB_TYPE; i++)
93 {
94 total_qp += frame_info->qp_sum[i];
95 total_mbs += frame_info->num_mbs[i];
96 }
97
98 if(total_mbs)
99 {
100 return (total_qp / total_mbs);
101 }
102 else
103 {
104 return 0;
105 }
106 }
107
irc_fi_get_avg_mb_header(frame_info_t * frame_info,UWORD8 mb_type)108 WORD32 irc_fi_get_avg_mb_header(frame_info_t *frame_info, UWORD8 mb_type)
109 {
110 if(frame_info->num_mbs[mb_type])
111 {
112 return (frame_info->mb_header_bits[mb_type]
113 / frame_info->num_mbs[mb_type]);
114 }
115 else
116 {
117 return 0;
118 }
119 }
120
irc_fi_get_total_mb_texture_bits(frame_info_t * frame_info,UWORD8 mb_type)121 WORD32 irc_fi_get_total_mb_texture_bits(frame_info_t *frame_info,
122 UWORD8 mb_type)
123 {
124 return (frame_info->mb_texture_bits[mb_type]);
125 }
126
irc_fi_get_total_mb_sad(frame_info_t * frame_info,UWORD8 mb_type)127 WORD32 irc_fi_get_total_mb_sad(frame_info_t *frame_info, UWORD8 mb_type)
128 {
129 return (frame_info->tot_mb_sad[mb_type]);
130 }
131
irc_fi_get_total_mb_qp(frame_info_t * frame_info,UWORD8 mb_type)132 WORD32 irc_fi_get_total_mb_qp(frame_info_t *frame_info, UWORD8 mb_type)
133 {
134 if(frame_info->num_mbs[mb_type])
135 {
136 return (frame_info->qp_sum[mb_type]);
137 }
138 else
139 {
140 return 0;
141 }
142 }
143
irc_fi_get_total_mb(frame_info_t * frame_info,UWORD8 mb_type)144 WORD32 irc_fi_get_total_mb(frame_info_t *frame_info, UWORD8 mb_type)
145 {
146 return (frame_info->num_mbs[mb_type]);
147 }
148
irc_fi_get_num_intra_mb(frame_info_t * frame_info)149 WORD32 irc_fi_get_num_intra_mb(frame_info_t *frame_info)
150 {
151 return (frame_info->num_mbs[MB_TYPE_INTRA]);
152 }
153
irc_fi_get_avg_activity(frame_info_t * frame_info)154 WORD32 irc_fi_get_avg_activity(frame_info_t *frame_info)
155 {
156 WORD32 i;
157 WORD32 i4_tot_mbs = 0;
158
159 for(i = 0; i < MAX_MB_TYPE; i++)
160 {
161 i4_tot_mbs += frame_info->num_mbs[i];
162 }
163
164 if(i4_tot_mbs)
165 {
166 return (frame_info->activity_sum / i4_tot_mbs);
167 }
168 else
169 {
170 return 0;
171 }
172 }
173
irc_fi_get_total_intra_mb_cost(frame_info_t * frame_info)174 WORD32 irc_fi_get_total_intra_mb_cost(frame_info_t *frame_info)
175 {
176 return (frame_info->intra_mb_cost_sum);
177 }
178