osr_video_consumer.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 <string>
  8. #include "base/callback.h"
  9. #include "base/memory/weak_ptr.h"
  10. #include "components/viz/host/client_frame_sink_video_capturer.h"
  11. #include "media/capture/mojom/video_capture_types.mojom.h"
  12. namespace electron {
  13. class OffScreenRenderWidgetHostView;
  14. typedef base::RepeatingCallback<void(const gfx::Rect&, const SkBitmap&)>
  15. OnPaintCallback;
  16. class OffScreenVideoConsumer : public viz::mojom::FrameSinkVideoConsumer {
  17. public:
  18. OffScreenVideoConsumer(OffScreenRenderWidgetHostView* view,
  19. OnPaintCallback callback);
  20. ~OffScreenVideoConsumer() override;
  21. void SetActive(bool active);
  22. void SetFrameRate(int frame_rate);
  23. void SizeChanged();
  24. private:
  25. // viz::mojom::FrameSinkVideoConsumer implementation.
  26. void OnFrameCaptured(
  27. base::ReadOnlySharedMemoryRegion data,
  28. ::media::mojom::VideoFrameInfoPtr info,
  29. const gfx::Rect& content_rect,
  30. mojo::PendingRemote<viz::mojom::FrameSinkVideoConsumerFrameCallbacks>
  31. callbacks) override;
  32. void OnStopped() override;
  33. void OnLog(const std::string& message) override;
  34. bool CheckContentRect(const gfx::Rect& content_rect);
  35. OnPaintCallback callback_;
  36. OffScreenRenderWidgetHostView* view_;
  37. std::unique_ptr<viz::ClientFrameSinkVideoCapturer> video_capturer_;
  38. base::WeakPtrFactory<OffScreenVideoConsumer> weak_ptr_factory_;
  39. DISALLOW_COPY_AND_ASSIGN(OffScreenVideoConsumer);
  40. };
  41. } // namespace electron
  42. #endif // SHELL_BROWSER_OSR_OSR_VIDEO_CONSUMER_H_