Skip to content

Commit 8a895ac

Browse files
committed
Merge pull request #216 from cchampet/dev_propertiesDeletePrintHeader
properties: overload operator<< in each class properties: added fillVector method to avoid copy of the vector
2 parents 6a915de + dac41e8 commit 8a895ac

24 files changed

+257
-214
lines changed

app/avMeta/avMeta.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#include <AvTranscoder/file/InputFile.hpp>
2-
#include <AvTranscoder/properties/print.hpp>
3-
42
#include <AvTranscoder/progress/NoDisplayProgress.hpp>
53

64
#include <iostream>

src/AvTranscoder/file/InputFile.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,51 @@ void InputFile::setupUnwrapping(const ProfileLoader::Profile& profile)
203203
}
204204
}
205205
}
206+
207+
std::ostream& operator<<(std::ostream& flux, const InputFile& input)
208+
{
209+
// wrapper
210+
flux << input.getProperties();
211+
212+
// video streams
213+
for(size_t videoStreamIndex = 0; videoStreamIndex < input.getProperties().getNbVideoStreams(); ++videoStreamIndex)
214+
{
215+
flux << input.getProperties().getVideoProperties().at(videoStreamIndex);
216+
}
217+
218+
// audio streams
219+
for(size_t audioStreamIndex = 0; audioStreamIndex < input.getProperties().getNbAudioStreams(); ++audioStreamIndex)
220+
{
221+
flux << input.getProperties().getAudioProperties().at(audioStreamIndex);
222+
}
223+
224+
// data streams
225+
for(size_t dataStreamIndex = 0; dataStreamIndex < input.getProperties().getNbDataStreams(); ++dataStreamIndex)
226+
{
227+
flux << input.getProperties().getDataProperties().at(dataStreamIndex);
228+
}
229+
230+
// subtitle streams
231+
for(size_t subtitleStreamIndex = 0; subtitleStreamIndex < input.getProperties().getNbSubtitleStreams();
232+
++subtitleStreamIndex)
233+
{
234+
flux << input.getProperties().getSubtitleProperties().at(subtitleStreamIndex);
235+
}
236+
237+
// attachement streams
238+
for(size_t attachementStreamIndex = 0; attachementStreamIndex < input.getProperties().getNbAttachementStreams();
239+
++attachementStreamIndex)
240+
{
241+
flux << input.getProperties().getAttachementProperties().at(attachementStreamIndex);
242+
}
243+
244+
// unknown streams
245+
for(size_t unknownStreamIndex = 0; unknownStreamIndex < input.getProperties().getNbUnknownStreams();
246+
++unknownStreamIndex)
247+
{
248+
flux << input.getProperties().getUnknownProperties().at(unknownStreamIndex);
249+
}
250+
251+
return flux;
252+
}
206253
}

src/AvTranscoder/file/InputFile.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ class AvExport InputFile
125125
std::string _filename;
126126
std::vector<InputStream*> _inputStreams; ///< Has ownership
127127
};
128+
129+
#ifndef SWIG
130+
AvExport std::ostream& operator<<(std::ostream& flux, const InputFile& input);
131+
#endif
128132
}
129133

130134
#endif
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "AttachementProperties.hpp"
2+
3+
#include <AvTranscoder/properties/util.hpp>
4+
5+
namespace avtranscoder
6+
{
7+
8+
std::ostream& operator<<(std::ostream& flux, const AttachementProperties& attachementProperties)
9+
{
10+
flux << detail::separator << " Attachement stream " << detail::separator << std::endl;
11+
12+
PropertyVector properties = attachementProperties.asVector();
13+
for(PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it)
14+
{
15+
flux << std::setw(detail::keyWidth) << it->first << ": " << it->second << std::endl;
16+
}
17+
18+
return flux;
19+
}
20+
}

src/AvTranscoder/properties/AttachementProperties.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class AvExport AttachementProperties : public StreamProperties
1414
{
1515
}
1616
};
17+
18+
#ifndef SWIG
19+
AvExport std::ostream& operator<<(std::ostream& flux, const AttachementProperties& attachementProperties);
20+
#endif
1721
}
1822

1923
#endif

src/AvTranscoder/properties/AudioProperties.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "AudioProperties.hpp"
22

3+
#include <AvTranscoder/properties/util.hpp>
4+
35
extern "C" {
46
#include <libavcodec/avcodec.h>
57
#include <libavformat/avformat.h>
@@ -147,12 +149,11 @@ size_t AudioProperties::getTicksPerFrame() const
147149
return _codecContext->ticks_per_frame;
148150
}
149151

150-
PropertyVector AudioProperties::asVector() const
152+
PropertyVector& AudioProperties::fillVector(PropertyVector& data) const
151153
{
152-
PropertyVector data;
153-
154154
// Add properties of base class
155-
PropertyVector basedProperty = StreamProperties::asVector();
155+
PropertyVector basedProperty;
156+
StreamProperties::fillVector(basedProperty);
156157
data.insert(data.begin(), basedProperty.begin(), basedProperty.end());
157158

158159
addProperty(data, "sampleFormatName", &AudioProperties::getSampleFormatName);
@@ -168,4 +169,18 @@ PropertyVector AudioProperties::asVector() const
168169

169170
return data;
170171
}
172+
173+
std::ostream& operator<<(std::ostream& flux, const AudioProperties& audioProperties)
174+
{
175+
flux << std::left;
176+
flux << detail::separator << " Audio stream " << detail::separator << std::endl;
177+
178+
PropertyVector properties = audioProperties.asVector();
179+
for(PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it)
180+
{
181+
flux << std::setw(detail::keyWidth) << it->first << ": " << it->second << std::endl;
182+
}
183+
184+
return flux;
185+
}
171186
}

src/AvTranscoder/properties/AudioProperties.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class AvExport AudioProperties : public StreamProperties
3030
AVCodecContext& getAVCodecContext() { return *_codecContext; }
3131
#endif
3232

33-
PropertyVector asVector() const;
33+
PropertyVector& fillVector(PropertyVector& data) const;
3434

3535
private:
3636
#ifndef SWIG
@@ -48,6 +48,10 @@ class AvExport AudioProperties : public StreamProperties
4848
}
4949
#endif
5050
};
51+
52+
#ifndef SWIG
53+
AvExport std::ostream& operator<<(std::ostream& flux, const AudioProperties& audioProperties);
54+
#endif
5155
}
5256

5357
#endif

src/AvTranscoder/properties/DataProperties.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "DataProperties.hpp"
22

3+
#include <AvTranscoder/properties/util.hpp>
4+
35
extern "C" {
46
#include <libavcodec/avcodec.h>
57
}
@@ -77,4 +79,17 @@ void DataProperties::detectAncillaryData()
7779
break;
7880
}
7981
}
82+
83+
std::ostream& operator<<(std::ostream& flux, const DataProperties& dataProperties)
84+
{
85+
flux << detail::separator << " Data stream " << detail::separator << std::endl;
86+
87+
PropertyVector properties = dataProperties.asVector();
88+
for(PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it)
89+
{
90+
flux << std::setw(detail::keyWidth) << it->first << ": " << it->second << std::endl;
91+
}
92+
93+
return flux;
94+
}
8095
}

src/AvTranscoder/properties/DataProperties.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ class AvExport DataProperties : public StreamProperties
1717
private:
1818
void detectAncillaryData();
1919
};
20+
21+
#ifndef SWIG
22+
AvExport std::ostream& operator<<(std::ostream& flux, const DataProperties& dataProperties);
23+
#endif
2024
}
2125

2226
#endif

src/AvTranscoder/properties/FileProperties.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "FileProperties.hpp"
22

3+
#include <AvTranscoder/properties/util.hpp>
34
#include <AvTranscoder/properties/JsonWriter.hpp>
45
#include <AvTranscoder/progress/NoDisplayProgress.hpp>
56

@@ -209,8 +210,12 @@ size_t FileProperties::getNbStreams() const
209210

210211
PropertyVector FileProperties::asVector() const
211212
{
212-
PropertyVector data;
213+
PropertyVector propertyVector;
214+
return fillVector(propertyVector);
215+
}
213216

217+
PropertyVector& FileProperties::fillVector(PropertyVector& data) const
218+
{
214219
addProperty(data, "filename", &FileProperties::getFilename);
215220
addProperty(data, "formatName", &FileProperties::getFormatName);
216221
addProperty(data, "formatLongName", &FileProperties::getFormatLongName);
@@ -341,4 +346,18 @@ void FileProperties::clearStreamProperties()
341346
_attachementStreams.clear();
342347
_unknownStreams.clear();
343348
}
349+
350+
std::ostream& operator<<(std::ostream& flux, const FileProperties& fileProperties)
351+
{
352+
flux << std::left;
353+
flux << detail::separator << " Wrapper " << detail::separator << std::endl;
354+
355+
PropertyVector properties = fileProperties.asVector();
356+
for(PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it)
357+
{
358+
flux << std::setw(detail::keyWidth) << it->first << ": " << it->second << std::endl;
359+
}
360+
361+
return flux;
362+
}
344363
}

src/AvTranscoder/properties/FileProperties.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class AvExport FileProperties
8585
std::string asJson() const; ///< Return all format properties as a json format.
8686
PropertyMap asMap() const; ///< Return format properties as a map (name of property, value)
8787
PropertyVector asVector() const; ///< Return format properties as a vector (name of property: value)
88+
PropertyVector& fillVector(PropertyVector& data) const; ///< To avoid copy of the vector
8889

8990
private:
9091
#ifndef SWIG
@@ -120,6 +121,10 @@ class AvExport FileProperties
120121

121122
PropertyVector _metadatas;
122123
};
124+
125+
#ifndef SWIG
126+
AvExport std::ostream& operator<<(std::ostream& flux, const FileProperties& fileProperties);
127+
#endif
123128
}
124129

125130
#endif

src/AvTranscoder/properties/PixelProperties.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,12 @@ std::vector<Channel> PixelProperties::getChannels() const
235235

236236
PropertyVector PixelProperties::asVector() const
237237
{
238-
PropertyVector data;
238+
PropertyVector propertyVector;
239+
return fillVector(propertyVector);
240+
}
239241

242+
PropertyVector& PixelProperties::fillVector(PropertyVector& data) const
243+
{
240244
addProperty(data, "pixelName", &PixelProperties::getPixelName);
241245
addProperty(data, "pixelFormatName", &PixelProperties::getPixelFormatName);
242246
addProperty(data, "bitDepth", &PixelProperties::getBitsPerPixel);

src/AvTranscoder/properties/PixelProperties.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class AvExport PixelProperties
8181
#endif
8282

8383
PropertyVector asVector() const; ///< Return all pixel properties as a vector (name of property: value)
84+
PropertyVector& fillVector(PropertyVector& data) const; ///< To avoid copy of the vector
8485

8586
private:
8687
void init(const AVPixelFormat avPixelFormat);

src/AvTranscoder/properties/StreamProperties.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "StreamProperties.hpp"
22

3+
#include <AvTranscoder/properties/util.hpp>
34
#include <AvTranscoder/properties/JsonWriter.hpp>
45

56
#include <stdexcept>
@@ -99,8 +100,12 @@ std::string StreamProperties::getCodecLongName() const
99100

100101
PropertyVector StreamProperties::asVector() const
101102
{
102-
PropertyVector data;
103+
PropertyVector propertyVector;
104+
return fillVector(propertyVector);
105+
}
103106

107+
PropertyVector& StreamProperties::fillVector(PropertyVector& data) const
108+
{
104109
addProperty(data, "streamId", &StreamProperties::getStreamId);
105110
addProperty(data, "streamIndex", &StreamProperties::getStreamIndex);
106111
addProperty(data, "timeBase", &StreamProperties::getTimeBase);
@@ -138,4 +143,18 @@ std::string StreamProperties::asJson() const
138143
writer << std::make_pair(it->first.c_str(), it->second.c_str());
139144
return writer.build();
140145
}
146+
147+
std::ostream& operator<<(std::ostream& flux, const StreamProperties& streamProperties)
148+
{
149+
flux << std::left;
150+
flux << detail::separator << " Stream " << detail::separator << std::endl;
151+
152+
PropertyVector properties = streamProperties.asVector();
153+
for(PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it)
154+
{
155+
flux << std::setw(detail::keyWidth) << it->first << ": " << it->second << std::endl;
156+
}
157+
158+
return flux;
159+
}
141160
}

src/AvTranscoder/properties/StreamProperties.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ class AvExport StreamProperties
3131
const AVFormatContext& getAVFormatContext() const { return *_formatContext; }
3232
#endif
3333

34-
std::string asJson() const; ///< Return all properties as a json format.
35-
PropertyMap asMap() const; ///< Return all properties as a map (name of property, value)
36-
virtual PropertyVector asVector() const; ///< Same data with a specific order
34+
std::string asJson() const; ///< Return all properties as a json format.
35+
PropertyMap asMap() const; ///< Return all properties as a map (name of property, value)
36+
PropertyVector asVector() const; ///< Same data with a specific order
37+
virtual PropertyVector& fillVector(PropertyVector& data) const; ///< To avoid copy of the vector
3738

3839
private:
3940
#ifndef SWIG
@@ -59,6 +60,10 @@ class AvExport StreamProperties
5960
size_t _streamIndex;
6061
PropertyVector _metadatas;
6162
};
63+
64+
#ifndef SWIG
65+
AvExport std::ostream& operator<<(std::ostream& flux, const StreamProperties& streamProperties);
66+
#endif
6267
}
6368

6469
#endif
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "SubtitleProperties.hpp"
2+
3+
#include <AvTranscoder/properties/util.hpp>
4+
5+
namespace avtranscoder
6+
{
7+
8+
std::ostream& operator<<(std::ostream& flux, const SubtitleProperties& subtitleProperties)
9+
{
10+
flux << detail::separator << " Subtitle stream " << detail::separator << std::endl;
11+
12+
PropertyVector properties = subtitleProperties.asVector();
13+
for(PropertyVector::iterator it = properties.begin(); it != properties.end(); ++it)
14+
{
15+
flux << std::setw(detail::keyWidth) << it->first << ": " << it->second << std::endl;
16+
}
17+
18+
return flux;
19+
}
20+
}

src/AvTranscoder/properties/SubtitleProperties.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class AvExport SubtitleProperties : public StreamProperties
1414
{
1515
}
1616
};
17+
18+
#ifndef SWIG
19+
AvExport std::ostream& operator<<(std::ostream& flux, const SubtitleProperties& subtitleProperties);
20+
#endif
1721
}
1822

1923
#endif

0 commit comments

Comments
 (0)