| 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/capture/video/fake_video_capture_device.h" | 5 #include "media/capture/video/fake_video_capture_device.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | |
| 9 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "media/audio/fake_audio_input_stream.h" | 13 #include "media/audio/fake_audio_input_stream.h" |
| 14 #include "media/base/video_frame.h" | 14 #include "media/base/video_frame.h" |
| 15 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
| 16 #include "third_party/skia/include/core/SkCanvas.h" | 16 #include "third_party/skia/include/core/SkCanvas.h" |
| 17 #include "third_party/skia/include/core/SkPaint.h" | 17 #include "third_party/skia/include/core/SkPaint.h" |
| 18 | 18 |
| 19 namespace media { | 19 namespace media { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 82 |
| 83 FakeVideoCaptureDevice::~FakeVideoCaptureDevice() { | 83 FakeVideoCaptureDevice::~FakeVideoCaptureDevice() { |
| 84 DCHECK(thread_checker_.CalledOnValidThread()); | 84 DCHECK(thread_checker_.CalledOnValidThread()); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void FakeVideoCaptureDevice::AllocateAndStart( | 87 void FakeVideoCaptureDevice::AllocateAndStart( |
| 88 const VideoCaptureParams& params, | 88 const VideoCaptureParams& params, |
| 89 scoped_ptr<VideoCaptureDevice::Client> client) { | 89 scoped_ptr<VideoCaptureDevice::Client> client) { |
| 90 DCHECK(thread_checker_.CalledOnValidThread()); | 90 DCHECK(thread_checker_.CalledOnValidThread()); |
| 91 | 91 |
| 92 client_ = client.Pass(); | 92 client_ = std::move(client); |
| 93 | 93 |
| 94 // Incoming |params| can be none of the supported formats, so we get the | 94 // Incoming |params| can be none of the supported formats, so we get the |
| 95 // closest thing rounded up. TODO(mcasas): Use the |params|, if they belong to | 95 // closest thing rounded up. TODO(mcasas): Use the |params|, if they belong to |
| 96 // the supported ones, when http://crbug.com/309554 is verified. | 96 // the supported ones, when http://crbug.com/309554 is verified. |
| 97 capture_format_.frame_rate = fake_capture_rate_; | 97 capture_format_.frame_rate = fake_capture_rate_; |
| 98 if (params.requested_format.frame_size.width() > 1280) | 98 if (params.requested_format.frame_size.width() > 1280) |
| 99 capture_format_.frame_size.SetSize(1920, 1080); | 99 capture_format_.frame_size.SetSize(1920, 1080); |
| 100 else if (params.requested_format.frame_size.width() > 640) | 100 else if (params.requested_format.frame_size.width() > 640) |
| 101 capture_format_.frame_size.SetSize(1280, 720); | 101 capture_format_.frame_size.SetSize(1280, 720); |
| 102 else if (params.requested_format.frame_size.width() > 320) | 102 else if (params.requested_format.frame_size.width() > 320) |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 } else { | 207 } else { |
| 208 DCHECK_EQ(capture_format_.pixel_storage, PIXEL_STORAGE_CPU); | 208 DCHECK_EQ(capture_format_.pixel_storage, PIXEL_STORAGE_CPU); |
| 209 DCHECK_EQ(capture_format_.pixel_format, PIXEL_FORMAT_ARGB); | 209 DCHECK_EQ(capture_format_.pixel_format, PIXEL_FORMAT_ARGB); |
| 210 uint8_t* data_ptr = static_cast<uint8_t*>(capture_buffer->data()); | 210 uint8_t* data_ptr = static_cast<uint8_t*>(capture_buffer->data()); |
| 211 memset(data_ptr, 0, capture_buffer->mapped_size()); | 211 memset(data_ptr, 0, capture_buffer->mapped_size()); |
| 212 DrawPacman(true /* use_argb */, data_ptr, elapsed_time_, fake_capture_rate_, | 212 DrawPacman(true /* use_argb */, data_ptr, elapsed_time_, fake_capture_rate_, |
| 213 capture_format_.frame_size); | 213 capture_format_.frame_size); |
| 214 } | 214 } |
| 215 | 215 |
| 216 // Give the captured frame to the client. | 216 // Give the captured frame to the client. |
| 217 client_->OnIncomingCapturedBuffer(capture_buffer.Pass(), capture_format_, | 217 client_->OnIncomingCapturedBuffer(std::move(capture_buffer), capture_format_, |
| 218 base::TimeTicks::Now()); | 218 base::TimeTicks::Now()); |
| 219 | 219 |
| 220 BeepAndScheduleNextCapture( | 220 BeepAndScheduleNextCapture( |
| 221 expected_execution_time, | 221 expected_execution_time, |
| 222 base::Bind(&FakeVideoCaptureDevice::CaptureUsingClientBuffers, | 222 base::Bind(&FakeVideoCaptureDevice::CaptureUsingClientBuffers, |
| 223 weak_factory_.GetWeakPtr())); | 223 weak_factory_.GetWeakPtr())); |
| 224 } | 224 } |
| 225 | 225 |
| 226 void FakeVideoCaptureDevice::BeepAndScheduleNextCapture( | 226 void FakeVideoCaptureDevice::BeepAndScheduleNextCapture( |
| 227 base::TimeTicks expected_execution_time, | 227 base::TimeTicks expected_execution_time, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 244 // Don't accumulate any debt if we are lagging behind - just post the next | 244 // Don't accumulate any debt if we are lagging behind - just post the next |
| 245 // frame immediately and continue as normal. | 245 // frame immediately and continue as normal. |
| 246 const base::TimeTicks next_execution_time = | 246 const base::TimeTicks next_execution_time = |
| 247 std::max(current_time, expected_execution_time + frame_interval); | 247 std::max(current_time, expected_execution_time + frame_interval); |
| 248 const base::TimeDelta delay = next_execution_time - current_time; | 248 const base::TimeDelta delay = next_execution_time - current_time; |
| 249 base::MessageLoop::current()->PostDelayedTask( | 249 base::MessageLoop::current()->PostDelayedTask( |
| 250 FROM_HERE, base::Bind(next_capture, next_execution_time), delay); | 250 FROM_HERE, base::Bind(next_capture, next_execution_time), delay); |
| 251 } | 251 } |
| 252 | 252 |
| 253 } // namespace media | 253 } // namespace media |
| OLD | NEW |