Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Side by Side Diff: content/renderer/media/webmediaplayer_ms_compositor.h

Issue 2529263004: Move passing of WebRTC rendering frames to IO thread (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 8 #include <stddef.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 21 matching lines...) Expand all
32 32
33 namespace media { 33 namespace media {
34 class VideoRendererAlgorithm; 34 class VideoRendererAlgorithm;
35 } 35 }
36 36
37 namespace content { 37 namespace content {
38 class WebMediaPlayerMS; 38 class WebMediaPlayerMS;
39 39
40 // This class is designed to handle the work load on compositor thread for 40 // This class is designed to handle the work load on compositor thread for
41 // WebMediaPlayerMS. It will be instantiated on the main thread, but destroyed 41 // WebMediaPlayerMS. It will be instantiated on the main thread, but destroyed
42 // on the compositor thread. 42 // on the thread holding the last reference.
43 // 43 //
44 // WebMediaPlayerMSCompositor utilizes VideoRendererAlgorithm to store the 44 // WebMediaPlayerMSCompositor utilizes VideoRendererAlgorithm to store the
45 // incoming frames and select the best frame for rendering to maximize the 45 // incoming frames and select the best frame for rendering to maximize the
46 // smoothness, if REFERENCE_TIMEs are populated for incoming VideoFrames. 46 // smoothness, if REFERENCE_TIMEs are populated for incoming VideoFrames.
47 // Otherwise, WebMediaPlayerMSCompositor will simply store the most recent 47 // Otherwise, WebMediaPlayerMSCompositor will simply store the most recent
48 // frame, and submit it whenever asked by the compositor. 48 // frame, and submit it whenever asked by the compositor.
49 class CONTENT_EXPORT WebMediaPlayerMSCompositor 49 class CONTENT_EXPORT WebMediaPlayerMSCompositor
50 : public NON_EXPORTED_BASE(cc::VideoFrameProvider) { 50 : public NON_EXPORTED_BASE(cc::VideoFrameProvider),
51 public base::RefCountedThreadSafe<WebMediaPlayerMSCompositor> {
51 public: 52 public:
52 // This |url| represents the media stream we are rendering. |url| is used to 53 // This |url| represents the media stream we are rendering. |url| is used to
53 // find out what web stream this WebMediaPlayerMSCompositor is playing, and 54 // find out what web stream this WebMediaPlayerMSCompositor is playing, and
54 // together with flag "--disable-rtc-smoothness-algorithm" determine whether 55 // together with flag "--disable-rtc-smoothness-algorithm" determine whether
55 // we enable algorithm or not. 56 // we enable algorithm or not.
56 WebMediaPlayerMSCompositor( 57 WebMediaPlayerMSCompositor(
57 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, 58 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner,
58 const blink::WebMediaStream& web_stream, 59 const blink::WebMediaStream& web_stream,
59 const base::WeakPtr<WebMediaPlayerMS>& player); 60 const base::WeakPtr<WebMediaPlayerMS>& player);
60 61
61 ~WebMediaPlayerMSCompositor() override;
62
63 void EnqueueFrame(scoped_refptr<media::VideoFrame> frame); 62 void EnqueueFrame(scoped_refptr<media::VideoFrame> frame);
64 63
65 // Statistical data 64 // Statistical data
66 gfx::Size GetCurrentSize(); 65 gfx::Size GetCurrentSize();
67 base::TimeDelta GetCurrentTime(); 66 base::TimeDelta GetCurrentTime();
68 size_t total_frame_count() const; 67 size_t total_frame_count() const;
69 size_t dropped_frame_count() const; 68 size_t dropped_frame_count() const;
70 69
71 // VideoFrameProvider implementation. 70 // VideoFrameProvider implementation.
72 void SetVideoFrameProviderClient( 71 void SetVideoFrameProviderClient(
73 cc::VideoFrameProvider::Client* client) override; 72 cc::VideoFrameProvider::Client* client) override;
74 bool UpdateCurrentFrame(base::TimeTicks deadline_min, 73 bool UpdateCurrentFrame(base::TimeTicks deadline_min,
75 base::TimeTicks deadline_max) override; 74 base::TimeTicks deadline_max) override;
76 bool HasCurrentFrame() override; 75 bool HasCurrentFrame() override;
77 scoped_refptr<media::VideoFrame> GetCurrentFrame() override; 76 scoped_refptr<media::VideoFrame> GetCurrentFrame() override;
78 void PutCurrentFrame() override; 77 void PutCurrentFrame() override;
79 78
80 // Return the current frame being rendered. 79 // Return the current frame being rendered.
81 // Difference between GetCurrentFrame(): GetCurrentFrame() is designed for 80 // Difference between GetCurrentFrame(): GetCurrentFrame() is designed for
82 // chrome compositor to pull frame from WebMediaPlayerMSCompositor, and thus 81 // chrome compositor to pull frame from WebMediaPlayerMSCompositor, and thus
83 // calling GetCurrentFrame() will affect statistics like |dropped_frames_| 82 // calling GetCurrentFrame() will affect statistics like |dropped_frames_|
84 // etc. Calling this function has no side effect. 83 // etc. Calling this function has no side effect.
85 scoped_refptr<media::VideoFrame> GetCurrentFrameWithoutUpdatingStatistics(); 84 scoped_refptr<media::VideoFrame> GetCurrentFrameWithoutUpdatingStatistics();
86 85
87 void StartRendering(); 86 void StartRendering();
88 void StopRendering(); 87 void StopRendering();
89 void ReplaceCurrentFrameWithACopy(); 88 void ReplaceCurrentFrameWithACopy();
90 89
90 // Tell |video_frame_provider_client_| to stop using this instance in
91 // preparation for dtor.
92 void StopUsingProvider();
93
91 private: 94 private:
95 friend class base::RefCountedThreadSafe<WebMediaPlayerMSCompositor>;
92 friend class WebMediaPlayerMSTest; 96 friend class WebMediaPlayerMSTest;
93 97
98 ~WebMediaPlayerMSCompositor() override;
99
94 bool MapTimestampsToRenderTimeTicks( 100 bool MapTimestampsToRenderTimeTicks(
95 const std::vector<base::TimeDelta>& timestamps, 101 const std::vector<base::TimeDelta>& timestamps,
96 std::vector<base::TimeTicks>* wall_clock_times); 102 std::vector<base::TimeTicks>* wall_clock_times);
97 103
98 void SetCurrentFrame(const scoped_refptr<media::VideoFrame>& frame);
99
100 // For algorithm enabled case only: given the render interval, update 104 // For algorithm enabled case only: given the render interval, update
101 // current_frame_ and dropped_frame_count_. 105 // current_frame_ and dropped_frame_count_.
102 void Render(base::TimeTicks deadline_min, base::TimeTicks deadline_max); 106 void Render(base::TimeTicks deadline_min, base::TimeTicks deadline_max);
103 107
108 void SetCurrentFrame(const scoped_refptr<media::VideoFrame>& frame);
qiangchen 2016/12/05 18:54:57 Can you order this before Render function to kill
emircan 2016/12/06 00:36:43 I wanted to sync the order of declaration/definiti
109
104 void StartRenderingInternal(); 110 void StartRenderingInternal();
105 void StopRenderingInternal(); 111 void StopRenderingInternal();
112 void StopUsingProviderInternal();
106 113
107 void SetAlgorithmEnabledForTesting(bool algorithm_enabled); 114 void SetAlgorithmEnabledForTesting(bool algorithm_enabled);
108 115
109 // Used for DCHECKs to ensure method calls executed in the correct thread. 116 // Used for DCHECKs to ensure method calls executed in the correct thread.
110 base::ThreadChecker thread_checker_; 117 base::ThreadChecker thread_checker_;
118 base::ThreadChecker media_thread_checker_;
111 119
112 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; 120 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
113 base::MessageLoop* main_message_loop_; 121 base::MessageLoop* main_message_loop_;
114 122
115 base::WeakPtr<WebMediaPlayerMS> player_; 123 base::WeakPtr<WebMediaPlayerMS> player_;
116 124
117 size_t serial_; 125 size_t serial_;
118 126
119 // A pointer back to the compositor to inform it about state changes. This 127 // A pointer back to the compositor to inform it about state changes. This
120 // is not |nullptr| while the compositor is actively using this 128 // is not |nullptr| while the compositor is actively using this
(...skipping 20 matching lines...) Expand all
141 // Historical data about last rendering. These are for detecting whether 149 // Historical data about last rendering. These are for detecting whether
142 // rendering is paused (one reason is that the tab is not in the front), in 150 // rendering is paused (one reason is that the tab is not in the front), in
143 // which case we need to do background rendering. 151 // which case we need to do background rendering.
144 base::TimeTicks last_deadline_max_; 152 base::TimeTicks last_deadline_max_;
145 base::TimeDelta last_render_length_; 153 base::TimeDelta last_render_length_;
146 154
147 size_t total_frame_count_; 155 size_t total_frame_count_;
148 size_t dropped_frame_count_; 156 size_t dropped_frame_count_;
149 157
150 bool stopped_; 158 bool stopped_;
159 bool provider_in_use_;
qiangchen 2016/12/05 18:54:57 Can you simply set video_frame_provider_client_ to
emircan 2016/12/06 00:36:43 Done.
151 160
152 std::map<base::TimeDelta, base::TimeTicks> timestamps_to_clock_times_; 161 std::map<base::TimeDelta, base::TimeTicks> timestamps_to_clock_times_;
153 162
154 // |current_frame_lock_| protects |current_frame_used_by_compositor_|, 163 // |current_frame_lock_| protects |current_frame_used_by_compositor_|,
155 // |current_frame_|, and |rendering_frame_buffer_|. 164 // |current_frame_|, and |rendering_frame_buffer_|.
156 base::Lock current_frame_lock_; 165 base::Lock current_frame_lock_;
157 166
158 // Make sure the weak pointer factory member is the last member of the class.
159 base::WeakPtrFactory<WebMediaPlayerMSCompositor> weak_ptr_factory_;
160
161 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerMSCompositor); 167 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerMSCompositor);
162 }; 168 };
163 } // namespace content 169 } // namespace content
164 170
165 #endif // CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_COMPOSITOR_H_ 171 #endif // CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_COMPOSITOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698