using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using Iisu; using bbiwarg.Utility; namespace bbiwarg.Input.InputProviding { /// /// signature for the event that the movie has restarted /// /// event sender /// event arguments public delegate void MovieRestartedEventHandler(object sender, EventArgs e); /// /// VideoInputProvider provides the raw depth and confidence data read from a video file. /// class VideoInputProvider : InputProvider { /// /// parameter handle for the current frame of the movie /// private IParameterHandle currentMovieFrame; /// /// parameter handle for the number of frames in the movie /// private IParameterHandle frameCount; /// /// parameter handle for the play step, which is the value that gets added to the current frame in each iteration /// private IParameterHandle playStep; /// /// the id of the current frame /// public override int CurrentFrameID { get { return currentMovieFrame.Value; } } /// /// the path to the movie file /// public String MoviePath { get; private set; } /// /// true iff the movie is paused /// public bool IsPaused { get; private set; } /// /// event that the movie has restarted /// public event MovieRestartedEventHandler MovieRestartedEvent; /// /// Constructs a VideoInputProvider. /// /// path to the movie file public VideoInputProvider(String moviePath) { MoviePath = moviePath; } /// /// Returns an iisu device configuration, which uses the movie to read the data. /// /// iisu device configuration protected override IDeviceConfiguration createDeviceConfiguration() { IDeviceConfiguration conf = base.createDeviceConfiguration(); conf.MoviePath = MoviePath; return conf; } /// /// Registers all parameter and data handles. /// protected override void registerHandles() { base.registerHandles(); device.RegisterParameterHandle("SOURCE.MOVIE.PlayMode").Value = 1; // 0=once, 1=loop, 2=pingPong currentMovieFrame = device.RegisterParameterHandle("SOURCE.MOVIE.CurrentFrame"); frameCount = device.RegisterParameterHandle("SOURCE.MOVIE.FrameCount"); playStep = device.RegisterParameterHandle("SOURCE.MOVIE.PlayStep"); } /// /// Pauses the movie. No data is read anymore. /// public void pause() { IsPaused = true; } /// /// Resumes playing the movie and reading data. /// public void play() { IsPaused = false; } /// /// Jumps to the next movie frame. /// public void goToNextFrame() { nextFrame(); } /// /// Jumps to the previous movie frame. /// public void goToPreviousFrame() { playStep.Value = -1; nextFrame(); playStep.Value = 1; } /// /// Provides the main loop for reading data from the video file. /// protected override void run() { while (IsActive) { if (!IsPaused) nextFrame(); else Thread.Sleep((int)(1000 / frameRate.Value)); } } /// /// Gets the next frame from the device and triggers an event if the movie has restarted. /// protected override void nextFrame() { base.nextFrame(); if (CurrentFrameID == 0 && MovieRestartedEvent != null) MovieRestartedEvent(this, new EventArgs()); } } }