Skip to content

Commit 129a8d1

Browse files
author
Clement Champetier
committed
AudioProperties: check formatContext/codecContext/codec pointers
1 parent 8df49bd commit 129a8d1

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/AvTranscoder/mediaProperty/AudioProperties.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ namespace avtranscoder
1313

1414
AudioProperties::AudioProperties( const AVFormatContext* formatContext, const size_t index )
1515
: _formatContext( formatContext )
16-
, _codecContext( formatContext->streams[index]->codec )
16+
, _codecContext( NULL )
1717
, _codec( NULL )
1818
, _streamId( index )
1919
{
20+
if( _formatContext )
21+
_codecContext = formatContext->streams[index]->codec;
22+
2023
if( _formatContext && _codecContext )
2124
_codec = avcodec_find_decoder( _codecContext->codec_id );
2225
}
@@ -38,6 +41,9 @@ std::string AudioProperties::getCodecLongName() const
3841

3942
std::string AudioProperties::getSampleFormatName() const
4043
{
44+
if( ! _codecContext )
45+
return "unknown codec context";
46+
4147
const char* fmtName = av_get_sample_fmt_name( _codecContext->sample_fmt );
4248
if( fmtName )
4349
return std::string( fmtName );
@@ -46,6 +52,9 @@ std::string AudioProperties::getSampleFormatName() const
4652

4753
std::string AudioProperties::getSampleFormatLongName() const
4854
{
55+
if( ! _codecContext )
56+
return "unknown codec context";
57+
4958
switch( _codecContext->sample_fmt )
5059
{
5160
case AV_SAMPLE_FMT_NONE:
@@ -78,13 +87,19 @@ std::string AudioProperties::getSampleFormatLongName() const
7887

7988
std::string AudioProperties::getChannelLayout() const
8089
{
90+
if( ! _codecContext )
91+
return "unknown codec context";
92+
8193
char buf1[1024];
8294
av_get_channel_layout_string( buf1, sizeof( buf1 ), -1, _codecContext->channel_layout );
8395
return std::string( buf1 );
8496
}
8597

8698
std::string AudioProperties::getChannelName() const
8799
{
100+
if( ! _codecContext )
101+
return "unknown codec context";
102+
88103
const char* channelName = av_get_channel_name( _codecContext->channel_layout );
89104
if( channelName )
90105
return std::string( channelName );
@@ -93,6 +108,9 @@ std::string AudioProperties::getChannelName() const
93108

94109
std::string AudioProperties::getChannelDescription() const
95110
{
111+
if( ! _codecContext )
112+
return "unknown codec context";
113+
96114
#ifdef FF_RESAMPLE_LIBRARY
97115
const char* channelDescription = av_get_channel_description( _codecContext->channel_layout );
98116
if( channelDescription )

0 commit comments

Comments
 (0)