From 294aa0342aa99f8fa057be490b79633eb1943976 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 7 Nov 2016 15:53:41 +0100 Subject: [PATCH 1/3] FileProperties: fix InputFile analysis * When manually analyse an InputFile, the previous StreamProperties created are used to access the codec (if decoding is needed). * So in that cases, the _streams vector should be cleared after the new analysis. --- .../properties/FileProperties.cpp | 22 ++++++++----------- .../properties/FileProperties.hpp | 2 -- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/AvTranscoder/properties/FileProperties.cpp b/src/AvTranscoder/properties/FileProperties.cpp index 15b03d61..b1c5572d 100644 --- a/src/AvTranscoder/properties/FileProperties.cpp +++ b/src/AvTranscoder/properties/FileProperties.cpp @@ -36,7 +36,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,6 +91,9 @@ void FileProperties::extractStreamProperties(IProgress& progress, const EAnalyse } } + // clear streams + _streams.clear(); + // once the streams vectors are filled, add their references the base streams vector for(size_t streamIndex = 0; streamIndex < _videoStreams.size(); ++streamIndex) { @@ -373,18 +381,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..932f3b96 100644 --- a/src/AvTranscoder/properties/FileProperties.hpp +++ b/src/AvTranscoder/properties/FileProperties.hpp @@ -107,8 +107,6 @@ 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) From bc67a2fcd27ef0f9d67a4cc324718e5ce2768c18 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 7 Nov 2016 20:18:04 +0100 Subject: [PATCH 2/3] FileProperties: rename attribute _streams to _streamsProperties --- .../properties/FileProperties.cpp | 19 ++++++++++--------- .../properties/FileProperties.hpp | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/AvTranscoder/properties/FileProperties.cpp b/src/AvTranscoder/properties/FileProperties.cpp index b1c5572d..3fbd940f 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() @@ -92,43 +93,43 @@ void FileProperties::extractStreamProperties(IProgress& progress, const EAnalyse } // clear streams - _streams.clear(); + _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 @@ -224,7 +225,7 @@ 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; @@ -236,7 +237,7 @@ const avtranscoder::StreamProperties& FileProperties::getStreamPropertiesWithInd 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); } diff --git a/src/AvTranscoder/properties/FileProperties.hpp b/src/AvTranscoder/properties/FileProperties.hpp index 932f3b96..780eb64f 100644 --- a/src/AvTranscoder/properties/FileProperties.hpp +++ b/src/AvTranscoder/properties/FileProperties.hpp @@ -113,7 +113,7 @@ class AvExport FileProperties 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 From 499097abf23e2aec6dacfc0cc770bc4fba52ffdd Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Mon, 7 Nov 2016 20:19:34 +0100 Subject: [PATCH 3/3] FileProperties: fix message log when cannot getStreamPropertiesWithIndex The local variable should not be called "os" when logging. --- src/AvTranscoder/properties/FileProperties.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/AvTranscoder/properties/FileProperties.cpp b/src/AvTranscoder/properties/FileProperties.cpp index 3fbd940f..8cabd289 100644 --- a/src/AvTranscoder/properties/FileProperties.cpp +++ b/src/AvTranscoder/properties/FileProperties.cpp @@ -228,10 +228,10 @@ const avtranscoder::StreamProperties& FileProperties::getStreamPropertiesWithInd 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