XnStatus XnSensorImageGenerator::SetPixelFormat(XnPixelFormat Format) { if (GetPixelFormat() == Format) { return (XN_STATUS_OK); } XN_PROPERTY_SET_CREATE_ON_STACK(props); XnStatus nRetVal = XnPropertySetAddModule(&props, m_strModule); XN_IS_STATUS_OK(nRetVal); XnOutputFormats OutputFormat; XnUInt32* anAllowedInputFormats = NULL; XnUInt32 nAllowedInputFormats = 0; switch (Format) { case XN_PIXEL_FORMAT_RGB24: OutputFormat = XN_OUTPUT_FORMAT_RGB24; anAllowedInputFormats = g_anAllowedRGBFormats; nAllowedInputFormats = sizeof(g_anAllowedRGBFormats)/sizeof(XnUInt32); break; case XN_PIXEL_FORMAT_YUV422: OutputFormat = XN_OUTPUT_FORMAT_YUV422; anAllowedInputFormats = g_anAllowedYUVFormats; nAllowedInputFormats = sizeof(g_anAllowedYUVFormats)/sizeof(XnUInt32); break; case XN_PIXEL_FORMAT_GRAYSCALE_8_BIT: OutputFormat = XN_OUTPUT_FORMAT_GRAYSCALE8; anAllowedInputFormats = g_anAllowedGray8Formats; nAllowedInputFormats = sizeof(g_anAllowedGray8Formats)/sizeof(XnUInt32); break; case XN_PIXEL_FORMAT_MJPEG: OutputFormat = XN_OUTPUT_FORMAT_JPEG; anAllowedInputFormats = g_anAllowedJPEGFormats; nAllowedInputFormats = sizeof(g_anAllowedJPEGFormats)/sizeof(XnUInt32); break; default: return XN_STATUS_INVALID_OPERATION; } XnUInt32 nInputFormat = FindSupportedInputFormat(anAllowedInputFormats, nAllowedInputFormats); if (nInputFormat == INVALID_INPUT_FORMAT) { XN_LOG_WARNING_RETURN(XN_STATUS_DEVICE_BAD_PARAM, XN_MASK_DEVICE_SENSOR, "Cannot set pixel format to %s - no matching input format.", xnPixelFormatToString(Format)); } XnPropertySetAddIntProperty(&props, m_strModule, XN_STREAM_PROPERTY_INPUT_FORMAT, (XnUInt64)nInputFormat); XnPropertySetAddIntProperty(&props, m_strModule, XN_STREAM_PROPERTY_OUTPUT_FORMAT, (XnUInt64)OutputFormat); return m_pSensor->BatchConfig(&props); }
XnStatus XnSensorImageGenerator::SetPixelFormat(XnPixelFormat Format) { if (GetPixelFormat() == Format) { return (XN_STATUS_OK); } XnUInt64 nCurrentInputFormat; GetIntProperty(XN_STREAM_PROPERTY_INPUT_FORMAT, nCurrentInputFormat); XN_PROPERTY_SET_CREATE_ON_STACK(props); XnStatus nRetVal = XnPropertySetAddModule(&props, m_strModule); XN_IS_STATUS_OK(nRetVal); XnOutputFormats OutputFormat; switch (Format) { case XN_PIXEL_FORMAT_RGB24: OutputFormat = XN_OUTPUT_FORMAT_RGB24; break; case XN_PIXEL_FORMAT_YUV422: OutputFormat = XN_OUTPUT_FORMAT_YUV422; break; case XN_PIXEL_FORMAT_GRAYSCALE_8_BIT: OutputFormat = XN_OUTPUT_FORMAT_GRAYSCALE8; break; case XN_PIXEL_FORMAT_MJPEG: OutputFormat = XN_OUTPUT_FORMAT_JPEG; break; default: return XN_STATUS_INVALID_OPERATION; } if (nCurrentInputFormat != XN_IO_IMAGE_FORMAT_JPEG && OutputFormat == XN_OUTPUT_FORMAT_JPEG) { XnPropertySetAddIntProperty(&props, m_strModule, XN_STREAM_PROPERTY_INPUT_FORMAT, (XnUInt64)XN_IO_IMAGE_FORMAT_JPEG); } else if (nCurrentInputFormat == XN_IO_IMAGE_FORMAT_JPEG && OutputFormat != XN_OUTPUT_FORMAT_JPEG) { XnPropertySetAddIntProperty(&props, m_strModule, XN_STREAM_PROPERTY_INPUT_FORMAT, (XnUInt64)XN_IMAGE_STREAM_DEFAULT_INPUT_FORMAT); } XnPropertySetAddIntProperty(&props, m_strModule, XN_STREAM_PROPERTY_OUTPUT_FORMAT, (XnUInt64)OutputFormat); return m_pSensor->BatchConfig(&props); }
XnStatus XnSensorAudioGenerator::SetWaveOutputMode(const XnWaveOutputMode& OutputMode) { XnStatus nRetVal = XN_STATUS_OK; if (OutputMode.nBitsPerSample != 16) { return XN_STATUS_INVALID_OPERATION; } XN_PROPERTY_SET_CREATE_ON_STACK(props); XnPropertySetAddModule(&props, m_strModule); XnPropertySetAddIntProperty(&props, m_strModule, XN_STREAM_PROPERTY_SAMPLE_RATE, OutputMode.nSampleRate); XnPropertySetAddIntProperty(&props, m_strModule, XN_STREAM_PROPERTY_NUMBER_OF_CHANNELS, OutputMode.nChannels); nRetVal = m_pSensor->BatchConfig(&props); XN_IS_STATUS_OK(nRetVal); return (XN_STATUS_OK); }
XnStatus XnServerSession::NewStreamImpl(const XnChar* strType, const XnChar* strName, const XnPropertySet* pInitialValues) { XnStatus nRetVal = XN_STATUS_OK; xnLogVerbose(XN_MASK_SENSOR_SERVER, "Client %u requested to create stream '%s' (%s)", m_nID, strName, strType); nRetVal = m_pSensor->GetStream(strType, pInitialValues); XN_IS_STATUS_OK(nRetVal); // send client the new stream data XN_PROPERTY_SET_CREATE_ON_STACK(streamProps); XN_PROPERTY_SET_CREATE_ON_STACK(clientStreamProps); // take properties nRetVal = m_pSensor->GetAllProperties(&streamProps, FALSE, strType); XN_IS_STATUS_OK(nRetVal); // copy relevant ones nRetVal = XnPropertySetCloneModule(&streamProps, &clientStreamProps, strType, strName); XN_IS_STATUS_OK(nRetVal); // now change the state property. It should be OFF, and not the real value (each client has // its own stream state). nRetVal = XnPropertySetRemoveProperty(&clientStreamProps, strName, XN_STREAM_PROPERTY_STATE); XN_IS_STATUS_OK(nRetVal); nRetVal = XnPropertySetAddIntProperty(&clientStreamProps, strName, XN_STREAM_PROPERTY_STATE, FALSE); XN_IS_STATUS_OK(nRetVal); m_pLogger->DumpMessage("NewStream", 0, m_nID, strName); { XnAutoCSLocker lock(m_hCommLock); nRetVal = m_privateOutgoingPacker.WriteNewStream(strType, strName, &clientStreamProps); } XN_IS_STATUS_OK(nRetVal); // now add it to client data nRetVal = AddSessionModule(strName, strType); XN_IS_STATUS_OK(nRetVal); // create client stream data XnStreamData* pStreamData = NULL; nRetVal = m_pSensor->CreateStreamData(strType, &pStreamData); XN_IS_STATUS_OK(nRetVal); // and add it to set nRetVal = XnStreamDataSetAdd(m_pStreamDataSet, pStreamData); XN_IS_STATUS_OK(nRetVal); return (XN_STATUS_OK); }
XnStatus XnIntProperty::AddToPropertySet(XnPropertySet* pSet) { XnStatus nRetVal = XN_STATUS_OK; XnUInt64 nValue; nRetVal = GetValue(&nValue); XN_IS_STATUS_OK(nRetVal); nRetVal = XnPropertySetAddIntProperty(pSet, GetModule(), GetName(), nValue); XN_IS_STATUS_OK(nRetVal); return (XN_STATUS_OK); }
XN_DDK_API XnStatus XnPropertySetCloneModule(const XnPropertySet* pSource, XnPropertySet* pDest, const XnChar* strModule, const XnChar* strNewName) { XnStatus nRetVal = XN_STATUS_OK; XnActualPropertiesHash* pModuleProps = NULL; nRetVal = pSource->pData->Get(strModule, pModuleProps); XN_IS_STATUS_OK(nRetVal); nRetVal = XnPropertySetAddModule(pDest, strNewName); XN_IS_STATUS_OK(nRetVal); for (XnActualPropertiesHash::ConstIterator it = pModuleProps->Begin(); it != pModuleProps->End(); ++it) { XnProperty* pProp = it->Value(); switch (pProp->GetType()) { case XN_PROPERTY_TYPE_INTEGER: { XnActualIntProperty* pIntProp = (XnActualIntProperty*)pProp; nRetVal = XnPropertySetAddIntProperty(pDest, strNewName, pIntProp->GetName(), pIntProp->GetValue()); XN_IS_STATUS_OK(nRetVal); break; } case XN_PROPERTY_TYPE_REAL: { XnActualRealProperty* pRealProp = (XnActualRealProperty*)pProp; nRetVal = XnPropertySetAddRealProperty(pDest, strNewName, pRealProp->GetName(), pRealProp->GetValue()); XN_IS_STATUS_OK(nRetVal); break; } case XN_PROPERTY_TYPE_STRING: { XnActualStringProperty* pStrProp = (XnActualStringProperty*)pProp; nRetVal = XnPropertySetAddStringProperty(pDest, strNewName, pStrProp->GetName(), pStrProp->GetValue()); XN_IS_STATUS_OK(nRetVal); break; } case XN_PROPERTY_TYPE_GENERAL: { XnActualGeneralProperty* pGenProp = (XnActualGeneralProperty*)pProp; nRetVal = XnPropertySetAddGeneralProperty(pDest, strNewName, pGenProp->GetName(), &pGenProp->GetValue()); XN_IS_STATUS_OK(nRetVal); break; } default: XN_LOG_WARNING_RETURN(XN_STATUS_ERROR, XN_MASK_DDK, "Unknown property type: %d", pProp->GetType()); } } return (XN_STATUS_OK); }
XnStatus XnDataPacker::ReadPropertySetImpl(XnPropertySet* pPropertySet) { XnStatus nRetVal = XN_STATUS_OK; XN_VALIDATE_OBJECT_TYPE(XN_PACKED_PROPERTY_SET); XnChar strModule[XN_DEVICE_MAX_STRING_LENGTH]; // read property set marker MoveToNextObject(); while (m_pCurrentHeader->nType != XN_PACKED_PROPERTY_SET_MODULES_END_MARKER) { nRetVal = ReadString(strModule); XN_IS_STATUS_OK(nRetVal); nRetVal = XnPropertySetAddModule(pPropertySet, strModule); XN_IS_STATUS_OK(nRetVal); } // read properties XnChar strName[XN_DEVICE_MAX_STRING_LENGTH]; // read the modules end marker MoveToNextObject(); while (m_pCurrentHeader->nType != XN_PACKED_PROPERTY_SET_PROPERTIES_END_MARKER) { // read property and add it to set switch (m_pCurrentHeader->nType) { case XN_PACKED_INT_PROPERTY: { XnUInt64 nValue; nRetVal = ReadPropertyImpl(strModule, strName, &nValue); XN_IS_STATUS_OK(nRetVal); nRetVal = XnPropertySetAddIntProperty(pPropertySet, strModule, strName, nValue); XN_IS_STATUS_OK(nRetVal); break; } case XN_PACKED_REAL_PROPERTY: { XnDouble dValue; nRetVal = ReadPropertyImpl(strModule, strName, &dValue); XN_IS_STATUS_OK(nRetVal); nRetVal = XnPropertySetAddRealProperty(pPropertySet, strModule, strName, dValue); XN_IS_STATUS_OK(nRetVal); break; } case XN_PACKED_STRING_PROPERTY: { XnChar strValue[XN_DEVICE_MAX_STRING_LENGTH]; nRetVal = ReadPropertyImpl(strModule, strName, strValue); XN_IS_STATUS_OK(nRetVal); nRetVal = XnPropertySetAddStringProperty(pPropertySet, strModule, strName, strValue); XN_IS_STATUS_OK(nRetVal); break; } case XN_PACKED_GENERAL_PROPERTY: { XnGeneralBuffer gbValue; nRetVal = ReadPropertyImpl(strModule, strName, &gbValue); XN_IS_STATUS_OK(nRetVal); nRetVal = XnPropertySetAddGeneralProperty(pPropertySet, strModule, strName, &gbValue); XN_IS_STATUS_OK(nRetVal); break; } default: XN_LOG_WARNING_RETURN(XN_STATUS_ERROR, XN_MASK_DDK, "Stream contains an object of type %d in the middle of a property set!", m_pCurrentHeader->nType); } } // props loop // read properties end marker MoveToNextObject(); return (XN_STATUS_OK); }