VideoStream* Device::createStream(OniSensorType sensorType) { OniSensorInfo* pSensorInfos; OniSensorInfo* pSensor = NULL; int numSensors = 0; getSensorInfoList(&pSensorInfos, numSensors); for (int i = 0; i < numSensors; ++i) { if (pSensorInfos[i].sensorType == sensorType) { pSensor = &pSensorInfos[i]; break; } } if (pSensor == NULL) { m_errorLogger.Append("Device: Can't find this source %d", sensorType); return NULL; } void* streamHandle = m_driverHandler.deviceCreateStream(m_deviceHandle, sensorType); if (streamHandle == NULL) { m_errorLogger.Append("Stream: couldn't create using source %d", sensorType); return NULL; } VideoStream* pStream = XN_NEW(VideoStream, streamHandle, pSensor, *this, m_driverHandler, m_errorLogger); m_streams.AddLast(pStream); if ((sensorType == ONI_SENSOR_DEPTH || sensorType == ONI_SENSOR_COLOR) && m_depthColorSyncHandle != NULL && m_pContext != NULL) { refreshDepthColorSyncState(); } return pStream; }
VideoStream* Device::createStream(OniSensorType sensorType) { OniSensorInfo* pSensorInfos; OniSensorInfo* pSensorInfo = NULL; int numSensors = 0; getSensorInfoList(&pSensorInfos, numSensors); for (int i = 0; i < numSensors; ++i) { if (pSensorInfos[i].sensorType == sensorType) { pSensorInfo = &pSensorInfos[i]; break; } } if (pSensorInfo == NULL) { m_errorLogger.Append("Device: Can't find this source %d", sensorType); return NULL; } // make sure our sensor array is big enough if ((int)sensorType >= MAX_SENSORS_PER_DEVICE) { xnLogError(XN_MASK_ONI_DEVICE, "Internal error!"); m_errorLogger.Append("Device: Can't find this source %d", sensorType); XN_ASSERT(FALSE); return NULL; } xnl::AutoCSLocker lock(m_cs); if (m_sensors[sensorType] == NULL) { m_sensors[sensorType] = XN_NEW(Sensor, m_errorLogger, m_frameManager, m_driverHandler); if (m_sensors[sensorType] == NULL) { XN_ASSERT(FALSE); return NULL; } } { // check if stream already exists. Do this in a lock to make it thread-safe xnl::AutoCSLocker lock(m_sensors[sensorType]->m_refCountCS); if (m_sensors[sensorType]->m_streamCount == 0) { void* streamHandle = m_driverHandler.deviceCreateStream(m_deviceHandle, sensorType); if (streamHandle == NULL) { m_errorLogger.Append("Stream: couldn't create using source %d", sensorType); return NULL; } m_sensors[sensorType]->setDriverStream(streamHandle); } ++m_sensors[sensorType]->m_streamCount; } VideoStream* pStream = XN_NEW(VideoStream, m_sensors[sensorType], pSensorInfo, *this, m_driverHandler, m_frameManager, m_errorLogger); m_streams.AddLast(pStream); if ((sensorType == ONI_SENSOR_DEPTH || sensorType == ONI_SENSOR_COLOR) && m_depthColorSyncHandle != NULL && m_pContext != NULL) { refreshDepthColorSyncState(); } return pStream; }