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

Last change on this file since 1314 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
RevLine 
[608]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// *
[1179]6// * Copyright (c) 2010-2015, ITU/ISO/IEC
[608]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
[56]36#include "TAppExtrTop.h"
37#include "../../Lib/TLibDecoder/AnnexBread.h"
38#include <fstream>
[42]39#include <list>
40#include <stdio.h>
41#include <fcntl.h>
42#include <assert.h>
43
[1313]44#if NH_MV
[42]45// ====================================================================================================================
46// Constructor / destructor / initialization / destroy
47// ====================================================================================================================
48
49TAppExtrTop::TAppExtrTop()
50{
[1313]51
[42]52}
53
[56]54TAppExtrTop::~TAppExtrTop()
[42]55{
56}
57
58// ====================================================================================================================
59// Public member functions
60// ====================================================================================================================
61
[608]62//
63//until the end of the bitstream, call extraction function in TExtrTop class
64//
65
[42]66Void TAppExtrTop::extract()
67{
68
[56]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  }
[42]75
[56]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  }
[42]86
[56]87  InputByteStream inputBytestream( inputBitstreamFile );
88
89  Bool bEndOfFile = false;
90  while( !bEndOfFile )
[42]91  {
[56]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() )
[42]100    {
[56]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" );
[42]107    }
[56]108    else
109    {
[1313]110      read( nalu );
[42]111
[56]112      // decide whether to extract packet or not
113      if ( m_cTExtrTop.extract( nalu, m_suiExtractLayerIds ) && outputBitstreamFile.is_open() )
[42]114      {
[56]115        inputBitstreamFile.clear();
116
117        streampos location2 = inputBitstreamFile.tellg();
118        inputBitstreamFile.seekg( location );
119
120        do
[42]121        {
[56]122          outputBitstreamFile.put( inputBitstreamFile.get() );
123        } while( inputBitstreamFile.tellg() != location2 );
[42]124      }
125    }
126  }
127
[56]128  inputBitstreamFile.close();
129  outputBitstreamFile.close();
130
[608]131
[42]132  // write SPS info file
133  if ( m_pchSpsInfoFile )
134  {
[56]135    fstream cSpsInfoFileHandle( m_pchSpsInfoFile, fstream::binary | fstream::out );
[42]136
[56]137    if( cSpsInfoFileHandle.fail() )
[42]138    {
[56]139      fprintf( stderr, "\nfailed writing SPS info file\n" );
140      exit( EXIT_FAILURE );
[42]141    }
142
[56]143    m_cTExtrTop.dumpSpsInfo( cSpsInfoFileHandle );
[42]144
[56]145    cSpsInfoFileHandle.close();
[42]146  }
[608]147
148  m_cTExtrTop.dumpVpsInfo( std::cout ); 
[56]149  m_cTExtrTop.dumpSpsInfo( std::cout );
[608]150
[42]151}
[608]152#endif
Note: See TracBrowser for help on using the repository browser.