This repository was archived by the owner on Feb 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathCameraDevice.h
397 lines (358 loc) · 11 KB
/
CameraDevice.h
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
/*
* This file is part of the Dronecode Camera Manager
*
* Copyright (C) 2017 Intel Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
//#include "CameraComponent.h"
#include <functional>
#include <vector>
#include "CameraParameters.h"
/**
* The CameraInfo structure is used to hold the camera device information.
*/
struct CameraInfo {
uint8_t vendorName[32]; /**< Name of the camera device vendor. */
uint8_t modelName[32]; /**< Name of the camera device model. */
uint32_t firmware_version; /**< Firmware version. */
float focal_length; /**< Focal length. */
float sensor_size_h; /**< Sensor size horizontol. */
float sensor_size_v; /**< Sensor size vertical. */
uint16_t resolution_h; /**< Resolution horizontol. */
uint16_t resolution_v; /**< Resolution vertical. */
uint8_t lens_id; /**< Lens ID. */
uint32_t flags; /**< Flags */
uint16_t cam_definition_version; /**< Camera Definition file version */
char cam_definition_uri[140]; /**< Camera Definition file URI address */
};
/**
* The CameraData structure is used to hold the camera image data and its
* meta-data.
*/
struct CameraData {
uint32_t sec = 0; /**< system time in sec. */
uint32_t nsec = 0; /**< system time in nano sec. */
uint32_t width = 0; /**< width of the image. */
uint32_t height = 0; /**< height of the image. */
uint32_t stride = 0; /**< stride. */
// CameraDevice::PixelFormat pixFmt = 0; /**< pixel format of the image. */
void *buf = nullptr; /**< buffer address. */
size_t bufSize = 0; /**< buffer size. */
};
/**
* The CameraDevice class is base for different camera devices.
*/
class CameraDevice {
private:
std::string mCamGstRTSPPipeline;
public:
CameraDevice() {}
virtual ~CameraDevice() {}
/**
* Possible return values from class methods.
*/
enum class Status {
SUCCESS,
ERROR_UNKNOWN,
INVALID_ARGUMENT,
INVALID_STATE,
NO_MEMORY,
PERM_DENIED,
TIMED_OUT,
NOT_SUPPORTED
};
/**
* Possible states of the object.
*/
enum class State {
STATE_ERROR,
STATE_IDLE,
STATE_INIT,
STATE_RUN,
};
/**
* Size of the camera image.
*/
struct Size {
uint32_t width;
uint32_t height;
Size()
{
width = 0;
height = 0;
}
Size(uint32_t w, uint32_t h)
{
width = w;
height = h;
}
};
/**
* Get the identifier of the Camera Device.
*
* @return string Camera device Id.
*/
virtual std::string getDeviceId() const = 0;
/**
* Get camera device information.
*
* @param[out] camInfo Camera Information
*
* @return Status of request.
*/
virtual Status getInfo(CameraInfo &camInfo) const = 0;
/**
* Check if gstreamer v4l2src element can be used to capture from the Camera Device.
*
* @return bool True if gstreamer v4l2src element supported, otherwise false
*/
virtual bool isGstV4l2Src() const = 0;
/**
* Initialize camera device.
*
* @param[out] camParam Camera Parameters with default values filled
*
* @return Status of request.
*/
virtual Status init(CameraParameters &camParam) = 0;
/**
* Uninitialize camera device.
*
* @return Status of request.
*/
virtual Status uninit() = 0;
/**
* Start camera device.
*
* @return Status of request.
*/
virtual Status start() { return Status::NOT_SUPPORTED; }
/**
* Start camera device in asynchronous mode.
*
* @param[in] cb Callback function to receive camera data
*
* @return Status of request.
*/
virtual Status start(const std::function<void(CameraData &)> cb)
{
return Status::NOT_SUPPORTED;
}
/**
* Stop camera device.
*
* @return Status of request.
*/
virtual Status stop() { return Status::NOT_SUPPORTED; }
/**
* Read camera images from camera device.
*
* @param[out] data CameraData to hold image and meta-data.
*
* @return Status of request.
*/
virtual Status read(CameraData &data) { return Status::NOT_SUPPORTED; }
/**
* Set parameter of the camera device.
*
* @param[in,out] camParam Camera Parameters.
* @param[in] param Name of the parameter.
* @param[in] param_value Value of the parameter to be set.
* @param[in] value_size Length of the value of the parameter.
* @param[in] param_type Type of the parameter.
*
* @return Status of request.
*/
virtual Status setParam(CameraParameters &camParam, const std::string param,
const char *param_value, const size_t value_size, const int param_type)
{
return Status::NOT_SUPPORTED;
}
/**
* Reset parameters of the camera device to default.
*
* @param[in] camParam Camera Parameters.
*
* @return Status of request.
*/
virtual Status resetParams(CameraParameters &camParam) { return Status::NOT_SUPPORTED; }
/**
* Set camera image resolution.
*
* @param[in] width Width of the output image to be set.
* @param[in] height Height of the output image to be set.
*
* @return Status of request.
*/
virtual Status setSize(const uint32_t width, const uint32_t height)
{
return Status::NOT_SUPPORTED;
}
/**
* Get camera image resolution.
*
* @param[out] width Width of the output image set.
* @param[out] height Height of the output image set.
*
* @return Status of request.
*/
virtual Status getSize(uint32_t &width, uint32_t &height) const
{
return Status::NOT_SUPPORTED;
}
/**
* Get list of supported camera image resolution.
*
* @param[out] sizes Vector of sizes supported.
*
* @return Status of request.
*/
virtual Status getSupportedSizes(std::vector<Size> &sizes) const
{
return Status::NOT_SUPPORTED;
}
/**
* Set camera image pixel format.
*
* @param[in] format Pixel format of the output image to be set.
*
* @return Status of request.
*/
virtual Status setPixelFormat(const CameraParameters::PixelFormat format)
{
return Status::NOT_SUPPORTED;
}
/**
* Get camera image pixel format.
*
* @param[out] format Pixel format of the output image set.
*
* @return Status of request.
*/
virtual Status getPixelFormat(CameraParameters::PixelFormat &format) const
{
return Status::NOT_SUPPORTED;
}
/**
* Get supported camera image pixel format.
*
* @param[out] formats Vector of PixelFormat supported by the camera device.
*
* @return Status of request.
*/
virtual Status
getSupportedPixelFormats(std::vector<CameraParameters::PixelFormat> &formats) const
{
return Status::NOT_SUPPORTED;
}
/**
* Set mode of the camera device.
*
* @param[in] mode Camera device mode to be set.
*
* @return Status of request.
*/
virtual Status setMode(const CameraParameters::Mode mode) { return Status::NOT_SUPPORTED; }
/**
* Get mode of the camera device.
*
* @param[out] mode Camera device mode that is set.
*
* @return Status of request.
*/
virtual Status getMode(CameraParameters::Mode &mode) const { return Status::NOT_SUPPORTED; }
/**
* Get supported modes of the camera device.
*
* @param[out] modes Camera device mode that are supported.
*
* @return Status of request.
*/
virtual Status getSupportedModes(std::vector<CameraParameters::Mode> &modes) const
{
return Status::NOT_SUPPORTED;
}
/**
* Set frame rate of the camera device.
*
* @param[in] fps Frame rate per second of the camera device to be set.
*
* @return Status of request.
*/
virtual Status setFrameRate(const uint32_t fps) { return Status::NOT_SUPPORTED; }
/**
* Get frame rate of the camera device.
*
* @param[out] fps Frame rate per second of the camera device.
*
* @return Status of request.
*/
virtual Status getFrameRate(uint32_t &fps) const { return Status::NOT_SUPPORTED; }
/**
* Get range of frame rate supported by the camera device.
*
* @param[out] minFps Minimum frame rate per second that can be set.
* @param[out] maxFps Maximum frame rate per second that can be set.
*
* @return Status of request.
*/
virtual Status getSupportedFrameRates(uint32_t &minFps, uint32_t &maxFps) const
{
return Status::NOT_SUPPORTED;
}
/**
* Set URI of the camera definition file for the camera device.
*
* @param[in] uri String with absolute address of the camera definition file.
*
* @return Status of request.
*/
virtual Status setCameraDefinitionUri(const std::string uri) { return Status::NOT_SUPPORTED; }
/**
* Get URI of the camera definition file for the camera device.
* Either the camera device has some predefined/generated URI address OR received by the set
* function
*
* @return string URI address of the camera definition file.
*/
virtual std::string getCameraDefinitionUri() const { return {}; }
/**
* Get text that needs to be overlayed on camera image frames.
* This may be helpful where some text information can be overlayed on camera images read from
* the device and displayed to the user. For example, on changing the brighntess parameter to
* 100, a text like "Brightness = 100" can be displayed on the video that is getting streamed.
*
* @return string Overlay text.
*/
virtual std::string getOverlayText() const { return {}; };
/**
* Set GStreamer RTSP pipeline
*
* @param[in] uri String with GStreamer RTSP pipeline
*
* @return Status of request.
*/
virtual Status setGstRTSPPipeline(std::string pipeline)
{
mCamGstRTSPPipeline = pipeline;
return Status::SUCCESS;
};
/**
* Get GStreamer RTSP pipeline
*
* @return string GStreamer RTSP Pipeline.
*/
virtual std::string getGstRTSPPipeline() const { return mCamGstRTSPPipeline; };
};