Skip to content

Commit b866c83

Browse files
author
Clement Champetier
committed
VideoProperties: all getters throw exception when can't access data
1 parent 079f14d commit b866c83

File tree

1 file changed

+35
-32
lines changed

1 file changed

+35
-32
lines changed

src/AvTranscoder/mediaProperty/VideoProperties.cpp

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,51 +51,54 @@ VideoProperties::VideoProperties( const FormatContext& formatContext, const size
5151

5252
std::string VideoProperties::getCodecName() const
5353
{
54-
if( _codecContext && _codec )
55-
{
56-
if( _codec->capabilities & CODEC_CAP_TRUNCATED )
57-
_codecContext->flags|= CODEC_FLAG_TRUNCATED;
54+
if( ! _codecContext || ! _codec )
55+
throw std::runtime_error( "unknown codec" );
5856

59-
if( _codec->name )
60-
return std::string( _codec->name );
61-
}
62-
return "unknown codec";
57+
if( _codec->capabilities & CODEC_CAP_TRUNCATED )
58+
_codecContext->flags|= CODEC_FLAG_TRUNCATED;
59+
60+
if( ! _codec->name )
61+
throw std::runtime_error( "unknown codec name" );
62+
63+
return std::string( _codec->name );
6364
}
6465

6566
std::string VideoProperties::getCodecLongName() const
6667
{
67-
if( _codecContext && _codec )
68-
{
69-
if( _codec->capabilities & CODEC_CAP_TRUNCATED )
70-
_codecContext->flags|= CODEC_FLAG_TRUNCATED;
68+
if( ! _codecContext || ! _codec )
69+
throw std::runtime_error( "unknown codec" );
7170

72-
if( _codec->long_name )
73-
return std::string( _codec->long_name );
74-
}
75-
return "unknown codec";
71+
if( _codec->capabilities & CODEC_CAP_TRUNCATED )
72+
_codecContext->flags|= CODEC_FLAG_TRUNCATED;
73+
74+
if( ! _codec->long_name )
75+
throw std::runtime_error( "unknown codec long name" );
76+
77+
return std::string( _codec->long_name );
7678
}
7779

7880
std::string VideoProperties::getProfileName() const
7981
{
80-
if( _codecContext && _codec )
82+
if( ! _codecContext || ! _codec )
83+
throw std::runtime_error( "unknown codec" );
84+
85+
if( _codec->capabilities & CODEC_CAP_TRUNCATED )
86+
_codecContext->flags|= CODEC_FLAG_TRUNCATED;
87+
88+
if( _codecContext->profile != -99 )
8189
{
82-
if( _codec->capabilities & CODEC_CAP_TRUNCATED )
83-
_codecContext->flags|= CODEC_FLAG_TRUNCATED;
90+
const char* profile = NULL;
91+
if( ( profile = av_get_profile_name( _codec, _codecContext->profile ) ) == NULL )
92+
throw std::runtime_error( "unknown codec profile" );
8493

85-
if( _codecContext->profile != -99 )
86-
{
87-
const char* profile = NULL;
88-
if( ( profile = av_get_profile_name( _codec, _codecContext->profile ) ) != NULL )
89-
return std::string( profile );
90-
}
94+
return std::string( profile );
9195
}
92-
return "unknown profile";
9396
}
9497

9598
std::string VideoProperties::getColorTransfert() const
9699
{
97100
if( ! _codecContext )
98-
return "unknown codec context";
101+
throw std::runtime_error( "unknown codec context" );
99102

100103
switch( _codecContext->color_trc )
101104
{
@@ -159,7 +162,7 @@ std::string VideoProperties::getColorTransfert() const
159162
std::string VideoProperties::getColorspace() const
160163
{
161164
if( ! _codecContext )
162-
return "unknown codec context";
165+
throw std::runtime_error( "unknown codec context" );
163166

164167
switch( _codecContext->colorspace )
165168
{
@@ -204,7 +207,7 @@ std::string VideoProperties::getColorspace() const
204207
std::string VideoProperties::getColorRange() const
205208
{
206209
if( ! _codecContext )
207-
return "unknown codec context";
210+
throw std::runtime_error( "unknown codec context" );
208211

209212
switch( _codecContext->color_range )
210213
{
@@ -224,7 +227,7 @@ std::string VideoProperties::getColorRange() const
224227
std::string VideoProperties::getColorPrimaries() const
225228
{
226229
if( ! _codecContext )
227-
return "unknown codec context";
230+
throw std::runtime_error( "unknown codec context" );
228231

229232
switch( _codecContext->color_primaries )
230233
{
@@ -258,7 +261,7 @@ std::string VideoProperties::getColorPrimaries() const
258261
std::string VideoProperties::getChromaSampleLocation() const
259262
{
260263
if( ! _codecContext )
261-
return "unknown codec context";
264+
throw std::runtime_error( "unknown codec context" );
262265

263266
switch( _codecContext->chroma_sample_location )
264267
{
@@ -286,7 +289,7 @@ std::string VideoProperties::getChromaSampleLocation() const
286289
std::string VideoProperties::getFieldOrder() const
287290
{
288291
if( ! _codecContext )
289-
return "unknown codec context";
292+
throw std::runtime_error( "unknown codec context" );
290293

291294
switch( _codecContext->field_order )
292295
{

0 commit comments

Comments
 (0)