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/in_process_video_capture_device_la
uncher.h" | 5 #include "content/browser/renderer_host/media/in_process_video_capture_device_la
uncher.h" |
6 | 6 |
7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "content/browser/media/capture/desktop_capture_device_uma_types.h" | 9 #include "content/browser/media/capture/desktop_capture_device_uma_types.h" |
10 #include "content/browser/media/capture/web_contents_video_capture_device.h" | 10 #include "content/browser/media/capture/web_contents_video_capture_device.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 | 85 |
86 base::Closure start_capture_closure; | 86 base::Closure start_capture_closure; |
87 // Use of Unretained |this| is safe, because |done_cb| guarantees that |this| | 87 // Use of Unretained |this| is safe, because |done_cb| guarantees that |this| |
88 // stays alive. | 88 // stays alive. |
89 ReceiveDeviceCallback after_start_capture_callback = media::BindToCurrentLoop( | 89 ReceiveDeviceCallback after_start_capture_callback = media::BindToCurrentLoop( |
90 base::Bind(&InProcessVideoCaptureDeviceLauncher::OnDeviceStarted, | 90 base::Bind(&InProcessVideoCaptureDeviceLauncher::OnDeviceStarted, |
91 base::Unretained(this), callbacks, base::Passed(&done_cb))); | 91 base::Unretained(this), callbacks, base::Passed(&done_cb))); |
92 | 92 |
93 switch (stream_type) { | 93 switch (stream_type) { |
94 case MEDIA_DEVICE_VIDEO_CAPTURE: { | 94 case MEDIA_DEVICE_VIDEO_CAPTURE: { |
| 95 if (!video_capture_system_) { |
| 96 // Clients who create an instance of |this| without providing a |
| 97 // VideoCaptureSystem instance are expected to know that |
| 98 // MEDIA_DEVICE_VIDEO_CAPTURE is not supported in this case. |
| 99 NOTREACHED(); |
| 100 return; |
| 101 } |
95 start_capture_closure = | 102 start_capture_closure = |
96 base::Bind(&InProcessVideoCaptureDeviceLauncher:: | 103 base::Bind(&InProcessVideoCaptureDeviceLauncher:: |
97 DoStartDeviceCaptureOnDeviceThread, | 104 DoStartDeviceCaptureOnDeviceThread, |
98 base::Unretained(this), device_id, params, | 105 base::Unretained(this), device_id, params, |
99 base::Passed(std::move(device_client)), | 106 base::Passed(std::move(device_client)), |
100 std::move(after_start_capture_callback)); | 107 std::move(after_start_capture_callback)); |
101 break; | 108 break; |
102 } | 109 } |
103 case MEDIA_TAB_VIDEO_CAPTURE: | 110 case MEDIA_TAB_VIDEO_CAPTURE: |
104 start_capture_closure = base::Bind( | 111 start_capture_closure = base::Bind( |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 Callbacks* callbacks, | 165 Callbacks* callbacks, |
159 base::OnceClosure done_cb, | 166 base::OnceClosure done_cb, |
160 std::unique_ptr<media::VideoCaptureDevice> device) { | 167 std::unique_ptr<media::VideoCaptureDevice> device) { |
161 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 168 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
162 State state_copy = state_; | 169 State state_copy = state_; |
163 state_ = State::READY_TO_LAUNCH; | 170 state_ = State::READY_TO_LAUNCH; |
164 if (!device) { | 171 if (!device) { |
165 switch (state_copy) { | 172 switch (state_copy) { |
166 case State::DEVICE_START_IN_PROGRESS: | 173 case State::DEVICE_START_IN_PROGRESS: |
167 callbacks->OnDeviceLaunchFailed(); | 174 callbacks->OnDeviceLaunchFailed(); |
| 175 base::ResetAndReturn(&done_cb).Run(); |
168 return; | 176 return; |
169 case State::DEVICE_START_ABORTING: | 177 case State::DEVICE_START_ABORTING: |
170 callbacks->OnDeviceLaunchAborted(); | 178 callbacks->OnDeviceLaunchAborted(); |
| 179 base::ResetAndReturn(&done_cb).Run(); |
171 return; | 180 return; |
172 case State::READY_TO_LAUNCH: | 181 case State::READY_TO_LAUNCH: |
173 NOTREACHED(); | 182 NOTREACHED(); |
174 return; | 183 return; |
175 } | 184 } |
176 } | 185 } |
177 | 186 |
178 auto launched_device = base::MakeUnique<InProcessLaunchedVideoCaptureDevice>( | 187 auto launched_device = base::MakeUnique<InProcessLaunchedVideoCaptureDevice>( |
179 std::move(device), device_task_runner_); | 188 std::move(device), device_task_runner_); |
180 | 189 |
181 switch (state_copy) { | 190 switch (state_copy) { |
182 case State::DEVICE_START_IN_PROGRESS: | 191 case State::DEVICE_START_IN_PROGRESS: |
183 callbacks->OnDeviceLaunched(std::move(launched_device)); | 192 callbacks->OnDeviceLaunched(std::move(launched_device)); |
| 193 base::ResetAndReturn(&done_cb).Run(); |
184 return; | 194 return; |
185 case State::DEVICE_START_ABORTING: | 195 case State::DEVICE_START_ABORTING: |
186 launched_device.reset(); | 196 launched_device.reset(); |
187 callbacks->OnDeviceLaunchAborted(); | 197 callbacks->OnDeviceLaunchAborted(); |
| 198 base::ResetAndReturn(&done_cb).Run(); |
188 return; | 199 return; |
189 case State::READY_TO_LAUNCH: | 200 case State::READY_TO_LAUNCH: |
190 NOTREACHED(); | 201 NOTREACHED(); |
191 return; | 202 return; |
192 } | 203 } |
193 base::ResetAndReturn(&done_cb).Run(); | |
194 } | 204 } |
195 | 205 |
196 void InProcessVideoCaptureDeviceLauncher::DoStartDeviceCaptureOnDeviceThread( | 206 void InProcessVideoCaptureDeviceLauncher::DoStartDeviceCaptureOnDeviceThread( |
197 const std::string& device_id, | 207 const std::string& device_id, |
198 const media::VideoCaptureParams& params, | 208 const media::VideoCaptureParams& params, |
199 std::unique_ptr<media::VideoCaptureDeviceClient> device_client, | 209 std::unique_ptr<media::VideoCaptureDeviceClient> device_client, |
200 ReceiveDeviceCallback result_callback) { | 210 ReceiveDeviceCallback result_callback) { |
201 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); | 211 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); |
202 DCHECK(device_task_runner_->BelongsToCurrentThread()); | 212 DCHECK(device_task_runner_->BelongsToCurrentThread()); |
| 213 DCHECK(video_capture_system_); |
203 | 214 |
204 std::unique_ptr<media::VideoCaptureDevice> video_capture_device = | 215 std::unique_ptr<media::VideoCaptureDevice> video_capture_device = |
205 video_capture_system_->CreateDevice(device_id); | 216 video_capture_system_->CreateDevice(device_id); |
206 | 217 |
207 if (!video_capture_device) { | 218 if (!video_capture_device) { |
208 result_callback.Run(nullptr); | 219 result_callback.Run(nullptr); |
209 return; | 220 return; |
210 } | 221 } |
211 | 222 |
212 video_capture_device->AllocateAndStart(params, std::move(device_client)); | 223 video_capture_device->AllocateAndStart(params, std::move(device_client)); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 if (!video_capture_device) { | 291 if (!video_capture_device) { |
281 result_callback.Run(nullptr); | 292 result_callback.Run(nullptr); |
282 return; | 293 return; |
283 } | 294 } |
284 | 295 |
285 video_capture_device->AllocateAndStart(params, std::move(device_client)); | 296 video_capture_device->AllocateAndStart(params, std::move(device_client)); |
286 result_callback.Run(std::move(video_capture_device)); | 297 result_callback.Run(std::move(video_capture_device)); |
287 } | 298 } |
288 | 299 |
289 } // namespace content | 300 } // namespace content |
OLD | NEW |