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 #include <algorithm> | 8 #include <algorithm> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 expected_execution_time, | 312 expected_execution_time, |
313 base::Bind(&FakeVideoCaptureDevice::CaptureUsingOwnBuffers, | 313 base::Bind(&FakeVideoCaptureDevice::CaptureUsingOwnBuffers, |
314 weak_factory_.GetWeakPtr())); | 314 weak_factory_.GetWeakPtr())); |
315 } | 315 } |
316 | 316 |
317 void FakeVideoCaptureDevice::CaptureUsingClientBuffers( | 317 void FakeVideoCaptureDevice::CaptureUsingClientBuffers( |
318 base::TimeTicks expected_execution_time) { | 318 base::TimeTicks expected_execution_time) { |
319 DCHECK(thread_checker_.CalledOnValidThread()); | 319 DCHECK(thread_checker_.CalledOnValidThread()); |
320 | 320 |
321 const int arbitrary_frame_feedback_id = 0; | 321 const int arbitrary_frame_feedback_id = 0; |
322 std::unique_ptr<VideoCaptureDevice::Client::Buffer> capture_buffer( | 322 VideoCaptureDevice::Client::Buffer capture_buffer = |
323 client_->ReserveOutputBuffer( | 323 client_->ReserveOutputBuffer( |
324 capture_format_.frame_size, capture_format_.pixel_format, | 324 capture_format_.frame_size, capture_format_.pixel_format, |
325 capture_format_.pixel_storage, arbitrary_frame_feedback_id)); | 325 capture_format_.pixel_storage, arbitrary_frame_feedback_id); |
326 DLOG_IF(ERROR, !capture_buffer) << "Couldn't allocate Capture Buffer"; | 326 DLOG_IF(ERROR, !capture_buffer.is_valid()) |
327 DCHECK(capture_buffer->data()) << "Buffer has NO backing memory"; | 327 << "Couldn't allocate Capture Buffer"; |
| 328 auto buffer_access = |
| 329 capture_buffer.handle_provider()->GetHandleForInProcessAccess(); |
| 330 DCHECK(buffer_access->data()) << "Buffer has NO backing memory"; |
328 | 331 |
329 DCHECK_EQ(PIXEL_STORAGE_CPU, capture_format_.pixel_storage); | 332 DCHECK_EQ(PIXEL_STORAGE_CPU, capture_format_.pixel_storage); |
330 uint8_t* data_ptr = static_cast<uint8_t*>(capture_buffer->data()); | 333 uint8_t* data_ptr = buffer_access->data(); |
331 memset(data_ptr, 0, capture_buffer->mapped_size()); | 334 memset(data_ptr, 0, buffer_access->mapped_size()); |
332 DrawPacman(capture_format_.pixel_format, data_ptr, elapsed_time_, | 335 DrawPacman(capture_format_.pixel_format, data_ptr, elapsed_time_, |
333 fake_capture_rate_, capture_format_.frame_size, current_zoom_); | 336 fake_capture_rate_, capture_format_.frame_size, current_zoom_); |
334 | 337 |
335 // Give the captured frame to the client. | 338 // Give the captured frame to the client. |
336 base::TimeTicks now = base::TimeTicks::Now(); | 339 base::TimeTicks now = base::TimeTicks::Now(); |
337 if (first_ref_time_.is_null()) | 340 if (first_ref_time_.is_null()) |
338 first_ref_time_ = now; | 341 first_ref_time_ = now; |
339 client_->OnIncomingCapturedBuffer(std::move(capture_buffer), capture_format_, | 342 client_->OnIncomingCapturedBuffer(std::move(capture_buffer), capture_format_, |
340 now, now - first_ref_time_); | 343 now, now - first_ref_time_); |
341 | 344 |
(...skipping 24 matching lines...) Expand all Loading... |
366 // Don't accumulate any debt if we are lagging behind - just post the next | 369 // Don't accumulate any debt if we are lagging behind - just post the next |
367 // frame immediately and continue as normal. | 370 // frame immediately and continue as normal. |
368 const base::TimeTicks next_execution_time = | 371 const base::TimeTicks next_execution_time = |
369 std::max(current_time, expected_execution_time + frame_interval); | 372 std::max(current_time, expected_execution_time + frame_interval); |
370 const base::TimeDelta delay = next_execution_time - current_time; | 373 const base::TimeDelta delay = next_execution_time - current_time; |
371 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 374 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
372 FROM_HERE, base::Bind(next_capture, next_execution_time), delay); | 375 FROM_HERE, base::Bind(next_capture, next_execution_time), delay); |
373 } | 376 } |
374 | 377 |
375 } // namespace media | 378 } // namespace media |
OLD | NEW |