webrtc_video_frame_adapter.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef REMOTING_PROTOCOL_WEBRTC_VIDEO_FRAME_ADAPTER_H_
  5. #define REMOTING_PROTOCOL_WEBRTC_VIDEO_FRAME_ADAPTER_H_
  6. #include <memory>
  7. #include "remoting/codec/webrtc_video_encoder.h"
  8. #include "third_party/webrtc/api/video/video_frame.h"
  9. #include "third_party/webrtc/api/video/video_frame_buffer.h"
  10. #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
  11. namespace remoting {
  12. namespace protocol {
  13. // Adapter class to wrap a DesktopFrame produced by the capturer, and provide
  14. // it as a VideoFrame to the WebRTC video sink. The encoder will extract the
  15. // captured DesktopFrame from VideoFrame::video_frame_buffer().
  16. class WebrtcVideoFrameAdapter : public webrtc::VideoFrameBuffer {
  17. public:
  18. WebrtcVideoFrameAdapter(
  19. std::unique_ptr<webrtc::DesktopFrame> frame,
  20. std::unique_ptr<WebrtcVideoEncoder::FrameStats> frame_stats);
  21. ~WebrtcVideoFrameAdapter() override;
  22. WebrtcVideoFrameAdapter(const WebrtcVideoFrameAdapter&) = delete;
  23. WebrtcVideoFrameAdapter& operator=(const WebrtcVideoFrameAdapter&) = delete;
  24. // Returns a VideoFrame that wraps the provided DesktopFrame.
  25. static webrtc::VideoFrame CreateVideoFrame(
  26. std::unique_ptr<webrtc::DesktopFrame> desktop_frame,
  27. std::unique_ptr<WebrtcVideoEncoder::FrameStats> frame_stats);
  28. // Used by the encoder. After this returns, the adapter no longer wraps a
  29. // DesktopFrame.
  30. std::unique_ptr<webrtc::DesktopFrame> TakeDesktopFrame();
  31. // Called by the encoder to transfer the frame stats out of this adapter
  32. // into the EncodedFrame. The encoder will also set the encode start/end
  33. // times.
  34. std::unique_ptr<WebrtcVideoEncoder::FrameStats> TakeFrameStats();
  35. // webrtc::VideoFrameBuffer overrides.
  36. Type type() const override;
  37. int width() const override;
  38. int height() const override;
  39. rtc::scoped_refptr<webrtc::I420BufferInterface> ToI420() override;
  40. private:
  41. std::unique_ptr<webrtc::DesktopFrame> frame_;
  42. webrtc::DesktopSize frame_size_;
  43. std::unique_ptr<WebrtcVideoEncoder::FrameStats> frame_stats_;
  44. };
  45. } // namespace protocol
  46. } // namespace remoting
  47. #endif // REMOTING_PROTOCOL_WEBRTC_VIDEO_FRAME_ADAPTER_H_