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

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