| OLD | NEW |
| 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" | 7 #include "content/browser/renderer_host/media/service_launched_video_capture_dev
ice.h" |
| 8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "media/capture/video/video_frame_receiver_on_task_runner.h" | 9 #include "media/capture/video/video_frame_receiver_on_task_runner.h" |
| 10 #include "mojo/public/cpp/bindings/strong_binding.h" | 10 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 11 #include "services/video_capture/public/cpp/receiver_media_to_mojo_adapter.h" | 11 #include "services/video_capture/public/cpp/receiver_media_to_mojo_adapter.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 void ConcludeLaunchDeviceWithSuccess( | 17 void ConcludeLaunchDeviceWithSuccess( |
| 18 bool abort_requested, | 18 bool abort_requested, |
| 19 const media::VideoCaptureParams& params, | 19 const media::VideoCaptureParams& params, |
| 20 video_capture::mojom::DevicePtr device, | 20 video_capture::mojom::DevicePtr device, |
| 21 base::WeakPtr<media::VideoFrameReceiver> receiver, | 21 base::WeakPtr<media::VideoFrameReceiver> receiver, |
| 22 base::OnceClosure connection_lost_cb, |
| 22 VideoCaptureDeviceLauncher::Callbacks* callbacks, | 23 VideoCaptureDeviceLauncher::Callbacks* callbacks, |
| 23 base::OnceClosure done_cb) { | 24 base::OnceClosure done_cb) { |
| 24 if (abort_requested) { | 25 if (abort_requested) { |
| 25 device.reset(); | 26 device.reset(); |
| 26 callbacks->OnDeviceLaunchAborted(); | 27 callbacks->OnDeviceLaunchAborted(); |
| 27 base::ResetAndReturn(&done_cb).Run(); | 28 base::ResetAndReturn(&done_cb).Run(); |
| 28 return; | 29 return; |
| 29 } | 30 } |
| 30 | 31 |
| 31 auto receiver_adapter = | 32 auto receiver_adapter = |
| 32 base::MakeUnique<video_capture::ReceiverMediaToMojoAdapter>( | 33 base::MakeUnique<video_capture::ReceiverMediaToMojoAdapter>( |
| 33 base::MakeUnique<media::VideoFrameReceiverOnTaskRunner>( | 34 base::MakeUnique<media::VideoFrameReceiverOnTaskRunner>( |
| 34 std::move(receiver), | 35 std::move(receiver), |
| 35 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO))); | 36 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO))); |
| 36 video_capture::mojom::ReceiverPtr receiver_proxy; | 37 video_capture::mojom::ReceiverPtr receiver_proxy; |
| 37 mojo::MakeStrongBinding<video_capture::mojom::Receiver>( | 38 mojo::MakeStrongBinding<video_capture::mojom::Receiver>( |
| 38 std::move(receiver_adapter), mojo::MakeRequest(&receiver_proxy)); | 39 std::move(receiver_adapter), mojo::MakeRequest(&receiver_proxy)); |
| 39 device->Start(params, std::move(receiver_proxy)); | 40 device->Start(params, std::move(receiver_proxy)); |
| 40 callbacks->OnDeviceLaunched( | 41 callbacks->OnDeviceLaunched( |
| 41 base::MakeUnique<ServiceLaunchedVideoCaptureDevice>(std::move(device))); | 42 base::MakeUnique<ServiceLaunchedVideoCaptureDevice>( |
| 43 std::move(device), std::move(connection_lost_cb))); |
| 42 base::ResetAndReturn(&done_cb).Run(); | 44 base::ResetAndReturn(&done_cb).Run(); |
| 43 } | 45 } |
| 44 | 46 |
| 45 void ConcludeLaunchDeviceWithFailure( | 47 void ConcludeLaunchDeviceWithFailure( |
| 46 bool abort_requested, | 48 bool abort_requested, |
| 47 VideoCaptureDeviceLauncher::Callbacks* callbacks, | 49 VideoCaptureDeviceLauncher::Callbacks* callbacks, |
| 48 base::OnceClosure done_cb) { | 50 base::OnceClosure done_cb) { |
| 49 if (abort_requested) | 51 if (abort_requested) |
| 50 callbacks->OnDeviceLaunchAborted(); | 52 callbacks->OnDeviceLaunchAborted(); |
| 51 else | 53 else |
| (...skipping 12 matching lines...) Expand all Loading... |
| 64 ServiceVideoCaptureDeviceLauncher::~ServiceVideoCaptureDeviceLauncher() { | 66 ServiceVideoCaptureDeviceLauncher::~ServiceVideoCaptureDeviceLauncher() { |
| 65 DCHECK(sequence_checker_.CalledOnValidSequence()); | 67 DCHECK(sequence_checker_.CalledOnValidSequence()); |
| 66 DCHECK(state_ == State::READY_TO_LAUNCH); | 68 DCHECK(state_ == State::READY_TO_LAUNCH); |
| 67 } | 69 } |
| 68 | 70 |
| 69 void ServiceVideoCaptureDeviceLauncher::LaunchDeviceAsync( | 71 void ServiceVideoCaptureDeviceLauncher::LaunchDeviceAsync( |
| 70 const std::string& device_id, | 72 const std::string& device_id, |
| 71 MediaStreamType stream_type, | 73 MediaStreamType stream_type, |
| 72 const media::VideoCaptureParams& params, | 74 const media::VideoCaptureParams& params, |
| 73 base::WeakPtr<media::VideoFrameReceiver> receiver, | 75 base::WeakPtr<media::VideoFrameReceiver> receiver, |
| 76 base::OnceClosure connection_lost_cb, |
| 74 Callbacks* callbacks, | 77 Callbacks* callbacks, |
| 75 base::OnceClosure done_cb) { | 78 base::OnceClosure done_cb) { |
| 76 DCHECK(sequence_checker_.CalledOnValidSequence()); | 79 DCHECK(sequence_checker_.CalledOnValidSequence()); |
| 77 DCHECK(state_ == State::READY_TO_LAUNCH); | 80 DCHECK(state_ == State::READY_TO_LAUNCH); |
| 78 | 81 |
| 79 if (stream_type != content::MEDIA_DEVICE_VIDEO_CAPTURE) { | 82 if (stream_type != content::MEDIA_DEVICE_VIDEO_CAPTURE) { |
| 80 // This launcher only supports MEDIA_DEVICE_VIDEO_CAPTURE. | 83 // This launcher only supports MEDIA_DEVICE_VIDEO_CAPTURE. |
| 81 NOTREACHED(); | 84 NOTREACHED(); |
| 82 return; | 85 return; |
| 83 } | 86 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 103 OnConnectionLostWhileWaitingForCallback, | 106 OnConnectionLostWhileWaitingForCallback, |
| 104 base::Unretained(this))); | 107 base::Unretained(this))); |
| 105 (*device_factory_) | 108 (*device_factory_) |
| 106 ->CreateDevice( | 109 ->CreateDevice( |
| 107 device_id, std::move(device_request), | 110 device_id, std::move(device_request), |
| 108 base::Bind( | 111 base::Bind( |
| 109 // Use of Unretained |this| is safe, because |done_cb_| guarantees | 112 // Use of Unretained |this| is safe, because |done_cb_| guarantees |
| 110 // that |this| stays alive. | 113 // that |this| stays alive. |
| 111 &ServiceVideoCaptureDeviceLauncher::OnCreateDeviceCallback, | 114 &ServiceVideoCaptureDeviceLauncher::OnCreateDeviceCallback, |
| 112 base::Unretained(this), params, base::Passed(&device), | 115 base::Unretained(this), params, base::Passed(&device), |
| 113 std::move(receiver))); | 116 std::move(receiver), base::Passed(&connection_lost_cb))); |
| 114 state_ = State::DEVICE_START_IN_PROGRESS; | 117 state_ = State::DEVICE_START_IN_PROGRESS; |
| 115 } | 118 } |
| 116 | 119 |
| 117 void ServiceVideoCaptureDeviceLauncher::AbortLaunch() { | 120 void ServiceVideoCaptureDeviceLauncher::AbortLaunch() { |
| 118 DCHECK(sequence_checker_.CalledOnValidSequence()); | 121 DCHECK(sequence_checker_.CalledOnValidSequence()); |
| 119 if (state_ == State::DEVICE_START_IN_PROGRESS) | 122 if (state_ == State::DEVICE_START_IN_PROGRESS) |
| 120 state_ = State::DEVICE_START_ABORTING; | 123 state_ = State::DEVICE_START_ABORTING; |
| 121 } | 124 } |
| 122 | 125 |
| 123 void ServiceVideoCaptureDeviceLauncher::OnCreateDeviceCallback( | 126 void ServiceVideoCaptureDeviceLauncher::OnCreateDeviceCallback( |
| 124 const media::VideoCaptureParams& params, | 127 const media::VideoCaptureParams& params, |
| 125 video_capture::mojom::DevicePtr device, | 128 video_capture::mojom::DevicePtr device, |
| 126 base::WeakPtr<media::VideoFrameReceiver> receiver, | 129 base::WeakPtr<media::VideoFrameReceiver> receiver, |
| 130 base::OnceClosure connection_lost_cb, |
| 127 video_capture::mojom::DeviceAccessResultCode result_code) { | 131 video_capture::mojom::DeviceAccessResultCode result_code) { |
| 128 DCHECK(sequence_checker_.CalledOnValidSequence()); | 132 DCHECK(sequence_checker_.CalledOnValidSequence()); |
| 129 DCHECK(callbacks_); | 133 DCHECK(callbacks_); |
| 130 DCHECK(done_cb_); | 134 DCHECK(done_cb_); |
| 131 device.set_connection_error_handler(base::Bind(&base::DoNothing)); | 135 device.set_connection_error_handler(base::Bind(&base::DoNothing)); |
| 132 const bool abort_requested = (state_ == State::DEVICE_START_ABORTING); | 136 const bool abort_requested = (state_ == State::DEVICE_START_ABORTING); |
| 133 state_ = State::READY_TO_LAUNCH; | 137 state_ = State::READY_TO_LAUNCH; |
| 134 Callbacks* callbacks = callbacks_; | 138 Callbacks* callbacks = callbacks_; |
| 135 callbacks_ = nullptr; | 139 callbacks_ = nullptr; |
| 136 switch (result_code) { | 140 switch (result_code) { |
| 137 case video_capture::mojom::DeviceAccessResultCode::SUCCESS: | 141 case video_capture::mojom::DeviceAccessResultCode::SUCCESS: |
| 138 ConcludeLaunchDeviceWithSuccess(abort_requested, params, | 142 ConcludeLaunchDeviceWithSuccess( |
| 139 std::move(device), std::move(receiver), | 143 abort_requested, params, std::move(device), std::move(receiver), |
| 140 callbacks, std::move(done_cb_)); | 144 std::move(connection_lost_cb), callbacks, std::move(done_cb_)); |
| 141 return; | 145 return; |
| 142 case video_capture::mojom::DeviceAccessResultCode::ERROR_DEVICE_NOT_FOUND: | 146 case video_capture::mojom::DeviceAccessResultCode::ERROR_DEVICE_NOT_FOUND: |
| 143 case video_capture::mojom::DeviceAccessResultCode::NOT_INITIALIZED: | 147 case video_capture::mojom::DeviceAccessResultCode::NOT_INITIALIZED: |
| 144 ConcludeLaunchDeviceWithFailure(abort_requested, callbacks, | 148 ConcludeLaunchDeviceWithFailure(abort_requested, callbacks, |
| 145 std::move(done_cb_)); | 149 std::move(done_cb_)); |
| 146 return; | 150 return; |
| 147 } | 151 } |
| 148 } | 152 } |
| 149 | 153 |
| 150 void ServiceVideoCaptureDeviceLauncher:: | 154 void ServiceVideoCaptureDeviceLauncher:: |
| 151 OnConnectionLostWhileWaitingForCallback() { | 155 OnConnectionLostWhileWaitingForCallback() { |
| 152 DCHECK(sequence_checker_.CalledOnValidSequence()); | 156 DCHECK(sequence_checker_.CalledOnValidSequence()); |
| 153 DCHECK(callbacks_); | 157 DCHECK(callbacks_); |
| 154 const bool abort_requested = (state_ == State::DEVICE_START_ABORTING); | 158 const bool abort_requested = (state_ == State::DEVICE_START_ABORTING); |
| 155 state_ = State::READY_TO_LAUNCH; | 159 state_ = State::READY_TO_LAUNCH; |
| 156 Callbacks* callbacks = callbacks_; | 160 Callbacks* callbacks = callbacks_; |
| 157 callbacks_ = nullptr; | 161 callbacks_ = nullptr; |
| 158 ConcludeLaunchDeviceWithFailure(abort_requested, callbacks, | 162 ConcludeLaunchDeviceWithFailure(abort_requested, callbacks, |
| 159 std::move(done_cb_)); | 163 std::move(done_cb_)); |
| 160 } | 164 } |
| 161 | 165 |
| 162 } // namespace content | 166 } // namespace content |
| OLD | NEW |