OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "media/blink/video_frame_compositor.h" | 5 #include "media/blink/video_frame_compositor.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/time/default_tick_clock.h" | 9 #include "base/time/default_tick_clock.h" |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
11 #include "base/trace_event/video_playback_pae.h" | |
11 #include "media/base/video_frame.h" | 12 #include "media/base/video_frame.h" |
12 | 13 |
13 namespace media { | 14 namespace media { |
14 | 15 |
15 // Amount of time to wait between UpdateCurrentFrame() callbacks before starting | 16 // Amount of time to wait between UpdateCurrentFrame() callbacks before starting |
16 // background rendering to keep the Render() callbacks moving. | 17 // background rendering to keep the Render() callbacks moving. |
17 const int kBackgroundRenderingTimeoutMs = 250; | 18 const int kBackgroundRenderingTimeoutMs = 250; |
18 | 19 |
19 VideoFrameCompositor::VideoFrameCompositor( | 20 VideoFrameCompositor::VideoFrameCompositor( |
20 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner) | 21 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner) |
21 : compositor_task_runner_(compositor_task_runner), | 22 : compositor_task_runner_(compositor_task_runner), |
22 tick_clock_(new base::DefaultTickClock()), | 23 tick_clock_(new base::DefaultTickClock()), |
23 background_rendering_enabled_(true), | 24 background_rendering_enabled_(true), |
24 background_rendering_timer_( | 25 background_rendering_timer_( |
25 FROM_HERE, | 26 FROM_HERE, |
26 base::TimeDelta::FromMilliseconds(kBackgroundRenderingTimeoutMs), | 27 base::TimeDelta::FromMilliseconds(kBackgroundRenderingTimeoutMs), |
27 base::Bind(&VideoFrameCompositor::BackgroundRender, | 28 base::Bind(&VideoFrameCompositor::BackgroundRender, |
28 base::Unretained(this)), | 29 base::Unretained(this)), |
29 // Task is not repeating, CallRender() will reset the task as needed. | 30 // Task is not repeating, CallRender() will reset the task as needed. |
30 false), | 31 false), |
31 client_(nullptr), | 32 client_(nullptr), |
32 rendering_(false), | 33 rendering_(false), |
33 rendered_last_frame_(false), | 34 rendered_last_frame_(false), |
34 is_background_rendering_(false), | 35 is_background_rendering_(false), |
35 new_background_frame_(false), | 36 new_background_frame_(false), |
36 // Assume 60Hz before the first UpdateCurrentFrame() call. | 37 // Assume 60Hz before the first UpdateCurrentFrame() call. |
37 last_interval_(base::TimeDelta::FromSecondsD(1.0 / 60)), | 38 last_interval_(base::TimeDelta::FromSecondsD(1.0 / 60)), |
38 callback_(nullptr) { | 39 callback_(nullptr), |
40 persistent_async_( | |
41 new base::trace_event::VideoPlaybackPersistentAsyncEvent()) { | |
39 background_rendering_timer_.SetTaskRunner(compositor_task_runner_); | 42 background_rendering_timer_.SetTaskRunner(compositor_task_runner_); |
40 } | 43 } |
41 | 44 |
42 VideoFrameCompositor::~VideoFrameCompositor() { | 45 VideoFrameCompositor::~VideoFrameCompositor() { |
43 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); | 46 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); |
44 DCHECK(!callback_); | 47 DCHECK(!callback_); |
45 DCHECK(!rendering_); | 48 DCHECK(!rendering_); |
46 if (client_) | 49 if (client_) |
47 client_->StopUsingProvider(); | 50 client_->StopUsingProvider(); |
48 } | 51 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); | 101 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); |
99 return CallRender(deadline_min, deadline_max, false); | 102 return CallRender(deadline_min, deadline_max, false); |
100 } | 103 } |
101 | 104 |
102 bool VideoFrameCompositor::HasCurrentFrame() { | 105 bool VideoFrameCompositor::HasCurrentFrame() { |
103 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); | 106 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); |
104 return static_cast<bool>(current_frame_); | 107 return static_cast<bool>(current_frame_); |
105 } | 108 } |
106 | 109 |
107 void VideoFrameCompositor::Start(RenderCallback* callback) { | 110 void VideoFrameCompositor::Start(RenderCallback* callback) { |
108 TRACE_EVENT_ASYNC_BEGIN0("media,rail", "VideoPlayback", | 111 persistent_async_->Start(); |
DaleCurtis
2016/08/30 19:09:49
Do we really need a Start()/Stop() API or should t
alexandermont
2016/08/30 19:34:36
I don't really see an advantage of doing it the wa
DaleCurtis
2016/08/30 19:42:31
Generally I find it preferable to avoid unnecessar
alexandermont
2016/08/31 18:31:59
See discussion below in comments. Given that futur
| |
109 static_cast<const void*>(this)); | |
110 | 112 |
111 // Called from the media thread, so acquire the callback under lock before | 113 // Called from the media thread, so acquire the callback under lock before |
112 // returning in case a Stop() call comes in before the PostTask is processed. | 114 // returning in case a Stop() call comes in before the PostTask is processed. |
113 base::AutoLock lock(callback_lock_); | 115 base::AutoLock lock(callback_lock_); |
114 DCHECK(!callback_); | 116 DCHECK(!callback_); |
115 callback_ = callback; | 117 callback_ = callback; |
116 compositor_task_runner_->PostTask( | 118 compositor_task_runner_->PostTask( |
117 FROM_HERE, base::Bind(&VideoFrameCompositor::OnRendererStateUpdate, | 119 FROM_HERE, base::Bind(&VideoFrameCompositor::OnRendererStateUpdate, |
118 base::Unretained(this), true)); | 120 base::Unretained(this), true)); |
119 } | 121 } |
120 | 122 |
121 void VideoFrameCompositor::Stop() { | 123 void VideoFrameCompositor::Stop() { |
122 TRACE_EVENT_ASYNC_END0("media,rail", "VideoPlayback", | 124 persistent_async_->Stop(); |
123 static_cast<const void*>(this)); | |
124 | 125 |
125 // Called from the media thread, so release the callback under lock before | 126 // Called from the media thread, so release the callback under lock before |
126 // returning to avoid a pending UpdateCurrentFrame() call occurring before | 127 // returning to avoid a pending UpdateCurrentFrame() call occurring before |
127 // the PostTask is processed. | 128 // the PostTask is processed. |
128 base::AutoLock lock(callback_lock_); | 129 base::AutoLock lock(callback_lock_); |
129 DCHECK(callback_); | 130 DCHECK(callback_); |
130 callback_ = nullptr; | 131 callback_ = nullptr; |
131 compositor_task_runner_->PostTask( | 132 compositor_task_runner_->PostTask( |
132 FROM_HERE, base::Bind(&VideoFrameCompositor::OnRendererStateUpdate, | 133 FROM_HERE, base::Bind(&VideoFrameCompositor::OnRendererStateUpdate, |
133 base::Unretained(this), false)); | 134 base::Unretained(this), false)); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 last_interval_ = deadline_max - deadline_min; | 242 last_interval_ = deadline_max - deadline_min; |
242 | 243 |
243 // Restart the background rendering timer whether we're background rendering | 244 // Restart the background rendering timer whether we're background rendering |
244 // or not; in either case we should wait for |kBackgroundRenderingTimeoutMs|. | 245 // or not; in either case we should wait for |kBackgroundRenderingTimeoutMs|. |
245 if (background_rendering_enabled_) | 246 if (background_rendering_enabled_) |
246 background_rendering_timer_.Reset(); | 247 background_rendering_timer_.Reset(); |
247 return new_frame || had_new_background_frame; | 248 return new_frame || had_new_background_frame; |
248 } | 249 } |
249 | 250 |
250 } // namespace media | 251 } // namespace media |
OLD | NEW |