Skip to content

Commit c7c0c56

Browse files
author
Clement Champetier
committed
AudioProperties: add private function to refactore try/catch of getPropertiesAsMap
1 parent 19354a1 commit c7c0c56

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

src/AvTranscoder/mediaProperty/AudioProperties.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -199,22 +199,22 @@ PropertiesMap AudioProperties::getPropertiesAsMap() const
199199
{
200200
PropertiesMap dataMap;
201201

202-
detail::add( dataMap, "streamId", getStreamId() );
203-
detail::add( dataMap, "codecId", getCodecId() );
204-
detail::add( dataMap, "codecName", getCodecName() );
205-
detail::add( dataMap, "codecLongName", getCodecLongName() );
206-
detail::add( dataMap, "sampleFormatName", getSampleFormatName() );
207-
detail::add( dataMap, "sampleFormatLongName", getSampleFormatLongName() );
208-
detail::add( dataMap, "sampleRate", getSampleRate() );
209-
detail::add( dataMap, "bitRate", getBitRate() );
210-
detail::add( dataMap, "nbSamples", getNbSamples() );
211-
detail::add( dataMap, "channels", getChannels() );
212-
detail::add( dataMap, "channelLayout", getChannelLayout() );
213-
detail::add( dataMap, "channelName", getChannelName() );
214-
detail::add( dataMap, "channelDescription", getChannelDescription() );
215-
detail::add( dataMap, "ticksPerFrame", getTicksPerFrame() );
216-
detail::add( dataMap, "timeBase", getTimeBase() );
217-
detail::add( dataMap, "duration", getDuration() );
202+
addProperty( dataMap, "streamId", &AudioProperties::getStreamId );
203+
addProperty( dataMap, "codecId", &AudioProperties::getCodecId );
204+
addProperty( dataMap, "codecName", &AudioProperties::getCodecName );
205+
addProperty( dataMap, "codecLongName", &AudioProperties::getCodecLongName );
206+
addProperty( dataMap, "sampleFormatName", &AudioProperties::getSampleFormatName );
207+
addProperty( dataMap, "sampleFormatLongName", &AudioProperties::getSampleFormatLongName );
208+
addProperty( dataMap, "sampleRate", &AudioProperties::getSampleRate );
209+
addProperty( dataMap, "bitRate", &AudioProperties::getBitRate );
210+
addProperty( dataMap, "nbSamples", &AudioProperties::getNbSamples );
211+
addProperty( dataMap, "channels", &AudioProperties::getChannels );
212+
addProperty( dataMap, "channelLayout", &AudioProperties::getChannelLayout );
213+
addProperty( dataMap, "channelName", &AudioProperties::getChannelName );
214+
addProperty( dataMap, "channelDescription", &AudioProperties::getChannelDescription );
215+
addProperty( dataMap, "ticksPerFrame", &AudioProperties::getTicksPerFrame );
216+
addProperty( dataMap, "timeBase", &AudioProperties::getTimeBase );
217+
addProperty( dataMap, "duration", &AudioProperties::getDuration );
218218

219219
for( size_t metadataIndex = 0; metadataIndex < _metadatas.size(); ++metadataIndex )
220220
{

src/AvTranscoder/mediaProperty/AudioProperties.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ class AvExport AudioProperties
4444

4545
PropertiesMap getPropertiesAsMap() const; ///< Return all audio properties as a map (name of property: value)
4646

47+
private:
48+
#ifndef SWIG
49+
template<typename T>
50+
void addProperty( PropertiesMap& dataMap, const std::string& key, T (AudioProperties::*getter)(void) const ) const
51+
{
52+
try
53+
{
54+
detail::add( dataMap, key, (this->*getter)() );
55+
}
56+
catch( const std::exception& e )
57+
{
58+
detail::add( dataMap, key, e.what() );
59+
}
60+
}
61+
#endif
62+
4763
private:
4864
const AVFormatContext* _formatContext; ///< Has link (no ownership)
4965
AVCodecContext* _codecContext; ///< Has link (no ownership)

0 commit comments

Comments
 (0)