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