Skip to content

Commit 9bbbe6e

Browse files
author
Clement Champetier
committed
properties: moved getCodecId/Name/LongName methods to based class of stream
1 parent bb9eb9b commit 9bbbe6e

File tree

6 files changed

+61
-96
lines changed

6 files changed

+61
-96
lines changed

src/AvTranscoder/mediaProperty/AudioProperties.cpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,6 @@ namespace avtranscoder
1616
AudioProperties::AudioProperties( const FormatContext& formatContext, const size_t index )
1717
: StreamProperties( formatContext, index )
1818
{
19-
if( _formatContext )
20-
_codecContext = _formatContext->streams[index]->codec;
21-
22-
if( _formatContext && _codecContext )
23-
_codec = avcodec_find_decoder( _codecContext->codec_id );
24-
}
25-
26-
std::string AudioProperties::getCodecName() const
27-
{
28-
if( ! _codec || ! _codec->name )
29-
throw std::runtime_error( "unknown codec name" );
30-
return std::string( _codec->name );
31-
}
32-
33-
std::string AudioProperties::getCodecLongName() const
34-
{
35-
if( ! _codec || ! _codec->long_name )
36-
throw std::runtime_error( "unknown codec long name" );
37-
return std::string( _codec->long_name );
3819
}
3920

4021
std::string AudioProperties::getSampleFormatName() const
@@ -121,13 +102,6 @@ std::string AudioProperties::getChannelDescription() const
121102
#endif
122103
}
123104

124-
size_t AudioProperties::getCodecId() const
125-
{
126-
if( ! _codecContext )
127-
throw std::runtime_error( "unknown codec context" );
128-
return _codecContext->codec_id;
129-
}
130-
131105
size_t AudioProperties::getSampleRate() const
132106
{
133107
if( ! _codecContext )
@@ -181,9 +155,6 @@ PropertyVector AudioProperties::getPropertiesAsVector() const
181155
PropertyVector basedProperty = StreamProperties::getPropertiesAsVector();
182156
data.insert( data.begin(), basedProperty.begin(), basedProperty.end() );
183157

184-
addProperty( data, "codecId", &AudioProperties::getCodecId );
185-
addProperty( data, "codecName", &AudioProperties::getCodecName );
186-
addProperty( data, "codecLongName", &AudioProperties::getCodecLongName );
187158
addProperty( data, "sampleFormatName", &AudioProperties::getSampleFormatName );
188159
addProperty( data, "sampleFormatLongName", &AudioProperties::getSampleFormatLongName );
189160
addProperty( data, "sampleRate", &AudioProperties::getSampleRate );

src/AvTranscoder/mediaProperty/AudioProperties.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@ class AvExport AudioProperties : public StreamProperties
1313
public:
1414
AudioProperties( const FormatContext& formatContext, const size_t index );
1515

16-
std::string getCodecName() const;
17-
std::string getCodecLongName() const;
1816
std::string getSampleFormatName() const;
1917
std::string getSampleFormatLongName() const;
2018
std::string getChannelLayout() const;
2119
std::string getChannelName() const;
2220
std::string getChannelDescription() const;
2321

24-
size_t getCodecId() const;
2522
size_t getSampleRate() const;
2623
size_t getChannels() const;
2724
size_t getBitRate() const; ///< 0 if unknown
@@ -50,10 +47,6 @@ class AvExport AudioProperties : public StreamProperties
5047
}
5148
}
5249
#endif
53-
54-
private:
55-
AVCodecContext* _codecContext; ///< Has link (no ownership)
56-
AVCodec* _codec; ///< Has link (no ownership)
5750
};
5851

5952
}

src/AvTranscoder/mediaProperty/StreamProperties.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,26 @@ namespace avtranscoder
77

88
StreamProperties::StreamProperties( const FormatContext& formatContext, const size_t index )
99
: _formatContext( &formatContext.getAVFormatContext() )
10+
, _codecContext( NULL )
11+
, _codec( NULL )
1012
, _streamIndex( index )
1113
{
1214
if( _formatContext )
1315
detail::fillMetadataDictionnary( _formatContext->streams[index]->metadata, _metadatas );
16+
17+
if( _formatContext )
18+
{
19+
if( _streamIndex > _formatContext->nb_streams )
20+
{
21+
std::stringstream ss;
22+
ss << "Stream at index " << _streamIndex << " does not exist.";
23+
throw std::runtime_error( ss.str() );
24+
}
25+
_codecContext = _formatContext->streams[_streamIndex]->codec;
26+
}
27+
28+
if( _formatContext && _codecContext )
29+
_codec = avcodec_find_decoder( _codecContext->codec_id );
1430
}
1531

1632
StreamProperties::~StreamProperties()
@@ -50,6 +66,41 @@ AVMediaType StreamProperties::getStreamType() const
5066
return _formatContext->streams[_streamIndex]->codec->codec_type;
5167
}
5268

69+
size_t StreamProperties::getCodecId() const
70+
{
71+
if( ! _codecContext )
72+
throw std::runtime_error( "unknown codec context" );
73+
return _codecContext->codec_id;
74+
}
75+
76+
std::string StreamProperties::getCodecName() const
77+
{
78+
if( ! _codecContext || ! _codec )
79+
throw std::runtime_error( "unknown codec" );
80+
81+
if( _codec->capabilities & CODEC_CAP_TRUNCATED )
82+
_codecContext->flags |= CODEC_FLAG_TRUNCATED;
83+
84+
if( ! _codec->name )
85+
throw std::runtime_error( "unknown codec name" );
86+
87+
return std::string( _codec->name );
88+
}
89+
90+
std::string StreamProperties::getCodecLongName() const
91+
{
92+
if( ! _codecContext || ! _codec )
93+
throw std::runtime_error( "unknown codec" );
94+
95+
if( _codec->capabilities & CODEC_CAP_TRUNCATED )
96+
_codecContext->flags |= CODEC_FLAG_TRUNCATED;
97+
98+
if( ! _codec->long_name )
99+
throw std::runtime_error( "unknown codec long name" );
100+
101+
return std::string( _codec->long_name );
102+
}
103+
53104
PropertyVector StreamProperties::getPropertiesAsVector() const
54105
{
55106
PropertyVector data;
@@ -58,6 +109,9 @@ PropertyVector StreamProperties::getPropertiesAsVector() const
58109
addProperty( data, "streamIndex", &StreamProperties::getStreamIndex );
59110
addProperty( data, "timeBase", &StreamProperties::getTimeBase );
60111
addProperty( data, "duration", &StreamProperties::getDuration );
112+
addProperty( data, "codecId", &StreamProperties::getCodecId );
113+
addProperty( data, "codecName", &StreamProperties::getCodecName );
114+
addProperty( data, "codecLongName", &StreamProperties::getCodecLongName );
61115

62116
for( size_t metadataIndex = 0; metadataIndex < _metadatas.size(); ++metadataIndex )
63117
{

src/AvTranscoder/mediaProperty/StreamProperties.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ class AvExport StreamProperties
2020
Rational getTimeBase() const;
2121
float getDuration() const; ///< in seconds
2222
AVMediaType getStreamType() const;
23+
24+
size_t getCodecId() const;
25+
std::string getCodecName() const;
26+
std::string getCodecLongName() const;
27+
2328
const PropertyVector& getMetadatas() const { return _metadatas; }
2429

2530
#ifndef SWIG
@@ -47,6 +52,8 @@ class AvExport StreamProperties
4752

4853
protected:
4954
const AVFormatContext* _formatContext; ///< Has link (no ownership)
55+
AVCodecContext* _codecContext; ///< Has link (no ownership)
56+
AVCodec* _codec; ///< Has link (no ownership)
5057

5158
size_t _streamIndex;
5259
PropertyVector _metadatas;

src/AvTranscoder/mediaProperty/VideoProperties.cpp

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,12 @@ namespace avtranscoder
1717

1818
VideoProperties::VideoProperties( const FormatContext& formatContext, const size_t index, IProgress& progress, const EAnalyseLevel level )
1919
: StreamProperties( formatContext, index )
20-
, _codecContext( NULL )
21-
, _codec( NULL )
2220
, _pixelProperties()
2321
, _isInterlaced( false )
2422
, _isTopFieldFirst( false )
2523
, _gopStructure()
2624
, _firstGopTimeCode( -1 )
2725
{
28-
if( _formatContext )
29-
{
30-
if( _streamIndex > _formatContext->nb_streams )
31-
{
32-
std::stringstream ss;
33-
ss << "video stream at index " << _streamIndex << " does not exist";
34-
throw std::runtime_error( ss.str() );
35-
}
36-
_codecContext = _formatContext->streams[_streamIndex]->codec;
37-
}
38-
39-
if( _formatContext && _codecContext )
40-
_codec = avcodec_find_decoder( _codecContext->codec_id );
41-
4226
if( _codecContext )
4327
{
4428
_pixelProperties = PixelProperties( _codecContext->pix_fmt );
@@ -49,34 +33,6 @@ VideoProperties::VideoProperties( const FormatContext& formatContext, const size
4933
analyseGopStructure( progress );
5034
}
5135

52-
std::string VideoProperties::getCodecName() const
53-
{
54-
if( ! _codecContext || ! _codec )
55-
throw std::runtime_error( "unknown codec" );
56-
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 );
64-
}
65-
66-
std::string VideoProperties::getCodecLongName() const
67-
{
68-
if( ! _codecContext || ! _codec )
69-
throw std::runtime_error( "unknown codec" );
70-
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 );
78-
}
79-
8036
std::string VideoProperties::getProfileName() const
8137
{
8238
if( ! _codecContext || ! _codec )
@@ -365,13 +321,6 @@ Rational VideoProperties::getDar() const
365321
return dar;
366322
}
367323

368-
size_t VideoProperties::getCodecId() const
369-
{
370-
if( ! _codecContext )
371-
throw std::runtime_error( "unknown codec context" );
372-
return _codecContext->codec_id;
373-
}
374-
375324
size_t VideoProperties::getBitRate() const
376325
{
377326
if( ! _codecContext )
@@ -606,9 +555,6 @@ PropertyVector VideoProperties::getPropertiesAsVector() const
606555
PropertyVector basedProperty = StreamProperties::getPropertiesAsVector();
607556
data.insert( data.begin(), basedProperty.begin(), basedProperty.end() );
608557

609-
addProperty( data, "codecId", &VideoProperties::getCodecId );
610-
addProperty( data, "codecName", &VideoProperties::getCodecName );
611-
addProperty( data, "codecLongName", &VideoProperties::getCodecLongName );
612558
addProperty( data, "profile", &VideoProperties::getProfile );
613559
addProperty( data, "profileName", &VideoProperties::getProfileName );
614560
addProperty( data, "level", &VideoProperties::getLevel );

src/AvTranscoder/mediaProperty/VideoProperties.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ class AvExport VideoProperties : public StreamProperties
2323
public:
2424
VideoProperties( const FormatContext& formatContext, const size_t index, IProgress& progress, const EAnalyseLevel level = eAnalyseLevelFirstGop );
2525

26-
std::string getCodecName() const;
27-
std::string getCodecLongName() const;
2826
std::string getProfileName() const;
2927
std::string getColorTransfert() const;
3028
std::string getColorspace() const;
@@ -41,7 +39,6 @@ class AvExport VideoProperties : public StreamProperties
4139
Rational getSar() const; // sample/pixel aspect ratio
4240
Rational getDar() const; // display aspect ratio
4341

44-
size_t getCodecId() const;
4542
size_t getBitRate() const; ///< in bits/s
4643
size_t getMaxBitRate() const;
4744
size_t getMinBitRate() const;
@@ -106,9 +103,6 @@ class AvExport VideoProperties : public StreamProperties
106103
#endif
107104

108105
private:
109-
AVCodecContext* _codecContext; ///< Has link (no ownership)
110-
AVCodec* _codec; ///< Has link (no ownership)
111-
112106
PixelProperties _pixelProperties;
113107
//@{
114108
// Can acces these data when analyse first gop

0 commit comments

Comments
 (0)