[5] | 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-2011, 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 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 | */ |
---|
[2] | 33 | |
---|
| 34 | |
---|
[5] | 35 | |
---|
[2] | 36 | /** \file CommonDef.h |
---|
| 37 | \brief Defines constants, macros and tool parameters |
---|
| 38 | */ |
---|
| 39 | |
---|
| 40 | #ifndef __COMMONDEF__ |
---|
| 41 | #define __COMMONDEF__ |
---|
| 42 | |
---|
| 43 | // this pragma can be used for turning off "signed and unsigned mismatch" |
---|
| 44 | #if _MSC_VER > 1000 |
---|
| 45 | #pragma warning( disable : 4018 ) |
---|
| 46 | #endif // _MSC_VER > 1000 |
---|
| 47 | #include "TypeDef.h" |
---|
| 48 | #include "TComRom.h" |
---|
| 49 | |
---|
| 50 | #include <string> |
---|
| 51 | #include <assert.h> |
---|
| 52 | #include <stdlib.h> |
---|
| 53 | #include <vector> |
---|
| 54 | |
---|
| 55 | // ==================================================================================================================== |
---|
| 56 | // Version information |
---|
| 57 | // ==================================================================================================================== |
---|
| 58 | |
---|
| 59 | #define HM_VERSION "3.0rc2" ///< Current software version |
---|
[20] | 60 | #define NV_VERSION "0.2r1-HHI" ///< Current software version |
---|
[2] | 61 | |
---|
| 62 | // ==================================================================================================================== |
---|
| 63 | // Platform information |
---|
| 64 | // ==================================================================================================================== |
---|
| 65 | |
---|
| 66 | #ifdef __GNUC__ |
---|
| 67 | #define NVM_COMPILEDBY "[GCC %d.%d.%d]", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ |
---|
| 68 | #ifdef __IA64__ |
---|
| 69 | #define NVM_ONARCH "[on 64-bit] " |
---|
| 70 | #else |
---|
| 71 | #define NVM_ONARCH "[on 32-bit] " |
---|
| 72 | #endif |
---|
| 73 | #endif |
---|
| 74 | |
---|
| 75 | #ifdef __INTEL_COMPILER |
---|
| 76 | #define NVM_COMPILEDBY "[ICC %d]", __INTEL_COMPILER |
---|
| 77 | #elif _MSC_VER |
---|
| 78 | #define NVM_COMPILEDBY "[VS %d]", _MSC_VER |
---|
| 79 | #endif |
---|
| 80 | |
---|
| 81 | #ifndef NVM_COMPILEDBY |
---|
| 82 | #define NVM_COMPILEDBY "[Unk-CXX]" |
---|
| 83 | #endif |
---|
| 84 | |
---|
| 85 | #ifdef _WIN32 |
---|
| 86 | #define NVM_ONOS "[Windows]" |
---|
| 87 | #elif __linux |
---|
| 88 | #define NVM_ONOS "[Linux]" |
---|
| 89 | #elif __CYGWIN__ |
---|
| 90 | #define NVM_ONOS "[Cygwin]" |
---|
| 91 | #elif __APPLE__ |
---|
| 92 | #define NVM_ONOS "[Mac OS X]" |
---|
| 93 | #else |
---|
| 94 | #define NVM_ONOS "[Unk-OS]" |
---|
| 95 | #endif |
---|
| 96 | |
---|
| 97 | #define NVM_BITS "[%d bit] ", (sizeof(void*) == 8 ? 64 : 32) ///< used for checking 64-bit O/S |
---|
| 98 | |
---|
| 99 | #ifndef NULL |
---|
| 100 | #define NULL 0 |
---|
| 101 | #endif |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | // ==================================================================================================================== |
---|
| 105 | // Common constants |
---|
| 106 | // ==================================================================================================================== |
---|
| 107 | |
---|
| 108 | #define _SUMMARY_OUT_ 0 ///< print-out PSNR results of all slices to summary.txt |
---|
| 109 | #define _SUMMARY_PIC_ 0 ///< print-out PSNR results for each slice type to summary.txt |
---|
| 110 | |
---|
| 111 | #define MAX_REF_PIC_NUM 64 |
---|
| 112 | #define MAX_GOP 64 ///< max. value of hierarchical GOP size |
---|
| 113 | |
---|
| 114 | #define MAX_NUM_REF 4 ///< max. value of multiple reference frames |
---|
| 115 | #if DCM_COMB_LIST |
---|
| 116 | #define MAX_NUM_REF_LC 8 ///< max. value of combined reference frames |
---|
| 117 | #endif |
---|
| 118 | |
---|
| 119 | #define MAX_UINT 0xFFFFFFFFU ///< max. value of unsigned 32-bit integer |
---|
| 120 | #define MAX_UINT64 0xFFFFFFFFFFFFFFFFU |
---|
| 121 | #define MAX_INT 2147483647 ///< max. value of signed 32-bit integer |
---|
| 122 | #define MIN_INT (-2147483647-1) // < min. value of signed 32-bit integer |
---|
| 123 | #define MAX_DOUBLE 1.7e+308 ///< max. value of double-type value |
---|
| 124 | |
---|
| 125 | #define MIN_QP 0 |
---|
| 126 | #define MAX_QP 51 |
---|
| 127 | |
---|
| 128 | #define NOT_VALID -1 |
---|
| 129 | |
---|
| 130 | #define STD_CAM_PARAMETERS_PRECISION 5 ///< quarter luma sample accuarcy for derived disparities (as default) |
---|
| 131 | |
---|
| 132 | #define MAX_INPUT_VIEW_NUM 10 ///< max. number of input view for multiview coding |
---|
| 133 | |
---|
[5] | 134 | #if HHI_VSO |
---|
[2] | 135 | #define MAX_ERREF_VIEW_NUM 15 ///< max. number of virtual external reference views |
---|
[5] | 136 | #endif |
---|
[2] | 137 | #define LOG2_DISP_PREC_LUT 2 ///< log2 of disparity precision used in integer disparity LUTs |
---|
| 138 | |
---|
| 139 | |
---|
[5] | 140 | #if ( HHI_INTER_VIEW_MOTION_PRED || HHI_INTER_VIEW_RESIDUAL_PRED ) |
---|
| 141 | #define DEPTH_MAP_GENERATION 1 |
---|
| 142 | #else |
---|
| 143 | #define DEPTH_MAP_GENERATION 0 |
---|
| 144 | #endif |
---|
| 145 | |
---|
[2] | 146 | //>>>>> generation and usage of virtual prediction depth maps >>>>> |
---|
| 147 | #define PDM_ONE_DEPTH_PER_PU 1 // use only a single depth for a prediction unit (in update) |
---|
[20] | 148 | #define PDM_NO_INTER_UPDATE 1 // no update for inter (but not inter-view) predicted blocks |
---|
[2] | 149 | #define PDM_MERGE_POS 0 // position of pdm in merge list (0..5) |
---|
| 150 | #define PDM_AMVP_POS 2 // position of pdm in amvp list (0..3) |
---|
| 151 | #define PDM_OUTPUT_PRED_DEPTH_MAP 0 // output prediction depth map (for debugging) |
---|
| 152 | |
---|
| 153 | #define PDM_INTERNAL_CALC_BIT_DEPTH 31 // bit depth for internal calculations (32 - 1 for signed values) |
---|
| 154 | #define PDM_BITDEPTH_VIRT_DEPTH 15 // bit depth for virtual depth storage (16 - 1 for signed values) |
---|
| 155 | #define PDM_LOG2_MAX_ABS_NORMAL_DISPARITY 8 // maximum absolute normal disparity = 256 (for setting accuracy) |
---|
| 156 | #define PDM_VIRT_DEPTH_PRECISION 4 // must be greater than or equal to 2 (since MVs are given in quarter-pel units) |
---|
| 157 | |
---|
| 158 | #define PDM_INTER_CALC_SHIFT ( PDM_INTERNAL_CALC_BIT_DEPTH - PDM_BITDEPTH_VIRT_DEPTH ) // avoids overflow |
---|
| 159 | #define PDM_LOG4_SCALE_DENOMINATOR ( PDM_LOG2_MAX_ABS_NORMAL_DISPARITY + PDM_VIRT_DEPTH_PRECISION ) // accuracy of scaling factor |
---|
| 160 | #define PDM_OFFSET_SHIFT ( PDM_LOG2_MAX_ABS_NORMAL_DISPARITY ) // accuracy of offset |
---|
| 161 | |
---|
| 162 | #define PDM_MAX_ABS_VIRT_DEPTH ( ( 1 << PDM_BITDEPTH_VIRT_DEPTH ) - 1 ) |
---|
| 163 | #define PDM_UNDEFINED_DEPTH ( -( 1 << PDM_BITDEPTH_VIRT_DEPTH ) ) |
---|
| 164 | |
---|
| 165 | #define PDM_USE_FOR_IVIEW 1 |
---|
| 166 | #define PDM_USE_FOR_INTER 2 |
---|
| 167 | #define PDM_USE_FOR_MERGE 4 |
---|
[20] | 168 | |
---|
| 169 | #define PDM_SUBSAMPLING_EXP 2 // subsampling factor is 2^PDM_SUBSAMPLING_EXP |
---|
| 170 | #define PDM_SUB_SAMP_EXP_X(Pdm) ((Pdm)==1?PDM_SUBSAMPLING_EXP:0) |
---|
| 171 | #define PDM_SUB_SAMP_EXP_Y(Pdm) ((Pdm)==1?PDM_SUBSAMPLING_EXP:0) |
---|
[2] | 172 | //<<<<< generation and usage of virtual prediction depth maps <<<<< |
---|
| 173 | |
---|
| 174 | #define OUTPUT_RESIDUAL_PICTURES 0 // output residual pictures (for debugging) |
---|
| 175 | |
---|
[5] | 176 | #define HHI_MPI_MERGE_POS 0 // position of mvi in merge list (0..5) |
---|
[2] | 177 | |
---|
| 178 | |
---|
| 179 | // ==================================================================================================================== |
---|
| 180 | // Macro functions |
---|
| 181 | // ==================================================================================================================== |
---|
| 182 | |
---|
| 183 | #define Max(x, y) ((x)>(y)?(x):(y)) ///< max of (x, y) |
---|
| 184 | #define Min(x, y) ((x)<(y)?(x):(y)) ///< min of (x, y) |
---|
| 185 | #define Median(a,b,c) ((a)>(b)?(a)>(c)?(b)>(c)?(b):(c):(a):(b)>(c)?(a)>(c)?(a):(c):(b)) ///< 3-point median |
---|
| 186 | #define Clip(x) ( Min(g_uiIBDI_MAX, Max( 0, (x)) ) ) ///< clip with bit-depth range |
---|
| 187 | #define Clip3( MinVal, MaxVal, a) ( ((a)<(MinVal)) ? (MinVal) : (((a)>(MaxVal)) ? (MaxVal) :(a)) ) ///< general min/max clip |
---|
| 188 | #define RemoveBitIncrement(x) ( (x + ( (1 << g_uiBitIncrement) >> 1 )) >> g_uiBitIncrement ) ///< Remove Bit increment |
---|
| 189 | |
---|
| 190 | #define DATA_ALIGN 1 ///< use 32-bit aligned malloc/free |
---|
| 191 | #if DATA_ALIGN && _WIN32 && ( _MSC_VER > 1300 ) |
---|
| 192 | #define xMalloc( type, len ) _aligned_malloc( sizeof(type)*(len), 32 ) |
---|
| 193 | #define xFree( ptr ) _aligned_free ( ptr ) |
---|
| 194 | #else |
---|
| 195 | #define xMalloc( type, len ) malloc ( sizeof(type)*(len) ) |
---|
| 196 | #define xFree( ptr ) free ( ptr ) |
---|
| 197 | #endif |
---|
| 198 | |
---|
| 199 | #define FATAL_ERROR_0(MESSAGE, EXITCODE) \ |
---|
| 200 | { \ |
---|
| 201 | printf(MESSAGE); \ |
---|
| 202 | exit(EXITCODE); \ |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | |
---|
| 206 | // ==================================================================================================================== |
---|
| 207 | // Coding tool configuration |
---|
| 208 | // ==================================================================================================================== |
---|
| 209 | |
---|
| 210 | // modified LCEC coefficient coding |
---|
| 211 | #if QC_MOD_LCEC |
---|
| 212 | #define MAX_TR1 4 |
---|
| 213 | #endif |
---|
| 214 | |
---|
| 215 | // AMVP: advanced motion vector prediction |
---|
| 216 | #define AMVP_MAX_NUM_CANDS 6 ///< max number of final candidates |
---|
| 217 | // MERGE |
---|
| 218 | #define MRG_MAX_NUM_CANDS 6 |
---|
| 219 | |
---|
| 220 | // Reference memory management |
---|
| 221 | #define DYN_REF_FREE 0 ///< dynamic free of reference memories |
---|
| 222 | |
---|
| 223 | // defines for multiview coding |
---|
| 224 | #define MAX_NUMBER_VIEWS 10 |
---|
| 225 | |
---|
| 226 | // Explicit temporal layer QP offset |
---|
| 227 | #define MAX_TLAYER 10 ///< max number of temporal layer |
---|
| 228 | #define HB_LAMBDA_FOR_LDC 1 ///< use of B-style lambda for non-key pictures in low-delay mode |
---|
| 229 | |
---|
| 230 | // Fast estimation of generalized B in low-delay mode |
---|
| 231 | #define GPB_SIMPLE 1 ///< Simple GPB mode |
---|
| 232 | #if GPB_SIMPLE |
---|
| 233 | #define GPB_SIMPLE_UNI 1 ///< Simple mode for uni-direction |
---|
| 234 | #endif |
---|
| 235 | |
---|
| 236 | // Fast ME using smoother MV assumption |
---|
| 237 | #define FASTME_SMOOTHER_MV 1 ///< reduce ME time using faster option |
---|
| 238 | |
---|
| 239 | // Adaptive search range depending on POC difference |
---|
| 240 | #define ADAPT_SR_SCALE 1 ///< division factor for adaptive search range |
---|
| 241 | |
---|
| 242 | #define ENABLE_IBDI 0 |
---|
| 243 | |
---|
| 244 | #define CLIP_TO_709_RANGE 0 |
---|
| 245 | |
---|
| 246 | // IBDI range restriction for skipping clip |
---|
| 247 | #define IBDI_NOCLIP_RANGE 0 ///< restrict max. value after IBDI to skip clip |
---|
| 248 | |
---|
| 249 | // Early-skip threshold (encoder) |
---|
| 250 | #define EARLY_SKIP_THRES 1.50 ///< if RD < thres*avg[BestSkipRD] |
---|
| 251 | |
---|
| 252 | const int g_iShift8x8 = 2; |
---|
| 253 | const int g_iShift16x16 = 2; |
---|
| 254 | const int g_iShift32x32 = 2; |
---|
| 255 | const int g_iShift64x64 = 2; |
---|
| 256 | |
---|
| 257 | |
---|
| 258 | |
---|
| 259 | //RENDERER |
---|
| 260 | #define REN_LUMA_MARGIN ( g_uiMaxCUWidth + 12 ) |
---|
| 261 | #define REN_VDWEIGHT_PREC 8 |
---|
| 262 | #define REN_IS_FILLED ( 1 << REN_VDWEIGHT_PREC ) |
---|
| 263 | #define REN_USED_PEL g_uiIBDI_MAX |
---|
| 264 | #define REN_UNUSED_PEL 0 |
---|
| 265 | #define REN_IS_HOLE 0 |
---|
| 266 | |
---|
| 267 | /* End of Rounding control */ |
---|
| 268 | |
---|
| 269 | enum NalRefIdc |
---|
| 270 | { |
---|
| 271 | NAL_REF_IDC_PRIORITY_LOWEST = 0, |
---|
| 272 | NAL_REF_IDC_PRIORITY_LOW, |
---|
| 273 | NAL_REF_IDC_PRIORITY_HIGH, |
---|
| 274 | NAL_REF_IDC_PRIORITY_HIGHEST |
---|
| 275 | }; |
---|
| 276 | |
---|
| 277 | enum NalUnitType |
---|
| 278 | { |
---|
| 279 | NAL_UNIT_UNSPECIFIED_0 = 0, |
---|
| 280 | NAL_UNIT_CODED_SLICE, |
---|
| 281 | NAL_UNIT_CODED_SLICE_DATAPART_A, |
---|
| 282 | NAL_UNIT_CODED_SLICE_DATAPART_B, |
---|
| 283 | #if DCM_DECODING_REFRESH |
---|
| 284 | NAL_UNIT_CODED_SLICE_CDR, |
---|
| 285 | #else |
---|
| 286 | NAL_UNIT_CODED_SLICE_DATAPART_C, |
---|
| 287 | #endif |
---|
| 288 | NAL_UNIT_CODED_SLICE_IDR, |
---|
| 289 | NAL_UNIT_SEI, |
---|
| 290 | NAL_UNIT_SPS, |
---|
| 291 | NAL_UNIT_PPS, |
---|
| 292 | NAL_UNIT_ACCESS_UNIT_DELIMITER, |
---|
| 293 | NAL_UNIT_END_OF_SEQUENCE, |
---|
| 294 | NAL_UNIT_END_OF_STREAM, |
---|
| 295 | NAL_UNIT_FILLER_DATA, |
---|
| 296 | NAL_UNIT_RESERVED_13, |
---|
| 297 | NAL_UNIT_RESERVED_14, |
---|
| 298 | NAL_UNIT_RESERVED_15, |
---|
| 299 | NAL_UNIT_RESERVED_16, |
---|
| 300 | NAL_UNIT_RESERVED_17, |
---|
| 301 | NAL_UNIT_RESERVED_18, |
---|
| 302 | NAL_UNIT_RESERVED_19, |
---|
| 303 | NAL_UNIT_RESERVED_20, |
---|
| 304 | NAL_UNIT_RESERVED_21, |
---|
| 305 | NAL_UNIT_RESERVED_22, |
---|
| 306 | NAL_UNIT_RESERVED_23, |
---|
| 307 | NAL_UNIT_UNSPECIFIED_24, |
---|
| 308 | NAL_UNIT_UNSPECIFIED_25, |
---|
| 309 | NAL_UNIT_UNSPECIFIED_26, |
---|
| 310 | NAL_UNIT_UNSPECIFIED_27, |
---|
| 311 | NAL_UNIT_UNSPECIFIED_28, |
---|
| 312 | NAL_UNIT_UNSPECIFIED_29, |
---|
| 313 | NAL_UNIT_UNSPECIFIED_30, |
---|
| 314 | NAL_UNIT_UNSPECIFIED_31, |
---|
| 315 | NAL_UNIT_INVALID, |
---|
| 316 | }; |
---|
| 317 | |
---|
| 318 | typedef _AlfParam ALFParam; |
---|
| 319 | #if MTK_SAO |
---|
| 320 | typedef _SaoParam SAOParam; |
---|
| 321 | #endif |
---|
| 322 | |
---|
| 323 | |
---|
| 324 | class VideoCodecException |
---|
| 325 | { |
---|
| 326 | public: |
---|
| 327 | VideoCodecException() : m_acFile( "unspecified" ), m_uiLine( 0 ) {} |
---|
| 328 | VideoCodecException( const char *pcFile, UInt uiLine ) : m_acFile( pcFile ), m_uiLine( uiLine ) {} |
---|
| 329 | |
---|
| 330 | std::string exceptionFile() const { return m_acFile; } |
---|
| 331 | UInt exceptionLine() const { return m_uiLine; } |
---|
| 332 | |
---|
| 333 | private: |
---|
| 334 | std::string m_acFile; |
---|
| 335 | UInt m_uiLine; |
---|
| 336 | }; |
---|
| 337 | |
---|
| 338 | #define RETURN_ERR_ON_EXCEPTION \ |
---|
| 339 | catch( std::exception &cEx ) \ |
---|
| 340 | { \ |
---|
| 341 | std::cerr << "Abnormal program termination: " << cEx.what() << std::endl; \ |
---|
| 342 | return Err::m_nERR; \ |
---|
| 343 | } \ |
---|
| 344 | catch( VideoCodecException &cEx ) \ |
---|
| 345 | { \ |
---|
| 346 | std::cerr << std::endl << "VideoCodecExcteption caught at: " << std::endl; \ |
---|
| 347 | std::cerr << "File: " << cEx.exceptionFile() << std::endl; \ |
---|
| 348 | std::cerr << "Line: " << cEx.exceptionLine() << std::endl; \ |
---|
| 349 | return Err::m_nERR; \ |
---|
| 350 | } \ |
---|
| 351 | catch( ... ) \ |
---|
| 352 | { \ |
---|
| 353 | std::cerr << "Caught unknown exception" << std::endl; \ |
---|
| 354 | return Err::m_nERR; \ |
---|
| 355 | } |
---|
| 356 | |
---|
| 357 | |
---|
| 358 | #define TOT( exp ) { if( exp ) { throw VideoCodecException( __FILE__, __LINE__ ); } } |
---|
| 359 | #define TOF( exp ) { if( !(exp) ) { throw VideoCodecException( __FILE__, __LINE__ ); } } |
---|
| 360 | #define TNOK( exp ) { if( Err::m_nOK != (exp) ) { throw VideoCodecException( __FILE__, __LINE__ ); } } |
---|
| 361 | |
---|
| 362 | #if defined( _DEBUG ) |
---|
| 363 | |
---|
| 364 | #define TOT_DBG( exp ) TOT( exp ) |
---|
| 365 | #define TOF_DBG( exp ) TOF( exp ) |
---|
| 366 | |
---|
| 367 | #else |
---|
| 368 | |
---|
| 369 | #define TOT_DBG( exp ) ((void)0) |
---|
| 370 | #define TOF_DBG( exp ) ((void)0) |
---|
| 371 | |
---|
| 372 | #endif |
---|
| 373 | |
---|
| 374 | typedef int ErrVal; |
---|
| 375 | |
---|
| 376 | |
---|
| 377 | class Err |
---|
| 378 | { |
---|
| 379 | public: |
---|
| 380 | enum |
---|
| 381 | { |
---|
| 382 | m_nOK = 0, |
---|
| 383 | m_nERR = -1, |
---|
| 384 | m_nEndOfFile = -2, |
---|
| 385 | m_nEndOfBuffer = -3, |
---|
| 386 | m_nInvalidParameter = -4, |
---|
| 387 | m_nDataNotAvailable = -5, |
---|
| 388 | m_nSizeNotAvailable = -5, |
---|
| 389 | }; |
---|
| 390 | }; |
---|
| 391 | |
---|
| 392 | |
---|
| 393 | #define ROF( exp ) \ |
---|
| 394 | { \ |
---|
| 395 | if( !( exp ) ) \ |
---|
| 396 | { \ |
---|
| 397 | assert( 0 ); \ |
---|
| 398 | return -1; \ |
---|
| 399 | } \ |
---|
| 400 | } |
---|
| 401 | |
---|
| 402 | #define ROT( exp ) \ |
---|
| 403 | { \ |
---|
| 404 | if( ( exp ) ) \ |
---|
| 405 | { \ |
---|
| 406 | assert( 0 ); \ |
---|
| 407 | return -1; \ |
---|
| 408 | } \ |
---|
| 409 | } |
---|
| 410 | |
---|
| 411 | #define ROFS( exp ) \ |
---|
| 412 | { \ |
---|
| 413 | if( !( exp ) ) \ |
---|
| 414 | { \ |
---|
| 415 | return -1; \ |
---|
| 416 | } \ |
---|
| 417 | } |
---|
| 418 | |
---|
| 419 | #define ROTS( exp ) \ |
---|
| 420 | { \ |
---|
| 421 | if( ( exp ) ) \ |
---|
| 422 | { \ |
---|
| 423 | return -1; \ |
---|
| 424 | } \ |
---|
| 425 | } |
---|
| 426 | |
---|
| 427 | #define ROFR( exp, retVal ) \ |
---|
| 428 | { \ |
---|
| 429 | if( !( exp ) ) \ |
---|
| 430 | { \ |
---|
| 431 | assert( 0 ); \ |
---|
| 432 | return retVal; \ |
---|
| 433 | } \ |
---|
| 434 | } |
---|
| 435 | |
---|
| 436 | #define ROTR( exp, retVal ) \ |
---|
| 437 | { \ |
---|
| 438 | if( ( exp ) ) \ |
---|
| 439 | { \ |
---|
| 440 | assert( 0 ); \ |
---|
| 441 | return retVal; \ |
---|
| 442 | } \ |
---|
| 443 | } |
---|
| 444 | |
---|
| 445 | #define ROFRS( exp, retVal ) \ |
---|
| 446 | { \ |
---|
| 447 | if( !( exp ) ) \ |
---|
| 448 | { \ |
---|
| 449 | return retVal; \ |
---|
| 450 | } \ |
---|
| 451 | } |
---|
| 452 | |
---|
| 453 | #define ROTRS( exp, retVal ) \ |
---|
| 454 | { \ |
---|
| 455 | if( ( exp ) ) \ |
---|
| 456 | { \ |
---|
| 457 | return retVal; \ |
---|
| 458 | } \ |
---|
| 459 | } |
---|
| 460 | |
---|
| 461 | #define ROFV( exp ) \ |
---|
| 462 | { \ |
---|
| 463 | if( !( exp ) ) \ |
---|
| 464 | { \ |
---|
| 465 | assert( 0 ); \ |
---|
| 466 | return; \ |
---|
| 467 | } \ |
---|
| 468 | } |
---|
| 469 | |
---|
| 470 | #define ROTV( exp ) \ |
---|
| 471 | { \ |
---|
| 472 | if( ( exp ) ) \ |
---|
| 473 | { \ |
---|
| 474 | assert( 0 ); \ |
---|
| 475 | return; \ |
---|
| 476 | } \ |
---|
| 477 | } |
---|
| 478 | |
---|
| 479 | #define ROFVS( exp ) \ |
---|
| 480 | { \ |
---|
| 481 | if( !( exp ) ) \ |
---|
| 482 | { \ |
---|
| 483 | return; \ |
---|
| 484 | } \ |
---|
| 485 | } |
---|
| 486 | |
---|
| 487 | #define ROTVS( exp ) \ |
---|
| 488 | { \ |
---|
| 489 | if( ( exp ) ) \ |
---|
| 490 | { \ |
---|
| 491 | return; \ |
---|
| 492 | } \ |
---|
| 493 | } |
---|
| 494 | |
---|
| 495 | #define RNOK( exp ) \ |
---|
| 496 | { \ |
---|
| 497 | const ErrVal nMSysRetVal = ( exp ); \ |
---|
| 498 | if( 0 != nMSysRetVal ) \ |
---|
| 499 | { \ |
---|
| 500 | assert( 0 ); \ |
---|
| 501 | return nMSysRetVal; \ |
---|
| 502 | } \ |
---|
| 503 | } |
---|
| 504 | |
---|
| 505 | #define RNOKR( exp, retVal ) \ |
---|
| 506 | { \ |
---|
| 507 | if( 0 != ( exp ) ) \ |
---|
| 508 | { \ |
---|
| 509 | assert( 0 ); \ |
---|
| 510 | return retVal; \ |
---|
| 511 | } \ |
---|
| 512 | } |
---|
| 513 | |
---|
| 514 | #define RNOKS( exp ) \ |
---|
| 515 | { \ |
---|
| 516 | const ErrVal nMSysRetVal = ( exp ); \ |
---|
| 517 | if( 0 != nMSysRetVal ) \ |
---|
| 518 | { \ |
---|
| 519 | return nMSysRetVal; \ |
---|
| 520 | } \ |
---|
| 521 | } |
---|
| 522 | |
---|
| 523 | #define RNOKRS( exp, retVal ) \ |
---|
| 524 | { \ |
---|
| 525 | if( 0 != ( exp ) ) \ |
---|
| 526 | { \ |
---|
| 527 | return retVal; \ |
---|
| 528 | } \ |
---|
| 529 | } |
---|
| 530 | |
---|
| 531 | #define RNOKV( exp ) \ |
---|
| 532 | { \ |
---|
| 533 | if( 0 != ( exp ) ) \ |
---|
| 534 | { \ |
---|
| 535 | assert( 0 ); \ |
---|
| 536 | return; \ |
---|
| 537 | } \ |
---|
| 538 | } |
---|
| 539 | |
---|
| 540 | #define RNOKVS( exp ) \ |
---|
| 541 | { \ |
---|
| 542 | if( 0 != ( exp ) ) \ |
---|
| 543 | { \ |
---|
| 544 | return; \ |
---|
| 545 | } \ |
---|
| 546 | } |
---|
| 547 | |
---|
| 548 | #define ANOK( exp ) \ |
---|
| 549 | { \ |
---|
| 550 | if( 0 != ( exp ) ) \ |
---|
| 551 | { \ |
---|
| 552 | assert( 0 ); \ |
---|
| 553 | } \ |
---|
| 554 | } |
---|
| 555 | |
---|
| 556 | #define AOF( exp ) \ |
---|
| 557 | { \ |
---|
| 558 | if( !( exp ) ) \ |
---|
| 559 | { \ |
---|
| 560 | assert( 0 ); \ |
---|
| 561 | } \ |
---|
| 562 | } |
---|
| 563 | |
---|
| 564 | #define AOT( exp ) \ |
---|
| 565 | { \ |
---|
| 566 | if( ( exp ) ) \ |
---|
| 567 | { \ |
---|
| 568 | assert( 0 ); \ |
---|
| 569 | } \ |
---|
| 570 | } |
---|
| 571 | |
---|
| 572 | #if defined( _DEBUG ) |
---|
| 573 | |
---|
| 574 | #define AOT_DBG( exp ) AOT( exp ) |
---|
| 575 | #define AOF_DBG( exp ) AOF( exp ) |
---|
| 576 | |
---|
| 577 | #else |
---|
| 578 | |
---|
| 579 | #define AOT_DBG( exp ) ((void)0) |
---|
| 580 | #define AOF_DBG( exp ) ((void)0) |
---|
| 581 | |
---|
| 582 | #endif |
---|
| 583 | |
---|
| 584 | #define DISABLE_DEFAULT_CPYCTOR_AND_ASOP(x) private: x( const x &r ); const x& operator=( const x &r ) |
---|
| 585 | typedef Int64 PicOrderCnt; |
---|
| 586 | |
---|
| 587 | template<class T> |
---|
| 588 | class AutoDeletePtrVector |
---|
| 589 | : public std::vector<T*> |
---|
| 590 | { |
---|
| 591 | public: |
---|
| 592 | AutoDeletePtrVector() {} |
---|
| 593 | |
---|
| 594 | virtual ~AutoDeletePtrVector() |
---|
| 595 | { |
---|
| 596 | while( !std::vector<T*>::empty() ) |
---|
| 597 | { |
---|
| 598 | delete std::vector<T*>::back(); |
---|
| 599 | std::vector<T*>::pop_back(); |
---|
| 600 | } |
---|
| 601 | } |
---|
| 602 | |
---|
| 603 | DISABLE_DEFAULT_CPYCTOR_AND_ASOP( AutoDeletePtrVector ); |
---|
| 604 | }; |
---|
| 605 | |
---|
| 606 | template<class T> |
---|
| 607 | __inline T gAbs(const T& x) |
---|
| 608 | { |
---|
| 609 | return x < 0 ? -x : x; |
---|
| 610 | } |
---|
| 611 | // |
---|
| 612 | |
---|
| 613 | template <typename T> |
---|
| 614 | __inline T gSign(const T& t) |
---|
| 615 | { |
---|
| 616 | if( t == 0 ) |
---|
| 617 | return T(0); |
---|
| 618 | else |
---|
| 619 | return (t < 0) ? T(-1) : T(1); |
---|
| 620 | } |
---|
| 621 | |
---|
| 622 | |
---|
| 623 | |
---|
| 624 | #endif // end of #ifndef __COMMONDEF__ |
---|
| 625 | |
---|