Skip to content

Commit 9fbb444

Browse files
author
Clement Champetier
committed
AudioProperties: all getters throw exception when can't access data
1 parent b866c83 commit 9fbb444

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

src/AvTranscoder/mediaProperty/AudioProperties.cpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,33 +38,34 @@ size_t AudioProperties::getStreamId() const
3838

3939
std::string AudioProperties::getCodecName() const
4040
{
41-
if( _codec && _codec->name )
42-
return std::string( _codec->name );
43-
return "unknown codec";
41+
if( ! _codec || ! _codec->name )
42+
throw std::runtime_error( "unknown codec name" );
43+
return std::string( _codec->name );
4444
}
4545

4646
std::string AudioProperties::getCodecLongName() const
4747
{
48-
if( _codec && _codec->long_name )
49-
return std::string( _codec->long_name );
50-
return "unknown codec";
48+
if( ! _codec || ! _codec->long_name )
49+
throw std::runtime_error( "unknown codec long name" );
50+
return std::string( _codec->long_name );
5151
}
5252

5353
std::string AudioProperties::getSampleFormatName() const
5454
{
5555
if( ! _codecContext )
56-
return "unknown codec context";
56+
throw std::runtime_error( "unknown codec context" );
5757

5858
const char* fmtName = av_get_sample_fmt_name( _codecContext->sample_fmt );
59-
if( fmtName )
60-
return std::string( fmtName );
61-
return "unknown sample format";
59+
if( ! fmtName )
60+
throw std::runtime_error( "unknown sample format" );
61+
62+
return std::string( fmtName );
6263
}
6364

6465
std::string AudioProperties::getSampleFormatLongName() const
6566
{
6667
if( ! _codecContext )
67-
return "unknown codec context";
68+
throw std::runtime_error( "unknown codec context" );
6869

6970
switch( _codecContext->sample_fmt )
7071
{
@@ -99,7 +100,7 @@ std::string AudioProperties::getSampleFormatLongName() const
99100
std::string AudioProperties::getChannelLayout() const
100101
{
101102
if( ! _codecContext )
102-
return "unknown codec context";
103+
throw std::runtime_error( "unknown codec context" );
103104

104105
char buf1[1024];
105106
av_get_channel_layout_string( buf1, sizeof( buf1 ), -1, _codecContext->channel_layout );
@@ -109,26 +110,27 @@ std::string AudioProperties::getChannelLayout() const
109110
std::string AudioProperties::getChannelName() const
110111
{
111112
if( ! _codecContext )
112-
return "unknown codec context";
113+
throw std::runtime_error( "unknown codec context" );
113114

114115
const char* channelName = av_get_channel_name( _codecContext->channel_layout );
115-
if( channelName )
116-
return std::string( channelName );
117-
return "unknown channel name";
116+
if( ! channelName )
117+
throw std::runtime_error( "unknown channel name" );
118+
119+
return std::string( channelName );
118120
}
119121

120122
std::string AudioProperties::getChannelDescription() const
121123
{
122124
if( ! _codecContext )
123-
return "unknown codec context";
125+
throw std::runtime_error( "unknown codec context" );
124126

125-
#ifdef FF_RESAMPLE_LIBRARY
127+
#ifdef AVTRANSCODER_FFMPEG_DEPENDENCY
126128
const char* channelDescription = av_get_channel_description( _codecContext->channel_layout );
127-
if( channelDescription )
128-
return std::string( channelDescription );
129-
return "unknown channel description";
129+
if( ! channelDescription )
130+
throw std::runtime_error( "unknown channel description" );
131+
return std::string( channelDescription );
130132
#else
131-
return "can't access channel description";
133+
throw std::runtime_error( "can't access channel description" );
132134
#endif
133135
}
134136

0 commit comments

Comments
 (0)