source: 3DVCSoftware/trunk/source/Lib/TLibDecoder/TDecConformance.h @ 1413

Last change on this file since 1413 was 1413, checked in by tech, 6 years ago

Merged HTM-16.2-dev@1412

  • Property svn:eol-style set to native
File size: 9.0 KB
Line 
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/** \file     TDecConformance.h
35    \brief    Decoder conformance functions (header)
36*/
37
38#ifndef __TDECCONFORMANCE__
39#define __TDECCONFORMANCE__
40
41// This can be enabled externally. Note that this is a PARTIAL CONFORMANCE CHECK - not a full check. More checks may be added later
42#ifndef DECODER_PARTIAL_CONFORMANCE_CHECK
43#define DECODER_PARTIAL_CONFORMANCE_CHECK                 0 ///< 0 (default) = do not check conformance. 1 = warn if conformance checks fail. 2 = error and quit if conformance checks fail. Note this is only a partial conformance check - not a full conformance check.
44#endif
45
46
47
48#if _MSC_VER > 1000
49#pragma once
50#endif // _MSC_VER > 1000
51
52#include "TLibCommon/CommonDef.h"
53#include <stdio.h>
54#include <iostream>
55#if DECODER_PARTIAL_CONFORMANCE_CHECK == 2
56#include <stdlib.h>
57#endif
58
59
60// Forward declarations
61class TComSlice;
62class TComSPS;
63class TComPPS;
64class InputNALUnit;
65class TComPTL;
66class TComPic;
67
68typedef enum TRISTATE
69{
70  DISABLED=0,
71  OPTIONAL=1,
72  ENABLED=2
73} TRISTATE;
74
75
76typedef enum HBRFACTOREQN
77{
78  HBR_1 = 0,
79  HBR_1_OR_2 = 1,
80  HBR_12_OR_24 = 2
81} HBRFACTOREQN;
82
83
84struct LevelTierFeatures
85{
86  Level::Name level;
87  UInt        maxLumaPs;
88  UInt        maxCpb[Level::NUMBER_OF_TIERS];    // in units of CpbVclFactor or CpbNalFactor bits
89  UInt        maxSliceSegmentsPerPicture;
90  UInt        maxTileRows;
91  UInt        maxTileCols;
92  UInt64      maxLumaSr;
93  UInt        maxBr[Level::NUMBER_OF_TIERS];     // in units of BrVclFactor or BrNalFactor bits/s
94  UInt        minCrBase[Level::NUMBER_OF_TIERS];
95  UInt        getMaxPicWidthInLumaSamples()  const;
96  UInt        getMaxPicHeightInLumaSamples() const;
97};
98
99
100struct ProfileFeatures
101{
102  Profile::Name            profile;
103  const TChar            *pNameString;
104  UInt                     maxBitDepth;
105  ChromaFormat             maxChromaFormat;
106  Bool                     generalIntraConstraintFlag;
107  Bool                     generalOnePictureOnlyConstraintFlag;
108  TRISTATE                 generalLowerBitRateConstraint;
109  TRISTATE                 generalRExtToolsEnabled;
110  TRISTATE                 extendedPrecisionProcessingFlag;
111  TRISTATE                 chromaQpOffsetListEnabledFlag;
112  TRISTATE                 cabacBypassAlignmentEnabledFlag;
113  HBRFACTOREQN             hbrFactorEqn;
114  Bool                     bWavefrontsAndTilesCanBeUsedSimultaneously;
115
116  UInt                     minTileColumnWidthInLumaSamples;
117  UInt                     minTileRowHeightInLumaSamples;
118  Bool                     bCanUseLevel8p5;
119  UInt                     cpbVclFactor;
120  UInt                     cpbNalFactor;                // currently not used for checking
121  UInt                     formatCapabilityFactorx1000; // currently not used for checking
122  UInt                     minCrScaleFactorx10;         // currently not used for checking
123  const LevelTierFeatures *pLevelTiersListInfo;
124
125  Bool chromaFormatValid(ChromaFormat chFmt) const { return (profile == Profile::MAINREXT || profile == Profile::HIGHTHROUGHPUTREXT) ? chFmt<=maxChromaFormat : (chFmt == maxChromaFormat ); }
126  Bool onlyIRAPPictures()                    const { return generalIntraConstraintFlag; }
127  UInt getHbrFactor(Bool bLowerBitRateConstraintFlag) const    // currently not used for checking
128  {
129    return hbrFactorEqn==HBR_1_OR_2   ? (2-(bLowerBitRateConstraintFlag?1:0)) :
130          (hbrFactorEqn==HBR_12_OR_24 ? 12*(2-(bLowerBitRateConstraintFlag?1:0)) :
131                                        1);
132  }
133};
134
135
136class ProfileLevelTierFeatures
137{
138  private:
139    const ProfileFeatures   *m_pProfile;
140    const LevelTierFeatures *m_pLevelTier;
141    UInt                     m_hbrFactor;               // currently not used for checking
142    Level::Tier              m_tier;
143    UInt                     m_maxRawCtuBits;
144  public:
145    ProfileLevelTierFeatures() : m_pProfile(0), m_pLevelTier(0), m_hbrFactor(0), m_tier(Level::MAIN), m_maxRawCtuBits(0) { }
146
147    Void activate(const TComSPS &sps);
148
149    const ProfileFeatures     *getProfileFeatures()   const { return m_pProfile; }
150    const LevelTierFeatures   *getLevelTierFeatures() const { return m_pLevelTier; }
151    Level::Tier                getTier() const { return m_tier; }
152    UInt64 getCpbSizeInBits()            const { return (m_pLevelTier!=0 && m_pProfile!=0) ? UInt64(m_pProfile->cpbVclFactor) * m_pLevelTier->maxCpb[m_tier?1:0] : UInt64(0); }
153    Double getMinCr()                    const { return (m_pLevelTier!=0 && m_pProfile!=0) ? (m_pProfile->minCrScaleFactorx10 * m_pLevelTier->minCrBase[m_tier?1:0])/10.0 : 0.0 ; }   // currently not used for checking
154    UInt getMaxRawCtuBits()              const { return m_maxRawCtuBits; }
155};
156
157
158class TDecConformanceCheck
159{
160private:
161#if MCTS_ENC_CHECK
162  Bool m_tmctsCheckEnabled;
163#endif
164#if DECODER_PARTIAL_CONFORMANCE_CHECK
165  UInt  m_numberOfSlicesInPicture;
166  UInt64 m_bytesInPicture;
167#endif
168  ProfileLevelTierFeatures m_activatedFeatures;
169
170public:
171
172  // Static member functions
173
174  static inline Bool doChecking()
175  {
176    return DECODER_PARTIAL_CONFORMANCE_CHECK != 0;
177  }
178
179  static UInt getMinLog2CtbSize(const TComPTL &ptl, UInt layerPlus1=0);
180  static UInt getMaxLog2CtbSize(const TComPTL &ptl, UInt layerPlus1=0);
181
182
183#if DECODER_PARTIAL_CONFORMANCE_CHECK == 0
184  static inline std::ostream &getStream()  { return std::cout; }
185
186  static inline Void finishWarningReport() { }
187
188  template <class T>
189  static Void checkRange(const T& , const TChar *, const T& , const T& ) { }
190
191#else
192
193
194  static inline std::ostream &getStream()
195  {
196#if DECODER_PARTIAL_CONFORMANCE_CHECK == 1
197    std::cout << "WARNING: Conformance failure - ";
198    return std::cout;
199#else
200    std::cerr << "ERROR: Conformance failure - ";
201    return std::cerr;
202#endif
203  }
204
205  static inline Void finishWarningReport()
206  {
207#if DECODER_PARTIAL_CONFORMANCE_CHECK == 2
208    exit(1);
209#endif
210  }
211
212  template <class T>
213  static Void checkRange(const T& val, const TChar *name, const T& minValInclusive, const T& maxValInclusive)
214  {
215    if (val<minValInclusive || val>maxValInclusive)
216    {
217      getStream() << name << " must be in the range of " << minValInclusive << " to " << maxValInclusive << " (inclusive) - decoded value of " << val << "\n";
218      finishWarningReport();
219    }
220  }
221
222#endif
223
224
225  // Member functions
226
227  TDecConformanceCheck();
228
229#if DECODER_PARTIAL_CONFORMANCE_CHECK == 0
230  Void
231  checkSliceActivation(const TComSlice &/*slice*/,
232                       const InputNALUnit &/*nalu*/,
233                       const TComPic &/*pic*/,
234                       const Bool /*bFirstSliceInStream*/,
235                       const Bool /*bFirstSliceInSequence*/,
236                       const Bool /*bFirstSliceInPicture*/) { }
237
238  Void
239  checkCtuDecoding(const UInt numUsedBits) { }
240#else
241  Void
242  checkSliceActivation(const TComSlice &slice,
243                       const InputNALUnit &nalu,
244                       const TComPic &pic,
245                       const Bool bFirstSliceInStream,
246                       const Bool bFirstSliceInSequence,
247                       const Bool bFirstSliceInPicture);
248
249  Void
250  checkCtuDecoding(const UInt numUsedBits);
251#endif
252
253#if MCTS_ENC_CHECK
254  Void enableTMctsCheck(Bool enabled) { m_tmctsCheckEnabled = enabled; };
255  Bool getTMctsCheck() const { return m_tmctsCheckEnabled;  }
256  Void flagTMctsError(const char *error)
257  {
258    fprintf(stderr, "TMCTS check error: %s\n", error);
259  }
260#endif
261};
262
263
264#endif
Note: See TracBrowser for help on using the repository browser.