Skip to content

Commit 079f14d

Browse files
author
Clement Champetier
committed
VideoProperties: add private function to refactore try/catch of getPropertiesAsMap
1 parent c7c0c56 commit 079f14d

File tree

2 files changed

+47
-32
lines changed

2 files changed

+47
-32
lines changed

src/AvTranscoder/mediaProperty/VideoProperties.cpp

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -587,36 +587,36 @@ PropertiesMap VideoProperties::getPropertiesAsMap() const
587587
{
588588
PropertiesMap dataMap;
589589

590-
detail::add( dataMap, "streamId", getStreamId() );
591-
detail::add( dataMap, "codecId", getCodecId() );
592-
detail::add( dataMap, "codecName", getCodecName() );
593-
detail::add( dataMap, "codecLongName", getCodecLongName() );
594-
detail::add( dataMap, "profile", getProfile() );
595-
detail::add( dataMap, "profileName", getProfileName() );
596-
detail::add( dataMap, "level", getLevel() );
597-
detail::add( dataMap, "startTimecode", getStartTimecodeString() );
598-
detail::add( dataMap, "width", getWidth() );
599-
detail::add( dataMap, "height", getHeight() );
600-
detail::add( dataMap, "pixelAspectRatio", getSar().num / getSar().den );
601-
detail::add( dataMap, "displayAspectRatio", getDar().num / getDar().den );
602-
detail::add( dataMap, "dtgActiveFormat", getDtgActiveFormat() );
603-
detail::add( dataMap, "colorTransfert", getColorTransfert() );
604-
detail::add( dataMap, "colorspace", getColorspace() );
605-
detail::add( dataMap, "colorRange", getColorRange() );
606-
detail::add( dataMap, "colorPrimaries", getColorPrimaries() );
607-
detail::add( dataMap, "chromaSampleLocation", getChromaSampleLocation() );
608-
detail::add( dataMap, "interlaced ", isInterlaced() );
609-
detail::add( dataMap, "topFieldFirst", isTopFieldFirst() );
610-
detail::add( dataMap, "fieldOrder", getFieldOrder() );
611-
detail::add( dataMap, "timeBase", getTimeBase() );
612-
detail::add( dataMap, "duration", getDuration() );
613-
detail::add( dataMap, "fps", getFps() );
614-
detail::add( dataMap, "nbFrame", getNbFrames() );
615-
detail::add( dataMap, "ticksPerFrame", getTicksPerFrame() );
616-
detail::add( dataMap, "bitRate", getBitRate() );
617-
detail::add( dataMap, "maxBitRate", getMaxBitRate() );
618-
detail::add( dataMap, "minBitRate", getMinBitRate() );
619-
detail::add( dataMap, "gopSize", getGopSize() );
590+
addProperty( dataMap, "streamId", &VideoProperties::getStreamId );
591+
addProperty( dataMap, "codecId", &VideoProperties::getCodecId );
592+
addProperty( dataMap, "codecName", &VideoProperties::getCodecName );
593+
addProperty( dataMap, "codecLongName", &VideoProperties::getCodecLongName );
594+
addProperty( dataMap, "profile", &VideoProperties::getProfile );
595+
addProperty( dataMap, "profileName", &VideoProperties::getProfileName );
596+
addProperty( dataMap, "level", &VideoProperties::getLevel );
597+
addProperty( dataMap, "startTimecode", &VideoProperties::getStartTimecodeString );
598+
addProperty( dataMap, "width", &VideoProperties::getWidth );
599+
addProperty( dataMap, "height", &VideoProperties::getHeight );
600+
addProperty( dataMap, "pixelAspectRatio", &VideoProperties::getSar );
601+
addProperty( dataMap, "displayAspectRatio", &VideoProperties::getDar );
602+
addProperty( dataMap, "dtgActiveFormat", &VideoProperties::getDtgActiveFormat );
603+
addProperty( dataMap, "colorTransfert", &VideoProperties::getColorTransfert );
604+
addProperty( dataMap, "colorspace", &VideoProperties::getColorspace );
605+
addProperty( dataMap, "colorRange", &VideoProperties::getColorRange );
606+
addProperty( dataMap, "colorPrimaries", &VideoProperties::getColorPrimaries );
607+
addProperty( dataMap, "chromaSampleLocation", &VideoProperties::getChromaSampleLocation );
608+
addProperty( dataMap, "interlaced ", &VideoProperties::isInterlaced );
609+
addProperty( dataMap, "topFieldFirst", &VideoProperties::isTopFieldFirst );
610+
addProperty( dataMap, "fieldOrder", &VideoProperties::getFieldOrder );
611+
addProperty( dataMap, "timeBase", &VideoProperties::getTimeBase );
612+
addProperty( dataMap, "duration", &VideoProperties::getDuration );
613+
addProperty( dataMap, "fps", &VideoProperties::getFps );
614+
addProperty( dataMap, "nbFrame", &VideoProperties::getNbFrames );
615+
addProperty( dataMap, "ticksPerFrame", &VideoProperties::getTicksPerFrame );
616+
addProperty( dataMap, "bitRate", &VideoProperties::getBitRate );
617+
addProperty( dataMap, "maxBitRate", &VideoProperties::getMaxBitRate );
618+
addProperty( dataMap, "minBitRate", &VideoProperties::getMinBitRate );
619+
addProperty( dataMap, "gopSize", &VideoProperties::getGopSize );
620620

621621
std::string gop;
622622
for( size_t frameIndex = 0; frameIndex < _gopStructure.size(); ++frameIndex )
@@ -627,8 +627,8 @@ PropertiesMap VideoProperties::getPropertiesAsMap() const
627627
detail::add( dataMap, "gop", gop );
628628
//detail::add( dataMap, "isClosedGop", isClosedGop() );
629629

630-
detail::add( dataMap, "hasBFrames", hasBFrames() );
631-
detail::add( dataMap, "referencesFrames", getReferencesFrames() );
630+
addProperty( dataMap, "hasBFrames", &VideoProperties::hasBFrames );
631+
addProperty( dataMap, "referencesFrames", &VideoProperties::getReferencesFrames );
632632

633633
for( size_t metadataIndex = 0; metadataIndex < _metadatas.size(); ++metadataIndex )
634634
{

src/AvTranscoder/mediaProperty/VideoProperties.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@ class AvExport VideoProperties
9292
*/
9393
void analyseGopStructure( IProgress& progress );
9494

95+
#ifndef SWIG
96+
template<typename T>
97+
void addProperty( PropertiesMap& dataMap, const std::string& key, T (VideoProperties::*getter)(void) const ) const
98+
{
99+
try
100+
{
101+
detail::add( dataMap, key, (this->*getter)() );
102+
}
103+
catch( const std::exception& e )
104+
{
105+
detail::add( dataMap, key, e.what() );
106+
}
107+
}
108+
#endif
109+
95110
private:
96111
const AVFormatContext* _formatContext; ///< Has link (no ownership)
97112
AVCodecContext* _codecContext; ///< Has link (no ownership)

0 commit comments

Comments
 (0)