Chromium Code Reviews| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 // TODO(miu): The value for tab capture should be determined programmatically. | 50 // TODO(miu): The value for tab capture should be determined programmatically. |
| 51 // http://crbug.com/460318 | 51 // http://crbug.com/460318 |
| 52 const int kMaxNumberOfBuffersForTabCapture = 10; | 52 const int kMaxNumberOfBuffersForTabCapture = 10; |
| 53 | 53 |
| 54 } // anonymous namespace | 54 } // anonymous namespace |
| 55 | 55 |
| 56 namespace content { | 56 namespace content { |
| 57 | 57 |
| 58 InProcessVideoCaptureDeviceLauncher::InProcessVideoCaptureDeviceLauncher( | 58 InProcessVideoCaptureDeviceLauncher::InProcessVideoCaptureDeviceLauncher( |
| 59 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner, | 59 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner, |
| 60 media::VideoCaptureSystem* video_capture_system) | 60 media::VideoCaptureSystem* optional_video_capture_system) |
| 61 : device_task_runner_(std::move(device_task_runner)), | 61 : device_task_runner_(std::move(device_task_runner)), |
| 62 video_capture_system_(video_capture_system), | 62 optional_video_capture_system_(optional_video_capture_system), |
| 63 state_(State::READY_TO_LAUNCH) {} | 63 state_(State::READY_TO_LAUNCH) {} |
| 64 | 64 |
| 65 InProcessVideoCaptureDeviceLauncher::~InProcessVideoCaptureDeviceLauncher() { | 65 InProcessVideoCaptureDeviceLauncher::~InProcessVideoCaptureDeviceLauncher() { |
| 66 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 66 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 67 DCHECK(state_ == State::READY_TO_LAUNCH); | 67 DCHECK(state_ == State::READY_TO_LAUNCH); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void InProcessVideoCaptureDeviceLauncher::LaunchDeviceAsync( | 70 void InProcessVideoCaptureDeviceLauncher::LaunchDeviceAsync( |
| 71 const std::string& device_id, | 71 const std::string& device_id, |
| 72 MediaStreamType stream_type, | 72 MediaStreamType stream_type, |
| (...skipping 12 matching lines...) Expand all 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 (!optional_video_capture_system_) { | |
| 96 callbacks->OnDeviceLaunchFailed(); | |
| 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 } |
|
mcasas
2017/05/16 22:22:22
If we want to run |done_cb| in every possible retu
chfremer
2017/05/16 22:45:02
Agreed that this would be better and cleaner. Unfo
| |
| 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()); |
| 203 | 211 |
| 204 std::unique_ptr<media::VideoCaptureDevice> video_capture_device = | 212 std::unique_ptr<media::VideoCaptureDevice> video_capture_device = |
| 205 video_capture_system_->CreateDevice(device_id); | 213 optional_video_capture_system_->CreateDevice(device_id); |
|
mcasas
2017/05/16 22:22:22
If it's optional, we should check if (optional_vid
chfremer
2017/05/16 22:45:01
True. There is already a check in LaunchDeviceAsyn
| |
| 206 | 214 |
| 207 if (!video_capture_device) { | 215 if (!video_capture_device) { |
| 208 result_callback.Run(nullptr); | 216 result_callback.Run(nullptr); |
| 209 return; | 217 return; |
| 210 } | 218 } |
| 211 | 219 |
| 212 video_capture_device->AllocateAndStart(params, std::move(device_client)); | 220 video_capture_device->AllocateAndStart(params, std::move(device_client)); |
| 213 result_callback.Run(std::move(video_capture_device)); | 221 result_callback.Run(std::move(video_capture_device)); |
| 214 } | 222 } |
| 215 | 223 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 if (!video_capture_device) { | 288 if (!video_capture_device) { |
| 281 result_callback.Run(nullptr); | 289 result_callback.Run(nullptr); |
| 282 return; | 290 return; |
| 283 } | 291 } |
| 284 | 292 |
| 285 video_capture_device->AllocateAndStart(params, std::move(device_client)); | 293 video_capture_device->AllocateAndStart(params, std::move(device_client)); |
| 286 result_callback.Run(std::move(video_capture_device)); | 294 result_callback.Run(std::move(video_capture_device)); |
| 287 } | 295 } |
| 288 | 296 |
| 289 } // namespace content | 297 } // namespace content |
| OLD | NEW |