Skip to content

Commit 8df49bd

Browse files
author
Clement Champetier
committed
AudioProperties: get AVCodec attribute
This removes multi call to avcodec_find_decoder().
1 parent 2918b40 commit 8df49bd

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/AvTranscoder/mediaProperty/AudioProperties.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,25 @@ namespace avtranscoder
1414
AudioProperties::AudioProperties( const AVFormatContext* formatContext, const size_t index )
1515
: _formatContext( formatContext )
1616
, _codecContext( formatContext->streams[index]->codec )
17+
, _codec( NULL )
1718
, _streamId( index )
18-
{}
19+
{
20+
if( _formatContext && _codecContext )
21+
_codec = avcodec_find_decoder( _codecContext->codec_id );
22+
}
1923

2024
std::string AudioProperties::getCodecName() const
2125
{
22-
AVCodec* codec = avcodec_find_decoder( _codecContext->codec_id );
23-
if( codec != NULL )
24-
return std::string( codec->name );
26+
if( _codec && _codec->name )
27+
return std::string( _codec->name );
2528
else
2629
return "unknown codec";
2730
}
2831

2932
std::string AudioProperties::getCodecLongName() const
3033
{
31-
AVCodec* codec = avcodec_find_decoder( _codecContext->codec_id );
32-
if( codec != NULL )
33-
return std::string( codec->long_name );
34+
if( _codec && _codec->long_name )
35+
return std::string( _codec->long_name );
3436
return "unknown codec";
3537
}
3638

src/AvTranscoder/mediaProperty/AudioProperties.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class AvExport AudioProperties
4343
private:
4444
const AVFormatContext* _formatContext; ///< Has link (no ownership)
4545
AVCodecContext* _codecContext; ///< Has link (no ownership)
46+
AVCodec* _codec; ///< Has link (no ownership)
4647

4748
size_t _streamId;
4849
MetadatasMap _metadatas;

0 commit comments

Comments
 (0)