Skip to content

Commit f041f8c

Browse files
author
Clement Champetier
committed
FileProperties: keep a FormatContext pointer as attribute
1 parent 108b7df commit f041f8c

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

src/AvTranscoder/mediaProperty/FileProperties.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,72 +6,73 @@ namespace avtranscoder
66
{
77

88
FileProperties::FileProperties( const FormatContext& formatContext )
9-
: _formatContext( &formatContext.getAVFormatContext() )
9+
: _formatContext( &formatContext )
10+
, _avFormatContext( &formatContext.getAVFormatContext() )
1011
, _videoStreams()
1112
, _audioStreams()
1213
, _dataStreams()
1314
, _subtitleStreams()
1415
, _attachementStreams()
1516
, _unknownStreams()
1617
{
17-
if( _formatContext )
18-
detail::fillMetadataDictionnary( _formatContext->metadata, _metadatas );
18+
if( _avFormatContext )
19+
detail::fillMetadataDictionnary( _avFormatContext->metadata, _metadatas );
1920
}
2021

2122
std::string FileProperties::getFilename() const
2223
{
23-
if( ! _formatContext || ! _formatContext->filename )
24+
if( ! _avFormatContext || ! _avFormatContext->filename )
2425
throw std::runtime_error( "unknown file name" );
25-
return _formatContext->filename;
26+
return _avFormatContext->filename;
2627
}
2728

2829
std::string FileProperties::getFormatName() const
2930
{
30-
if( ! _formatContext || ! _formatContext->iformat || ! _formatContext->iformat->name )
31+
if( ! _avFormatContext || ! _avFormatContext->iformat || ! _avFormatContext->iformat->name )
3132
throw std::runtime_error( "unknown format name");
32-
return _formatContext->iformat->name;
33+
return _avFormatContext->iformat->name;
3334
}
3435

3536
std::string FileProperties::getFormatLongName() const
3637
{
37-
if( ! _formatContext || ! _formatContext->iformat || ! _formatContext->iformat->long_name )
38+
if( ! _avFormatContext || ! _avFormatContext->iformat || ! _avFormatContext->iformat->long_name )
3839
throw std::runtime_error( "unknown format long name");
39-
return _formatContext->iformat->long_name;
40+
return _avFormatContext->iformat->long_name;
4041
}
4142

4243
size_t FileProperties::getProgramsCount() const
4344
{
44-
if( ! _formatContext )
45+
if( ! _avFormatContext )
4546
throw std::runtime_error( "unknown format context" );
46-
return _formatContext->nb_programs;
47+
return _avFormatContext->nb_programs;
4748
}
4849

4950
double FileProperties::getStartTime() const
5051
{
51-
if( ! _formatContext )
52+
if( ! _avFormatContext )
5253
throw std::runtime_error( "unknown format context" );
53-
return 1.0 * (unsigned int)_formatContext->start_time / AV_TIME_BASE;
54+
return 1.0 * (unsigned int)_avFormatContext->start_time / AV_TIME_BASE;
5455
}
5556

5657
double FileProperties::getDuration() const
5758
{
58-
if( ! _formatContext )
59+
if( ! _avFormatContext )
5960
throw std::runtime_error( "unknown format context" );
60-
return 1.0 * _formatContext->duration / AV_TIME_BASE;
61+
return 1.0 * _avFormatContext->duration / AV_TIME_BASE;
6162
}
6263

6364
size_t FileProperties::getBitRate() const
6465
{
65-
if( ! _formatContext )
66+
if( ! _avFormatContext )
6667
throw std::runtime_error( "unknown format context" );
67-
return _formatContext->bit_rate;
68+
return _avFormatContext->bit_rate;
6869
}
6970

7071
size_t FileProperties::getPacketSize() const
7172
{
72-
if( ! _formatContext )
73+
if( ! _avFormatContext )
7374
throw std::runtime_error( "unknown format context" );
74-
return _formatContext->packet_size;
75+
return _avFormatContext->packet_size;
7576
}
7677

7778
VideoProperties& FileProperties::getVideoPropertiesWithStreamIndex( const size_t streamIndex )
@@ -124,9 +125,9 @@ const avtranscoder::AudioProperties& FileProperties::getAudioPropertiesWithStrea
124125

125126
size_t FileProperties::getNbStreams() const
126127
{
127-
if( ! _formatContext )
128+
if( ! _avFormatContext )
128129
throw std::runtime_error( "unknown format context" );
129-
return _formatContext->nb_streams;
130+
return _avFormatContext->nb_streams;
130131
}
131132

132133
PropertyVector FileProperties::getPropertiesAsVector() const

src/AvTranscoder/mediaProperty/FileProperties.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class AvExport FileProperties
4242
size_t getNbAttachementStreams() const { return _attachementStreams.size(); }
4343
size_t getNbUnknownStreams() const { return _unknownStreams.size(); }
4444

45+
const FormatContext& getFormatContext() { return *_formatContext; }
46+
4547
//@{
4648
// @brief Get the properties with the indicated stream index
4749
avtranscoder::VideoProperties& getVideoPropertiesWithStreamIndex( const size_t streamIndex );
@@ -59,7 +61,7 @@ class AvExport FileProperties
5961
//@}
6062

6163
#ifndef SWIG
62-
const AVFormatContext& getAVFormatContext() { return *_formatContext; }
64+
const AVFormatContext& getAVFormatContext() { return *_avFormatContext; }
6365

6466
const avtranscoder::VideoProperties& getVideoPropertiesWithStreamIndex( const size_t streamIndex ) const;
6567
const avtranscoder::AudioProperties& getAudioPropertiesWithStreamIndex( const size_t streamIndex ) const;
@@ -93,7 +95,8 @@ class AvExport FileProperties
9395
#endif
9496

9597
private:
96-
const AVFormatContext* _formatContext; ///< Has link (no ownership)
98+
const FormatContext* _formatContext; ///< Has link (no ownership)
99+
const AVFormatContext* _avFormatContext; ///< Has link (no ownership)
97100

98101
std::vector< VideoProperties > _videoStreams; ///< Array of properties per video stream
99102
std::vector< AudioProperties > _audioStreams; ///< Array of properties per audio stream

0 commit comments

Comments
 (0)