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

Unified Diff: media/capture/video/fake_video_capture_device.cc

Issue 1952463002: Media Stream Image Capture (4): wire takePhoto and implement in FakeVCDevice (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tommi@ and mlamouri@ comments Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
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..9e1479d81cfd44ec20c3d1deacaf0dafd3a28a2f 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 DoTakeFakePhoto(const VideoCaptureDevice::TakePhotoCallback& callback,
+ 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,14 @@ void FakeVideoCaptureDevice::StopAndDeAllocate() {
client_.reset();
}
+bool FakeVideoCaptureDevice::TakePhoto(
+ const TakePhotoCallback& photo_callback) {
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(&DoTakeFakePhoto, photo_callback, capture_format_,
+ elapsed_time_, fake_capture_rate_));
+ return true;
+}
+
void FakeVideoCaptureDevice::CaptureUsingOwnBuffers(
base::TimeTicks expected_execution_time) {
DCHECK(thread_checker_.CalledOnValidThread());
« no previous file with comments | « media/capture/video/fake_video_capture_device.h ('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