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

Side by Side Diff: media/blink/video_frame_compositor.cc

Issue 2159323002: Add tracing AutoOpenCloseEvent. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: implement new design Created 4 years, 3 months 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 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/persistent_async_event.h"
10 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.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::PersistentAsyncEvent("media,rail",
42 "VideoPlayback")) {
39 background_rendering_timer_.SetTaskRunner(compositor_task_runner_); 43 background_rendering_timer_.SetTaskRunner(compositor_task_runner_);
40 } 44 }
41 45
42 VideoFrameCompositor::~VideoFrameCompositor() { 46 VideoFrameCompositor::~VideoFrameCompositor() {
43 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); 47 DCHECK(compositor_task_runner_->BelongsToCurrentThread());
44 DCHECK(!callback_); 48 DCHECK(!callback_);
45 DCHECK(!rendering_); 49 DCHECK(!rendering_);
46 if (client_) 50 if (client_)
47 client_->StopUsingProvider(); 51 client_->StopUsingProvider();
48 } 52 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); 102 DCHECK(compositor_task_runner_->BelongsToCurrentThread());
99 return CallRender(deadline_min, deadline_max, false); 103 return CallRender(deadline_min, deadline_max, false);
100 } 104 }
101 105
102 bool VideoFrameCompositor::HasCurrentFrame() { 106 bool VideoFrameCompositor::HasCurrentFrame() {
103 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); 107 DCHECK(compositor_task_runner_->BelongsToCurrentThread());
104 return static_cast<bool>(current_frame_); 108 return static_cast<bool>(current_frame_);
105 } 109 }
106 110
107 void VideoFrameCompositor::Start(RenderCallback* callback) { 111 void VideoFrameCompositor::Start(RenderCallback* callback) {
108 TRACE_EVENT_ASYNC_BEGIN0("media,rail", "VideoPlayback", 112 persistent_async_->Begin();
109 static_cast<const void*>(this));
110 113
111 // Called from the media thread, so acquire the callback under lock before 114 // 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. 115 // returning in case a Stop() call comes in before the PostTask is processed.
113 base::AutoLock lock(callback_lock_); 116 base::AutoLock lock(callback_lock_);
114 DCHECK(!callback_); 117 DCHECK(!callback_);
115 callback_ = callback; 118 callback_ = callback;
116 compositor_task_runner_->PostTask( 119 compositor_task_runner_->PostTask(
117 FROM_HERE, base::Bind(&VideoFrameCompositor::OnRendererStateUpdate, 120 FROM_HERE, base::Bind(&VideoFrameCompositor::OnRendererStateUpdate,
118 base::Unretained(this), true)); 121 base::Unretained(this), true));
119 } 122 }
120 123
121 void VideoFrameCompositor::Stop() { 124 void VideoFrameCompositor::Stop() {
122 TRACE_EVENT_ASYNC_END0("media,rail", "VideoPlayback", 125 persistent_async_->End();
123 static_cast<const void*>(this));
124 126
125 // Called from the media thread, so release the callback under lock before 127 // Called from the media thread, so release the callback under lock before
126 // returning to avoid a pending UpdateCurrentFrame() call occurring before 128 // returning to avoid a pending UpdateCurrentFrame() call occurring before
127 // the PostTask is processed. 129 // the PostTask is processed.
128 base::AutoLock lock(callback_lock_); 130 base::AutoLock lock(callback_lock_);
129 DCHECK(callback_); 131 DCHECK(callback_);
130 callback_ = nullptr; 132 callback_ = nullptr;
131 compositor_task_runner_->PostTask( 133 compositor_task_runner_->PostTask(
132 FROM_HERE, base::Bind(&VideoFrameCompositor::OnRendererStateUpdate, 134 FROM_HERE, base::Bind(&VideoFrameCompositor::OnRendererStateUpdate,
133 base::Unretained(this), false)); 135 base::Unretained(this), false));
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 last_interval_ = deadline_max - deadline_min; 243 last_interval_ = deadline_max - deadline_min;
242 244
243 // Restart the background rendering timer whether we're background rendering 245 // Restart the background rendering timer whether we're background rendering
244 // or not; in either case we should wait for |kBackgroundRenderingTimeoutMs|. 246 // or not; in either case we should wait for |kBackgroundRenderingTimeoutMs|.
245 if (background_rendering_enabled_) 247 if (background_rendering_enabled_)
246 background_rendering_timer_.Reset(); 248 background_rendering_timer_.Reset();
247 return new_frame || had_new_background_frame; 249 return new_frame || had_new_background_frame;
248 } 250 }
249 251
250 } // namespace media 252 } // namespace media
OLDNEW
« base/trace_event/trace_log.cc ('K') | « media/blink/video_frame_compositor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698