Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/video/capture/fake_video_capture_device.h" | 5 #include "media/video/capture/fake_video_capture_device.h" |
| 6 | 6 |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "media/audio/fake_audio_input_stream.h" | 10 #include "media/audio/fake_audio_input_stream.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 weak_factory_.GetWeakPtr(), (device_type_ == USING_CLIENT_BUFFERS_I420 | 116 weak_factory_.GetWeakPtr(), (device_type_ == USING_CLIENT_BUFFERS_I420 |
| 117 ? PIXEL_FORMAT_I420 | 117 ? PIXEL_FORMAT_I420 |
| 118 : PIXEL_FORMAT_GPUMEMORYBUFFER))); | 118 : PIXEL_FORMAT_GPUMEMORYBUFFER))); |
| 119 } else { | 119 } else { |
| 120 client_->OnError("Unknown Fake Video Capture Device type."); | 120 client_->OnError("Unknown Fake Video Capture Device type."); |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 | 123 |
| 124 void FakeVideoCaptureDevice::StopAndDeAllocate() { | 124 void FakeVideoCaptureDevice::StopAndDeAllocate() { |
| 125 DCHECK(thread_checker_.CalledOnValidThread()); | 125 DCHECK(thread_checker_.CalledOnValidThread()); |
| 126 next_frame_time_ = base::TimeTicks(); | |
| 126 client_.reset(); | 127 client_.reset(); |
| 127 } | 128 } |
| 128 | 129 |
| 129 void FakeVideoCaptureDevice::CaptureUsingOwnBuffers() { | 130 void FakeVideoCaptureDevice::CaptureUsingOwnBuffers() { |
| 130 DCHECK(thread_checker_.CalledOnValidThread()); | 131 DCHECK(thread_checker_.CalledOnValidThread()); |
| 131 const size_t frame_size = capture_format_.ImageAllocationSize(); | 132 const size_t frame_size = capture_format_.ImageAllocationSize(); |
| 132 memset(fake_frame_.get(), 0, frame_size); | 133 memset(fake_frame_.get(), 0, frame_size); |
| 133 | 134 |
| 134 DrawPacman(false /* use_argb */, | 135 DrawPacman(false /* use_argb */, |
| 135 fake_frame_.get(), | 136 fake_frame_.get(), |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 client_->OnIncomingCapturedBuffer(capture_buffer.Pass(), format, | 190 client_->OnIncomingCapturedBuffer(capture_buffer.Pass(), format, |
| 190 base::TimeTicks::Now()); | 191 base::TimeTicks::Now()); |
| 191 } | 192 } |
| 192 | 193 |
| 193 BeepAndScheduleNextCapture( | 194 BeepAndScheduleNextCapture( |
| 194 base::Bind(&FakeVideoCaptureDevice::CaptureUsingClientBuffers, | 195 base::Bind(&FakeVideoCaptureDevice::CaptureUsingClientBuffers, |
| 195 weak_factory_.GetWeakPtr(), pixel_format)); | 196 weak_factory_.GetWeakPtr(), pixel_format)); |
| 196 } | 197 } |
| 197 | 198 |
| 198 void FakeVideoCaptureDevice::BeepAndScheduleNextCapture( | 199 void FakeVideoCaptureDevice::BeepAndScheduleNextCapture( |
| 199 const base::Closure& next_capture) { | 200 const base::Closure& next_capture) { |
|
mcasas
2015/06/08 17:30:35
What about adding a parameter to BeepAndScheduleNe
| |
| 200 // Generate a synchronized beep sound every so many frames. | 201 // Generate a synchronized beep sound every so many frames. |
| 201 if (frame_count_++ % kFakeCaptureBeepCycle == 0) | 202 if (frame_count_++ % kFakeCaptureBeepCycle == 0) |
| 202 FakeAudioInputStream::BeepOnce(); | 203 FakeAudioInputStream::BeepOnce(); |
| 203 | 204 |
| 204 // Reschedule next CaptureTask. | 205 // Reschedule next CaptureTask. |
| 205 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, next_capture, | 206 const base::TimeTicks current_time = base::TimeTicks::Now(); |
| 206 base::TimeDelta::FromMilliseconds(kFakeCapturePeriodMs)); | 207 const base::TimeDelta frame_interval = |
| 208 base::TimeDelta::FromMilliseconds(kFakeCapturePeriodMs); | |
| 209 if (next_frame_time_.is_null()) { | |
|
mcasas
2015/06/08 17:30:35
I'm not super happy with l.209, it feels like we'l
| |
| 210 next_frame_time_ = current_time + frame_interval; | |
| 211 } else { | |
| 212 next_frame_time_ += frame_interval; | |
| 213 // Don't accumulate any debt if we are lagging behind - just post the next | |
| 214 // frame immediately and continue as normal. | |
| 215 if (next_frame_time_ < current_time) | |
| 216 next_frame_time_ = current_time; | |
| 217 } | |
| 218 base::MessageLoop::current()->PostDelayedTask( | |
| 219 FROM_HERE, next_capture, next_frame_time_ - current_time); | |
| 207 } | 220 } |
| 208 | 221 |
| 209 } // namespace media | 222 } // namespace media |
| OLD | NEW |