[313] | 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 | * |
---|
[595] | 6 | * Copyright (c) 2010-2014, ITU/ISO/IEC |
---|
[313] | 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 CommonDef.h |
---|
| 35 | \brief Defines constants, macros and tool parameters |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #ifndef __COMMONDEF__ |
---|
| 39 | #define __COMMONDEF__ |
---|
| 40 | |
---|
| 41 | #include <algorithm> |
---|
[1029] | 42 | #include <iostream> |
---|
| 43 | #include <assert.h> |
---|
[595] | 44 | |
---|
[313] | 45 | #if _MSC_VER > 1000 |
---|
| 46 | // disable "signed and unsigned mismatch" |
---|
| 47 | #pragma warning( disable : 4018 ) |
---|
[1029] | 48 | // disable Bool coercion "performance warning" |
---|
[313] | 49 | #pragma warning( disable : 4800 ) |
---|
| 50 | #endif // _MSC_VER > 1000 |
---|
| 51 | #include "TypeDef.h" |
---|
| 52 | |
---|
| 53 | //! \ingroup TLibCommon |
---|
| 54 | //! \{ |
---|
| 55 | |
---|
| 56 | // ==================================================================================================================== |
---|
| 57 | // Version information |
---|
| 58 | // ==================================================================================================================== |
---|
| 59 | |
---|
| 60 | #if SVC_EXTENSION |
---|
[540] | 61 | #include <vector> |
---|
[1080] | 62 | #define NV_VERSION "9.0 (HM-16.2)" ///< Current software version |
---|
[313] | 63 | #else |
---|
[1029] | 64 | #define NV_VERSION "16.2" ///< Current software version |
---|
[313] | 65 | #endif |
---|
| 66 | |
---|
| 67 | // ==================================================================================================================== |
---|
| 68 | // Platform information |
---|
| 69 | // ==================================================================================================================== |
---|
| 70 | |
---|
| 71 | #ifdef __GNUC__ |
---|
| 72 | #define NVM_COMPILEDBY "[GCC %d.%d.%d]", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ |
---|
| 73 | #ifdef __IA64__ |
---|
| 74 | #define NVM_ONARCH "[on 64-bit] " |
---|
| 75 | #else |
---|
| 76 | #define NVM_ONARCH "[on 32-bit] " |
---|
| 77 | #endif |
---|
| 78 | #endif |
---|
| 79 | |
---|
| 80 | #ifdef __INTEL_COMPILER |
---|
| 81 | #define NVM_COMPILEDBY "[ICC %d]", __INTEL_COMPILER |
---|
| 82 | #elif _MSC_VER |
---|
| 83 | #define NVM_COMPILEDBY "[VS %d]", _MSC_VER |
---|
| 84 | #endif |
---|
| 85 | |
---|
| 86 | #ifndef NVM_COMPILEDBY |
---|
| 87 | #define NVM_COMPILEDBY "[Unk-CXX]" |
---|
| 88 | #endif |
---|
| 89 | |
---|
| 90 | #ifdef _WIN32 |
---|
| 91 | #define NVM_ONOS "[Windows]" |
---|
| 92 | #elif __linux |
---|
| 93 | #define NVM_ONOS "[Linux]" |
---|
| 94 | #elif __CYGWIN__ |
---|
| 95 | #define NVM_ONOS "[Cygwin]" |
---|
| 96 | #elif __APPLE__ |
---|
| 97 | #define NVM_ONOS "[Mac OS X]" |
---|
| 98 | #else |
---|
| 99 | #define NVM_ONOS "[Unk-OS]" |
---|
| 100 | #endif |
---|
| 101 | |
---|
[1029] | 102 | #define NVM_BITS "[%d bit] ", (sizeof(Void*) == 8 ? 64 : 32) ///< used for checking 64-bit O/S |
---|
[313] | 103 | |
---|
| 104 | #ifndef NULL |
---|
| 105 | #define NULL 0 |
---|
| 106 | #endif |
---|
| 107 | |
---|
| 108 | // ==================================================================================================================== |
---|
| 109 | // Common constants |
---|
| 110 | // ==================================================================================================================== |
---|
| 111 | |
---|
| 112 | #define _SUMMARY_OUT_ 0 ///< print-out PSNR results of all slices to summary.txt |
---|
| 113 | #define _SUMMARY_PIC_ 0 ///< print-out PSNR results for each slice type to summary.txt |
---|
| 114 | |
---|
| 115 | #define MAX_GOP 64 ///< max. value of hierarchical GOP size |
---|
| 116 | |
---|
| 117 | #define MAX_NUM_REF_PICS 16 ///< max. number of pictures used for reference |
---|
| 118 | #define MAX_NUM_REF 16 ///< max. number of entries in picture reference list |
---|
| 119 | |
---|
| 120 | #define MAX_UINT 0xFFFFFFFFU ///< max. value of unsigned 32-bit integer |
---|
| 121 | #define MAX_INT 2147483647 ///< max. value of signed 32-bit integer |
---|
| 122 | #define MAX_INT64 0x7FFFFFFFFFFFFFFFLL ///< max. value of signed 64-bit integer |
---|
[1029] | 123 | #if RExt__HIGH_BIT_DEPTH_SUPPORT |
---|
| 124 | #define MAX_INTERMEDIATE_INT MAX_INT64 |
---|
| 125 | #else |
---|
| 126 | #define MAX_INTERMEDIATE_INT MAX_INT |
---|
| 127 | #endif |
---|
[313] | 128 | |
---|
[1029] | 129 | #define MAX_DOUBLE 1.7e+308 ///< max. value of Double-type value |
---|
| 130 | |
---|
[313] | 131 | #define MIN_QP 0 |
---|
| 132 | #define MAX_QP 51 |
---|
| 133 | |
---|
| 134 | #define NOT_VALID -1 |
---|
| 135 | |
---|
| 136 | // ==================================================================================================================== |
---|
| 137 | // Macro functions |
---|
| 138 | // ==================================================================================================================== |
---|
[1029] | 139 | |
---|
| 140 | extern Int g_bitDepth[MAX_NUM_CHANNEL_TYPE]; |
---|
| 141 | |
---|
[494] | 142 | #if O0194_DIFFERENT_BITDEPTH_EL_BL |
---|
[1029] | 143 | extern Int g_bitDepthLayer[MAX_NUM_CHANNEL_TYPE][MAX_LAYERS]; |
---|
[494] | 144 | #endif |
---|
| 145 | #if O0194_WEIGHTED_PREDICTION_CGS |
---|
| 146 | extern void* g_refWeightACDCParam; //type:wpACDCParam |
---|
| 147 | #endif |
---|
[313] | 148 | |
---|
[1029] | 149 | template <typename T> inline T Clip3 (const T minVal, const T maxVal, const T a) { return std::min<T> (std::max<T> (minVal, a) , maxVal); } ///< general min/max clip |
---|
| 150 | template <typename T> inline T ClipBD(const T x, const Int bitDepth) { return Clip3(T(0), T((1 << bitDepth)-1), x); } |
---|
| 151 | template <typename T> inline T Clip (const T x, const ChannelType type) { return ClipBD(x, g_bitDepth[type]); } |
---|
[313] | 152 | |
---|
[1029] | 153 | template <typename T> inline Void Check3( T minVal, T maxVal, T a) |
---|
| 154 | { |
---|
| 155 | if ((a > maxVal) || (a < minVal)) |
---|
| 156 | { |
---|
| 157 | std::cerr << "ERROR: Range check " << minVal << " >= " << a << " <= " << maxVal << " failed" << std::endl; |
---|
| 158 | assert(false); |
---|
| 159 | exit(1); |
---|
| 160 | } |
---|
| 161 | } ///< general min/max clip |
---|
| 162 | |
---|
[313] | 163 | #define DATA_ALIGN 1 ///< use 32-bit aligned malloc/free |
---|
| 164 | #if DATA_ALIGN && _WIN32 && ( _MSC_VER > 1300 ) |
---|
| 165 | #define xMalloc( type, len ) _aligned_malloc( sizeof(type)*(len), 32 ) |
---|
| 166 | #define xFree( ptr ) _aligned_free ( ptr ) |
---|
| 167 | #else |
---|
| 168 | #define xMalloc( type, len ) malloc ( sizeof(type)*(len) ) |
---|
| 169 | #define xFree( ptr ) free ( ptr ) |
---|
| 170 | #endif |
---|
| 171 | |
---|
| 172 | #define FATAL_ERROR_0(MESSAGE, EXITCODE) \ |
---|
| 173 | { \ |
---|
| 174 | printf(MESSAGE); \ |
---|
| 175 | exit(EXITCODE); \ |
---|
| 176 | } |
---|
| 177 | |
---|
[1029] | 178 | template <typename ValueType> inline ValueType leftShift (const ValueType value, const Int shift) { return (shift >= 0) ? ( value << shift) : ( value >> -shift); } |
---|
| 179 | template <typename ValueType> inline ValueType rightShift (const ValueType value, const Int shift) { return (shift >= 0) ? ( value >> shift) : ( value << -shift); } |
---|
| 180 | template <typename ValueType> inline ValueType leftShift_round (const ValueType value, const Int shift) { return (shift >= 0) ? ( value << shift) : ((value + (ValueType(1) << (-shift - 1))) >> -shift); } |
---|
| 181 | template <typename ValueType> inline ValueType rightShift_round(const ValueType value, const Int shift) { return (shift >= 0) ? ((value + (ValueType(1) << (shift - 1))) >> shift) : ( value << -shift); } |
---|
| 182 | #if O0043_BEST_EFFORT_DECODING |
---|
| 183 | // when shift = 0, returns value |
---|
| 184 | // when shift = 1, (value + 0 + value[1]) >> 1 |
---|
| 185 | // when shift = 2, (value + 1 + value[2]) >> 2 |
---|
| 186 | // when shift = 3, (value + 3 + value[3]) >> 3 |
---|
| 187 | template <typename ValueType> inline ValueType rightShiftEvenRounding(const ValueType value, const UInt shift) { return (shift == 0) ? value : ((value + (1<<(shift-1))-1 + ((value>>shift)&1)) >> shift) ; } |
---|
| 188 | #endif |
---|
[313] | 189 | |
---|
| 190 | // ==================================================================================================================== |
---|
| 191 | // Coding tool configuration |
---|
| 192 | // ==================================================================================================================== |
---|
| 193 | |
---|
| 194 | // AMVP: advanced motion vector prediction |
---|
| 195 | #define AMVP_MAX_NUM_CANDS 2 ///< max number of final candidates |
---|
| 196 | #define AMVP_MAX_NUM_CANDS_MEM 3 ///< max number of candidates |
---|
| 197 | // MERGE |
---|
| 198 | #define MRG_MAX_NUM_CANDS 5 |
---|
| 199 | |
---|
| 200 | // Reference memory management |
---|
| 201 | #define DYN_REF_FREE 0 ///< dynamic free of reference memories |
---|
| 202 | |
---|
| 203 | // Explicit temporal layer QP offset |
---|
[644] | 204 | #define MAX_TLAYER 7 ///< max number of temporal layer |
---|
[313] | 205 | #define HB_LAMBDA_FOR_LDC 1 ///< use of B-style lambda for non-key pictures in low-delay mode |
---|
| 206 | |
---|
| 207 | // Fast estimation of generalized B in low-delay mode |
---|
| 208 | #define GPB_SIMPLE 1 ///< Simple GPB mode |
---|
| 209 | #if GPB_SIMPLE |
---|
| 210 | #define GPB_SIMPLE_UNI 1 ///< Simple mode for uni-direction |
---|
| 211 | #endif |
---|
| 212 | |
---|
| 213 | // Fast ME using smoother MV assumption |
---|
| 214 | #define FASTME_SMOOTHER_MV 1 ///< reduce ME time using faster option |
---|
| 215 | |
---|
| 216 | // Adaptive search range depending on POC difference |
---|
| 217 | #define ADAPT_SR_SCALE 1 ///< division factor for adaptive search range |
---|
| 218 | |
---|
| 219 | #define CLIP_TO_709_RANGE 0 |
---|
| 220 | |
---|
| 221 | // Early-skip threshold (encoder) |
---|
| 222 | #define EARLY_SKIP_THRES 1.50 ///< if RD < thres*avg[BestSkipRD] |
---|
| 223 | |
---|
| 224 | |
---|
| 225 | #define MAX_CHROMA_FORMAT_IDC 3 |
---|
| 226 | |
---|
| 227 | // TODO: Existing names used for the different NAL unit types can be altered to better reflect the names in the spec. |
---|
| 228 | // However, the names in the spec are not yet stable at this point. Once the names are stable, a cleanup |
---|
| 229 | // effort can be done without use of macros to alter the names used to indicate the different NAL unit types. |
---|
| 230 | enum NalUnitType |
---|
| 231 | { |
---|
| 232 | NAL_UNIT_CODED_SLICE_TRAIL_N = 0, // 0 |
---|
| 233 | NAL_UNIT_CODED_SLICE_TRAIL_R, // 1 |
---|
| 234 | |
---|
| 235 | NAL_UNIT_CODED_SLICE_TSA_N, // 2 |
---|
[540] | 236 | NAL_UNIT_CODED_SLICE_TSA_R, // 3 |
---|
[313] | 237 | |
---|
| 238 | NAL_UNIT_CODED_SLICE_STSA_N, // 4 |
---|
| 239 | NAL_UNIT_CODED_SLICE_STSA_R, // 5 |
---|
| 240 | |
---|
| 241 | NAL_UNIT_CODED_SLICE_RADL_N, // 6 |
---|
| 242 | NAL_UNIT_CODED_SLICE_RADL_R, // 7 |
---|
| 243 | |
---|
| 244 | NAL_UNIT_CODED_SLICE_RASL_N, // 8 |
---|
| 245 | NAL_UNIT_CODED_SLICE_RASL_R, // 9 |
---|
| 246 | |
---|
| 247 | NAL_UNIT_RESERVED_VCL_N10, |
---|
| 248 | NAL_UNIT_RESERVED_VCL_R11, |
---|
| 249 | NAL_UNIT_RESERVED_VCL_N12, |
---|
| 250 | NAL_UNIT_RESERVED_VCL_R13, |
---|
| 251 | NAL_UNIT_RESERVED_VCL_N14, |
---|
| 252 | NAL_UNIT_RESERVED_VCL_R15, |
---|
| 253 | |
---|
| 254 | NAL_UNIT_CODED_SLICE_BLA_W_LP, // 16 |
---|
| 255 | NAL_UNIT_CODED_SLICE_BLA_W_RADL, // 17 |
---|
| 256 | NAL_UNIT_CODED_SLICE_BLA_N_LP, // 18 |
---|
| 257 | NAL_UNIT_CODED_SLICE_IDR_W_RADL, // 19 |
---|
| 258 | NAL_UNIT_CODED_SLICE_IDR_N_LP, // 20 |
---|
| 259 | NAL_UNIT_CODED_SLICE_CRA, // 21 |
---|
| 260 | NAL_UNIT_RESERVED_IRAP_VCL22, |
---|
| 261 | NAL_UNIT_RESERVED_IRAP_VCL23, |
---|
| 262 | |
---|
| 263 | NAL_UNIT_RESERVED_VCL24, |
---|
| 264 | NAL_UNIT_RESERVED_VCL25, |
---|
| 265 | NAL_UNIT_RESERVED_VCL26, |
---|
| 266 | NAL_UNIT_RESERVED_VCL27, |
---|
| 267 | NAL_UNIT_RESERVED_VCL28, |
---|
| 268 | NAL_UNIT_RESERVED_VCL29, |
---|
| 269 | NAL_UNIT_RESERVED_VCL30, |
---|
| 270 | NAL_UNIT_RESERVED_VCL31, |
---|
| 271 | |
---|
| 272 | NAL_UNIT_VPS, // 32 |
---|
| 273 | NAL_UNIT_SPS, // 33 |
---|
| 274 | NAL_UNIT_PPS, // 34 |
---|
| 275 | NAL_UNIT_ACCESS_UNIT_DELIMITER, // 35 |
---|
| 276 | NAL_UNIT_EOS, // 36 |
---|
| 277 | NAL_UNIT_EOB, // 37 |
---|
| 278 | NAL_UNIT_FILLER_DATA, // 38 |
---|
| 279 | NAL_UNIT_PREFIX_SEI, // 39 |
---|
| 280 | NAL_UNIT_SUFFIX_SEI, // 40 |
---|
[1029] | 281 | |
---|
[313] | 282 | NAL_UNIT_RESERVED_NVCL41, |
---|
| 283 | NAL_UNIT_RESERVED_NVCL42, |
---|
| 284 | NAL_UNIT_RESERVED_NVCL43, |
---|
| 285 | NAL_UNIT_RESERVED_NVCL44, |
---|
| 286 | NAL_UNIT_RESERVED_NVCL45, |
---|
| 287 | NAL_UNIT_RESERVED_NVCL46, |
---|
| 288 | NAL_UNIT_RESERVED_NVCL47, |
---|
| 289 | NAL_UNIT_UNSPECIFIED_48, |
---|
| 290 | NAL_UNIT_UNSPECIFIED_49, |
---|
| 291 | NAL_UNIT_UNSPECIFIED_50, |
---|
| 292 | NAL_UNIT_UNSPECIFIED_51, |
---|
| 293 | NAL_UNIT_UNSPECIFIED_52, |
---|
| 294 | NAL_UNIT_UNSPECIFIED_53, |
---|
| 295 | NAL_UNIT_UNSPECIFIED_54, |
---|
| 296 | NAL_UNIT_UNSPECIFIED_55, |
---|
| 297 | NAL_UNIT_UNSPECIFIED_56, |
---|
| 298 | NAL_UNIT_UNSPECIFIED_57, |
---|
| 299 | NAL_UNIT_UNSPECIFIED_58, |
---|
| 300 | NAL_UNIT_UNSPECIFIED_59, |
---|
| 301 | NAL_UNIT_UNSPECIFIED_60, |
---|
| 302 | NAL_UNIT_UNSPECIFIED_61, |
---|
| 303 | NAL_UNIT_UNSPECIFIED_62, |
---|
| 304 | NAL_UNIT_UNSPECIFIED_63, |
---|
| 305 | NAL_UNIT_INVALID, |
---|
| 306 | }; |
---|
| 307 | |
---|
[540] | 308 | #if OUTPUT_LAYER_SET_INDEX |
---|
| 309 | class CommonDecoderParams |
---|
| 310 | { |
---|
| 311 | Int m_targetLayerId; |
---|
[588] | 312 | Int m_targetOutputLayerSetIdx; |
---|
[1029] | 313 | std::vector<Int> *m_targetDecLayerIdSet; |
---|
[540] | 314 | Bool m_valueCheckedFlag; |
---|
[644] | 315 | Int m_highestTId; |
---|
[540] | 316 | public: |
---|
[1029] | 317 | CommonDecoderParams(): |
---|
[1106] | 318 | #if CONFORMANCE_BITSTREAM_MODE |
---|
[1046] | 319 | m_targetLayerId(MAX_VPS_LAYER_IDX_PLUS1) |
---|
[952] | 320 | #else |
---|
[540] | 321 | m_targetLayerId(0) |
---|
[952] | 322 | #endif |
---|
[588] | 323 | , m_targetOutputLayerSetIdx(-1) |
---|
[540] | 324 | , m_targetDecLayerIdSet(NULL) |
---|
| 325 | , m_valueCheckedFlag(false) |
---|
[644] | 326 | , m_highestTId(6) |
---|
[540] | 327 | {} |
---|
| 328 | |
---|
| 329 | Void setTargetLayerId(const Int x) { m_targetLayerId = x; } |
---|
| 330 | Int getTargetLayerId() { return m_targetLayerId;} |
---|
| 331 | |
---|
[588] | 332 | Void setTargetOutputLayerSetIdx(const Int x) { m_targetOutputLayerSetIdx = x; } |
---|
| 333 | Int getTargetOutputLayerSetIdx() { return m_targetOutputLayerSetIdx;} |
---|
[540] | 334 | |
---|
| 335 | Void setTargetDecLayerIdSet(std::vector<Int> *x) { m_targetDecLayerIdSet = x; } |
---|
| 336 | std::vector<Int>* getTargetDecLayerIdSet() { return m_targetDecLayerIdSet;} |
---|
| 337 | |
---|
| 338 | Void setValueCheckedFlag(const Bool x) { m_valueCheckedFlag = x; } |
---|
| 339 | Bool getValueCheckedFlag() { return m_valueCheckedFlag;} |
---|
| 340 | |
---|
[644] | 341 | Void setHighestTId(const Int x) { m_highestTId = x; } |
---|
| 342 | Int getHighestTId() { return m_highestTId; } |
---|
[540] | 343 | }; |
---|
| 344 | #endif |
---|
[313] | 345 | //! \} |
---|
| 346 | |
---|
| 347 | #endif // end of #ifndef __COMMONDEF__ |
---|
| 348 | |
---|