source: 3DVCSoftware/trunk/source/App/TAppExtractor/TAppExtrTop.cpp @ 1313

Last change on this file since 1313 was 1313, checked in by tech, 9 years ago

Merged 14.1-update-dev1@1312.

  • Property svn:eol-style set to native
File size: 5.1 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-2015, ITU/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     TAppExtrTop.cpp
35//    \brief    Extractor application class
36#include "TAppExtrTop.h"
37#include "../../Lib/TLibDecoder/AnnexBread.h"
38#include <fstream>
39#include <list>
40#include <stdio.h>
41#include <fcntl.h>
42#include <assert.h>
43
44#if NH_MV
45// ====================================================================================================================
46// Constructor / destructor / initialization / destroy
47// ====================================================================================================================
48
49TAppExtrTop::TAppExtrTop()
50{
51
52}
53
54TAppExtrTop::~TAppExtrTop()
55{
56}
57
58// ====================================================================================================================
59// Public member functions
60// ====================================================================================================================
61
62//
63//until the end of the bitstream, call extraction function in TExtrTop class
64//
65
66Void TAppExtrTop::extract()
67{
68
69  ifstream inputBitstreamFile( m_pchInputBitstreamFile, ifstream::in | ifstream::binary );
70  if( inputBitstreamFile.fail() )
71  {
72    fprintf( stderr, "\nfailed to open bitstream file `%s' for reading\n", m_pchInputBitstreamFile );
73    exit( EXIT_FAILURE );
74  }
75
76  fstream outputBitstreamFile;
77  if( m_pchOutputBitstreamFile )
78  {
79    outputBitstreamFile.open( m_pchOutputBitstreamFile, fstream::binary | fstream::out );
80    if( outputBitstreamFile.fail() )
81    {
82      fprintf( stderr, "\nfailed to open bitstream file `%s' for writing\n", m_pchOutputBitstreamFile );
83      exit( EXIT_FAILURE );
84    }
85  }
86
87  InputByteStream inputBytestream( inputBitstreamFile );
88
89  Bool bEndOfFile = false;
90  while( !bEndOfFile )
91  {
92    streampos location = inputBitstreamFile.tellg();
93    AnnexBStats stats = AnnexBStats();
94    vector<uint8_t> nalUnit;
95    InputNALUnit nalu;
96    bEndOfFile = byteStreamNALUnit( inputBytestream, nalUnit, stats );
97
98    // handle NAL unit
99    if( nalUnit.empty() )
100    {
101      /* this can happen if the following occur:
102       *  - empty input file
103       *  - two back-to-back start_code_prefixes
104       *  - start_code_prefix immediately followed by EOF
105       */
106      fprintf( stderr, "Warning: Attempt to decode an empty NAL unit\n" );
107    }
108    else
109    {
110      read( nalu );
111
112      // decide whether to extract packet or not
113      if ( m_cTExtrTop.extract( nalu, m_suiExtractLayerIds ) && outputBitstreamFile.is_open() )
114      {
115        inputBitstreamFile.clear();
116
117        streampos location2 = inputBitstreamFile.tellg();
118        inputBitstreamFile.seekg( location );
119
120        do
121        {
122          outputBitstreamFile.put( inputBitstreamFile.get() );
123        } while( inputBitstreamFile.tellg() != location2 );
124      }
125    }
126  }
127
128  inputBitstreamFile.close();
129  outputBitstreamFile.close();
130
131
132  // write SPS info file
133  if ( m_pchSpsInfoFile )
134  {
135    fstream cSpsInfoFileHandle( m_pchSpsInfoFile, fstream::binary | fstream::out );
136
137    if( cSpsInfoFileHandle.fail() )
138    {
139      fprintf( stderr, "\nfailed writing SPS info file\n" );
140      exit( EXIT_FAILURE );
141    }
142
143    m_cTExtrTop.dumpSpsInfo( cSpsInfoFileHandle );
144
145    cSpsInfoFileHandle.close();
146  }
147
148  m_cTExtrTop.dumpVpsInfo( std::cout ); 
149  m_cTExtrTop.dumpSpsInfo( std::cout );
150
151}
152#endif
Note: See TracBrowser for help on using the repository browser.