Minor refactor CalypStream header and format handler
This commit is contained in:
7 files changed
+113
-97
No files matched your search
+1
-1
@@ -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: ''
|
WarningsAsErrors: ''
|
||||||
HeaderFilterRegex: ''
|
HeaderFilterRegex: ''
|
||||||
AnalyzeTemporaryDtors: false
|
AnalyzeTemporaryDtors: false
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ enum CLP_RGB_Components
|
|||||||
|
|
||||||
enum CLP_Endianness
|
enum CLP_Endianness
|
||||||
{
|
{
|
||||||
|
CLP_INVALID_ENDIANESS = -1,
|
||||||
CLP_BIG_ENDIAN = 0,
|
CLP_BIG_ENDIAN = 0,
|
||||||
CLP_LITTLE_ENDIAN = 1,
|
CLP_LITTLE_ENDIAN = 1,
|
||||||
};
|
};
|
||||||
|
|||||||
+50
-44
@@ -48,6 +48,8 @@
|
|||||||
constexpr auto kDefaultBitsPerPixel = 8;
|
constexpr auto kDefaultBitsPerPixel = 8;
|
||||||
constexpr auto kDefaultFrameRate = 30;
|
constexpr auto kDefaultFrameRate = 30;
|
||||||
|
|
||||||
|
auto find_stream_handler( std::string strFilename, bool bRead ) -> CalypStreamFormat::CreateStreamHandlerFn;
|
||||||
|
|
||||||
std::vector<CalypStreamFormat> CalypStream::supportedReadFormats()
|
std::vector<CalypStreamFormat> CalypStream::supportedReadFormats()
|
||||||
{
|
{
|
||||||
INI_REGIST_CALYP_SUPPORTED_FMT;
|
INI_REGIST_CALYP_SUPPORTED_FMT;
|
||||||
@@ -166,8 +168,7 @@ public:
|
|||||||
bool isInit;
|
bool isInit;
|
||||||
bool isInput;
|
bool isInput;
|
||||||
|
|
||||||
CalypStreamHandlerIf* handler;
|
std::unique_ptr<CalypStreamHandlerIf> handler;
|
||||||
CreateStreamHandlerFn pfctCreateHandler;
|
|
||||||
|
|
||||||
std::shared_ptr<CalypStreamFrameBuffer> frameBuffer;
|
std::shared_ptr<CalypStreamFrameBuffer> frameBuffer;
|
||||||
std::deque<std::shared_ptr<CalypFrame>> frameFifo;
|
std::deque<std::shared_ptr<CalypFrame>> frameFifo;
|
||||||
@@ -187,7 +188,6 @@ public:
|
|||||||
CalypStreamPrivate()
|
CalypStreamPrivate()
|
||||||
{
|
{
|
||||||
handler = nullptr;
|
handler = nullptr;
|
||||||
pfctCreateHandler = nullptr;
|
|
||||||
isInput = true;
|
isInput = true;
|
||||||
isInit = false;
|
isInit = false;
|
||||||
bLoadAll = false;
|
bLoadAll = false;
|
||||||
@@ -205,7 +205,6 @@ public:
|
|||||||
if( handler )
|
if( handler )
|
||||||
{
|
{
|
||||||
handler->closeHandler();
|
handler->closeHandler();
|
||||||
handler->Delete();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bLoadAll = false;
|
bLoadAll = false;
|
||||||
@@ -253,43 +252,6 @@ std::vector<std::string> CalypStreamFormat::getExts()
|
|||||||
return arrayExt;
|
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()
|
CalypStream::CalypStream()
|
||||||
: d{ std::make_unique<CalypStreamPrivate>() }
|
: 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->isInit = false;
|
||||||
d->isInput = bInput;
|
d->isInput = bInput;
|
||||||
|
|
||||||
d->pfctCreateHandler = CalypStream::findStreamHandler( filename, d->isInput );
|
auto createHandlerFct = find_stream_handler( filename, d->isInput );
|
||||||
if( !d->pfctCreateHandler )
|
if( !createHandlerFct )
|
||||||
{
|
{
|
||||||
throw CalypFailure( "CalypStream", "Invalid handler" );
|
throw CalypFailure( "CalypStream", "Invalid handler" );
|
||||||
}
|
}
|
||||||
|
|
||||||
d->handler = d->pfctCreateHandler();
|
d->handler = createHandlerFct();
|
||||||
|
|
||||||
if( !d->handler )
|
if( !d->handler )
|
||||||
{
|
{
|
||||||
@@ -434,6 +396,13 @@ bool CalypStream::open( std::string filename, unsigned int width, unsigned int h
|
|||||||
return d->isInit;
|
return d->isInit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CalypStream::supportsFormating()
|
||||||
|
{
|
||||||
|
if( d->handler != nullptr )
|
||||||
|
return false;
|
||||||
|
return d->handler->m_bSupportsFormat;
|
||||||
|
}
|
||||||
|
|
||||||
bool CalypStream::reload()
|
bool CalypStream::reload()
|
||||||
{
|
{
|
||||||
d->frameFifo.clear();
|
d->frameFifo.clear();
|
||||||
@@ -695,3 +664,40 @@ bool CalypStream::seekInput( unsigned long new_frame_num )
|
|||||||
d->readNextFrame();
|
d->readNextFrame();
|
||||||
return true;
|
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
@@ -34,17 +34,6 @@
|
|||||||
|
|
||||||
class CalypStreamHandlerIf;
|
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
|
struct CalypStandardResolution
|
||||||
{
|
{
|
||||||
std::string shortName;
|
std::string shortName;
|
||||||
@@ -52,6 +41,26 @@ struct CalypStandardResolution
|
|||||||
unsigned int uiHeight;
|
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
|
* \class CalypStream
|
||||||
* \ingroup CalypLibGrp CalypStreamGrp
|
* \ingroup CalypLibGrp CalypStreamGrp
|
||||||
@@ -62,9 +71,6 @@ class CalypStream
|
|||||||
public:
|
public:
|
||||||
static std::vector<CalypStreamFormat> supportedReadFormats();
|
static std::vector<CalypStreamFormat> supportedReadFormats();
|
||||||
static std::vector<CalypStreamFormat> supportedWriteFormats();
|
static std::vector<CalypStreamFormat> supportedWriteFormats();
|
||||||
|
|
||||||
static CreateStreamHandlerFn findStreamHandler( std::string strFilename, bool bRead );
|
|
||||||
|
|
||||||
static std::vector<CalypStandardResolution> stdResolutionSizes();
|
static std::vector<CalypStandardResolution> stdResolutionSizes();
|
||||||
|
|
||||||
CalypStream();
|
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 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 bInput );
|
||||||
|
|
||||||
|
bool supportsFormating();
|
||||||
bool reload();
|
bool reload();
|
||||||
|
|
||||||
bool isNative() const;
|
bool isNative() const;
|
||||||
|
|||||||
+33
-37
@@ -51,12 +51,11 @@
|
|||||||
formatsList.insert( formatsList.end(), new_fmts.begin(), new_fmts.end() ); \
|
formatsList.insert( formatsList.end(), new_fmts.begin(), new_fmts.end() ); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define REGISTER_CALYP_STREAM_HANDLER( X ) \
|
#define REGISTER_CALYP_STREAM_HANDLER( X ) \
|
||||||
public: \
|
public: \
|
||||||
static CalypStreamHandlerIf* Create() { return new X(); } \
|
static std::unique_ptr<CalypStreamHandlerIf> Create() { return std::make_unique<X>(); } \
|
||||||
void Delete() { delete this; } \
|
static std::vector<CalypStreamFormat> supportedReadFormats(); \
|
||||||
static std::vector<CalypStreamFormat> supportedReadFormats(); \
|
static std::vector<CalypStreamFormat> supportedWriteFormats(); \
|
||||||
static std::vector<CalypStreamFormat> supportedWriteFormats(); \
|
|
||||||
// static int checkforSupportedFile( String, bool );
|
// static int checkforSupportedFile( String, bool );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,23 +68,7 @@ class CalypStreamHandlerIf
|
|||||||
friend class CalypStream;
|
friend class CalypStream;
|
||||||
|
|
||||||
public:
|
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 ~CalypStreamHandlerIf() {}
|
||||||
virtual void Delete() = 0;
|
|
||||||
|
|
||||||
virtual bool openHandler( std::string strFilename, bool bInput ) = 0;
|
virtual bool openHandler( std::string strFilename, bool bInput ) = 0;
|
||||||
virtual void closeHandler() = 0;
|
virtual void closeHandler() = 0;
|
||||||
@@ -96,28 +79,41 @@ public:
|
|||||||
|
|
||||||
virtual void calculateFrameNumber(){};
|
virtual void calculateFrameNumber(){};
|
||||||
|
|
||||||
std::string getFormatName() { return m_strFormatName; }
|
std::string getFormatName()
|
||||||
std::string getCodecName() { return m_strCodecName; }
|
{
|
||||||
|
return m_strFormatName;
|
||||||
|
}
|
||||||
|
std::string getCodecName()
|
||||||
|
{
|
||||||
|
return m_strCodecName;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
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_strFormatName;
|
||||||
std::string m_strCodecName;
|
std::string m_strCodecName;
|
||||||
bool m_bIsInput;
|
bool m_bIsInput{ true };
|
||||||
bool m_bNative;
|
bool m_bNative{ true };
|
||||||
std::string m_cFilename;
|
std::string m_cFilename;
|
||||||
unsigned int m_uiWidth;
|
unsigned int m_uiWidth{ 0 };
|
||||||
unsigned int m_uiHeight;
|
unsigned int m_uiHeight{ 0 };
|
||||||
int m_iPixelFormat;
|
int m_iPixelFormat{ -1 };
|
||||||
unsigned int m_uiBitsPerPixel;
|
unsigned int m_uiBitsPerPixel{ 8 };
|
||||||
int m_iEndianness;
|
int m_iEndianness{ CLP_INVALID_ENDIANESS };
|
||||||
double m_dFrameRate;
|
double m_dFrameRate{ 30 };
|
||||||
std::uint64_t m_uiCurrFrameFileIdx;
|
std::uint64_t m_uiCurrFrameFileIdx{ 0 };
|
||||||
std::uint64_t m_uiTotalNumberFrames;
|
std::uint64_t m_uiTotalNumberFrames{ 0 };
|
||||||
std::vector<ClpByte> m_pStreamBuffer;
|
std::vector<ClpByte> m_pStreamBuffer;
|
||||||
std::uint64_t m_uiNBytesPerFrame;
|
std::uint64_t m_uiNBytesPerFrame{ 0 };
|
||||||
bool m_isEOF;
|
bool m_isEOF{ false };
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __CALYPSTREAMHANDLERIF_H__
|
#endif // __CALYPSTREAMHANDLERIF_H__
|
||||||
@@ -44,6 +44,12 @@ std::vector<CalypStreamFormat> StreamHandlerRaw::supportedWriteFormats()
|
|||||||
END_REGIST_CALYP_SUPPORTED_FMT;
|
END_REGIST_CALYP_SUPPORTED_FMT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StreamHandlerRaw::StreamHandlerRaw()
|
||||||
|
: CalypStreamHandlerIf{ true }
|
||||||
|
{
|
||||||
|
m_pchHandlerName = "RawVideo";
|
||||||
|
}
|
||||||
|
|
||||||
bool StreamHandlerRaw::openHandler( std::string strFilename, bool bInput )
|
bool StreamHandlerRaw::openHandler( std::string strFilename, bool bInput )
|
||||||
{
|
{
|
||||||
m_bIsInput = bInput;
|
m_bIsInput = bInput;
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ private:
|
|||||||
FILE* m_pFile; /**< The input file pointer >*/
|
FILE* m_pFile; /**< The input file pointer >*/
|
||||||
|
|
||||||
public:
|
public:
|
||||||
StreamHandlerRaw() { m_pchHandlerName = "RawVideo"; }
|
StreamHandlerRaw();
|
||||||
~StreamHandlerRaw() {}
|
~StreamHandlerRaw() {}
|
||||||
bool openHandler( std::string strFilename, bool bInput );
|
bool openHandler( std::string strFilename, bool bInput );
|
||||||
void closeHandler();
|
void closeHandler();
|
||||||
|
|||||||
Reference in new issue
Block a user