GIFRecorder.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * NatCorder
  3. * Copyright (c) 2020 Yusuf Olokoba.
  4. */
  5. namespace NatSuite.Recorders {
  6. using System;
  7. using System.Threading.Tasks;
  8. using Internal;
  9. /// <summary>
  10. /// Animated GIF image recorder.
  11. /// </summary>
  12. public sealed class GIFRecorder : IMediaRecorder {
  13. #region --Client API--
  14. /// <summary>
  15. /// Image size.
  16. /// </summary>
  17. public (int width, int height) frameSize => recorder.frameSize;
  18. /// <summary>
  19. /// Create a GIF recorder.
  20. /// </summary>
  21. /// <param name="width">Image width.</param>
  22. /// <param name="height">Image height.</param>
  23. /// <param name="frameDuration">Frame duration in seconds.</param>
  24. public GIFRecorder (int width, int height, float frameDuration) => this.recorder = new NativeRecorder((callback, context) => Bridge.CreateGIFRecorder(width, height, frameDuration, Utility.GetPath(@".gif"), callback, context));
  25. /// <summary>
  26. /// Commit a video pixel buffer for encoding.
  27. /// The pixel buffer MUST have an RGBA8888 pixel layout.
  28. /// </summary>
  29. /// <param name="pixelBuffer">Pixel buffer containing video frame to commit.</param>
  30. /// <param name="timestamp">Not used.</param>
  31. public void CommitFrame<T> (T[] pixelBuffer, long timestamp = default) where T : struct => recorder.CommitFrame(pixelBuffer, timestamp);
  32. /// <summary>
  33. /// Commit a video pixel buffer for encoding.
  34. /// The pixel buffer MUST have an RGBA8888 pixel layout.
  35. /// </summary>
  36. /// <param name="nativeBuffer">Pixel buffer in native memory to commit.</param>
  37. /// <param name="timestamp">Not used.</param>
  38. public void CommitFrame (IntPtr nativeBuffer, long timestamp = default) => recorder.CommitFrame(nativeBuffer, timestamp);
  39. /// <summary>
  40. /// This recorder does not support committing sample buffers.
  41. /// </summary>
  42. public void CommitSamples (float[] sampleBuffer = default, long timestamp = default) { }
  43. /// <summary>
  44. /// Finish writing and return the path to the recorded media file.
  45. /// </summary>
  46. public Task<string> FinishWriting () => recorder.FinishWriting();
  47. #endregion
  48. private readonly IMediaRecorder recorder;
  49. }
  50. }