Minor refactor CalypStream header and format handler

This commit is contained in:
2021-10-10 19:48:14 +01:00
parent fbbd77bfbf
commit b7ad00a4c5
7 changed files with 113 additions and 97 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
---
Checks: 'clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-pointer-arithmetic'
Checks: 'clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-non-private-member-variables-in-classes'
WarningsAsErrors: ''
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false
+1
View File
@@ -93,6 +93,7 @@ enum CLP_RGB_Components
enum CLP_Endianness
{
CLP_INVALID_ENDIANESS = -1,
CLP_BIG_ENDIAN = 0,
CLP_LITTLE_ENDIAN = 1,
};
+50 -44
View File
@@ -48,6 +48,8 @@
constexpr auto kDefaultBitsPerPixel = 8;
constexpr auto kDefaultFrameRate = 30;
auto find_stream_handler( std::string strFilename, bool bRead ) -> CalypStreamFormat::CreateStreamHandlerFn;
std::vector<CalypStreamFormat> CalypStream::supportedReadFormats()
{
INI_REGIST_CALYP_SUPPORTED_FMT;
@@ -166,8 +168,7 @@ public:
bool isInit;
bool isInput;
CalypStreamHandlerIf* handler;
CreateStreamHandlerFn pfctCreateHandler;
std::unique_ptr<CalypStreamHandlerIf> handler;
std::shared_ptr<CalypStreamFrameBuffer> frameBuffer;
std::deque<std::shared_ptr<CalypFrame>> frameFifo;
@@ -187,7 +188,6 @@ public:
CalypStreamPrivate()
{
handler = nullptr;
pfctCreateHandler = nullptr;
isInput = true;
isInit = false;
bLoadAll = false;
@@ -205,7 +205,6 @@ public:
if( handler )
{
handler->closeHandler();
handler->Delete();
}
bLoadAll = false;
@@ -253,43 +252,6 @@ std::vector<std::string> CalypStreamFormat::getExts()
return arrayExt;
}
CreateStreamHandlerFn CalypStream::findStreamHandler( std::string strFilename, bool bRead )
{
std::string currExt = strFilename.substr( strFilename.find_last_of( "." ) + 1 );
currExt = clpLowercase( currExt );
std::vector<CalypStreamFormat> supportedFmts;
if( bRead )
{
supportedFmts = CalypStream::supportedReadFormats();
}
else
{
supportedFmts = CalypStream::supportedWriteFormats();
}
for( unsigned int i = 0; i < supportedFmts.size(); i++ )
{
std::vector<std::string> arrayExt = supportedFmts[i].getExts();
for( std::vector<std::string>::iterator e = arrayExt.begin(); e != arrayExt.end(); ++e )
{
if( currExt != "" && currExt == *e )
{
return supportedFmts[i].formatFct;
}
else if( strFilename.find( *e ) != std::string::npos )
{
return supportedFmts[i].formatFct;
}
}
}
#ifdef USE_FFMPEG
return &StreamHandlerLibav::Create;
#else
return &StreamHandlerRaw::Create;
#endif
}
CalypStream::CalypStream()
: d{ std::make_unique<CalypStreamPrivate>() }
{
@@ -348,13 +310,13 @@ bool CalypStream::open( std::string filename, unsigned int width, unsigned int h
d->isInit = false;
d->isInput = bInput;
d->pfctCreateHandler = CalypStream::findStreamHandler( filename, d->isInput );
if( !d->pfctCreateHandler )
auto createHandlerFct = find_stream_handler( filename, d->isInput );
if( !createHandlerFct )
{
throw CalypFailure( "CalypStream", "Invalid handler" );
}
d->handler = d->pfctCreateHandler();
d->handler = createHandlerFct();
if( !d->handler )
{
@@ -434,6 +396,13 @@ bool CalypStream::open( std::string filename, unsigned int width, unsigned int h
return d->isInit;
}
bool CalypStream::supportsFormating()
{
if( d->handler != nullptr )
return false;
return d->handler->m_bSupportsFormat;
}
bool CalypStream::reload()
{
d->frameFifo.clear();
@@ -695,3 +664,40 @@ bool CalypStream::seekInput( unsigned long new_frame_num )
d->readNextFrame();
return true;
}
auto find_stream_handler( std::string strFilename, bool bRead ) -> CalypStreamFormat::CreateStreamHandlerFn
{
std::string currExt = strFilename.substr( strFilename.find_last_of( "." ) + 1 );
currExt = clpLowercase( currExt );
std::vector<CalypStreamFormat> supportedFmts;
if( bRead )
{
supportedFmts = CalypStream::supportedReadFormats();
}
else
{
supportedFmts = CalypStream::supportedWriteFormats();
}
for( unsigned int i = 0; i < supportedFmts.size(); i++ )
{
std::vector<std::string> arrayExt = supportedFmts[i].getExts();
for( std::vector<std::string>::iterator e = arrayExt.begin(); e != arrayExt.end(); ++e )
{
if( currExt != "" && currExt == *e )
{
return supportedFmts[i].formatFct;
}
else if( strFilename.find( *e ) != std::string::npos )
{
return supportedFmts[i].formatFct;
}
}
}
#ifdef USE_FFMPEG
return &StreamHandlerLibav::Create;
#else
return &StreamHandlerRaw::Create;
#endif
}
+21 -14
View File
@@ -34,17 +34,6 @@
class CalypStreamHandlerIf;
typedef CalypStreamHandlerIf* ( *CreateStreamHandlerFn )( void );
struct CalypStreamFormat
{
std::string formatName;
std::string formatExt;
std::vector<std::string> getExts();
std::string formatPattern;
CreateStreamHandlerFn formatFct;
};
struct CalypStandardResolution
{
std::string shortName;
@@ -52,6 +41,26 @@ struct CalypStandardResolution
unsigned int uiHeight;
};
/**
* \class CalypStreamFormat
* \ingroup CalypLibGrp CalypStreamGrp
* \brief Stream format handling class
*/
class CalypStreamFormat
{
public:
using CreateStreamHandlerFn = auto ( * )( void ) -> std::unique_ptr<CalypStreamHandlerIf>;
CalypStreamFormat() = default;
std::vector<std::string> getExts();
std::string formatName;
std::string formatExt;
std::string formatPattern;
CreateStreamHandlerFn formatFct;
};
/**
* \class CalypStream
* \ingroup CalypLibGrp CalypStreamGrp
@@ -62,9 +71,6 @@ class CalypStream
public:
static std::vector<CalypStreamFormat> supportedReadFormats();
static std::vector<CalypStreamFormat> supportedWriteFormats();
static CreateStreamHandlerFn findStreamHandler( std::string strFilename, bool bRead );
static std::vector<CalypStandardResolution> stdResolutionSizes();
CalypStream();
@@ -84,6 +90,7 @@ public:
bool open( std::string filename, unsigned int width, unsigned int height, int input_format, unsigned int bitsPel, int endianness, bool hasNegative, unsigned int frame_rate,
bool bInput );
bool supportsFormating();
bool reload();
bool isNative() const;
+33 -37
View File
@@ -51,12 +51,11 @@
formatsList.insert( formatsList.end(), new_fmts.begin(), new_fmts.end() ); \
}
#define REGISTER_CALYP_STREAM_HANDLER( X ) \
public: \
static CalypStreamHandlerIf* Create() { return new X(); } \
void Delete() { delete this; } \
static std::vector<CalypStreamFormat> supportedReadFormats(); \
static std::vector<CalypStreamFormat> supportedWriteFormats(); \
#define REGISTER_CALYP_STREAM_HANDLER( X ) \
public: \
static std::unique_ptr<CalypStreamHandlerIf> Create() { return std::make_unique<X>(); } \
static std::vector<CalypStreamFormat> supportedReadFormats(); \
static std::vector<CalypStreamFormat> supportedWriteFormats(); \
// static int checkforSupportedFile( String, bool );
/**
@@ -69,23 +68,7 @@ class CalypStreamHandlerIf
friend class CalypStream;
public:
CalypStreamHandlerIf()
: m_bIsInput( true )
, m_bNative( true )
, m_uiWidth( 0 )
, m_uiHeight( 0 )
, m_iPixelFormat( -1 )
, m_uiBitsPerPixel( 8 )
, m_iEndianness( -1 )
, m_dFrameRate( 30 )
, m_uiCurrFrameFileIdx( 0 )
, m_uiTotalNumberFrames( 0 )
, m_uiNBytesPerFrame( 0 )
, m_isEOF( false )
{
}
virtual ~CalypStreamHandlerIf() {}
virtual void Delete() = 0;
virtual bool openHandler( std::string strFilename, bool bInput ) = 0;
virtual void closeHandler() = 0;
@@ -96,28 +79,41 @@ public:
virtual void calculateFrameNumber(){};
std::string getFormatName() { return m_strFormatName; }
std::string getCodecName() { return m_strCodecName; }
std::string getFormatName()
{
return m_strFormatName;
}
std::string getCodecName()
{
return m_strCodecName;
}
protected:
const char* m_pchHandlerName;
CalypStreamHandlerIf() = default;
CalypStreamHandlerIf( bool supportsFormats )
: m_bSupportsFormat{ supportsFormats }
{
}
const char* m_pchHandlerName{ "" };
const bool m_bSupportsFormat{ false };
std::string m_strFormatName;
std::string m_strCodecName;
bool m_bIsInput;
bool m_bNative;
bool m_bIsInput{ true };
bool m_bNative{ true };
std::string m_cFilename;
unsigned int m_uiWidth;
unsigned int m_uiHeight;
int m_iPixelFormat;
unsigned int m_uiBitsPerPixel;
int m_iEndianness;
double m_dFrameRate;
std::uint64_t m_uiCurrFrameFileIdx;
std::uint64_t m_uiTotalNumberFrames;
unsigned int m_uiWidth{ 0 };
unsigned int m_uiHeight{ 0 };
int m_iPixelFormat{ -1 };
unsigned int m_uiBitsPerPixel{ 8 };
int m_iEndianness{ CLP_INVALID_ENDIANESS };
double m_dFrameRate{ 30 };
std::uint64_t m_uiCurrFrameFileIdx{ 0 };
std::uint64_t m_uiTotalNumberFrames{ 0 };
std::vector<ClpByte> m_pStreamBuffer;
std::uint64_t m_uiNBytesPerFrame;
bool m_isEOF;
std::uint64_t m_uiNBytesPerFrame{ 0 };
bool m_isEOF{ false };
};
#endif // __CALYPSTREAMHANDLERIF_H__
+6
View File
@@ -44,6 +44,12 @@ std::vector<CalypStreamFormat> StreamHandlerRaw::supportedWriteFormats()
END_REGIST_CALYP_SUPPORTED_FMT;
}
StreamHandlerRaw::StreamHandlerRaw()
: CalypStreamHandlerIf{ true }
{
m_pchHandlerName = "RawVideo";
}
bool StreamHandlerRaw::openHandler( std::string strFilename, bool bInput )
{
m_bIsInput = bInput;
+1 -1
View File
@@ -40,7 +40,7 @@ private:
FILE* m_pFile; /**< The input file pointer >*/
public:
StreamHandlerRaw() { m_pchHandlerName = "RawVideo"; }
StreamHandlerRaw();
~StreamHandlerRaw() {}
bool openHandler( std::string strFilename, bool bInput );
void closeHandler();