Chromium Code Reviews| Index: media/capture/video/fake_video_capture_device.cc |
| diff --git a/media/capture/video/fake_video_capture_device.cc b/media/capture/video/fake_video_capture_device.cc |
| index 9b15110b17270b8f74f3f74e4fed8252c1dd83be..21a6037483aa3901b4f31e03e5ac0af44d72fd69 100644 |
| --- a/media/capture/video/fake_video_capture_device.cc |
| +++ b/media/capture/video/fake_video_capture_device.cc |
| @@ -15,6 +15,7 @@ |
| #include "third_party/skia/include/core/SkBitmap.h" |
| #include "third_party/skia/include/core/SkCanvas.h" |
| #include "third_party/skia/include/core/SkPaint.h" |
| +#include "ui/gfx/codec/png_codec.h" |
| namespace media { |
| @@ -72,6 +73,29 @@ void DrawPacman(bool use_argb, |
| canvas.drawText(time_string.data(), time_string.length(), 30, 20, paint); |
| } |
| +// Creates a PNG-encoded frame and sends it back to |callback|. The other |
| +// parameters are used to replicate the PacMan rendering. |
| +void RunTakePhotoCallback(const VideoCaptureDevice::TakePhotoCallback& callback, |
|
miu
2016/05/05 22:04:24
naming: RunTakePhotoCallback() doesn't really tell
mcasas
2016/05/05 23:05:50
Done.
|
| + const VideoCaptureFormat& capture_format, |
| + base::TimeDelta elapsed_time, |
| + float fake_capture_rate) { |
| + std::unique_ptr<uint8_t[]> buffer(new uint8_t[VideoFrame::AllocationSize( |
| + PIXEL_FORMAT_ARGB, capture_format.frame_size)]); |
| + |
| + DrawPacman(true /* use_argb */, buffer.get(), elapsed_time, fake_capture_rate, |
| + capture_format.frame_size); |
| + |
| + std::unique_ptr<std::vector<uint8_t>> encoded_data( |
| + new std::vector<uint8_t>()); |
| + const bool result = gfx::PNGCodec::Encode( |
| + buffer.get(), gfx::PNGCodec::FORMAT_RGBA, capture_format.frame_size, |
| + capture_format.frame_size.width() * 4, true /* discard_transparency */, |
| + std::vector<gfx::PNGCodec::Comment>(), encoded_data.get()); |
| + DCHECK(result); |
| + |
| + callback.Run("image/png", std::move(encoded_data)); |
| +} |
| + |
| FakeVideoCaptureDevice::FakeVideoCaptureDevice(BufferOwnership buffer_ownership, |
| float fake_capture_rate) |
| : buffer_ownership_(buffer_ownership), |
| @@ -137,6 +161,15 @@ void FakeVideoCaptureDevice::StopAndDeAllocate() { |
| client_.reset(); |
| } |
| +bool FakeVideoCaptureDevice::TakePhoto( |
| + const TakePhotoCallback& photo_callback) { |
| + base::MessageLoop::current()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&RunTakePhotoCallback, photo_callback, capture_format_, |
| + elapsed_time_, fake_capture_rate_)); |
| + return true; |
| +} |
| + |
| void FakeVideoCaptureDevice::CaptureUsingOwnBuffers( |
| base::TimeTicks expected_execution_time) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |