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-2017, 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 | #if NH_3D |
---|
84 | STATS__CABAC_BITS__DBBP_FLAG, |
---|
85 | STATS__CABAC_BITS__ARP_FLAG, |
---|
86 | #endif |
---|
87 | STATS__CABAC_BITS__SAO, |
---|
88 | STATS__CABAC_TRM_BITS, |
---|
89 | STATS__CABAC_FIXED_BITS, |
---|
90 | STATS__CABAC_PCM_ALIGN_BITS, |
---|
91 | STATS__CABAC_PCM_CODE_BITS, |
---|
92 | STATS__BYTE_ALIGNMENT_BITS, |
---|
93 | STATS__TRAILING_BITS, |
---|
94 | STATS__EXPLICIT_RDPCM_BITS, |
---|
95 | STATS__CABAC_EP_BIT_ALIGNMENT, |
---|
96 | STATS__CABAC_BITS__ALIGNED_SIGN_BIT, |
---|
97 | STATS__CABAC_BITS__ALIGNED_ESCAPE_BITS, |
---|
98 | |
---|
99 | #if NH_3D |
---|
100 | STATS__CABAC_BITS__3D_IC, |
---|
101 | STATS__CABAC_BITS__DELTADC_SIGN_EP, |
---|
102 | STATS__CABAC_BITS__DELTADC_PREFIX, |
---|
103 | STATS__CABAC_BITS__DELTADC_SUFFIX_EP, |
---|
104 | STATS__CABAC_BITS__NOTDMM_FLAG, |
---|
105 | STATS__CABAC_BITS__DMMMODE, |
---|
106 | STATS__CABAC_BITS__DMM1_BITS_EP, |
---|
107 | STATS__CABAC_BITS__SDC_INTRA_FLAG, |
---|
108 | STATS__CABAC_BITS__SDC_DELTADC_FLAG, |
---|
109 | #endif |
---|
110 | |
---|
111 | STATS__NUM_STATS |
---|
112 | }; |
---|
113 | |
---|
114 | static inline const TChar* getName(TComCodingStatisticsType name) |
---|
115 | { |
---|
116 | static const TChar *statNames[]= |
---|
117 | { |
---|
118 | "NAL_UNIT_TOTAL_BODY", // This is a special case and is not included in the total sums. |
---|
119 | "NAL_UNIT_PACKING", |
---|
120 | "EMULATION_PREVENTION_3_BYTES", |
---|
121 | "NAL_UNIT_HEADER_BITS", |
---|
122 | "CABAC_INITIALISATION-and-rounding", |
---|
123 | "CABAC_BITS__TQ_BYPASS_FLAG", |
---|
124 | "CABAC_BITS__SKIP_FLAG", |
---|
125 | "CABAC_BITS__MERGE_FLAG", |
---|
126 | "CABAC_BITS__MERGE_INDEX", |
---|
127 | "CABAC_BITS__MVP_IDX", |
---|
128 | "CABAC_BITS__SPLIT_FLAG", |
---|
129 | "CABAC_BITS__PART_SIZE", |
---|
130 | "CABAC_BITS__PRED_MODE", |
---|
131 | "CABAC_BITS__INTRA_DIR_ANG", |
---|
132 | "CABAC_BITS__INTER_DIR", |
---|
133 | "CABAC_BITS__REF_FRM_IDX", |
---|
134 | "CABAC_BITS__MVD", |
---|
135 | "CABAC_BITS__MVD_EP", |
---|
136 | "CABAC_BITS__TRANSFORM_SUBDIV_FLAG", |
---|
137 | "CABAC_BITS__QT_ROOT_CBF", |
---|
138 | "CABAC_BITS__DELTA_QP_EP", |
---|
139 | "CABAC_BITS__CHROMA_QP_ADJUSTMENT", |
---|
140 | "CABAC_BITS__QT_CBF", |
---|
141 | "CABAC_BITS__CROSS_COMPONENT_PREDICTION", |
---|
142 | "CABAC_BITS__TRANSFORM_SKIP_FLAGS", |
---|
143 | "CABAC_BITS__LAST_SIG_X_Y", |
---|
144 | "CABAC_BITS__SIG_COEFF_GROUP_FLAG", |
---|
145 | "CABAC_BITS__SIG_COEFF_MAP_FLAG", |
---|
146 | "CABAC_BITS__GT1_FLAG", |
---|
147 | "CABAC_BITS__GT2_FLAG", |
---|
148 | "CABAC_BITS__SIGN_BIT", |
---|
149 | "CABAC_BITS__ESCAPE_BITS", |
---|
150 | #if NH_3D |
---|
151 | "CABAC_BITS__DBBP_FLAG", |
---|
152 | #endif |
---|
153 | "CABAC_BITS__SAO", |
---|
154 | "CABAC_TRM_BITS", |
---|
155 | "CABAC_FIXED_BITS", |
---|
156 | "CABAC_PCM_ALIGN_BITS", |
---|
157 | "CABAC_PCM_CODE_BITS", |
---|
158 | "BYTE_ALIGNMENT_BITS", |
---|
159 | "TRAILING_BITS", |
---|
160 | "EXPLICIT_RDPCM_BITS", |
---|
161 | "CABAC_EP_BIT_ALIGNMENT", |
---|
162 | "CABAC_BITS__ALIGNED_SIGN_BIT", |
---|
163 | "CABAC_BITS__ALIGNED_ESCAPE_BITS" |
---|
164 | |
---|
165 | #if NH_3D |
---|
166 | "CABAC_BITS__3D_IC" |
---|
167 | ,"STATS__CABAC_BITS__DELTADC_SIGN_EP" |
---|
168 | ,"STATS__CABAC_BITS__DELTADC_PREFIX" |
---|
169 | ,"STATS__CABAC_BITS__DELTADC_SUFFIX_EP" |
---|
170 | ,"STATS__CABAC_BITS__NOTDMM_FLAG" |
---|
171 | ,"STATS__CABAC_BITS__DMMMODE" |
---|
172 | ,"STATS__CABAC_BITS__DMM1_BITS_EP" |
---|
173 | ,"STATS__CABAC_BITS__SDC_INTRA_FLAG" |
---|
174 | ,"STATS__CABAC_BITS__SDC_DELTADC_FLAG" |
---|
175 | #endif |
---|
176 | }; |
---|
177 | assert(STATS__NUM_STATS == sizeof(statNames)/sizeof(TChar *) && name < STATS__NUM_STATS); |
---|
178 | return statNames[name]; |
---|
179 | } |
---|
180 | |
---|
181 | static inline Bool isAlignedBins(TComCodingStatisticsType statT) { return statT==STATS__CABAC_BITS__ALIGNED_SIGN_BIT || statT==STATS__CABAC_BITS__ALIGNED_ESCAPE_BITS; } |
---|
182 | |
---|
183 | static const UInt CODING_STATS_NUM_WIDTHS=7; |
---|
184 | static const UInt CODING_STATS_NUM_SUBCLASSES=CODING_STATS_NUM_WIDTHS*(1+MAX_NUM_COMPONENT+MAX_NUM_CHANNEL_TYPE); |
---|
185 | |
---|
186 | class TComCodingStatisticsClassType |
---|
187 | { |
---|
188 | public: |
---|
189 | |
---|
190 | TComCodingStatisticsClassType(const TComCodingStatisticsType t) |
---|
191 | : type(t), subClass(0) |
---|
192 | { } |
---|
193 | TComCodingStatisticsClassType(const TComCodingStatisticsType t, const UInt log2w ) |
---|
194 | : type(t), subClass(log2w) |
---|
195 | { } |
---|
196 | TComCodingStatisticsClassType(const TComCodingStatisticsType t, const Int log2w ) |
---|
197 | : type(t), subClass(log2w) |
---|
198 | { } |
---|
199 | TComCodingStatisticsClassType(const TComCodingStatisticsType t, const ComponentID cid ) |
---|
200 | : type(t), subClass((cid+1)*CODING_STATS_NUM_WIDTHS) |
---|
201 | { } |
---|
202 | TComCodingStatisticsClassType(const TComCodingStatisticsType t, const ChannelType chid ) |
---|
203 | : type(t), subClass((chid+MAX_NUM_COMPONENT+1)*CODING_STATS_NUM_WIDTHS) |
---|
204 | { } |
---|
205 | TComCodingStatisticsClassType(const TComCodingStatisticsType t, const UInt log2w, const ComponentID cid ) |
---|
206 | : type(t), subClass((cid+1)*CODING_STATS_NUM_WIDTHS + log2w) |
---|
207 | { } |
---|
208 | TComCodingStatisticsClassType(const TComCodingStatisticsType t, const UInt log2w, const ChannelType chid ) |
---|
209 | : type(t), subClass((chid+MAX_NUM_COMPONENT+1)*CODING_STATS_NUM_WIDTHS + log2w) |
---|
210 | { } |
---|
211 | |
---|
212 | static UInt GetSubClassWidth(const UInt subClass) |
---|
213 | { |
---|
214 | return subClass%CODING_STATS_NUM_WIDTHS; |
---|
215 | } |
---|
216 | |
---|
217 | static const TChar *GetSubClassString(const UInt subClass) |
---|
218 | { |
---|
219 | assert (subClass<CODING_STATS_NUM_SUBCLASSES); |
---|
220 | static const TChar *strings[1+MAX_NUM_COMPONENT+MAX_NUM_CHANNEL_TYPE]={"-", "Y", "Cb", "Cr", "Luma", "Chroma"}; |
---|
221 | return strings[subClass/CODING_STATS_NUM_WIDTHS]; |
---|
222 | } |
---|
223 | |
---|
224 | TComCodingStatisticsType type; |
---|
225 | UInt subClass; |
---|
226 | }; |
---|
227 | |
---|
228 | |
---|
229 | |
---|
230 | class TComCodingStatistics |
---|
231 | { |
---|
232 | public: |
---|
233 | |
---|
234 | |
---|
235 | struct StatLogValue |
---|
236 | { |
---|
237 | UInt values[512+1]; |
---|
238 | StatLogValue() |
---|
239 | { |
---|
240 | const Double es=Double(TCOMCODINGSTATISTICS_ENTROPYSCALE); |
---|
241 | values[0]=0; |
---|
242 | for(UInt i=1; i<sizeof(values)/sizeof(UInt); i++) |
---|
243 | { |
---|
244 | values[i]=UInt( log(Double(i))*es/log(2.0) ); |
---|
245 | } |
---|
246 | } |
---|
247 | }; |
---|
248 | |
---|
249 | struct SStat |
---|
250 | { |
---|
251 | SStat() : bits(0), count(0), sum(0) { } |
---|
252 | Int64 bits; |
---|
253 | Int64 count; |
---|
254 | Int64 sum; |
---|
255 | Void clear() { bits=0; count=0; sum=0; } |
---|
256 | |
---|
257 | SStat &operator+=(const SStat &src) |
---|
258 | { bits+=src.bits; count+=src.count; sum+=src.sum; return *this; } |
---|
259 | }; |
---|
260 | |
---|
261 | class TComCodingStatisticsData |
---|
262 | { |
---|
263 | private: |
---|
264 | SStat statistics[STATS__NUM_STATS+1][CODING_STATS_NUM_SUBCLASSES]; |
---|
265 | SStat statistics_ep[STATS__NUM_STATS+1][CODING_STATS_NUM_SUBCLASSES ]; |
---|
266 | std::map<std::string, SStat> mappings_ep; |
---|
267 | friend class TComCodingStatistics; |
---|
268 | }; |
---|
269 | |
---|
270 | private: |
---|
271 | |
---|
272 | TComCodingStatisticsData data; |
---|
273 | |
---|
274 | TComCodingStatistics() : data() |
---|
275 | { } |
---|
276 | |
---|
277 | static Void OutputLine(const TChar *pName, const TChar sep, UInt width, const TChar *pSubClassStr, const SStat &sCABAC, const SStat &sEP) |
---|
278 | { |
---|
279 | if (width==0) |
---|
280 | { |
---|
281 | OutputLine(pName, sep, "-", pSubClassStr, sCABAC, sEP); |
---|
282 | } |
---|
283 | else |
---|
284 | { |
---|
285 | printf("%c%-45s%c %6d %6s %12lld %12lld %12lld %12lld %12lld %12lld %12lld (%12lld)%c\n", |
---|
286 | sep=='~'?'[':' ', pName, sep, 1<<width, pSubClassStr, |
---|
287 | sCABAC.count, sCABAC.sum, sCABAC.bits, sEP.count, sEP.sum, sEP.bits, sCABAC.bits+sEP.bits, (sCABAC.bits+sEP.bits)/8, sep=='~'?']':' '); |
---|
288 | } |
---|
289 | } |
---|
290 | static Void OutputLine(const TChar *pName, const TChar sep, const TChar *pWidthString, const TChar *pSubClassStr, const SStat &sCABAC, const SStat &sEP) |
---|
291 | { |
---|
292 | printf("%c%-45s%c %6s %6s %12lld %12lld %12lld %12lld %12lld %12lld %12lld (%12lld)%c\n", |
---|
293 | sep=='~'?'[':' ', pName, sep, pWidthString, pSubClassStr, |
---|
294 | sCABAC.count, sCABAC.sum, sCABAC.bits, sEP.count, sEP.sum, sEP.bits, sCABAC.bits+sEP.bits, (sCABAC.bits+sEP.bits)/8, sep=='~'?']':' '); |
---|
295 | } |
---|
296 | static Void OutputLine(const TChar *pName, const TChar sep, const TChar *pWidthString, const TChar *pSubClassStr, const SStat &sEP) |
---|
297 | { |
---|
298 | printf("%c%-45s%c %6s %6s %12s %12s %12s %12lld %12lld %12lld %12lld (%12lld)%c\n", |
---|
299 | sep=='~'?'[':' ', pName, sep, pWidthString, pSubClassStr, |
---|
300 | "", "", "", sEP.count, sEP.sum, sEP.bits, sEP.bits, (sEP.bits)/8, sep=='~'?']':' '); |
---|
301 | } |
---|
302 | |
---|
303 | static Void OutputDashedLine(const TChar *pText) |
---|
304 | { |
---|
305 | printf("--%s",pText); |
---|
306 | UInt tot=0; |
---|
307 | for(;pText[tot]!=0; tot++); |
---|
308 | |
---|
309 | tot+=2; |
---|
310 | for (; tot<168; tot++) |
---|
311 | { |
---|
312 | printf("-"); |
---|
313 | } |
---|
314 | printf("\n"); |
---|
315 | } |
---|
316 | |
---|
317 | ~TComCodingStatistics() |
---|
318 | { |
---|
319 | const Int64 es=TCOMCODINGSTATISTICS_ENTROPYSCALE; |
---|
320 | |
---|
321 | Int64 cr=0; // CABAC remainder, which is added to "STATS__CABAC_INITIALISATION" |
---|
322 | { |
---|
323 | Int64 totalCABACbits=0, roundedCABACbits=0; |
---|
324 | for(Int i=STATS__NAL_UNIT_PACKING; i<STATS__NUM_STATS; i++) |
---|
325 | { |
---|
326 | for(UInt c=0; c<CODING_STATS_NUM_SUBCLASSES; c++) |
---|
327 | { |
---|
328 | totalCABACbits+=data.statistics[i][c].bits; |
---|
329 | roundedCABACbits+=data.statistics[i][c].bits/es; |
---|
330 | } |
---|
331 | } |
---|
332 | Int64 remainder=totalCABACbits - roundedCABACbits*es; |
---|
333 | cr=(remainder+es/2)/es; |
---|
334 | } |
---|
335 | |
---|
336 | 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)); |
---|
337 | printf(" %-45s- Width Type CABAC Count CABAC Sum CABAC bits EP Count EP Sum EP bits Total bits ( Total bytes)\n", "Decoder statistics"); |
---|
338 | |
---|
339 | OutputDashedLine(""); |
---|
340 | SStat cabacTotalBits, epTotalBits; |
---|
341 | SStat statTotals_cabac[CODING_STATS_NUM_SUBCLASSES]; |
---|
342 | SStat statTotals_ep[CODING_STATS_NUM_SUBCLASSES]; |
---|
343 | |
---|
344 | for(Int i=0; i<STATS__NUM_STATS; i++) |
---|
345 | { |
---|
346 | SStat cabacSubTotal, epSubTotal; |
---|
347 | Bool bHadClassifiedEntry=false; |
---|
348 | const TChar *pName=getName(TComCodingStatisticsType(i)); |
---|
349 | |
---|
350 | for(UInt c=0; c<CODING_STATS_NUM_SUBCLASSES; c++) |
---|
351 | { |
---|
352 | SStat &sCABACorig=data.statistics[i][c]; |
---|
353 | SStat &sEP=data.statistics_ep[i][c]; |
---|
354 | |
---|
355 | if (sCABACorig.bits==0 && sEP.bits==0) |
---|
356 | { |
---|
357 | continue; |
---|
358 | } |
---|
359 | |
---|
360 | SStat sCABAC; |
---|
361 | { |
---|
362 | Int64 thisCABACbits=sCABACorig.bits/es; |
---|
363 | if (i==STATS__CABAC_INITIALISATION && sCABACorig.bits!=0) |
---|
364 | { |
---|
365 | thisCABACbits+=cr; |
---|
366 | cr=0; |
---|
367 | } |
---|
368 | sCABAC.bits=thisCABACbits; |
---|
369 | sCABAC.count=sCABACorig.count; |
---|
370 | sCABAC.sum=sCABACorig.sum; |
---|
371 | } |
---|
372 | UInt width=TComCodingStatisticsClassType::GetSubClassWidth(c); |
---|
373 | OutputLine(pName, ':', width, TComCodingStatisticsClassType::GetSubClassString(c), sCABAC, sEP); |
---|
374 | cabacSubTotal+=sCABAC; |
---|
375 | epSubTotal+=sEP; |
---|
376 | if (i!=STATS__NAL_UNIT_TOTAL_BODY) |
---|
377 | { |
---|
378 | cabacTotalBits+=sCABAC; |
---|
379 | epTotalBits+=sEP; |
---|
380 | statTotals_cabac[c]+=sCABAC; |
---|
381 | statTotals_ep[c]+=sEP; |
---|
382 | } |
---|
383 | bHadClassifiedEntry=bHadClassifiedEntry||(c!=0); |
---|
384 | } |
---|
385 | if (bHadClassifiedEntry) |
---|
386 | { |
---|
387 | OutputLine(pName, '~', "~~ST~~", "~~ST~~", cabacSubTotal, epSubTotal); |
---|
388 | } |
---|
389 | if (i==STATS__NAL_UNIT_TOTAL_BODY) |
---|
390 | { |
---|
391 | OutputDashedLine(""); |
---|
392 | } |
---|
393 | } |
---|
394 | OutputDashedLine(""); |
---|
395 | OutputLine("CABAC Sub-total", '~', "~~ST~~", "~~ST~~", cabacTotalBits, epTotalBits); |
---|
396 | |
---|
397 | OutputDashedLine("CAVLC HEADER BITS"); |
---|
398 | SStat cavlcTotalBits; |
---|
399 | for(std::map<std::string, SStat>::iterator it=data.mappings_ep.begin(); it!=data.mappings_ep.end(); it++) |
---|
400 | { |
---|
401 | SStat s=it->second; |
---|
402 | cavlcTotalBits+=s; |
---|
403 | OutputLine(it->first.c_str(), ':', "-", "-", s); |
---|
404 | } |
---|
405 | |
---|
406 | OutputDashedLine(""); |
---|
407 | OutputLine("CAVLC Header Sub-total", '~', "~~ST~~", "~~ST~~", cavlcTotalBits); |
---|
408 | |
---|
409 | // Now output the breakdowns |
---|
410 | OutputDashedLine("CABAC Break down by size"); |
---|
411 | for(UInt s=0; s<CODING_STATS_NUM_WIDTHS; s++) |
---|
412 | { |
---|
413 | SStat subTotalCabac, subTotalEP; |
---|
414 | for(UInt c=0; c<CODING_STATS_NUM_SUBCLASSES; c+=CODING_STATS_NUM_WIDTHS) |
---|
415 | { |
---|
416 | subTotalCabac+=statTotals_cabac[c+s]; |
---|
417 | subTotalEP+=statTotals_ep[c+s]; |
---|
418 | } |
---|
419 | if (subTotalCabac.bits!=0 || subTotalEP.bits!=0) |
---|
420 | { |
---|
421 | OutputLine("CABAC by size Sub-total", '=', s, "All", subTotalCabac, subTotalEP); |
---|
422 | } |
---|
423 | } |
---|
424 | OutputDashedLine("Break down by component/Channel type"); |
---|
425 | for(UInt c=0; c<CODING_STATS_NUM_SUBCLASSES; c+=CODING_STATS_NUM_WIDTHS) |
---|
426 | { |
---|
427 | SStat subTotalCabac, subTotalEP; |
---|
428 | for(UInt s=0; s<CODING_STATS_NUM_WIDTHS; s++) |
---|
429 | { |
---|
430 | subTotalCabac+=statTotals_cabac[c+s]; |
---|
431 | subTotalEP+=statTotals_ep[c+s]; |
---|
432 | } |
---|
433 | if (subTotalCabac.bits!=0 || subTotalEP.bits!=0) |
---|
434 | { |
---|
435 | OutputLine("CABAC by type Sub-total", '=', "-", TComCodingStatisticsClassType::GetSubClassString(c), subTotalCabac, subTotalEP); |
---|
436 | } |
---|
437 | } |
---|
438 | OutputDashedLine("Break down by size and component/Channel type"); |
---|
439 | for(UInt c=0; c<CODING_STATS_NUM_SUBCLASSES; c+=CODING_STATS_NUM_WIDTHS) |
---|
440 | { |
---|
441 | for(UInt s=0; s<CODING_STATS_NUM_WIDTHS; s++) |
---|
442 | { |
---|
443 | SStat subTotalCabac, subTotalEP; |
---|
444 | subTotalCabac+=statTotals_cabac[c+s]; |
---|
445 | subTotalEP+=statTotals_ep[c+s]; |
---|
446 | if (subTotalCabac.bits!=0 || subTotalEP.bits!=0) |
---|
447 | { |
---|
448 | OutputLine("CABAC by size and type Sub-total", '=', s, TComCodingStatisticsClassType::GetSubClassString(c), subTotalCabac, subTotalEP); |
---|
449 | } |
---|
450 | } |
---|
451 | } |
---|
452 | |
---|
453 | OutputDashedLine(""); |
---|
454 | OutputLine("CABAC Sub-total", '~', "~~ST~~", "~~ST~~", cabacTotalBits, epTotalBits); |
---|
455 | OutputLine("CAVLC Header Sub-total", '~', "~~ST~~", "~~ST~~", cavlcTotalBits); |
---|
456 | OutputDashedLine("GRAND TOTAL"); |
---|
457 | epTotalBits+=cavlcTotalBits; |
---|
458 | OutputLine("TOTAL", '~', "~~GT~~", "~~GT~~", cabacTotalBits, epTotalBits); |
---|
459 | } |
---|
460 | |
---|
461 | |
---|
462 | public: |
---|
463 | static TComCodingStatistics& GetSingletonInstance() |
---|
464 | { |
---|
465 | static TComCodingStatistics inst; |
---|
466 | return inst; |
---|
467 | } |
---|
468 | |
---|
469 | static const TComCodingStatisticsData &GetStatistics() { return GetSingletonInstance().data; } |
---|
470 | static Void SetStatistics(const TComCodingStatisticsData &src) { GetSingletonInstance().data=src; } |
---|
471 | |
---|
472 | static SStat &GetStatisticEP(const TComCodingStatisticsClassType &stat) { return GetSingletonInstance().data.statistics_ep[stat.type][stat.subClass]; } |
---|
473 | |
---|
474 | static SStat &GetStatisticEP(const std::string &str) { return GetSingletonInstance().data.mappings_ep[str]; } |
---|
475 | |
---|
476 | static SStat &GetStatisticEP(const TChar *pKey) {return GetStatisticEP(std::string(pKey)); } |
---|
477 | |
---|
478 | static Void IncrementStatisticEP(const TComCodingStatisticsClassType &stat, const Int numBits, const Int value) |
---|
479 | { |
---|
480 | SStat &s=GetStatisticEP(stat); |
---|
481 | s.bits+=numBits; |
---|
482 | s.count++; |
---|
483 | s.sum+=value; |
---|
484 | } |
---|
485 | |
---|
486 | static Void IncrementStatisticEP(const std::string &str, const Int numBits, const Int value) |
---|
487 | { |
---|
488 | SStat &s=GetStatisticEP(str); |
---|
489 | s.bits+=numBits; |
---|
490 | s.count++; |
---|
491 | s.sum+=value; |
---|
492 | } |
---|
493 | |
---|
494 | static Void IncrementStatisticEP(const TChar *pKey, const Int numBits, const Int value) |
---|
495 | { |
---|
496 | SStat &s=GetStatisticEP(pKey); |
---|
497 | s.bits+=numBits; |
---|
498 | s.count++; |
---|
499 | s.sum+=value; |
---|
500 | } |
---|
501 | |
---|
502 | StatLogValue values; |
---|
503 | |
---|
504 | static Void UpdateCABACStat(const TComCodingStatisticsClassType &stat, UInt uiRangeBefore, UInt uiRangeAfter, Int val) |
---|
505 | { |
---|
506 | TComCodingStatistics &inst=GetSingletonInstance(); |
---|
507 | // doing rangeBefore*p(x)=rangeAfter |
---|
508 | // p(x)=rangeAfter/rangeBefore |
---|
509 | // entropy = -log2(p(x))=-log(p(x))/log(2) = -(log rangeAfter - log rangeBefore) / log(2) = (log rangeBefore / log 2 - log rangeAfter / log 2) |
---|
510 | SStat &s=inst.data.statistics[stat.type][stat.subClass]; |
---|
511 | s.bits+=inst.values.values[uiRangeBefore]-inst.values.values[uiRangeAfter]; |
---|
512 | s.count++; |
---|
513 | s.sum+=val; |
---|
514 | } |
---|
515 | }; |
---|
516 | |
---|
517 | #endif |
---|