示例#1
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);
}
示例#2
0
XnStatus XnFileDevice::SetInputStream(void *pStreamCookie, XnPlayerInputStreamInterface *pStream)
{
    XnStatus nRetVal = XN_STATUS_OK;

    XN_VALIDATE_NEW(m_pInputStream, XnInputStream, pStream, pStreamCookie);

    nRetVal = m_pInputStream->Init();
    if (nRetVal != XN_STATUS_OK)
    {
        XN_DELETE(m_pInputStream);
        m_pInputStream = NULL;
        return (nRetVal);
    }

    // read format version
    nRetVal = ReadFileVersion();
    XN_IS_STATUS_OK(nRetVal);

    m_pDataPacker = XN_NEW(XnDataPacker, m_pInputStream, XN_DEVICE_FILE_MAX_INTERNAL_BUFFER);
    if (m_pDataPacker == NULL)
    {
        XN_DELETE(m_pInputStream);
        return (XN_STATUS_ALLOC_FAILED);
    }

    nRetVal = m_pDataPacker->Init();
    if (nRetVal != XN_STATUS_OK)
    {
        XN_DELETE(m_pDataPacker);
        XN_DELETE(m_pInputStream);
        return (nRetVal);
    }

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

    nRetVal = SetInitialState(&props);
    XN_IS_STATUS_OK(nRetVal);

    // now read till first data
    XnBool bWrap;
    nRetVal = ReadTillNextData(&bWrap);
    XN_IS_STATUS_OK(nRetVal);

    return (XN_STATUS_OK);
}
XnStatus XnStreamReaderDevice::InitImpl(const XnDeviceConfig* pDeviceConfig)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	// we will init the device using state from the stream, instead of the one from user.
	// the one from user will be used to set properties afterwards.

	// first open the stream
	nRetVal = InitPacker(pDeviceConfig->cpConnectionString);
	XN_IS_STATUS_OK(nRetVal);

	// create a property set
	XnPropertySet* pSet;
	nRetVal = XnPropertySetCreate(&pSet);
	XN_IS_STATUS_OK(nRetVal);

	// read initial state (we assume first object in the stream is the initial state)
	nRetVal = ReadInitialState(pSet);
	if (nRetVal != XN_STATUS_OK)
	{
		XnPropertySetDestroy(&pSet);
		return (nRetVal);
	}

	nRetVal = SetInitialState(pDeviceConfig, pSet);
	if (nRetVal != XN_STATUS_OK)
	{
		XnPropertySetDestroy(&pSet);
		return (nRetVal);
	}

	// destroy the property set (we don't need it anymore)
	nRetVal = XnPropertySetDestroy(&pSet);
	XN_IS_STATUS_OK(nRetVal);

	return (XN_STATUS_OK);
}
XnStatus XnDeviceFileReader::Rewind()
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	// go back to start of stream
	nRetVal = GetIOStream()->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
	XnDeviceModuleHolderList streams;
	nRetVal = GetStreamsList(streams);
	XN_IS_STATUS_OK(nRetVal);

	for (XnDeviceModuleHolderList::Iterator it = streams.Begin(); it != streams.End(); ++it)
	{
		XnDeviceModuleHolder* pHolder = *it;

		if (m_bStreamsCollectionChanged)
		{
			// we need to destroy all streams, and recreate them later
			nRetVal = DestroyStream(pHolder->GetModule()->GetName());
			XN_IS_STATUS_OK(nRetVal);
		}
		else
		{
			// just reset frame ID
			XnStreamReaderStream* pStream = (XnStreamReaderStream*)pHolder->GetModule();
			pStream->Reset();
		}
	}

	// if we need, recreate streams
	if (m_bStreamsCollectionChanged)
	{
		nRetVal = CreateStreams(&state);
		XN_IS_STATUS_OK(nRetVal);
	}

	// now set state.
	for (XnPropertySetData::Iterator it = state.pData->Begin(); it != state.pData->End(); ++it)
	{
		const XnChar* strName = it->Key();
		XnActualPropertiesHash* pHash = it->Value();

		// fix it first
		if (strcmp(strName, XN_MODULE_NAME_DEVICE) == 0)
		{
			pHash->Remove(XN_MODULE_PROPERTY_READ_WRITE_MODE);
			pHash->Remove(XN_MODULE_PROPERTY_PRIMARY_STREAM);
		}

		XnDeviceModule* pModule;
		nRetVal = FindModule(strName, &pModule);
		XN_IS_STATUS_OK(nRetVal);

		nRetVal = pModule->UnsafeBatchConfig(*pHash);
		XN_IS_STATUS_OK(nRetVal);
	}

	ResetLastTimestampAndFrame();
	m_nReferenceTimestamp = 0;
	m_nReferenceTime = 0;
	m_bStreamsCollectionChanged = FALSE;

	return (XN_STATUS_OK);
}