IVideoFrameObserver.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. namespace Agora.Rtc
  2. {
  3. ///
  4. /// <summary>
  5. /// The IVideoFrameObserver class.
  6. /// </summary>
  7. ///
  8. public abstract class IVideoFrameObserver
  9. {
  10. ///
  11. /// <summary>
  12. /// Occurs each time the SDK receives a video frame captured by the local camera.
  13. /// After you successfully register the video frame observer, the SDK triggers this Callback each time it receives a video frame. In this Callback, you can get the video data captured by the local camera. You can then pre-process the data according to your scenarios.After pre-processing, you can send the processed video data back to the SDK through this Callback.The video data that this Callback gets has not been pre-processed, and is not watermarked, cropped, rotated or beautified.
  14. /// </summary>
  15. ///
  16. /// <param name="videoFrame"> The video frame. See VideoFrame .</param>
  17. ///
  18. /// <param name="config"> The configuration of the video frame. See VideoFrameBufferConfig .</param>
  19. ///
  20. /// <returns>
  21. /// true: Sets the SDK to receive the video frame.false: Sets the SDK to discard the video frame.
  22. /// </returns>
  23. ///
  24. public virtual bool OnCaptureVideoFrame(VideoFrame videoFrame, VideoFrameBufferConfig config)
  25. {
  26. return true;
  27. }
  28. ///
  29. /// <summary>
  30. /// Occurs each time the SDK receives a video frame before encoding.
  31. /// After you successfully register the video frame observer, the SDK triggers this Callback each time it receives a video frame. In this Callback, you can get the video data before encoding and then process the data according to your particular scenarios.After processing, you can send the processed video data back to the SDK in this Callback.To get the video data captured from the second screen before encoding, you need to set POSITION_PRE_ENCODER(1 << 2) as a frame position through GetObservedFramePosition .The video data that this callback gets has been preprocessed, with its content cropped and rotated, and the image enhanced.
  32. /// </summary>
  33. ///
  34. /// <param name="config"> The configuration of the video frame. See VideoFrameBufferConfig .</param>
  35. ///
  36. /// <param name="videoFrame"> The video frame. See VideoFrame .</param>
  37. ///
  38. /// <returns>
  39. /// true: Sets the SDK to receive the video frame.false: Sets the SDK to discard the video frame.
  40. /// </returns>
  41. ///
  42. public virtual bool OnPreEncodeVideoFrame(VideoFrame videoFrame, VideoFrameBufferConfig config)
  43. {
  44. return true;
  45. }
  46. ///
  47. /// <summary>
  48. /// Occurs each time the SDK receives a video frame sent by the remote user.
  49. /// After you successfully register the video frame observer, the SDK triggers this Callback each time it receives a video frame. In this Callback, you can get the video data before encoding. You can then process the data according to your particular scenarios.
  50. /// </summary>
  51. ///
  52. /// <param name="videoFrame"> The video frame. See VideoFrame .</param>
  53. ///
  54. /// <param name="uid"> The ID of the remote user who sends the current video frame.</param>
  55. ///
  56. /// <param name="channelId"> The channel ID.</param>
  57. ///
  58. /// <returns>
  59. /// true:The SDK ignores this return value.false:The SDK ignores this return value.
  60. /// </returns>
  61. ///
  62. public virtual bool OnRenderVideoFrame(string channelId, uint uid, VideoFrame videoFrame)
  63. {
  64. return true;
  65. }
  66. ///
  67. /// <summary>
  68. /// Sets the format of the raw video data output by the SDK.
  69. /// If you want to get raw video data in a color encoding format other than YUV 420, register this Callback when calling RegisterVideoFrameObserver . After you successfully register the video frame observer, the SDK triggers this Callback each time it receives a video frame. You need to set your preferred video data in the return value of this Callback.
  70. /// </summary>
  71. ///
  72. /// <returns>
  73. /// Sets the video format. See VIDEO_OBSERVER_FRAME_TYPE .
  74. /// </returns>
  75. ///
  76. public virtual VIDEO_OBSERVER_FRAME_TYPE GetVideoFormatPreference()
  77. {
  78. return VIDEO_OBSERVER_FRAME_TYPE.FRAME_TYPE_RGBA;
  79. }
  80. ///
  81. /// <summary>
  82. /// Sets the frame position for the video observer.
  83. /// After successfully registering the video data observer, the SDK uses this Callback to determine whether to trigger OnCaptureVideoFrame , OnRenderVideoFrame and OnPreEncodeVideoFrame Callback at each specific video frame processing position, so that you can observe the locally collected video data, the video data sent by the remote end, and the video data before encoding. You can set one or more positions you need to observe by modifying the return value according to your scenario:POSITION_POST_CAPTURER(1 << 0) : The position after capturing the video data, which corresponds to the OnCaptureVideoFrame callback.POSITION_PRE_RENDERER(1 << 1): The position before receiving the remote video data, which corresponds to the OnRenderVideoFrame callback.POSITION_PRE_ENCODER(1 << 2): The position before encoding the video data, which corresponds to the OnPreEncodeVideoFrame callback.Use '|' (the OR operator) to observe multiple frame positions.This callback observesPOSITION_POST_CAPTURER (1 << 0) andPOSITION_PRE_RENDERER (1 << 1) by default.To conserve the system consumption, you can reduce the number of frame positions that you want to observe.
  84. /// </summary>
  85. ///
  86. /// <returns>
  87. /// A bit mask that controls the frame position of the video observer. See VIDEO_MODULE_POSITION .
  88. /// </returns>
  89. ///
  90. public virtual VIDEO_OBSERVER_POSITION GetObservedFramePosition()
  91. {
  92. return VIDEO_OBSERVER_POSITION.POSITION_POST_CAPTURER | VIDEO_OBSERVER_POSITION.POSITION_PRE_RENDERER;
  93. }
  94. }
  95. }