Skip to content
Snippets Groups Projects
Commit 9ea4a38d authored by Philippe de Lagrange's avatar Philippe de Lagrange
Browse files

Added a new app to scan NAL units in a VVC elementary stream: report NAL unit...

Added a new app to scan NAL units in a VVC elementary stream: report NAL unit size (in bytes), type, layer id, temporal id, and type as text (with SEI payload type for SEI NAL units).
parent c4d8ef48
No related branches found
No related tags found
No related merge requests found
......@@ -142,6 +142,7 @@ add_subdirectory( "source/App/SEIFilmGrainApp" )
add_subdirectory( "source/App/Parcat" )
add_subdirectory( "source/App/StreamMergeApp" )
add_subdirectory( "source/App/BitstreamExtractorApp" )
add_subdirectory( "source/App/BitstreamScanApp" )
add_subdirectory( "source/App/SubpicMergeApp" )
if( EXTENSION_360_VIDEO )
add_subdirectory( "source/App/utils/360ConvertApp" )
......
/* 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-2023, 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 BitstreamScanApp.cpp
\brief Bitstream scan application class
*/
#include <list>
#include <vector>
#include <stdio.h>
#include <fcntl.h>
#include "BitstreamScanApp.h"
#include "DecoderLib/AnnexBread.h"
#include "DecoderLib/NALread.h"
#include "CommonLib/Rom.h"
//! \ingroup DecoderApp
//! \{
// ====================================================================================================================
// Constructor / destructor / initialization / destroy
// ====================================================================================================================
BitstreamScanApp::BitstreamScanApp()
{
}
// ====================================================================================================================
// Public member functions
// ====================================================================================================================
void read2(InputNALUnit& nalu)
{
InputBitstream& bs = nalu.getBitstream();
nalu.m_forbiddenZeroBit = bs.read(1); // forbidden zero bit
nalu.m_nuhReservedZeroBit = bs.read(1); // nuh_reserved_zero_bit
nalu.m_nuhLayerId = bs.read(6); // nuh_layer_id
nalu.m_nalUnitType = (NalUnitType) bs.read(5); // nal_unit_type
nalu.m_temporalId = bs.read(3) - 1; // nuh_temporal_id_plus1
}
uint32_t BitstreamScanApp::decode()
{
std::ifstream bitstreamFileIn(m_bitstreamFileNameIn.c_str(), std::ifstream::in | std::ifstream::binary);
if (!bitstreamFileIn)
{
EXIT( "failed to open bitstream file " << m_bitstreamFileNameIn.c_str() << " for reading" ) ;
}
InputByteStream bytestream(bitstreamFileIn);
bitstreamFileIn.clear();
bitstreamFileIn.seekg(0, std::ios::beg);
int unitCnt = 0;
while (!!bitstreamFileIn)
{
AnnexBStats stats = AnnexBStats();
InputNALUnit nalu;
byteStreamNALUnit(bytestream, nalu.getBitstream().getFifo(), stats);
int bytes = stats.m_numLeadingZero8BitsBytes + stats.m_numZeroByteBytes + stats.m_numStartCodePrefixBytes + stats.m_numBytesInNALUnit + stats.m_numTrailingZero8BitsBytes;
// 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;
if (unitCnt >= m_numNALUnitsToSkip)
{
printf("%d,%d,%d,%d,%s\n", bytes, NAL_UNIT_INVALID, 0, 0, "empty");
}
}
else
{
read2( nalu );
unitCnt++;
if (unitCnt >= m_numNALUnitsToSkip)
{
printf("%d,%d,%d,%d,%s", bytes, nalu.m_nalUnitType, nalu.m_nuhLayerId, nalu.m_temporalId, nalUnitTypeToString(nalu.m_nalUnitType));
if (nalu.m_nalUnitType == NAL_UNIT_PREFIX_SEI || nalu.m_nalUnitType == NAL_UNIT_SUFFIX_SEI)
{
int payloadType = 0;
uint32_t val = 0;
do
{
nalu.getBitstream().read(8, val);
payloadType += val;
} while (val==0xFF);
uint32_t payloadSize = 0;
do
{
nalu.getBitstream().read(8, val);
payloadSize += val;
} while (val==0xFF);
printf(" [%d:%d]", payloadType, payloadSize);
}
printf("\n");
}
}
}
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-2023, 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 BitstreamScanApp.h
\brief Decoder application class (header)
*/
#ifndef __BITSTREAMSCANAPP__
#define __BITSTREAMSCANAPP__
#pragma once
#include <stdio.h>
#include <fstream>
#include <iostream>
#include "CommonLib/CommonDef.h"
#include "BitstreamScanAppCfg.h"
// ====================================================================================================================
// Class definition
// ====================================================================================================================
/// decoder application class
class BitstreamScanApp : public BitstreamScanAppCfg
{
public:
BitstreamScanApp();
virtual ~BitstreamScanApp () {}
uint32_t decode (); ///< main decoding function
};
#endif // __BITSTREAMSCANAPP__
/* 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-2023, 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 BitstreamScanAppCfg.cpp
\brief Bitstream scan configuration class
*/
#include <cstdio>
#include <cstring>
#include <string>
#include "BitstreamScanAppCfg.h"
#include "Utilities/program_options_lite.h"
namespace po = ProgramOptionsLite;
//! \ingroup DecoderApp
//! \{
// ====================================================================================================================
// Public member functions
// ====================================================================================================================
/** \param argc number of arguments
\param argv array of arguments
*/
bool BitstreamScanAppCfg::parseCfg( int argc, char* argv[] )
{
bool do_help = false;
int warnUnknowParameter = 0;
po::Options opts;
// clang-format off
opts.addOptions()
("help", do_help, false, "this help text")
("BitstreamFileIn,b", m_bitstreamFileNameIn, std::string(""), "bitstream input file name")
("NumSkip", m_numNALUnitsToSkip, 0, "number of NAL units to skip (counted inclusive the units skipped with -p/-s options)" )
("WarnUnknowParameter,w", warnUnknowParameter, 0, "warn for unknown configuration parameters instead of failing")
;
// clang-format on
po::setDefaults(opts);
po::ErrorReporter err;
const std::list<const char *> &argv_unhandled = po::scanArgv(opts, argc, (const char **) argv, err);
for (std::list<const char *>::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(std::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;
}
return true;
}
BitstreamScanAppCfg::BitstreamScanAppCfg()
: m_bitstreamFileNameIn()
{
}
BitstreamScanAppCfg::~BitstreamScanAppCfg()
{
}
//! \}
/* 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-2023, 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 BitstreamScanAppCfg.h
\brief Decoder configuration class (header)
*/
#ifndef __BITSTREAMSCANAPPCFG__
#define __BITSTREAMSCANAPPCFG__
#pragma once
#include "CommonLib/CommonDef.h"
#include <vector>
//! \ingroup DecoderApp
//! \{
// ====================================================================================================================
// Class definition
// ====================================================================================================================
/// Decoder configuration class
class BitstreamScanAppCfg
{
protected:
std::string m_bitstreamFileNameIn; ///< input bitstream file name
int m_numNALUnitsToSkip;
public:
BitstreamScanAppCfg();
virtual ~BitstreamScanAppCfg();
bool parseCfg ( int argc, char* argv[] ); ///< initialize option class from configuration
};
//! \}
#endif // __BITSTREAMSCANAPPCFG__
# executable
set( EXE_NAME BitstreamScanApp )
# 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} ${NATVIS_FILES} )
include_directories(${CMAKE_CURRENT_BINARY_DIR})
if( DEFINED ENABLE_TRACING )
if( ENABLE_TRACING )
target_compile_definitions( ${EXE_NAME} PUBLIC ENABLE_TRACING=1 )
else()
target_compile_definitions( ${EXE_NAME} PUBLIC ENABLE_TRACING=0 )
endif()
endif()
if( DEFINED ENABLE_HIGH_BITDEPTH )
if( ENABLE_HIGH_BITDEPTH )
target_compile_definitions( ${EXE_NAME} PUBLIC RExt__HIGH_BIT_DEPTH_SUPPORT=1 )
else()
target_compile_definitions( ${EXE_NAME} PUBLIC RExt__HIGH_BIT_DEPTH_SUPPORT=0 )
endif()
endif()
if( CMAKE_COMPILER_IS_GNUCC AND BUILD_STATIC )
set( ADDITIONAL_LIBS ${ADDITIONAL_LIBS} -static -static-libgcc -static-libstdc++ )
target_compile_definitions( ${EXE_NAME} PUBLIC ENABLE_WPP_STATIC_LINK=1 )
endif()
target_link_libraries( ${EXE_NAME} CommonLib DecoderLib Utilities ${ADDITIONAL_LIBS} )
# lldb custom data formatters
if( XCODE )
add_dependencies( ${EXE_NAME} Install${PROJECT_NAME}LldbFiles )
endif()
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}/BitstreamScanApp>
$<$<CONFIG:Release>:${CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE}/BitstreamScanApp>
$<$<CONFIG:RelWithDebInfo>:${CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO}/BitstreamScanApp>
$<$<CONFIG:MinSizeRel>:${CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL}/BitstreamScanApp>
$<$<CONFIG:Debug>:${CMAKE_SOURCE_DIR}/bin/BitstreamScanAppStaticd>
$<$<CONFIG:Release>:${CMAKE_SOURCE_DIR}/bin/BitstreamScanAppStatic>
$<$<CONFIG:RelWithDebInfo>:${CMAKE_SOURCE_DIR}/bin/BitstreamScanAppStaticp>
$<$<CONFIG:MinSizeRel>:${CMAKE_SOURCE_DIR}/bin/BitstreamScanAppStaticm> )
endif()
# example: place header files in different folders
source_group( "Natvis Files" FILES ${NATVIS_FILES} )
# 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-2023, 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 bitstreamscanmain.cpp
\brief Bitstream scan application main
*/
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "BitstreamScanApp.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, "VVCSoftware: VTM Decoder Version %s ", VTM_VERSION );
fprintf( stdout, NVM_ONOS );
fprintf( stdout, NVM_COMPILEDBY );
fprintf( stdout, NVM_BITS );
#if ENABLE_SIMD_OPT
std::string SIMD;
ProgramOptionsLite::Options optsSimd;
optsSimd.addOptions()("SIMD", SIMD, std::string(""), "");
ProgramOptionsLite::SilentReporter err;
ProgramOptionsLite::scanArgv(optsSimd, argc, (const char**) argv, err);
fprintf( stdout, "[SIMD=%s] ", read_x86_extension( SIMD ) );
#endif
#if ENABLE_TRACING
fprintf( stdout, "[ENABLE_TRACING] " );
#endif
fprintf( stdout, "\n" );
BitstreamScanApp *pcDecApp = new BitstreamScanApp;
// parse configuration
if(!pcDecApp->parseCfg( argc, argv ))
{
returnCode = EXIT_FAILURE;
return returnCode;
}
// starting time
double dResult;
clock_t lBefore = clock();
// call decoding function
#ifndef _DEBUG
try
{
#endif // !_DEBUG
if( 0 != pcDecApp->decode() )
{
// never happens
returnCode = EXIT_FAILURE;
}
#ifndef _DEBUG
}
catch( Exception &e )
{
std::cerr << e.what() << std::endl;
returnCode = EXIT_FAILURE;
}
catch( ... )
{
std::cerr << "Unspecified error occurred" << std::endl;
returnCode = EXIT_FAILURE;
}
#endif
// ending time
dResult = (double)(clock()-lBefore) / CLOCKS_PER_SEC;
printf("\n Total Time: %12.3f sec.\n", dResult);
delete pcDecApp;
return returnCode;
}
//! \}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment