Skip to content

Commit 14920f9

Browse files
author
Marc-Antoine Arnaud
committed
update output Json structure to return typed values
1 parent 3c5acc5 commit 14920f9

17 files changed

+404
-178
lines changed

src/AvTranscoder/file/OutputFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ void OutputFile::addMetadata(const PropertyVector& data)
242242
{
243243
for(PropertyVector::const_iterator it = data.begin(); it != data.end(); ++it)
244244
{
245-
addMetadata(it->first, it->second);
245+
addMetadata(it->first, it->second.asString());
246246
}
247247
}
248248

src/AvTranscoder/properties/AudioProperties.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,16 @@ PropertyVector& AudioProperties::fillVector(PropertyVector& data) const
158158
StreamProperties::fillVector(basedProperty);
159159
data.insert(data.begin(), basedProperty.begin(), basedProperty.end());
160160

161-
addProperty(data, "sampleFormatName", &AudioProperties::getSampleFormatName);
162-
addProperty(data, "sampleFormatLongName", &AudioProperties::getSampleFormatLongName);
163-
addProperty(data, "bitRate", &AudioProperties::getBitRate);
164-
addProperty(data, "sampleRate", &AudioProperties::getSampleRate);
165-
addProperty(data, "nbSamples", &AudioProperties::getNbSamples);
166-
addProperty(data, "nbChannels", &AudioProperties::getNbChannels);
167-
addProperty(data, "channelLayout", &AudioProperties::getChannelLayout);
168-
addProperty(data, "channelName", &AudioProperties::getChannelName);
169-
addProperty(data, "channelDescription", &AudioProperties::getChannelDescription);
170-
addProperty(data, "ticksPerFrame", &AudioProperties::getTicksPerFrame);
161+
detail::addProperty(data, "sampleFormatName", this, &AudioProperties::getSampleFormatName);
162+
detail::addProperty(data, "sampleFormatLongName", this, &AudioProperties::getSampleFormatLongName);
163+
detail::addProperty(data, "bitRate", this, &AudioProperties::getBitRate);
164+
detail::addProperty(data, "sampleRate", this, &AudioProperties::getSampleRate);
165+
detail::addProperty(data, "nbSamples", this, &AudioProperties::getNbSamples);
166+
detail::addProperty(data, "nbChannels", this, &AudioProperties::getNbChannels);
167+
detail::addProperty(data, "channelLayout", this, &AudioProperties::getChannelLayout);
168+
detail::addProperty(data, "channelName", this, &AudioProperties::getChannelName);
169+
detail::addProperty(data, "channelDescription", this, &AudioProperties::getChannelDescription);
170+
detail::addProperty(data, "ticksPerFrame", this, &AudioProperties::getTicksPerFrame);
171171

172172
return data;
173173
}

src/AvTranscoder/properties/AudioProperties.hpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,6 @@ class AvExport AudioProperties : public StreamProperties
3131
#endif
3232

3333
PropertyVector& fillVector(PropertyVector& data) const;
34-
35-
private:
36-
#ifndef SWIG
37-
template <typename T>
38-
void addProperty(PropertyVector& data, const std::string& key, T (AudioProperties::*getter)(void) const) const
39-
{
40-
try
41-
{
42-
detail::add(data, key, (this->*getter)());
43-
}
44-
catch(const std::exception& e)
45-
{
46-
detail::add(data, key, detail::propertyValueIfError);
47-
}
48-
}
49-
#endif
5034
};
5135

5236
#ifndef SWIG

src/AvTranscoder/properties/FileProperties.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
#include <AvTranscoder/properties/util.hpp>
44
#include <AvTranscoder/properties/JsonWriter.hpp>
5+
#include <AvTranscoder/properties/jsonWriterHelper.hpp>
56
#include <AvTranscoder/progress/NoDisplayProgress.hpp>
67

78
#include <stdexcept>
89
#include <sstream>
910
#include <fstream>
11+
#include <iostream>
1012

1113
namespace avtranscoder
1214
{
@@ -259,19 +261,19 @@ PropertyVector FileProperties::asVector() const
259261

260262
PropertyVector& FileProperties::fillVector(PropertyVector& data) const
261263
{
262-
addProperty(data, "filename", &FileProperties::getFilename);
263-
addProperty(data, "formatName", &FileProperties::getFormatName);
264-
addProperty(data, "formatLongName", &FileProperties::getFormatLongName);
265-
addProperty(data, "mimeType", &FileProperties::getFormatMimeType);
266-
addProperty(data, "rawFormat", &FileProperties::isRawFormat);
267-
268-
addProperty(data, "startTime", &FileProperties::getStartTime);
269-
addProperty(data, "duration", &FileProperties::getDuration);
270-
addProperty(data, "bitrate", &FileProperties::getBitRate);
271-
addProperty(data, "fileSize", &FileProperties::getFileSize);
272-
addProperty(data, "packetSize", &FileProperties::getPacketSize);
273-
addProperty(data, "numberOfStreams", &FileProperties::getNbStreams);
274-
addProperty(data, "numberOfPrograms", &FileProperties::getProgramsCount);
264+
detail::addProperty(data, "filename", this, &FileProperties::getFilename);
265+
detail::addProperty(data, "formatName", this, &FileProperties::getFormatName);
266+
detail::addProperty(data, "formatLongName", this, &FileProperties::getFormatLongName);
267+
detail::addProperty(data, "mimeType", this, &FileProperties::getFormatMimeType);
268+
detail::addProperty(data, "rawFormat", this, &FileProperties::isRawFormat);
269+
270+
detail::addProperty(data, "startTime", this, &FileProperties::getStartTime);
271+
detail::addProperty(data, "duration", this, &FileProperties::getDuration);
272+
detail::addProperty(data, "bitrate", this, &FileProperties::getBitRate);
273+
detail::addProperty(data, "fileSize", this, &FileProperties::getFileSize);
274+
detail::addProperty(data, "packetSize", this, &FileProperties::getPacketSize);
275+
detail::addProperty(data, "numberOfStreams", this, &FileProperties::getNbStreams);
276+
detail::addProperty(data, "numberOfPrograms", this, &FileProperties::getProgramsCount);
275277

276278
detail::add(data, "numberOfVideoStreams", getNbVideoStreams());
277279
detail::add(data, "numberOfAudioStreams", getNbAudioStreams());
@@ -303,11 +305,8 @@ PropertyMap FileProperties::asMap() const
303305

304306
std::string FileProperties::asJson() const
305307
{
306-
json::JsonObjectStreamWriter writer;
307308
PropertyMap properties = asMap();
308-
for(PropertyMap::iterator it = properties.begin(); it != properties.end(); ++it)
309-
writer << std::make_pair(it->first.c_str(), it->second.c_str());
310-
return writer.build();
309+
return json::build(properties);
311310
}
312311

313312
std::string FileProperties::allPropertiesAsJson() const

src/AvTranscoder/properties/FileProperties.hpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,6 @@ class AvExport FileProperties
9191
PropertyVector asVector() const; ///< Return format properties as a vector (name of property: value)
9292
PropertyVector& fillVector(PropertyVector& data) const; ///< To avoid copy of the vector
9393

94-
private:
95-
#ifndef SWIG
96-
template <typename T>
97-
void addProperty(PropertyVector& data, const std::string& key, T (FileProperties::*getter)(void) const) const
98-
{
99-
try
100-
{
101-
detail::add(data, key, (this->*getter)());
102-
}
103-
catch(const std::exception& e)
104-
{
105-
detail::add(data, key, detail::propertyValueIfError);
106-
}
107-
}
108-
#endif
109-
11094
private:
11195
const InputFile& _file; ///< Has link (no ownership)
11296
const FormatContext* _formatContext; ///< Has link (no ownership)

src/AvTranscoder/properties/PixelProperties.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,13 @@ PropertyVector PixelProperties::asVector() const
241241

242242
PropertyVector& PixelProperties::fillVector(PropertyVector& data) const
243243
{
244-
addProperty(data, "pixelName", &PixelProperties::getPixelName);
245-
addProperty(data, "pixelFormatName", &PixelProperties::getPixelFormatName);
246-
addProperty(data, "bitDepth", &PixelProperties::getBitsPerPixel);
247-
addProperty(data, "maxNbBitsInChannels", &PixelProperties::getMaxNbBitsInChannels);
248-
addProperty(data, "nbComponents", &PixelProperties::getNbComponents);
249-
addProperty(data, "chromaWidth", &PixelProperties::getChromaWidth);
250-
addProperty(data, "chromaHeight", &PixelProperties::getChromaHeight);
244+
detail::addProperty(data, "pixelName", this, &PixelProperties::getPixelName);
245+
detail::addProperty(data, "pixelFormatName", this, &PixelProperties::getPixelFormatName);
246+
detail::addProperty(data, "bitDepth", this, &PixelProperties::getBitsPerPixel);
247+
detail::addProperty(data, "maxNbBitsInChannels", this, &PixelProperties::getMaxNbBitsInChannels);
248+
detail::addProperty(data, "nbComponents", this, &PixelProperties::getNbComponents);
249+
detail::addProperty(data, "chromaWidth", this, &PixelProperties::getChromaWidth);
250+
detail::addProperty(data, "chromaHeight", this, &PixelProperties::getChromaHeight);
251251

252252
try
253253
{
@@ -308,14 +308,14 @@ PropertyVector& PixelProperties::fillVector(PropertyVector& data) const
308308
detail::add(data, "subsampling", detail::propertyValueIfError);
309309
}
310310

311-
addProperty(data, "isBigEndian", &PixelProperties::isBigEndian);
312-
addProperty(data, "hasAlpha", &PixelProperties::hasAlpha);
313-
addProperty(data, "isPlanar", &PixelProperties::isPlanar);
314-
addProperty(data, "isIndexedColors", &PixelProperties::isIndexedColors);
315-
addProperty(data, "bitWiseAcked", &PixelProperties::isBitWisePacked);
316-
addProperty(data, "isHardwareAccelerated", &PixelProperties::isHardwareAccelerated);
317-
addProperty(data, "rgbPixel", &PixelProperties::isRgbPixelData);
318-
addProperty(data, "isPseudoPaletted", &PixelProperties::isPseudoPaletted);
311+
detail::addProperty(data, "isBigEndian", this, &PixelProperties::isBigEndian);
312+
detail::addProperty(data, "hasAlpha", this, &PixelProperties::hasAlpha);
313+
detail::addProperty(data, "isPlanar", this, &PixelProperties::isPlanar);
314+
detail::addProperty(data, "isIndexedColors", this, &PixelProperties::isIndexedColors);
315+
detail::addProperty(data, "bitWiseAcked", this, &PixelProperties::isBitWisePacked);
316+
detail::addProperty(data, "isHardwareAccelerated", this, &PixelProperties::isHardwareAccelerated);
317+
detail::addProperty(data, "rgbPixel", this, &PixelProperties::isRgbPixelData);
318+
detail::addProperty(data, "isPseudoPaletted", this, &PixelProperties::isPseudoPaletted);
319319

320320
try
321321
{

src/AvTranscoder/properties/PixelProperties.hpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,6 @@ class AvExport PixelProperties
8686
private:
8787
void init(const AVPixelFormat avPixelFormat);
8888

89-
#ifndef SWIG
90-
template <typename T>
91-
void addProperty(PropertyVector& data, const std::string& key, T (PixelProperties::*getter)(void) const) const
92-
{
93-
try
94-
{
95-
detail::add(data, key, (this->*getter)());
96-
}
97-
catch(const std::exception& e)
98-
{
99-
detail::add(data, key, detail::propertyValueIfError);
100-
}
101-
}
102-
#endif
103-
10489
private:
10590
AVPixelFormat _pixelFormat;
10691
const AVPixFmtDescriptor* _pixelDesc; ///< Has link (no ownership)
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
2+
#include "PropertyValue.hpp"
3+
#include <iostream>
4+
#include <sstream>
5+
6+
namespace avtranscoder
7+
{
8+
9+
PropertyValue::PropertyValue(const EPropertyValueKind kind, const std::string& data)
10+
: _kind(kind)
11+
, _data(data.c_str(), data.c_str() + data.size() + 1)
12+
{}
13+
14+
PropertyValue::PropertyValue(const EPropertyValueKind kind, const bool data)
15+
: _kind(kind)
16+
, _data(sizeof(bool), data)
17+
{}
18+
19+
PropertyValue::PropertyValue(const EPropertyValueKind kind, const size_t data)
20+
: _kind(kind)
21+
, _data(sizeof(size_t), data)
22+
{
23+
::memcpy(_data.data(), &data, sizeof(size_t));
24+
}
25+
26+
PropertyValue::PropertyValue(const EPropertyValueKind kind, const int data)
27+
: _kind(kind)
28+
, _data(sizeof(int), data)
29+
{}
30+
31+
PropertyValue::PropertyValue(const EPropertyValueKind kind, const float data)
32+
: _kind(kind)
33+
, _data(sizeof(float), data)
34+
{}
35+
36+
PropertyValue::PropertyValue(const EPropertyValueKind kind, const double data)
37+
: _kind(kind)
38+
, _data(sizeof(double), data)
39+
{}
40+
41+
PropertyValue::PropertyValue(const EPropertyValueKind kind, const Rational data)
42+
: _kind(kind)
43+
, _data(2 * sizeof(int), 0)
44+
{
45+
_data[sizeof(int)] = data.num;
46+
_data[0] = data.den;
47+
}
48+
49+
50+
const EPropertyValueKind PropertyValue::getType() const
51+
{
52+
return _kind;
53+
}
54+
55+
const std::string PropertyValue::getString() const
56+
{
57+
return std::string(_data.begin(), _data.begin() + _data.size());
58+
}
59+
60+
const bool PropertyValue::getBool() const
61+
{
62+
return (bool)_data[0];
63+
}
64+
65+
const size_t PropertyValue::getUInt() const
66+
{
67+
size_t v = 0;
68+
::memcpy(&v, _data.data(), sizeof(size_t));
69+
return v;
70+
}
71+
72+
const int PropertyValue::getInt() const
73+
{
74+
return (int)_data[0];
75+
}
76+
77+
const float PropertyValue::getFloat() const
78+
{
79+
return (float)_data[0];
80+
}
81+
82+
const double PropertyValue::getDouble() const
83+
{
84+
return (double)_data[0];
85+
}
86+
87+
const Rational PropertyValue::getRational() const
88+
{
89+
Rational r;
90+
r.num = (int)_data[sizeof(int)];
91+
r.den = (int)_data[0];
92+
return r;
93+
}
94+
95+
const std::string PropertyValue::asString() const
96+
{
97+
std::ostringstream os;
98+
switch(getType())
99+
{
100+
case EPropertyValueKind::EPropertyValueKindString:
101+
{
102+
os << getString();
103+
break;
104+
}
105+
case EPropertyValueKind::EPropertyValueKindUInt:
106+
{
107+
os << getUInt();
108+
break;
109+
}
110+
case EPropertyValueKind::EPropertyValueKindInt:
111+
{
112+
os << getInt();
113+
break;
114+
}
115+
case EPropertyValueKind::EPropertyValueKindFloat:
116+
{
117+
os << getFloat();
118+
break;
119+
}
120+
case EPropertyValueKind::EPropertyValueKindDouble:
121+
{
122+
os << getDouble();
123+
break;
124+
}
125+
case EPropertyValueKind::EPropertyValueKindBoolean:
126+
{
127+
os << (getBool() ? "true": "false");
128+
break;
129+
}
130+
case EPropertyValueKind::EPropertyValueKindRational:
131+
{
132+
Rational r = getRational();
133+
os << r.num << "/" << r.den;
134+
break;
135+
}
136+
}
137+
return os.str();
138+
}
139+
140+
std::ostream& operator<<(std::ostream& stream, const PropertyValue& value)
141+
{
142+
stream << value.asString();
143+
return stream;
144+
}
145+
146+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy