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

Unified Diff: content/browser/media/capture/image_capture_impl.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
« no previous file with comments | « no previous file | content/browser/renderer_host/media/media_stream_manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/media/capture/image_capture_impl.cc
diff --git a/content/browser/media/capture/image_capture_impl.cc b/content/browser/media/capture/image_capture_impl.cc
index bfc8b0d0aec9be4af5c1e59d29aeb5512a03753b..1722a4f3a59c4622915872f4099bab3c91fc0e2d 100644
--- a/content/browser/media/capture/image_capture_impl.cc
+++ b/content/browser/media/capture/image_capture_impl.cc
@@ -5,10 +5,52 @@
#include "content/browser/media/capture/image_capture_impl.h"
#include "base/bind_helpers.h"
+#include "content/browser/browser_main_loop.h"
+#include "content/browser/renderer_host/media/media_stream_manager.h"
+#include "content/browser/renderer_host/media/video_capture_manager.h"
+#include "content/common/media/media_stream_options.h"
#include "content/public/browser/browser_thread.h"
+#include "media/capture/video/video_capture_device.h"
namespace content {
+namespace {
+
+void RunMojoCallback(const ImageCaptureImpl::TakePhotoCallback& callback,
+ const std::string& mime_type,
+ mojo::Array<uint8_t> data) {
+ callback.Run(mime_type, std::move(data));
+}
+
+void RunTakePhotoCallback(const ImageCaptureImpl::TakePhotoCallback& callback,
+ const std::string& mime_type,
+ std::unique_ptr<std::vector<uint8_t>> data) {
+ DCHECK(data.get());
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&RunMojoCallback, callback, mime_type,
+ base::Passed(mojo::Array<uint8_t>::From(*data))));
+}
+
+void TakePhotoOnIOThread(const mojo::String& source_id,
+ const ImageCaptureImpl::TakePhotoCallback& callback,
+ MediaStreamManager* media_stream_manager) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+ const int session_id =
+ media_stream_manager->VideoDeviceIdToSessionId(source_id);
+
+ if (session_id == StreamDeviceInfo::kNoId ||
+ !media_stream_manager->video_capture_manager()->TakePhoto(
+ session_id, base::Bind(&RunTakePhotoCallback, callback))) {
+ std::unique_ptr<std::vector<uint8_t>> empty_vector(
+ new std::vector<uint8_t>());
+ RunTakePhotoCallback(callback, "", std::move(empty_vector));
+ }
+}
+
+} // anonymous namespace
+
// static
void ImageCaptureImpl::Create(
mojo::InterfaceRequest<blink::mojom::ImageCapture> request) {
@@ -18,13 +60,14 @@ void ImageCaptureImpl::Create(
ImageCaptureImpl::~ImageCaptureImpl() {}
-void ImageCaptureImpl::TakePhoto(const mojo::String& /* source_id */,
+void ImageCaptureImpl::TakePhoto(const mojo::String& source_id,
const TakePhotoCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
-
- // TODO(mcasas): Implement this feature., https://crbug.com/518807.
- mojo::Array<uint8_t> data(1);
- callback.Run("text/plain", std::move(data));
+ // media_stream_manager() can only be called on UI thread.
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&TakePhotoOnIOThread, source_id, callback,
+ BrowserMainLoop::GetInstance()->media_stream_manager()));
}
ImageCaptureImpl::ImageCaptureImpl(
« no previous file with comments | « no previous file | content/browser/renderer_host/media/media_stream_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698