// initializes the syncher for the given sensor interface public int StartSyncherForSensor(Kinect4AzureInterface sensorInt, KinectInterop.SensorData sensorData, bool isMaster, long expectedDelay) { if (sensorInt == null) { return(-1); } int sensorIndex = numSensors; sensorInts.Add(sensorInt); sensorDatas.Add(sensorData); expectedDelays.Add(expectedDelay); numSensors++; if (isMaster) { if (iMaster >= 0) { throw new Exception("Master index already set at " + iMaster + ". Current interface index is " + sensorIndex + ". Multiple masters are not supported."); } iMaster = sensorIndex; } //Debug.Log("Started syncher for sensor D" + sensorInt.deviceIndex + ", delay: " + expectedDelay + ", index: " + sensorIndex + ", master: " + iMaster); return(sensorIndex); }
// updates the body tracking frame public void UpdateBtFrame(int sensorIndex, long frameTimestamp) { if (frameTimestamp == 0) { Debug.Log("Ignoring bt-frame for syncher index " + sensorIndex + ". Timestamp: " + frameTimestamp); return; } lock (syncherLock) { if (syncherData == null || numSensors != syncherData.Length || syncherData[sensorIndex] == null) { CreateSyncherData(sensorIndex); } // set new frame //Debug.Log("Setting bt-frame for syncher index " + sensorIndex + ". Timestamp: " + frameTimestamp); syncherData[sensorIndex].btTimestamp = frameTimestamp; // check for synched body frames bool bAllSynched = numSensors > 1 && iMaster >= 0 && syncherData[iMaster] != null && syncherData[iMaster].btTimestamp != 0; if (bAllSynched) { long masterTime = syncherData[iMaster].btTimestamp; for (int i = 0; i < numSensors; i++) { if (syncherData[i] == null || syncherData[i].btTimestamp == 0) { bAllSynched = false; break; } long subTime = syncherData[i].btTimestamp; long expTime = masterTime + syncherData[i].expDelay; long subError = subTime - expTime; if (i != iMaster && (subTime == 0 || subError < -MAX_TIME_ERROR || subError > MAX_TIME_ERROR)) { bAllSynched = false; break; } } } if (bAllSynched) { //Debug.Log("Synched bt-frames. Index: " + sensorIndex + " MasterTime: " + syncherData[iMaster].btTimestamp); // process synched body frames for (int i = 0; i < numSensors; i++) { Kinect4AzureInterface sensorInt = sensorInts[i]; KinectInterop.SensorData sensorData = sensorDatas[i]; //Debug.Log(" Processing bt-frame " + i + ". Timestamp: " + syncherData[i].btTimestamp); sensorInt.ProcessBodyFrame(sensorData, IntPtr.Zero, true); sensorInt.ProcessBtSensorCapture(sensorData); } } else { //Debug.Log("Bt-frames not synched. Index: " + sensorIndex + " ThisTime: " + syncherData[sensorIndex].btTimestamp + ", MasterTime: " + syncherData[iMaster].btTimestamp); } } }
// updates the push bt-capture public void UpdatePushBtCapture(int sensorIndex, long capTimestamp, Capture capture) { if (capture == null || capture.Depth == null) { return; } if (capTimestamp == 0) { Debug.Log("Ignoring push-capture for syncher index " + sensorIndex + ". Timestamp: " + capTimestamp); capture.Dispose(); return; } lock (syncherLock) { if (syncherData == null || numSensors != syncherData.Length || syncherData[sensorIndex] == null) { CreateSyncherData(sensorIndex); } // dispose current capture if (syncherData[sensorIndex].pushCapture != null) { //Debug.Log("Disposing push-capture for syncher index " + sensorIndex + ". Timestamp: " + syncherData[sensorIndex].pushCapTimestamp); syncherData[sensorIndex].pushCapture.Dispose(); syncherData[sensorIndex].pushCapture = null; } // set new capture //Debug.Log("Setting push-capture for syncher index " + sensorIndex + ". Timestamp: " + capTimestamp); syncherData[sensorIndex].pushCapTimestamp = capTimestamp; syncherData[sensorIndex].pushCapture = capture; // check for synched captures bool bAllSynched = numSensors > 1 && iMaster >= 0 && syncherData[iMaster] != null && syncherData[iMaster].pushCapTimestamp != 0; if (bAllSynched) { long masterTime = syncherData[iMaster].pushCapTimestamp; for (int i = 0; i < numSensors; i++) { if (syncherData[i] == null || syncherData[i].pushCapTimestamp == 0) { bAllSynched = false; break; } long subTime = syncherData[i].pushCapTimestamp; long expTime = masterTime + syncherData[i].expDelay; long subError = subTime - expTime; if (i != iMaster && (subTime == 0 || subError < -MAX_TIME_ERROR || subError > MAX_TIME_ERROR)) { bAllSynched = false; break; } } } if (bAllSynched) { //Debug.Log("Synched push-captures. Index: " + sensorIndex + " MasterTime: " + syncherData[iMaster].pushCapTimestamp); // process synched sensor captures for (int i = 0; i < numSensors; i++) { Kinect4AzureInterface sensorInt = sensorInts[i]; KinectInterop.SensorData sensorData = sensorDatas[i]; //Debug.Log(" Processing push capture " + i + ". Timestamp: " + syncherData[i].pushCapTimestamp); sensorInt.PushBodyFrame(sensorData, syncherData[i].pushCapture, true); syncherData[i].pushCapture = null; } } else { //Debug.Log("Push-captures not synched. Index: " + sensorIndex + " ThisTime: " + syncherData[sensorIndex].pushCapTimestamp + ", MasterTime: " + syncherData[iMaster].pushCapTimestamp); } } }