Commit 36deab3a authored by Karsten Suehring's avatar Karsten Suehring
Browse files

Backport of SEIRemovalApp from VTM

parent b13a0f42
Pipeline #5787 passed with stage
in 7 minutes and 48 seconds
......@@ -134,6 +134,7 @@ add_subdirectory( "source/App/TAppDecoderAnalyser" )
add_subdirectory( "source/App/TAppEncoder" )
add_subdirectory( "source/App/TAppMCTSExtractor" )
add_subdirectory( "source/App/Parcat" )
add_subdirectory( "source/App/SEIRemovalApp" )
if( EXTENSION_360_VIDEO )
add_subdirectory( "source/App/utils/360ConvertApp" )
endif()
# executable
set( EXE_NAME SEIRemovalApp )
# get source files
file( GLOB SRC_FILES "*.cpp" )
# get include files
file( GLOB INC_FILES "*.h" )
# get additional libs for gcc on Ubuntu systems
if( CMAKE_SYSTEM_NAME STREQUAL "Linux" )
if( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
if( USE_ADDRESS_SANITIZER )
set( ADDITIONAL_LIBS asan )
endif()
endif()
endif()
# NATVIS files for Visual Studio
if( MSVC )
file( GLOB NATVIS_FILES "../../VisualStudio/*.natvis" )
endif()
# add executable
add_executable( ${EXE_NAME} ${SRC_FILES} ${INC_FILES} )
# include the output directory, where the svnrevision.h file is generated
include_directories(${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries( ${EXE_NAME} TLibCommon TLibDecoder Utilities Threads::Threads ${ADDITIONAL_LIBS} )
if( CMAKE_SYSTEM_NAME STREQUAL "Linux" )
add_custom_command( TARGET ${EXE_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy
$<$<CONFIG:Debug>:${CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG}/SEIRemovalApp>
$<$<CONFIG:Release>:${CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE}/SEIRemovalApp>
$<$<CONFIG:RelWithDebInfo>:${CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO}/SEIRemovalApp>
$<$<CONFIG:MinSizeRel>:${CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL}/SEIRemovalApp>
$<$<CONFIG:Debug>:${CMAKE_SOURCE_DIR}/bin/SEIRemovalAppStaticd>
$<$<CONFIG:Release>:${CMAKE_SOURCE_DIR}/bin/SEIRemovalAppStatic>
$<$<CONFIG:RelWithDebInfo>:${CMAKE_SOURCE_DIR}/bin/SEIRemovalAppStaticp>
$<$<CONFIG:MinSizeRel>:${CMAKE_SOURCE_DIR}/bin/SEIRemovalAppStaticm> )
endif()
# set the folder where to place the projects
set_target_properties( ${EXE_NAME} PROPERTIES FOLDER app LINKER_LANGUAGE CXX )
/* The copyright in this software is being made available under the BSD
* License, included below. This software may be subject to other third party
* and contributor rights, including patent rights, and no such rights are
* granted under this license.
*
* Copyright (c) 2010-2020, ITU/ISO/IEC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/** \file SEIRemovalApp.cpp
\brief Decoder application class
*/
#include <list>
#include <vector>
#include <stdio.h>
#include <fcntl.h>
#include "SEIRemovalApp.h"
#include "TLibDecoder/AnnexBread.h"
#include "TLibDecoder/NALread.h"
//! \ingroup DecoderApp
//! \{
// ====================================================================================================================
// Constructor / destructor / initialization / destroy
// ====================================================================================================================
SEIRemovalApp::SEIRemovalApp()
{
}
// ====================================================================================================================
// Public member functions
// ====================================================================================================================
/**
- create internal class
- initialize internal class
- until the end of the bitstream, call decoding function in SEIRemovalApp class
- delete allocated buffers
- destroy internal class
- returns the number of mismatching pictures
*/
Void read2(InputNALUnit& nalu)
{
TComInputBitstream& bs = nalu.getBitstream();
Bool forbidden_zero_bit = bs.read(1); // forbidden_zero_bit
if (forbidden_zero_bit != 0)
{
std::cerr << "Forbidden zero-bit not '0'" << std::endl;
exit(1);
}
nalu.m_nalUnitType = (NalUnitType) bs.read(6); // nal_unit_type
nalu.m_nuhLayerId = bs.read(6); // nuh_layer_id
nalu.m_temporalId = bs.read(3) - 1; // nuh_temporal_id_plus1
}
UInt SEIRemovalApp::decode()
{
// Int poc;
// PicList* pcListPic = NULL;
ifstream bitstreamFileIn(m_bitstreamFileNameIn.c_str(), ifstream::in | ifstream::binary);
if (!bitstreamFileIn)
{
std::cerr << "failed to open bitstream file " << m_bitstreamFileNameIn.c_str() << " for reading";
exit(1);
}
ofstream bitstreamFileOut(m_bitstreamFileNameOut.c_str(), ifstream::out | ifstream::binary);
InputByteStream bytestream(bitstreamFileIn);
bitstreamFileIn.clear();
bitstreamFileIn.seekg( 0, ios::beg );
int unitCnt = 0;
while (!!bitstreamFileIn)
{
/* location serves to work around a design fault in the decoder, whereby
* the process of reading a new slice that is the first slice of a new frame
* requires the SEIRemovalApp::decode() method to be called again with the same
* nal unit. */
AnnexBStats stats = AnnexBStats();
InputNALUnit nalu;
byteStreamNALUnit(bytestream, nalu.getBitstream().getFifo(), stats);
// call actual decoding function
if (nalu.getBitstream().getFifo().empty())
{
/* this can happen if the following occur:
* - empty input file
* - two back-to-back start_code_prefixes
* - start_code_prefix immediately followed by EOF
*/
std::cerr << "Warning: Attempt to decode an empty NAL unit" << std::endl;
}
else
{
read2( nalu );
unitCnt++;
bool bWrite = true;
// just kick out all suffix SEIS
bWrite &= (( !m_discardSuffixSEIs || nalu.m_nalUnitType != NAL_UNIT_SUFFIX_SEI ) && ( !m_discardPrefixSEIs || nalu.m_nalUnitType != NAL_UNIT_PREFIX_SEI ));
bWrite &= unitCnt >= m_numNALUnitsToSkip;
bWrite &= m_numNALUnitsToWrite < 0 || unitCnt <= m_numNALUnitsToWrite;
if( bWrite )
{
int iNumZeros = stats.m_numLeadingZero8BitsBytes + stats.m_numZeroByteBytes + stats.m_numStartCodePrefixBytes -1;
char ch = 0;
for( int i = 0 ; i < iNumZeros; i++ ) { bitstreamFileOut.write( &ch, 1 ); }
ch = 1; bitstreamFileOut.write( &ch, 1 );
bitstreamFileOut.write( (const char*)nalu.getBitstream().getFifo().data(), nalu.getBitstream().getFifo().size() );
}
}
}
return 0;
}
//! \}
/* The copyright in this software is being made available under the BSD
* License, included below. This software may be subject to other third party
* and contributor rights, including patent rights, and no such rights are
* granted under this license.
*
* Copyright (c) 2010-2020, ITU/ISO/IEC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/** \file SEIRemovalApp.h
\brief Decoder application class (header)
*/
#ifndef __SEIREMOVALAPP__
#define __SEIREMOVALAPP__
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <stdio.h>
#include <fstream>
#include <iostream>
#include "TLibCommon/CommonDef.h"
#include "SEIRemovalAppCfg.h"
using namespace std;
// ====================================================================================================================
// Class definition
// ====================================================================================================================
/// decoder application class
class SEIRemovalApp : public SEIRemovalAppCfg
{
public:
SEIRemovalApp();
virtual ~SEIRemovalApp () {}
UInt decode (); ///< main decoding function
};
#endif // __SEIREMOVALAPP__
/* The copyright in this software is being made available under the BSD
* License, included below. This software may be subject to other third party
* and contributor rights, including patent rights, and no such rights are
* granted under this license.
*
* Copyright (c) 2010-2020, ITU/ISO/IEC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/** \file SEIRemovalAppCfg.cpp
\brief Decoder configuration class
*/
#include <cstdio>
#include <cstring>
#include <string>
#include "SEIRemovalAppCfg.h"
#include "Utilities/program_options_lite.h"
using namespace std;
namespace po = df::program_options_lite;
//! \ingroup DecoderApp
//! \{
// ====================================================================================================================
// Public member functions
// ====================================================================================================================
/** \param argc number of arguments
\param argv array of arguments
*/
Bool SEIRemovalAppCfg::parseCfg( Int argc, TChar* argv[] )
{
Bool do_help = false;
Int warnUnknowParameter = 0;
po::Options opts;
opts.addOptions()
("help", do_help, false, "this help text")
("BitstreamFileIn,b", m_bitstreamFileNameIn, string(""), "bitstream input file name")
("BitstreamFileOut,o", m_bitstreamFileNameOut, string(""), "bitstream output file name")
("DiscardPrefixSEI,p", m_discardPrefixSEIs, false, "remove all prefix SEIs (default: 0)")
("DiscardSuffixSEI,s", m_discardSuffixSEIs, true, "remove all suffix SEIs (default: 1)")
("NumSkip", m_numNALUnitsToSkip, 0, "number of NAL units to skip (counted inclusive the units skipped with -p/-s options)" )
("NumWrite", m_numNALUnitsToWrite, -1, "number of NAL units to write (counted inclusive the units skipped with -p/-s/--NumSkip options), -1 to disable" )
("WarnUnknowParameter,w", warnUnknowParameter, 0, "warn for unknown configuration parameters instead of failing")
;
po::setDefaults(opts);
po::ErrorReporter err;
const list<const TChar*>& argv_unhandled = po::scanArgv(opts, argc, (const TChar**) argv, err);
for (list<const TChar*>::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++)
{
std::cerr << "Unhandled argument ignored: "<< *it << std::endl;
}
if (argc == 1 || do_help)
{
po::doHelp(cout, opts);
return false;
}
if (err.is_errored)
{
if (!warnUnknowParameter)
{
/* errors have already been reported to stderr */
return false;
}
}
if (m_bitstreamFileNameIn.empty())
{
std::cerr << "No input file specified, aborting" << std::endl;
return false;
}
if (m_bitstreamFileNameOut.empty())
{
std::cerr << "No output file specified, aborting" << std::endl;
return false;
}
return true;
}
SEIRemovalAppCfg::SEIRemovalAppCfg()
: m_bitstreamFileNameIn()
, m_bitstreamFileNameOut()
, m_discardPrefixSEIs( false )
, m_discardSuffixSEIs( false )
{
}
SEIRemovalAppCfg::~SEIRemovalAppCfg()
{
}
//! \}
/* The copyright in this software is being made available under the BSD
* License, included below. This software may be subject to other third party
* and contributor rights, including patent rights, and no such rights are
* granted under this license.
*
* Copyright (c) 2010-2020, ITU/ISO/IEC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/** \file SEIRemovalAppCfg.h
\brief Decoder configuration class (header)
*/
#ifndef __SEIREMOVALAPPCFG__
#define __SEIREMOVALAPPCFG__
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "TLibCommon/CommonDef.h"
#include <vector>
//! \ingroup DecoderApp
//! \{
// ====================================================================================================================
// Class definition
// ====================================================================================================================
/// Decoder configuration class
class SEIRemovalAppCfg
{
protected:
std::string m_bitstreamFileNameIn; ///< output bitstream file name
std::string m_bitstreamFileNameOut; ///< input bitstream file name
bool m_discardPrefixSEIs;
bool m_discardSuffixSEIs;
int m_numNALUnitsToSkip;
int m_numNALUnitsToWrite;
public:
SEIRemovalAppCfg();
virtual ~SEIRemovalAppCfg();
Bool parseCfg ( Int argc, TChar* argv[] ); ///< initialize option class from configuration
};
//! \}
#endif // __SEIREMOVALAPPCFG__
/* The copyright in this software is being made available under the BSD
* License, included below. This software may be subject to other third party
* and contributor rights, including patent rights, and no such rights are
* granted under this license.
*
* Copyright (c) 2010-2020, ITU/ISO/IEC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/** \file decmain.cpp
\brief Decoder application main
*/
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "SEIRemovalApp.h"
#include "program_options_lite.h"
//! \ingroup DecoderApp
//! \{
// ====================================================================================================================
// Main function
// ====================================================================================================================
int main(int argc, char* argv[])
{
Int returnCode = EXIT_SUCCESS;
// print information
fprintf( stdout, "\n" );
fprintf( stdout, "HM: SEIRemovalApp Version %s ", NV_VERSION );
fprintf( stdout, NVM_ONOS );
fprintf( stdout, NVM_COMPILEDBY );
fprintf( stdout, NVM_BITS );
#if HHI_SIMD_OPT
std::string SIMD;
df::program_options_lite::Options optsSimd;
optsSimd.addOptions()( "SIMD", SIMD, string( "" ), "" );
df::program_options_lite::SilentReporter err;
df::program_options_lite::scanArgv( optsSimd, argc, ( const TChar** ) argv, err );
fprintf( stdout, "[SIMD=%s] ", read_x86_extension( SIMD ) );
#endif
#if ENABLE_TRACING
fprintf( stdout, "[ENABLE_TRACING] " );
#endif
fprintf( stdout, "\n" );
SEIRemovalApp *pcDecApp = new SEIRemovalApp;
// parse configuration
if(!pcDecApp->parseCfg( argc, argv ))
{
returnCode = EXIT_FAILURE;
return returnCode;
}
// starting time
Double dResult;
clock_t lBefore = clock();
// call decoding function
if( 0 != pcDecApp->decode() )
{
printf( "\n\n***ERROR*** A decoding mismatch occured: signalled md5sum does not match\n" );
returnCode = EXIT_FAILURE;
}
// ending time
dResult = (Double)(clock()-lBefore) / CLOCKS_PER_SEC;
printf("\n Total Time: %12.3f sec.\n", dResult);
delete pcDecApp;
return returnCode;
}
//! \}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment