| 646 | } |
| 647 | |
| 648 | XnStatus PlayerImpl::SetNodeNewData(const XnChar* strNodeName, XnUInt64 nTimeStamp, XnUInt32 nFrame, const void* pData, XnUInt32 nSize) |
| 649 | { |
| 650 | XnStatus nRetVal = XN_STATUS_OK; |
| 651 | |
| 652 | XnUInt64 nNow; |
| 653 | xnOSGetHighResTimeStamp(&nNow); |
| 654 | |
| 655 | if (!m_bHasTimeReference) |
| 656 | { |
| 657 | m_nStartTimestamp = nTimeStamp; |
| 658 | m_nStartTime = nNow; |
| 659 | |
| 660 | m_bHasTimeReference = TRUE; |
| 661 | } |
| 662 | else if (m_dPlaybackSpeed != XN_PLAYBACK_SPEED_FASTEST) |
| 663 | { |
| 664 | // check this data timestamp compared to when we started |
| 665 | XnInt64 nTimestampDiff = nTimeStamp - m_nStartTimestamp; |
| 666 | |
| 667 | // in some recordings, frames are not ordered by timestamp. Make sure this does not break the mechanism |
| 668 | if (nTimestampDiff > 0) |
| 669 | { |
| 670 | XnInt64 nTimeDiff = nNow - m_nStartTime; |
| 671 | |
| 672 | // check if we need to wait some time |
| 673 | XnInt64 nRequestedTimeDiff = (XnInt64)(nTimestampDiff / m_dPlaybackSpeed); |
| 674 | if (nTimeDiff < nRequestedTimeDiff) |
| 675 | { |
| 676 | XnUInt32 nSleep = XnUInt32((nRequestedTimeDiff - nTimeDiff)/1000); |
| 677 | nSleep = XN_MIN(nSleep, XN_PLAYBACK_SPEED_SANITY_SLEEP); |
| 678 | xnOSSleep(nSleep); |
| 679 | } |
| 680 | |
| 681 | // update reference to current frame (this will handle cases in which application |
| 682 | // stopped reading frames and continued after a while) |
| 683 | m_nStartTimestamp = nTimeStamp; |
| 684 | xnOSGetHighResTimeStamp(&m_nStartTime); |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | PlayedNodeInfo playedNode; |
| 689 | nRetVal = m_playedNodes.Get(strNodeName, playedNode); |
| 690 | XN_IS_STATUS_OK(nRetVal); |
| 691 | |
| 692 | nRetVal = xnLockedNodeStartChanges(playedNode.hNode, playedNode.hLock); |
| 693 | XN_IS_STATUS_OK(nRetVal); |
| 694 | |
| 695 | nRetVal = xnSetIntProperty(playedNode.hNode, XN_PROP_TIMESTAMP, nTimeStamp); |
| 696 | if (nRetVal != XN_STATUS_OK) |
| 697 | { |
| 698 | xnLockedNodeEndChanges(playedNode.hNode, playedNode.hLock); |
| 699 | return (nRetVal); |
| 700 | } |
| 701 | nRetVal = xnSetIntProperty(playedNode.hNode, XN_PROP_FRAME_ID, nFrame); |
| 702 | if (nRetVal != XN_STATUS_OK) |
| 703 | { |
| 704 | xnLockedNodeEndChanges(playedNode.hNode, playedNode.hLock); |
| 705 | return (nRetVal); |
no test coverage detected