#pragma once #include #include #include #include #include "WebRTCPlugin.h" namespace unity { namespace webrtc { using namespace ::webrtc; class UnityVideoRenderer : public rtc::VideoSinkInterface<::webrtc::VideoFrame> { public: UnityVideoRenderer(uint32_t id, DelegateVideoFrameResize callback, bool needFlipVertical); ~UnityVideoRenderer() override; void OnFrame(const ::webrtc::VideoFrame& frame) override; uint32_t GetId(); rtc::scoped_refptr GetFrameBuffer(); void SetFrameBuffer(rtc::scoped_refptr buffer, int64_t timestamp); // used in UnityRenderingExtEventUpdateTexture // called on RenderThread void* ConvertVideoFrameToTextureAndWriteToBuffer(int width, int height, libyuv::FourCC format); private: uint32_t m_id; std::mutex m_mutex; std::vector tempBuffer; rtc::scoped_refptr m_frameBuffer; int64_t m_last_renderered_timestamp; std::atomic m_timestamp; DelegateVideoFrameResize m_callback; bool m_needFlipVertical; }; } // end namespace webrtc } // end namespace unity