1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
// Copyright (c) 2012-2017 VideoStitch SAS
// Copyright (c) 2018 stitchEm
#include "libvideostitch/status.hpp"
#include "libvideostitch/logging.hpp"
#include <iostream>
#include <sstream>
namespace VideoStitch {
// Trigger the debugger if a Status is ignored in DEBUG mode
// TODOLATERSTATUS: enable this by default in DEBUG mode
// need to make all tests compatible
//#ifndef NDEBUG
// #define DEBUG_IGNORED_STATUS
//#endif
#ifdef DEBUG_IGNORED_STATUS
#ifdef NDEBUG
#error "This is not supposed to be included in non-debug mode."
#endif
#include <signal.h>
// an error Status has been created, but the contained information was never accessed
inline void trigger_debugger() {
#ifdef _MSC_VER
__debugbreak();
#else
asm("int3");
#endif
}
#endif
static const char* originToString(Origin origin) {
switch (origin) {
case Origin::AudioPipeline:
return "audio pipeline";
case Origin::AudioPipelineConfiguration:
return "audio pipeline configuration";
case Origin::AudioPreProcessor:
return "audio preprocessor";
case Origin::BlendingMaskAlgorithm:
return "blending mask algorithm";
case Origin::CropAlgorithm:
return "automatic crop detection";
case Origin::CalibrationAlgorithm:
return "calibration algorithm";
case Origin::ExposureAlgorithm:
return "exposure algorithm";
case Origin::ExternalModule:
return "external module";
case Origin::GPU:
return "GPU";
case Origin::PhotometricCalibrationAlgorithm:
return "photometric calibration algorithm";
case Origin::ScoringAlgorithm:
return "stitching score algorithm";
case Origin::StabilizationAlgorithm:
return "stabilization algorithm";
case Origin::SynchronizationAlgorithm:
return "synchronization algorithm";
case Origin::MotionEstimationAlgorithm:
return "motion estimation algorithm";
case Origin::MaskInterpolationAlgorithm:
return "blending mask interpolation algorithm";
case Origin::EpipolarCurvesAlgorithm:
return "epipolar curves algorithm";
case Origin::Stitcher:
return "stitcher";
case Origin::PostProcessor:
return "post-processor";
case Origin::PreProcessor:
return "pre-processor";
case Origin::Input:
return "input";
case Origin::ImageFlow:
return "image flow";
case Origin::ImageWarper:
return "image warper";
case Origin::Output:
return "output";
case Origin::PanoramaConfiguration:
return "panorama configuration";
case Origin::GeometryProcessingUtils:
return "geometry processing utils";
case Origin::Surface:
return "surface";
case Origin::Unspecified:
return "unspecified module";
}
assert(false);
return "Invalid error origin";
}
static const char* typeToString(ErrType type) {
switch (type) {
case ErrType::ImplementationError:
return "Internal error";
case ErrType::UnsupportedAction:
return "Unsupported action";
case ErrType::None:
return "None";
case ErrType::OutOfResources:
return "Out of resources";
case ErrType::SetupFailure:
return "Setup failure";
case ErrType::AlgorithmFailure:
return "Algorithm execution failure";
case ErrType::InvalidConfiguration:
return "Invalid configuration";
case ErrType::RuntimeError:
return "Runtime error";
case ErrType::OperationAbortedByUser:
return "Operation cancelled by user";
}
assert(false);
return "Invalid error type";
}
/**
* An object that indicates error status.
*/
class Status::Description {
public:
explicit Description(Origin o, ErrType t, const std::string& msg)
: origin(o), type(t), message(msg), cause(nullptr) {}
explicit Description(Origin o, ErrType t, const std::string& msg, Status p)
: origin(o), type(t), message(msg), cause(new Status(p)) {}
bool hasCause() const { return !!cause; }
const Status* getCause() const { return cause.get(); }
Origin getOrigin() const {
#ifdef DEBUG_IGNORED_STATUS
hasBeenChecked = true;
#endif
return origin;
}
ErrType getType() const {
#ifdef DEBUG_IGNORED_STATUS
hasBeenChecked = true;
#endif
return type;
}
std::string getCurrentMessageOnly() const {
#ifdef DEBUG_IGNORED_STATUS
hasBeenChecked = true;
#endif
return message;
}
#ifdef DEBUG_IGNORED_STATUS
~Description() {
if (!hasBeenChecked) {
// an error Status has been created, but the contained information was never accessed
trigger_debugger();
}
}
#endif
Description(const Description& other)
: origin(other.getOrigin()),
type(other.getType()),
message(other.getCurrentMessageOnly()),
cause(other.cause ? new Status(*other.cause) : nullptr) {}
private:
Origin origin;
ErrType type;
std::string message;
std::unique_ptr<Status> cause;
#ifdef DEBUG_IGNORED_STATUS
mutable bool hasBeenChecked = false;
#endif
};
const std::string STATUStag("Status");
Status::Status(Origin o, ErrType t, const std::string& message) : description(new Description(o, t, message)) {
std::stringstream msg;
msg << typeToString(t) << ": " << message << std::endl;
Logger::warning(STATUStag, originToString(o)) << msg.str() << std::flush;
// Should never happen, impossible
assert(t != ErrType::ImplementationError);
}
Status::Status(Origin o, ErrType t, const std::string& message, Status parent)
: description(new Description(o, t, message, parent)) {
std::stringstream msg;
msg << typeToString(t) << ": " << description->getCurrentMessageOnly() << std::endl;
Logger::warning(STATUStag, originToString(o)) << msg.str();
}
Status::Status(Origin o, ErrType t, const std::string& tag, const std::string& message)
: description(new Description(o, t, Logger::concatenateTags(tag) + message)) {
std::stringstream msg;
msg << typeToString(t) << ": " << message << std::endl;
Logger::warning(STATUStag, tag, originToString(o)) << msg.str() << std::flush;
}
Status::Status(Origin o, ErrType t, const std::string& tag, const std::string& message, Status parent)
: description(new Description(o, t, Logger::concatenateTags(tag) + message, parent)) {
std::stringstream msg;
msg << typeToString(t) << ": " << description->getCurrentMessageOnly() << std::endl;
Logger::warning(STATUStag, tag, originToString(o)) << msg.str() << std::flush;
}
Status::Status() : description(nullptr) {}
Status::Status(const Status& other) : description(other.description ? new Description(*other.description) : nullptr) {}
std::string Status::getErrorMessage() const {
if (description) {
return description->getCurrentMessageOnly();
}
assert(false);
return "";
}
Origin Status::getOrigin() const {
if (description) {
return description->getOrigin();
}
assert(false);
return Origin::Unspecified;
}
ErrType Status::getType() const {
if (description) {
return description->getType();
}
assert(false);
return ErrType::None;
}
std::string Status::getOriginString() const { return originToString(getOrigin()); }
std::string Status::getTypeString() const { return typeToString(getType()); }
bool Status::hasCause() const {
if (description) {
if (description->hasCause()) {
return !description->getCause()->ok();
}
}
return false;
}
const Status& Status::getCause() const {
if (hasCause()) {
return *description->getCause();
}
return *this;
}
bool Status::hasUnderlyingCause(ErrType t) const {
if (getType() == t) {
return true;
} else if (hasCause()) {
return description->getCause()->hasUnderlyingCause(t);
} else {
return false;
}
}
Status::~Status() { delete description; }
} // namespace VideoStitch