| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/video_capture_host.h" | 5 #include "content/browser/renderer_host/media/video_capture_host.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 mojo::MakeStrongBinding( | 32 mojo::MakeStrongBinding( |
| 33 base::MakeUnique<VideoCaptureHost>(media_stream_manager), | 33 base::MakeUnique<VideoCaptureHost>(media_stream_manager), |
| 34 std::move(request)); | 34 std::move(request)); |
| 35 } | 35 } |
| 36 | 36 |
| 37 VideoCaptureHost::~VideoCaptureHost() { | 37 VideoCaptureHost::~VideoCaptureHost() { |
| 38 for (auto it = controllers_.begin(); it != controllers_.end(); ) { | 38 for (auto it = controllers_.begin(); it != controllers_.end(); ) { |
| 39 const base::WeakPtr<VideoCaptureController>& controller = it->second; | 39 const base::WeakPtr<VideoCaptureController>& controller = it->second; |
| 40 if (controller) { | 40 if (controller) { |
| 41 const VideoCaptureControllerID controller_id(it->first); | 41 const VideoCaptureControllerID controller_id(it->first); |
| 42 media_stream_manager_->video_capture_manager()->StopCaptureForClient( | 42 media_stream_manager_->video_capture_manager()->DisconnectClient( |
| 43 controller.get(), controller_id, this, false); | 43 controller.get(), controller_id, this, false); |
| 44 ++it; | 44 ++it; |
| 45 } else { | 45 } else { |
| 46 // Remove the entry for this controller_id so that when the controller | 46 // Remove the entry for this controller_id so that when the controller |
| 47 // is added, the controller will be notified to stop for this client | 47 // is added, the controller will be notified to stop for this client |
| 48 // in DoControllerAdded. | 48 // in DoControllerAdded. |
| 49 controllers_.erase(it++); | 49 controllers_.erase(it++); |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 } | 52 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 device_id_to_observer_map_[device_id] = std::move(observer); | 135 device_id_to_observer_map_[device_id] = std::move(observer); |
| 136 | 136 |
| 137 const VideoCaptureControllerID controller_id(device_id); | 137 const VideoCaptureControllerID controller_id(device_id); |
| 138 if (controllers_.find(controller_id) != controllers_.end()) { | 138 if (controllers_.find(controller_id) != controllers_.end()) { |
| 139 device_id_to_observer_map_[device_id]->OnStateChanged( | 139 device_id_to_observer_map_[device_id]->OnStateChanged( |
| 140 mojom::VideoCaptureState::STARTED); | 140 mojom::VideoCaptureState::STARTED); |
| 141 return; | 141 return; |
| 142 } | 142 } |
| 143 | 143 |
| 144 controllers_[controller_id] = base::WeakPtr<VideoCaptureController>(); | 144 controllers_[controller_id] = base::WeakPtr<VideoCaptureController>(); |
| 145 media_stream_manager_->video_capture_manager()->StartCaptureForClient( | 145 media_stream_manager_->video_capture_manager()->ConnectClient( |
| 146 session_id, params, controller_id, this, | 146 session_id, params, controller_id, this, |
| 147 base::Bind(&VideoCaptureHost::OnControllerAdded, | 147 base::Bind(&VideoCaptureHost::OnControllerAdded, |
| 148 weak_factory_.GetWeakPtr(), device_id)); | 148 weak_factory_.GetWeakPtr(), device_id)); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void VideoCaptureHost::Stop(int32_t device_id) { | 151 void VideoCaptureHost::Stop(int32_t device_id) { |
| 152 DVLOG(1) << __func__ << " " << device_id; | 152 DVLOG(1) << __func__ << " " << device_id; |
| 153 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 153 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 154 | 154 |
| 155 VideoCaptureControllerID controller_id(device_id); | 155 VideoCaptureControllerID controller_id(device_id); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 } | 288 } |
| 289 | 289 |
| 290 void VideoCaptureHost::OnControllerAdded( | 290 void VideoCaptureHost::OnControllerAdded( |
| 291 int device_id, | 291 int device_id, |
| 292 const base::WeakPtr<VideoCaptureController>& controller) { | 292 const base::WeakPtr<VideoCaptureController>& controller) { |
| 293 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 293 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 294 VideoCaptureControllerID controller_id(device_id); | 294 VideoCaptureControllerID controller_id(device_id); |
| 295 auto it = controllers_.find(controller_id); | 295 auto it = controllers_.find(controller_id); |
| 296 if (it == controllers_.end()) { | 296 if (it == controllers_.end()) { |
| 297 if (controller) { | 297 if (controller) { |
| 298 media_stream_manager_->video_capture_manager()->StopCaptureForClient( | 298 media_stream_manager_->video_capture_manager()->DisconnectClient( |
| 299 controller.get(), controller_id, this, false); | 299 controller.get(), controller_id, this, false); |
| 300 } | 300 } |
| 301 return; | 301 return; |
| 302 } | 302 } |
| 303 | 303 |
| 304 if (!controller) { | 304 if (!controller) { |
| 305 if (base::ContainsKey(device_id_to_observer_map_, controller_id)) { | 305 if (base::ContainsKey(device_id_to_observer_map_, controller_id)) { |
| 306 device_id_to_observer_map_[device_id]->OnStateChanged( | 306 device_id_to_observer_map_[device_id]->OnStateChanged( |
| 307 mojom::VideoCaptureState::FAILED); | 307 mojom::VideoCaptureState::FAILED); |
| 308 } | 308 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 320 | 320 |
| 321 auto it = controllers_.find(controller_id); | 321 auto it = controllers_.find(controller_id); |
| 322 if (it == controllers_.end()) | 322 if (it == controllers_.end()) |
| 323 return; | 323 return; |
| 324 | 324 |
| 325 const base::WeakPtr<VideoCaptureController> controller = it->second; | 325 const base::WeakPtr<VideoCaptureController> controller = it->second; |
| 326 controllers_.erase(it); | 326 controllers_.erase(it); |
| 327 if (!controller) | 327 if (!controller) |
| 328 return; | 328 return; |
| 329 | 329 |
| 330 media_stream_manager_->video_capture_manager()->StopCaptureForClient( | 330 media_stream_manager_->video_capture_manager()->DisconnectClient( |
| 331 controller.get(), controller_id, this, on_error); | 331 controller.get(), controller_id, this, on_error); |
| 332 } | 332 } |
| 333 | 333 |
| 334 } // namespace content | 334 } // namespace content |
| OLD | NEW |