source: 3DVCSoftware/branches/HTM-4.0-Nokia/source/App/TAppExtractor/TAppExtrCfg.cpp @ 165

Last change on this file since 165 was 56, checked in by hschwarz, 13 years ago

updated trunk (move to HM6.1)

  • Property svn:eol-style set to native
File size: 4.6 KB
Line 
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 */
33
34/** \file     TAppExtrCfg.cpp
35    \brief    Extractor configuration class
36*/
37
38#include <cstdio>
39#include <cstring>
40#include <string>
41#include "TAppExtrCfg.h"
42#include "../../Lib/TAppCommon/program_options_lite.h"
43#include <stdio.h>
44#include <stdlib.h>
45
46#ifdef WIN32
47#define strdup _strdup
48#endif
49
50using namespace std;
51namespace po = df::program_options_lite;
52
53// ====================================================================================================================
54// Public member functions
55// ====================================================================================================================
56
57/** \param argc number of arguments
58    \param argv array of arguments
59 */
60Bool TAppExtrCfg::parseCfg( Int argc, Char* argv[] )
61{
62  bool do_help = false;
63  string cfg_InputBitstreamFile;
64  string cfg_OutputBitstreamFile;
65  string cfg_SpsInfoFile;
66  string cfg_ExtractLayerIds;
67
68  po::Options opts;
69  opts.addOptions()
70  ("help",                   do_help,                   false,      "this help text")
71  ("InputBitstreamFile,i",   cfg_InputBitstreamFile,    string(""), "bitstream input file name")
72  ("OutputBitstreamFile,o",  cfg_OutputBitstreamFile,   string(""), "bitstream output file name")
73  ("SpsInfoFile,s",          cfg_SpsInfoFile,           string(""), "SPS info file name")
74  ("ExtractLayerIds,e",      cfg_ExtractLayerIds,       string(""), "comma-separated list of layer IDs for extraction")
75  ;
76
77  po::setDefaults(opts);
78  const list<const char*>& argv_unhandled = po::scanArgv(opts, argc, (const char**) argv);
79
80  for (list<const char*>::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++)
81  {
82    fprintf(stderr, "Unhandled argument ignored: `%s'\n", *it);
83  }
84
85  if (argc == 1 || do_help)
86  {
87    po::doHelp(cout, opts);
88    return false;
89  }
90
91  /* convert std::string to c string for compatability */
92  m_pchInputBitstreamFile = cfg_InputBitstreamFile.empty() ? NULL : strdup(cfg_InputBitstreamFile.c_str());
93  m_pchOutputBitstreamFile = cfg_OutputBitstreamFile.empty() ? NULL : strdup(cfg_OutputBitstreamFile.c_str());
94  m_pchSpsInfoFile = cfg_SpsInfoFile.empty() ? NULL : strdup(cfg_SpsInfoFile.c_str());
95
96  xSplitUIntString( cfg_ExtractLayerIds, m_suiExtractLayerIds );
97
98  if (!m_pchInputBitstreamFile)
99  {
100    fprintf(stderr, "No input file specifed, aborting\n");
101    return false;
102  }
103
104  if (!m_pchOutputBitstreamFile && !m_pchSpsInfoFile)
105  {
106    fprintf(stderr, "No output file specifed, aborting\n");
107    return false;
108  }
109
110  return true;
111}
112
113Void TAppExtrCfg::xSplitUIntString( const std::string& rString, std::set<UInt>& rSet )
114{
115  char* cString = NULL;
116  char* cElement = NULL;
117
118  cString = new char[rString.size()+1];
119  strcpy(cString, rString.c_str());
120
121  cElement = strtok( cString, "," );
122  while ( cElement != NULL )
123  {
124     rSet.insert( atoi( cElement ) );
125     cElement = strtok( NULL, "," );
126  }
127
128  delete cString;
129}
130
Note: See TracBrowser for help on using the repository browser.