Rs2StreamProps.cpp
Go to the documentation of this file.
1 #include "Rs2Driver.h"
2 #include "PS1080.h"
3 
4 static const unsigned long long GAIN_VAL = 42;
5 static const unsigned long long CONST_SHIFT_VAL = 200;
6 static const unsigned long long MAX_SHIFT_VAL = 2047;
7 static const unsigned long long PARAM_COEFF_VAL = 4;
8 static const unsigned long long SHIFT_SCALE_VAL = 10;
9 static const unsigned long long ZERO_PLANE_DISTANCE_VAL = 120;
10 static const double ZERO_PLANE_PIXEL_SIZE_VAL = 0.10520000010728836;
11 static const double EMITTER_DCMOS_DISTANCE_VAL = 7.5;
12 
13 namespace oni { namespace driver {
14 
15 OniStatus Rs2Stream::setProperty(int propertyId, const void* data, int dataSize)
16 {
18 
19  rsTraceFunc("propertyId=%d dataSize=%d", propertyId, dataSize);
20 
21  switch (propertyId)
22  {
23  case ONI_STREAM_PROPERTY_VIDEO_MODE:
24  {
25  if (data && (dataSize == sizeof(OniVideoMode)))
26  {
27  OniVideoMode* mode = (OniVideoMode*)data;
28  rsLogDebug("set video mode: %dx%d @%d format=%d",
29  (int)mode->resolutionX, (int)mode->resolutionY, (int)mode->fps, (int)mode->pixelFormat);
30 
31  if (isVideoModeSupported(mode))
32  {
33  m_videoMode = *mode;
34  return ONI_STATUS_OK;
35  }
36  }
37  break;
38  }
39 
40  case ONI_STREAM_PROPERTY_AUTO_WHITE_BALANCE:
41  {
42  if (data && dataSize == sizeof(OniBool) && m_oniType == ONI_SENSOR_COLOR)
43  {
44  Rs2Error e;
45  float value = (float)*((OniBool*)data);
47  if (e.success()) return ONI_STATUS_OK;
48  }
49  break;
50  }
51 
52  case ONI_STREAM_PROPERTY_AUTO_EXPOSURE:
53  {
54  if (data && dataSize == sizeof(OniBool) && m_oniType == ONI_SENSOR_COLOR)
55  {
56  Rs2Error e;
57  float value = (float)*((OniBool*)data);
59  if (e.success()) return ONI_STATUS_OK;
60  }
61  break;
62  }
63 
64  case ONI_STREAM_PROPERTY_EXPOSURE:
65  {
66  if (data && dataSize == sizeof(int) && m_oniType == ONI_SENSOR_COLOR)
67  {
68  Rs2Error e;
69  float value = (float)*((int*)data);
71  if (e.success()) return ONI_STATUS_OK;
72  }
73  break;
74  }
75 
76  case ONI_STREAM_PROPERTY_GAIN:
77  {
78  if (data && dataSize == sizeof(int) && m_oniType == ONI_SENSOR_COLOR)
79  {
80  Rs2Error e;
81  float value = (float)*((int*)data);
83  if (e.success()) return ONI_STATUS_OK;
84  }
85  break;
86  }
87 
88  case XN_STREAM_PROPERTY_S2D_TABLE:
89  {
90  if (data && m_oniType == ONI_SENSOR_DEPTH)
91  {
92  if (setTable(data, dataSize, m_s2d))
93  {
94  return ONI_STATUS_OK;
95  }
96  }
97  break;
98  }
99 
100  case XN_STREAM_PROPERTY_D2S_TABLE:
101  {
102  if (data && m_oniType == ONI_SENSOR_DEPTH)
103  {
104  if (setTable(data, dataSize, m_d2s))
105  {
106  return ONI_STATUS_OK;
107  }
108  }
109  break;
110  }
111 
112  default:
113  {
114  #if defined(RS2_TRACE_NOT_SUPPORTED_PROPS)
115  rsTraceError("Not supported: propertyId=%d", propertyId);
116  #endif
117  return ONI_STATUS_NOT_SUPPORTED;
118  }
119  }
120 
121  rsTraceError("propertyId=%d dataSize=%d", propertyId, dataSize);
122  return ONI_STATUS_ERROR;
123 }
124 
125 OniStatus Rs2Stream::getProperty(int propertyId, void* data, int* dataSize)
126 {
128 
129  switch (propertyId)
130  {
131  case ONI_STREAM_PROPERTY_CROPPING:
132  {
133  if (data && dataSize && *dataSize == sizeof(OniCropping))
134  {
135  OniCropping value;
136  value.enabled = false;
137  value.originX = 0;
138  value.originY = 0;
139  value.width = m_videoMode.resolutionX;
140  value.height = m_videoMode.resolutionY;
141  *((OniCropping*)data) = value;
142  return ONI_STATUS_OK;
143  }
144  break;
145  }
146 
147  case ONI_STREAM_PROPERTY_HORIZONTAL_FOV:
148  {
149  if (data && dataSize && *dataSize == sizeof(float))
150  {
151  *((float*)data) = m_fovX * 0.01745329251994329576923690768489f;
152  return ONI_STATUS_OK;
153  }
154  break;
155  }
156 
157  case ONI_STREAM_PROPERTY_VERTICAL_FOV:
158  {
159  if (data && dataSize && *dataSize == sizeof(float))
160  {
161  *((float*)data) = m_fovY * 0.01745329251994329576923690768489f;
162  return ONI_STATUS_OK;
163  }
164  break;
165  }
166 
167  case ONI_STREAM_PROPERTY_VIDEO_MODE:
168  {
169  if (data && dataSize && *dataSize == sizeof(OniVideoMode))
170  {
171  *((OniVideoMode*)data) = m_videoMode;
172  return ONI_STATUS_OK;
173  }
174  break;
175  }
176 
177  case ONI_STREAM_PROPERTY_MAX_VALUE:
178  {
179  if (data && dataSize && *dataSize == sizeof(int) && m_oniType == ONI_SENSOR_DEPTH)
180  {
181  *((int*)data) = ONI_MAX_DEPTH;
182  return ONI_STATUS_OK;
183  }
184  break;
185  }
186 
187  case ONI_STREAM_PROPERTY_MIN_VALUE:
188  {
189  if (data && dataSize && *dataSize == sizeof(int) && m_oniType == ONI_SENSOR_DEPTH)
190  {
191  *((int*)data) = 0;
192  return ONI_STATUS_OK;
193  }
194  break;
195  }
196 
197  case ONI_STREAM_PROPERTY_STRIDE:
198  {
199  if (data && dataSize && *dataSize == sizeof(int))
200  {
201  *((int*)data) = m_videoMode.resolutionX * getPixelFormatBytes(convertPixelFormat(m_videoMode.pixelFormat));
202  return ONI_STATUS_OK;
203  }
204  break;
205  }
206 
207  case ONI_STREAM_PROPERTY_MIRRORING:
208  {
209  if (data && dataSize && *dataSize == sizeof(OniBool))
210  {
211  *((OniBool*)data) = false;
212  return ONI_STATUS_OK;
213  }
214  break;
215  }
216 
217  case ONI_STREAM_PROPERTY_AUTO_WHITE_BALANCE:
218  {
219  if (data && dataSize && *dataSize == sizeof(OniBool) && m_oniType == ONI_SENSOR_COLOR)
220  {
221  Rs2Error e;
223  if (e.success())
224  {
225  *((OniBool*)data) = (int)value ? true : false;
226  return ONI_STATUS_OK;
227  }
228  }
229  break;
230  }
231 
232  case ONI_STREAM_PROPERTY_AUTO_EXPOSURE:
233  {
234  if (data && dataSize && *dataSize == sizeof(OniBool) && m_oniType == ONI_SENSOR_COLOR)
235  {
236  Rs2Error e;
238  if (e.success())
239  {
240  *((OniBool*)data) = (int)value ? true : false;
241  return ONI_STATUS_OK;
242  }
243  }
244  break;
245  }
246 
247  case ONI_STREAM_PROPERTY_EXPOSURE:
248  {
249  if (data && dataSize && *dataSize == sizeof(int) && m_oniType == ONI_SENSOR_COLOR)
250  {
251  Rs2Error e;
253  if (e.success())
254  {
255  *((int*)data) = (int)value;
256  return ONI_STATUS_OK;
257  }
258  }
259  break;
260  }
261 
262  case ONI_STREAM_PROPERTY_GAIN:
263  {
264  if (data && dataSize && *dataSize == sizeof(int) && m_oniType == ONI_SENSOR_COLOR)
265  {
266  Rs2Error e;
268  if (e.success())
269  {
270  *((int*)data) = (int)value;
271  return ONI_STATUS_OK;
272  }
273  }
274  break;
275  }
276 
277  case XN_STREAM_PROPERTY_GAIN:
278  {
279  if (data && dataSize && *dataSize == sizeof(unsigned long long) && m_oniType == ONI_SENSOR_DEPTH)
280  {
281  *((unsigned long long*)data) = GAIN_VAL;
282  return ONI_STATUS_OK;
283  }
284  break;
285  }
286 
287  case XN_STREAM_PROPERTY_CONST_SHIFT:
288  {
289  if (data && dataSize && *dataSize == sizeof(unsigned long long) && m_oniType == ONI_SENSOR_DEPTH)
290  {
291  *((unsigned long long*)data) = CONST_SHIFT_VAL;
292  return ONI_STATUS_OK;
293  }
294  break;
295  }
296 
297  case XN_STREAM_PROPERTY_MAX_SHIFT:
298  {
299  if (data && dataSize && *dataSize == sizeof(unsigned long long) && m_oniType == ONI_SENSOR_DEPTH)
300  {
301  *((unsigned long long*)data) = MAX_SHIFT_VAL;
302  return ONI_STATUS_OK;
303  }
304  break;
305  }
306 
307  case XN_STREAM_PROPERTY_PARAM_COEFF:
308  {
309  if (data && dataSize && *dataSize == sizeof(unsigned long long) && m_oniType == ONI_SENSOR_DEPTH)
310  {
311  *((unsigned long long*)data) = PARAM_COEFF_VAL;
312  return ONI_STATUS_OK;
313  }
314  break;
315  }
316 
317  case XN_STREAM_PROPERTY_SHIFT_SCALE:
318  {
319  if (data && dataSize && *dataSize == sizeof(unsigned long long) && m_oniType == ONI_SENSOR_DEPTH)
320  {
321  *((unsigned long long*)data) = SHIFT_SCALE_VAL;
322  return ONI_STATUS_OK;
323  }
324  break;
325  }
326 
327  case XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE:
328  {
329  if (data && dataSize && *dataSize == sizeof(unsigned long long) && m_oniType == ONI_SENSOR_DEPTH)
330  {
331  *((unsigned long long*)data) = ZERO_PLANE_DISTANCE_VAL;
332  return ONI_STATUS_OK;
333  }
334  break;
335  }
336 
337  case XN_STREAM_PROPERTY_ZERO_PLANE_PIXEL_SIZE:
338  {
339  if (data && dataSize && *dataSize == sizeof(double) && m_oniType == ONI_SENSOR_DEPTH)
340  {
341  *((double*)data) = ZERO_PLANE_PIXEL_SIZE_VAL;
342  return ONI_STATUS_OK;
343  }
344  break;
345  }
346 
347  case XN_STREAM_PROPERTY_EMITTER_DCMOS_DISTANCE:
348  {
349  if (data && dataSize && *dataSize == sizeof(double) && m_oniType == ONI_SENSOR_DEPTH)
350  {
351  *((double*)data) = EMITTER_DCMOS_DISTANCE_VAL;
352  return ONI_STATUS_OK;
353  }
354  break;
355  }
356 
357  case XN_STREAM_PROPERTY_S2D_TABLE:
358  {
359  if (data && dataSize && m_oniType == ONI_SENSOR_DEPTH)
360  {
361  if (getTable(data, dataSize, m_s2d))
362  {
363  return ONI_STATUS_OK;
364  }
365  }
366  break;
367  }
368 
369  case XN_STREAM_PROPERTY_D2S_TABLE:
370  {
371  if (data && dataSize && m_oniType == ONI_SENSOR_DEPTH)
372  {
373  if (getTable(data, dataSize, m_d2s))
374  {
375  return ONI_STATUS_OK;
376  }
377  }
378  break;
379  }
380 
381  default:
382  {
383  #if defined(RS2_TRACE_NOT_SUPPORTED_PROPS)
384  rsTraceError("Not supported: propertyId=%d", propertyId);
385  #endif
386  return ONI_STATUS_NOT_SUPPORTED;
387  }
388  }
389 
390  rsTraceError("propertyId=%d dataSize=%d", propertyId, *dataSize);
391  return ONI_STATUS_ERROR;
392 }
393 
394 OniBool Rs2Stream::isPropertySupported(int propertyId)
395 {
396  switch (propertyId)
397  {
398  case ONI_STREAM_PROPERTY_CROPPING: // OniCropping*
399  case ONI_STREAM_PROPERTY_HORIZONTAL_FOV: // float: radians
400  case ONI_STREAM_PROPERTY_VERTICAL_FOV: // float: radians
401  case ONI_STREAM_PROPERTY_VIDEO_MODE: // OniVideoMode*
402  case ONI_STREAM_PROPERTY_MAX_VALUE: // int
403  case ONI_STREAM_PROPERTY_MIN_VALUE: // int
404  case ONI_STREAM_PROPERTY_STRIDE: // int
405  case ONI_STREAM_PROPERTY_MIRRORING: // OniBool
406  return true;
407 
408 
409  case ONI_STREAM_PROPERTY_NUMBER_OF_FRAMES: // int
410  return false;
411 
412  case ONI_STREAM_PROPERTY_AUTO_WHITE_BALANCE: // OniBool
413  case ONI_STREAM_PROPERTY_AUTO_EXPOSURE: // OniBool
414  case ONI_STREAM_PROPERTY_EXPOSURE: // int
415  case ONI_STREAM_PROPERTY_GAIN: // int
416  return true;
417 
418  case XN_STREAM_PROPERTY_GAIN:
419  case XN_STREAM_PROPERTY_CONST_SHIFT:
420  case XN_STREAM_PROPERTY_MAX_SHIFT:
421  case XN_STREAM_PROPERTY_PARAM_COEFF:
422  case XN_STREAM_PROPERTY_SHIFT_SCALE:
423  case XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE:
424  case XN_STREAM_PROPERTY_ZERO_PLANE_PIXEL_SIZE:
425  case XN_STREAM_PROPERTY_EMITTER_DCMOS_DISTANCE:
426  case XN_STREAM_PROPERTY_S2D_TABLE:
427  case XN_STREAM_PROPERTY_D2S_TABLE:
428  return true;
429 
430  default:
431  return false;
432  }
433 }
434 
435 }} // namespace
float rs2_get_option(const rs2_options *options, rs2_option option, rs2_error **error)
Definition: rs.cpp:628
bool setTable(const void *src, int size, std::vector< uint16_t > &table)
Definition: Rs2Stream.cpp:277
std::vector< uint16_t > m_d2s
Definition: Rs2Stream.h:89
static const unsigned long long PARAM_COEFF_VAL
bool getTable(void *dst, int *size, const std::vector< uint16_t > &table)
Definition: Rs2Stream.cpp:262
virtual OniStatus setProperty(int propertyId, const void *data, int dataSize)
GLenum GLsizei dataSize
Definition: glext.h:5691
GLfloat value
rs2_sensor * m_sensor
Definition: Rs2Stream.h:74
e
Definition: rmse.py:177
#define rsTraceError(format,...)
Definition: Rs2Base.h:41
int getPixelFormatBytes(rs2_format type)
Definition: Rs2Base.cpp:61
Definition: Rs2Base.cpp:3
static const unsigned long long ZERO_PLANE_DISTANCE_VAL
GLenum mode
#define ONI_MAX_DEPTH
Definition: Rs2Base.h:17
static const double EMITTER_DCMOS_DISTANCE_VAL
#define SCOPED_PROFILER
Definition: Rs2Base.h:32
static const double ZERO_PLANE_PIXEL_SIZE_VAL
static const unsigned long long SHIFT_SCALE_VAL
#define rsLogDebug(format,...)
Definition: Rs2Base.h:43
#define rsTraceFunc(format,...)
Definition: Rs2Base.h:42
static const unsigned long long CONST_SHIFT_VAL
virtual OniBool isPropertySupported(int propertyId)
bool success() const
Definition: Rs2Base.h:58
static const unsigned long long GAIN_VAL
void rs2_set_option(const rs2_options *options, rs2_option option, float value, rs2_error **error)
Definition: rs.cpp:636
static const unsigned long long MAX_SHIFT_VAL
std::vector< uint16_t > m_s2d
Definition: Rs2Stream.h:88
OniPixelFormat convertPixelFormat(rs2_format type)
Definition: Rs2Base.cpp:76
GLboolean * data
virtual OniStatus getProperty(int propertyId, void *data, int *dataSize)
OniVideoMode m_videoMode
Definition: Rs2Stream.h:80
bool isVideoModeSupported(OniVideoMode *reqMode)
Definition: Rs2Stream.cpp:239
Definition: parser.hpp:150
OniSensorType m_oniType
Definition: Rs2Stream.h:71


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:40