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 callbacks->OnDeviceLaunchFailed(); | |
emircan
2017/05/18 18:40:16
This becomes the second caller of OnDeviceLaunchFa
chfremer
2017/05/18 19:03:21
Good point. I realized that this code path is actu
| |
97 base::ResetAndReturn(&done_cb).Run(); | |
98 return; | |
99 } | |
95 start_capture_closure = | 100 start_capture_closure = |
96 base::Bind(&InProcessVideoCaptureDeviceLauncher:: | 101 base::Bind(&InProcessVideoCaptureDeviceLauncher:: |
97 DoStartDeviceCaptureOnDeviceThread, | 102 DoStartDeviceCaptureOnDeviceThread, |
98 base::Unretained(this), device_id, params, | 103 base::Unretained(this), device_id, params, |
99 base::Passed(std::move(device_client)), | 104 base::Passed(std::move(device_client)), |
100 std::move(after_start_capture_callback)); | 105 std::move(after_start_capture_callback)); |
101 break; | 106 break; |
102 } | 107 } |
103 case MEDIA_TAB_VIDEO_CAPTURE: | 108 case MEDIA_TAB_VIDEO_CAPTURE: |
104 start_capture_closure = base::Bind( | 109 start_capture_closure = base::Bind( |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 Callbacks* callbacks, | 163 Callbacks* callbacks, |
159 base::OnceClosure done_cb, | 164 base::OnceClosure done_cb, |
160 std::unique_ptr<media::VideoCaptureDevice> device) { | 165 std::unique_ptr<media::VideoCaptureDevice> device) { |
161 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 166 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
162 State state_copy = state_; | 167 State state_copy = state_; |
163 state_ = State::READY_TO_LAUNCH; | 168 state_ = State::READY_TO_LAUNCH; |
164 if (!device) { | 169 if (!device) { |
165 switch (state_copy) { | 170 switch (state_copy) { |
166 case State::DEVICE_START_IN_PROGRESS: | 171 case State::DEVICE_START_IN_PROGRESS: |
167 callbacks->OnDeviceLaunchFailed(); | 172 callbacks->OnDeviceLaunchFailed(); |
173 base::ResetAndReturn(&done_cb).Run(); | |
168 return; | 174 return; |
169 case State::DEVICE_START_ABORTING: | 175 case State::DEVICE_START_ABORTING: |
170 callbacks->OnDeviceLaunchAborted(); | 176 callbacks->OnDeviceLaunchAborted(); |
177 base::ResetAndReturn(&done_cb).Run(); | |
171 return; | 178 return; |
172 case State::READY_TO_LAUNCH: | 179 case State::READY_TO_LAUNCH: |
173 NOTREACHED(); | 180 NOTREACHED(); |
174 return; | 181 return; |
175 } | 182 } |
176 } | 183 } |
177 | 184 |
178 auto launched_device = base::MakeUnique<InProcessLaunchedVideoCaptureDevice>( | 185 auto launched_device = base::MakeUnique<InProcessLaunchedVideoCaptureDevice>( |
179 std::move(device), device_task_runner_); | 186 std::move(device), device_task_runner_); |
180 | 187 |
181 switch (state_copy) { | 188 switch (state_copy) { |
182 case State::DEVICE_START_IN_PROGRESS: | 189 case State::DEVICE_START_IN_PROGRESS: |
183 callbacks->OnDeviceLaunched(std::move(launched_device)); | 190 callbacks->OnDeviceLaunched(std::move(launched_device)); |
191 base::ResetAndReturn(&done_cb).Run(); | |
184 return; | 192 return; |
185 case State::DEVICE_START_ABORTING: | 193 case State::DEVICE_START_ABORTING: |
186 launched_device.reset(); | 194 launched_device.reset(); |
187 callbacks->OnDeviceLaunchAborted(); | 195 callbacks->OnDeviceLaunchAborted(); |
196 base::ResetAndReturn(&done_cb).Run(); | |
188 return; | 197 return; |
189 case State::READY_TO_LAUNCH: | 198 case State::READY_TO_LAUNCH: |
190 NOTREACHED(); | 199 NOTREACHED(); |
191 return; | 200 return; |
192 } | 201 } |
193 base::ResetAndReturn(&done_cb).Run(); | |
194 } | 202 } |
195 | 203 |
196 void InProcessVideoCaptureDeviceLauncher::DoStartDeviceCaptureOnDeviceThread( | 204 void InProcessVideoCaptureDeviceLauncher::DoStartDeviceCaptureOnDeviceThread( |
197 const std::string& device_id, | 205 const std::string& device_id, |
198 const media::VideoCaptureParams& params, | 206 const media::VideoCaptureParams& params, |
199 std::unique_ptr<media::VideoCaptureDeviceClient> device_client, | 207 std::unique_ptr<media::VideoCaptureDeviceClient> device_client, |
200 ReceiveDeviceCallback result_callback) { | 208 ReceiveDeviceCallback result_callback) { |
201 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); | 209 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); |
202 DCHECK(device_task_runner_->BelongsToCurrentThread()); | 210 DCHECK(device_task_runner_->BelongsToCurrentThread()); |
211 DCHECK(video_capture_system_); | |
203 | 212 |
204 std::unique_ptr<media::VideoCaptureDevice> video_capture_device = | 213 std::unique_ptr<media::VideoCaptureDevice> video_capture_device = |
205 video_capture_system_->CreateDevice(device_id); | 214 video_capture_system_->CreateDevice(device_id); |
206 | 215 |
207 if (!video_capture_device) { | 216 if (!video_capture_device) { |
208 result_callback.Run(nullptr); | 217 result_callback.Run(nullptr); |
209 return; | 218 return; |
210 } | 219 } |
211 | 220 |
212 video_capture_device->AllocateAndStart(params, std::move(device_client)); | 221 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) { | 289 if (!video_capture_device) { |
281 result_callback.Run(nullptr); | 290 result_callback.Run(nullptr); |
282 return; | 291 return; |
283 } | 292 } |
284 | 293 |
285 video_capture_device->AllocateAndStart(params, std::move(device_client)); | 294 video_capture_device->AllocateAndStart(params, std::move(device_client)); |
286 result_callback.Run(std::move(video_capture_device)); | 295 result_callback.Run(std::move(video_capture_device)); |
287 } | 296 } |
288 | 297 |
289 } // namespace content | 298 } // namespace content |
OLD | NEW |