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

Side by Side Diff: content/browser/renderer_host/media/service_video_capture_device_launcher.cc

Issue 2857303002: [Mojo Video Capture] Implement a VideoCaptureProvider using the Mojo service (part 2) (Closed)
Patch Set: Incorporated suggestions from PatchSets 1 and 2 Created 3 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/renderer_host/media/service_video_capture_device_launc her.h" 5 #include "content/browser/renderer_host/media/service_video_capture_device_launc her.h"
6 6
7 #include "content/browser/renderer_host/media/service_launched_video_capture_dev ice.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "media/capture/video/video_frame_receiver_on_task_runner.h"
10 #include "mojo/public/cpp/bindings/strong_binding.h"
11 #include "services/video_capture/public/cpp/receiver_media_to_mojo_adapter.h"
12
7 namespace content { 13 namespace content {
8 14
15 namespace {
16
17 void ConcludeLaunchDeviceWithSuccess(
18 bool abort_requested,
19 const media::VideoCaptureParams& params,
20 video_capture::mojom::DevicePtr device,
21 base::WeakPtr<media::VideoFrameReceiver> receiver,
22 VideoCaptureDeviceLauncher::Callbacks* callbacks,
23 base::OnceClosure done_cb) {
24 if (abort_requested) {
25 device.reset();
26 callbacks->OnDeviceLaunchAborted();
27 base::ResetAndReturn(&done_cb).Run();
28 return;
29 }
30
31 auto receiver_adapter =
32 base::MakeUnique<video_capture::ReceiverMediaToMojoAdapter>(
33 base::MakeUnique<media::VideoFrameReceiverOnTaskRunner>(
34 std::move(receiver),
35 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)));
36 video_capture::mojom::ReceiverPtr receiver_proxy;
37 mojo::MakeStrongBinding<video_capture::mojom::Receiver>(
38 std::move(receiver_adapter), mojo::MakeRequest(&receiver_proxy));
39 device->Start(params, std::move(receiver_proxy));
40 callbacks->OnDeviceLaunched(
41 base::MakeUnique<ServiceLaunchedVideoCaptureDevice>(std::move(device)));
42 base::ResetAndReturn(&done_cb).Run();
43 }
44
45 void ConcludeLaunchDeviceWithFailure(
46 bool abort_requested,
47 VideoCaptureDeviceLauncher::Callbacks* callbacks,
48 base::OnceClosure done_cb) {
49 if (abort_requested)
50 callbacks->OnDeviceLaunchAborted();
51 else
52 callbacks->OnDeviceLaunchFailed();
53 base::ResetAndReturn(&done_cb).Run();
54 }
55
56 } // anonymous namespace
57
9 ServiceVideoCaptureDeviceLauncher::ServiceVideoCaptureDeviceLauncher( 58 ServiceVideoCaptureDeviceLauncher::ServiceVideoCaptureDeviceLauncher(
10 video_capture::mojom::DeviceFactoryPtr* device_factory) 59 video_capture::mojom::DeviceFactoryPtr* device_factory)
11 : device_factory_(device_factory) {} 60 : device_factory_(device_factory), state_(State::READY_TO_LAUNCH) {}
12 61
13 ServiceVideoCaptureDeviceLauncher::~ServiceVideoCaptureDeviceLauncher() {} 62 ServiceVideoCaptureDeviceLauncher::~ServiceVideoCaptureDeviceLauncher() {
63 DCHECK(state_ == State::READY_TO_LAUNCH);
64 }
14 65
15 void ServiceVideoCaptureDeviceLauncher::LaunchDeviceAsync( 66 void ServiceVideoCaptureDeviceLauncher::LaunchDeviceAsync(
16 const std::string& device_id, 67 const std::string& device_id,
17 MediaStreamType stream_type, 68 MediaStreamType stream_type,
18 const media::VideoCaptureParams& params, 69 const media::VideoCaptureParams& params,
19 base::WeakPtr<media::VideoFrameReceiver> receiver, 70 base::WeakPtr<media::VideoFrameReceiver> receiver,
20 Callbacks* callbacks, 71 Callbacks* callbacks,
21 base::OnceClosure done_cb) { 72 base::OnceClosure done_cb) {
22 NOTIMPLEMENTED(); 73 DCHECK(state_ == State::READY_TO_LAUNCH);
74
75 if (stream_type != content::MEDIA_DEVICE_VIDEO_CAPTURE) {
76 // This launcher only supports MEDIA_DEVICE_VIDEO_CAPTURE.
77 NOTREACHED();
78 return;
79 }
80
81 if (!device_factory_->is_bound()) {
82 // This can happen when the ServiceVideoCaptureProvider owning
83 // |device_factory_| loses connection to the service process and resets
84 // |device_factory_|.
85 ConcludeLaunchDeviceWithFailure(false, callbacks, std::move(done_cb));
86 return;
87 }
88 video_capture::mojom::DevicePtr device;
89 (*device_factory_)
90 ->CreateDevice(
91 device_id, mojo::MakeRequest(&device),
92 base::Bind(
93 // Use of Unretained |this| is safe, because |done_cb| guarantees
94 // that |this| stays alive.
95 &ServiceVideoCaptureDeviceLauncher::OnCreateDeviceCallback,
96 base::Unretained(this), params, base::Passed(&device),
97 std::move(receiver), callbacks, base::Passed(&done_cb)));
98 state_ = State::DEVICE_START_IN_PROGRESS;
23 } 99 }
24 100
25 void ServiceVideoCaptureDeviceLauncher::AbortLaunch() { 101 void ServiceVideoCaptureDeviceLauncher::AbortLaunch() {
26 NOTIMPLEMENTED(); 102 if (state_ == State::DEVICE_START_IN_PROGRESS)
103 state_ = State::DEVICE_START_ABORTING;
104 }
105
106 void ServiceVideoCaptureDeviceLauncher::OnCreateDeviceCallback(
107 const media::VideoCaptureParams& params,
108 video_capture::mojom::DevicePtr device,
109 base::WeakPtr<media::VideoFrameReceiver> receiver,
110 Callbacks* callbacks,
111 base::OnceClosure done_cb,
112 video_capture::mojom::DeviceAccessResultCode result_code) {
113 bool abort_requested = (state_ == State::DEVICE_START_ABORTING);
mcasas 2017/05/09 19:00:54 micro-nit: const
114 switch (result_code) {
115 case video_capture::mojom::DeviceAccessResultCode::SUCCESS:
116 ConcludeLaunchDeviceWithSuccess(abort_requested, params,
117 std::move(device), std::move(receiver),
118 callbacks, std::move(done_cb));
119 return;
120 case video_capture::mojom::DeviceAccessResultCode::ERROR_DEVICE_NOT_FOUND:
121 case video_capture::mojom::DeviceAccessResultCode::NOT_INITIALIZED:
122 ConcludeLaunchDeviceWithFailure(abort_requested, callbacks,
123 std::move(done_cb));
124 return;
125 }
27 } 126 }
28 127
29 } // namespace content 128 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/service_video_capture_device_launcher.h ('k') | services/video_capture/service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698