Пример #1
0
        /// <summary>
        /// Initialize synchro using players current time origins.
        /// </summary>
        public void Initialize(PlayerScreen leftPlayer, PlayerScreen rightPlayer)
        {
            PlayerSyncInfo leftInfo = new PlayerSyncInfo();

            leftInfo.SyncTime = leftPlayer.LocalTimeOriginPhysical;
            leftInfo.LastTime = leftPlayer.LocalLastTime;

            PlayerSyncInfo rightInfo = new PlayerSyncInfo();

            rightInfo.SyncTime = rightPlayer.LocalTimeOriginPhysical;
            rightInfo.LastTime = rightPlayer.LocalLastTime;

            leftInfo.Scale  = 1.0;
            rightInfo.Scale = 1.0;
            if (PreferencesManager.PlayerPreferences.SyncByMotion)
            {
                long leftDuration  = leftInfo.LastTime - leftInfo.SyncTime;
                long rightDuration = rightInfo.LastTime - rightInfo.SyncTime;
                rightInfo.Scale = (double)rightDuration / leftDuration;
            }

            // Start of each video in common time. One will start at 0 while the other will have an offset.
            // This is what aligns the videos on their respective time origin.
            long offsetLeft  = 0;
            long offsetRight = 0;
            long rightOrigin = (long)(rightPlayer.LocalTimeOriginPhysical / rightInfo.Scale);

            if (leftPlayer.LocalTimeOriginPhysical < rightOrigin)
            {
                offsetLeft = rightOrigin - leftPlayer.LocalTimeOriginPhysical;
            }
            else
            {
                offsetRight = leftPlayer.LocalTimeOriginPhysical - rightOrigin;
            }

            leftInfo.Offset  = offsetLeft;
            rightInfo.Offset = offsetRight;

            syncInfos.Clear();
            syncInfos.Add(leftPlayer.Id, leftInfo);
            syncInfos.Add(rightPlayer.Id, rightInfo);

            frameTime = Math.Min((long)(leftPlayer.LocalFrameTime * leftInfo.Scale), (long)(rightPlayer.LocalFrameTime * rightInfo.Scale));

            long leftEnd  = GetCommonTime(leftPlayer, leftInfo.LastTime);
            long rightEnd = GetCommonTime(rightPlayer, rightInfo.LastTime);

            commonLastTime = Math.Max(leftEnd, rightEnd);
        }
Пример #2
0
        public void Initialize(PlayerScreen leftPlayer, long leftSyncTime, PlayerScreen rightPlayer, long rightSyncTime)
        {
            syncInfos.Clear();

            leftPlayer.LocalSyncTime  = leftSyncTime;
            rightPlayer.LocalSyncTime = rightSyncTime;

            PlayerSyncInfo leftInfo = new PlayerSyncInfo();

            leftInfo.SyncTime = leftSyncTime;
            leftInfo.LastTime = leftPlayer.LocalLastTime;

            PlayerSyncInfo rightInfo = new PlayerSyncInfo();

            rightInfo.SyncTime = rightSyncTime;
            rightInfo.LastTime = rightPlayer.LocalLastTime;

            // Start of each video in common time. One will start at 0 while the other will have an offset.
            long offsetLeft  = 0;
            long offsetRight = 0;

            if (leftSyncTime < rightSyncTime)
            {
                offsetLeft = rightSyncTime - leftSyncTime;
            }
            else
            {
                offsetRight = leftSyncTime - rightSyncTime;
            }

            leftInfo.Offset  = offsetLeft;
            rightInfo.Offset = offsetRight;

            syncInfos.Add(leftPlayer.Id, leftInfo);
            syncInfos.Add(rightPlayer.Id, rightInfo);

            frameTime = Math.Min(leftPlayer.LocalFrameTime, rightPlayer.LocalFrameTime);

            long leftEnd  = GetCommonTime(leftPlayer, leftInfo.LastTime);
            long rightEnd = GetCommonTime(rightPlayer, rightInfo.LastTime);

            commonLastTime = Math.Max(leftEnd, rightEnd);
        }