Skip to content
Snippets Groups Projects
EncAppCfg.h 59.7 KiB
Newer Older
/* 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-2024, 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.
 */

/** \file     EncAppCfg.h
    \brief    Handle encoder configuration parameters (header)
*/

#ifndef __ENCAPPCFG__
#define __ENCAPPCFG__

#include "CommonLib/CommonDef.h"
#include "EncoderLib/EncCfgParam.h"

#include <map>
template <class T1, class T2>
static inline std::istream& operator >> (std::istream &in, std::map<T1, T2> &map);

#include "Utilities/program_options_lite.h"
#include "EncoderLib/EncCfg.h"
#if EXTENSION_360_VIDEO
#include "AppEncHelper360/TExt360AppEncCfg.h"
#endif

#if JVET_O0756_CALCULATE_HDRMETRICS
#include "HDRLib/inc/DistortionMetric.H"
#ifdef UNDEFINED
#undef UNDEFINED
#endif
namespace po = ProgramOptionsLite;
//! \ingroup EncoderApp
//! \{

// ====================================================================================================================
// Class definition
// ====================================================================================================================

/// encoder configuration class
class EncAppCfg
{
protected:
  // file I/O
  std::string m_inputFileName;                                ///< source file name
  std::string m_bitstreamFileName;                            ///< output bitstream file
  std::string m_reconFileName;                                ///< output reconstruction file

  // Lambda modifiers
  double    m_adLambdaModifier[ MAX_TLAYER ];                 ///< Lambda modifier array for each temporal layer
  std::vector<double> m_adIntraLambdaModifier;                ///< Lambda modifier for Intra pictures, one for each temporal layer. If size>temporalLayer, then use [temporalLayer], else if size>0, use [size()-1], else use m_adLambdaModifier.
  double    m_dIntraQpFactor;                                 ///< Intra Q Factor. If negative, use a default equation: 0.57*(1.0 - Clip3( 0.0, 0.5, 0.05*(double)(isField ? (GopSize-1)/2 : GopSize-1) ))

  // source specification
Frank Bossen's avatar
Frank Bossen committed
  uint32_t      m_frameSkip;                                      ///< number of skipped frames from the beginning
  uint32_t      m_temporalSubsampleRatio;                         ///< temporal subsample ratio, 2 means code every two frames
  int       m_sourceWidth;                                   ///< source width in pixel
  int       m_sourceHeight;                                  ///< source height in pixel (when interlaced = field height)
  double    m_sourceScalingRatioHor;                          ////< source scaling ratio Horizontal
  double    m_sourceScalingRatioVer;                          ////< source scaling ratio Vertical
  int       m_sourceWidthBeforeScale;                         ///< source width in pixel before applying source scaling ratio Horizontal 
  int       m_sourceHeightBeforeScale;                        ///< source height in pixel before applying source scaling ratio Vertical (when interlaced = field height)
#if EXTENSION_360_VIDEO
  int       m_inputFileWidth;                                 ///< width of image in input file  (this is equivalent to sourceWidth,  if sourceWidth  is not subsequently altered due to padding)
  int       m_inputFileHeight;                                ///< height of image in input file (this is equivalent to sourceHeight, if sourceHeight is not subsequently altered due to padding)
#endif
  int       m_iSourceHeightOrg;                               ///< original source height in pixel (when interlaced = frame height)

  bool      m_isField;                                        ///< enable field coding
  bool      m_isTopFieldFirst;
  bool      m_efficientFieldIRAPEnabled;   ///< enable an efficient field IRAP structure.
  bool      m_harmonizeGopFirstFieldCoupleEnabled;

  int       m_conformanceWindowMode;
  int       m_confWinLeft;
  int       m_confWinRight;
  int       m_confWinTop;
  int       m_confWinBottom;
  bool      m_explicitScalingWindowEnabled;
  int       m_scalWinLeft;
  int       m_scalWinRight;
  int       m_scalWinTop;
  int       m_scalWinBottom;
  int       m_sourcePadding[2];                                       ///< number of padded pixels for width and height
  int       m_firstValidFrame;
  int       m_lastValidFrame;
  int       m_framesToBeEncoded;                              ///< number of encoded frames
  bool      m_AccessUnitDelimiter;                            ///< add Access Unit Delimiter NAL units
  bool      m_enablePictureHeaderInSliceHeader;               ///< Enable Picture Header in Slice Header
  InputColourSpaceConversion m_inputColourSpaceConvert;       ///< colour space conversion to apply to input video
  bool      m_snrInternalColourSpace;                       ///< if true, then no colour space conversion is applied for snr calculation, otherwise inverse of input is applied.
  bool      m_outputInternalColourSpace;                    ///< if true, then no colour space conversion is applied for reconstructed video, otherwise inverse of input is applied.
Frank Bossen's avatar
Frank Bossen committed
  ChromaFormat               m_inputChromaFormatIDC;

  bool      m_printMSEBasedSequencePSNR;
  bool      m_printHexPsnr;
  bool      m_printFrameMSE;
  bool      m_printSequenceMSE;
Xiang Li's avatar
Xiang Li committed
  bool      m_printMSSSIM;
  bool      m_printWPSNR;
  bool      m_printHighPrecEncTime = false;
Frank Bossen's avatar
Frank Bossen committed
  bool      m_clipInputVideoToRec709Range;
  bool      m_clipOutputVideoToRec709Range;
  bool      m_packedYUVMode;                                  ///< If true, output 10-bit and 12-bit YUV data as 5-byte and 3-byte (respectively) packed YUV data
  bool      m_gciPresentFlag;
Zhipin Deng's avatar
Zhipin Deng committed
  bool      m_bIntraOnlyConstraintFlag;
  uint32_t  m_maxBitDepthConstraintIdc;
  ChromaFormat m_maxChromaFormatConstraintIdc;
  bool      m_allLayersIndependentConstraintFlag;
  bool      m_noMrlConstraintFlag;
  bool      m_noIspConstraintFlag;
  bool      m_noMipConstraintFlag;
  bool      m_noLfnstConstraintFlag;
  bool      m_noMmvdConstraintFlag;
  bool      m_noSmvdConstraintFlag;
  bool      m_noProfConstraintFlag;
  bool      m_noPaletteConstraintFlag;
  bool      m_noActConstraintFlag;
  bool      m_noLmcsConstraintFlag;
  bool      m_noExplicitScaleListConstraintFlag;
  bool      m_noVirtualBoundaryConstraintFlag;
  bool      m_noMttConstraintFlag;
  bool      m_noChromaQpOffsetConstraintFlag;
  bool      m_noQtbttDualTreeIntraConstraintFlag;
  int       m_maxLog2CtuSizeConstraintIdc;
  bool      m_noPartitionConstraintsOverrideConstraintFlag;
  bool      m_noSaoConstraintFlag;
  bool      m_noAlfConstraintFlag;
  bool      m_noCCAlfConstraintFlag;
  bool      m_noWeightedPredictionConstraintFlag;
  bool      m_noRefWraparoundConstraintFlag;
  bool      m_noTemporalMvpConstraintFlag;
  bool      m_noSbtmvpConstraintFlag;
  bool      m_noAmvrConstraintFlag;
  bool      m_noBdofConstraintFlag;
  bool      m_noDmvrConstraintFlag;
  bool      m_noCclmConstraintFlag;
  bool      m_noMtsConstraintFlag;
  bool      m_noSbtConstraintFlag;
  bool      m_noAffineMotionConstraintFlag;
  bool      m_noBcwConstraintFlag;
  bool      m_noIbcConstraintFlag;
  bool      m_noCiipConstraintFlag;
Han Gao's avatar
Han Gao committed
  bool      m_noGeoConstraintFlag;
  bool      m_noLadfConstraintFlag;
  bool      m_noTransformSkipConstraintFlag;
  bool      m_noLumaTransformSize64ConstraintFlag;
  bool      m_noJointCbCrConstraintFlag;
  bool      m_noDepQuantConstraintFlag;
  bool      m_noSignDataHidingConstraintFlag;
  bool      m_noTrailConstraintFlag;
  bool      m_noStsaConstraintFlag;
  bool      m_noRaslConstraintFlag;
  bool      m_noRadlConstraintFlag;
  bool      m_noIdrConstraintFlag;
  bool      m_noCraConstraintFlag;
  bool      m_noGdrConstraintFlag;
  bool      m_noApsConstraintFlag;
Tomohiro Ikai's avatar
Tomohiro Ikai committed
  bool      m_noExtendedPrecisionProcessingConstraintFlag;
Tomohiro Ikai's avatar
Tomohiro Ikai committed
  bool      m_noTsResidualCodingRiceConstraintFlag;
  bool      m_noRrcRiceExtensionConstraintFlag;
  bool      m_noPersistentRiceAdaptationConstraintFlag;
  bool      m_noReverseLastSigCoeffConstraintFlag;
Zhipin Deng's avatar
Zhipin Deng committed

  // profile/level
  Profile::Name m_profile;
  Level::Tier   m_levelTier;
  Level::Name   m_level;
  bool          m_frameOnlyConstraintFlag;
  bool          m_multiLayerEnabledFlag;
  std::vector<uint32_t>  m_subProfile;
  uint8_t      m_numSubProfile;
  uint32_t          m_bitDepthConstraint;
  ChromaFormat  m_chromaFormatConstraint;
  bool          m_onePictureOnlyConstraintFlag;
  bool          m_intraOnlyConstraintFlag;
  bool          m_nonProjectedConstraintFlag;
  bool          m_noResChangeInClvsConstraintFlag;
  bool          m_oneTilePerPicConstraintFlag;
bdchoi's avatar
bdchoi committed
  bool          m_picHeaderInSliceHeaderConstraintFlag;
  bool          m_oneSlicePerPicConstraintFlag;
  bool          m_noIdrRplConstraintFlag;
  bool          m_noRectSliceConstraintFlag;
  bool          m_oneSlicePerSubpicConstraintFlag;
  bool          m_noSubpicInfoConstraintFlag;
Frank Bossen's avatar
Frank Bossen committed
  int m_intraPeriod;   ///< period of I-slice (random access period)
  int       m_gdrPocStart;
  int       m_gdrPeriod;
  int       m_gdrInterval;
  bool      m_gdrNoHash;
Seungwook Hong's avatar
Seungwook Hong committed
#endif
Frank Bossen's avatar
Frank Bossen committed
  int       m_intraRefreshType;                               ///< random access type
  int       m_gopSize;                                        ///< GOP size of hierarchical structure
  int       m_drapPeriod;                                     ///< period of dependent RAP pictures
Yang Wang's avatar
Yang Wang committed
  int       m_edrapPeriod;                                    ///< period of extended dependent RAP pictures
  bool      m_rewriteParamSets;                              ///< Flag to enable rewriting of parameter sets at random access points
Hendry's avatar
Hendry committed
  RPLEntry  m_RPLList0[MAX_GOP];                               ///< the RPL entries from the config file
  RPLEntry  m_RPLList1[MAX_GOP];                               ///< the RPL entries from the config file
  bool      m_idrRefParamList;                                ///< indicates if reference picture list syntax elements are present in slice headers of IDR pictures
  GOPEntry  m_GOPList[MAX_GOP];                               ///< the coding structure entries from the config file
  int       m_maxNumReorderPics[MAX_TLAYER];                  ///< total number of reorder pictures
  int       m_maxDecPicBuffering[MAX_TLAYER];                 ///< total number of pictures in the decoded picture buffer
  bool      m_reconBasedCrossCPredictionEstimate;             ///< causes the alpha calculation in encoder search to be based on the decoded residual rather than the pre-transform encoder-side residual
  bool      m_useTransformSkip;                               ///< flag for enabling intra transform skipping
  bool      m_useTransformSkipFast;                           ///< flag for enabling fast intra transform skipping
  uint32_t      m_log2MaxTransformSkipBlockSize;                  ///< transform-skip maximum size (minimum of 2)
  bool      m_transformSkipRotationEnabledFlag;               ///< control flag for transform-skip/transquant-bypass residual rotation
  bool      m_transformSkipContextEnabledFlag;                ///< control flag for transform-skip/transquant-bypass single significance map context
  bool      m_rrcRiceExtensionEnableFlag;                        ///< control flag for enabling extension of the Golomb-Rice parameter derivation for RRC
  bool      m_persistentRiceAdaptationEnabledFlag;            ///< control flag for Golomb-Rice parameter adaptation over each slice
  bool      m_cabacBypassAlignmentEnabledFlag;
  bool      m_useFastISP;                                    ///< flag for enabling fast methods for ISP
  int       m_fastAdaptCostPredMode;                         ///< mode for cost prediction, 0..2
  bool      m_disableFastDecisionTT;                         ///< flag for disabling fast decision for TT from BT
  std::optional<uint32_t> m_qpIncrementAtSourceFrame;   // Optional source frame number at which all subsequent frames
                                                        // are to use an increased internal QP.
  int       m_iQP;                                            ///< QP value of key-picture (integer)
  ChromaQpMappingTableParams m_chromaQpMappingTableParams;
  int       m_intraQPOffset;                                  ///< QP offset for intra slice (integer)
  bool      m_lambdaFromQPEnable;                             ///< enable flag for QP:lambda fix
  std::string m_dQPFileName;                                  ///< QP offset for each slice (initialized from external file)

  FrameDeltaQps m_frameDeltaQps;   // array of frame delta QP values

  uint32_t  m_uiDeltaQpRD;                                    ///< dQP range for multi-pass slice QP optimization
  int       m_cuQpDeltaSubdiv;                                ///< Maximum subdiv for CU luma Qp adjustment (0:default)
  int       m_cuChromaQpOffsetSubdiv;                         ///< If negative, then do not apply chroma qp offsets.
  std::vector<ChromaQpAdj> m_cuChromaQpOffsetList;            ///< Local chroma QP offsets list (to be signalled in PPS)
  bool      m_cuChromaQpOffsetEnabled;                        ///< Enable local chroma QP offsets (slice level flag)
  bool      m_bFastDeltaQP;                                   ///< Fast Delta QP (false:default)

  int       m_cbQpOffset;                                     ///< Chroma Cb QP Offset (0:default)
  int       m_crQpOffset;                                     ///< Chroma Cr QP Offset (0:default)
  int       m_cbQpOffsetDualTree;                             ///< Chroma Cb QP Offset for dual tree (overwrite m_cbQpOffset for dual tree)
  int       m_crQpOffsetDualTree;                             ///< Chroma Cr QP Offset for dual tree (overwrite m_crQpOffset for dual tree)
  int       m_cbCrQpOffset;                                   ///< QP Offset for joint Cb-Cr mode
  int       m_cbCrQpOffsetDualTree;                           ///< QP Offset for joint Cb-Cr mode (overwrite m_cbCrQpOffset for dual tree)
#if ER_CHROMA_QP_WCG_PPS
  WCGChromaQPControl m_wcgChromaQpControl;                    ///< Wide-colour-gamut chroma QP control.
#endif
#if W0038_CQP_ADJ
  uint32_t      m_sliceChromaQpOffsetPeriodicity;                 ///< Used in conjunction with Slice Cb/Cr QpOffsetIntraOrPeriodic. Use 0 (default) to disable periodic nature.
  int       m_sliceChromaQpOffsetIntraOrPeriodic[2/*Cb,Cr*/]; ///< Chroma Cb QP Offset at slice level for I slice or for periodic inter slices as defined by SliceChromaQPOffsetPeriodicity. Replaces offset in the GOP table.
#endif
#if SHARP_LUMA_DELTA_QP
  LumaLevelToDeltaQPMapping m_lumaLevelToDeltaQPMapping;      ///< mapping from luma level to Delta QP.
#endif
  SEIMasteringDisplay m_masteringDisplay;
  bool      m_smoothQPReductionEnable;
  double    m_smoothQPReductionThresholdIntra;
  double    m_smoothQPReductionModelScaleIntra;
  double    m_smoothQPReductionModelOffsetIntra;
  int       m_smoothQPReductionLimitIntra;
  double    m_smoothQPReductionThresholdInter;
  double    m_smoothQPReductionModelScaleInter;
  double    m_smoothQPReductionModelOffsetInter;
  int       m_smoothQPReductionLimitInter;
  int       m_smoothQPReductionPeriodicity;
  bool      m_bUseAdaptiveQP;                                 ///< Flag for enabling QP adaptation based on a psycho-visual model
  int       m_iQPAdaptationRange;                             ///< dQP range by QP adaptation
#if ENABLE_QPA
  bool      m_bUsePerceptQPA;                                 ///< Flag to enable perceptually motivated input-adaptive QP modification
  bool      m_bUseWPSNR;                                      ///< Flag to output perceptually weighted peak SNR (WPSNR) instead of PSNR
#endif
  int       m_maxTempLayer;                                   ///< Max temporal layer
Frank Bossen's avatar
Frank Bossen committed
  unsigned              m_ctuSize;
  unsigned m_numSubPics;
Mitsuru Katsumata's avatar
Mitsuru Katsumata committed
  bool m_subPicSameSizeFlag;
  std::vector<uint32_t> m_subPicCtuTopLeftX;
  std::vector<uint32_t> m_subPicCtuTopLeftY;
  std::vector<uint32_t> m_subPicWidth;
  std::vector<uint32_t> m_subPicHeight;
  std::vector<bool>     m_subPicTreatedAsPicFlag;
  std::vector<bool>     m_loopFilterAcrossSubpicEnabledFlag;
  bool m_subPicIdMappingExplicitlySignalledFlag;
  unsigned m_subPicIdLen;
  std::vector<uint16_t> m_subPicId;
  bool      m_SplitConsOverrideEnabledFlag;
Frank Bossen's avatar
Frank Bossen committed
  unsigned              m_minQt[3];   // 0: I slice luma; 1: P/B slice; 2: I slice chroma
Remy Foray's avatar
Remy Foray committed
  unsigned  m_uiMaxMTTHierarchyDepth;
  unsigned  m_uiMaxMTTHierarchyDepthI;
  unsigned  m_uiMaxMTTHierarchyDepthIChroma;
Frank Bossen's avatar
Frank Bossen committed
  unsigned              m_maxBt[3];
  unsigned              m_maxTt[3];
  bool      m_LFNST;
  bool      m_useFastLFNST;
  bool      m_sbTmvpEnableFlag;
  bool      m_adaptBypassAffineMe;
  int                   m_horCollocatedChromaFlag;
  int                   m_verCollocatedChromaFlag;

  int       m_mtsMode;                                        ///< XZ: Multiple Transform Set
Tung Nguyen's avatar
Tung Nguyen committed
  int       m_MTSIntraMaxCand;                                ///< XZ: Number of additional candidates to test
  int       m_MTSInterMaxCand;                                ///< XZ: Number of additional candidates to test
  bool      m_SBT;                                            ///< Sub-Block Transform for inter blocks
  int       m_SBTFast64WidthTh;
  bool      m_SMVD;
  bool      m_bcw;
  bool      m_BcwFast;
  int              m_ladfNumIntervals;
  std::vector<int> m_ladfQpOffset;
  int              m_ladfIntervalLowerBound[MAX_LADF_INTERVALS];
Loading
Loading full blame...