Skip to content

Commit

Permalink
Fix bitstream error handling, other minor stuff (#341)
Browse files Browse the repository at this point in the history
* Output error handling, minor issues

* remove obsolete code
  • Loading branch information
adamjw24 authored Jan 3, 2024
1 parent ed1fa2d commit 09b35ad
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 30 deletions.
36 changes: 26 additions & 10 deletions source/App/vvencFFapp/EncApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ int EncApp::encode()
appCfg.m_inputFileChromaFormat, vvencCfg.m_internChromaFormat, appCfg.m_bClipInputVideoToRec709Range, appCfg.m_packedYUVInput,
appCfg.m_forceY4mInput, appCfg.m_logoFileName ))
{
msgApp( VVENC_ERROR, "open input file failed: %s\n", m_yuvInputFile.getLastError().c_str() );
msgApp( VVENC_ERROR, "\nopen input file failed: %s\n", m_yuvInputFile.getLastError().c_str() );
vvenc_encoder_close( m_encCtx );
vvenc_YUVBuffer_free_buffer( &yuvInBuf );
vvenc_accessUnit_free_payload( &au );
Expand All @@ -267,7 +267,7 @@ int EncApp::encode()
const int remSkipFrames = appCfg.m_FrameSkip - vvencCfg.m_leadFrames;
if( remSkipFrames < 0 )
{
msgApp( VVENC_ERROR, "skip frames (%d) less than number of lead frames required (%d)\n", appCfg.m_FrameSkip, vvencCfg.m_leadFrames );
msgApp( VVENC_ERROR, "\nskip frames (%d) less than number of lead frames required (%d)\n", appCfg.m_FrameSkip, vvencCfg.m_leadFrames );
vvenc_encoder_close( m_encCtx );
vvenc_YUVBuffer_free_buffer( &yuvInBuf );
vvenc_accessUnit_free_payload( &au );
Expand All @@ -279,9 +279,9 @@ int EncApp::encode()
if( 0 != m_yuvInputFile.skipYuvFrames(remSkipFrames, vvencCfg.m_SourceWidth, vvencCfg.m_SourceHeight) )
{
if( ! strcmp( appCfg.m_inputFileName.c_str(), "-" ) )
msgApp( VVENC_ERROR, "skip %d frames from stdin failed\n", remSkipFrames );
msgApp( VVENC_ERROR, "\nskip %d frames from stdin failed\n", remSkipFrames );
else
msgApp( VVENC_ERROR, "skip %d frames failed. file contains %d frames only.\n", remSkipFrames, m_yuvInputFile.countYuvFrames( vvencCfg.m_SourceWidth, vvencCfg.m_SourceHeight) );
msgApp( VVENC_ERROR, "\nskip %d frames failed. file contains %d frames only.\n", remSkipFrames, m_yuvInputFile.countYuvFrames( vvencCfg.m_SourceWidth, vvencCfg.m_SourceHeight) );

vvenc_encoder_close( m_encCtx );
vvenc_YUVBuffer_free_buffer( &yuvInBuf );
Expand All @@ -295,7 +295,7 @@ int EncApp::encode()
iRet = vvenc_init_pass( m_encCtx, pass, appCfg.m_RCStatsFileName.c_str() );
if( iRet != 0 )
{
msgApp( VVENC_ERROR, "init pass failed: %s\n", vvenc_get_last_error(m_encCtx) );
msgApp( VVENC_ERROR, "\ninit pass failed: %s\n", vvenc_get_last_error(m_encCtx) );
vvenc_encoder_close( m_encCtx );
vvenc_YUVBuffer_free_buffer( &yuvInBuf );
vvenc_accessUnit_free_payload( &au );
Expand Down Expand Up @@ -326,7 +326,7 @@ int EncApp::encode()
{
if( 0 != m_yuvInputFile.readYuvBuf( yuvInBuf, inputDone ) )
{
msgApp( VVENC_ERROR, "read input file failed: %s\n", m_yuvInputFile.getLastError().c_str() );
msgApp( VVENC_ERROR, "\nread input file failed: %s\n", m_yuvInputFile.getLastError().c_str() );
vvenc_encoder_close( m_encCtx );
vvenc_YUVBuffer_free_buffer( &yuvInBuf );
vvenc_accessUnit_free_payload( &au );
Expand Down Expand Up @@ -354,15 +354,23 @@ int EncApp::encode()
iRet = vvenc_encode( m_encCtx, inputPacket, &au, &encDone );
if( 0 != iRet )
{
msgApp( VVENC_ERROR, "encoding failed: err code %d: %s\n", iRet, vvenc_get_last_error(m_encCtx) );
msgApp( VVENC_ERROR, "\nencoding failed: err code %d: %s\n", iRet, vvenc_get_last_error(m_encCtx) );
encDone = true;
inputDone = true;
}

// write out encoded access units
if( au.payloadUsedSize )
{
outputAU( au );
if ( 0 != outputAU( au ) )
{
msgApp( VVENC_ERROR, "\nwrite bitstream file failed (disk full?)\n");
vvenc_encoder_close( m_encCtx );
vvenc_YUVBuffer_free_buffer( &yuvInBuf );
vvenc_accessUnit_free_payload( &au );
closeFileIO();
return -1;
}

if( appCfg.m_printStats )
{
Expand Down Expand Up @@ -400,14 +408,19 @@ int EncApp::encode()
return iRet;
}

void EncApp::outputAU( const vvencAccessUnit& au )
int EncApp::outputAU( const vvencAccessUnit& au )
{
m_bitstream.write(reinterpret_cast<const char*>(au.payload), au.payloadUsedSize);
if( m_bitstream.fail() )
{
return -1;
}

m_totalBytes += au.payloadUsedSize;
m_essentialBytes += au.essentialBytes;

m_bitstream.flush();
return 0;
}

void EncApp::outputYuv( void* ctx, vvencYUVBuffer* yuvOutBuf )
Expand All @@ -417,7 +430,10 @@ void EncApp::outputYuv( void* ctx, vvencYUVBuffer* yuvOutBuf )
{
if ( yuvReconFile->isOpen() && nullptr != yuvOutBuf )
{
yuvReconFile->writeYuvBuf( *yuvOutBuf );
if( !yuvReconFile->writeYuvBuf( *yuvOutBuf ) )
{
msgApp( VVENC_ERROR, "\nwrite reconstruction file for pic %ld failed\n", yuvOutBuf->sequenceNumber);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/App/vvencFFapp/EncApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static void changePreset( vvenc_config* c, vvencPresetMode preset )

bool parseCfg( int argc, char* argv[] ); ///< parse configuration file to fill member variables
int encode(); ///< main encoding function
void outputAU ( const vvencAccessUnit& au ); ///< write encoded access units to bitstream
int outputAU ( const vvencAccessUnit& au ); ///< write encoded access units to bitstream
static void outputYuv( void*, vvencYUVBuffer* ); ///< write reconstructed yuv output

bool isShowVersionHelp()
Expand Down
8 changes: 8 additions & 0 deletions source/App/vvencapp/vvencapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,14 @@ int main( int argc, char* argv[] )
{
// write output
cOutBitstream.write( (const char*)AU.payload, AU.payloadUsedSize );
if( cOutBitstream.fail() )
{
msgApp( nullptr, VVENC_ERROR, "\nvvencapp [error]: write bitstream file failed (disk full?)\n");
vvenc_YUVBuffer_free_buffer( &cYUVInputBuffer );
vvenc_accessUnit_free_payload( &AU );
vvenc_encoder_close( enc );
return VVENC_ERR_UNSPECIFIED;
}
}
uiFrames++;
}
Expand Down
2 changes: 1 addition & 1 deletion source/Lib/CommonLib/HRD.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ the Software are granted under this license.
The Clear BSD License
Copyright (c) 2019-2023, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVenC Authors.
Copyright (c) 2019-2023, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVenC Authors.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
Expand Down
2 changes: 1 addition & 1 deletion source/Lib/CommonLib/ProfileLevelTier.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ the Software are granted under this license.
The Clear BSD License
Copyright (c) 2019-2023, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVenC Authors.
Copyright (c) 2019-2023, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVenC Authors.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
Expand Down
1 change: 1 addition & 0 deletions source/Lib/EncoderLib/EncGOP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ void EncGOP::xOutputRecYuv( const PicList& picList )
vvencYUVBuffer yuvBuffer;
vvenc_YUVBuffer_default( &yuvBuffer );
setupYuvBuffer( pic->getRecoBuf(), yuvBuffer, &pps.conformanceWindow );
yuvBuffer.sequenceNumber = pic->poc;
m_recYuvBufFunc( m_recYuvBufCtx, &yuvBuffer );

m_pocRecOut += 1;
Expand Down
18 changes: 1 addition & 17 deletions source/Lib/apputils/IStreamIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -673,22 +673,6 @@ class IStreamToAbbr
const std::vector<SVPair<A>>* toMap;
};

template<bool isFloat> class FloatRoundingOffset
{
};

template<> class FloatRoundingOffset<true>
{
public:
static const int offset = 0;
};

template<> class FloatRoundingOffset<false>
{
public:
static const int offset = 1;
};

template<typename T, typename A>
inline std::istream& operator >> ( std::istream& in, IStreamToAbbr<T,A>& toValue )
{
Expand All @@ -715,7 +699,7 @@ inline std::istream& operator >> ( std::istream& in, IStreamToAbbr<T,A>& toValue
double value = strtod(str.c_str(), NULL); // convert input string to double
value *= map.value; // scale depending on given abbreviation/scaling factor
double roundDir = value < 0 ? -1 : ( value > 0 ? 1 : 0 );
double roundOffset = ( FloatRoundingOffset<std::is_floating_point<T>::value>::offset / 2.0 );
double roundOffset = std::is_floating_point<T>::value ? 0.0 : 0.5;
value += roundDir * roundOffset;
*toValue.dstVal = ( T ) value;
return in;
Expand Down
3 changes: 3 additions & 0 deletions source/Lib/apputils/YuvFileIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,10 @@ class YuvFileIO
for( int comp = 0; comp < numComp; comp++ )
{
if ( ! FileIOHelper::writeYuvPlane( m_cHandle, yuvWriteBuf.planes[ comp ], is16bit, m_fileBitdepth, m_packedYUVMode, comp, m_bufferChrFmt, m_fileChrFmt ) )
{
vvenc_YUVBuffer_free_buffer( &yuvScaled );
return false;
}
}

m_packetCount++;
Expand Down

0 comments on commit 09b35ad

Please sign in to comment.