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

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

Issue 2167313002: ImageCapture: introduce image_capture Blob to allow move-only semantics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: foolip comments and rebase Created 4 years, 5 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 const VideoCaptureFormat& capture_format, 94 const VideoCaptureFormat& capture_format,
95 base::TimeDelta elapsed_time, 95 base::TimeDelta elapsed_time,
96 float fake_capture_rate, 96 float fake_capture_rate,
97 uint32_t zoom) { 97 uint32_t zoom) {
98 std::unique_ptr<uint8_t[]> buffer(new uint8_t[VideoFrame::AllocationSize( 98 std::unique_ptr<uint8_t[]> buffer(new uint8_t[VideoFrame::AllocationSize(
99 PIXEL_FORMAT_ARGB, capture_format.frame_size)]); 99 PIXEL_FORMAT_ARGB, capture_format.frame_size)]);
100 100
101 DrawPacman(true /* use_argb */, buffer.get(), elapsed_time, fake_capture_rate, 101 DrawPacman(true /* use_argb */, buffer.get(), elapsed_time, fake_capture_rate,
102 capture_format.frame_size, zoom); 102 capture_format.frame_size, zoom);
103 103
104 std::vector<uint8_t> encoded_data; 104 mojom::BlobPtr blob = mojom::Blob::New();
105 const bool result = gfx::PNGCodec::Encode( 105 const bool result = gfx::PNGCodec::Encode(
106 buffer.get(), gfx::PNGCodec::FORMAT_RGBA, capture_format.frame_size, 106 buffer.get(), gfx::PNGCodec::FORMAT_RGBA, capture_format.frame_size,
107 capture_format.frame_size.width() * 4, true /* discard_transparency */, 107 capture_format.frame_size.width() * 4, true /* discard_transparency */,
108 std::vector<gfx::PNGCodec::Comment>(), &encoded_data); 108 std::vector<gfx::PNGCodec::Comment>(), &blob->data);
109 DCHECK(result); 109 DCHECK(result);
110 110
111 callback.Run("image/png", encoded_data); 111 blob->mime_type = "image/png";
112 callback.Run(std::move(blob));
112 } 113 }
113 114
114 FakeVideoCaptureDevice::FakeVideoCaptureDevice(BufferOwnership buffer_ownership, 115 FakeVideoCaptureDevice::FakeVideoCaptureDevice(BufferOwnership buffer_ownership,
115 float fake_capture_rate) 116 float fake_capture_rate)
116 : buffer_ownership_(buffer_ownership), 117 : buffer_ownership_(buffer_ownership),
117 fake_capture_rate_(fake_capture_rate), 118 fake_capture_rate_(fake_capture_rate),
118 current_zoom_(kMinZoom), 119 current_zoom_(kMinZoom),
119 weak_factory_(this) {} 120 weak_factory_(this) {}
120 121
121 FakeVideoCaptureDevice::~FakeVideoCaptureDevice() { 122 FakeVideoCaptureDevice::~FakeVideoCaptureDevice() {
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 // Don't accumulate any debt if we are lagging behind - just post the next 311 // Don't accumulate any debt if we are lagging behind - just post the next
311 // frame immediately and continue as normal. 312 // frame immediately and continue as normal.
312 const base::TimeTicks next_execution_time = 313 const base::TimeTicks next_execution_time =
313 std::max(current_time, expected_execution_time + frame_interval); 314 std::max(current_time, expected_execution_time + frame_interval);
314 const base::TimeDelta delay = next_execution_time - current_time; 315 const base::TimeDelta delay = next_execution_time - current_time;
315 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 316 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
316 FROM_HERE, base::Bind(next_capture, next_execution_time), delay); 317 FROM_HERE, base::Bind(next_capture, next_execution_time), delay);
317 } 318 }
318 319
319 } // namespace media 320 } // namespace media
OLDNEW
« no previous file with comments | « media/capture/video/android/video_capture_device_android.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