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

Side by Side 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: unittests 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/browser/media/capture/image_capture_impl.h" 5 #include "content/browser/media/capture/image_capture_impl.h"
6 6
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "content/browser/browser_main_loop.h"
miu 2016/05/04 23:45:50 Doesn't look like this include is needed.
mcasas 2016/05/05 00:57:12 Is needed for BrowserMainLoop::GetInstance() in l.
9 #include "content/browser/renderer_host/media/media_stream_manager.h"
10 #include "content/browser/renderer_host/media/video_capture_manager.h"
11 #include "content/common/media/media_stream_options.h"
8 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "media/capture/video/video_capture_device.h"
9 14
10 namespace content { 15 namespace content {
11 16
17 namespace {
18
19 void RunTakePhotoCallback(const ImageCaptureImpl::TakePhotoCallback& callback,
20 const std::string& mime_type,
21 std::unique_ptr<std::string> data) {
miu 2016/05/04 23:45:50 Any particular reason you're mixing use of std::st
mcasas 2016/05/05 00:57:12 Good point, yeah. The previous CL shifted between
22 DCHECK(data.get());
23 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
24 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
25 base::Bind(&RunTakePhotoCallback, callback,
26 mime_type, base::Passed(&data)));
27 return;
28 }
29 DCHECK_CURRENTLY_ON(BrowserThread::UI);
30 callback.Run(mime_type, std::vector<uint8_t>(data->begin(), data->end()));
31 }
32
33 } // anonymous namespace
34
12 // static 35 // static
13 void ImageCaptureImpl::Create( 36 void ImageCaptureImpl::Create(
14 mojo::InterfaceRequest<blink::mojom::ImageCapture> request) { 37 mojo::InterfaceRequest<blink::mojom::ImageCapture> request) {
15 // |binding_| will take ownership of ImageCaptureImpl. 38 // |binding_| will take ownership of ImageCaptureImpl.
16 new ImageCaptureImpl(std::move(request)); 39 new ImageCaptureImpl(std::move(request));
17 } 40 }
18 41
19 ImageCaptureImpl::~ImageCaptureImpl() {} 42 ImageCaptureImpl::~ImageCaptureImpl() {}
20 43
21 void ImageCaptureImpl::TakePhoto(const mojo::String& /* source_id */, 44 void ImageCaptureImpl::TakePhoto(const mojo::String& source_id,
22 const TakePhotoCallback& callback) { 45 const TakePhotoCallback& callback) {
23 DCHECK_CURRENTLY_ON(BrowserThread::UI); 46 DCHECK_CURRENTLY_ON(BrowserThread::UI);
24 47 // media_stream_manager() can only be called on UI thread.
25 // TODO(mcasas): Implement this feature., https://crbug.com/518807. 48 BrowserThread::PostTask(
26 mojo::Array<uint8_t> data(1); 49 BrowserThread::IO, FROM_HERE,
27 callback.Run("text/plain", std::move(data)); 50 base::Bind(&ImageCaptureImpl::TakePhotoOnIOThread, base::Unretained(this),
miu 2016/05/04 23:45:50 base::Unretained(this) is safe, right? (I'm not t
mcasas 2016/05/05 00:57:12 Phew, it might be hard to reason as to if it's rea
51 source_id, callback,
52 BrowserMainLoop::GetInstance()->media_stream_manager()));
28 } 53 }
29 54
30 ImageCaptureImpl::ImageCaptureImpl( 55 ImageCaptureImpl::ImageCaptureImpl(
31 mojo::InterfaceRequest<blink::mojom::ImageCapture> request) 56 mojo::InterfaceRequest<blink::mojom::ImageCapture> request)
32 : binding_(this, std::move(request)) {} 57 : binding_(this, std::move(request)) {}
33 58
59 void ImageCaptureImpl::TakePhotoOnIOThread(
60 const mojo::String& source_id,
61 const TakePhotoCallback& callback,
62 MediaStreamManager* media_stream_manager) {
63 DCHECK_CURRENTLY_ON(BrowserThread::IO);
64
65 const int session_id =
66 media_stream_manager->VideoDeviceIdToSessionId(source_id);
67 if (session_id == StreamDeviceInfo::kNoId) {
68 std::unique_ptr<std::string> empty_string(new std::string(""));
69 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
miu 2016/05/04 23:45:50 IMHO, just call RunTakePhotoCallback() directly (i
mcasas 2016/05/05 00:57:12 Done.
70 base::Bind(&RunTakePhotoCallback, callback, "",
71 base::Passed(&empty_string)));
72 return;
73 }
74
75 const bool result = media_stream_manager->video_capture_manager()->TakePhoto(
76 session_id, base::Bind(&RunTakePhotoCallback, callback));
77 DCHECK(result);
78 }
79
34 } // namespace content 80 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698