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

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: create the AutoOpenCloseEvent when you use it Created 4 years, 2 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
« no previous file with comments | « media/blink/video_frame_compositor.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/auto_open_close_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 auto_open_close_(nullptr) {
39 background_rendering_timer_.SetTaskRunner(compositor_task_runner_); 41 background_rendering_timer_.SetTaskRunner(compositor_task_runner_);
40 } 42 }
41 43
42 VideoFrameCompositor::~VideoFrameCompositor() { 44 VideoFrameCompositor::~VideoFrameCompositor() {
43 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); 45 DCHECK(compositor_task_runner_->BelongsToCurrentThread());
benjhayden 2016/10/11 21:42:19 You're deleting auto_open_close_ on the compositor
44 DCHECK(!callback_); 46 DCHECK(!callback_);
45 DCHECK(!rendering_); 47 DCHECK(!rendering_);
48 if (auto_open_close_)
49 delete auto_open_close_;
46 if (client_) 50 if (client_)
47 client_->StopUsingProvider(); 51 client_->StopUsingProvider();
48 } 52 }
49 53
50 void VideoFrameCompositor::OnRendererStateUpdate(bool new_state) { 54 void VideoFrameCompositor::OnRendererStateUpdate(bool new_state) {
51 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); 55 DCHECK(compositor_task_runner_->BelongsToCurrentThread());
52 DCHECK_NE(rendering_, new_state); 56 DCHECK_NE(rendering_, new_state);
53 rendering_ = new_state; 57 rendering_ = new_state;
54 58
55 if (rendering_) { 59 if (rendering_) {
(...skipping 42 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 if (auto_open_close_ == nullptr) {
benjhayden 2016/10/11 21:42:19 It looks like you're creating this and calling Beg
109 static_cast<const void*>(this)); 113 auto_open_close_ = new base::trace_event::AutoOpenCloseEvent(
114 base::trace_event::AutoOpenCloseEvent::Type::ASYNC, "media,rail",
115 "VideoPlayback");
116 }
117 auto_open_close_->Begin();
110 118
111 // Called from the media thread, so acquire the callback under lock before 119 // 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. 120 // returning in case a Stop() call comes in before the PostTask is processed.
113 base::AutoLock lock(callback_lock_); 121 base::AutoLock lock(callback_lock_);
114 DCHECK(!callback_); 122 DCHECK(!callback_);
115 callback_ = callback; 123 callback_ = callback;
116 compositor_task_runner_->PostTask( 124 compositor_task_runner_->PostTask(
117 FROM_HERE, base::Bind(&VideoFrameCompositor::OnRendererStateUpdate, 125 FROM_HERE, base::Bind(&VideoFrameCompositor::OnRendererStateUpdate,
118 base::Unretained(this), true)); 126 base::Unretained(this), true));
119 } 127 }
120 128
121 void VideoFrameCompositor::Stop() { 129 void VideoFrameCompositor::Stop() {
122 TRACE_EVENT_ASYNC_END0("media,rail", "VideoPlayback", 130 auto_open_close_->End();
123 static_cast<const void*>(this));
124 131
125 // Called from the media thread, so release the callback under lock before 132 // Called from the media thread, so release the callback under lock before
126 // returning to avoid a pending UpdateCurrentFrame() call occurring before 133 // returning to avoid a pending UpdateCurrentFrame() call occurring before
127 // the PostTask is processed. 134 // the PostTask is processed.
128 base::AutoLock lock(callback_lock_); 135 base::AutoLock lock(callback_lock_);
129 DCHECK(callback_); 136 DCHECK(callback_);
130 callback_ = nullptr; 137 callback_ = nullptr;
131 compositor_task_runner_->PostTask( 138 compositor_task_runner_->PostTask(
132 FROM_HERE, base::Bind(&VideoFrameCompositor::OnRendererStateUpdate, 139 FROM_HERE, base::Bind(&VideoFrameCompositor::OnRendererStateUpdate,
133 base::Unretained(this), false)); 140 base::Unretained(this), false));
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 last_interval_ = deadline_max - deadline_min; 248 last_interval_ = deadline_max - deadline_min;
242 249
243 // Restart the background rendering timer whether we're background rendering 250 // Restart the background rendering timer whether we're background rendering
244 // or not; in either case we should wait for |kBackgroundRenderingTimeoutMs|. 251 // or not; in either case we should wait for |kBackgroundRenderingTimeoutMs|.
245 if (background_rendering_enabled_) 252 if (background_rendering_enabled_)
246 background_rendering_timer_.Reset(); 253 background_rendering_timer_.Reset();
247 return new_frame || had_new_background_frame; 254 return new_frame || had_new_background_frame;
248 } 255 }
249 256
250 } // namespace media 257 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/video_frame_compositor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698