VideoInputProvider.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Iisu;
  7. using bbiwarg.Utility;
  8. namespace bbiwarg.InputProviders
  9. {
  10. class VideoInputProvider : InputProvider
  11. {
  12. public override int CurrentFrameID { get { return currentMovieFrame.Value; } }
  13. public String MoviePath { get; private set; }
  14. public bool IsPaused { get { return (playStep.Value == 0); } }
  15. private IParameterHandle<int> currentMovieFrame;
  16. private IParameterHandle<int> frameCount;
  17. private IParameterHandle<int> playStep;
  18. public VideoInputProvider(String moviePath)
  19. {
  20. MoviePath = moviePath;
  21. }
  22. protected override IDeviceConfiguration createDeviceConfiguration()
  23. {
  24. IDeviceConfiguration conf = base.createDeviceConfiguration();
  25. conf.MoviePath = MoviePath;
  26. return conf;
  27. }
  28. protected override void registerHandles()
  29. {
  30. base.registerHandles();
  31. device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayMode").Value = 1; // 0=once, 1=loop, 2=pingPong
  32. currentMovieFrame = device.RegisterParameterHandle<int>("SOURCE.MOVIE.CurrentFrame");
  33. frameCount = device.RegisterParameterHandle<int>("SOURCE.MOVIE.FrameCount");
  34. playStep = device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayStep");
  35. }
  36. public void pause()
  37. {
  38. playStep.Value = 0;
  39. Logger.log("Video pause", LogSubject.VideoControls);
  40. }
  41. public void play()
  42. {
  43. playStep.Value = 1;
  44. Logger.log("Video play", LogSubject.VideoControls);
  45. }
  46. public void nextFrame()
  47. {
  48. playStep.Value = 1;
  49. int nextFrame = Math.Min((currentMovieFrame.Value + 1), frameCount.Value - 1);
  50. while (currentMovieFrame.Value != nextFrame)
  51. {
  52. device.UpdateFrame(true);
  53. device.ReleaseFrame();
  54. }
  55. playStep.Value = 0;
  56. Logger.log("Video nextFrame", LogSubject.VideoControls);
  57. }
  58. public void previousFrame()
  59. {
  60. playStep.Value = -1;
  61. int previousFrame = Math.Max((currentMovieFrame.Value - 1), 0);
  62. while (currentMovieFrame.Value != previousFrame)
  63. {
  64. device.UpdateFrame(true);
  65. device.ReleaseFrame();
  66. }
  67. playStep.Value = 0;
  68. Logger.log("Video previousFrame", LogSubject.VideoControls);
  69. }
  70. }
  71. }