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
// Copyright (c) 2012-2017 VideoStitch SAS
// Copyright (c) 2018 stitchEm
#pragma once
#include "config.hpp"
#include <iostream>
#include <cmath>
namespace VideoStitch {
/**
* Frame rate. http://en.wikipedia.org/wiki/Frame_rate
* @brief Defines the frame rate at which the system is functioning.
*/
struct VS_EXPORT FrameRate {
/** Double Million constant **/
static const int MILLION = 1000000;
/** Numerator */
int num;
/** Denominator */
int den;
/** default constructor, arguments are "unknown framerate" */
FrameRate(int numerator = -1, int denominator = 1) : num(numerator), den(denominator) {}
/** Equality operator
* True when framerates are valid and exactly equal or offset by an integer factor
* True when framerates are invalid and exactly equal
*/
bool operator==(const FrameRate& rhs) const {
if (num != 0 && den != 0 && rhs.num != 0 && rhs.den != 0) {
return num * rhs.den == rhs.num * den;
}
return num == rhs.num && den == rhs.den;
}
/** Equality operator */
bool operator!=(const FrameRate& rhs) const { return !(*this == rhs); }
/**
* @brief Helper method to convert frameid to timestamp
* @param frame input frame id
* @return timestamp
*/
mtime_t frameToTimestamp(frameid_t frame) const {
return (mtime_t)round((double)frame * (double)den * MILLION / (double)num);
}
/**
* @brief Helper method to convert timestamp to frameid
* @param timestamp input timestamp
* @return frameid
*/
frameid_t timestampToFrame(mtime_t timestamp) const {
return (frameid_t)round(((double)timestamp * (double)num / MILLION / (double)den));
}
};
inline std::ostream& operator<<(std::ostream& os, const FrameRate& frameRate) {
return os << frameRate.num << "/" << frameRate.den;
}
/**
* Pixel format. Also see: http://www.fourcc.org/fourcc.php
* @brief Defines the supported pixel formats in VideoStitch.
*/
enum PixelFormat {
// RGB
RGBA,
RGB,
// BGR
BGR,
BGRU,
// 4:2:2
UYVY, // 16bpp
YUY2, // 16bpp
YUV422P10, // 20bpp, planar YUV 4:2:2, (1 Cr & Cb per 2x1 Y samples)
// 4:2:0
YV12, // 12bpp, planar
NV12, // 12bpp, UV interleaved
// monochrome
Grayscale,
// monochrome 16bpp
Grayscale16,
// demosaicing
Bayer_RGGB,
Bayer_BGGR,
Bayer_GRBG,
Bayer_GBRG,
F32_C1,
// depth map encoding
DEPTH,
Unknown
};
/**
* @brief Return a string representation of a pixel format.
* This can be used when serializing/parsing a pixel format enum.
* @param pixelFormat A video stitch pixel format
* @return A string representing the pixel format
*/
VS_EXPORT const char* getStringFromPixelFormat(const PixelFormat pixelFormat);
/**
* @brief Return a Pixel format from a string.
* @param name Pixel format string name
* @return A pixel format enum
*/
VS_EXPORT PixelFormat getPixelFormatFromString(const std::string& name);
/**
* @brief Return a Frame buffer size in bytes according to Pixel format.
* @param width A video width
* @param height A video stitch pixel format
* @param pixelFormat A video stitch pixel format
* @return A Frame buffer size
*/
VS_EXPORT int32_t getFrameDataSize(const int32_t width, const int32_t height, const PixelFormat pixelFormat);
/**
* Video frame.
*/
struct Frame {
/**
* Pointer to the picture planes.
*/
void* planes[3];
/**
* Size in bytes of each picture line.
*/
size_t pitches[3];
/**
* Width of the video frame in pixels.
*/
int32_t width;
/**
* Height of the video frame in pixels.
*/
int32_t height;
/**
* Presentation timestamp in microseconds of the video frame.
*/
mtime_t pts;
/**
* Pixel format of the video frame.
*/
PixelFormat fmt;
};
} // namespace VideoStitch