void XnFileDevice::Free()
{
	for (XnNodeInfoMap::Iterator it = m_nodeInfoMap.begin(); it != m_nodeInfoMap.end(); ++it)
	{
		XnNodeInfo& nodeInfo = it.Value();
		XN_DELETE(nodeInfo.pXnCodec);
	}
	m_nodeInfoMap.Clear();

	if (m_ShiftToDepth.bIsInitialized)
	{
		XnShiftToDepthFree(&m_ShiftToDepth);
	}

	if (m_pInputStream != NULL)
	{
		XN_DELETE(m_pInputStream);
		m_pInputStream = NULL;
	}

	if (m_pDataPacker != NULL)
	{
		m_pDataPacker->Free();
		XN_DELETE(m_pDataPacker);
		m_pDataPacker = NULL;
	}

	if (m_pStreamData != NULL)
	{
		XnStreamDataDestroy(&m_pStreamData);
		m_pStreamData = NULL;
	}
}
Exemple #2
0
XnStatus XnFileDevice::Rewind()
{
    XnStatus nRetVal = XN_STATUS_OK;

    // go back to start of stream
    nRetVal = m_pInputStream->Seek(XN_DEVICE_FILE_MAGIC_LEN);
    XN_IS_STATUS_OK(nRetVal);

    // read initial state
    XN_PROPERTY_SET_CREATE_ON_STACK(state);
    nRetVal = ReadInitialState(&state);
    XN_IS_STATUS_OK(nRetVal);

    // first handle current streams. remove or reset them
    for (XnNodeInfoMap::Iterator it = m_nodeInfoMap.Begin(); it != m_nodeInfoMap.End(); ++it)
    {
        const XnChar* strName = it->Key();

        if (m_bNodeCollectionChanged)
        {
            // we need to destroy all streams, and recreate them later
            nRetVal = m_pNotifications->OnNodeRemoved(m_pNotificationsCookie, strName);
            XN_IS_STATUS_OK(nRetVal);
        }
        else
        {
            // just reset frame ID
            it->Value().nCurrFrameID = 0;
            // and mark not to recreate it
            nRetVal = m_ignoreNewNodes.Set(strName, it->Value());
            XN_IS_STATUS_OK(nRetVal);
        }
    }

    // if we need, recreate nodes
    if (m_bNodeCollectionChanged)
    {
        nRetVal = SetInitialState(&state);
        XN_IS_STATUS_OK(nRetVal);
    }

// 	ResetLastTimestampAndFrame();
// 	m_nReferenceTimestamp = 0;
// 	m_nReferenceTime = 0;

    m_bNodeCollectionChanged = FALSE;
    m_nCurrTimestamp = 0;

    return (XN_STATUS_OK);
}
Exemple #3
0
void XnFileDevice::Free()
{
    for (XnNodeInfoMap::Iterator it = m_nodeInfoMap.Begin(); it != m_nodeInfoMap.End(); ++it)
    {
        XnNodeInfo& nodeInfo = it->Value();
        XN_DELETE(nodeInfo.pXnCodec);
        if (nodeInfo.codec.IsValid())
        {
            xnRemoveNeededNode(GetSelfNodeHandle(), nodeInfo.codec);
            nodeInfo.codec.Release();
        }

    }
    m_nodeInfoMap.Clear();

    if (m_ShiftToDepth.bIsInitialized)
    {
        XnShiftToDepthFree(&m_ShiftToDepth);
    }

    if (m_pInputStream != NULL)
    {
        XN_DELETE(m_pInputStream);
        m_pInputStream = NULL;
    }

    if (m_pDataPacker != NULL)
    {
        m_pDataPacker->Free();
        XN_DELETE(m_pDataPacker);
        m_pDataPacker = NULL;
    }

    if (m_pStreamData != NULL)
    {
        XnStreamDataDestroy(&m_pStreamData);
        m_pStreamData = NULL;
    }
}
Exemple #4
0
XnStatus XnFileDevice::BCSeekFrame(XnUInt32 nFrameID)
{
	XnStatus nRetVal = XN_STATUS_OK;

	XnDeviceFileFrameHeaderV3 FileFrameHeader;
	XnUInt32 nReadBytes = 0;
	XnUInt32 nShouldRead = 0;
	XnInt32 nExpectedFrameID = 1;

	// go back to start of file
	nRetVal = Rewind();
	XN_IS_STATUS_OK(nRetVal);

	// Update the frame position to the new position (treat 0 as 1)
	m_pBCData->nFramePos = XN_MAX(nFrameID, 1);

	// Make sure we aren't trying to reach a frame that's beyond the number of frames
	if (m_pBCData->nFramePos > m_pBCData->StreamProperties.nNumOfFrames)
	{
		// Set the frame position to the last frame
		m_pBCData->nFramePos = m_pBCData->StreamProperties.nNumOfFrames;
	}

	// Set the file position to the first frame data (right after the file header)
	XnUInt32 nOffset = 0;
	switch (m_nFileVersion)
	{
	case 3:
		nOffset = sizeof(XnDeviceFileHeader);
		break;
	case 2:
		nOffset = sizeof(XnDeviceFileHeaderV2);
		break;
	case 1:
		nOffset = sizeof(XnDeviceFileHeaderV1);
		break;
	default:
		return (XN_STATUS_IO_INVALID_STREAM_HEADER);
	}

	nRetVal = m_pInputStream->Seek(nOffset);
	XN_IS_STATUS_OK(nRetVal);

	// Keep reading frames until we reach the wanted frame
	XnUInt32 nCurrFilePos = 1;
	while (nCurrFilePos < m_pBCData->nFramePos)
	{
		// Read the frame header
		switch (m_nFileVersion)
		{
		case 3:
			{
				nShouldRead = nReadBytes = sizeof(XnDeviceFileFrameHeaderV3);
				nRetVal = m_pInputStream->ReadData((XnUChar*)&FileFrameHeader, nReadBytes);
				XN_IS_STATUS_OK(nRetVal);
				nExpectedFrameID = nCurrFilePos;
			}
			break;
		case 2:
			{
				XnDeviceFileFrameHeaderV2 FileFrameHeaderV2;
				nShouldRead = nReadBytes = sizeof(XnDeviceFileFrameHeaderV2);
				nRetVal = m_pInputStream->ReadData((XnUChar*)&FileFrameHeaderV2, nReadBytes);
				XN_IS_STATUS_OK(nRetVal);
				nRetVal = XnDeviceFileAdjustFileFrameHeaderV2(&FileFrameHeaderV2, &FileFrameHeader);
				XN_IS_STATUS_OK(nRetVal);
				nExpectedFrameID = nCurrFilePos - 1;
			}
			break;
		case 1:
			{
				XnDeviceFileFrameHeaderV1 FileFrameHeaderV1;
				nShouldRead = nReadBytes = sizeof(XnDeviceFileFrameHeaderV1);
				nRetVal = m_pInputStream->ReadData((XnUChar*)&FileFrameHeaderV1, nReadBytes);
				XN_IS_STATUS_OK(nRetVal);
				nRetVal = XnDeviceFileAdjustFileFrameHeaderV1(&FileFrameHeaderV1, &FileFrameHeader);
				XN_IS_STATUS_OK(nRetVal);
				nExpectedFrameID = nCurrFilePos - 1;
			}
			break;
		default:
			return XN_STATUS_IO_INVALID_STREAM_HEADER;
		}

		// Make sure we got the right header size
		if (nReadBytes != nShouldRead)
		{
			return (XN_STATUS_IO_INVALID_STREAM_FRAME_HEADER);
		}

		// Skip the frame data
		XnUInt32 nPosition;
		nRetVal = m_pInputStream->Tell(&nPosition);
		XN_IS_STATUS_OK(nRetVal);

		nRetVal = m_pInputStream->Seek(FileFrameHeader.nPackedStreamSize + nPosition);
		XN_IS_STATUS_OK(nRetVal);

		// increment streams frame ID
		for (XnNodeInfoMap::Iterator it = m_nodeInfoMap.Begin(); it != m_nodeInfoMap.End(); ++it)
		{
			it->Value().nCurrFrameID++;
		}

		// Make sure frame ids are sequential
		if (FileFrameHeader.FrameProperties.nDepthFrameID != nExpectedFrameID)
		{
			return (XN_STATUS_IO_STREAM_NOT_SEQUENTIAL);
		}

		// Update the current file frame position
		nCurrFilePos++;
	}

	// now read last frame (the one we wanted)
	XnBool bWrapOccured;
	nRetVal = BCReadFrame(&bWrapOccured);
	XN_IS_STATUS_OK(nRetVal);

	return (XN_STATUS_OK);
}