void XnFrameStreamProcessor::OnEndOfFrame(const XnSensorProtocolResponseHeader* pHeader)
{
	// write dump
	XnBuffer* pCurWriteBuffer = m_pTripleBuffer->GetWriteBuffer();
	xnDumpFileWriteBuffer(m_InternalDump, pCurWriteBuffer->GetData(), pCurWriteBuffer->GetSize());
	xnDumpFileClose(m_InternalDump);
	xnDumpFileClose(m_InDump);

	if (!m_bFrameCorrupted)
	{
		// mark the buffer as stable
		XnUInt64 nTimestamp;
		if (m_pDevicePrivateData->pSensor->ShouldUseHostTimestamps())
		{
			// use the host timestamp of the first packet
			nTimestamp = m_nFirstPacketTimestamp;
		}
		else
		{
			// use timestamp in last packet
			nTimestamp = CreateTimestampFromDevice(pHeader->nTimeStamp);
		}

		OniFrame* pFrame = m_pTripleBuffer->GetWriteFrame();
		pFrame->timestamp = nTimestamp;
		
		XnUInt32 nFrameID;
		m_pTripleBuffer->MarkWriteBufferAsStable(&nFrameID);

		// let inheriting classes do their stuff
		OnFrameReady(nFrameID, nTimestamp);
	}
	else
	{
		// restart
		m_pTripleBuffer->GetWriteBuffer()->Reset();
	}

	// log bandwidth
	XnUInt64 nSysTime;
	xnOSGetTimeStamp(&nSysTime);
	xnDumpFileWriteString(m_pDevicePrivateData->BandwidthDump, "%llu,%s,%d,%d\n", 
		nSysTime, m_csName, GetCurrentFrameID(), m_nBytesReceived);

	// re-init dumps
	m_InDump = xnDumpFileOpen(m_csInDumpMask, "%s_%d.raw", m_csInDumpMask, GetCurrentFrameID());
	m_InternalDump = xnDumpFileOpen(m_csInternalDumpMask, "%s_%d.raw", m_csInternalDumpMask, GetCurrentFrameID());
	m_nBytesReceived = 0;
}
Beispiel #2
0
XnStatus XnDeviceBase::InitImpl(const XnDeviceConfig* pDeviceConfig)
{
    XnStatus nRetVal = XN_STATUS_OK;

    XN_VALIDATE_INPUT_PTR(pDeviceConfig);

    // create device module
    nRetVal = CreateDeviceModule(&m_pDevicePropertiesHolder);
    XN_IS_STATUS_OK(nRetVal);

    // check if we have initial values for device modules
    XnActualPropertiesHash* pDeviceModuleInitialProps = NULL;
    if (pDeviceConfig->pInitialValues != NULL)
    {
        pDeviceConfig->pInitialValues->pData->Get(XN_MODULE_NAME_DEVICE, pDeviceModuleInitialProps);
    }

    // init device module
    nRetVal = m_pDevicePropertiesHolder->Init(pDeviceModuleInitialProps);
    XN_IS_STATUS_OK(nRetVal);

    // add the device module
    nRetVal = AddModule(m_pDevicePropertiesHolder);
    XN_IS_STATUS_OK(nRetVal);

    // init dump
    m_StreamsDataDump = xnDumpFileOpen(XN_DUMP_STREAMS_DATA, "%s.csv", XN_DUMP_STREAMS_DATA);

    return (XN_STATUS_OK);
}
XnAudioProcessor::XnAudioProcessor(XnSensorAudioStream* pStream, XnSensorStreamHelper* pHelper, XnUInt32 nInputPacketSize) :
	XnWholePacketProcessor(pHelper->GetPrivateData(), pStream->GetType(), nInputPacketSize),
	m_pStream(pStream),
	m_pHelper(pHelper),
	m_AudioInDump(NULL)
{
	m_AudioInDump = xnDumpFileOpen(XN_DUMP_AUDIO_IN, "AudioIn.pcm");
}
Beispiel #4
0
XnStatus XnSensor::InitReading()
{
	XnStatus nRetVal = XN_STATUS_OK;

	// open data endpoints
	nRetVal = m_SensorIO.OpenDataEndPoints((XnSensorUsbInterface)m_Interface.GetValue(), *m_Firmware.GetInfo());
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = m_Interface.UnsafeUpdateValue(m_SensorIO.GetCurrentInterface());
	XN_IS_STATUS_OK(nRetVal);

	// take frequency information
	XnFrequencyInformation FrequencyInformation;

	nRetVal = XnHostProtocolAlgorithmParams(&m_DevicePrivateData, XN_HOST_PROTOCOL_ALGORITHM_FREQUENCY, &FrequencyInformation, sizeof(XnFrequencyInformation), (XnResolutions)0, 0);
	if (nRetVal != XN_STATUS_OK)
		return nRetVal;

	m_DevicePrivateData.fDeviceFrequency = XN_PREPARE_VAR_FLOAT_IN_BUFFER(FrequencyInformation.fDeviceFrequency);

	// Init Dumps
	m_DevicePrivateData.BandwidthDump = xnDumpFileOpen(XN_DUMP_BANDWIDTH, "Bandwidth.csv");
	xnDumpFileWriteString(m_DevicePrivateData.BandwidthDump, "Timestamp,Frame Type,Frame ID,Size\n");
	m_DevicePrivateData.TimestampsDump = xnDumpFileOpen(XN_DUMP_TIMESTAMPS, "Timestamps.csv");
	xnDumpFileWriteString(m_DevicePrivateData.TimestampsDump, "Host Time (us),Stream,Device TS,Time (ms),Comments\n");
	m_DevicePrivateData.MiniPacketsDump = xnDumpFileOpen(XN_DUMP_MINI_PACKETS, "MiniPackets.csv");
	xnDumpFileWriteString(m_DevicePrivateData.MiniPacketsDump, "HostTS,Type,ID,Size,Timestamp\n");

	m_DevicePrivateData.nGlobalReferenceTS = 0;
	nRetVal = xnOSCreateCriticalSection(&m_DevicePrivateData.hEndPointsCS);
	XN_IS_STATUS_OK(nRetVal);

	// NOTE: when we go up, some streams might be open, and so we'll receive lots of garbage.
	// wait till streams are turned off, and then start reading.
//	pDevicePrivateData->bIgnoreDataPackets = TRUE;

	// open input threads
	nRetVal = XnDeviceSensorOpenInputThreads(GetDevicePrivateData(), (XnBool)m_ReadFromEP1.GetValue(), (XnBool)m_ReadFromEP2.GetValue(), (XnBool)m_ReadFromEP3.GetValue());
	XN_IS_STATUS_OK(nRetVal);


	return XN_STATUS_OK;
}
//---------------------------------------------------------------------------
// Code
//---------------------------------------------------------------------------
XnFrameStreamProcessor::XnFrameStreamProcessor(XnFrameStream* pStream, XnSensorStreamHelper* pHelper, XnFrameBufferManager* pBufferManager, XnUInt16 nTypeSOF, XnUInt16 nTypeEOF) :
	XnStreamProcessor(pStream, pHelper),
	m_nTypeSOF(nTypeSOF),
	m_nTypeEOF(nTypeEOF),
	m_pTripleBuffer(pBufferManager),
	m_InDump(NULL),
	m_InternalDump(NULL),
	m_bFrameCorrupted(FALSE),
	m_bAllowDoubleSOF(FALSE),
	m_nLastSOFPacketID(0),
	m_nFirstPacketTimestamp(0),
  m_nLastSOFTimestamp(0),
  m_bProcessNextFrame(FALSE)
{
	sprintf(m_csInDumpMask, "%sIn", pStream->GetType());
	sprintf(m_csInternalDumpMask, "Internal%s", pStream->GetType());
	m_InDump = xnDumpFileOpen(m_csInDumpMask, "%s_0.raw", m_csInDumpMask);
	m_InternalDump = xnDumpFileOpen(m_csInternalDumpMask, "%s_0.raw", m_csInternalDumpMask);
}
Beispiel #6
0
void audioInit()
{
	g_AudioData.hWaveOut = NULL;
	g_AudioData.bFlush = false;
	g_AudioData.nFirstToCheck = -1;
	g_AudioData.SyncDump = xnDumpFileOpen(AUDIO_SYNC_DUMP_MASK, "%s.txt", AUDIO_SYNC_DUMP_MASK);;

	// check if device audio is enabled
	const AudioMetaData* pAudioMD = getAudioMetaData();
	if (pAudioMD == NULL)
		return;

	// start audio out device
	WAVEFORMATEX wf;
	wf.wFormatTag = 0x0001; // PCM
	wf.nChannels = pAudioMD->NumberOfChannels();
	wf.nSamplesPerSec = pAudioMD->SampleRate();
	wf.wBitsPerSample = pAudioMD->BitsPerSample();
	wf.nBlockAlign = wf.wBitsPerSample * wf.nChannels / 8;
	wf.nAvgBytesPerSec = wf.nBlockAlign * wf.nSamplesPerSec;
	MMRESULT mmRes = waveOutOpen(&g_AudioData.hWaveOut, WAVE_MAPPER, &wf, (DWORD_PTR)audioCallback, NULL, CALLBACK_FUNCTION);
	if (mmRes != MMSYSERR_NOERROR)
	{
		printf("Warning: Failed opening wave out device. Audio will not be played!\n");
		g_AudioData.hWaveOut = NULL;
		return;
	}

	// create some wave headers for playing
	g_AudioData.pAudioBuffers = new WAVEHDR[NUMBER_OF_AUDIO_BUFFERS];
	g_AudioData.pAudioTimestamps = new XnUInt64[NUMBER_OF_AUDIO_BUFFERS];
	xnOSMemSet(g_AudioData.pAudioBuffers, 0, sizeof(WAVEHDR)*NUMBER_OF_AUDIO_BUFFERS);

	// allocate max buffer for one second
	g_AudioData.nBufferSize = wf.nAvgBytesPerSec;

	for (int i = 0; i < NUMBER_OF_AUDIO_BUFFERS; ++i)
	{
		g_AudioData.pAudioBuffers[i].lpData = new XnChar[g_AudioData.nBufferSize];
		g_AudioData.pAudioBuffers[i].dwUser = i;
		g_AudioData.pAudioBuffers[i].dwFlags = WHDR_DONE; // mark this buffer as empty (already played)
	}

	g_AudioData.nAudioNextBuffer = 0;
}
Beispiel #7
0
XnStatus XnDeviceBase::InitImpl(const XnDeviceConfig* pDeviceConfig)
{
	XnStatus nRetVal = XN_STATUS_OK;

	XN_VALIDATE_INPUT_PTR(pDeviceConfig);

	// create device module
	nRetVal = CreateDeviceModule(&m_pDevicePropertiesHolder);
	XN_IS_STATUS_OK(nRetVal);

	// check if we have initial values for device modules
	XnActualPropertiesHash* pDeviceModuleInitialProps = NULL;
	if (pDeviceConfig->pInitialValues != NULL)
	{
		pDeviceConfig->pInitialValues->pData->Get(XN_MODULE_NAME_DEVICE, pDeviceModuleInitialProps);
	}

	// init device module
	nRetVal = m_pDevicePropertiesHolder->Init(pDeviceModuleInitialProps);
	XN_IS_STATUS_OK(nRetVal);

	// set read/write mode (we need to do it AFTER module init to override original value)
	nRetVal = m_ReadWriteMode.UnsafeUpdateValue(pDeviceConfig->DeviceMode);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = m_SharingMode.UnsafeUpdateValue(pDeviceConfig->SharingMode);
	XN_IS_STATUS_OK(nRetVal);

	// add the device module
	nRetVal = AddModule(m_pDevicePropertiesHolder);
	XN_IS_STATUS_OK(nRetVal);

	// create the new data event
	nRetVal = xnOSCreateEvent(&m_hNewDataEvent, FALSE);
	XN_IS_STATUS_OK(nRetVal);

	// init dump
	m_StreamsDataDump = xnDumpFileOpen(XN_DUMP_STREAMS_DATA, "%s.csv", XN_DUMP_STREAMS_DATA);

	return (XN_STATUS_OK);
}
XnStatus LinkContInputStream::StartImpl()
{
    XnStatus nRetVal = XN_STATUS_OK;
    if (m_bStreaming)
    {
        return XN_STATUS_OK;
    }
	
    m_pDumpFile = xnDumpFileOpen(m_strDumpName, "%s", m_strDumpName);
	
	//We only need log buffer output if dumping is on
	m_logParser.GenerateOutputBuffer(m_pDumpFile != NULL);

    nRetVal = m_pConnection->Connect();
    XN_IS_STATUS_OK_LOG_ERROR("Connect stream's input connection", nRetVal);
    nRetVal = m_pLinkControlEndpoint->StartStreaming(m_nStreamID);
    XN_IS_STATUS_OK_LOG_ERROR("Start streaming", nRetVal);
    m_bStreaming = TRUE;

    return XN_STATUS_OK;
}
Beispiel #9
0
//---------------------------------------------------------------------------
// Code
//---------------------------------------------------------------------------
XnVideoSource::XnVideoSource(LPUNKNOWN lpunk, HRESULT *phr) :
    CSource(g_videoName, lpunk, CLSID_OpenNIVideo),
    m_pVideoProcAmp(NULL),
    m_pCameraControl(NULL),
    m_Dump(xnDumpFileOpen(XN_MASK_FILTER, "FilterFlow.log"))
{
    ASSERT(phr != NULL);

    xnLogVerbose(XN_MASK_FILTER, "Creating video source filter");

    CAutoLock cAutoLock(&m_cStateLock);

    // initialize OpenNI
    XnStatus nRetVal = m_context.Init();
    if (nRetVal != XN_STATUS_OK)
    {
        xnLogWarning(XN_MASK_FILTER, "Can't init context");
        *phr = E_UNEXPECTED;
    }

    // try to create an image generator
    nRetVal = m_image.Create(m_context);
    if (nRetVal != XN_STATUS_OK)
    {
        xnLogWarning(XN_MASK_FILTER, "Can't create image generator");
        *phr = VFW_E_NO_CAPTURE_HARDWARE;
        return;
    }

    // create output pins. Every pin registers itself with the source object
    XnVideoStream* pStream = new XnVideoStream(phr, this, m_image, L"VideoOut");
    if (pStream == NULL)
    {
        *phr = E_OUTOFMEMORY;
    }

    *phr = NOERROR;
}
Beispiel #10
0
XnStatus XnSensor::InitImpl(const XnDeviceConfig *pDeviceConfig)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	xnLogVerbose(XN_MASK_DEVICE_SENSOR, "Initializing device sensor...");


	// Frame Sync
	XnCallbackHandle hCallbackDummy;
	nRetVal = m_FrameSync.OnChangeEvent().Register(FrameSyncPropertyChangedCallback, this, hCallbackDummy);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = GetFirmware()->GetParams()->m_Stream0Mode.OnChangeEvent().Register(FrameSyncPropertyChangedCallback, this, hCallbackDummy);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = GetFirmware()->GetParams()->m_Stream1Mode.OnChangeEvent().Register(FrameSyncPropertyChangedCallback, this, hCallbackDummy);
	XN_IS_STATUS_OK(nRetVal);

	// other stuff
	m_FrameSyncDump = xnDumpFileOpen(XN_DUMP_FRAME_SYNC, "FrameSync.csv");
	xnDumpFileWriteString(m_FrameSyncDump, "HostTime(us),DepthNewData,DepthTimestamp(ms),ImageNewData,ImageTimestamp(ms),Diff(ms),Action\n");

	nRetVal = XnDeviceBase::InitImpl(pDeviceConfig);
	XN_IS_STATUS_OK(nRetVal);

	// now that everything is configured, open the sensor
	nRetVal = InitSensor(pDeviceConfig);
	if (nRetVal != XN_STATUS_OK)
	{
		Destroy();
		return (nRetVal);
	}

	xnLogInfo(XN_MASK_DEVICE_SENSOR, "Device sensor initialized");

	return (XN_STATUS_OK);
}
XN_C_API void* xnOSLogMemAlloc(void* pMemBlock, XnAllocationType nAllocType, XnUInt32 nBytes, const XnChar* csFunction, const XnChar* csFile, XnUInt32 nLine, const XnChar* csAdditional)
{
	static XnBool bFirstTime = TRUE;
	static XnBool bReentrent = FALSE;

	if (bFirstTime)
	{
		bFirstTime = FALSE;
		printf("************************************************************\n");
		printf("**  WARNING: Memory Profiling is on!                      **\n");
		printf("************************************************************\n");

		bReentrent = TRUE;
		xnOSCreateCriticalSection(&g_hCS);

#ifdef XN_MEMORY_PROFILING_DUMP
		xnDumpSetMaskState("MemProf", TRUE);
#endif
		g_dump = xnDumpFileOpen("MemProf", "MemProfiling.log");
		xnDumpFileWriteString(g_dump, "Entry,Address,AllocType,Bytes,Function,File,Line,AdditionalInfo\n");
		bReentrent = FALSE;
	}

	// ignore stuff that is being allocated during "first time"
	if (bReentrent)
	{
		return pMemBlock;
	}

	XnMemBlockDataNode* pNode;
	pNode = (XnMemBlockDataNode*)xnOSMalloc(sizeof(XnMemBlockDataNode));
	pNode->Data.pMemBlock = pMemBlock;
	pNode->Data.nAllocType = nAllocType;
	pNode->Data.nBytes = nBytes;
	pNode->Data.csFunction = csFunction;
	pNode->Data.csFile = csFile;
	pNode->Data.nLine = nLine;
	pNode->Data.csAdditional = csAdditional;
	pNode->Data.nFrames = XN_MEM_PROF_MAX_FRAMES;
	xnDumpFileWriteString(g_dump, "Alloc,0x%x,%s,%u,%s,%s,%u,%s\n", pMemBlock, XnGetAllocTypeString(nAllocType), nBytes, csFunction, csFile, nLine, csAdditional);

	// try to get call stack (skip 2 frames - this one and the alloc func)
	XnChar* pstrFrames[XN_MEM_PROF_MAX_FRAMES];
	for (XnUInt32 i = 0; i < XN_MEM_PROF_MAX_FRAMES; ++i)
	{
		pstrFrames[i] = pNode->Data.aFrames[i];
	}
	if (XN_STATUS_OK != xnOSGetCurrentCallStack(2, pstrFrames, XN_MEM_PROF_MAX_FRAME_LEN, &pNode->Data.nFrames))
	{
		pNode->Data.nFrames = 0;
	}

	pNode->pNext = NULL;

	XnAutoCSLocker lock(g_hCS);
	if (g_allocatedMemory.pLast == NULL)
	{
		g_allocatedMemory.pFirst = g_allocatedMemory.pLast = pNode;
	}
	else
	{
		g_allocatedMemory.pLast->pNext = pNode;
		g_allocatedMemory.pLast = pNode;
	}

	return pMemBlock;
}