Skip to content

Commit 6295036

Browse files
author
Clement Champetier
committed
FileProperties: add private function to refactore try/catch of getPropertiesAsMap
1 parent f1cbae8 commit 6295036

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

src/AvTranscoder/mediaProperty/FileProperties.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,16 @@ PropertiesMap FileProperties::getPropertiesAsMap() const
133133
{
134134
PropertiesMap dataMap;
135135

136-
detail::add( dataMap, "filename", getFilename() );
137-
detail::add( dataMap, "formatName", getFormatName() );
138-
detail::add( dataMap, "formatLongName", getFormatLongName() );
139-
140-
detail::add( dataMap, "startTime", getStartTime() );
141-
detail::add( dataMap, "duration", getDuration() );
142-
detail::add( dataMap, "bitrate", getBitRate() );
143-
detail::add( dataMap, "numberOfStreams", getNbStreams() );
144-
detail::add( dataMap, "numberOfPrograms", getProgramsCount() );
136+
addProperty( dataMap, "filename", &FileProperties::getFilename );
137+
addProperty( dataMap, "formatName", &FileProperties::getFormatName );
138+
addProperty( dataMap, "formatLongName", &FileProperties::getFormatLongName );
139+
140+
addProperty( dataMap, "startTime", &FileProperties::getStartTime );
141+
addProperty( dataMap, "duration", &FileProperties::getDuration );
142+
addProperty( dataMap, "bitrate", &FileProperties::getBitRate );
143+
addProperty( dataMap, "numberOfStreams", &FileProperties::getNbStreams );
144+
addProperty( dataMap, "numberOfPrograms", &FileProperties::getProgramsCount );
145+
145146
detail::add( dataMap, "numberOfVideoStreams", getNbVideoStreams() );
146147
detail::add( dataMap, "numberOfAudioStreams", getNbAudioStreams() );
147148
detail::add( dataMap, "numberOfDataStreams", getNbDataStreams() );

src/AvTranscoder/mediaProperty/FileProperties.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,22 @@ class AvExport FileProperties
7676

7777
void clearStreamProperties(); ///< Clear all array of stream properties
7878

79+
private:
80+
#ifndef SWIG
81+
template<typename T>
82+
void addProperty( PropertiesMap& dataMap, const std::string& key, T (FileProperties::*getter)(void) const ) const
83+
{
84+
try
85+
{
86+
detail::add( dataMap, key, (this->*getter)() );
87+
}
88+
catch( const std::exception& e )
89+
{
90+
detail::add( dataMap, key, e.what() );
91+
}
92+
}
93+
#endif
94+
7995
private:
8096
const AVFormatContext* _formatContext; ///< Has link (no ownership)
8197

0 commit comments

Comments
 (0)