UnityVideoRenderer.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #pragma once
  2. #include <mutex>
  3. #include <api/video/video_frame.h>
  4. #include <api/video/video_sink_interface.h>
  5. #include <third_party/libyuv/include/libyuv.h>
  6. #include "WebRTCPlugin.h"
  7. namespace unity
  8. {
  9. namespace webrtc
  10. {
  11. using namespace ::webrtc;
  12. class UnityVideoRenderer : public rtc::VideoSinkInterface<::webrtc::VideoFrame>
  13. {
  14. public:
  15. UnityVideoRenderer(uint32_t id, DelegateVideoFrameResize callback, bool needFlipVertical);
  16. ~UnityVideoRenderer() override;
  17. void OnFrame(const ::webrtc::VideoFrame& frame) override;
  18. uint32_t GetId();
  19. rtc::scoped_refptr<VideoFrameBuffer> GetFrameBuffer();
  20. void SetFrameBuffer(rtc::scoped_refptr<VideoFrameBuffer> buffer, int64_t timestamp);
  21. // used in UnityRenderingExtEventUpdateTexture
  22. // called on RenderThread
  23. void* ConvertVideoFrameToTextureAndWriteToBuffer(int width, int height, libyuv::FourCC format);
  24. private:
  25. uint32_t m_id;
  26. std::mutex m_mutex;
  27. std::vector<uint8_t> tempBuffer;
  28. rtc::scoped_refptr<webrtc::VideoFrameBuffer> m_frameBuffer;
  29. int64_t m_last_renderered_timestamp;
  30. std::atomic<int64_t> m_timestamp;
  31. DelegateVideoFrameResize m_callback;
  32. bool m_needFlipVertical;
  33. };
  34. } // end namespace webrtc
  35. } // end namespace unity