XnStatus XnSensorDepthStream::CreateDataProcessor(XnDataProcessor** ppProcessor) { XnStatus nRetVal = XN_STATUS_OK; XnStreamProcessor* pNew; switch (m_InputFormat.GetValue()) { case XN_IO_DEPTH_FORMAT_UNCOMPRESSED_16_BIT: XN_VALIDATE_NEW_AND_INIT(pNew, XnUncompressedDepthProcessor, this, &m_Helper); break; case XN_IO_DEPTH_FORMAT_COMPRESSED_PS: XN_VALIDATE_NEW_AND_INIT(pNew, XnPSCompressedDepthProcessor, this, &m_Helper); break; case XN_IO_DEPTH_FORMAT_UNCOMPRESSED_11_BIT: XN_VALIDATE_NEW_AND_INIT(pNew, XnPacked11DepthProcessor, this, &m_Helper); break; default: return XN_STATUS_IO_INVALID_STREAM_DEPTH_FORMAT; } *ppProcessor = pNew; return XN_STATUS_OK; }
XnStatus XnFileDevice::CreateCodec(xn::ProductionNode& node) { XnStatus nRetVal = XN_STATUS_OK; XnNodeInfo* pNodeInfo = NULL; if (m_nodeInfoMap.Get(node.GetName(), pNodeInfo) == XN_STATUS_OK) { XnUInt64 nValue; nRetVal = node.GetIntProperty(XN_STREAM_PROPERTY_COMPRESSION, nValue); XN_IS_STATUS_OK(nRetVal); // create new one XnCodecID codecID = XnCodec::GetCodecIDFromCompressionFormat((XnCompressionFormats)nValue); if (codecID == XN_CODEC_NULL) { XN_LOG_WARNING_RETURN(XN_STATUS_CORRUPT_FILE, XN_MASK_FILE, "Invalid compression type: %llu", nValue); } if (pNodeInfo->pXnCodec == NULL || pNodeInfo->pXnCodec->GetCompressionFormat() != nValue) { // release old codec XN_DELETE(pNodeInfo->pXnCodec); if (pNodeInfo->codec.IsValid()) { xnRemoveNeededNode(GetSelfNodeHandle(), pNodeInfo->codec); pNodeInfo->codec.Release(); } // special case: IR recorded with JPEG. This mode is no longer allowed by OpenNI (JPEG // can now only be used for image). We'll have to handle it ourselves. if (node.GetInfo().GetDescription().Type == XN_NODE_TYPE_IR && codecID == XN_CODEC_JPEG) { xn::IRGenerator irGen(node); XnMapOutputMode outputMode; nRetVal = irGen.GetMapOutputMode(outputMode); XN_IS_STATUS_OK(nRetVal); XN_VALIDATE_NEW_AND_INIT(pNodeInfo->pXnCodec, XnJpegCodec, TRUE, outputMode.nXRes, outputMode.nYRes); } else { // normal case nRetVal = m_context.CreateCodec(codecID, node, pNodeInfo->codec); XN_IS_STATUS_OK(nRetVal); // we need to make the codec a needed node, so that if xnForceShutdown() is called, we will be // destroyed *before* it does (as we hold a reference to it). nRetVal = xnAddNeededNode(GetSelfNodeHandle(), pNodeInfo->codec); XN_IS_STATUS_OK(nRetVal); XN_VALIDATE_NEW(pNodeInfo->pXnCodec, XnNiCodec, pNodeInfo->codec); } } } return (XN_STATUS_OK); }
XnStatus XnSensorIRStream::CreateDataProcessor(XnDataProcessor** ppProcessor) { XnDataProcessor* pNew; XN_VALIDATE_NEW_AND_INIT(pNew, XnIRProcessor, this, &m_Helper); *ppProcessor = pNew; return (XN_STATUS_OK); }
XnStatus XnSensorAudioStream::CreateDataProcessor(XnDataProcessor** ppProcessor) { XnDataProcessor* pAudioProcessor; XN_VALIDATE_NEW_AND_INIT(pAudioProcessor, XnAudioProcessor, this, &m_Helper, &m_buffer, m_nOrigAudioPacketSize); *ppProcessor = pAudioProcessor; return XN_STATUS_OK; }
XnStatus XnSensorIRStream::CreateDataProcessor(XnDataProcessor** ppProcessor) { XnStatus nRetVal = XN_STATUS_OK; XnFrameBufferManager* pBufferManager; nRetVal = GetTripleBuffer(&pBufferManager); XN_IS_STATUS_OK(nRetVal); XnDataProcessor* pNew; XN_VALIDATE_NEW_AND_INIT(pNew, XnIRProcessor, this, &m_Helper, pBufferManager); *ppProcessor = pNew; return (XN_STATUS_OK); }
XnStatus XnSensorImageStream::CreateDataProcessor(XnDataProcessor** ppProcessor) { XnStreamProcessor* pNew; switch (m_InputFormat.GetValue()) { case XN_IO_IMAGE_FORMAT_BAYER: XN_VALIDATE_NEW_AND_INIT(pNew, XnBayerImageProcessor, this, &m_Helper); break; case XN_IO_IMAGE_FORMAT_YUV422: XN_VALIDATE_NEW_AND_INIT(pNew, XnPSCompressedImageProcessor, this, &m_Helper); break; case XN_IO_IMAGE_FORMAT_JPEG: if (GetOutputFormat() == XN_OUTPUT_FORMAT_JPEG) { XN_VALIDATE_NEW_AND_INIT(pNew, XnJpegImageProcessor, this, &m_Helper); } else if (GetOutputFormat() == XN_OUTPUT_FORMAT_RGB24) { XN_VALIDATE_NEW_AND_INIT(pNew, XnJpegToRGBImageProcessor, this, &m_Helper); } else { XN_LOG_WARNING_RETURN(XN_STATUS_BAD_PARAM, XN_MASK_DEVICE_SENSOR, "invalid output format %d!", GetOutputFormat()); } break; case XN_IO_IMAGE_FORMAT_UNCOMPRESSED_YUV422: if (GetOutputFormat() == XN_OUTPUT_FORMAT_YUV422) { XN_VALIDATE_NEW_AND_INIT(pNew, XnUncompressedYUVImageProcessor, this, &m_Helper); } else if (GetOutputFormat() == XN_OUTPUT_FORMAT_RGB24) { XN_VALIDATE_NEW_AND_INIT(pNew, XnUncompressedYUVtoRGBImageProcessor, this, &m_Helper); } else { XN_LOG_WARNING_RETURN(XN_STATUS_BAD_PARAM, XN_MASK_DEVICE_SENSOR, "invalid output format %d!", GetOutputFormat()); } break; case XN_IO_IMAGE_FORMAT_UNCOMPRESSED_BAYER: XN_VALIDATE_NEW_AND_INIT(pNew, XnUncompressedBayerProcessor, this, &m_Helper); break; default: return XN_STATUS_IO_INVALID_STREAM_IMAGE_FORMAT; } *ppProcessor = pNew; return XN_STATUS_OK; }
XnStatus XnDeviceFileWriter::CreateIOStreamImpl(const XnChar* strConnectionString, XnIOStream*& pStream) { XnStatus nRetVal = XN_STATUS_OK; XN_VALIDATE_NEW_AND_INIT(pStream, XnIOFileStream, strConnectionString, XN_OS_FILE_WRITE | XN_OS_FILE_TRUNCATE); // write down the magic nRetVal = pStream->WriteData((const XnUChar*)XN_DEVICE_FILE_MAGIC_V4, (XnUInt32)strlen(XN_DEVICE_FILE_MAGIC_V4)); if (nRetVal != XN_STATUS_OK) { XN_DELETE(pStream); pStream = NULL; return (nRetVal); } return (XN_STATUS_OK); }
XnStatus XnDeviceFileReader::CreateIOStreamImpl(const XnChar* strConnectionString, XnIOStream*& pStream) { XnStatus nRetVal = XN_STATUS_OK; // open file XN_VALIDATE_NEW_AND_INIT(pStream, XnIOFileStream, strConnectionString, XN_OS_FILE_READ); // read version nRetVal = ReadFileVersion(); if (nRetVal != XN_STATUS_OK) { XN_DELETE(pStream); pStream = NULL; return (nRetVal); } return (XN_STATUS_OK); }
XnStatus ExportedRecorder::Create(xn::Context& context, const XnChar* strInstanceName, const XnChar* strCreationInfo, xn::NodeInfoList* pNeededTrees, const XnChar* strConfigurationDir, xn::ModuleProductionNode** ppInstance) { XnStatus nRetVal = XN_STATUS_OK; XN_VALIDATE_INPUT_PTR(strInstanceName); XN_VALIDATE_INPUT_PTR(strCreationInfo); XN_VALIDATE_OUTPUT_PTR(ppInstance); nRetVal = xnOSStrCopy(m_strInstanceName, strInstanceName, sizeof(m_strInstanceName)); XN_IS_STATUS_OK(nRetVal); if (strcmp(strCreationInfo, CREATION_INFO) != 0) { //This is not the creation info we gave in EnumerateProductionTrees XN_LOG_ERROR_RETURN(XN_STATUS_NO_MATCH, XN_MASK_OPEN_NI, "Invalid creation info"); } RecorderNode *pRecorderNode; XN_VALIDATE_NEW_AND_INIT(pRecorderNode, RecorderNode, context); *ppInstance = pRecorderNode; return XN_STATUS_OK; }
//--------------------------------------------------------------------------- // Code //--------------------------------------------------------------------------- XnStatus XnCodecFactory::Create(XnCompressionFormats nFormat, XnDeviceModule* pStream, const XnChar* /*StreamName*/, XnCodec** ppCodec) { XnStatus nRetVal = XN_STATUS_OK; XnCodec* pCodec = NULL; switch (nFormat) { case XN_COMPRESSION_NONE: { XN_VALIDATE_NEW_AND_INIT(pCodec, XnUncompressedCodec); } break; case XN_COMPRESSION_16Z: { XN_VALIDATE_NEW_AND_INIT(pCodec, Xn16zCodec); } break; case XN_COMPRESSION_16Z_EMB_TABLE: { // first we need to find max depth XnUInt64 nMaxDepth; nRetVal = pStream->GetProperty(XN_STREAM_PROPERTY_MAX_DEPTH, &nMaxDepth); XN_IS_STATUS_OK(nRetVal); XN_VALIDATE_NEW_AND_INIT(pCodec, Xn16zEmbTablesCodec, (XnDepthPixel)nMaxDepth); } break; case XN_COMPRESSION_COLOR_8Z: { XN_VALIDATE_NEW_AND_INIT(pCodec, Xn8zCodec); } break; case XN_COMPRESSION_JPEG: { // check what is the output format XnUInt64 nOutputFormat; nRetVal = pStream->GetProperty(XN_STREAM_PROPERTY_OUTPUT_FORMAT, &nOutputFormat); XN_IS_STATUS_OK(nRetVal); XnBool bRGB = FALSE; switch (nOutputFormat) { case XN_OUTPUT_FORMAT_GRAYSCALE8: bRGB = FALSE; break; case XN_OUTPUT_FORMAT_RGB24: bRGB = TRUE; break; default: XN_LOG_WARNING_RETURN(XN_STATUS_ERROR, XN_MASK_DDK, "Codec factory currently supports JPEG codec only for streams of type Gray8 or RGB24!"); } // take X and Y res XnUInt64 nXRes, nYRes; nRetVal = pStream->GetProperty(XN_STREAM_PROPERTY_X_RES, &nXRes); XN_IS_STATUS_OK(nRetVal); nRetVal = pStream->GetProperty(XN_STREAM_PROPERTY_Y_RES, &nYRes); XN_IS_STATUS_OK(nRetVal); XN_VALIDATE_NEW_AND_INIT(pCodec, XnJpegCodec, bRGB, (XnUInt32)nXRes, (XnUInt32)nYRes); } break; default: XN_LOG_WARNING_RETURN(XN_STATUS_ERROR, XN_MASK_DDK, "Codec factory does not support compression type %d", nFormat); } *ppCodec = pCodec; return (XN_STATUS_OK); }
XnStatus XnStreamDeviceStreamHolder::ChooseCodec() { XnStatus nRetVal = XN_STATUS_OK; // create new codec (we also need to register on all the properties) XnCodec* pCodec; XnPropertiesList CodecProps; switch (GetCompression()) { case XN_COMPRESSION_NONE: { XN_VALIDATE_NEW_AND_INIT(pCodec, XnUncompressedCodec); } break; case XN_COMPRESSION_16Z: { XN_VALIDATE_NEW_AND_INIT(pCodec, Xn16zCodec); } break; case XN_COMPRESSION_16Z_EMB_TABLE: { // first we need to find max depth XnIntProperty* pDeviceMaxDepthProp; nRetVal = GetStream()->GetProperty(XN_STREAM_PROPERTY_DEVICE_MAX_DEPTH, &pDeviceMaxDepthProp); XN_IS_STATUS_OK(nRetVal); XnUInt64 nMaxDepth; nRetVal = pDeviceMaxDepthProp->GetValue(&nMaxDepth); XN_IS_STATUS_OK(nRetVal); nRetVal = CodecProps.AddLast(pDeviceMaxDepthProp); XN_IS_STATUS_OK(nRetVal); XN_VALIDATE_NEW_AND_INIT(pCodec, Xn16zEmbTablesCodec, (XnDepthPixel)nMaxDepth); } break; case XN_COMPRESSION_COLOR_8Z: { XN_VALIDATE_NEW_AND_INIT(pCodec, Xn8zCodec); } break; case XN_COMPRESSION_JPEG: { // check what is the output format XnIntProperty* pOutputFormatProp; nRetVal = GetStream()->GetProperty(XN_STREAM_PROPERTY_OUTPUT_FORMAT, &pOutputFormatProp); XN_IS_STATUS_OK(nRetVal); XnUInt64 nOutputFormat; nRetVal = pOutputFormatProp->GetValue(&nOutputFormat); XN_IS_STATUS_OK(nRetVal); XnBool bRGB = FALSE; switch (nOutputFormat) { case XN_OUTPUT_FORMAT_GRAYSCALE8: bRGB = FALSE; break; case XN_OUTPUT_FORMAT_RGB24: bRGB = TRUE; break; default: XN_LOG_WARNING_RETURN(XN_STATUS_ERROR, XN_MASK_DDK, "Codec factory currently supports JPEG codec only for streams of type Gray8 or RGB24!"); } nRetVal = CodecProps.AddLast(pOutputFormatProp); XN_IS_STATUS_OK(nRetVal); // X res XnIntProperty* pXResProp; nRetVal = GetStream()->GetProperty(XN_STREAM_PROPERTY_X_RES, &pXResProp); XN_IS_STATUS_OK(nRetVal); XnUInt64 nXRes; nRetVal = pXResProp->GetValue(&nXRes); XN_IS_STATUS_OK(nRetVal); nRetVal = CodecProps.AddLast(pXResProp); XN_IS_STATUS_OK(nRetVal); // Y res XnIntProperty* pYResProp; nRetVal = GetStream()->GetProperty(XN_STREAM_PROPERTY_Y_RES, &pYResProp); XN_IS_STATUS_OK(nRetVal); XnUInt64 nYRes; nRetVal = pYResProp->GetValue(&nYRes); XN_IS_STATUS_OK(nRetVal); // Cropping XnGeneralProperty* pCroppingProp; nRetVal = GetStream()->GetProperty(XN_STREAM_PROPERTY_CROPPING, &pCroppingProp); XN_IS_STATUS_OK(nRetVal); XnCropping cropping; nRetVal = pCroppingProp->GetValue(XN_PACK_GENERAL_BUFFER(cropping)); XN_IS_STATUS_OK(nRetVal); nRetVal = CodecProps.AddLast(pCroppingProp); XN_IS_STATUS_OK(nRetVal); // calc x,y if (cropping.bEnabled) { nXRes = cropping.nXSize; nYRes = cropping.nYSize; } XN_VALIDATE_NEW_AND_INIT(pCodec, XnJpegCodec, bRGB, (XnUInt32)nXRes, (XnUInt32)nYRes); } break; default: XN_LOG_WARNING_RETURN(XN_STATUS_ERROR, XN_MASK_DDK, "Codec factory does not support compression type %d", GetCompression()); } // register to new props for (XnPropertiesList::Iterator it = CodecProps.Begin(); it != CodecProps.End(); ++it) { XnProperty* pProp = *it; XnPropertiesHash::Iterator hashIt = m_CodecProperties.End(); nRetVal = m_CodecProperties.Find(pProp, hashIt); if (nRetVal == XN_STATUS_NO_MATCH) { XnCallbackHandle hCallbackDummy; nRetVal = pProp->OnChangeEvent().Register(CodecPropertyChangedCallback, this, hCallbackDummy); if (nRetVal != XN_STATUS_OK) { XN_DELETE(pCodec); return (nRetVal); } nRetVal = m_CodecProperties.Set(pProp, NULL); if (nRetVal != XN_STATUS_OK) { XN_DELETE(pCodec); return (nRetVal); } } else if (nRetVal != XN_STATUS_OK) { XN_DELETE(pCodec); return (nRetVal); } } // replace it XN_DELETE(m_pCodec); m_pCodec = pCodec; return (XN_STATUS_OK); }