video_frame_provider_client_impl.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright 2013 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 CC_LAYERS_VIDEO_FRAME_PROVIDER_CLIENT_IMPL_H_
  5. #define CC_LAYERS_VIDEO_FRAME_PROVIDER_CLIENT_IMPL_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "base/memory/ref_counted.h"
  8. #include "base/synchronization/lock.h"
  9. #include "base/threading/thread_checker.h"
  10. #include "cc/cc_export.h"
  11. #include "cc/layers/video_frame_provider.h"
  12. #include "cc/scheduler/video_frame_controller.h"
  13. #include "ui/gfx/geometry/transform.h"
  14. namespace media { class VideoFrame; }
  15. namespace cc {
  16. class VideoLayerImpl;
  17. // VideoFrameProviderClientImpl liaisons with the VideoFrameProvider and the
  18. // VideoLayer. It receives updates from the provider and updates the layer as a
  19. // result. It also allows the layer to access the video frame that the provider
  20. // has.
  21. class CC_EXPORT VideoFrameProviderClientImpl
  22. : public VideoFrameProvider::Client,
  23. public VideoFrameController,
  24. public base::RefCounted<VideoFrameProviderClientImpl> {
  25. public:
  26. // Must be created on the impl thread while the main thread is blocked.
  27. static scoped_refptr<VideoFrameProviderClientImpl> Create(
  28. VideoFrameProvider* provider,
  29. VideoFrameControllerClient* client);
  30. VideoFrameProviderClientImpl(const VideoFrameProviderClientImpl&) = delete;
  31. VideoFrameProviderClientImpl& operator=(const VideoFrameProviderClientImpl&) =
  32. delete;
  33. VideoLayerImpl* ActiveVideoLayer() const;
  34. void SetActiveVideoLayer(VideoLayerImpl* video_layer);
  35. bool Stopped() const;
  36. // Must be called on the impl thread while the main thread is blocked.
  37. void Stop();
  38. scoped_refptr<media::VideoFrame> AcquireLockAndCurrentFrame()
  39. EXCLUSIVE_LOCK_FUNCTION(provider_lock_);
  40. void PutCurrentFrame() EXCLUSIVE_LOCKS_REQUIRED(provider_lock_);
  41. void ReleaseLock() UNLOCK_FUNCTION(provider_lock_);
  42. void AssertLocked() const ASSERT_EXCLUSIVE_LOCK(provider_lock_) {
  43. provider_lock_.AssertAcquired();
  44. }
  45. bool HasCurrentFrame();
  46. // VideoFrameController implementation.
  47. void OnBeginFrame(const viz::BeginFrameArgs& args) override;
  48. void DidDrawFrame() override;
  49. // VideoFrameProvider::Client implementation.
  50. // Called on the main thread.
  51. void StopUsingProvider() override;
  52. // Called on the impl thread.
  53. void StartRendering() override;
  54. void StopRendering() override;
  55. void DidReceiveFrame() override;
  56. bool IsDrivingFrameUpdates() const override;
  57. const VideoFrameProvider* get_provider_for_testing() const {
  58. return provider_;
  59. }
  60. private:
  61. friend class base::RefCounted<VideoFrameProviderClientImpl>;
  62. VideoFrameProviderClientImpl(VideoFrameProvider* provider,
  63. VideoFrameControllerClient* client);
  64. ~VideoFrameProviderClientImpl() override;
  65. raw_ptr<VideoFrameProvider> provider_;
  66. raw_ptr<VideoFrameControllerClient> client_;
  67. raw_ptr<VideoLayerImpl> active_video_layer_;
  68. bool stopped_;
  69. bool rendering_;
  70. bool needs_put_current_frame_;
  71. // Since the provider lives on another thread, it can be destroyed while the
  72. // frame controller are accessing its frame. Before being destroyed the
  73. // provider calls StopUsingProvider. provider_lock_ blocks StopUsingProvider
  74. // from returning until the frame controller is done using the frame.
  75. base::Lock provider_lock_;
  76. base::ThreadChecker thread_checker_;
  77. };
  78. } // namespace cc
  79. #endif // CC_LAYERS_VIDEO_FRAME_PROVIDER_CLIENT_IMPL_H_