| 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" | |
| 18 | 17 |
| 19 namespace base { | 18 namespace base { |
| 20 class SingleThreadTaskRunner; | 19 class SingleThreadTaskRunner; |
| 21 } | 20 } |
| 22 | 21 |
| 23 namespace blink { | 22 namespace blink { |
| 24 class WebURL; | 23 class WebURL; |
| 25 } | 24 } |
| 26 | 25 |
| 27 namespace gfx { | 26 namespace gfx { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 38 | 37 |
| 39 // This class is designed to handle the work load on compositor thread for | 38 // This class is designed to handle the work load on compositor thread for |
| 40 // WebMediaPlayerMS. It will be instantiated on the main thread, but destroyed | 39 // WebMediaPlayerMS. It will be instantiated on the main thread, but destroyed |
| 41 // on the compositor thread. | 40 // on the compositor thread. |
| 42 // | 41 // |
| 43 // WebMediaPlayerMSCompositor utilizes VideoRendererAlgorithm to store the | 42 // WebMediaPlayerMSCompositor utilizes VideoRendererAlgorithm to store the |
| 44 // incoming frames and select the best frame for rendering to maximize the | 43 // incoming frames and select the best frame for rendering to maximize the |
| 45 // smoothness, if REFERENCE_TIMEs are populated for incoming VideoFrames. | 44 // smoothness, if REFERENCE_TIMEs are populated for incoming VideoFrames. |
| 46 // Otherwise, WebMediaPlayerMSCompositor will simply store the most recent | 45 // Otherwise, WebMediaPlayerMSCompositor will simply store the most recent |
| 47 // frame, and submit it whenever asked by the compositor. | 46 // frame, and submit it whenever asked by the compositor. |
| 48 class CONTENT_EXPORT WebMediaPlayerMSCompositor | 47 class WebMediaPlayerMSCompositor : public cc::VideoFrameProvider { |
| 49 : public NON_EXPORTED_BASE(cc::VideoFrameProvider) { | |
| 50 public: | 48 public: |
| 51 // This |url| represents the media stream we are rendering. |url| is used to | 49 // This |url| represents the media stream we are rendering. |
| 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. | |
| 55 WebMediaPlayerMSCompositor( | 50 WebMediaPlayerMSCompositor( |
| 56 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, | 51 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, |
| 57 const blink::WebURL& url, | 52 const blink::WebURL& url, |
| 58 const base::WeakPtr<WebMediaPlayerMS>& player); | 53 const base::WeakPtr<WebMediaPlayerMS>& player); |
| 59 | |
| 60 ~WebMediaPlayerMSCompositor() override; | 54 ~WebMediaPlayerMSCompositor() override; |
| 61 | 55 |
| 62 void EnqueueFrame(const scoped_refptr<media::VideoFrame>& frame); | 56 void EnqueueFrame(const scoped_refptr<media::VideoFrame>& frame); |
| 63 | 57 |
| 64 // Statistical data | 58 // Statistical data |
| 65 gfx::Size GetCurrentSize(); | 59 gfx::Size GetCurrentSize(); |
| 66 base::TimeDelta GetCurrentTime(); | 60 base::TimeDelta GetCurrentTime(); |
| 67 size_t total_frame_count() const; | 61 size_t total_frame_count() const; |
| 68 size_t dropped_frame_count() const; | 62 size_t dropped_frame_count() const; |
| 69 | 63 |
| 70 // VideoFrameProvider implementation. | 64 // VideoFrameProvider implementation. |
| 71 void SetVideoFrameProviderClient( | 65 void SetVideoFrameProviderClient( |
| 72 cc::VideoFrameProvider::Client* client) override; | 66 cc::VideoFrameProvider::Client* client) override; |
| 73 bool UpdateCurrentFrame(base::TimeTicks deadline_min, | 67 bool UpdateCurrentFrame(base::TimeTicks deadline_min, |
| 74 base::TimeTicks deadline_max) override; | 68 base::TimeTicks deadline_max) override; |
| 75 bool HasCurrentFrame() override; | 69 bool HasCurrentFrame() override; |
| 76 scoped_refptr<media::VideoFrame> GetCurrentFrame() override; | 70 scoped_refptr<media::VideoFrame> GetCurrentFrame() override; |
| 77 void PutCurrentFrame() override; | 71 void PutCurrentFrame() override; |
| 78 | 72 |
| 79 void StartRendering(); | 73 void StartRendering(); |
| 80 void StopRendering(); | 74 void StopRendering(); |
| 81 void ReplaceCurrentFrameWithACopy(); | 75 void ReplaceCurrentFrameWithACopy(); |
| 82 | 76 |
| 83 private: | 77 private: |
| 84 friend class WebMediaPlayerMSTest; | |
| 85 | |
| 86 bool MapTimestampsToRenderTimeTicks( | 78 bool MapTimestampsToRenderTimeTicks( |
| 87 const std::vector<base::TimeDelta>& timestamps, | 79 const std::vector<base::TimeDelta>& timestamps, |
| 88 std::vector<base::TimeTicks>* wall_clock_times); | 80 std::vector<base::TimeTicks>* wall_clock_times); |
| 89 | 81 |
| 90 void SetCurrentFrame(const scoped_refptr<media::VideoFrame>& frame); | 82 void SetCurrentFrame(const scoped_refptr<media::VideoFrame>& frame); |
| 91 | 83 |
| 92 // For algorithm enabled case only: given the render interval, update | 84 // For algorithm enabled case only: given the render interval, update |
| 93 // current_frame_ and dropped_frame_count_. | 85 // current_frame_ and dropped_frame_count_. |
| 94 void Render(base::TimeTicks deadline_min, base::TimeTicks deadline_max); | 86 void Render(base::TimeTicks deadline_min, base::TimeTicks deadline_max); |
| 95 | 87 |
| 96 void StartRenderingInternal(); | 88 void StartRenderingInternal(); |
| 97 void StopRenderingInternal(); | 89 void StopRenderingInternal(); |
| 98 | 90 |
| 99 void SetAlgorithmEnabledForTesting(bool algorithm_enabled); | |
| 100 | |
| 101 // Used for DCHECKs to ensure method calls executed in the correct thread. | 91 // Used for DCHECKs to ensure method calls executed in the correct thread. |
| 102 base::ThreadChecker thread_checker_; | 92 base::ThreadChecker thread_checker_; |
| 103 | 93 |
| 104 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | 94 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
| 105 base::MessageLoop* main_message_loop_; | 95 base::MessageLoop* main_message_loop_; |
| 106 | 96 |
| 107 base::WeakPtr<WebMediaPlayerMS> player_; | 97 base::WeakPtr<WebMediaPlayerMS> player_; |
| 108 | 98 |
| 109 size_t serial_; | 99 size_t serial_; |
| 110 | 100 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 133 |
| 144 std::map<base::TimeDelta, base::TimeTicks> timestamps_to_clock_times_; | 134 std::map<base::TimeDelta, base::TimeTicks> timestamps_to_clock_times_; |
| 145 | 135 |
| 146 // |current_frame_lock_| protects |current_frame_used_by_compositor_|, | 136 // |current_frame_lock_| protects |current_frame_used_by_compositor_|, |
| 147 // |current_frame_|, and |rendering_frame_buffer_|. | 137 // |current_frame_|, and |rendering_frame_buffer_|. |
| 148 base::Lock current_frame_lock_; | 138 base::Lock current_frame_lock_; |
| 149 }; | 139 }; |
| 150 } | 140 } |
| 151 | 141 |
| 152 #endif // CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_COMPOSITOR_H | 142 #endif // CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_COMPOSITOR_H |
| OLD | NEW |