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

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: miu@s 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 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"
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::vector<uint8_t>> data) {
22 DCHECK(data.get());
23 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
miu 2016/05/05 22:04:24 FWICT, the trampoline to run the callback on the U
mcasas 2016/05/05 23:05:50 Done.
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, mojo::Array<uint8_t>::From(*data));
31 }
32
33 void TakePhotoOnIOThread(const mojo::String& source_id,
34 const ImageCaptureImpl::TakePhotoCallback& callback,
35 MediaStreamManager* media_stream_manager) {
36 DCHECK_CURRENTLY_ON(BrowserThread::IO);
37
38 const int session_id =
39 media_stream_manager->VideoDeviceIdToSessionId(source_id);
40
41 if (session_id == StreamDeviceInfo::kNoId) {
42 std::unique_ptr<std::vector<uint8_t>> empty_vector(
43 new std::vector<uint8_t>());
44 RunTakePhotoCallback(callback, "", std::move(empty_vector));
45 return;
46 }
47
48 const bool result = media_stream_manager->video_capture_manager()->TakePhoto(
49 session_id, base::Bind(&RunTakePhotoCallback, callback));
50 DCHECK(result);
miu 2016/05/05 22:04:24 This feels brittle. It's possible for the TakePhot
mcasas 2016/05/05 23:05:50 Done.
51 }
52
53 } // anonymous namespace
54
12 // static 55 // static
13 void ImageCaptureImpl::Create( 56 void ImageCaptureImpl::Create(
14 mojo::InterfaceRequest<blink::mojom::ImageCapture> request) { 57 mojo::InterfaceRequest<blink::mojom::ImageCapture> request) {
15 // |binding_| will take ownership of ImageCaptureImpl. 58 // |binding_| will take ownership of ImageCaptureImpl.
16 new ImageCaptureImpl(std::move(request)); 59 new ImageCaptureImpl(std::move(request));
17 } 60 }
18 61
19 ImageCaptureImpl::~ImageCaptureImpl() {} 62 ImageCaptureImpl::~ImageCaptureImpl() {}
20 63
21 void ImageCaptureImpl::TakePhoto(const mojo::String& /* source_id */, 64 void ImageCaptureImpl::TakePhoto(const mojo::String& source_id,
22 const TakePhotoCallback& callback) { 65 const TakePhotoCallback& callback) {
23 DCHECK_CURRENTLY_ON(BrowserThread::UI); 66 DCHECK_CURRENTLY_ON(BrowserThread::UI);
24 67 // media_stream_manager() can only be called on UI thread.
25 // TODO(mcasas): Implement this feature., https://crbug.com/518807. 68 BrowserThread::PostTask(
26 mojo::Array<uint8_t> data(1); 69 BrowserThread::IO, FROM_HERE,
27 callback.Run("text/plain", std::move(data)); 70 base::Bind(&TakePhotoOnIOThread, source_id, callback,
71 BrowserMainLoop::GetInstance()->media_stream_manager()));
28 } 72 }
29 73
30 ImageCaptureImpl::ImageCaptureImpl( 74 ImageCaptureImpl::ImageCaptureImpl(
31 mojo::InterfaceRequest<blink::mojom::ImageCapture> request) 75 mojo::InterfaceRequest<blink::mojom::ImageCapture> request)
32 : binding_(this, std::move(request)) {} 76 : binding_(this, std::move(request)) {}
33 77
34 } // namespace content 78 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698