diff --git a/src/AvTranscoder/properties/FileProperties.cpp b/src/AvTranscoder/properties/FileProperties.cpp index 15b03d61..8cabd289 100644 --- a/src/AvTranscoder/properties/FileProperties.cpp +++ b/src/AvTranscoder/properties/FileProperties.cpp @@ -15,6 +15,7 @@ FileProperties::FileProperties(const InputFile& file) : _file(file) , _formatContext(&file.getFormatContext()) , _avFormatContext(&file.getFormatContext().getAVFormatContext()) + , _streamsProperties() , _videoStreams() , _audioStreams() , _dataStreams() @@ -36,7 +37,12 @@ void FileProperties::extractStreamProperties(IProgress& progress, const EAnalyse const_cast(_file).seekAtFrame(0, AVSEEK_FLAG_BACKWARD); // clear properties - clearStreamProperties(); + _videoStreams.clear(); + _audioStreams.clear(); + _dataStreams.clear(); + _subtitleStreams.clear(); + _attachementStreams.clear(); + _unknownStreams.clear(); // reload properties for(size_t streamIndex = 0; streamIndex < _formatContext->getNbStreams(); ++streamIndex) @@ -86,41 +92,44 @@ void FileProperties::extractStreamProperties(IProgress& progress, const EAnalyse } } + // clear streams + _streamsProperties.clear(); + // once the streams vectors are filled, add their references the base streams vector for(size_t streamIndex = 0; streamIndex < _videoStreams.size(); ++streamIndex) { const size_t videoStreamIndex = _videoStreams.at(streamIndex).getStreamIndex(); - _streams[videoStreamIndex] = &_videoStreams.at(streamIndex); + _streamsProperties[videoStreamIndex] = &_videoStreams.at(streamIndex); } for(size_t streamIndex = 0; streamIndex < _audioStreams.size(); ++streamIndex) { const size_t audioStreamIndex = _audioStreams.at(streamIndex).getStreamIndex(); - _streams[audioStreamIndex] = &_audioStreams.at(streamIndex); + _streamsProperties[audioStreamIndex] = &_audioStreams.at(streamIndex); } for(size_t streamIndex = 0; streamIndex < _dataStreams.size(); ++streamIndex) { const size_t dataStreamIndex = _dataStreams.at(streamIndex).getStreamIndex(); - _streams[dataStreamIndex] = &_dataStreams.at(streamIndex); + _streamsProperties[dataStreamIndex] = &_dataStreams.at(streamIndex); } for(size_t streamIndex = 0; streamIndex < _subtitleStreams.size(); ++streamIndex) { const size_t subtitleStreamIndex = _subtitleStreams.at(streamIndex).getStreamIndex(); - _streams[subtitleStreamIndex] = &_subtitleStreams.at(streamIndex); + _streamsProperties[subtitleStreamIndex] = &_subtitleStreams.at(streamIndex); } for(size_t streamIndex = 0; streamIndex < _attachementStreams.size(); ++streamIndex) { const size_t attachementStreamIndex = _attachementStreams.at(streamIndex).getStreamIndex(); - _streams[attachementStreamIndex] = &_attachementStreams.at(streamIndex); + _streamsProperties[attachementStreamIndex] = &_attachementStreams.at(streamIndex); } for(size_t streamIndex = 0; streamIndex < _unknownStreams.size(); ++streamIndex) { const size_t unknownStreamIndex = _unknownStreams.at(streamIndex).getStreamIndex(); - _streams[unknownStreamIndex] = &_unknownStreams.at(streamIndex); + _streamsProperties[unknownStreamIndex] = &_unknownStreams.at(streamIndex); } // Returns at the beginning of the stream after any deep analysis @@ -216,19 +225,19 @@ size_t FileProperties::getPacketSize() const const avtranscoder::StreamProperties& FileProperties::getStreamPropertiesWithIndex(const size_t streamIndex) const { - avtranscoder::StreamProperties* properties = _streams.find(streamIndex)->second; + avtranscoder::StreamProperties* properties = _streamsProperties.find(streamIndex)->second; if(properties) return *properties; - std::stringstream os; - os << "No stream properties correspond to stream at index "; - os << streamIndex; - throw std::runtime_error(os.str()); + std::stringstream msg; + msg << "No stream properties correspond to stream at index "; + msg << streamIndex; + throw std::runtime_error(msg.str()); } const std::vector FileProperties::getStreamProperties() const { std::vector streams; - for(std::map::const_iterator it = _streams.begin(); it != _streams.end(); ++it) + for(std::map::const_iterator it = _streamsProperties.begin(); it != _streamsProperties.end(); ++it) { streams.push_back(it->second); } @@ -373,18 +382,6 @@ std::string FileProperties::allPropertiesAsJson() const return writer.build(); } -void FileProperties::clearStreamProperties() -{ - _streams.clear(); - - _videoStreams.clear(); - _audioStreams.clear(); - _dataStreams.clear(); - _subtitleStreams.clear(); - _attachementStreams.clear(); - _unknownStreams.clear(); -} - std::ostream& operator<<(std::ostream& flux, const FileProperties& fileProperties) { flux << std::left; diff --git a/src/AvTranscoder/properties/FileProperties.hpp b/src/AvTranscoder/properties/FileProperties.hpp index d926339f..780eb64f 100644 --- a/src/AvTranscoder/properties/FileProperties.hpp +++ b/src/AvTranscoder/properties/FileProperties.hpp @@ -107,15 +107,13 @@ class AvExport FileProperties } #endif - void clearStreamProperties(); ///< Clear all array of stream properties - private: const InputFile& _file; ///< Has link (no ownership) const FormatContext* _formatContext; ///< Has link (no ownership) const AVFormatContext* _avFormatContext; ///< Has link (no ownership) std::map - _streams; ///< Map of properties per stream index (of all types) - only references to the following properties + _streamsProperties; ///< Map of properties per stream index (of all types) - only references to the following properties std::vector _videoStreams; ///< Array of properties per video stream std::vector _audioStreams; ///< Array of properties per audio stream