Bladeren bron

Added pause / unpause and next / previous frame to video playback. (pause / unpause: space, prev / next: left / right)

Daniel Kauth 10 jaren geleden
bovenliggende
commit
2f055d997c

+ 50 - 2
bbiwarg/Graphics/OutputWindow.cs

@@ -16,10 +16,15 @@ namespace bbiwarg.Graphics
         private VideoHandle videoHandle;
         private uint depthTextureID;
         private uint edgeTextureID;
+        private bool paused = false;
+        private long timeSpacePressed, timeLeftPressed, timeRightPressed;
+        private Stopwatch watch;
 
         public OutputWindow(VideoHandle videoHandle): base(3 * videoHandle.getWidth(), 2 * videoHandle.getHeight())
         {
             this.videoHandle = videoHandle;
+            watch = new Stopwatch();
+            watch.Start();
         }
 
         protected override void OnLoad(EventArgs e)
@@ -68,8 +73,51 @@ namespace bbiwarg.Graphics
             Matrix4 modelview = Matrix4.LookAt(Vector3.Zero, -Vector3.UnitZ, Vector3.UnitY);
             GL.MatrixMode(MatrixMode.Modelview);
             GL.LoadMatrix(ref modelview);
-            
-            videoHandle.nextFrame();
+
+            const int auotRepeatDelay = 100; // ms
+            if (videoHandle.sourceIsMovie())
+            {
+                // pause and unpause with space
+                long elapsed = watch.ElapsedMilliseconds;
+                if (OpenTK.Input.Keyboard.GetState().IsKeyDown(OpenTK.Input.Key.Space) && (elapsed - timeSpacePressed) >= auotRepeatDelay)
+                {
+                    timeSpacePressed = elapsed;
+                    if (paused)
+                        videoHandle.unpauseMovie();
+                    else
+                        videoHandle.pauseMovie();
+                    paused = !paused;
+                }
+
+                // when paused go to next / previous frame with right / left keys
+                if (paused)
+                {
+                    if (OpenTK.Input.Keyboard.GetState().IsKeyDown(OpenTK.Input.Key.Right) && (elapsed - timeRightPressed) >= auotRepeatDelay)
+                    {
+                        timeRightPressed = elapsed;
+                        videoHandle.unpauseMovie();
+                        videoHandle.nextFrame();
+                        videoHandle.pauseMovie();
+                    }
+                    else if (OpenTK.Input.Keyboard.GetState().IsKeyDown(OpenTK.Input.Key.Left) && (elapsed - timeLeftPressed) >= auotRepeatDelay)
+                    {
+                        timeLeftPressed = elapsed;
+                        videoHandle.unpauseMovie();
+                        videoHandle.reversePlay();
+                        videoHandle.nextFrame();
+                        videoHandle.reversePlay();
+                        videoHandle.pauseMovie();
+                    }
+                }
+                else
+                {
+                    videoHandle.nextFrame();
+                }
+            }
+            else
+            {
+                videoHandle.nextFrame();
+            }
 
             //draw textures
             Int16[] depthTextureData = new Int16[3 * videoHandle.getWidth() * videoHandle.getHeight()];

+ 8 - 0
bbiwarg/InputProvider/IInputProvider.cs

@@ -50,5 +50,13 @@ namespace bbiwarg.InputProviders
         Vector[] getFingerTipPositions3D(uint handIndex);
         Vector[] getFingerTipPositions2D(uint handIndex);
         HandSide getHandSide(uint handIndex);
+
+        void pauseMovie();
+
+        void unpauseMovie();
+
+        bool sourceIsMovie();
+
+        void reversePlay();
     }
 }

+ 25 - 0
bbiwarg/InputProvider/IisuInputProvider.cs

@@ -19,6 +19,7 @@ namespace bbiwarg.InputProviders
         private IParameterHandle<float> frameRate;
         private IParameterHandle<float> hfov;
         private IParameterHandle<float> vfov;
+        private IParameterHandle<int> playStep;
 
         //data
         private IDataHandle<int>[] handStatus = new IDataHandle<int>[2];
@@ -69,6 +70,7 @@ namespace bbiwarg.InputProviders
                 //device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayMode").Value = 0; // playMode = once
                 device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayMode").Value = 1; // playMode = loop
                 //device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayMode").Value = 2; // playMode = ping-pong
+                playStep = device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayStep");
             }
             else
             {
@@ -337,5 +339,28 @@ namespace bbiwarg.InputProviders
             return vector;
         }
 
+        public void pauseMovie()
+        {
+            if (sourceIsMovie)
+                playStep.Value = 0;
+        }
+
+        public void unpauseMovie()
+        {
+            if (sourceIsMovie)
+                playStep.Value = 1;
+        }
+
+
+        bool IInputProvider.sourceIsMovie()
+        {
+            return sourceIsMovie;
+        }
+
+        public void reversePlay()
+        {
+            if (sourceIsMovie)
+                playStep.Value = -playStep.Value;
+        }
     }
 }

+ 20 - 0
bbiwarg/VideoHandle.cs

@@ -51,6 +51,26 @@ namespace bbiwarg
             inputProvider.stop();
         }
 
+        public bool sourceIsMovie()
+        {
+            return inputProvider.sourceIsMovie();
+        }
+
+        public void reversePlay()
+        {
+            inputProvider.reversePlay();
+        }
+
+        public void pauseMovie()
+        {
+            inputProvider.pauseMovie();
+        }
+
+        public void unpauseMovie()
+        {
+            inputProvider.unpauseMovie();
+        }
+
         public void nextFrame()
         {
             if (inputProvider.isActive())