Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
|
xhwang
2015/04/28 23:12:06
2015
DaleCurtis
2015/04/29 00:54:07
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "media/base/null_video_sink.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/callback_helpers.h" | |
| 9 #include "base/location.h" | |
| 10 #include "base/single_thread_task_runner.h" | |
| 11 | |
| 12 namespace media { | |
| 13 | |
| 14 NullVideoSink::NullVideoSink( | |
| 15 bool clockless, | |
| 16 base::TimeDelta interval, | |
| 17 const NewFrameCB& new_frame_cb, | |
| 18 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) | |
| 19 : clockless_(clockless), | |
| 20 interval_(interval), | |
| 21 new_frame_cb_(new_frame_cb), | |
| 22 task_runner_(task_runner), | |
| 23 started_(false), | |
| 24 callback_(nullptr), | |
| 25 tick_clock_(&default_tick_clock_) { | |
| 26 } | |
| 27 | |
| 28 NullVideoSink::~NullVideoSink() { | |
| 29 DCHECK(!started_); | |
| 30 } | |
| 31 | |
| 32 void NullVideoSink::Start(RenderCallback* callback) { | |
| 33 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 34 DCHECK(!started_); | |
| 35 callback_ = callback; | |
| 36 started_ = true; | |
| 37 last_now_ = current_render_time_ = tick_clock_->NowTicks(); | |
| 38 cancelable_worker_.Reset( | |
| 39 base::Bind(&NullVideoSink::CallRender, base::Unretained(this))); | |
| 40 task_runner_->PostTask(FROM_HERE, cancelable_worker_.callback()); | |
| 41 } | |
| 42 | |
| 43 void NullVideoSink::Stop() { | |
| 44 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 45 cancelable_worker_.Cancel(); | |
| 46 started_ = false; | |
| 47 if (!stop_cb_.is_null()) | |
| 48 base::ResetAndReturn(&stop_cb_).Run(); | |
| 49 } | |
| 50 | |
| 51 void NullVideoSink::CallRender() { | |
| 52 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 53 DCHECK(started_); | |
| 54 | |
| 55 const base::TimeTicks end_of_interval = current_render_time_ + interval_; | |
| 56 DVLOG(2) << "NullVideoSink::Render(" << current_render_time_.ToInternalValue() | |
|
xhwang
2015/04/28 23:12:06
s/Render/CallRender? This doesn't necessarily trig
DaleCurtis
2015/04/29 00:54:07
Just going to remove, it was really for debugging
| |
| 57 << ", " << end_of_interval.ToInternalValue() << ")"; | |
| 58 | |
| 59 if (current_render_time_ > pause_end_time_) { | |
| 60 scoped_refptr<VideoFrame> new_frame = | |
| 61 callback_->Render(current_render_time_, end_of_interval); | |
| 62 const bool is_new_frame = new_frame != last_frame_; | |
| 63 last_frame_ = new_frame; | |
| 64 if (is_new_frame) | |
| 65 new_frame_cb_.Run(new_frame); | |
| 66 } | |
| 67 | |
| 68 current_render_time_ += interval_; | |
| 69 | |
| 70 if (clockless_) { | |
| 71 task_runner_->PostTask(FROM_HERE, cancelable_worker_.callback()); | |
| 72 return; | |
| 73 } | |
| 74 | |
| 75 // Recompute now to compensate for the cost of Render(). | |
| 76 const base::TimeTicks now = tick_clock_->NowTicks(); | |
| 77 base::TimeDelta delay = current_render_time_ - now; | |
| 78 | |
| 79 // If we're behind, find the next nearest on time interval. | |
| 80 if (delay < base::TimeDelta()) | |
| 81 delay += interval_ * (-delay / interval_ + 1); | |
|
xhwang
2015/04/28 23:12:06
IIUIC, this translates to:
delay += interval_ *
DaleCurtis
2015/04/29 00:54:07
That's not quite true since this is integer math a
xhwang
2015/04/29 03:49:13
Ah, I see. Sorry for my ignorance :)
Just an extr
DaleCurtis
2015/04/29 04:26:48
It could go either way, since delay is 0, we may n
| |
| 82 current_render_time_ = now + delay; | |
| 83 | |
| 84 // The tick clock is frozen in this case, so clamp delay to the interval time. | |
| 85 // We still want the interval passed to Render() to grow, but we also don't | |
| 86 // want the delay used here to increase slowly over time. | |
| 87 if (last_now_ == now && delay > interval_) | |
| 88 delay = interval_; | |
| 89 last_now_ = now; | |
| 90 | |
| 91 task_runner_->PostDelayedTask(FROM_HERE, cancelable_worker_.callback(), | |
| 92 delay); | |
| 93 } | |
| 94 | |
| 95 void NullVideoSink::PaintFrameUsingOldRenderingPath( | |
| 96 const scoped_refptr<VideoFrame>& frame) { | |
| 97 new_frame_cb_.Run(frame); | |
| 98 } | |
| 99 | |
| 100 } // namespace media | |
| OLD | NEW |