osr_video_consumer.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (c) 2019 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef SHELL_BROWSER_OSR_OSR_VIDEO_CONSUMER_H_
  5. #define SHELL_BROWSER_OSR_OSR_VIDEO_CONSUMER_H_
  6. #include <memory>
  7. #include "base/callback.h"
  8. #include "base/memory/weak_ptr.h"
  9. #include "components/viz/host/client_frame_sink_video_capturer.h"
  10. namespace electron {
  11. class OffScreenRenderWidgetHostView;
  12. typedef base::RepeatingCallback<void(const gfx::Rect&, const SkBitmap&)>
  13. OnPaintCallback;
  14. class OffScreenVideoConsumer : public viz::mojom::FrameSinkVideoConsumer {
  15. public:
  16. OffScreenVideoConsumer(OffScreenRenderWidgetHostView* view,
  17. OnPaintCallback callback);
  18. ~OffScreenVideoConsumer() override;
  19. void SetActive(bool active);
  20. void SetFrameRate(int frame_rate);
  21. void SizeChanged();
  22. private:
  23. // viz::mojom::FrameSinkVideoConsumer implementation.
  24. void OnFrameCaptured(
  25. base::ReadOnlySharedMemoryRegion data,
  26. ::media::mojom::VideoFrameInfoPtr info,
  27. const gfx::Rect& content_rect,
  28. viz::mojom::FrameSinkVideoConsumerFrameCallbacksPtr callbacks) override;
  29. void OnStopped() override;
  30. bool CheckContentRect(const gfx::Rect& content_rect);
  31. OnPaintCallback callback_;
  32. OffScreenRenderWidgetHostView* view_;
  33. std::unique_ptr<viz::ClientFrameSinkVideoCapturer> video_capturer_;
  34. base::WeakPtrFactory<OffScreenVideoConsumer> weak_ptr_factory_;
  35. DISALLOW_COPY_AND_ASSIGN(OffScreenVideoConsumer);
  36. };
  37. } // namespace electron
  38. #endif // SHELL_BROWSER_OSR_OSR_VIDEO_CONSUMER_H_