Beispiel #1
0
        // Update is called once per frame
        void Update()
        {
            _multipleMedia = sphere.GetComponent <MultiplePlayerControl>();
            _player        = _multipleMedia.Player;
            _gatedClips    = GetComponents <GatedClip>();
            _playableClips = GetComponents <PlayableClip>();
            _previewMode   = GetComponent <PreviewMode>();
            Array.Sort(_playableClips);
            this.transform.position = Camera.main.transform.position;

            currentTime        = _multipleMedia.GetCurrentTime();
            CurrentVisibleView = GetVisibleView();
            if (_multipleMedia.IsPaused())
            {
                float relativeTime = currentTime - _playableClips[_currentClipIndex].startTime;
                Debug.Log("Current frame: " + (int)(currentTime * _multipleMedia.Player.Info.GetVideoFrameRate()) + ". Current view is " + CurrentVisibleView + ". Current clip: " + GetCurrentClipIndex());
                Debug.Log("Relative frame: " + (int)(relativeTime * _multipleMedia.Player.Info.GetVideoFrameRate()));
            }

            currentTime = _multipleMedia.GetCurrentTime();

            if (initialized)  // Need in case the first clip does not start at t = 0s of the raw video.
            {
                Debug.Log("Is playing? " + _multipleMedia.IsPlaying());
                _multipleMedia.Seek(_playableClips[0].startTime);
                if (Mathf.Abs(_player.Control.GetCurrentTimeMs() / 1000f - _playableClips[0].startTime) < GetVideoFps())
                {
                    initialized = false;
                }
                Debug.Log("Initialized. Current time: " + Mathf.Abs(_player.Control.GetCurrentTimeMs()) / 1000f + ", Initialized? " + initialized.ToString());
                return;
            }

            // If there are no playable clips, stop.
            if (_playableClips.Length == 0 || _currentClipIndex < 0 || _currentClipIndex >= _playableClips.Length)
            {
                this.SetPlayMode(false);
                this.PauseVideo();
                return;
            }

            if (!_multipleMedia.SyncMediaPlayers() && _multipleMedia.isTransitioning)
            {
                Debug.Log("Not in sync DESPITE FORCEWAIT");
                if (_multipleMedia.Player.Control.IsSeeking())
                {
                    playMode = false;
                }
                else if (_multipleMedia.OtherPlayer.Control.IsSeeking())
                {
                    playMode = false;
                }
            }

            currentTime = _multipleMedia.GetCurrentTime();

            if (playMode)
            {
                this.PlayVideo();
            }
            else
            {
                this.PauseVideo();
            }
            this.SetupEquirectTexture();

            // Storing equirect texture into PreviewMode component, which is read by VideoEditorWindow.
            if (_player.TextureProducer != null)
            {
                if (_previewMode.equirectTexture != null)
                {
                    MediaPlayer equirectPlayer = _multipleMedia.GetEquirectPlayer();
                    if (equirectPlayer != null)
                    {
                        _previewMode.equirectTexture = (Texture2D)equirectPlayer.TextureProducer.GetTexture();
                    }
                }
            }

            if (currentTime < _playableClips[_currentClipIndex].startTime - 5)
            {
                Debug.Log("Current time " + currentTime + " is less than start time of clip index " + _currentClipIndex + ": " + _playableClips[_currentClipIndex] + ". Skipping ahead...");
                _multipleMedia.Seek(_playableClips[_currentClipIndex].startTime);
                return;
            }

            _previewMode.SetCurrentClip(_playableClips[_currentClipIndex].clipIndex);
            int previousClipIndex = _currentClipIndex;
            int currentFrame      = (int)(currentTime * _multipleMedia.Player.Info.GetVideoFrameRate());

            // Check whether playable clip is gated clip.
            GatedClip gc = _playableClips[_currentClipIndex] as GatedClip;

            if (gc != null)
            {
                // This clip is a gated clip.
                if ((_player.Control.IsPlaying() || _multipleMedia.IsPaused()) && gc.checkSalient(currentTime, _multipleMedia, this))
                {
                    currentTime = _multipleMedia.GetCurrentTime();
                    Debug.Log("Current time: " + currentTime + ". Current face: " + GetVisibleView() + ". Passed gated clip " + gc + ". Moving from index: " + _currentClipIndex);

                    if (_multipleMedia.isTransitioning)
                    {
                        Debug.Log("Finishing in-progress transition.");
                        _multipleMedia.FinishTransition();
                        Debug.Log("Multiple media is transition? " + _multipleMedia.isTransitioning);
                    }
                    else
                    {
                        Debug.Log("No in-progress transition");
                    }
                    _playableClips = sphere.GetComponents <PlayableClip>();
                    Array.Sort(_playableClips);

                    _currentClipIndex++;
                    _multipleMedia.expectedCurrentFrame = 0;
                    _multipleMedia.expectedNextFrame    = 1;
                    while (_currentClipIndex < _playableClips.Length && !_playableClips[_currentClipIndex].enabled)
                    {
                        _currentClipIndex++;
                        _multipleMedia.expectedCurrentFrame = 0;
                        _multipleMedia.expectedNextFrame    = 1;
                    }
                    Debug.Log("Next clip index: " + _currentClipIndex);
                    if (_currentClipIndex >= 0 && _currentClipIndex < _playableClips.Length)
                    {
                        Debug.Log(_playableClips[_currentClipIndex].ToString());
                    }
                    _multipleMedia.UpdateAudio();
                }
            }
            else  // Not a gated clip.
            {
                if (_player.Control.IsPlaying() && _playableClips[_currentClipIndex].checkSalient(currentTime, _multipleMedia, this))
                {
                    _playableClips = sphere.GetComponents <PlayableClip>();
                    Array.Sort(_playableClips);
                    Debug.Log("Current time: " + currentTime + ". Finished clip " + _playableClips[_currentClipIndex] + ". Moving from index: " + _currentClipIndex);
                    _currentClipIndex++;
                    _multipleMedia.expectedCurrentFrame = 0;
                    _multipleMedia.expectedNextFrame    = 1;

                    while (_currentClipIndex < _playableClips.Length && !_playableClips[_currentClipIndex].enabled)
                    {
                        _currentClipIndex++;
                        _multipleMedia.expectedCurrentFrame = 0;
                        _multipleMedia.expectedNextFrame    = 1;
                    }
                    Debug.Log("Next clip index: " + _currentClipIndex);
                    _multipleMedia.UpdateAudio();
                }
            }

            if (_currentClipIndex >= _playableClips.Length)
            {
                _currentClipIndex = -1;
                Debug.Log("End of all clips.");
                SetPlayMode(false);
                return;
            }

            if (previousClipIndex != _currentClipIndex && Mathf.Abs(_playableClips[_currentClipIndex].startTime - _playableClips[previousClipIndex].endTime) > 0.5f)
            {
                Debug.Log("Jumping to beginning of next clip index: " + _currentClipIndex + ". " + _playableClips[_currentClipIndex].ToString());
                _multipleMedia.Seek(_playableClips[_currentClipIndex].startTime);
            }
        }
Beispiel #2
0
        public void Transition(int currentFrame, int curView, MultiplePlayerControl multiMedia, HeadTrack _headtrack)
        {
            int gateFrame = (int)(this.gateTime * multiMedia.Player.Info.GetVideoFrameRate());

            if (!isTargetView(curView) && (multiMedia.expectedCurrentFrame == gateFrame || multiMedia.expectedNextFrame == gateFrame) && currentFrame != multiMedia.expectedCurrentFrame && currentFrame != multiMedia.expectedNextFrame)
            {
                Debug.LogError("SKIPPED GATE FRAME!");
            }
            else if (currentFrame > gateFrame || isTargetView(curView))
            {
                multiMedia.expectedCurrentFrame = currentFrame;
                multiMedia.expectedNextFrame    = currentFrame + 1;

                if (sp.jumpImmediately && currentFrame < gateFrame - HeadTrack._LOOP_TRANS_DURATION && isTargetView(curView))
                {
                    int jumpToFrame = gateFrame - (int)(HeadTrack._LOOP_TRANS_DURATION * multiMedia.Player.Info.GetVideoFrameRate());
                    if (sp.views[curView].CanJumpTo(currentFrame, jumpToFrame, sp.jumpThreshold))
                    {
                        float jumpToTime = this.gateTime - HeadTrack._LOOP_TRANS_DURATION;
                        Debug.Log("Frame rate: " + multiMedia.Player.Info.GetVideoFrameRate());
                        Debug.Log("Sp start time: " + sp.startTime + " Jump to time: " + jumpToTime);
                        Debug.Log("GOING to jump from " + (sp.startTime + 1f * currentFrame / multiMedia.Player.Info.GetVideoFrameRate()) + " to time " + (sp.startTime + jumpToTime));
                        this.sp.views[curView].AddLoopArc(sp.startTime + 1f * currentFrame / multiMedia.Player.Info.GetVideoFrameRate(), sp.startTime + jumpToTime, sp.startTime, sp.endTime);
                        Debug.Log("Sp now has " + this.sp.views[curView].GetLoopArcs().Count() + " looparcs");

                        LoopArc currentLoop = this.sp.views[curView].GetCurrentLoop();
                        multiMedia.currentLoopArc = currentLoop;
                        multiMedia._mediaOffset   = currentLoop.fromTime - currentLoop.toTime;
                        Debug.Log("Media current loop arc is " + multiMedia.currentLoopArc + ". Set media offset to " + multiMedia._mediaOffset);

                        // Seek to apply media offset.
                        multiMedia.isTransitioning = true;
                        multiMedia.SyncMediaPlayers();
                        multiMedia.expectedCurrentFrame = jumpToFrame;
                        multiMedia.expectedNextFrame    = jumpToFrame + 1;
                    }
                }

                return; // Don't transition if current frame is past gate frame.
            }

            int jumpTo;
            int fromFrame = currentFrame;

            if (sp.ReachedCutFrame(curView, currentFrame))
            {
                jumpTo = sp.FindJumpToFrame(curView, currentFrame);
                Debug.Log("Reached cut frame. Jumping to: " + jumpTo);
            }
            else if (sp.PastLastCutFrame(curView, currentFrame))  // May happen if computer suddenly lagged and missed a frame update.
            {
                Debug.LogWarning("ERROR! REACHED DANGER ZONE " + curView + ", " + currentFrame);
                int lastCutFrame = sp.FindLastCutFrame(curView);
                jumpTo    = sp.FindJumpToFrame(curView, lastCutFrame);
                fromFrame = lastCutFrame;
            }
            else
            {
                jumpTo = currentFrame + 1;
            }
            multiMedia.expectedCurrentFrame = currentFrame;
            multiMedia.expectedNextFrame    = jumpTo;

            if (jumpTo == currentFrame)
            {
                Debug.Log("Paused media player because jumpto " + jumpTo + " is same as current frame: " + currentFrame);
                _headtrack.playMode = false;
                multiMedia.Pause();
            }
            else if (jumpTo != currentFrame + 1)  // if jumping to a frame that's not the next frame, then perform a seek. Otherwise just keep playing.
            {
                float jumpToTime = 1f * jumpTo / multiMedia.Player.Info.GetVideoFrameRate();
                Debug.Log("Frame rate: " + multiMedia.Player.Info.GetVideoFrameRate());
                Debug.Log("Sp start tiem: " + sp.startTime + " Jump to time: " + jumpToTime);
                Debug.Log("GOING to jump from " + (sp.startTime + 1f * currentFrame / multiMedia.Player.Info.GetVideoFrameRate()) + " to time " + (sp.startTime + jumpToTime));
                this.sp.views[curView].AddLoopArc(sp.startTime + currentFrame / multiMedia.Player.Info.GetVideoFrameRate(), sp.startTime + jumpToTime, sp.startTime, sp.endTime);
                Debug.Log("Sp now has " + this.sp.views[curView].GetLoopArcs().Count() + " looparcs");

                // Set media offset.
                LoopArc currentLoop = this.sp.views[curView].GetCurrentLoop();
                multiMedia.currentLoopArc = currentLoop;
                multiMedia._mediaOffset   = currentLoop.fromTime - currentLoop.toTime;

                Debug.Log("Set media offset to " + multiMedia._mediaOffset);

                // Seek to apply media offset.
                multiMedia.isTransitioning = true;
                multiMedia.SyncMediaPlayers();
                multiMedia.expectedCurrentFrame = jumpTo;
                multiMedia.expectedNextFrame    = jumpTo + 1;
            }
        }