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

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 multithreading 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
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) {
Primiano Tucci (use gerrit) 2016/10/13 20:11:00 no need to initialze this. unique_ptr is not a POD
alexandermont 2016/10/14 17:55:00 Done
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());
44 DCHECK(!callback_); 46 DCHECK(!callback_);
45 DCHECK(!rendering_); 47 DCHECK(!rendering_);
46 if (client_) 48 if (client_)
47 client_->StopUsingProvider(); 49 client_->StopUsingProvider();
48 } 50 }
49 51
50 void VideoFrameCompositor::OnRendererStateUpdate(bool new_state) { 52 void VideoFrameCompositor::OnRendererStateUpdate(bool new_state) {
51 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); 53 DCHECK(compositor_task_runner_->BelongsToCurrentThread());
52 DCHECK_NE(rendering_, new_state); 54 DCHECK_NE(rendering_, new_state);
53 rendering_ = new_state; 55 rendering_ = new_state;
54 56
57 if (!auto_open_close_) {
58 auto_open_close_.reset(new base::trace_event::AutoOpenCloseEvent(
59 base::trace_event::AutoOpenCloseEvent::Type::ASYNC, "media,rail",
60 "VideoPlayback"));
61 }
62
63 if (rendering_) {
64 auto_open_close_->Begin();
65 } else {
66 auto_open_close_->End();
67 }
68
55 if (rendering_) { 69 if (rendering_) {
56 // Always start playback in background rendering mode, if |client_| kicks 70 // Always start playback in background rendering mode, if |client_| kicks
57 // in right away it's okay. 71 // in right away it's okay.
58 BackgroundRender(); 72 BackgroundRender();
59 } else if (background_rendering_enabled_) { 73 } else if (background_rendering_enabled_) {
60 background_rendering_timer_.Stop(); 74 background_rendering_timer_.Stop();
61 } else { 75 } else {
62 DCHECK(!background_rendering_timer_.IsRunning()); 76 DCHECK(!background_rendering_timer_.IsRunning());
63 } 77 }
64 78
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); 112 DCHECK(compositor_task_runner_->BelongsToCurrentThread());
99 return CallRender(deadline_min, deadline_max, false); 113 return CallRender(deadline_min, deadline_max, false);
100 } 114 }
101 115
102 bool VideoFrameCompositor::HasCurrentFrame() { 116 bool VideoFrameCompositor::HasCurrentFrame() {
103 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); 117 DCHECK(compositor_task_runner_->BelongsToCurrentThread());
104 return static_cast<bool>(current_frame_); 118 return static_cast<bool>(current_frame_);
105 } 119 }
106 120
107 void VideoFrameCompositor::Start(RenderCallback* callback) { 121 void VideoFrameCompositor::Start(RenderCallback* callback) {
108 TRACE_EVENT_ASYNC_BEGIN0("media,rail", "VideoPlayback",
109 static_cast<const void*>(this));
110
111 // Called from the media thread, so acquire the callback under lock before 122 // 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. 123 // returning in case a Stop() call comes in before the PostTask is processed.
113 base::AutoLock lock(callback_lock_); 124 base::AutoLock lock(callback_lock_);
114 DCHECK(!callback_); 125 DCHECK(!callback_);
115 callback_ = callback; 126 callback_ = callback;
116 compositor_task_runner_->PostTask( 127 compositor_task_runner_->PostTask(
117 FROM_HERE, base::Bind(&VideoFrameCompositor::OnRendererStateUpdate, 128 FROM_HERE, base::Bind(&VideoFrameCompositor::OnRendererStateUpdate,
118 base::Unretained(this), true)); 129 base::Unretained(this), true));
119 } 130 }
120 131
121 void VideoFrameCompositor::Stop() { 132 void VideoFrameCompositor::Stop() {
122 TRACE_EVENT_ASYNC_END0("media,rail", "VideoPlayback",
123 static_cast<const void*>(this));
124
125 // Called from the media thread, so release the callback under lock before 133 // Called from the media thread, so release the callback under lock before
126 // returning to avoid a pending UpdateCurrentFrame() call occurring before 134 // returning to avoid a pending UpdateCurrentFrame() call occurring before
127 // the PostTask is processed. 135 // the PostTask is processed.
128 base::AutoLock lock(callback_lock_); 136 base::AutoLock lock(callback_lock_);
129 DCHECK(callback_); 137 DCHECK(callback_);
130 callback_ = nullptr; 138 callback_ = nullptr;
131 compositor_task_runner_->PostTask( 139 compositor_task_runner_->PostTask(
132 FROM_HERE, base::Bind(&VideoFrameCompositor::OnRendererStateUpdate, 140 FROM_HERE, base::Bind(&VideoFrameCompositor::OnRendererStateUpdate,
133 base::Unretained(this), false)); 141 base::Unretained(this), false));
134 } 142 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 last_interval_ = deadline_max - deadline_min; 249 last_interval_ = deadline_max - deadline_min;
242 250
243 // Restart the background rendering timer whether we're background rendering 251 // Restart the background rendering timer whether we're background rendering
244 // or not; in either case we should wait for |kBackgroundRenderingTimeoutMs|. 252 // or not; in either case we should wait for |kBackgroundRenderingTimeoutMs|.
245 if (background_rendering_enabled_) 253 if (background_rendering_enabled_)
246 background_rendering_timer_.Reset(); 254 background_rendering_timer_.Reset();
247 return new_frame || had_new_background_frame; 255 return new_frame || had_new_background_frame;
248 } 256 }
249 257
250 } // namespace media 258 } // 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