VideoInputProvider.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 CurrentFrame { 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> playStep;
  17. public VideoInputProvider(String moviePath)
  18. {
  19. MoviePath = moviePath;
  20. }
  21. protected override IDeviceConfiguration createDeviceConfiguration()
  22. {
  23. IDeviceConfiguration conf = base.createDeviceConfiguration();
  24. conf.MoviePath = MoviePath;
  25. return conf;
  26. }
  27. protected override void registerHandles()
  28. {
  29. base.registerHandles();
  30. device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayMode").Value = 1; // 0=once, 1=loop, 2=pingPong
  31. currentMovieFrame = device.RegisterParameterHandle<int>("SOURCE.MOVIE.CurrentFrame");
  32. playStep = device.RegisterParameterHandle<int>("SOURCE.MOVIE.PlayStep");
  33. }
  34. public void pause()
  35. {
  36. playStep.Value = 0;
  37. Logger.log("Video pause", LogSubject.VideoControls);
  38. }
  39. public void play()
  40. {
  41. playStep.Value = 1;
  42. Logger.log("Video play", LogSubject.VideoControls);
  43. }
  44. public void nextFrame()
  45. {
  46. playStep.Value = 1;
  47. int nextFrame = currentMovieFrame.Value + 1;
  48. while (currentMovieFrame.Value != nextFrame)
  49. {
  50. device.UpdateFrame(false);
  51. device.ReleaseFrame();
  52. }
  53. playStep.Value = 0;
  54. Logger.log("Video nextFrame", LogSubject.VideoControls);
  55. }
  56. public void previousFrame()
  57. {
  58. playStep.Value = -1;
  59. int previousFrame = currentMovieFrame.Value - 1;
  60. while (currentMovieFrame.Value != previousFrame)
  61. {
  62. device.UpdateFrame(false);
  63. device.ReleaseFrame();
  64. }
  65. playStep.Value = 0;
  66. Logger.log("Video previousFrame", LogSubject.VideoControls);
  67. }
  68. }
  69. }