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