/* The copyright in this software is being made available under the BSD * License, included below. This software may be subject to other third party * and contributor rights, including patent rights, and no such rights are * granted under this license. * * Copyright (c) 2010-2015, ITU/ISO/IEC * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may * be used to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __TCOMCODINGSTATISTICS__ #define __TCOMCODINGSTATISTICS__ #include "TypeDef.h" #include #include #include #include #include "TComChromaFormat.h" static const Int64 TCOMCODINGSTATISTICS_ENTROPYSCALE=32768; enum TComCodingStatisticsType { STATS__NAL_UNIT_TOTAL_BODY,// This is a special case and is not included in the total sums. STATS__NAL_UNIT_PACKING, STATS__EMULATION_PREVENTION_3_BYTES, STATS__NAL_UNIT_HEADER_BITS, STATS__CABAC_INITIALISATION, STATS__CABAC_BITS__TQ_BYPASS_FLAG, STATS__CABAC_BITS__SKIP_FLAG, STATS__CABAC_BITS__MERGE_FLAG, STATS__CABAC_BITS__MERGE_INDEX, STATS__CABAC_BITS__MVP_IDX, STATS__CABAC_BITS__SPLIT_FLAG, STATS__CABAC_BITS__PART_SIZE, STATS__CABAC_BITS__PRED_MODE, STATS__CABAC_BITS__INTRA_DIR_ANG, STATS__CABAC_BITS__INTER_DIR, STATS__CABAC_BITS__REF_FRM_IDX, STATS__CABAC_BITS__MVD, STATS__CABAC_BITS__MVD_EP, STATS__CABAC_BITS__TRANSFORM_SUBDIV_FLAG, STATS__CABAC_BITS__QT_ROOT_CBF, STATS__CABAC_BITS__DELTA_QP_EP, STATS__CABAC_BITS__CHROMA_QP_ADJUSTMENT, STATS__CABAC_BITS__QT_CBF, STATS__CABAC_BITS__CROSS_COMPONENT_PREDICTION, STATS__CABAC_BITS__TRANSFORM_SKIP_FLAGS, STATS__CABAC_BITS__LAST_SIG_X_Y, STATS__CABAC_BITS__SIG_COEFF_GROUP_FLAG, STATS__CABAC_BITS__SIG_COEFF_MAP_FLAG, STATS__CABAC_BITS__GT1_FLAG, STATS__CABAC_BITS__GT2_FLAG, STATS__CABAC_BITS__SIGN_BIT, STATS__CABAC_BITS__ESCAPE_BITS, STATS__CABAC_BITS__SAO, STATS__CABAC_TRM_BITS, STATS__CABAC_FIXED_BITS, STATS__CABAC_PCM_ALIGN_BITS, STATS__CABAC_PCM_CODE_BITS, STATS__BYTE_ALIGNMENT_BITS, STATS__TRAILING_BITS, STATS__EXPLICIT_RDPCM_BITS, STATS__CABAC_EP_BIT_ALIGNMENT, STATS__CABAC_BITS__ALIGNED_SIGN_BIT, STATS__CABAC_BITS__ALIGNED_ESCAPE_BITS, STATS__NUM_STATS }; static inline const Char* getName(TComCodingStatisticsType name) { static const Char *statNames[]= { "NAL_UNIT_TOTAL_BODY", // This is a special case and is not included in the total sums. "NAL_UNIT_PACKING", "EMULATION_PREVENTION_3_BYTES", "NAL_UNIT_HEADER_BITS", "CABAC_INITIALISATION-and-rounding", "CABAC_BITS__TQ_BYPASS_FLAG", "CABAC_BITS__SKIP_FLAG", "CABAC_BITS__MERGE_FLAG", "CABAC_BITS__MERGE_INDEX", "CABAC_BITS__MVP_IDX", "CABAC_BITS__SPLIT_FLAG", "CABAC_BITS__PART_SIZE", "CABAC_BITS__PRED_MODE", "CABAC_BITS__INTRA_DIR_ANG", "CABAC_BITS__INTER_DIR", "CABAC_BITS__REF_FRM_IDX", "CABAC_BITS__MVD", "CABAC_BITS__MVD_EP", "CABAC_BITS__TRANSFORM_SUBDIV_FLAG", "CABAC_BITS__QT_ROOT_CBF", "CABAC_BITS__DELTA_QP_EP", "CABAC_BITS__CHROMA_QP_ADJUSTMENT", "CABAC_BITS__QT_CBF", "CABAC_BITS__CROSS_COMPONENT_PREDICTION", "CABAC_BITS__TRANSFORM_SKIP_FLAGS", "CABAC_BITS__LAST_SIG_X_Y", "CABAC_BITS__SIG_COEFF_GROUP_FLAG", "CABAC_BITS__SIG_COEFF_MAP_FLAG", "CABAC_BITS__GT1_FLAG", "CABAC_BITS__GT2_FLAG", "CABAC_BITS__SIGN_BIT", "CABAC_BITS__ESCAPE_BITS", "CABAC_BITS__SAO", "CABAC_TRM_BITS", "CABAC_FIXED_BITS", "CABAC_PCM_ALIGN_BITS", "CABAC_PCM_CODE_BITS", "BYTE_ALIGNMENT_BITS", "TRAILING_BITS", "EXPLICIT_RDPCM_BITS", "CABAC_EP_BIT_ALIGNMENT", "CABAC_BITS__ALIGNED_SIGN_BIT", "CABAC_BITS__ALIGNED_ESCAPE_BITS" }; assert(STATS__NUM_STATS == sizeof(statNames)/sizeof(Char *) && name < STATS__NUM_STATS); return statNames[name]; } static inline Bool isAlignedBins(TComCodingStatisticsType statT) { return statT==STATS__CABAC_BITS__ALIGNED_SIGN_BIT || statT==STATS__CABAC_BITS__ALIGNED_ESCAPE_BITS; } static const UInt CODING_STATS_NUM_WIDTHS=7; static const UInt CODING_STATS_NUM_SUBCLASSES=CODING_STATS_NUM_WIDTHS*(1+MAX_NUM_COMPONENT+MAX_NUM_CHANNEL_TYPE); class TComCodingStatisticsClassType { public: TComCodingStatisticsClassType(const TComCodingStatisticsType t) : type(t), subClass(0) { } TComCodingStatisticsClassType(const TComCodingStatisticsType t, const UInt log2w ) : type(t), subClass(log2w) { } TComCodingStatisticsClassType(const TComCodingStatisticsType t, const Int log2w ) : type(t), subClass(log2w) { } TComCodingStatisticsClassType(const TComCodingStatisticsType t, const ComponentID cid ) : type(t), subClass((cid+1)*CODING_STATS_NUM_WIDTHS) { } TComCodingStatisticsClassType(const TComCodingStatisticsType t, const ChannelType chid ) : type(t), subClass((chid+MAX_NUM_COMPONENT+1)*CODING_STATS_NUM_WIDTHS) { } TComCodingStatisticsClassType(const TComCodingStatisticsType t, const UInt log2w, const ComponentID cid ) : type(t), subClass((cid+1)*CODING_STATS_NUM_WIDTHS + log2w) { } TComCodingStatisticsClassType(const TComCodingStatisticsType t, const UInt log2w, const ChannelType chid ) : type(t), subClass((chid+MAX_NUM_COMPONENT+1)*CODING_STATS_NUM_WIDTHS + log2w) { } static UInt GetSubClassWidth(const UInt subClass) { return subClass%CODING_STATS_NUM_WIDTHS; } static const Char *GetSubClassString(const UInt subClass) { assert (subClass mappings_ep; friend class TComCodingStatistics; }; private: TComCodingStatisticsData data; TComCodingStatistics() : data() { } static Void OutputLine(const Char *pName, const Char sep, UInt width, const Char *pSubClassStr, const SStat &sCABAC, const SStat &sEP) { if (width==0) { OutputLine(pName, sep, "-", pSubClassStr, sCABAC, sEP); } else { printf("%c%-45s%c %6d %6s %12lld %12lld %12lld %12lld %12lld %12lld %12lld (%12lld)%c\n", sep=='~'?'[':' ', pName, sep, 1<::iterator it=data.mappings_ep.begin(); it!=data.mappings_ep.end(); it++) { SStat s=it->second; cavlcTotalBits+=s; OutputLine(it->first.c_str(), ':', "-", "-", s); } OutputDashedLine(""); OutputLine("CAVLC Header Sub-total", '~', "~~ST~~", "~~ST~~", cavlcTotalBits); // Now output the breakdowns OutputDashedLine("CABAC Break down by size"); for(UInt s=0; s