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

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

Issue 1978973002: Moves video frame callbacks from VideoFrameCompositor to Renderer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes media_bit_reader_fuzzer link error Created 4 years, 7 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 "media/base/video_frame.h" 11 #include "media/base/video_frame.h"
12 12
13 namespace media { 13 namespace media {
14 14
15 // Amount of time to wait between UpdateCurrentFrame() callbacks before starting 15 // Amount of time to wait between UpdateCurrentFrame() callbacks before starting
16 // background rendering to keep the Render() callbacks moving. 16 // background rendering to keep the Render() callbacks moving.
17 const int kBackgroundRenderingTimeoutMs = 250; 17 const int kBackgroundRenderingTimeoutMs = 250;
18 18
19 VideoFrameCompositor::VideoFrameCompositor( 19 VideoFrameCompositor::VideoFrameCompositor(
20 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, 20 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner)
21 const base::Callback<void(gfx::Size)>& natural_size_changed_cb,
22 const base::Callback<void(bool)>& opacity_changed_cb)
23 : compositor_task_runner_(compositor_task_runner), 21 : compositor_task_runner_(compositor_task_runner),
24 tick_clock_(new base::DefaultTickClock()), 22 tick_clock_(new base::DefaultTickClock()),
25 natural_size_changed_cb_(natural_size_changed_cb),
26 opacity_changed_cb_(opacity_changed_cb),
27 background_rendering_enabled_(true), 23 background_rendering_enabled_(true),
28 background_rendering_timer_( 24 background_rendering_timer_(
29 FROM_HERE, 25 FROM_HERE,
30 base::TimeDelta::FromMilliseconds(kBackgroundRenderingTimeoutMs), 26 base::TimeDelta::FromMilliseconds(kBackgroundRenderingTimeoutMs),
31 base::Bind(&VideoFrameCompositor::BackgroundRender, 27 base::Bind(&VideoFrameCompositor::BackgroundRender,
32 base::Unretained(this)), 28 base::Unretained(this)),
33 // Task is not repeating, CallRender() will reset the task as needed. 29 // Task is not repeating, CallRender() will reset the task as needed.
34 false), 30 false),
35 client_(nullptr), 31 client_(nullptr),
36 rendering_(false), 32 rendering_(false),
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 const scoped_refptr<VideoFrame>& frame) { 182 const scoped_refptr<VideoFrame>& frame) {
187 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); 183 DCHECK(compositor_task_runner_->BelongsToCurrentThread());
188 184
189 if (frame == current_frame_) 185 if (frame == current_frame_)
190 return false; 186 return false;
191 187
192 // Set the flag indicating that the current frame is unrendered, if we get a 188 // Set the flag indicating that the current frame is unrendered, if we get a
193 // subsequent PutCurrentFrame() call it will mark it as rendered. 189 // subsequent PutCurrentFrame() call it will mark it as rendered.
194 rendered_last_frame_ = false; 190 rendered_last_frame_ = false;
195 191
196 if (!current_frame_ ||
197 current_frame_->natural_size() != frame->natural_size()) {
198 natural_size_changed_cb_.Run(frame->natural_size());
199 }
200
201 if (!current_frame_ ||
202 IsOpaque(current_frame_->format()) != IsOpaque(frame->format()))
203 opacity_changed_cb_.Run(IsOpaque(frame->format()));
204
205 current_frame_ = frame; 192 current_frame_ = frame;
206 return true; 193 return true;
207 } 194 }
208 195
209 void VideoFrameCompositor::BackgroundRender() { 196 void VideoFrameCompositor::BackgroundRender() {
210 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); 197 DCHECK(compositor_task_runner_->BelongsToCurrentThread());
211 const base::TimeTicks now = tick_clock_->NowTicks(); 198 const base::TimeTicks now = tick_clock_->NowTicks();
212 last_background_render_ = now; 199 last_background_render_ = now;
213 bool new_frame = CallRender(now, now + last_interval_, true); 200 bool new_frame = CallRender(now, now + last_interval_, true);
214 if (new_frame && client_) 201 if (new_frame && client_)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 last_interval_ = deadline_max - deadline_min; 236 last_interval_ = deadline_max - deadline_min;
250 237
251 // Restart the background rendering timer whether we're background rendering 238 // Restart the background rendering timer whether we're background rendering
252 // or not; in either case we should wait for |kBackgroundRenderingTimeoutMs|. 239 // or not; in either case we should wait for |kBackgroundRenderingTimeoutMs|.
253 if (background_rendering_enabled_) 240 if (background_rendering_enabled_)
254 background_rendering_timer_.Reset(); 241 background_rendering_timer_.Reset();
255 return new_frame || had_new_background_frame; 242 return new_frame || had_new_background_frame;
256 } 243 }
257 244
258 } // namespace media 245 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698