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

Side by Side Diff: media/capture/video/fake_video_capture_device.cc

Issue 2573223002: [Mojo Video Capture] Simplify media::VideoCaptureDevice::Client:Buffer to a struct (Closed)
Patch Set: mcasas comments Created 3 years, 11 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 (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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 expected_execution_time, 313 expected_execution_time,
314 base::Bind(&FakeVideoCaptureDevice::CaptureUsingOwnBuffers, 314 base::Bind(&FakeVideoCaptureDevice::CaptureUsingOwnBuffers,
315 weak_factory_.GetWeakPtr())); 315 weak_factory_.GetWeakPtr()));
316 } 316 }
317 317
318 void FakeVideoCaptureDevice::CaptureUsingClientBuffers( 318 void FakeVideoCaptureDevice::CaptureUsingClientBuffers(
319 base::TimeTicks expected_execution_time) { 319 base::TimeTicks expected_execution_time) {
320 DCHECK(thread_checker_.CalledOnValidThread()); 320 DCHECK(thread_checker_.CalledOnValidThread());
321 321
322 const int arbitrary_frame_feedback_id = 0; 322 const int arbitrary_frame_feedback_id = 0;
323 std::unique_ptr<VideoCaptureDevice::Client::Buffer> capture_buffer( 323 VideoCaptureDevice::Client::Buffer capture_buffer =
324 client_->ReserveOutputBuffer( 324 client_->ReserveOutputBuffer(
325 capture_format_.frame_size, capture_format_.pixel_format, 325 capture_format_.frame_size, capture_format_.pixel_format,
326 capture_format_.pixel_storage, arbitrary_frame_feedback_id)); 326 capture_format_.pixel_storage, arbitrary_frame_feedback_id);
327 DLOG_IF(ERROR, !capture_buffer) << "Couldn't allocate Capture Buffer"; 327 DLOG_IF(ERROR, !capture_buffer.is_valid())
328 DCHECK(capture_buffer->data()) << "Buffer has NO backing memory"; 328 << "Couldn't allocate Capture Buffer";
329 auto buffer_access =
330 capture_buffer.handle_provider()->GetHandleForInProcessAccess();
331 DCHECK(buffer_access->data()) << "Buffer has NO backing memory";
329 332
330 DCHECK_EQ(PIXEL_STORAGE_CPU, capture_format_.pixel_storage); 333 DCHECK_EQ(PIXEL_STORAGE_CPU, capture_format_.pixel_storage);
331 uint8_t* data_ptr = static_cast<uint8_t*>(capture_buffer->data()); 334 uint8_t* data_ptr = buffer_access->data();
332 memset(data_ptr, 0, capture_buffer->mapped_size()); 335 memset(data_ptr, 0, buffer_access->mapped_size());
333 DrawPacman(capture_format_.pixel_format, data_ptr, elapsed_time_, 336 DrawPacman(capture_format_.pixel_format, data_ptr, elapsed_time_,
334 fake_capture_rate_, capture_format_.frame_size, current_zoom_); 337 fake_capture_rate_, capture_format_.frame_size, current_zoom_);
335 338
336 // Give the captured frame to the client. 339 // Give the captured frame to the client.
337 base::TimeTicks now = base::TimeTicks::Now(); 340 base::TimeTicks now = base::TimeTicks::Now();
338 if (first_ref_time_.is_null()) 341 if (first_ref_time_.is_null())
339 first_ref_time_ = now; 342 first_ref_time_ = now;
340 client_->OnIncomingCapturedBuffer(std::move(capture_buffer), capture_format_, 343 client_->OnIncomingCapturedBuffer(std::move(capture_buffer), capture_format_,
341 now, now - first_ref_time_); 344 now, now - first_ref_time_);
342 345
(...skipping 24 matching lines...) Expand all
367 // Don't accumulate any debt if we are lagging behind - just post the next 370 // Don't accumulate any debt if we are lagging behind - just post the next
368 // frame immediately and continue as normal. 371 // frame immediately and continue as normal.
369 const base::TimeTicks next_execution_time = 372 const base::TimeTicks next_execution_time =
370 std::max(current_time, expected_execution_time + frame_interval); 373 std::max(current_time, expected_execution_time + frame_interval);
371 const base::TimeDelta delay = next_execution_time - current_time; 374 const base::TimeDelta delay = next_execution_time - current_time;
372 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 375 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
373 FROM_HERE, base::Bind(next_capture, next_execution_time), delay); 376 FROM_HERE, base::Bind(next_capture, next_execution_time), delay);
374 } 377 }
375 378
376 } // namespace media 379 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/content/thread_safe_capture_oracle.cc ('k') | media/capture/video/fake_video_capture_device_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698