[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 |
---|
[1200] | 4 | * granted under this license. |
---|
[5] | 5 | * |
---|
[1200] | 6 | * Copyright (c) 2010-2015, ITU/ISO/IEC |
---|
[5] | 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. |
---|
[56] | 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
[5] | 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 | /** \file TAppDecCfg.cpp |
---|
| 35 | \brief Decoder configuration class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include <cstdio> |
---|
| 39 | #include <cstring> |
---|
| 40 | #include <string> |
---|
| 41 | #include "TAppDecCfg.h" |
---|
[56] | 42 | #include "TAppCommon/program_options_lite.h" |
---|
[1200] | 43 | #include "TLibCommon/TComChromaFormat.h" |
---|
[2] | 44 | #ifdef WIN32 |
---|
| 45 | #define strdup _strdup |
---|
| 46 | #endif |
---|
[1200] | 47 | #if NH_MV |
---|
| 48 | #include <cassert> |
---|
| 49 | #endif |
---|
[2] | 50 | |
---|
| 51 | using namespace std; |
---|
| 52 | namespace po = df::program_options_lite; |
---|
| 53 | |
---|
[56] | 54 | //! \ingroup TAppDecoder |
---|
| 55 | //! \{ |
---|
| 56 | |
---|
[2] | 57 | // ==================================================================================================================== |
---|
| 58 | // Public member functions |
---|
| 59 | // ==================================================================================================================== |
---|
| 60 | |
---|
| 61 | /** \param argc number of arguments |
---|
| 62 | \param argv array of arguments |
---|
| 63 | */ |
---|
| 64 | Bool TAppDecCfg::parseCfg( Int argc, Char* argv[] ) |
---|
| 65 | { |
---|
[608] | 66 | Bool do_help = false; |
---|
[2] | 67 | string cfg_BitstreamFile; |
---|
| 68 | string cfg_ReconFile; |
---|
[608] | 69 | string cfg_TargetDecLayerIdSetFile; |
---|
[1200] | 70 | #if NH_3D |
---|
[2] | 71 | string cfg_ScaleOffsetFile; |
---|
[608] | 72 | #endif |
---|
[1200] | 73 | string outputColourSpaceConvert; |
---|
| 74 | Int warnUnknowParameter = 0; |
---|
[2] | 75 | |
---|
| 76 | po::Options opts; |
---|
| 77 | opts.addOptions() |
---|
[1200] | 78 | |
---|
| 79 | |
---|
| 80 | ("help", do_help, false, "this help text") |
---|
| 81 | ("BitstreamFile,b", cfg_BitstreamFile, string(""), "bitstream input file name") |
---|
| 82 | ("ReconFile,o", cfg_ReconFile, string(""), "reconstructed YUV output file name\n" |
---|
| 83 | "YUV writing is skipped if omitted") |
---|
| 84 | #if NH_3D |
---|
| 85 | ("ScaleOffsetFile,p", cfg_ScaleOffsetFile, string(""), "file with coded scales and offsets") |
---|
| 86 | ("Depth420OutputFlag", m_depth420OutputFlag, true , "Output depth layers in 4:2:0 ") |
---|
[608] | 87 | #endif |
---|
[1200] | 88 | ("WarnUnknowParameter,w", warnUnknowParameter, 0, "warn for unknown configuration parameters instead of failing") |
---|
| 89 | ("SkipFrames,s", m_iSkipFrame, 0, "number of frames to skip before random access") |
---|
| 90 | ("OutputBitDepth,d", m_outputBitDepth[CHANNEL_TYPE_LUMA], 0, "bit depth of YUV output luma component (default: use 0 for native depth)") |
---|
| 91 | ("OutputBitDepthC,d", m_outputBitDepth[CHANNEL_TYPE_CHROMA], 0, "bit depth of YUV output chroma component (default: use 0 for native depth)") |
---|
| 92 | ("OutputColourSpaceConvert", outputColourSpaceConvert, string(""), "Colour space conversion to apply to input 444 video. Permitted values are (empty string=UNCHANGED) " + getListOfColourSpaceConverts(false)) |
---|
| 93 | #if NH_MV |
---|
| 94 | ("TargetOptLayerSetIdx,x", m_targetOptLayerSetIdx, -1, "Target output layer set index. (default: -1, determine automatically to be equal to highest layer set index") // Should actually equal to 0 as default. However, this would cause only the base layer to be decoded. |
---|
[608] | 95 | #endif |
---|
[1200] | 96 | ("MaxTemporalLayer,t", m_iMaxTemporalLayer, -1, "Maximum Temporal Layer to be decoded. -1 to decode all layers") |
---|
| 97 | ("SEIDecodedPictureHash", m_decodedPictureHashSEIEnabled, 1, "Control handling of decoded picture hash SEI messages\n" |
---|
| 98 | "\t1: check hash in SEI messages if available in the bitstream\n" |
---|
| 99 | "\t0: ignore SEI message") |
---|
| 100 | ("SEINoDisplay", m_decodedNoDisplaySEIEnabled, true, "Control handling of decoded no display SEI messages") |
---|
| 101 | ("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.") |
---|
| 102 | ("RespectDefDispWindow,w", m_respectDefDispWindow, 0, "Only output content inside the default display window\n") |
---|
| 103 | #if NH_MV |
---|
| 104 | ("OutputVpsInfo,v", m_outputVpsInfo, false, "Output information about the layer dependencies and layer sets") |
---|
[1066] | 105 | #endif |
---|
[1200] | 106 | #if O0043_BEST_EFFORT_DECODING |
---|
| 107 | ("ForceDecodeBitDepth", m_forceDecodeBitDepth, 0U, "Force the decoder to operate at a particular bit-depth (best effort decoding)") |
---|
| 108 | #endif |
---|
| 109 | ("OutputDecodedSEIMessagesFilename", m_outputDecodedSEIMessagesFilename, string(""), "When non empty, output decoded SEI messages to the indicated file. If file is '-', then output to stdout\n") |
---|
| 110 | ("ClipOutputVideoToRec709Range", m_bClipOutputVideoToRec709Range, false, "If true then clip output video to the Rec. 709 Range on saving") |
---|
[2] | 111 | ; |
---|
[1200] | 112 | |
---|
[2] | 113 | po::setDefaults(opts); |
---|
[1200] | 114 | po::ErrorReporter err; |
---|
| 115 | const list<const Char*>& argv_unhandled = po::scanArgv(opts, argc, (const Char**) argv, err); |
---|
[2] | 116 | |
---|
[608] | 117 | for (list<const Char*>::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++) |
---|
[2] | 118 | { |
---|
| 119 | fprintf(stderr, "Unhandled argument ignored: `%s'\n", *it); |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | if (argc == 1 || do_help) |
---|
| 123 | { |
---|
| 124 | po::doHelp(cout, opts); |
---|
| 125 | return false; |
---|
| 126 | } |
---|
| 127 | |
---|
[1200] | 128 | if (err.is_errored) |
---|
| 129 | { |
---|
| 130 | if (!warnUnknowParameter) |
---|
| 131 | { |
---|
| 132 | /* errors have already been reported to stderr */ |
---|
| 133 | return false; |
---|
| 134 | } |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | m_outputColourSpaceConvert = stringToInputColourSpaceConvert(outputColourSpaceConvert, false); |
---|
| 138 | if (m_outputColourSpaceConvert>=NUMBER_INPUT_COLOUR_SPACE_CONVERSIONS) |
---|
| 139 | { |
---|
| 140 | fprintf(stderr, "Bad output colour space conversion string\n"); |
---|
| 141 | return false; |
---|
| 142 | } |
---|
| 143 | |
---|
[2] | 144 | /* convert std::string to c string for compatability */ |
---|
| 145 | m_pchBitstreamFile = cfg_BitstreamFile.empty() ? NULL : strdup(cfg_BitstreamFile.c_str()); |
---|
| 146 | m_pchReconFile = cfg_ReconFile.empty() ? NULL : strdup(cfg_ReconFile.c_str()); |
---|
[608] | 147 | |
---|
[1200] | 148 | #if NH_3D |
---|
[2] | 149 | m_pchScaleOffsetFile = cfg_ScaleOffsetFile.empty() ? NULL : strdup(cfg_ScaleOffsetFile.c_str()); |
---|
[608] | 150 | #endif |
---|
[1200] | 151 | |
---|
[2] | 152 | if (!m_pchBitstreamFile) |
---|
| 153 | { |
---|
[1200] | 154 | fprintf(stderr, "No input file specified, aborting\n"); |
---|
[2] | 155 | return false; |
---|
| 156 | } |
---|
| 157 | |
---|
[608] | 158 | if ( !cfg_TargetDecLayerIdSetFile.empty() ) |
---|
| 159 | { |
---|
[1200] | 160 | #if NH_MV |
---|
[738] | 161 | m_targetDecLayerIdSetFileEmpty = false; |
---|
| 162 | #endif |
---|
[608] | 163 | FILE* targetDecLayerIdSetFile = fopen ( cfg_TargetDecLayerIdSetFile.c_str(), "r" ); |
---|
| 164 | if ( targetDecLayerIdSetFile ) |
---|
| 165 | { |
---|
| 166 | Bool isLayerIdZeroIncluded = false; |
---|
| 167 | while ( !feof(targetDecLayerIdSetFile) ) |
---|
| 168 | { |
---|
| 169 | Int layerIdParsed = 0; |
---|
| 170 | if ( fscanf( targetDecLayerIdSetFile, "%d ", &layerIdParsed ) != 1 ) |
---|
| 171 | { |
---|
| 172 | if ( m_targetDecLayerIdSet.size() == 0 ) |
---|
| 173 | { |
---|
| 174 | fprintf(stderr, "No LayerId could be parsed in file %s. Decoding all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() ); |
---|
| 175 | } |
---|
| 176 | break; |
---|
| 177 | } |
---|
| 178 | if ( layerIdParsed == -1 ) // The file includes a -1, which means all LayerIds are to be decoded. |
---|
| 179 | { |
---|
| 180 | m_targetDecLayerIdSet.clear(); // Empty set means decoding all layers. |
---|
| 181 | break; |
---|
| 182 | } |
---|
| 183 | if ( layerIdParsed < 0 || layerIdParsed >= MAX_NUM_LAYER_IDS ) |
---|
| 184 | { |
---|
[1200] | 185 | fprintf(stderr, "Warning! Parsed LayerId %d is not within allowed range [0,%d]. Ignoring this value.\n", layerIdParsed, MAX_NUM_LAYER_IDS-1 ); |
---|
[608] | 186 | } |
---|
| 187 | else |
---|
| 188 | { |
---|
| 189 | isLayerIdZeroIncluded = layerIdParsed == 0 ? true : isLayerIdZeroIncluded; |
---|
| 190 | m_targetDecLayerIdSet.push_back ( layerIdParsed ); |
---|
| 191 | } |
---|
| 192 | } |
---|
| 193 | fclose (targetDecLayerIdSetFile); |
---|
| 194 | if ( m_targetDecLayerIdSet.size() > 0 && !isLayerIdZeroIncluded ) |
---|
| 195 | { |
---|
| 196 | fprintf(stderr, "TargetDecLayerIdSet must contain LayerId=0, aborting" ); |
---|
| 197 | return false; |
---|
| 198 | } |
---|
| 199 | } |
---|
| 200 | else |
---|
| 201 | { |
---|
| 202 | fprintf(stderr, "File %s could not be opened. Using all LayerIds as default.\n", cfg_TargetDecLayerIdSetFile.c_str() ); |
---|
| 203 | } |
---|
| 204 | } |
---|
[1200] | 205 | |
---|
| 206 | #if NH_MV |
---|
| 207 | //m_targetDecLayerIdSet.push_back( 0 ); // Only base layer at startup |
---|
[608] | 208 | #endif |
---|
[2] | 209 | return true; |
---|
| 210 | } |
---|
| 211 | |
---|
[1200] | 212 | #if NH_MV |
---|
[2] | 213 | Void TAppDecCfg::xAppendToFileNameEnd( Char* pchInputFileName, const Char* pchStringToAppend, Char*& rpchOutputFileName) |
---|
| 214 | { |
---|
| 215 | size_t iInLength = strlen(pchInputFileName); |
---|
| 216 | size_t iAppendLength = strlen(pchStringToAppend); |
---|
| 217 | |
---|
[100] | 218 | rpchOutputFileName = (Char*) malloc(iInLength+iAppendLength+1); |
---|
| 219 | Char* pCDot = strrchr(pchInputFileName,'.'); |
---|
| 220 | pCDot = pCDot ? pCDot : pchInputFileName + iInLength; |
---|
[2] | 221 | size_t iCharsToDot = pCDot - pchInputFileName ; |
---|
[100] | 222 | size_t iCharsToEnd = iInLength - iCharsToDot; |
---|
[2] | 223 | strncpy(rpchOutputFileName , pchInputFileName , iCharsToDot ); |
---|
| 224 | strncpy(rpchOutputFileName+ iCharsToDot , pchStringToAppend , iAppendLength); |
---|
[100] | 225 | strncpy(rpchOutputFileName+ iCharsToDot+iAppendLength , pchInputFileName+iCharsToDot, iCharsToEnd ); |
---|
| 226 | rpchOutputFileName[iInLength+iAppendLength] = '\0'; |
---|
[2] | 227 | } |
---|
[608] | 228 | #endif |
---|
[56] | 229 | //! \} |
---|