public void RefreshTimeline() { if (sphere == null) { sphere = GameObject.Find("Sphere"); } _multipleMedia = sphere.GetComponent <MultiplePlayerControl>(); _player = _multipleMedia.Player; _gatedClips = GetComponents <GatedClip>(); _playableClips = GetComponents <PlayableClip>(); _previewMode = GetComponent <PreviewMode>(); Debug.Assert(_previewMode != null); _previewMode.equirectTexture = null; this.SetupEquirectTexture(); Array.Sort(_playableClips); Debug.Log("Inside refresh timeline. Number of playable clips: " + _playableClips.Length + ", Number of gated clips: " + _gatedClips.Length); for (int i = 0; i < _playableClips.Length; i++) { if (_playableClips[i].enabled) { _currentClipIndex = i; break; } } initialized = true; }
public override bool PassedGate(float currentTime, MultiplePlayerControl multiMedia) { float relativeTime = currentTime - this.startTime; int currentFrame = (int)(relativeTime * multiMedia.Player.Info.GetVideoFrameRate()); int gateFrame = (int)(this.gateTime * multiMedia.Player.Info.GetVideoFrameRate()); return(currentFrame > gateFrame); }
public void SeekRequest(float sec) // Sec on timeline. { _playableClips = GetComponents <PlayableClip>(); Array.Sort(_playableClips); Debug.Log("Seek Request: " + sec); // Find the right clip. int requestedClipIndex = -1; for (int i = 0; i < _playableClips.Length - 1; i++) { if (sec >= _playableClips[i].timelinePos && sec < _playableClips[i + 1].timelinePos) { requestedClipIndex = i; break; } } int lastIndex = _playableClips.Length - 1; if (sec >= _playableClips[lastIndex].timelinePos && sec < _playableClips[lastIndex].timelinePos + (_playableClips[lastIndex].endTime - _playableClips[lastIndex].startTime)) { requestedClipIndex = lastIndex; } // Seek to location. if (requestedClipIndex >= 0) { _multipleMedia = sphere.GetComponent <MultiplePlayerControl>(); _player = _multipleMedia.Player; _currentClipIndex = requestedClipIndex; float videoTime = (sec - _playableClips[requestedClipIndex].timelinePos) + _playableClips[requestedClipIndex].startTime; Debug.Log("Set current clip index to " + _currentClipIndex + ": " + _playableClips[_currentClipIndex].ToString()); if (_player != null && _player.Control != null) { Debug.Log("Seeking to video time: " + videoTime); _multipleMedia.Seek(videoTime); this.CurrentVisibleView = GetVisibleView(); } else { Debug.Log("Either player or player control is null. Not seeking."); } } else { Debug.Log("Did not find clip that seek time falls under. Ignoring."); } }
public virtual bool checkSalient(float currentTime, MultiplePlayerControl multiMedia, HeadTrack _headtrack) { if (_headTrack == null) { _headTrack = GetComponent <HeadTrack>(); } MediaPlayer player = multiMedia.Player; float threshold = 1.0f / _headtrack.GetVideoFps(); if (Math.Abs(currentTime - endTime) < threshold) { return(true); // Saliency means we passed this clip. Can move pointer to next clip. } return(false); }
// 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); } }
public virtual bool PassedGate(float time, MultiplePlayerControl multicontrol) { return(true); }
public override bool checkSalient(float currentTime, MultiplePlayerControl multiMedia, HeadTrack _headtrack) { float relativeTime = currentTime - this.startTime; int currentFrame = (int)(relativeTime * multiMedia.Player.Info.GetVideoFrameRate()); int gateFrame = (int)(this.gateTime * multiMedia.Player.Info.GetVideoFrameRate()); int curView = _headTrack.GetVisibleView(); if (_currentView != curView) { if (multiMedia.isTransitioning && multiMedia.currentLoopArc.toTime > multiMedia.currentLoopArc.fromTime) { Debug.Log("VIEW CHANGED IN MIDDLE OF TRANSITION. Was " + _currentView + ". Now: " + curView + ". Calling FinishTransition."); multiMedia.FinishTransition(); } if (multiMedia.IsPaused()) { if (GetComponent <PreviewMode>().requestedPlayMode) { Debug.Log("CURVIEW WAS IN PAUSED STATE. Now: " + curView + ". Playing again."); _headtrack.playMode = true; } } _currentView = curView; } if (!_ROIWithinView) { if (isTargetView(curView)) { _ROIWithinView = true; if (multiMedia.isTransitioning) { Debug.Log("TARGET CAME INTO VIEW AGAIN. Calling FinishTransition"); multiMedia.FinishTransition(); } if (multiMedia.IsPaused()) { _headtrack.playMode = true; multiMedia.Play(); } } } if (multiMedia.isTransitioning && (!isTargetView(curView) && sp.IsCutFrame(curView, currentFrame))) { Debug.Log("Current frame: " + currentFrame + ". Entered another valid frame when transitioning.... Exiting transition"); multiMedia.FinishTransition(); Debug.Log("Exited? " + !multiMedia.isTransitioning); } if (multiMedia.isTransitioning) { Debug.Log("Current loop is " + multiMedia.currentLoopArc); multiMedia.UnidirectionalTransition(); multiMedia.expectedCurrentFrame = currentFrame; multiMedia.expectedNextFrame = currentFrame + 1; } else { Transition(currentFrame, _currentView, multiMedia, _headtrack); } return(currentTime > this.endTime); // Return true if Headtrack can move onto the next clip. Else false. }
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; } }