diff --git a/src/AvTranscoder/mediaProperty/FileProperties.cpp b/src/AvTranscoder/mediaProperty/FileProperties.cpp index ed595bf2..de278187 100644 --- a/src/AvTranscoder/mediaProperty/FileProperties.cpp +++ b/src/AvTranscoder/mediaProperty/FileProperties.cpp @@ -82,22 +82,22 @@ void FileProperties::extractStreamProperties( IProgress& progress, const EAnalys // once the streams vectors are filled, add their references the base streams vector for( size_t streamIndex = 0; streamIndex < _videoStreams.size(); ++streamIndex ) - _streams.push_back( &_videoStreams.at( streamIndex ) ); + _streams[ _videoStreams.at( streamIndex ).getStreamIndex() ] = &_videoStreams.at( streamIndex ); for( size_t streamIndex = 0; streamIndex < _audioStreams.size(); ++ streamIndex ) - _streams.push_back( &_audioStreams.at(streamIndex) ); + _streams[ _audioStreams.at(streamIndex).getStreamIndex() ] = &_audioStreams.at(streamIndex); for( size_t streamIndex = 0; streamIndex < _dataStreams.size(); ++ streamIndex ) - _streams.push_back( &_dataStreams.at(streamIndex) ); + _streams[ _dataStreams.at(streamIndex).getStreamIndex() ] = &_dataStreams.at(streamIndex); for( size_t streamIndex = 0; streamIndex < _subtitleStreams.size(); ++ streamIndex ) - _streams.push_back( &_subtitleStreams.at(streamIndex) ); + _streams[ _subtitleStreams.at(streamIndex).getStreamIndex() ] = &_subtitleStreams.at(streamIndex); for( size_t streamIndex = 0; streamIndex < _attachementStreams.size(); ++ streamIndex ) - _streams.push_back( &_attachementStreams.at(streamIndex) ); + _streams[ _attachementStreams.at(streamIndex).getStreamIndex() ] = &_attachementStreams.at(streamIndex); for( size_t streamIndex = 0; streamIndex < _unknownStreams.size(); ++ streamIndex ) - _streams.push_back( &_unknownStreams.at(streamIndex) ); + _streams[ _unknownStreams.at(streamIndex).getStreamIndex() ] = &_unknownStreams.at(streamIndex); // if the analysis level has decoded some streams parts, return at the beginning if( level > eAnalyseLevelHeader ) @@ -162,11 +162,9 @@ size_t FileProperties::getPacketSize() const const avtranscoder::StreamProperties& FileProperties::getStreamPropertiesWithIndex( const size_t streamIndex ) const { - for( std::vector< StreamProperties* >::const_iterator it = _streams.begin(); it != _streams.end(); ++it ) - { - if( (*it)->getStreamIndex() == streamIndex ) - return *(*it); - } + avtranscoder::StreamProperties* properties = _streams.find( streamIndex )->second; + if( properties ) + return *properties; std::stringstream os; os << "No stream properties correspond to stream at index "; os << streamIndex; diff --git a/src/AvTranscoder/mediaProperty/FileProperties.hpp b/src/AvTranscoder/mediaProperty/FileProperties.hpp index 6ee440c1..e90c3ab0 100644 --- a/src/AvTranscoder/mediaProperty/FileProperties.hpp +++ b/src/AvTranscoder/mediaProperty/FileProperties.hpp @@ -16,6 +16,7 @@ #include #include +#include namespace avtranscoder { @@ -61,6 +62,7 @@ class AvExport FileProperties //@{ // @brief Get the properties at the indicated stream index + // @throws A runtime error if the streamIndex does not match any stream const avtranscoder::StreamProperties& getStreamPropertiesWithIndex( const size_t streamIndex ) const; //@} @@ -102,7 +104,8 @@ class AvExport FileProperties const FormatContext* _formatContext; ///< Has link (no ownership) const AVFormatContext* _avFormatContext; ///< Has link (no ownership) - std::vector< StreamProperties* > _streams; ///< Array of properties per stream (of all types) - only references to the following properties + std::map< size_t, StreamProperties* > _streams; ///< Map of properties per stream index (of all types) - only references to the following properties + std::vector< VideoProperties > _videoStreams; ///< Array of properties per video stream std::vector< AudioProperties > _audioStreams; ///< Array of properties per audio stream std::vector< DataProperties > _dataStreams; ///< Array of properties per data stream