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)
233 this->resolutionX = resolutionX;
234 this->resolutionY = resolutionY;
243 void setFps(
int fps) { this->fps = fps; }
289 SensorInfo() : m_pInfo(NULL), m_videoModes(NULL, 0) {}
291 SensorInfo(
const OniSensorInfo* pInfo) : m_pInfo(NULL), m_videoModes(NULL, 0)
296 void _setInternal(
const OniSensorInfo* pInfo)
301 m_videoModes._setData(NULL, 0);
305 m_videoModes._setData(static_cast<VideoMode*>(pInfo->pSupportedVideoModes), pInfo->numSupportedVideoModes);
309 const OniSensorInfo* m_pInfo;
310 Array<VideoMode> m_videoModes;
332 const char*
getUri()
const {
return uri; }
386 _setFrame(other.m_pFrame);
396 _setFrame(other.m_pFrame);
407 return m_pFrame->dataSize;
417 return m_pFrame->data;
440 return static_cast<const VideoMode&
>(m_pFrame->videoMode);
452 return m_pFrame->timestamp;
467 return m_pFrame->frameIndex;
478 return m_pFrame->width;
488 return m_pFrame->height;
497 return m_pFrame->croppingEnabled == TRUE;
506 return m_pFrame->cropOriginX;
515 return m_pFrame->cropOriginY;
525 return m_pFrame->stride;
533 return m_pFrame != NULL;
542 if (m_pFrame != NULL)
544 oniFrameRelease(m_pFrame);
550 void _setFrame(OniFrame* pFrame)
552 setReference(pFrame);
555 oniFrameAddRef(pFrame);
560 OniFrame* _getFrame()
567 inline void setReference(OniFrame* pFrame)
601 class CameraSettings;
631 static void ONI_CALLBACK_TYPE callback(OniStreamHandle streamHandle,
void* pCookie)
635 stream._setHandle(streamHandle);
637 stream._setHandle(NULL);
639 OniCallbackHandle m_callbackHandle;
646 VideoStream() : m_stream(NULL), m_sensorInfo(), m_pCameraSettings(NULL)
664 return m_stream != NULL;
708 return (
Status)oniStreamStart(m_stream);
721 oniStreamStop(m_stream);
742 Status rc = (
Status)oniStreamReadFrame(m_stream, &pOniFrame);
744 pFrame->setReference(pOniFrame);
761 if (pListener->m_callbackHandle != NULL)
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;
1129 class PlaybackControl;
1154 Device() : m_pPlaybackControl(NULL), m_device(NULL)
1165 if (m_device != NULL)
1207 inline void close();
1220 return m_deviceInfo;
1233 for (i = 0; (i < ONI_MAX_SENSORS) && (m_aSensorInfo[i].m_pInfo != NULL); ++i)
1235 if (m_aSensorInfo[i].getSensorType() == sensorType)
1241 if (i == ONI_MAX_SENSORS)
1246 const OniSensorInfo* pInfo = oniDeviceGetSensorInfo(m_device, (OniSensorType)sensorType);
1253 m_aSensorInfo[i]._setInternal(pInfo);
1268 for (i = 0; (i < ONI_MAX_SENSORS) && (m_aSensorInfo[i].m_pInfo != NULL); ++i)
1270 if (m_aSensorInfo[i].getSensorType() == sensorType)
1272 return &m_aSensorInfo[i];
1277 if (i == ONI_MAX_SENSORS)
1282 const OniSensorInfo* pInfo = oniDeviceGetSensorInfo(m_device, (OniSensorType)sensorType);
1288 m_aSensorInfo[i]._setInternal(pInfo);
1289 return &m_aSensorInfo[i];
1296 OniDeviceHandle _getHandle()
const
1320 return (
Status)oniDeviceGetProperty(m_device, propertyId, data, dataSize);
1336 return (
Status)oniDeviceSetProperty(m_device, propertyId, data, dataSize);
1348 return (oniDeviceIsImageRegistrationModeSupported(m_device, (OniImageRegistrationMode)mode) == TRUE);
1361 Status rc = getProperty<ImageRegistrationMode>(DEVICE_PROPERTY_IMAGE_REGISTRATION, &mode);
1384 return setProperty<ImageRegistrationMode>(DEVICE_PROPERTY_IMAGE_REGISTRATION, mode);
1393 return m_device != NULL;
1421 rc = (
Status)oniDeviceEnableDepthColorSync(m_device);
1425 oniDeviceDisableDepthColorSync(m_device);
1444 return setProperty(propertyId, &value,
sizeof(T));
1459 int size =
sizeof(T);
1470 return oniDeviceIsPropertySupported(m_device, propertyId) == TRUE;
1484 return (
Status)oniDeviceInvoke(m_device, commandId, data, dataSize);
1499 return invoke(propertyId, &value,
sizeof(T));
1509 return oniDeviceIsCommandSupported(m_device, commandId) == TRUE;
1518 for (
int i = 0; i < ONI_MAX_SENSORS; ++i)
1520 m_aSensorInfo[i]._setInternal(NULL);
1524 Status _setHandle(OniDeviceHandle deviceHandle)
1526 if (m_device == NULL)
1528 m_device = deviceHandle;
1532 oniDeviceGetInfo(m_device, &m_deviceInfo);
1541 PlaybackControl* m_pPlaybackControl;
1543 OniDeviceHandle m_device;
1544 DeviceInfo m_deviceInfo;
1545 SensorInfo m_aSensorInfo[ONI_MAX_SENSORS];
1602 Status rc = m_pDevice->
getProperty<
float>(DEVICE_PROPERTY_PLAYBACK_SPEED, &speed);
1622 return m_pDevice->
setProperty<
float>(DEVICE_PROPERTY_PLAYBACK_SPEED, speed);
1638 Status rc = m_pDevice->
getProperty<OniBool>(DEVICE_PROPERTY_PLAYBACK_REPEAT_ENABLED, &repeat);
1644 return repeat == TRUE;
1662 return m_pDevice->
setProperty<OniBool>(DEVICE_PROPERTY_PLAYBACK_REPEAT_ENABLED, repeat ? TRUE : FALSE);
1682 seek.frameIndex = frameIndex;
1683 seek.stream = stream._getHandle();
1684 return m_pDevice->
invoke(DEVICE_COMMAND_SEEK, seek);
1697 int numOfFrames = -1;
1698 Status rc = stream.
getProperty<
int>(STREAM_PROPERTY_NUMBER_OF_FRAMES, &numOfFrames);
1708 return m_pDevice != NULL;
1731 if (pDevice != NULL)
1746 return setProperty(STREAM_PROPERTY_AUTO_EXPOSURE, enabled ? TRUE : FALSE);
1750 return setProperty(STREAM_PROPERTY_AUTO_WHITE_BALANCE, enabled ? TRUE : FALSE);
1755 OniBool enabled = FALSE;
1757 Status rc = getProperty(STREAM_PROPERTY_AUTO_EXPOSURE, &enabled);
1758 return rc ==
STATUS_OK && enabled == TRUE;
1762 OniBool enabled = FALSE;
1764 Status rc = getProperty(STREAM_PROPERTY_AUTO_WHITE_BALANCE, &enabled);
1765 return rc ==
STATUS_OK && enabled == TRUE;
1771 Status getProperty(
int propertyId, T* value)
const
1775 return m_pStream->
getProperty<T>(propertyId, value);
1778 Status setProperty(
int propertyId,
const T& value)
1782 return m_pStream->
setProperty<T>(propertyId, value);
1788 m_pStream = pStream;
1831 m_deviceConnectedCallbacks.deviceConnected = deviceConnectedCallback;
1832 m_deviceConnectedCallbacks.deviceDisconnected = NULL;
1833 m_deviceConnectedCallbacks.deviceStateChanged = NULL;
1834 m_deviceConnectedCallbacksHandle = NULL;
1849 static void ONI_CALLBACK_TYPE deviceConnectedCallback(
const OniDeviceInfo* pInfo,
void* pCookie)
1856 OniDeviceCallbacks m_deviceConnectedCallbacks;
1857 OniCallbackHandle m_deviceConnectedCallbacksHandle;
1881 m_deviceDisconnectedCallbacks.deviceConnected = NULL;
1882 m_deviceDisconnectedCallbacks.deviceDisconnected = deviceDisconnectedCallback;
1883 m_deviceDisconnectedCallbacks.deviceStateChanged = NULL;
1884 m_deviceDisconnectedCallbacksHandle = NULL;
1896 static void ONI_CALLBACK_TYPE deviceDisconnectedCallback(
const OniDeviceInfo* pInfo,
void* pCookie)
1903 OniDeviceCallbacks m_deviceDisconnectedCallbacks;
1904 OniCallbackHandle m_deviceDisconnectedCallbacksHandle;
1924 m_deviceStateChangedCallbacks.deviceConnected = NULL;
1925 m_deviceStateChangedCallbacks.deviceDisconnected = NULL;
1926 m_deviceStateChangedCallbacks.deviceStateChanged = deviceStateChangedCallback;
1927 m_deviceStateChangedCallbacksHandle = NULL;
1937 static void ONI_CALLBACK_TYPE deviceStateChangedCallback(
const OniDeviceInfo* pInfo, OniDeviceState state,
void* pCookie)
1944 OniDeviceCallbacks m_deviceStateChangedCallbacks;
1945 OniCallbackHandle m_deviceStateChangedCallbacksHandle;
1955 return (
Status)oniInitialize(ONI_API_VERSION);
1972 OniVersion version = oniGetVersion();
1991 return oniGetExtendedError();
2000 OniDeviceInfo* m_pDeviceInfos;
2001 int m_deviceInfoCount;
2002 oniGetDeviceList(&m_pDeviceInfos, &m_deviceInfoCount);
2003 deviceInfoList->_setData((
DeviceInfo*)m_pDeviceInfos, m_deviceInfoCount,
true);
2004 oniReleaseDeviceList(m_pDeviceInfos);
2017 static const int ONI_MAX_STREAMS = 50;
2018 OniStreamHandle streams[ONI_MAX_STREAMS];
2020 if (streamCount > ONI_MAX_STREAMS)
2022 printf(
"Too many streams for wait: %d > %d\n", streamCount, ONI_MAX_STREAMS);
2026 *pReadyStreamIndex = -1;
2027 for (
int i = 0; i < streamCount; ++i)
2029 if (pStreams[i] != NULL)
2031 streams[i] = pStreams[i]->_getHandle();
2038 Status rc = (
Status)oniWaitForAnyStream(streams, streamCount, pReadyStreamIndex, timeout);
2052 if (pListener->m_deviceConnectedCallbacksHandle != NULL)
2056 return (
Status)oniRegisterDeviceCallbacks(&pListener->m_deviceConnectedCallbacks, pListener, &pListener->m_deviceConnectedCallbacksHandle);
2067 if (pListener->m_deviceDisconnectedCallbacksHandle != NULL)
2071 return (
Status)oniRegisterDeviceCallbacks(&pListener->m_deviceDisconnectedCallbacks, pListener, &pListener->m_deviceDisconnectedCallbacksHandle);
2082 if (pListener->m_deviceStateChangedCallbacksHandle != NULL)
2086 return (
Status)oniRegisterDeviceCallbacks(&pListener->m_deviceStateChangedCallbacks, pListener, &pListener->m_deviceStateChangedCallbacksHandle);
2097 oniUnregisterDeviceCallbacks(pListener->m_deviceConnectedCallbacksHandle);
2098 pListener->m_deviceConnectedCallbacksHandle = NULL;
2109 oniUnregisterDeviceCallbacks(pListener->m_deviceDisconnectedCallbacksHandle);
2110 pListener->m_deviceDisconnectedCallbacksHandle = NULL;
2121 oniUnregisterDeviceCallbacks(pListener->m_deviceStateChangedCallbacksHandle);
2122 pListener->m_deviceStateChangedCallbacksHandle = NULL;
2180 float depthX, depthY, depthZ;
2181 Status rc = (
Status)oniCoordinateConverterWorldToDepth(depthStream._getHandle(), worldX, worldY, worldZ, &depthX, &depthY, &depthZ);
2182 *pDepthX = (int)depthX;
2183 *pDepthY = (int)depthY;
2200 return (
Status)oniCoordinateConverterWorldToDepth(depthStream._getHandle(), worldX, worldY, worldZ, pDepthX, pDepthY, pDepthZ);
2215 return (
Status)oniCoordinateConverterDepthToWorld(depthStream._getHandle(), float(depthX), float(depthY), float(depthZ), pWorldX, pWorldY, pWorldZ);
2230 return (
Status)oniCoordinateConverterDepthToWorld(depthStream._getHandle(), depthX, depthY, depthZ, pWorldX, pWorldY, pWorldZ);
2246 return (
Status)oniCoordinateConverterDepthToColor(depthStream._getHandle(), colorStream._getHandle(), depthX, depthY, depthZ, pColorX, pColorY);
2298 return (
Status)oniCreateRecorder(fileName, &m_recorder);
2311 return NULL != getHandle();
2330 return (
Status)oniRecorderAttachStream(
2332 stream._getHandle(),
2333 allowLossyCompression);
2348 return (
Status)oniRecorderStart(m_recorder);
2358 oniRecorderStop(m_recorder);
2369 oniRecorderDestroy(&m_recorder);
2380 OniRecorderHandle getHandle()
const
2386 OniRecorderHandle m_recorder;
2392 OniStreamHandle streamHandle;
2393 Status rc = (
Status)oniDeviceCreateStream(device._getHandle(), (OniSensorType)sensorType, &streamHandle);
2399 _setHandle(streamHandle);
2416 if (m_pCameraSettings != NULL)
2418 delete m_pCameraSettings;
2419 m_pCameraSettings = NULL;
2422 if (m_stream != NULL)
2424 oniStreamDestroy(m_stream);
2431 OniDeviceHandle deviceHandle;
2438 _setHandle(deviceHandle);
2450 if (m_pPlaybackControl != NULL)
2452 delete m_pPlaybackControl;
2453 m_pPlaybackControl = NULL;
2456 if (m_device != NULL)
2458 oniDeviceClose(m_device);
2466 #endif // _OPEN_NI_HPP_