24 #include "OniPlatform.h"
25 #include "OniProperties.h"
29 #include "OniCProperties.h"
48 #if ONI_PLATFORM != ONI_PLATFORM_WIN32
49 #pragma GCC diagnostic ignored "-Wunused-variable"
50 #pragma GCC diagnostic push
53 #if ONI_PLATFORM != ONI_PLATFORM_WIN32
54 #pragma GCC diagnostic pop
68 Array() : m_data(NULL), m_count(0), m_owner(false) {}
77 Array(
const T* data,
int count) : m_owner(false) { _setData(data, count); }
96 const T&
operator[](
int index)
const {
return m_data[index];}
108 void _setData(
const T* data,
int count,
bool isOwner =
false)
119 m_data =
new T[count];
120 memcpy((
void*)m_data, data, count*
sizeof(T));
125 Array(
const Array<T>&);
126 Array<T>& operator=(
const Array<T>&);
130 if (m_owner && m_data != NULL)
148 class CameraSettings;
149 class PlaybackControl;
242 this->resolutionX = resolutionX;
243 this->resolutionY = resolutionY;
252 void setFps(
int fps) { this->fps = fps; }
298 SensorInfo() : m_pInfo(NULL), m_videoModes(NULL, 0) {}
300 SensorInfo(
const OniSensorInfo* pInfo) : m_pInfo(NULL), m_videoModes(NULL, 0)
305 void _setInternal(
const OniSensorInfo* pInfo)
310 m_videoModes._setData(NULL, 0);
314 m_videoModes._setData(static_cast<VideoMode*>(pInfo->pSupportedVideoModes), pInfo->numSupportedVideoModes);
318 const OniSensorInfo* m_pInfo;
319 Array<VideoMode> m_videoModes;
341 const char*
getUri()
const {
return uri; }
395 _setFrame(other.m_pFrame);
405 _setFrame(other.m_pFrame);
416 return m_pFrame->dataSize;
426 return m_pFrame->data;
449 return static_cast<const VideoMode&
>(m_pFrame->videoMode);
461 return m_pFrame->timestamp;
476 return m_pFrame->frameIndex;
487 return m_pFrame->width;
497 return m_pFrame->height;
506 return m_pFrame->croppingEnabled == TRUE;
515 return m_pFrame->cropOriginX;
524 return m_pFrame->cropOriginY;
534 return m_pFrame->stride;
542 return m_pFrame != NULL;
551 if (m_pFrame != NULL)
553 oniFrameRelease(m_pFrame);
559 void _setFrame(OniFrame* pFrame)
561 setReference(pFrame);
564 oniFrameAddRef(pFrame);
569 OniFrame* _getFrame()
576 inline void setReference(OniFrame* pFrame)
635 static void ONI_CALLBACK_TYPE callback(OniStreamHandle streamHandle,
void* pCookie)
639 stream._setHandle(streamHandle);
641 stream._setHandle(NULL);
643 OniCallbackHandle m_callbackHandle;
650 VideoStream() : m_stream(NULL), m_sensorInfo(), m_pCameraSettings(NULL)
668 return m_stream != NULL;
712 return (
Status)oniStreamStart(m_stream);
725 oniStreamStop(m_stream);
746 Status rc = (
Status)oniStreamReadFrame(m_stream, &pOniFrame);
748 pFrame->setReference(pOniFrame);
766 return (
Status)oniStreamRegisterNewFrameCallback(m_stream, pListener->callback, pListener, &pListener->m_callbackHandle);
780 oniStreamUnregisterNewFrameCallback(m_stream, pListener->m_callbackHandle);
781 pListener->m_callbackHandle = NULL;
788 OniStreamHandle _getHandle()
const
816 return (
Status)oniStreamGetProperty(m_stream, propertyId, data, dataSize);
836 return (
Status)oniStreamSetProperty(m_stream, propertyId, data, dataSize);
848 getProperty<OniVideoMode>(STREAM_PROPERTY_VIDEO_MODE,
static_cast<OniVideoMode*
>(&videoMode));
862 return setProperty<OniVideoMode>(STREAM_PROPERTY_VIDEO_MODE,
static_cast<const OniVideoMode&
>(videoMode));
873 Status rc = getProperty<int>(STREAM_PROPERTY_MAX_VALUE, &maxValue);
889 Status rc = getProperty<int>(STREAM_PROPERTY_MIN_VALUE, &minValue);
914 bool getCropping(
int* pOriginX,
int* pOriginY,
int* pWidth,
int* pHeight)
const
916 OniCropping cropping;
917 bool enabled =
false;
919 Status rc = getProperty<OniCropping>(STREAM_PROPERTY_CROPPING, &cropping);
923 *pOriginX = cropping.originX;
924 *pOriginY = cropping.originY;
925 *pWidth = cropping.width;
926 *pHeight = cropping.height;
927 enabled = (cropping.enabled == TRUE);
944 OniCropping cropping;
945 cropping.enabled =
true;
946 cropping.originX = originX;
947 cropping.originY = originY;
948 cropping.width = width;
949 cropping.height = height;
950 return setProperty<OniCropping>(STREAM_PROPERTY_CROPPING, cropping);
959 OniCropping cropping;
960 cropping.enabled =
false;
961 return setProperty<OniCropping>(STREAM_PROPERTY_CROPPING, cropping);
971 Status rc = getProperty<OniBool>(STREAM_PROPERTY_MIRRORING, &enabled);
976 return enabled == TRUE;
986 return setProperty<OniBool>(STREAM_PROPERTY_MIRRORING, isEnabled ? TRUE : FALSE);
995 float horizontal = 0;
996 getProperty<float>(STREAM_PROPERTY_HORIZONTAL_FOV, &horizontal);
1007 getProperty<float>(STREAM_PROPERTY_VERTICAL_FOV, &vertical);
1023 return setProperty(propertyId, &value,
sizeof(T));
1038 int size =
sizeof(T);
1054 return oniStreamIsPropertySupported(m_stream, propertyId) == TRUE;
1073 return (
Status)oniStreamInvoke(m_stream, commandId, data, dataSize);
1088 return invoke(commandId, &value,
sizeof(T));
1103 return (
Status)oniStreamIsCommandSupported(m_stream, commandId) == TRUE;
1109 void _setHandle(OniStreamHandle stream)
1111 m_sensorInfo._setInternal(NULL);
1116 m_sensorInfo._setInternal(oniStreamGetSensorInfo(m_stream));
1124 OniStreamHandle m_stream;
1125 SensorInfo m_sensorInfo;
1126 CameraSettings* m_pCameraSettings;
1152 Device() : m_pPlaybackControl(NULL), m_device(NULL)
1163 if (m_device != NULL)
1205 inline void close();
1218 return m_deviceInfo;
1231 for (i = 0; (i < ONI_MAX_SENSORS) && (m_aSensorInfo[i].m_pInfo != NULL); ++i)
1233 if (m_aSensorInfo[i].getSensorType() == sensorType)
1239 if (i == ONI_MAX_SENSORS)
1244 const OniSensorInfo* pInfo = oniDeviceGetSensorInfo(m_device, (OniSensorType)sensorType);
1251 m_aSensorInfo[i]._setInternal(pInfo);
1266 for (i = 0; (i < ONI_MAX_SENSORS) && (m_aSensorInfo[i].m_pInfo != NULL); ++i)
1268 if (m_aSensorInfo[i].getSensorType() == sensorType)
1270 return &m_aSensorInfo[i];
1275 if (i == ONI_MAX_SENSORS)
1280 const OniSensorInfo* pInfo = oniDeviceGetSensorInfo(m_device, (OniSensorType)sensorType);
1286 m_aSensorInfo[i]._setInternal(pInfo);
1287 return &m_aSensorInfo[i];
1294 OniDeviceHandle _getHandle()
const
1318 return (
Status)oniDeviceGetProperty(m_device, propertyId, data, dataSize);
1334 return (
Status)oniDeviceSetProperty(m_device, propertyId, data, dataSize);
1346 return (oniDeviceIsImageRegistrationModeSupported(m_device, (OniImageRegistrationMode)mode) == TRUE);
1359 Status rc = getProperty<ImageRegistrationMode>(DEVICE_PROPERTY_IMAGE_REGISTRATION, &mode);
1382 return setProperty<ImageRegistrationMode>(DEVICE_PROPERTY_IMAGE_REGISTRATION, mode);
1391 return m_device != NULL;
1419 rc = (
Status)oniDeviceEnableDepthColorSync(m_device);
1423 oniDeviceDisableDepthColorSync(m_device);
1442 return setProperty(propertyId, &value,
sizeof(T));
1457 int size =
sizeof(T);
1468 return oniDeviceIsPropertySupported(m_device, propertyId) == TRUE;
1482 return (
Status)oniDeviceInvoke(m_device, commandId, data, dataSize);
1497 return invoke(propertyId, &value,
sizeof(T));
1507 return oniDeviceIsCommandSupported(m_device, commandId) == TRUE;
1516 for (
int i = 0; i < ONI_MAX_SENSORS; ++i)
1518 m_aSensorInfo[i]._setInternal(NULL);
1522 Status _setHandle(OniDeviceHandle deviceHandle)
1524 if (m_device == NULL)
1526 m_device = deviceHandle;
1530 oniDeviceGetInfo(m_device, &m_deviceInfo);
1539 PlaybackControl* m_pPlaybackControl;
1541 OniDeviceHandle m_device;
1542 DeviceInfo m_deviceInfo;
1543 SensorInfo m_aSensorInfo[ONI_MAX_SENSORS];
1600 Status rc = m_pDevice->
getProperty<
float>(DEVICE_PROPERTY_PLAYBACK_SPEED, &speed);
1620 return m_pDevice->
setProperty<
float>(DEVICE_PROPERTY_PLAYBACK_SPEED, speed);
1636 Status rc = m_pDevice->
getProperty<OniBool>(DEVICE_PROPERTY_PLAYBACK_REPEAT_ENABLED, &repeat);
1642 return repeat == TRUE;
1660 return m_pDevice->
setProperty<OniBool>(DEVICE_PROPERTY_PLAYBACK_REPEAT_ENABLED, repeat ? TRUE : FALSE);
1680 seek.frameIndex = frameIndex;
1681 seek.stream = stream._getHandle();
1682 return m_pDevice->
invoke(DEVICE_COMMAND_SEEK, seek);
1695 int numOfFrames = -1;
1696 Status rc = stream.
getProperty<
int>(STREAM_PROPERTY_NUMBER_OF_FRAMES, &numOfFrames);
1706 return m_pDevice != NULL;
1729 if (pDevice != NULL)
1744 return setProperty(STREAM_PROPERTY_AUTO_EXPOSURE, enabled ? TRUE : FALSE);
1748 return setProperty(STREAM_PROPERTY_AUTO_WHITE_BALANCE, enabled ? TRUE : FALSE);
1753 OniBool enabled = FALSE;
1755 Status rc = getProperty(STREAM_PROPERTY_AUTO_EXPOSURE, &enabled);
1756 return rc ==
STATUS_OK && enabled == TRUE;
1760 OniBool enabled = FALSE;
1762 Status rc = getProperty(STREAM_PROPERTY_AUTO_WHITE_BALANCE, &enabled);
1763 return rc ==
STATUS_OK && enabled == TRUE;
1769 Status getProperty(
int propertyId, T* value)
const
1773 return m_pStream->
getProperty<T>(propertyId, value);
1776 Status setProperty(
int propertyId,
const T& value)
1780 return m_pStream->
setProperty<T>(propertyId, value);
1786 m_pStream = pStream;
1829 m_deviceConnectedCallbacks.deviceConnected = deviceConnectedCallback;
1830 m_deviceConnectedCallbacks.deviceDisconnected = NULL;
1831 m_deviceConnectedCallbacks.deviceStateChanged = NULL;
1832 m_deviceConnectedCallbacksHandle = NULL;
1847 static void ONI_CALLBACK_TYPE deviceConnectedCallback(
const OniDeviceInfo* pInfo,
void* pCookie)
1854 OniDeviceCallbacks m_deviceConnectedCallbacks;
1855 OniCallbackHandle m_deviceConnectedCallbacksHandle;
1879 m_deviceDisconnectedCallbacks.deviceConnected = NULL;
1880 m_deviceDisconnectedCallbacks.deviceDisconnected = deviceDisconnectedCallback;
1881 m_deviceDisconnectedCallbacks.deviceStateChanged = NULL;
1882 m_deviceDisconnectedCallbacksHandle = NULL;
1894 static void ONI_CALLBACK_TYPE deviceDisconnectedCallback(
const OniDeviceInfo* pInfo,
void* pCookie)
1901 OniDeviceCallbacks m_deviceDisconnectedCallbacks;
1902 OniCallbackHandle m_deviceDisconnectedCallbacksHandle;
1922 m_deviceStateChangedCallbacks.deviceConnected = NULL;
1923 m_deviceStateChangedCallbacks.deviceDisconnected = NULL;
1924 m_deviceStateChangedCallbacks.deviceStateChanged = deviceStateChangedCallback;
1925 m_deviceStateChangedCallbacksHandle = NULL;
1935 static void ONI_CALLBACK_TYPE deviceStateChangedCallback(
const OniDeviceInfo* pInfo, OniDeviceState state,
void* pCookie)
1942 OniDeviceCallbacks m_deviceStateChangedCallbacks;
1943 OniCallbackHandle m_deviceStateChangedCallbacksHandle;
1953 return (
Status)oniInitialize(ONI_API_VERSION);
1970 OniVersion version = oniGetVersion();
1989 return oniGetExtendedError();
1998 OniDeviceInfo* m_pDeviceInfos;
1999 int m_deviceInfoCount;
2000 oniGetDeviceList(&m_pDeviceInfos, &m_deviceInfoCount);
2001 deviceInfoList->_setData((
DeviceInfo*)m_pDeviceInfos, m_deviceInfoCount,
true);
2002 oniReleaseDeviceList(m_pDeviceInfos);
2015 static const int ONI_MAX_STREAMS = 50;
2016 OniStreamHandle streams[ONI_MAX_STREAMS];
2018 if (streamCount > ONI_MAX_STREAMS)
2020 printf(
"Too many streams for wait: %d > %d\n", streamCount, ONI_MAX_STREAMS);
2024 *pReadyStreamIndex = -1;
2025 for (
int i = 0; i < streamCount; ++i)
2027 if (pStreams[i] != NULL)
2029 streams[i] = pStreams[i]->_getHandle();
2036 Status rc = (
Status)oniWaitForAnyStream(streams, streamCount, pReadyStreamIndex, timeout);
2050 if (pListener->m_deviceConnectedCallbacksHandle != NULL)
2054 return (
Status)oniRegisterDeviceCallbacks(&pListener->m_deviceConnectedCallbacks, pListener, &pListener->m_deviceConnectedCallbacksHandle);
2065 if (pListener->m_deviceDisconnectedCallbacksHandle != NULL)
2069 return (
Status)oniRegisterDeviceCallbacks(&pListener->m_deviceDisconnectedCallbacks, pListener, &pListener->m_deviceDisconnectedCallbacksHandle);
2080 if (pListener->m_deviceStateChangedCallbacksHandle != NULL)
2084 return (
Status)oniRegisterDeviceCallbacks(&pListener->m_deviceStateChangedCallbacks, pListener, &pListener->m_deviceStateChangedCallbacksHandle);
2095 oniUnregisterDeviceCallbacks(pListener->m_deviceConnectedCallbacksHandle);
2096 pListener->m_deviceConnectedCallbacksHandle = NULL;
2107 oniUnregisterDeviceCallbacks(pListener->m_deviceDisconnectedCallbacksHandle);
2108 pListener->m_deviceDisconnectedCallbacksHandle = NULL;
2119 oniUnregisterDeviceCallbacks(pListener->m_deviceStateChangedCallbacksHandle);
2120 pListener->m_deviceStateChangedCallbacksHandle = NULL;
2178 float depthX, depthY, depthZ;
2179 Status rc = (
Status)oniCoordinateConverterWorldToDepth(depthStream._getHandle(), worldX, worldY, worldZ, &depthX, &depthY, &depthZ);
2180 *pDepthX = (int)depthX;
2181 *pDepthY = (int)depthY;
2198 return (
Status)oniCoordinateConverterWorldToDepth(depthStream._getHandle(), worldX, worldY, worldZ, pDepthX, pDepthY, pDepthZ);
2213 return (
Status)oniCoordinateConverterDepthToWorld(depthStream._getHandle(), float(depthX), float(depthY), float(depthZ), pWorldX, pWorldY, pWorldZ);
2228 return (
Status)oniCoordinateConverterDepthToWorld(depthStream._getHandle(), depthX, depthY, depthZ, pWorldX, pWorldY, pWorldZ);
2244 return (
Status)oniCoordinateConverterDepthToColor(depthStream._getHandle(), colorStream._getHandle(), depthX, depthY, depthZ, pColorX, pColorY);
2296 return (
Status)oniCreateRecorder(fileName, &m_recorder);
2309 return NULL != getHandle();
2328 return (
Status)oniRecorderAttachStream(
2330 stream._getHandle(),
2331 allowLossyCompression);
2346 return (
Status)oniRecorderStart(m_recorder);
2356 oniRecorderStop(m_recorder);
2367 oniRecorderDestroy(&m_recorder);
2378 OniRecorderHandle getHandle()
const
2384 OniRecorderHandle m_recorder;
2390 OniStreamHandle streamHandle;
2391 Status rc = (
Status)oniDeviceCreateStream(device._getHandle(), (OniSensorType)sensorType, &streamHandle);
2397 _setHandle(streamHandle);
2414 if (m_pCameraSettings != NULL)
2416 delete m_pCameraSettings;
2417 m_pCameraSettings = NULL;
2420 if (m_stream != NULL)
2422 oniStreamDestroy(m_stream);
2429 OniDeviceHandle deviceHandle;
2436 _setHandle(deviceHandle);
2448 if (m_pPlaybackControl != NULL)
2450 delete m_pPlaybackControl;
2451 m_pPlaybackControl = NULL;
2454 if (m_device != NULL)
2456 oniDeviceClose(m_device);
2464 #endif // _OPEN_NI_HPP_