Skip to content
Snippets Groups Projects
EncAppCfg.cpp 371 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-2023, 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.cpp
    \brief    Handle encoder configuration parameters
*/

#include "EncAppCfg.h"

#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <string>
#include <fstream>
#include <limits>

#include "Utilities/program_options_lite.h"
#include "Utilities/VideoIOYuv.h"
#include "CommonLib/Rom.h"
#include "EncoderLib/RateCtrl.h"

#include "CommonLib/dtrace_next.h"
#include "CommonLib/ProfileTierLevel.h"

#define MACRO_TO_STRING_HELPER(val) #val
#define MACRO_TO_STRING(val) MACRO_TO_STRING_HELPER(val)

namespace po = df::program_options_lite;

enum ExtendedProfileName   // this is used for determining profile strings, where multiple profiles map to a single
                           // profile idc with various constraint flag combinations
  MAIN_10,
  MAIN_10_STILL_PICTURE,
  MAIN_10_444,
  MAIN_10_444_STILL_PICTURE,
  MULTILAYER_MAIN_10,
  MULTILAYER_MAIN_10_STILL_PICTURE,
  MULTILAYER_MAIN_10_444,
  MULTILAYER_MAIN_10_444_STILL_PICTURE,
  MAIN_12,
  MAIN_12_444,
  MAIN_16_444,
  MAIN_12_INTRA,
  MAIN_12_444_INTRA,
  MAIN_16_444_INTRA,
  MAIN_12_STILL_PICTURE,
  MAIN_12_444_STILL_PICTURE,
  MAIN_16_444_STILL_PICTURE,
constexpr int TF_DEFAULT_REFS = 4;

//! \ingroup EncoderApp
//! \{

// ====================================================================================================================
// Constructor / destructor / initialization / destroy
// ====================================================================================================================

EncAppCfg::EncAppCfg()
: m_inputColourSpaceConvert(IPCOLOURSPACE_UNCHANGED)
, m_snrInternalColourSpace(false)
, m_outputInternalColourSpace(false)
#if EXTENSION_360_VIDEO
, m_ext360(*this)
#endif
{
}

EncAppCfg::~EncAppCfg()
{
#if ENABLE_TRACING
  tracing_uninit(g_trace_ctx);
  g_trace_ctx = nullptr;
#endif
}

void EncAppCfg::create()
{
}

void EncAppCfg::destroy()
{
}

std::istringstream &operator>>(std::istringstream &in, GOPEntry &entry)     //input
{
  in>>entry.m_sliceType;
  in>>entry.m_POC;
  in>>entry.m_QPOffset;
  in>>entry.m_QPOffsetModelOffset;
  in>>entry.m_QPOffsetModelScale;
#if W0038_CQP_ADJ
  in>>entry.m_CbQPoffset;
  in>>entry.m_CrQPoffset;
#endif
  in>>entry.m_QPFactor;
  in>>entry.m_tcOffsetDiv2;
  in>>entry.m_betaOffsetDiv2;
  in>>entry.m_CbTcOffsetDiv2;
  in>>entry.m_CbBetaOffsetDiv2;
  in>>entry.m_CrTcOffsetDiv2;
  in>>entry.m_CrBetaOffsetDiv2;
Hendry's avatar
Hendry committed
  in >> entry.m_numRefPicsActive0;
  in >> entry.m_numRefPics0;
  for (int i = 0; i < entry.m_numRefPics0; i++)
  {
    in >> entry.m_deltaRefPics0[i];
  }
  in >> entry.m_numRefPicsActive1;
  in >> entry.m_numRefPics1;
  for (int i = 0; i < entry.m_numRefPics1; i++)
  {
    in >> entry.m_deltaRefPics1[i];
  }
bool confirmPara(bool bflag, const char* message);

static inline ChromaFormat numberToChromaFormat(const int val)
{
  switch (val)
  {
    case 400: return CHROMA_400; break;
    case 420: return CHROMA_420; break;
    case 422: return CHROMA_422; break;
    case 444: return CHROMA_444; break;
    default:  return NUM_CHROMA_FORMAT;
  }
}

static const struct MapStrToProfile
{
  const char* str;
  Profile::Name value;
} strToProfile[] = {
  { "none", Profile::NONE },
  { "main_10", Profile::MAIN_10 },
  { "main_10_444", Profile::MAIN_10_444 },
  { "main_10_still_picture", Profile::MAIN_10_STILL_PICTURE },
  { "main_10_444_still_picture", Profile::MAIN_10_444_STILL_PICTURE },
  { "multilayer_main_10", Profile::MULTILAYER_MAIN_10 },
  { "multilayer_main_10_444", Profile::MULTILAYER_MAIN_10_444 },
  { "multilayer_main_10_still_picture", Profile::MULTILAYER_MAIN_10_STILL_PICTURE },
  { "multilayer_main_10_444_still_picture", Profile::MULTILAYER_MAIN_10_444_STILL_PICTURE },
  { "main_12", Profile::MAIN_12 },
  { "main_12_444", Profile::MAIN_12_444 },
  { "main_16_444", Profile::MAIN_16_444 },
  { "main_12_intra", Profile::MAIN_12_INTRA },
  { "main_12_444_intra", Profile::MAIN_12_444_INTRA },
  { "main_16_444_intra", Profile::MAIN_16_444_INTRA },
  { "main_12_still_picture", Profile::MAIN_12_STILL_PICTURE },
  { "main_12_444_still_picture", Profile::MAIN_12_444_STILL_PICTURE },
  { "main_16_444_still_picture", Profile::MAIN_16_444_STILL_PICTURE },
};

static const struct MapStrToExtendedProfile
{
  const char* str;
  ExtendedProfileName value;
} strToExtendedProfile[] = {
Loading
Loading full blame...