| OLD | NEW | 
|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_COMPOSITOR_H | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_COMPOSITOR_H | 
| 6 #define CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_COMPOSITOR_H | 6 #define CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_COMPOSITOR_H | 
| 7 | 7 | 
| 8 #include <map> | 8 #include <map> | 
| 9 #include <vector> | 9 #include <vector> | 
| 10 | 10 | 
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" | 
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" | 
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" | 
| 14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" | 
| 15 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" | 
| 16 #include "cc/layers/video_frame_provider.h" | 16 #include "cc/layers/video_frame_provider.h" | 
|  | 17 #include "content/common/content_export.h" | 
| 17 | 18 | 
| 18 namespace base { | 19 namespace base { | 
| 19 class SingleThreadTaskRunner; | 20 class SingleThreadTaskRunner; | 
| 20 } | 21 } | 
| 21 | 22 | 
| 22 namespace blink { | 23 namespace blink { | 
| 23 class WebURL; | 24 class WebURL; | 
| 24 } | 25 } | 
| 25 | 26 | 
| 26 namespace gfx { | 27 namespace gfx { | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 37 | 38 | 
| 38 // This class is designed to handle the work load on compositor thread for | 39 // This class is designed to handle the work load on compositor thread for | 
| 39 // WebMediaPlayerMS. It will be instantiated on the main thread, but destroyed | 40 // WebMediaPlayerMS. It will be instantiated on the main thread, but destroyed | 
| 40 // on the compositor thread. | 41 // on the compositor thread. | 
| 41 // | 42 // | 
| 42 // WebMediaPlayerMSCompositor utilizes VideoRendererAlgorithm to store the | 43 // WebMediaPlayerMSCompositor utilizes VideoRendererAlgorithm to store the | 
| 43 // incoming frames and select the best frame for rendering to maximize the | 44 // incoming frames and select the best frame for rendering to maximize the | 
| 44 // smoothness, if REFERENCE_TIMEs are populated for incoming VideoFrames. | 45 // smoothness, if REFERENCE_TIMEs are populated for incoming VideoFrames. | 
| 45 // Otherwise, WebMediaPlayerMSCompositor will simply store the most recent | 46 // Otherwise, WebMediaPlayerMSCompositor will simply store the most recent | 
| 46 // frame, and submit it whenever asked by the compositor. | 47 // frame, and submit it whenever asked by the compositor. | 
| 47 class WebMediaPlayerMSCompositor : public cc::VideoFrameProvider { | 48 class CONTENT_EXPORT WebMediaPlayerMSCompositor | 
|  | 49     : public NON_EXPORTED_BASE(cc::VideoFrameProvider) { | 
| 48  public: | 50  public: | 
| 49   // This |url| represents the media stream we are rendering. | 51   // This |url| represents the media stream we are rendering. |url| is used to | 
|  | 52   // find out what web stream this WebMediaPlayerMSCompositor is playing, and | 
|  | 53   // together with flag "--disable-rtc-smoothness-algorithm" determine whether | 
|  | 54   // we enable algorithm or not. | 
| 50   WebMediaPlayerMSCompositor( | 55   WebMediaPlayerMSCompositor( | 
| 51       const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, | 56       const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, | 
| 52       const blink::WebURL& url, | 57       const blink::WebURL& url, | 
| 53       const base::WeakPtr<WebMediaPlayerMS>& player); | 58       const base::WeakPtr<WebMediaPlayerMS>& player); | 
|  | 59 | 
| 54   ~WebMediaPlayerMSCompositor() override; | 60   ~WebMediaPlayerMSCompositor() override; | 
| 55 | 61 | 
| 56   void EnqueueFrame(const scoped_refptr<media::VideoFrame>& frame); | 62   void EnqueueFrame(const scoped_refptr<media::VideoFrame>& frame); | 
| 57 | 63 | 
| 58   // Statistical data | 64   // Statistical data | 
| 59   gfx::Size GetCurrentSize(); | 65   gfx::Size GetCurrentSize(); | 
| 60   base::TimeDelta GetCurrentTime(); | 66   base::TimeDelta GetCurrentTime(); | 
| 61   size_t total_frame_count() const; | 67   size_t total_frame_count() const; | 
| 62   size_t dropped_frame_count() const; | 68   size_t dropped_frame_count() const; | 
| 63 | 69 | 
| 64   // VideoFrameProvider implementation. | 70   // VideoFrameProvider implementation. | 
| 65   void SetVideoFrameProviderClient( | 71   void SetVideoFrameProviderClient( | 
| 66       cc::VideoFrameProvider::Client* client) override; | 72       cc::VideoFrameProvider::Client* client) override; | 
| 67   bool UpdateCurrentFrame(base::TimeTicks deadline_min, | 73   bool UpdateCurrentFrame(base::TimeTicks deadline_min, | 
| 68                           base::TimeTicks deadline_max) override; | 74                           base::TimeTicks deadline_max) override; | 
| 69   bool HasCurrentFrame() override; | 75   bool HasCurrentFrame() override; | 
| 70   scoped_refptr<media::VideoFrame> GetCurrentFrame() override; | 76   scoped_refptr<media::VideoFrame> GetCurrentFrame() override; | 
| 71   void PutCurrentFrame() override; | 77   void PutCurrentFrame() override; | 
| 72 | 78 | 
| 73   void StartRendering(); | 79   void StartRendering(); | 
| 74   void StopRendering(); | 80   void StopRendering(); | 
| 75   void ReplaceCurrentFrameWithACopy(); | 81   void ReplaceCurrentFrameWithACopy(); | 
| 76 | 82 | 
| 77  private: | 83  private: | 
|  | 84   friend class WebMediaPlayerMSTest; | 
|  | 85 | 
| 78   bool MapTimestampsToRenderTimeTicks( | 86   bool MapTimestampsToRenderTimeTicks( | 
| 79       const std::vector<base::TimeDelta>& timestamps, | 87       const std::vector<base::TimeDelta>& timestamps, | 
| 80       std::vector<base::TimeTicks>* wall_clock_times); | 88       std::vector<base::TimeTicks>* wall_clock_times); | 
| 81 | 89 | 
| 82   void SetCurrentFrame(const scoped_refptr<media::VideoFrame>& frame); | 90   void SetCurrentFrame(const scoped_refptr<media::VideoFrame>& frame); | 
| 83 | 91 | 
| 84   // For algorithm enabled case only: given the render interval, update | 92   // For algorithm enabled case only: given the render interval, update | 
| 85   // current_frame_ and dropped_frame_count_. | 93   // current_frame_ and dropped_frame_count_. | 
| 86   void Render(base::TimeTicks deadline_min, base::TimeTicks deadline_max); | 94   void Render(base::TimeTicks deadline_min, base::TimeTicks deadline_max); | 
| 87 | 95 | 
| 88   void StartRenderingInternal(); | 96   void StartRenderingInternal(); | 
| 89   void StopRenderingInternal(); | 97   void StopRenderingInternal(); | 
| 90 | 98 | 
|  | 99   void SetAlgorithmEnabledForTesting(bool algorithm_enabled); | 
|  | 100 | 
| 91   // Used for DCHECKs to ensure method calls executed in the correct thread. | 101   // Used for DCHECKs to ensure method calls executed in the correct thread. | 
| 92   base::ThreadChecker thread_checker_; | 102   base::ThreadChecker thread_checker_; | 
| 93 | 103 | 
| 94   scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | 104   scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | 
| 95   base::MessageLoop* main_message_loop_; | 105   base::MessageLoop* main_message_loop_; | 
| 96 | 106 | 
| 97   base::WeakPtr<WebMediaPlayerMS> player_; | 107   base::WeakPtr<WebMediaPlayerMS> player_; | 
| 98 | 108 | 
| 99   size_t serial_; | 109   size_t serial_; | 
| 100 | 110 | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 133 | 143 | 
| 134   std::map<base::TimeDelta, base::TimeTicks> timestamps_to_clock_times_; | 144   std::map<base::TimeDelta, base::TimeTicks> timestamps_to_clock_times_; | 
| 135 | 145 | 
| 136   // |current_frame_lock_| protects |current_frame_used_by_compositor_|, | 146   // |current_frame_lock_| protects |current_frame_used_by_compositor_|, | 
| 137   // |current_frame_|, and |rendering_frame_buffer_|. | 147   // |current_frame_|, and |rendering_frame_buffer_|. | 
| 138   base::Lock current_frame_lock_; | 148   base::Lock current_frame_lock_; | 
| 139 }; | 149 }; | 
| 140 } | 150 } | 
| 141 | 151 | 
| 142 #endif  // CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_COMPOSITOR_H | 152 #endif  // CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_COMPOSITOR_H | 
| OLD | NEW | 
|---|