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

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

Issue 2398813002: Cleanup of video capture into GpuMemoryBuffer (Closed)
Patch Set: Rebase Created 4 years, 2 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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 base::TimeTicks expected_execution_time) { 252 base::TimeTicks expected_execution_time) {
253 DCHECK(thread_checker_.CalledOnValidThread()); 253 DCHECK(thread_checker_.CalledOnValidThread());
254 254
255 std::unique_ptr<VideoCaptureDevice::Client::Buffer> capture_buffer( 255 std::unique_ptr<VideoCaptureDevice::Client::Buffer> capture_buffer(
256 client_->ReserveOutputBuffer(capture_format_.frame_size, 256 client_->ReserveOutputBuffer(capture_format_.frame_size,
257 capture_format_.pixel_format, 257 capture_format_.pixel_format,
258 capture_format_.pixel_storage)); 258 capture_format_.pixel_storage));
259 DLOG_IF(ERROR, !capture_buffer) << "Couldn't allocate Capture Buffer"; 259 DLOG_IF(ERROR, !capture_buffer) << "Couldn't allocate Capture Buffer";
260 DCHECK(capture_buffer->data()) << "Buffer has NO backing memory"; 260 DCHECK(capture_buffer->data()) << "Buffer has NO backing memory";
261 261
262 if (capture_format_.pixel_storage == PIXEL_STORAGE_GPUMEMORYBUFFER && 262 DCHECK_EQ(PIXEL_STORAGE_CPU, capture_format_.pixel_storage);
263 capture_format_.pixel_format == media::PIXEL_FORMAT_I420) { 263 DCHECK_EQ(PIXEL_FORMAT_ARGB, capture_format_.pixel_format);
264 // Since SkBitmap expects a packed&continuous memory region for I420, we 264 uint8_t* data_ptr = static_cast<uint8_t*>(capture_buffer->data());
265 // need to use |fake_frame_| to draw onto. 265 memset(data_ptr, 0, capture_buffer->mapped_size());
266 memset(fake_frame_.get(), 0, capture_format_.ImageAllocationSize()); 266 DrawPacman(true /* use_argb */, data_ptr, elapsed_time_, fake_capture_rate_,
267 DrawPacman(false /* use_argb */, fake_frame_.get(), elapsed_time_, 267 capture_format_.frame_size, current_zoom_);
268 fake_capture_rate_, capture_format_.frame_size, current_zoom_);
269
270 // Copy data from |fake_frame_| into the reserved planes of GpuMemoryBuffer.
271 size_t offset = 0;
272 for (size_t i = 0; i < VideoFrame::NumPlanes(PIXEL_FORMAT_I420); ++i) {
273 const size_t plane_size =
274 VideoFrame::PlaneSize(PIXEL_FORMAT_I420, i,
275 capture_format_.frame_size)
276 .GetArea();
277 memcpy(capture_buffer->data(i), fake_frame_.get() + offset, plane_size);
278 offset += plane_size;
279 }
280 } else {
281 DCHECK_EQ(capture_format_.pixel_storage, PIXEL_STORAGE_CPU);
282 DCHECK_EQ(capture_format_.pixel_format, PIXEL_FORMAT_ARGB);
283 uint8_t* data_ptr = static_cast<uint8_t*>(capture_buffer->data());
284 memset(data_ptr, 0, capture_buffer->mapped_size());
285 DrawPacman(true /* use_argb */, data_ptr, elapsed_time_, fake_capture_rate_,
286 capture_format_.frame_size, current_zoom_);
287 }
288 268
289 // Give the captured frame to the client. 269 // Give the captured frame to the client.
290 base::TimeTicks now = base::TimeTicks::Now(); 270 base::TimeTicks now = base::TimeTicks::Now();
291 if (first_ref_time_.is_null()) 271 if (first_ref_time_.is_null())
292 first_ref_time_ = now; 272 first_ref_time_ = now;
293 client_->OnIncomingCapturedBuffer(std::move(capture_buffer), capture_format_, 273 client_->OnIncomingCapturedBuffer(std::move(capture_buffer), capture_format_,
294 now, now - first_ref_time_); 274 now, now - first_ref_time_);
295 275
296 BeepAndScheduleNextCapture( 276 BeepAndScheduleNextCapture(
297 expected_execution_time, 277 expected_execution_time,
(...skipping 22 matching lines...) Expand all
320 // Don't accumulate any debt if we are lagging behind - just post the next 300 // Don't accumulate any debt if we are lagging behind - just post the next
321 // frame immediately and continue as normal. 301 // frame immediately and continue as normal.
322 const base::TimeTicks next_execution_time = 302 const base::TimeTicks next_execution_time =
323 std::max(current_time, expected_execution_time + frame_interval); 303 std::max(current_time, expected_execution_time + frame_interval);
324 const base::TimeDelta delay = next_execution_time - current_time; 304 const base::TimeDelta delay = next_execution_time - current_time;
325 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 305 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
326 FROM_HERE, base::Bind(next_capture, next_execution_time), delay); 306 FROM_HERE, base::Bind(next_capture, next_execution_time), delay);
327 } 307 }
328 308
329 } // namespace media 309 } // namespace media
OLDNEW
« no previous file with comments | « media/base/video_capture_types.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