Skip to content

Commit cdb849f

Browse files
author
Clement Champetier
committed
FileProperties: add array of properties per stream (of all types)
* It containes only references to the other properties (video, audio...). * Get the properties at the indicated stream index with only one function.
1 parent 44595a0 commit cdb849f

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

src/AvTranscoder/mediaProperty/FileProperties.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <AvTranscoder/progress/NoDisplayProgress.hpp>
44

55
#include <stdexcept>
6+
#include <sstream>
67

78
namespace avtranscoder
89
{
@@ -40,36 +41,42 @@ void FileProperties::extractStreamProperties( IProgress& progress, const EAnalys
4041
{
4142
VideoProperties properties( *_formatContext, streamIndex, progress, level );
4243
_videoStreams.push_back( properties );
44+
_streams.push_back( &_videoStreams.back() );
4345
break;
4446
}
4547
case AVMEDIA_TYPE_AUDIO:
4648
{
4749
AudioProperties properties( *_formatContext, streamIndex );
4850
_audioStreams.push_back( properties );
51+
_streams.push_back( &_audioStreams.back() );
4952
break;
5053
}
5154
case AVMEDIA_TYPE_DATA:
5255
{
5356
DataProperties properties( *_formatContext, streamIndex );
5457
_dataStreams.push_back( properties );
58+
_streams.push_back( &_dataStreams.back() );
5559
break;
5660
}
5761
case AVMEDIA_TYPE_SUBTITLE:
5862
{
5963
SubtitleProperties properties( *_formatContext, streamIndex );
6064
_subtitleStreams.push_back( properties );
65+
_streams.push_back( &_subtitleStreams.back() );
6166
break;
6267
}
6368
case AVMEDIA_TYPE_ATTACHMENT:
6469
{
6570
AttachementProperties properties( *_formatContext, streamIndex );
6671
_attachementStreams.push_back( properties );
72+
_streams.push_back( &_attachementStreams.back() );
6773
break;
6874
}
6975
case AVMEDIA_TYPE_UNKNOWN:
7076
{
7177
UnknownProperties properties( *_formatContext, streamIndex );
7278
_unknownStreams.push_back( properties );
79+
_streams.push_back( &_unknownStreams.back() );
7380
break;
7481
}
7582
case AVMEDIA_TYPE_NB:
@@ -140,28 +147,17 @@ size_t FileProperties::getPacketSize() const
140147
return _avFormatContext->packet_size;
141148
}
142149

143-
const avtranscoder::VideoProperties& FileProperties::getVideoPropertiesWithStreamIndex( const size_t streamIndex ) const
150+
const avtranscoder::StreamProperties& FileProperties::getStreamPropertiesWithIndex( const size_t streamIndex ) const
144151
{
145-
for( std::vector< VideoProperties >::const_iterator it = _videoStreams.begin(); it != _videoStreams.end(); ++it )
152+
for( std::vector< StreamProperties* >::const_iterator it = _streams.begin(); it != _streams.end(); ++it )
146153
{
147-
if( it->getStreamIndex() == streamIndex )
148-
return *it;
154+
if( (*it)->getStreamIndex() == streamIndex )
155+
return *(*it);
149156
}
150-
std::string msg( "no video properties correspond to stream at index " );
151-
msg += streamIndex;
152-
throw std::runtime_error( msg );
153-
}
154-
155-
const avtranscoder::AudioProperties& FileProperties::getAudioPropertiesWithStreamIndex( const size_t streamIndex ) const
156-
{
157-
for( std::vector< AudioProperties >::const_iterator it = _audioStreams.begin(); it != _audioStreams.end(); ++it )
158-
{
159-
if( it->getStreamIndex() == streamIndex )
160-
return *it;
161-
}
162-
std::string msg( "no audio properties correspond to stream at index " );
163-
msg += streamIndex;
164-
throw std::runtime_error( msg );
157+
std::stringstream os;
158+
os << "No stream properties correspond to stream at index ";
159+
os << streamIndex;
160+
throw std::runtime_error( os.str() );
165161
}
166162

167163
size_t FileProperties::getNbStreams() const
@@ -202,6 +198,8 @@ PropertyVector FileProperties::getPropertiesAsVector() const
202198

203199
void FileProperties::clearStreamProperties()
204200
{
201+
_streams.clear();
202+
205203
_videoStreams.clear();
206204
_audioStreams.clear();
207205
_dataStreams.clear();

src/AvTranscoder/mediaProperty/FileProperties.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <AvTranscoder/file/FormatContext.hpp>
77
#include <AvTranscoder/progress/IProgress.hpp>
88

9+
#include <AvTranscoder/mediaProperty/StreamProperties.hpp>
910
#include <AvTranscoder/mediaProperty/VideoProperties.hpp>
1011
#include <AvTranscoder/mediaProperty/AudioProperties.hpp>
1112
#include <AvTranscoder/mediaProperty/DataProperties.hpp>
@@ -59,9 +60,8 @@ class AvExport FileProperties
5960
const FormatContext& getFormatContext() { return *_formatContext; }
6061

6162
//@{
62-
// @brief Get the properties with the indicated stream index
63-
const avtranscoder::VideoProperties& getVideoPropertiesWithStreamIndex( const size_t streamIndex ) const;
64-
const avtranscoder::AudioProperties& getAudioPropertiesWithStreamIndex( const size_t streamIndex ) const;
63+
// @brief Get the properties at the indicated stream index
64+
const avtranscoder::StreamProperties& getStreamPropertiesWithIndex( const size_t streamIndex ) const;
6565
//@}
6666

6767
//@{
@@ -102,6 +102,7 @@ class AvExport FileProperties
102102
const FormatContext* _formatContext; ///< Has link (no ownership)
103103
const AVFormatContext* _avFormatContext; ///< Has link (no ownership)
104104

105+
std::vector< StreamProperties* > _streams; ///< Array of properties per stream (of all types) - only references to the following properties
105106
std::vector< VideoProperties > _videoStreams; ///< Array of properties per video stream
106107
std::vector< AudioProperties > _audioStreams; ///< Array of properties per audio stream
107108
std::vector< DataProperties > _dataStreams; ///< Array of properties per data stream

src/AvTranscoder/transcoder/Transcoder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include <limits>
77
#include <algorithm>
8-
#include <sstream>
98

109
namespace avtranscoder
1110
{
@@ -375,18 +374,19 @@ InputFile* Transcoder::addInputFile( const std::string& filename, const size_t s
375374

376375
ProfileLoader::Profile Transcoder::getProfileFromFile( InputFile& inputFile, const size_t streamIndex )
377376
{
377+
const StreamProperties* streamProperties = &inputFile.getProperties().getStreamPropertiesWithIndex( streamIndex );
378378
const VideoProperties* videoProperties = NULL;
379379
const AudioProperties* audioProperties = NULL;
380380
switch( inputFile.getStream( streamIndex ).getStreamType() )
381381
{
382382
case AVMEDIA_TYPE_VIDEO:
383383
{
384-
videoProperties = &inputFile.getProperties().getVideoPropertiesWithStreamIndex( streamIndex );
384+
videoProperties = dynamic_cast<const VideoProperties*>( streamProperties );
385385
break;
386386
}
387387
case AVMEDIA_TYPE_AUDIO:
388388
{
389-
audioProperties = &inputFile.getProperties().getAudioPropertiesWithStreamIndex( streamIndex );
389+
audioProperties = dynamic_cast<const AudioProperties*>( streamProperties );
390390
break;
391391
}
392392
default:

0 commit comments

Comments
 (0)