[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 TAppDecCfg.cpp |
---|
| 35 | \brief Decoder configuration class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include <cstdio> |
---|
| 39 | #include <cstring> |
---|
| 40 | #include <string> |
---|
| 41 | #include "TAppDecCfg.h" |
---|
| 42 | #include "TAppCommon/program_options_lite.h" |
---|
[1029] | 43 | #include "TLibCommon/TComChromaFormat.h" |
---|
[313] | 44 | #if SVC_EXTENSION |
---|
| 45 | #include <cassert> |
---|
| 46 | #endif |
---|
| 47 | |
---|
| 48 | #ifdef WIN32 |
---|
| 49 | #define strdup _strdup |
---|
| 50 | #endif |
---|
| 51 | |
---|
| 52 | using namespace std; |
---|
| 53 | namespace po = df::program_options_lite; |
---|
| 54 | |
---|
| 55 | //! \ingroup TAppDecoder |
---|
| 56 | //! \{ |
---|
| 57 | |
---|
| 58 | // ==================================================================================================================== |
---|
| 59 | // Public member functions |
---|
| 60 | // ==================================================================================================================== |
---|
| 61 | |
---|
| 62 | /** \param argc number of arguments |
---|
| 63 | \param argv array of arguments |
---|
| 64 | */ |
---|
| 65 | Bool TAppDecCfg::parseCfg( Int argc, Char* argv[] ) |
---|
| 66 | { |
---|
| 67 | Bool do_help = false; |
---|
| 68 | string cfg_BitstreamFile; |
---|
| 69 | #if SVC_EXTENSION |
---|
| 70 | string cfg_ReconFile [MAX_LAYERS]; |
---|
| 71 | Int nLayerNum; |
---|
[540] | 72 | #if OUTPUT_LAYER_SET_INDEX |
---|
| 73 | Int olsIdx; |
---|
| 74 | #endif |
---|
[924] | 75 | #if CONFORMANCE_BITSTREAM_MODE |
---|
| 76 | string cfg_confPrefix; |
---|
| 77 | #endif |
---|
[313] | 78 | #if AVC_BASE |
---|
| 79 | string cfg_BLReconFile; |
---|
| 80 | #endif |
---|
| 81 | #else |
---|
| 82 | string cfg_ReconFile; |
---|
| 83 | #endif |
---|
[820] | 84 | |
---|
[313] | 85 | string cfg_TargetDecLayerIdSetFile; |
---|
[1029] | 86 | string outputColourSpaceConvert; |
---|
[313] | 87 | |
---|
| 88 | po::Options opts; |
---|
| 89 | opts.addOptions() |
---|
[1029] | 90 | |
---|
| 91 | |
---|
| 92 | ("help", do_help, false, "this help text") |
---|
| 93 | ("BitstreamFile,b", cfg_BitstreamFile, string(""), "bitstream input file name") |
---|
[313] | 94 | #if SVC_EXTENSION |
---|
| 95 | ("ReconFileL%d,-o%d", cfg_ReconFile, string(""), MAX_LAYERS, "Layer %d reconstructed YUV output file name\n" |
---|
| 96 | "YUV writing is skipped if omitted") |
---|
| 97 | #if AVC_BASE |
---|
| 98 | ("BLReconFile,-ibl", cfg_BLReconFile, string(""), "BL reconstructed YUV input file name") |
---|
[713] | 99 | #if !REPN_FORMAT_IN_VPS |
---|
[313] | 100 | ("BLSourceWidth,-wdt", m_iBLSourceWidth, 0, "BL source picture width") |
---|
| 101 | ("BLSourceHeight,-hgt", m_iBLSourceHeight, 0, "BL source picture height") |
---|
[713] | 102 | #endif |
---|
[313] | 103 | #endif |
---|
[952] | 104 | #if FIX_CONF_MODE |
---|
| 105 | ("LayerNum,-ls", nLayerNum, MAX_NUM_LAYER_IDS, "Number of layers to be decoded.") |
---|
| 106 | #else |
---|
[313] | 107 | ("LayerNum,-ls", nLayerNum, 1, "Number of layers to be decoded.") |
---|
[952] | 108 | #endif |
---|
[540] | 109 | #if OUTPUT_LAYER_SET_INDEX |
---|
| 110 | ("OutpuLayerSetIdx,-olsidx", olsIdx, -1, "Index of output layer set to be decoded.") |
---|
| 111 | #endif |
---|
[924] | 112 | #if CONFORMANCE_BITSTREAM_MODE |
---|
| 113 | ("ConformanceBitstremMode,-confMode", m_confModeFlag, false, "Enable generation of conformance bitstream metadata; True: Generate metadata, False: No metadata generated") |
---|
| 114 | ("ConformanceMetadataPrefix,-confPrefix", cfg_confPrefix, string(""), "Prefix for the file name of the conformance data. Default name - 'decodedBitstream'") |
---|
| 115 | #endif |
---|
[1029] | 116 | #else |
---|
| 117 | ("ReconFile,o", cfg_ReconFile, string(""), "reconstructed YUV output file name\n" |
---|
| 118 | "YUV writing is skipped if omitted") |
---|
| 119 | #endif |
---|
| 120 | |
---|
| 121 | ("SkipFrames,s", m_iSkipFrame, 0, "number of frames to skip before random access") |
---|
| 122 | ("OutputBitDepth,d", m_outputBitDepth[CHANNEL_TYPE_LUMA], 0, "bit depth of YUV output luma component (default: use 0 for native depth)") |
---|
| 123 | ("OutputBitDepthC,d", m_outputBitDepth[CHANNEL_TYPE_CHROMA], 0, "bit depth of YUV output chroma component (default: use 0 for native depth)") |
---|
| 124 | ("OutputColourSpaceConvert", outputColourSpaceConvert, string(""), "Colour space conversion to apply to input 444 video. Permitted values are (empty string=UNCHANGED) " + getListOfColourSpaceConverts(false)) |
---|
| 125 | ("MaxTemporalLayer,t", m_iMaxTemporalLayer, -1, "Maximum Temporal Layer to be decoded. -1 to decode all layers") |
---|
| 126 | ("SEIDecodedPictureHash", m_decodedPictureHashSEIEnabled, 1, "Control handling of decoded picture hash SEI messages\n" |
---|
| 127 | "\t1: check hash in SEI messages if available in the bitstream\n" |
---|
| 128 | "\t0: ignore SEI message") |
---|
| 129 | ("SEIpictureDigest", m_decodedPictureHashSEIEnabled, 1, "deprecated alias for SEIDecodedPictureHash") |
---|
| 130 | ("SEINoDisplay", m_decodedNoDisplaySEIEnabled, true, "Control handling of decoded no display SEI messages") |
---|
| 131 | ("TarDecLayerIdSetFile,l", cfg_TargetDecLayerIdSetFile, string(""), "targetDecLayerIdSet file name. The file should include white space separated LayerId values to be decoded. Omitting the option or a value of -1 in the file decodes all layers.") |
---|
| 132 | ("RespectDefDispWindow,w", m_respectDefDispWindow, 0, "Only output content inside the default display window\n") |
---|
| 133 | #if O0043_BEST_EFFORT_DECODING |
---|
| 134 | ("ForceDecodeBitDepth", m_forceDecodeBitDepth, 0U, "Force the decoder to operate at a particular bit-depth (best effort decoding)") |
---|
| 135 | #endif |
---|
[856] | 136 | #if Q0074_COLOUR_REMAPPING_SEI |
---|
| 137 | ("SEIColourRemappingInfo", m_colourRemapSEIEnabled, false, "Control handling of Colour Remapping Information SEI messages\n" |
---|
| 138 | "\t1: apply colour remapping on decoded pictures if available in the bitstream\n" |
---|
| 139 | "\t0: ignore SEI message") |
---|
| 140 | #endif |
---|
[313] | 141 | ; |
---|
[1029] | 142 | |
---|
[313] | 143 | po::setDefaults(opts); |
---|
| 144 | const list<const Char*>& argv_unhandled = po::scanArgv(opts, argc, (const Char**) argv); |
---|
| 145 | |
---|
| 146 | for (list<const Char*>::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++) |
---|
| 147 | { |
---|
| 148 | fprintf(stderr, "Unhandled argument ignored: `%s'\n", *it); |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | if (argc == 1 || do_help) |
---|
| 152 | { |
---|
| 153 | po::doHelp(cout, opts); |
---|
| 154 | return false; |
---|
| 155 | } |
---|
| 156 | |
---|
[1029] | 157 | m_outputColourSpaceConvert = stringToInputColourSpaceConvert(outputColourSpaceConvert, false); |
---|
| 158 | if (m_outputColourSpaceConvert>=NUMBER_INPUT_COLOUR_SPACE_CONVERSIONS) |
---|
| 159 | { |
---|
| 160 | fprintf(stderr, "Bad output colour space conversion string\n"); |
---|
| 161 | return false; |
---|
| 162 | } |
---|
| 163 | |
---|
[313] | 164 | /* convert std::string to c string for compatability */ |
---|
| 165 | m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str()); |
---|
| 166 | #if SVC_EXTENSION |
---|
| 167 | m_tgtLayerId = nLayerNum - 1; |
---|
| 168 | assert( m_tgtLayerId >= 0 ); |
---|
[953] | 169 | #if !FIX_CONF_MODE |
---|
| 170 | assert( m_tgtLayerId < MAX_LAYERS ); // If this is wrong, it should be caught by asserts in other locations. |
---|
| 171 | #endif |
---|
[547] | 172 | #if O0137_MAX_LAYERID |
---|
| 173 | assert( m_tgtLayerId < MAX_NUM_LAYER_IDS ); |
---|
| 174 | #endif |
---|
[1029] | 175 | #if OUTPUT_LAYER_SET_INDEX |
---|
[924] | 176 | #if CONFORMANCE_BITSTREAM_MODE |
---|
| 177 | if( m_confModeFlag ) |
---|
| 178 | { |
---|
| 179 | assert( olsIdx != -1 ); // In the conformance mode, target output layer set index is to be explicitly specified. |
---|
| 180 | |
---|
| 181 | if( cfg_confPrefix.empty() ) |
---|
| 182 | { |
---|
| 183 | m_confPrefix = string("decodedBitstream"); |
---|
| 184 | } |
---|
| 185 | else |
---|
| 186 | { |
---|
| 187 | m_confPrefix = cfg_confPrefix; |
---|
| 188 | } |
---|
| 189 | // Open metadata file and write |
---|
| 190 | char fileNameSuffix[255]; |
---|
| 191 | sprintf(fileNameSuffix, "%s-OLS%d.opl", m_confPrefix.c_str(), olsIdx); // olsIdx is the target output layer set index. |
---|
| 192 | m_metadataFileName = string(fileNameSuffix); |
---|
| 193 | m_metadataFileRefresh = true; |
---|
| 194 | |
---|
| 195 | // Decoded layer YUV files |
---|
[953] | 196 | #if FIX_CONF_MODE |
---|
[1044] | 197 | for(Int layer= 0; layer < MAX_VPS_LAYER_IDX_PLUS1; layer++ ) |
---|
[953] | 198 | #else |
---|
[924] | 199 | for(UInt layer=0; layer<= m_tgtLayerId; layer++) |
---|
[953] | 200 | #endif |
---|
[924] | 201 | { |
---|
| 202 | sprintf(fileNameSuffix, "%s-L%d.yuv", m_confPrefix.c_str(), layer); // olsIdx is the target output layer set index. |
---|
| 203 | m_decodedYuvLayerFileName[layer] = std::string( fileNameSuffix ); |
---|
| 204 | m_decodedYuvLayerRefresh[layer] = true; |
---|
| 205 | } |
---|
| 206 | } |
---|
| 207 | #endif |
---|
[1029] | 208 | m_commonDecoderParams.setTargetOutputLayerSetIdx( olsIdx ); |
---|
| 209 | m_commonDecoderParams.setTargetLayerId( m_tgtLayerId ); |
---|
[540] | 210 | #endif |
---|
[953] | 211 | #if FIX_CONF_MODE |
---|
[1044] | 212 | for(Int layer = 0; layer < MAX_VPS_LAYER_IDX_PLUS1; layer++ ) |
---|
[953] | 213 | { |
---|
| 214 | #else |
---|
[313] | 215 | for(UInt layer=0; layer<= m_tgtLayerId; layer++) |
---|
| 216 | { |
---|
[932] | 217 | assert( layer < MAX_LAYERS ); |
---|
[953] | 218 | #endif |
---|
[313] | 219 | m_pchReconFile[layer] = cfg_ReconFile[layer].empty() ? NULL : strdup(cfg_ReconFile[layer].c_str()); |
---|
| 220 | } |
---|
| 221 | #if AVC_BASE |
---|
| 222 | m_pchBLReconFile = cfg_BLReconFile.empty() ? NULL : strdup(cfg_BLReconFile.c_str()); |
---|
| 223 | #endif |
---|
| 224 | #else |
---|
| 225 | m_pchReconFile = cfg_ReconFile.empty() ? NULL : strdup(cfg_ReconFile.c_str()); |
---|
| 226 | #endif |
---|
| 227 | |
---|
| 228 | if (!m_pchBitstreamFile) |
---|
| 229 | { |
---|
[1029] | 230 | fprintf(stderr, "No input file specified, aborting\n"); |
---|
[313] | 231 | return false; |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | if ( !cfg_TargetDecLayerIdSetFile.empty() ) |
---|
| 235 | { |
---|
| 236 | FILE* targetDecLayerIdSetFile = fopen ( cfg_TargetDecLayerIdSetFile.c_str(), "r" ); |
---|
| 237 | if ( targetDecLayerIdSetFile ) |
---|
| 238 | { |
---|
| 239 | Bool isLayerIdZeroIncluded = false; |
---|
| 240 | while ( !feof(targetDecLayerIdSetFile) ) |
---|
| 241 | { |
---|
| 242 | Int layerIdParsed = 0; |
---|
| 243 | if ( fscanf( targetDecLayerIdSetFile, "%d ", &layerIdParsed ) != 1 ) |
---|
| 244 | { |
---|
| 245 | if ( m_targetDecLayerIdSet.size() == 0 ) |
---|
| 246 | { |
---|
| 247 | fprintf(stderr, "No LayerId could be parsed in file %s. Decoding all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() ); |
---|
| 248 | } |
---|
| 249 | break; |
---|
| 250 | } |
---|
| 251 | if ( layerIdParsed == -1 ) // The file includes a -1, which means all LayerIds are to be decoded. |
---|
| 252 | { |
---|
| 253 | m_targetDecLayerIdSet.clear(); // Empty set means decoding all layers. |
---|
| 254 | break; |
---|
| 255 | } |
---|
| 256 | if ( layerIdParsed < 0 || layerIdParsed >= MAX_NUM_LAYER_IDS ) |
---|
| 257 | { |
---|
[1029] | 258 | fprintf(stderr, "Warning! Parsed LayerId %d is not within allowed range [0,%d]. Ignoring this value.\n", layerIdParsed, MAX_NUM_LAYER_IDS-1 ); |
---|
[313] | 259 | } |
---|
| 260 | else |
---|
| 261 | { |
---|
| 262 | isLayerIdZeroIncluded = layerIdParsed == 0 ? true : isLayerIdZeroIncluded; |
---|
| 263 | m_targetDecLayerIdSet.push_back ( layerIdParsed ); |
---|
| 264 | } |
---|
| 265 | } |
---|
| 266 | fclose (targetDecLayerIdSetFile); |
---|
[1005] | 267 | #if !R0235_SMALLEST_LAYER_ID // LayerId=0 is not required anymore in some cases |
---|
[1029] | 268 | if ( m_targetDecLayerIdSet.size() > 0 && !isLayerIdZeroIncluded ) |
---|
[313] | 269 | { |
---|
| 270 | fprintf(stderr, "TargetDecLayerIdSet must contain LayerId=0, aborting" ); |
---|
| 271 | return false; |
---|
| 272 | } |
---|
[1005] | 273 | #endif |
---|
[313] | 274 | } |
---|
| 275 | else |
---|
| 276 | { |
---|
| 277 | fprintf(stderr, "File %s could not be opened. Using all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() ); |
---|
| 278 | } |
---|
[540] | 279 | #if OUTPUT_LAYER_SET_INDEX |
---|
| 280 | this->getCommonDecoderParams()->setTargetDecLayerIdSet( &m_targetDecLayerIdSet ); |
---|
| 281 | #endif |
---|
[313] | 282 | } |
---|
| 283 | |
---|
| 284 | return true; |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | //! \} |
---|