From 9c1948f619d8744955408a3008c50f0a1a5f30b9 Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Tue, 19 Jan 2016 18:21:43 +0100 Subject: [PATCH 1/2] properties: overload operator<< in each class * Removed print files in properties folder. * Fix #215 --- app/avMeta/avMeta.cpp | 2 - src/AvTranscoder/file/InputFile.cpp | 47 +++++ src/AvTranscoder/file/InputFile.hpp | 4 + .../properties/AttachementProperties.cpp | 20 +++ .../properties/AttachementProperties.hpp | 4 + .../properties/AudioProperties.cpp | 16 ++ .../properties/AudioProperties.hpp | 4 + .../properties/DataProperties.cpp | 15 ++ .../properties/DataProperties.hpp | 4 + .../properties/FileProperties.cpp | 15 ++ .../properties/FileProperties.hpp | 4 + .../properties/StreamProperties.cpp | 15 ++ .../properties/StreamProperties.hpp | 4 + .../properties/SubtitleProperties.cpp | 20 +++ .../properties/SubtitleProperties.hpp | 4 + .../properties/UnknownProperties.cpp | 20 +++ .../properties/UnknownProperties.hpp | 4 + .../properties/VideoProperties.cpp | 15 ++ .../properties/VideoProperties.hpp | 4 + src/AvTranscoder/properties/print.cpp | 167 ------------------ src/AvTranscoder/properties/print.hpp | 28 --- src/AvTranscoder/properties/util.hpp | 7 + src/AvTranscoder/reader/AudioReader.cpp | 1 - src/AvTranscoder/reader/IReader.cpp | 2 - src/AvTranscoder/reader/VideoReader.cpp | 1 - 25 files changed, 226 insertions(+), 201 deletions(-) create mode 100644 src/AvTranscoder/properties/AttachementProperties.cpp create mode 100644 src/AvTranscoder/properties/SubtitleProperties.cpp create mode 100644 src/AvTranscoder/properties/UnknownProperties.cpp delete mode 100644 src/AvTranscoder/properties/print.cpp delete mode 100644 src/AvTranscoder/properties/print.hpp diff --git a/app/avMeta/avMeta.cpp b/app/avMeta/avMeta.cpp index f9439244..9aa326ca 100644 --- a/app/avMeta/avMeta.cpp +++ b/app/avMeta/avMeta.cpp @@ -1,6 +1,4 @@ #include -#include - #include #include diff --git a/src/AvTranscoder/file/InputFile.cpp b/src/AvTranscoder/file/InputFile.cpp index 074fc57c..433a7baa 100644 --- a/src/AvTranscoder/file/InputFile.cpp +++ b/src/AvTranscoder/file/InputFile.cpp @@ -203,4 +203,51 @@ void InputFile::setupUnwrapping(const ProfileLoader::Profile& profile) } } } + +std::ostream& operator<<(std::ostream& flux, const InputFile& input) +{ + // wrapper + flux << input.getProperties(); + + // video streams + for(size_t videoStreamIndex = 0; videoStreamIndex < input.getProperties().getNbVideoStreams(); ++videoStreamIndex) + { + flux << input.getProperties().getVideoProperties().at(videoStreamIndex); + } + + // audio streams + for(size_t audioStreamIndex = 0; audioStreamIndex < input.getProperties().getNbAudioStreams(); ++audioStreamIndex) + { + flux << input.getProperties().getAudioProperties().at(audioStreamIndex); + } + + // data streams + for(size_t dataStreamIndex = 0; dataStreamIndex < input.getProperties().getNbDataStreams(); ++dataStreamIndex) + { + flux << input.getProperties().getDataProperties().at(dataStreamIndex); + } + + // subtitle streams + for(size_t subtitleStreamIndex = 0; subtitleStreamIndex < input.getProperties().getNbSubtitleStreams(); + ++subtitleStreamIndex) + { + flux << input.getProperties().getSubtitleProperties().at(subtitleStreamIndex); + } + + // attachement streams + for(size_t attachementStreamIndex = 0; attachementStreamIndex < input.getProperties().getNbAttachementStreams(); + ++attachementStreamIndex) + { + flux << input.getProperties().getAttachementProperties().at(attachementStreamIndex); + } + + // unknown streams + for(size_t unknownStreamIndex = 0; unknownStreamIndex < input.getProperties().getNbUnknownStreams(); + ++unknownStreamIndex) + { + flux << input.getProperties().getUnknownProperties().at(unknownStreamIndex); + } + + return flux; +} } \ No newline at end of file diff --git a/src/AvTranscoder/file/InputFile.hpp b/src/AvTranscoder/file/InputFile.hpp index 97846ef4..396ebfff 100644 --- a/src/AvTranscoder/file/InputFile.hpp +++ b/src/AvTranscoder/file/InputFile.hpp @@ -125,6 +125,10 @@ class AvExport InputFile std::string _filename; std::vector _inputStreams; ///< Has ownership }; + +#ifndef SWIG +AvExport std::ostream& operator<<(std::ostream& flux, const InputFile& input); +#endif } #endif diff --git a/src/AvTranscoder/properties/AttachementProperties.cpp b/src/AvTranscoder/properties/AttachementProperties.cpp new file mode 100644 index 00000000..0d71a7f1 --- /dev/null +++ b/src/AvTranscoder/properties/AttachementProperties.cpp @@ -0,0 +1,20 @@ +#include "AttachementProperties.hpp" + +#include + +namespace avtranscoder +{ + +std::ostream& operator<<(std::ostream& flux, const AttachementProperties& attachementProperties) +{ + flux << detail::separator << " Attachement stream " << detail::separator << std::endl; + + PropertyVector properties = attachementProperties.asVector(); + for(PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it) + { + flux << std::setw(detail::keyWidth) << it->first << ": " << it->second << std::endl; + } + + return flux; +} +} diff --git a/src/AvTranscoder/properties/AttachementProperties.hpp b/src/AvTranscoder/properties/AttachementProperties.hpp index eaba5ef1..3c1d736a 100644 --- a/src/AvTranscoder/properties/AttachementProperties.hpp +++ b/src/AvTranscoder/properties/AttachementProperties.hpp @@ -14,6 +14,10 @@ class AvExport AttachementProperties : public StreamProperties { } }; + +#ifndef SWIG +AvExport std::ostream& operator<<(std::ostream& flux, const AttachementProperties& attachementProperties); +#endif } #endif diff --git a/src/AvTranscoder/properties/AudioProperties.cpp b/src/AvTranscoder/properties/AudioProperties.cpp index 93db9bd3..4b196a6e 100644 --- a/src/AvTranscoder/properties/AudioProperties.cpp +++ b/src/AvTranscoder/properties/AudioProperties.cpp @@ -1,5 +1,7 @@ #include "AudioProperties.hpp" +#include + extern "C" { #include #include @@ -168,4 +170,18 @@ PropertyVector AudioProperties::asVector() const return data; } + +std::ostream& operator<<(std::ostream& flux, const AudioProperties& audioProperties) +{ + flux << std::left; + flux << detail::separator << " Audio stream " << detail::separator << std::endl; + + PropertyVector properties = audioProperties.asVector(); + for(PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it) + { + flux << std::setw(detail::keyWidth) << it->first << ": " << it->second << std::endl; + } + + return flux; +} } diff --git a/src/AvTranscoder/properties/AudioProperties.hpp b/src/AvTranscoder/properties/AudioProperties.hpp index e8ce9945..dfa140d2 100644 --- a/src/AvTranscoder/properties/AudioProperties.hpp +++ b/src/AvTranscoder/properties/AudioProperties.hpp @@ -48,6 +48,10 @@ class AvExport AudioProperties : public StreamProperties } #endif }; + +#ifndef SWIG +AvExport std::ostream& operator<<(std::ostream& flux, const AudioProperties& audioProperties); +#endif } #endif diff --git a/src/AvTranscoder/properties/DataProperties.cpp b/src/AvTranscoder/properties/DataProperties.cpp index d1b66812..cba9cdeb 100644 --- a/src/AvTranscoder/properties/DataProperties.cpp +++ b/src/AvTranscoder/properties/DataProperties.cpp @@ -1,5 +1,7 @@ #include "DataProperties.hpp" +#include + extern "C" { #include } @@ -77,4 +79,17 @@ void DataProperties::detectAncillaryData() break; } } + +std::ostream& operator<<(std::ostream& flux, const DataProperties& dataProperties) +{ + flux << detail::separator << " Data stream " << detail::separator << std::endl; + + PropertyVector properties = dataProperties.asVector(); + for(PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it) + { + flux << std::setw(detail::keyWidth) << it->first << ": " << it->second << std::endl; + } + + return flux; +} } diff --git a/src/AvTranscoder/properties/DataProperties.hpp b/src/AvTranscoder/properties/DataProperties.hpp index 919663cb..6da7a04a 100644 --- a/src/AvTranscoder/properties/DataProperties.hpp +++ b/src/AvTranscoder/properties/DataProperties.hpp @@ -17,6 +17,10 @@ class AvExport DataProperties : public StreamProperties private: void detectAncillaryData(); }; + +#ifndef SWIG +AvExport std::ostream& operator<<(std::ostream& flux, const DataProperties& dataProperties); +#endif } #endif diff --git a/src/AvTranscoder/properties/FileProperties.cpp b/src/AvTranscoder/properties/FileProperties.cpp index 1463c20a..139fd6e6 100644 --- a/src/AvTranscoder/properties/FileProperties.cpp +++ b/src/AvTranscoder/properties/FileProperties.cpp @@ -1,5 +1,6 @@ #include "FileProperties.hpp" +#include #include #include @@ -341,4 +342,18 @@ void FileProperties::clearStreamProperties() _attachementStreams.clear(); _unknownStreams.clear(); } + +std::ostream& operator<<(std::ostream& flux, const FileProperties& fileProperties) +{ + flux << std::left; + flux << detail::separator << " Wrapper " << detail::separator << std::endl; + + PropertyVector properties = fileProperties.asVector(); + for(PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it) + { + flux << std::setw(detail::keyWidth) << it->first << ": " << it->second << std::endl; + } + + return flux; +} } diff --git a/src/AvTranscoder/properties/FileProperties.hpp b/src/AvTranscoder/properties/FileProperties.hpp index 6fca21ad..dd1a5b86 100644 --- a/src/AvTranscoder/properties/FileProperties.hpp +++ b/src/AvTranscoder/properties/FileProperties.hpp @@ -120,6 +120,10 @@ class AvExport FileProperties PropertyVector _metadatas; }; + +#ifndef SWIG +AvExport std::ostream& operator<<(std::ostream& flux, const FileProperties& fileProperties); +#endif } #endif diff --git a/src/AvTranscoder/properties/StreamProperties.cpp b/src/AvTranscoder/properties/StreamProperties.cpp index e2f67430..d7bf6c41 100644 --- a/src/AvTranscoder/properties/StreamProperties.cpp +++ b/src/AvTranscoder/properties/StreamProperties.cpp @@ -1,5 +1,6 @@ #include "StreamProperties.hpp" +#include #include #include @@ -138,4 +139,18 @@ std::string StreamProperties::asJson() const writer << std::make_pair(it->first.c_str(), it->second.c_str()); return writer.build(); } + +std::ostream& operator<<(std::ostream& flux, const StreamProperties& streamProperties) +{ + flux << std::left; + flux << detail::separator << " Stream " << detail::separator << std::endl; + + PropertyVector properties = streamProperties.asVector(); + for(PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it) + { + flux << std::setw(detail::keyWidth) << it->first << ": " << it->second << std::endl; + } + + return flux; +} } diff --git a/src/AvTranscoder/properties/StreamProperties.hpp b/src/AvTranscoder/properties/StreamProperties.hpp index 98e54868..8fd1ddd0 100644 --- a/src/AvTranscoder/properties/StreamProperties.hpp +++ b/src/AvTranscoder/properties/StreamProperties.hpp @@ -59,6 +59,10 @@ class AvExport StreamProperties size_t _streamIndex; PropertyVector _metadatas; }; + +#ifndef SWIG +AvExport std::ostream& operator<<(std::ostream& flux, const StreamProperties& streamProperties); +#endif } #endif diff --git a/src/AvTranscoder/properties/SubtitleProperties.cpp b/src/AvTranscoder/properties/SubtitleProperties.cpp new file mode 100644 index 00000000..8242b7a4 --- /dev/null +++ b/src/AvTranscoder/properties/SubtitleProperties.cpp @@ -0,0 +1,20 @@ +#include "SubtitleProperties.hpp" + +#include + +namespace avtranscoder +{ + +std::ostream& operator<<(std::ostream& flux, const SubtitleProperties& subtitleProperties) +{ + flux << detail::separator << " Subtitle stream " << detail::separator << std::endl; + + PropertyVector properties = subtitleProperties.asVector(); + for(PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it) + { + flux << std::setw(detail::keyWidth) << it->first << ": " << it->second << std::endl; + } + + return flux; +} +} diff --git a/src/AvTranscoder/properties/SubtitleProperties.hpp b/src/AvTranscoder/properties/SubtitleProperties.hpp index ec97f361..2fe4ae90 100644 --- a/src/AvTranscoder/properties/SubtitleProperties.hpp +++ b/src/AvTranscoder/properties/SubtitleProperties.hpp @@ -14,6 +14,10 @@ class AvExport SubtitleProperties : public StreamProperties { } }; + +#ifndef SWIG +AvExport std::ostream& operator<<(std::ostream& flux, const SubtitleProperties& subtitleProperties); +#endif } #endif diff --git a/src/AvTranscoder/properties/UnknownProperties.cpp b/src/AvTranscoder/properties/UnknownProperties.cpp new file mode 100644 index 00000000..85518ea2 --- /dev/null +++ b/src/AvTranscoder/properties/UnknownProperties.cpp @@ -0,0 +1,20 @@ +#include "UnknownProperties.hpp" + +#include + +namespace avtranscoder +{ + +std::ostream& operator<<(std::ostream& flux, const UnknownProperties& unknownProperties) +{ + flux << detail::separator << " Unknown stream " << detail::separator << std::endl; + + PropertyVector properties = unknownProperties.asVector(); + for(PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it) + { + flux << std::setw(detail::keyWidth) << it->first << ": " << it->second << std::endl; + } + + return flux; +} +} diff --git a/src/AvTranscoder/properties/UnknownProperties.hpp b/src/AvTranscoder/properties/UnknownProperties.hpp index 540ec05a..2a8dc6fd 100644 --- a/src/AvTranscoder/properties/UnknownProperties.hpp +++ b/src/AvTranscoder/properties/UnknownProperties.hpp @@ -14,6 +14,10 @@ class AvExport UnknownProperties : public StreamProperties { } }; + +#ifndef SWIG +AvExport std::ostream& operator<<(std::ostream& flux, const UnknownProperties& unknownProperties); +#endif } #endif diff --git a/src/AvTranscoder/properties/VideoProperties.cpp b/src/AvTranscoder/properties/VideoProperties.cpp index 9cb22523..9613a194 100644 --- a/src/AvTranscoder/properties/VideoProperties.cpp +++ b/src/AvTranscoder/properties/VideoProperties.cpp @@ -1,5 +1,6 @@ #include "VideoProperties.hpp" +#include #include extern "C" { @@ -602,4 +603,18 @@ PropertyVector VideoProperties::asVector() const return data; } + +std::ostream& operator<<(std::ostream& flux, const VideoProperties& videoProperties) +{ + flux << std::left; + flux << detail::separator << " Video stream " << detail::separator << std::endl; + + PropertyVector properties = videoProperties.asVector(); + for(PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it) + { + flux << std::setw(detail::keyWidth) << it->first << ": " << it->second << std::endl; + } + + return flux; +} } diff --git a/src/AvTranscoder/properties/VideoProperties.hpp b/src/AvTranscoder/properties/VideoProperties.hpp index 781cb6d4..541ac6bd 100644 --- a/src/AvTranscoder/properties/VideoProperties.hpp +++ b/src/AvTranscoder/properties/VideoProperties.hpp @@ -118,6 +118,10 @@ class AvExport VideoProperties : public StreamProperties */ int64_t _firstGopTimeCode; }; + +#ifndef SWIG +AvExport std::ostream& operator<<(std::ostream& flux, const StreamProperties& streamProperties); +#endif } #endif diff --git a/src/AvTranscoder/properties/print.cpp b/src/AvTranscoder/properties/print.cpp deleted file mode 100644 index 1f94fad8..00000000 --- a/src/AvTranscoder/properties/print.cpp +++ /dev/null @@ -1,167 +0,0 @@ -#include "print.hpp" - -#include -#include -#include - -namespace avtranscoder -{ - -static const size_t keyWidth = 32; -static const std::string separator = "===================="; - -std::ostream& operator<<(std::ostream& flux, const FileProperties& fileProperties) -{ - flux << std::left; - flux << separator << " Wrapper " << separator << std::endl; - - PropertyVector properties = fileProperties.asVector(); - for(PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it) - { - flux << std::setw(keyWidth) << it->first << ": " << it->second << std::endl; - } - - return flux; -} - -std::ostream& operator<<(std::ostream& flux, const StreamProperties& streamProperties) -{ - flux << std::left; - flux << separator << " Stream " << separator << std::endl; - - PropertyVector properties = streamProperties.asVector(); - for(PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it) - { - flux << std::setw(keyWidth) << it->first << ": " << it->second << std::endl; - } - - return flux; -} - -std::ostream& operator<<(std::ostream& flux, const VideoProperties& videoProperties) -{ - flux << std::left; - flux << separator << " Video stream " << separator << std::endl; - - PropertyVector properties = videoProperties.asVector(); - for(PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it) - { - flux << std::setw(keyWidth) << it->first << ": " << it->second << std::endl; - } - - return flux; -} - -std::ostream& operator<<(std::ostream& flux, const AudioProperties& audioProperties) -{ - flux << std::left; - flux << separator << " Audio stream " << separator << std::endl; - - PropertyVector properties = audioProperties.asVector(); - for(PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it) - { - flux << std::setw(keyWidth) << it->first << ": " << it->second << std::endl; - } - - return flux; -} - -std::ostream& operator<<(std::ostream& flux, const DataProperties& dataProperties) -{ - flux << separator << " Data stream " << separator << std::endl; - - PropertyVector properties = dataProperties.asVector(); - for(PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it) - { - flux << std::setw(keyWidth) << it->first << ": " << it->second << std::endl; - } - - return flux; -} - -std::ostream& operator<<(std::ostream& flux, const SubtitleProperties& subtitleProperties) -{ - flux << separator << " Subtitle stream " << separator << std::endl; - - PropertyVector properties = subtitleProperties.asVector(); - for(PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it) - { - flux << std::setw(keyWidth) << it->first << ": " << it->second << std::endl; - } - - return flux; -} - -std::ostream& operator<<(std::ostream& flux, const AttachementProperties& attachementProperties) -{ - flux << separator << " Attachement stream " << separator << std::endl; - - PropertyVector properties = attachementProperties.asVector(); - for(PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it) - { - flux << std::setw(keyWidth) << it->first << ": " << it->second << std::endl; - } - - return flux; -} - -std::ostream& operator<<(std::ostream& flux, const UnknownProperties& unknownProperties) -{ - flux << separator << " Unknown stream " << separator << std::endl; - - PropertyVector properties = unknownProperties.asVector(); - for(PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it) - { - flux << std::setw(keyWidth) << it->first << ": " << it->second << std::endl; - } - - return flux; -} - -std::ostream& operator<<(std::ostream& flux, const InputFile& input) -{ - // wrapper - flux << input.getProperties(); - - // video streams - for(size_t videoStreamIndex = 0; videoStreamIndex < input.getProperties().getNbVideoStreams(); ++videoStreamIndex) - { - flux << input.getProperties().getVideoProperties().at(videoStreamIndex); - } - - // audio streams - for(size_t audioStreamIndex = 0; audioStreamIndex < input.getProperties().getNbAudioStreams(); ++audioStreamIndex) - { - flux << input.getProperties().getAudioProperties().at(audioStreamIndex); - } - - // data streams - for(size_t dataStreamIndex = 0; dataStreamIndex < input.getProperties().getNbDataStreams(); ++dataStreamIndex) - { - flux << input.getProperties().getDataProperties().at(dataStreamIndex); - } - - // subtitle streams - for(size_t subtitleStreamIndex = 0; subtitleStreamIndex < input.getProperties().getNbSubtitleStreams(); - ++subtitleStreamIndex) - { - flux << input.getProperties().getSubtitleProperties().at(subtitleStreamIndex); - } - - // attachement streams - for(size_t attachementStreamIndex = 0; attachementStreamIndex < input.getProperties().getNbAttachementStreams(); - ++attachementStreamIndex) - { - flux << input.getProperties().getAttachementProperties().at(attachementStreamIndex); - } - - // unknown streams - for(size_t unknownStreamIndex = 0; unknownStreamIndex < input.getProperties().getNbUnknownStreams(); - ++unknownStreamIndex) - { - flux << input.getProperties().getUnknownProperties().at(unknownStreamIndex); - } - - return flux; -} -} diff --git a/src/AvTranscoder/properties/print.hpp b/src/AvTranscoder/properties/print.hpp deleted file mode 100644 index 2c33fb23..00000000 --- a/src/AvTranscoder/properties/print.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _AV_TRANSCODER_PRINT_HPP_ -#define _AV_TRANSCODER_PRINT_HPP_ - -#include - -namespace avtranscoder -{ - -AvExport std::ostream& operator<<(std::ostream& flux, const FileProperties& fileProperties); - -AvExport std::ostream& operator<<(std::ostream& flux, const StreamProperties& streamProperties); - -AvExport std::ostream& operator<<(std::ostream& flux, const VideoProperties& videoProperties); - -AvExport std::ostream& operator<<(std::ostream& flux, const AudioProperties& audioProperties); - -AvExport std::ostream& operator<<(std::ostream& flux, const DataProperties& dataProperties); - -AvExport std::ostream& operator<<(std::ostream& flux, const SubtitleProperties& subtitleProperties); - -AvExport std::ostream& operator<<(std::ostream& flux, const AttachementProperties& attachementProperties); - -AvExport std::ostream& operator<<(std::ostream& flux, const UnknownProperties& unknownProperties); - -AvExport std::ostream& operator<<(std::ostream& flux, const InputFile& input); -} - -#endif diff --git a/src/AvTranscoder/properties/util.hpp b/src/AvTranscoder/properties/util.hpp index bf86dfd0..4087c09d 100644 --- a/src/AvTranscoder/properties/util.hpp +++ b/src/AvTranscoder/properties/util.hpp @@ -12,6 +12,7 @@ extern "C" { #include #include #include +#include namespace avtranscoder { @@ -25,6 +26,12 @@ typedef std::map PropertyMap; namespace detail { +/** + * Variables to print properties class to the terminal. + */ +const size_t keyWidth = 32; +const std::string separator = "===================="; + /** * If cannot access the property, get this value. */ diff --git a/src/AvTranscoder/reader/AudioReader.cpp b/src/AvTranscoder/reader/AudioReader.cpp index c1962824..2ae9efb9 100644 --- a/src/AvTranscoder/reader/AudioReader.cpp +++ b/src/AvTranscoder/reader/AudioReader.cpp @@ -4,7 +4,6 @@ #include #include #include -#include namespace avtranscoder { diff --git a/src/AvTranscoder/reader/IReader.cpp b/src/AvTranscoder/reader/IReader.cpp index 55bde9b3..59075218 100644 --- a/src/AvTranscoder/reader/IReader.cpp +++ b/src/AvTranscoder/reader/IReader.cpp @@ -1,7 +1,5 @@ #include "IReader.hpp" -#include - #include namespace avtranscoder diff --git a/src/AvTranscoder/reader/VideoReader.cpp b/src/AvTranscoder/reader/VideoReader.cpp index 46ea7e65..35e94ce0 100644 --- a/src/AvTranscoder/reader/VideoReader.cpp +++ b/src/AvTranscoder/reader/VideoReader.cpp @@ -4,7 +4,6 @@ #include #include #include -#include namespace avtranscoder { From dac41e85a103231b7d12361a960cbcfcfbb4362c Mon Sep 17 00:00:00 2001 From: Clement Champetier Date: Wed, 20 Jan 2016 10:21:03 +0100 Subject: [PATCH 2/2] properties: added fillVector method to avoid copy of the vector Fix #140 --- src/AvTranscoder/properties/AudioProperties.cpp | 7 +++---- src/AvTranscoder/properties/AudioProperties.hpp | 2 +- src/AvTranscoder/properties/FileProperties.cpp | 6 +++++- src/AvTranscoder/properties/FileProperties.hpp | 1 + src/AvTranscoder/properties/PixelProperties.cpp | 6 +++++- src/AvTranscoder/properties/PixelProperties.hpp | 1 + src/AvTranscoder/properties/StreamProperties.cpp | 6 +++++- src/AvTranscoder/properties/StreamProperties.hpp | 7 ++++--- src/AvTranscoder/properties/VideoProperties.cpp | 10 +++++----- src/AvTranscoder/properties/VideoProperties.hpp | 2 +- 10 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/AvTranscoder/properties/AudioProperties.cpp b/src/AvTranscoder/properties/AudioProperties.cpp index 4b196a6e..dd82533d 100644 --- a/src/AvTranscoder/properties/AudioProperties.cpp +++ b/src/AvTranscoder/properties/AudioProperties.cpp @@ -149,12 +149,11 @@ size_t AudioProperties::getTicksPerFrame() const return _codecContext->ticks_per_frame; } -PropertyVector AudioProperties::asVector() const +PropertyVector& AudioProperties::fillVector(PropertyVector& data) const { - PropertyVector data; - // Add properties of base class - PropertyVector basedProperty = StreamProperties::asVector(); + PropertyVector basedProperty; + StreamProperties::fillVector(basedProperty); data.insert(data.begin(), basedProperty.begin(), basedProperty.end()); addProperty(data, "sampleFormatName", &AudioProperties::getSampleFormatName); diff --git a/src/AvTranscoder/properties/AudioProperties.hpp b/src/AvTranscoder/properties/AudioProperties.hpp index dfa140d2..f8b2f851 100644 --- a/src/AvTranscoder/properties/AudioProperties.hpp +++ b/src/AvTranscoder/properties/AudioProperties.hpp @@ -30,7 +30,7 @@ class AvExport AudioProperties : public StreamProperties AVCodecContext& getAVCodecContext() { return *_codecContext; } #endif - PropertyVector asVector() const; + PropertyVector& fillVector(PropertyVector& data) const; private: #ifndef SWIG diff --git a/src/AvTranscoder/properties/FileProperties.cpp b/src/AvTranscoder/properties/FileProperties.cpp index 139fd6e6..a59f51ce 100644 --- a/src/AvTranscoder/properties/FileProperties.cpp +++ b/src/AvTranscoder/properties/FileProperties.cpp @@ -210,8 +210,12 @@ size_t FileProperties::getNbStreams() const PropertyVector FileProperties::asVector() const { - PropertyVector data; + PropertyVector propertyVector; + return fillVector(propertyVector); +} +PropertyVector& FileProperties::fillVector(PropertyVector& data) const +{ addProperty(data, "filename", &FileProperties::getFilename); addProperty(data, "formatName", &FileProperties::getFormatName); addProperty(data, "formatLongName", &FileProperties::getFormatLongName); diff --git a/src/AvTranscoder/properties/FileProperties.hpp b/src/AvTranscoder/properties/FileProperties.hpp index dd1a5b86..264e7708 100644 --- a/src/AvTranscoder/properties/FileProperties.hpp +++ b/src/AvTranscoder/properties/FileProperties.hpp @@ -85,6 +85,7 @@ class AvExport FileProperties std::string asJson() const; ///< Return all format properties as a json format. PropertyMap asMap() const; ///< Return format properties as a map (name of property, value) PropertyVector asVector() const; ///< Return format properties as a vector (name of property: value) + PropertyVector& fillVector(PropertyVector& data) const; ///< To avoid copy of the vector private: #ifndef SWIG diff --git a/src/AvTranscoder/properties/PixelProperties.cpp b/src/AvTranscoder/properties/PixelProperties.cpp index b7b30769..2f104421 100644 --- a/src/AvTranscoder/properties/PixelProperties.cpp +++ b/src/AvTranscoder/properties/PixelProperties.cpp @@ -235,8 +235,12 @@ std::vector PixelProperties::getChannels() const PropertyVector PixelProperties::asVector() const { - PropertyVector data; + PropertyVector propertyVector; + return fillVector(propertyVector); +} +PropertyVector& PixelProperties::fillVector(PropertyVector& data) const +{ addProperty(data, "pixelName", &PixelProperties::getPixelName); addProperty(data, "pixelFormatName", &PixelProperties::getPixelFormatName); addProperty(data, "bitDepth", &PixelProperties::getBitsPerPixel); diff --git a/src/AvTranscoder/properties/PixelProperties.hpp b/src/AvTranscoder/properties/PixelProperties.hpp index 643cebb0..5e087ef2 100644 --- a/src/AvTranscoder/properties/PixelProperties.hpp +++ b/src/AvTranscoder/properties/PixelProperties.hpp @@ -81,6 +81,7 @@ class AvExport PixelProperties #endif PropertyVector asVector() const; ///< Return all pixel properties as a vector (name of property: value) + PropertyVector& fillVector(PropertyVector& data) const; ///< To avoid copy of the vector private: void init(const AVPixelFormat avPixelFormat); diff --git a/src/AvTranscoder/properties/StreamProperties.cpp b/src/AvTranscoder/properties/StreamProperties.cpp index d7bf6c41..1bc28f31 100644 --- a/src/AvTranscoder/properties/StreamProperties.cpp +++ b/src/AvTranscoder/properties/StreamProperties.cpp @@ -100,8 +100,12 @@ std::string StreamProperties::getCodecLongName() const PropertyVector StreamProperties::asVector() const { - PropertyVector data; + PropertyVector propertyVector; + return fillVector(propertyVector); +} +PropertyVector& StreamProperties::fillVector(PropertyVector& data) const +{ addProperty(data, "streamId", &StreamProperties::getStreamId); addProperty(data, "streamIndex", &StreamProperties::getStreamIndex); addProperty(data, "timeBase", &StreamProperties::getTimeBase); diff --git a/src/AvTranscoder/properties/StreamProperties.hpp b/src/AvTranscoder/properties/StreamProperties.hpp index 8fd1ddd0..f3c68e04 100644 --- a/src/AvTranscoder/properties/StreamProperties.hpp +++ b/src/AvTranscoder/properties/StreamProperties.hpp @@ -31,9 +31,10 @@ class AvExport StreamProperties const AVFormatContext& getAVFormatContext() const { return *_formatContext; } #endif - std::string asJson() const; ///< Return all properties as a json format. - PropertyMap asMap() const; ///< Return all properties as a map (name of property, value) - virtual PropertyVector asVector() const; ///< Same data with a specific order + std::string asJson() const; ///< Return all properties as a json format. + PropertyMap asMap() const; ///< Return all properties as a map (name of property, value) + PropertyVector asVector() const; ///< Same data with a specific order + virtual PropertyVector& fillVector(PropertyVector& data) const; ///< To avoid copy of the vector private: #ifndef SWIG diff --git a/src/AvTranscoder/properties/VideoProperties.cpp b/src/AvTranscoder/properties/VideoProperties.cpp index 9613a194..0dd86102 100644 --- a/src/AvTranscoder/properties/VideoProperties.cpp +++ b/src/AvTranscoder/properties/VideoProperties.cpp @@ -552,12 +552,11 @@ void VideoProperties::analyseGopStructure(IProgress& progress) } } -PropertyVector VideoProperties::asVector() const +PropertyVector& VideoProperties::fillVector(PropertyVector& data) const { - PropertyVector data; - // Add properties of base class - PropertyVector basedProperty = StreamProperties::asVector(); + PropertyVector basedProperty; + StreamProperties::fillVector(basedProperty); data.insert(data.begin(), basedProperty.begin(), basedProperty.end()); addProperty(data, "profile", &VideoProperties::getProfile); @@ -598,7 +597,8 @@ PropertyVector VideoProperties::asVector() const addProperty(data, "referencesFrames", &VideoProperties::getReferencesFrames); // Add properties of the pixel - PropertyVector pixelProperties = _pixelProperties.asVector(); + PropertyVector pixelProperties; + _pixelProperties.fillVector(pixelProperties); data.insert(data.end(), pixelProperties.begin(), pixelProperties.end()); return data; diff --git a/src/AvTranscoder/properties/VideoProperties.hpp b/src/AvTranscoder/properties/VideoProperties.hpp index 541ac6bd..bd1cc301 100644 --- a/src/AvTranscoder/properties/VideoProperties.hpp +++ b/src/AvTranscoder/properties/VideoProperties.hpp @@ -79,7 +79,7 @@ class AvExport VideoProperties : public StreamProperties const PixelProperties& getPixelProperties() const { return _pixelProperties; } #endif - PropertyVector asVector() const; + PropertyVector& fillVector(PropertyVector& data) const; private: /**