1 | /* The copyright in this software is being made available under the BSD |
---|
2 | * License, included below. This software may be subject to other third party |
---|
3 | * and contributor rights, including patent rights, and no such rights are |
---|
4 | * granted under this license. |
---|
5 | * |
---|
6 | * Copyright (c) 2010-2015, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | #ifndef __TCOMCODINGSTATISTICS__ |
---|
35 | #define __TCOMCODINGSTATISTICS__ |
---|
36 | |
---|
37 | #include "CommonDef.h" |
---|
38 | #include <stdio.h> |
---|
39 | #include <string> |
---|
40 | #include <map> |
---|
41 | #include <math.h> |
---|
42 | #include "TComChromaFormat.h" |
---|
43 | |
---|
44 | static const Int64 TCOMCODINGSTATISTICS_ENTROPYSCALE=32768; |
---|
45 | |
---|
46 | |
---|
47 | enum TComCodingStatisticsType |
---|
48 | { |
---|
49 | STATS__NAL_UNIT_TOTAL_BODY,// This is a special case and is not included in the total sums. |
---|
50 | STATS__NAL_UNIT_PACKING, |
---|
51 | STATS__EMULATION_PREVENTION_3_BYTES, |
---|
52 | STATS__NAL_UNIT_HEADER_BITS, |
---|
53 | STATS__CABAC_INITIALISATION, |
---|
54 | STATS__CABAC_BITS__TQ_BYPASS_FLAG, |
---|
55 | STATS__CABAC_BITS__SKIP_FLAG, |
---|
56 | STATS__CABAC_BITS__MERGE_FLAG, |
---|
57 | STATS__CABAC_BITS__MERGE_INDEX, |
---|
58 | STATS__CABAC_BITS__MVP_IDX, |
---|
59 | STATS__CABAC_BITS__SPLIT_FLAG, |
---|
60 | STATS__CABAC_BITS__PART_SIZE, |
---|
61 | STATS__CABAC_BITS__PRED_MODE, |
---|
62 | STATS__CABAC_BITS__INTRA_DIR_ANG, |
---|
63 | STATS__CABAC_BITS__INTER_DIR, |
---|
64 | STATS__CABAC_BITS__REF_FRM_IDX, |
---|
65 | STATS__CABAC_BITS__MVD, |
---|
66 | STATS__CABAC_BITS__MVD_EP, |
---|
67 | STATS__CABAC_BITS__TRANSFORM_SUBDIV_FLAG, |
---|
68 | STATS__CABAC_BITS__QT_ROOT_CBF, |
---|
69 | STATS__CABAC_BITS__DELTA_QP_EP, |
---|
70 | STATS__CABAC_BITS__CHROMA_QP_ADJUSTMENT, |
---|
71 | STATS__CABAC_BITS__QT_CBF, |
---|
72 | STATS__CABAC_BITS__CROSS_COMPONENT_PREDICTION, |
---|
73 | STATS__CABAC_BITS__TRANSFORM_SKIP_FLAGS, |
---|
74 | |
---|
75 | STATS__CABAC_BITS__LAST_SIG_X_Y, |
---|
76 | STATS__CABAC_BITS__SIG_COEFF_GROUP_FLAG, |
---|
77 | STATS__CABAC_BITS__SIG_COEFF_MAP_FLAG, |
---|
78 | STATS__CABAC_BITS__GT1_FLAG, |
---|
79 | STATS__CABAC_BITS__GT2_FLAG, |
---|
80 | STATS__CABAC_BITS__SIGN_BIT, |
---|
81 | STATS__CABAC_BITS__ESCAPE_BITS, |
---|
82 | |
---|
83 | STATS__CABAC_BITS__SAO, |
---|
84 | STATS__CABAC_TRM_BITS, |
---|
85 | STATS__CABAC_FIXED_BITS, |
---|
86 | STATS__CABAC_PCM_ALIGN_BITS, |
---|
87 | STATS__CABAC_PCM_CODE_BITS, |
---|
88 | STATS__BYTE_ALIGNMENT_BITS, |
---|
89 | STATS__TRAILING_BITS, |
---|
90 | STATS__EXPLICIT_RDPCM_BITS, |
---|
91 | STATS__CABAC_EP_BIT_ALIGNMENT, |
---|
92 | STATS__CABAC_BITS__ALIGNED_SIGN_BIT, |
---|
93 | STATS__CABAC_BITS__ALIGNED_ESCAPE_BITS, |
---|
94 | #if NH_3D_IC |
---|
95 | STATS__CABAC_BITS__3D_IC, |
---|
96 | #endif |
---|
97 | STATS__NUM_STATS |
---|
98 | }; |
---|
99 | |
---|
100 | static inline const Char* getName(TComCodingStatisticsType name) |
---|
101 | { |
---|
102 | static const Char *statNames[]= |
---|
103 | { |
---|
104 | "NAL_UNIT_TOTAL_BODY", // This is a special case and is not included in the total sums. |
---|
105 | "NAL_UNIT_PACKING", |
---|
106 | "EMULATION_PREVENTION_3_BYTES", |
---|
107 | "NAL_UNIT_HEADER_BITS", |
---|
108 | "CABAC_INITIALISATION-and-rounding", |
---|
109 | "CABAC_BITS__TQ_BYPASS_FLAG", |
---|
110 | "CABAC_BITS__SKIP_FLAG", |
---|
111 | "CABAC_BITS__MERGE_FLAG", |
---|
112 | "CABAC_BITS__MERGE_INDEX", |
---|
113 | "CABAC_BITS__MVP_IDX", |
---|
114 | "CABAC_BITS__SPLIT_FLAG", |
---|
115 | "CABAC_BITS__PART_SIZE", |
---|
116 | "CABAC_BITS__PRED_MODE", |
---|
117 | "CABAC_BITS__INTRA_DIR_ANG", |
---|
118 | "CABAC_BITS__INTER_DIR", |
---|
119 | "CABAC_BITS__REF_FRM_IDX", |
---|
120 | "CABAC_BITS__MVD", |
---|
121 | "CABAC_BITS__MVD_EP", |
---|
122 | "CABAC_BITS__TRANSFORM_SUBDIV_FLAG", |
---|
123 | "CABAC_BITS__QT_ROOT_CBF", |
---|
124 | "CABAC_BITS__DELTA_QP_EP", |
---|
125 | "CABAC_BITS__CHROMA_QP_ADJUSTMENT", |
---|
126 | "CABAC_BITS__QT_CBF", |
---|
127 | "CABAC_BITS__CROSS_COMPONENT_PREDICTION", |
---|
128 | "CABAC_BITS__TRANSFORM_SKIP_FLAGS", |
---|
129 | "CABAC_BITS__LAST_SIG_X_Y", |
---|
130 | "CABAC_BITS__SIG_COEFF_GROUP_FLAG", |
---|
131 | "CABAC_BITS__SIG_COEFF_MAP_FLAG", |
---|
132 | "CABAC_BITS__GT1_FLAG", |
---|
133 | "CABAC_BITS__GT2_FLAG", |
---|
134 | "CABAC_BITS__SIGN_BIT", |
---|
135 | "CABAC_BITS__ESCAPE_BITS", |
---|
136 | "CABAC_BITS__SAO", |
---|
137 | "CABAC_TRM_BITS", |
---|
138 | "CABAC_FIXED_BITS", |
---|
139 | "CABAC_PCM_ALIGN_BITS", |
---|
140 | "CABAC_PCM_CODE_BITS", |
---|
141 | "BYTE_ALIGNMENT_BITS", |
---|
142 | "TRAILING_BITS", |
---|
143 | "EXPLICIT_RDPCM_BITS", |
---|
144 | "CABAC_EP_BIT_ALIGNMENT", |
---|
145 | "CABAC_BITS__ALIGNED_SIGN_BIT", |
---|
146 | "CABAC_BITS__ALIGNED_ESCAPE_BITS" |
---|
147 | #if NH_3D_IC |
---|
148 | "CABAC_BITS__3D_IC" |
---|
149 | #endif |
---|
150 | }; |
---|
151 | assert(STATS__NUM_STATS == sizeof(statNames)/sizeof(Char *) && name < STATS__NUM_STATS); |
---|
152 | return statNames[name]; |
---|
153 | } |
---|
154 | |
---|
155 | static inline Bool isAlignedBins(TComCodingStatisticsType statT) { return statT==STATS__CABAC_BITS__ALIGNED_SIGN_BIT || statT==STATS__CABAC_BITS__ALIGNED_ESCAPE_BITS; } |
---|
156 | |
---|
157 | static const UInt CODING_STATS_NUM_WIDTHS=7; |
---|
158 | static const UInt CODING_STATS_NUM_SUBCLASSES=CODING_STATS_NUM_WIDTHS*(1+MAX_NUM_COMPONENT+MAX_NUM_CHANNEL_TYPE); |
---|
159 | |
---|
160 | class TComCodingStatisticsClassType |
---|
161 | { |
---|
162 | public: |
---|
163 | |
---|
164 | TComCodingStatisticsClassType(const TComCodingStatisticsType t) |
---|
165 | : type(t), subClass(0) |
---|
166 | { } |
---|
167 | TComCodingStatisticsClassType(const TComCodingStatisticsType t, const UInt log2w ) |
---|
168 | : type(t), subClass(log2w) |
---|
169 | { } |
---|
170 | TComCodingStatisticsClassType(const TComCodingStatisticsType t, const Int log2w ) |
---|
171 | : type(t), subClass(log2w) |
---|
172 | { } |
---|
173 | TComCodingStatisticsClassType(const TComCodingStatisticsType t, const ComponentID cid ) |
---|
174 | : type(t), subClass((cid+1)*CODING_STATS_NUM_WIDTHS) |
---|
175 | { } |
---|
176 | TComCodingStatisticsClassType(const TComCodingStatisticsType t, const ChannelType chid ) |
---|
177 | : type(t), subClass((chid+MAX_NUM_COMPONENT+1)*CODING_STATS_NUM_WIDTHS) |
---|
178 | { } |
---|
179 | TComCodingStatisticsClassType(const TComCodingStatisticsType t, const UInt log2w, const ComponentID cid ) |
---|
180 | : type(t), subClass((cid+1)*CODING_STATS_NUM_WIDTHS + log2w) |
---|
181 | { } |
---|
182 | TComCodingStatisticsClassType(const TComCodingStatisticsType t, const UInt log2w, const ChannelType chid ) |
---|
183 | : type(t), subClass((chid+MAX_NUM_COMPONENT+1)*CODING_STATS_NUM_WIDTHS + log2w) |
---|
184 | { } |
---|
185 | |
---|
186 | static UInt GetSubClassWidth(const UInt subClass) |
---|
187 | { |
---|
188 | return subClass%CODING_STATS_NUM_WIDTHS; |
---|
189 | } |
---|
190 | |
---|
191 | static const Char *GetSubClassString(const UInt subClass) |
---|
192 | { |
---|
193 | assert (subClass<CODING_STATS_NUM_SUBCLASSES); |
---|
194 | static const Char *strings[1+MAX_NUM_COMPONENT+MAX_NUM_CHANNEL_TYPE]={"-", "Y", "Cb", "Cr", "Luma", "Chroma"}; |
---|
195 | return strings[subClass/CODING_STATS_NUM_WIDTHS]; |
---|
196 | } |
---|
197 | |
---|
198 | TComCodingStatisticsType type; |
---|
199 | UInt subClass; |
---|
200 | }; |
---|
201 | |
---|
202 | |
---|
203 | |
---|
204 | class TComCodingStatistics |
---|
205 | { |
---|
206 | public: |
---|
207 | |
---|
208 | |
---|
209 | struct StatLogValue |
---|
210 | { |
---|
211 | UInt values[512+1]; |
---|
212 | StatLogValue() |
---|
213 | { |
---|
214 | const Double es=Double(TCOMCODINGSTATISTICS_ENTROPYSCALE); |
---|
215 | values[0]=0; |
---|
216 | for(UInt i=1; i<sizeof(values)/sizeof(UInt); i++) |
---|
217 | { |
---|
218 | values[i]=UInt( log(Double(i))*es/log(2.0) ); |
---|
219 | } |
---|
220 | } |
---|
221 | }; |
---|
222 | |
---|
223 | struct SStat |
---|
224 | { |
---|
225 | SStat() : bits(0), count(0), sum(0) { } |
---|
226 | Int64 bits; |
---|
227 | Int64 count; |
---|
228 | Int64 sum; |
---|
229 | Void clear() { bits=0; count=0; sum=0; } |
---|
230 | |
---|
231 | SStat &operator+=(const SStat &src) |
---|
232 | { bits+=src.bits; count+=src.count; sum+=src.sum; return *this; } |
---|
233 | }; |
---|
234 | |
---|
235 | class TComCodingStatisticsData |
---|
236 | { |
---|
237 | private: |
---|
238 | SStat statistics[STATS__NUM_STATS+1][CODING_STATS_NUM_SUBCLASSES]; |
---|
239 | SStat statistics_ep[STATS__NUM_STATS+1][CODING_STATS_NUM_SUBCLASSES ]; |
---|
240 | std::map<std::string, SStat> mappings_ep; |
---|
241 | friend class TComCodingStatistics; |
---|
242 | }; |
---|
243 | |
---|
244 | private: |
---|
245 | |
---|
246 | TComCodingStatisticsData data; |
---|
247 | |
---|
248 | TComCodingStatistics() : data() |
---|
249 | { } |
---|
250 | |
---|
251 | static Void OutputLine(const Char *pName, const Char sep, UInt width, const Char *pSubClassStr, const SStat &sCABAC, const SStat &sEP) |
---|
252 | { |
---|
253 | if (width==0) |
---|
254 | { |
---|
255 | OutputLine(pName, sep, "-", pSubClassStr, sCABAC, sEP); |
---|
256 | } |
---|
257 | else |
---|
258 | { |
---|
259 | printf("%c%-45s%c %6d %6s %12lld %12lld %12lld %12lld %12lld %12lld %12lld (%12lld)%c\n", |
---|
260 | sep=='~'?'[':' ', pName, sep, 1<<width, pSubClassStr, |
---|
261 | sCABAC.count, sCABAC.sum, sCABAC.bits, sEP.count, sEP.sum, sEP.bits, sCABAC.bits+sEP.bits, (sCABAC.bits+sEP.bits)/8, sep=='~'?']':' '); |
---|
262 | } |
---|
263 | } |
---|
264 | static Void OutputLine(const Char *pName, const Char sep, const Char *pWidthString, const Char *pSubClassStr, const SStat &sCABAC, const SStat &sEP) |
---|
265 | { |
---|
266 | printf("%c%-45s%c %6s %6s %12lld %12lld %12lld %12lld %12lld %12lld %12lld (%12lld)%c\n", |
---|
267 | sep=='~'?'[':' ', pName, sep, pWidthString, pSubClassStr, |
---|
268 | sCABAC.count, sCABAC.sum, sCABAC.bits, sEP.count, sEP.sum, sEP.bits, sCABAC.bits+sEP.bits, (sCABAC.bits+sEP.bits)/8, sep=='~'?']':' '); |
---|
269 | } |
---|
270 | static Void OutputLine(const Char *pName, const Char sep, const Char *pWidthString, const Char *pSubClassStr, const SStat &sEP) |
---|
271 | { |
---|
272 | printf("%c%-45s%c %6s %6s %12s %12s %12s %12lld %12lld %12lld %12lld (%12lld)%c\n", |
---|
273 | sep=='~'?'[':' ', pName, sep, pWidthString, pSubClassStr, |
---|
274 | "", "", "", sEP.count, sEP.sum, sEP.bits, sEP.bits, (sEP.bits)/8, sep=='~'?']':' '); |
---|
275 | } |
---|
276 | |
---|
277 | static Void OutputDashedLine(const Char *pText) |
---|
278 | { |
---|
279 | printf("--%s",pText); |
---|
280 | UInt tot=0; |
---|
281 | for(;pText[tot]!=0; tot++); |
---|
282 | |
---|
283 | tot+=2; |
---|
284 | for (; tot<168; tot++) |
---|
285 | { |
---|
286 | printf("-"); |
---|
287 | } |
---|
288 | printf("\n"); |
---|
289 | } |
---|
290 | |
---|
291 | ~TComCodingStatistics() |
---|
292 | { |
---|
293 | const Int64 es=TCOMCODINGSTATISTICS_ENTROPYSCALE; |
---|
294 | |
---|
295 | Int64 cr=0; // CABAC remainder, which is added to "STATS__CABAC_INITIALISATION" |
---|
296 | { |
---|
297 | Int64 totalCABACbits=0, roundedCABACbits=0; |
---|
298 | for(Int i=STATS__NAL_UNIT_PACKING; i<STATS__NUM_STATS; i++) |
---|
299 | { |
---|
300 | for(UInt c=0; c<CODING_STATS_NUM_SUBCLASSES; c++) |
---|
301 | { |
---|
302 | totalCABACbits+=data.statistics[i][c].bits; |
---|
303 | roundedCABACbits+=data.statistics[i][c].bits/es; |
---|
304 | } |
---|
305 | } |
---|
306 | Int64 remainder=totalCABACbits - roundedCABACbits*es; |
---|
307 | cr=(remainder+es/2)/es; |
---|
308 | } |
---|
309 | |
---|
310 | printf("Note %s will be excluded from the total as it should be the sum of all the other entries (except for %s)\n", getName(STATS__NAL_UNIT_TOTAL_BODY), getName(STATS__NAL_UNIT_PACKING)); |
---|
311 | printf(" %-45s- Width Type CABAC Count CABAC Sum CABAC bits EP Count EP Sum EP bits Total bits ( Total bytes)\n", "Decoder statistics"); |
---|
312 | |
---|
313 | OutputDashedLine(""); |
---|
314 | SStat cabacTotalBits, epTotalBits; |
---|
315 | SStat statTotals_cabac[CODING_STATS_NUM_SUBCLASSES]; |
---|
316 | SStat statTotals_ep[CODING_STATS_NUM_SUBCLASSES]; |
---|
317 | |
---|
318 | for(Int i=0; i<STATS__NUM_STATS; i++) |
---|
319 | { |
---|
320 | SStat cabacSubTotal, epSubTotal; |
---|
321 | Bool bHadClassifiedEntry=false; |
---|
322 | const Char *pName=getName(TComCodingStatisticsType(i)); |
---|
323 | |
---|
324 | for(UInt c=0; c<CODING_STATS_NUM_SUBCLASSES; c++) |
---|
325 | { |
---|
326 | SStat &sCABACorig=data.statistics[i][c]; |
---|
327 | SStat &sEP=data.statistics_ep[i][c]; |
---|
328 | |
---|
329 | if (sCABACorig.bits==0 && sEP.bits==0) |
---|
330 | { |
---|
331 | continue; |
---|
332 | } |
---|
333 | |
---|
334 | SStat sCABAC; |
---|
335 | { |
---|
336 | Int64 thisCABACbits=sCABACorig.bits/es; |
---|
337 | if (i==STATS__CABAC_INITIALISATION && sCABACorig.bits!=0) |
---|
338 | { |
---|
339 | thisCABACbits+=cr; |
---|
340 | cr=0; |
---|
341 | } |
---|
342 | sCABAC.bits=thisCABACbits; |
---|
343 | sCABAC.count=sCABACorig.count; |
---|
344 | sCABAC.sum=sCABACorig.sum; |
---|
345 | } |
---|
346 | UInt width=TComCodingStatisticsClassType::GetSubClassWidth(c); |
---|
347 | OutputLine(pName, ':', width, TComCodingStatisticsClassType::GetSubClassString(c), sCABAC, sEP); |
---|
348 | cabacSubTotal+=sCABAC; |
---|
349 | epSubTotal+=sEP; |
---|
350 | if (i!=STATS__NAL_UNIT_TOTAL_BODY) |
---|
351 | { |
---|
352 | cabacTotalBits+=sCABAC; |
---|
353 | epTotalBits+=sEP; |
---|
354 | statTotals_cabac[c]+=sCABAC; |
---|
355 | statTotals_ep[c]+=sEP; |
---|
356 | } |
---|
357 | bHadClassifiedEntry=bHadClassifiedEntry||(c!=0); |
---|
358 | } |
---|
359 | if (bHadClassifiedEntry) |
---|
360 | { |
---|
361 | OutputLine(pName, '~', "~~ST~~", "~~ST~~", cabacSubTotal, epSubTotal); |
---|
362 | } |
---|
363 | if (i==STATS__NAL_UNIT_TOTAL_BODY) |
---|
364 | { |
---|
365 | OutputDashedLine(""); |
---|
366 | } |
---|
367 | } |
---|
368 | OutputDashedLine(""); |
---|
369 | OutputLine("CABAC Sub-total", '~', "~~ST~~", "~~ST~~", cabacTotalBits, epTotalBits); |
---|
370 | |
---|
371 | OutputDashedLine("CAVLC HEADER BITS"); |
---|
372 | SStat cavlcTotalBits; |
---|
373 | for(std::map<std::string, SStat>::iterator it=data.mappings_ep.begin(); it!=data.mappings_ep.end(); it++) |
---|
374 | { |
---|
375 | SStat s=it->second; |
---|
376 | cavlcTotalBits+=s; |
---|
377 | OutputLine(it->first.c_str(), ':', "-", "-", s); |
---|
378 | } |
---|
379 | |
---|
380 | OutputDashedLine(""); |
---|
381 | OutputLine("CAVLC Header Sub-total", '~', "~~ST~~", "~~ST~~", cavlcTotalBits); |
---|
382 | |
---|
383 | // Now output the breakdowns |
---|
384 | OutputDashedLine("CABAC Break down by size"); |
---|
385 | for(UInt s=0; s<CODING_STATS_NUM_WIDTHS; s++) |
---|
386 | { |
---|
387 | SStat subTotalCabac, subTotalEP; |
---|
388 | for(UInt c=0; c<CODING_STATS_NUM_SUBCLASSES; c+=CODING_STATS_NUM_WIDTHS) |
---|
389 | { |
---|
390 | subTotalCabac+=statTotals_cabac[c+s]; |
---|
391 | subTotalEP+=statTotals_ep[c+s]; |
---|
392 | } |
---|
393 | if (subTotalCabac.bits!=0 || subTotalEP.bits!=0) |
---|
394 | { |
---|
395 | OutputLine("CABAC by size Sub-total", '=', s, "All", subTotalCabac, subTotalEP); |
---|
396 | } |
---|
397 | } |
---|
398 | OutputDashedLine("Break down by component/Channel type"); |
---|
399 | for(UInt c=0; c<CODING_STATS_NUM_SUBCLASSES; c+=CODING_STATS_NUM_WIDTHS) |
---|
400 | { |
---|
401 | SStat subTotalCabac, subTotalEP; |
---|
402 | for(UInt s=0; s<CODING_STATS_NUM_WIDTHS; s++) |
---|
403 | { |
---|
404 | subTotalCabac+=statTotals_cabac[c+s]; |
---|
405 | subTotalEP+=statTotals_ep[c+s]; |
---|
406 | } |
---|
407 | if (subTotalCabac.bits!=0 || subTotalEP.bits!=0) |
---|
408 | { |
---|
409 | OutputLine("CABAC by type Sub-total", '=', "-", TComCodingStatisticsClassType::GetSubClassString(c), subTotalCabac, subTotalEP); |
---|
410 | } |
---|
411 | } |
---|
412 | OutputDashedLine("Break down by size and component/Channel type"); |
---|
413 | for(UInt c=0; c<CODING_STATS_NUM_SUBCLASSES; c+=CODING_STATS_NUM_WIDTHS) |
---|
414 | { |
---|
415 | for(UInt s=0; s<CODING_STATS_NUM_WIDTHS; s++) |
---|
416 | { |
---|
417 | SStat subTotalCabac, subTotalEP; |
---|
418 | subTotalCabac+=statTotals_cabac[c+s]; |
---|
419 | subTotalEP+=statTotals_ep[c+s]; |
---|
420 | if (subTotalCabac.bits!=0 || subTotalEP.bits!=0) |
---|
421 | { |
---|
422 | OutputLine("CABAC by size and type Sub-total", '=', s, TComCodingStatisticsClassType::GetSubClassString(c), subTotalCabac, subTotalEP); |
---|
423 | } |
---|
424 | } |
---|
425 | } |
---|
426 | |
---|
427 | OutputDashedLine(""); |
---|
428 | OutputLine("CABAC Sub-total", '~', "~~ST~~", "~~ST~~", cabacTotalBits, epTotalBits); |
---|
429 | OutputLine("CAVLC Header Sub-total", '~', "~~ST~~", "~~ST~~", cavlcTotalBits); |
---|
430 | OutputDashedLine("GRAND TOTAL"); |
---|
431 | epTotalBits+=cavlcTotalBits; |
---|
432 | OutputLine("TOTAL", '~', "~~GT~~", "~~GT~~", cabacTotalBits, epTotalBits); |
---|
433 | } |
---|
434 | |
---|
435 | |
---|
436 | public: |
---|
437 | static TComCodingStatistics& GetSingletonInstance() |
---|
438 | { |
---|
439 | static TComCodingStatistics inst; |
---|
440 | return inst; |
---|
441 | } |
---|
442 | |
---|
443 | static const TComCodingStatisticsData &GetStatistics() { return GetSingletonInstance().data; } |
---|
444 | static Void SetStatistics(const TComCodingStatisticsData &src) { GetSingletonInstance().data=src; } |
---|
445 | |
---|
446 | static SStat &GetStatisticEP(const TComCodingStatisticsClassType &stat) { return GetSingletonInstance().data.statistics_ep[stat.type][stat.subClass]; } |
---|
447 | |
---|
448 | static SStat &GetStatisticEP(const std::string &str) { return GetSingletonInstance().data.mappings_ep[str]; } |
---|
449 | |
---|
450 | static SStat &GetStatisticEP(const Char *pKey) {return GetStatisticEP(std::string(pKey)); } |
---|
451 | |
---|
452 | static Void IncrementStatisticEP(const TComCodingStatisticsClassType &stat, const Int numBits, const Int value) |
---|
453 | { |
---|
454 | SStat &s=GetStatisticEP(stat); |
---|
455 | s.bits+=numBits; |
---|
456 | s.count++; |
---|
457 | s.sum+=value; |
---|
458 | } |
---|
459 | |
---|
460 | static Void IncrementStatisticEP(const std::string &str, const Int numBits, const Int value) |
---|
461 | { |
---|
462 | SStat &s=GetStatisticEP(str); |
---|
463 | s.bits+=numBits; |
---|
464 | s.count++; |
---|
465 | s.sum+=value; |
---|
466 | } |
---|
467 | |
---|
468 | static Void IncrementStatisticEP(const Char *pKey, const Int numBits, const Int value) |
---|
469 | { |
---|
470 | SStat &s=GetStatisticEP(pKey); |
---|
471 | s.bits+=numBits; |
---|
472 | s.count++; |
---|
473 | s.sum+=value; |
---|
474 | } |
---|
475 | |
---|
476 | StatLogValue values; |
---|
477 | |
---|
478 | static Void UpdateCABACStat(const TComCodingStatisticsClassType &stat, UInt uiRangeBefore, UInt uiRangeAfter, Int val) |
---|
479 | { |
---|
480 | TComCodingStatistics &inst=GetSingletonInstance(); |
---|
481 | // doing rangeBefore*p(x)=rangeAfter |
---|
482 | // p(x)=rangeAfter/rangeBefore |
---|
483 | // entropy = -log2(p(x))=-log(p(x))/log(2) = -(log rangeAfter - log rangeBefore) / log(2) = (log rangeBefore / log 2 - log rangeAfter / log 2) |
---|
484 | SStat &s=inst.data.statistics[stat.type][stat.subClass]; |
---|
485 | s.bits+=inst.values.values[uiRangeBefore]-inst.values.values[uiRangeAfter]; |
---|
486 | s.count++; |
---|
487 | s.sum+=val; |
---|
488 | } |
---|
489 | }; |
---|
490 | |
---|
491 | #endif |
---|