| 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" |
| 11 #include "content/browser/browser_main_loop.h" | 11 #include "content/browser/browser_main_loop.h" |
| 12 #include "content/browser/renderer_host/media/media_stream_manager.h" | 12 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 13 #include "content/browser/renderer_host/media/video_capture_manager.h" | 13 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 14 #include "content/common/media/video_capture_messages.h" | 14 #include "content/common/media/video_capture_messages.h" |
| 15 #include "mojo/public/cpp/system/platform_handle.h" |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 | 18 |
| 18 VideoCaptureHost::VideoCaptureHost(MediaStreamManager* media_stream_manager) | 19 VideoCaptureHost::VideoCaptureHost(MediaStreamManager* media_stream_manager) |
| 19 : BrowserMessageFilter(VideoCaptureMsgStart), | 20 : BrowserMessageFilter(VideoCaptureMsgStart), |
| 20 BrowserAssociatedInterface(this, this), | 21 BrowserAssociatedInterface(this, this), |
| 21 media_stream_manager_(media_stream_manager) { | 22 media_stream_manager_(media_stream_manager) { |
| 22 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 23 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 23 } | 24 } |
| 24 | 25 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 } | 61 } |
| 61 | 62 |
| 62 void VideoCaptureHost::OnBufferCreated(VideoCaptureControllerID controller_id, | 63 void VideoCaptureHost::OnBufferCreated(VideoCaptureControllerID controller_id, |
| 63 base::SharedMemoryHandle handle, | 64 base::SharedMemoryHandle handle, |
| 64 int length, | 65 int length, |
| 65 int buffer_id) { | 66 int buffer_id) { |
| 66 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 67 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 67 if (controllers_.find(controller_id) == controllers_.end()) | 68 if (controllers_.find(controller_id) == controllers_.end()) |
| 68 return; | 69 return; |
| 69 | 70 |
| 70 Send(new VideoCaptureMsg_NewBuffer(controller_id, handle, length, buffer_id)); | 71 if (base::ContainsKey(device_id_to_observer_map_, controller_id)) { |
| 72 device_id_to_observer_map_[controller_id]->OnBufferCreated( |
| 73 buffer_id, |
| 74 mojo::WrapSharedMemoryHandle(handle, length, true /* read_only */)); |
| 75 } |
| 71 } | 76 } |
| 72 | 77 |
| 73 void VideoCaptureHost::OnBufferDestroyed(VideoCaptureControllerID controller_id, | 78 void VideoCaptureHost::OnBufferDestroyed(VideoCaptureControllerID controller_id, |
| 74 int buffer_id) { | 79 int buffer_id) { |
| 75 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 80 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 76 if (controllers_.find(controller_id) == controllers_.end()) | 81 if (controllers_.find(controller_id) == controllers_.end()) |
| 77 return; | 82 return; |
| 78 | 83 |
| 79 if (base::ContainsKey(device_id_to_observer_map_, controller_id)) | 84 if (base::ContainsKey(device_id_to_observer_map_, controller_id)) |
| 80 device_id_to_observer_map_[controller_id]->OnBufferDestroyed(buffer_id); | 85 device_id_to_observer_map_[controller_id]->OnBufferDestroyed(buffer_id); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 106 } | 111 } |
| 107 | 112 |
| 108 void VideoCaptureHost::OnEnded(VideoCaptureControllerID controller_id) { | 113 void VideoCaptureHost::OnEnded(VideoCaptureControllerID controller_id) { |
| 109 DVLOG(1) << __func__; | 114 DVLOG(1) << __func__; |
| 110 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 115 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 111 BrowserThread::PostTask( | 116 BrowserThread::PostTask( |
| 112 BrowserThread::IO, FROM_HERE, | 117 BrowserThread::IO, FROM_HERE, |
| 113 base::Bind(&VideoCaptureHost::DoEnded, this, controller_id)); | 118 base::Bind(&VideoCaptureHost::DoEnded, this, controller_id)); |
| 114 } | 119 } |
| 115 | 120 |
| 116 void VideoCaptureHost::DoError(VideoCaptureControllerID controller_id) { | |
| 117 DVLOG(1) << __func__; | |
| 118 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 119 if (controllers_.find(controller_id) == controllers_.end()) | |
| 120 return; | |
| 121 | |
| 122 if (base::ContainsKey(device_id_to_observer_map_, controller_id)) { | |
| 123 device_id_to_observer_map_[controller_id]->OnStateChanged( | |
| 124 mojom::VideoCaptureState::FAILED); | |
| 125 } | |
| 126 | |
| 127 DeleteVideoCaptureController(controller_id, true); | |
| 128 } | |
| 129 | |
| 130 void VideoCaptureHost::DoEnded(VideoCaptureControllerID controller_id) { | |
| 131 DVLOG(1) << __func__; | |
| 132 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 133 if (controllers_.find(controller_id) == controllers_.end()) | |
| 134 return; | |
| 135 | |
| 136 if (base::ContainsKey(device_id_to_observer_map_, controller_id)) { | |
| 137 device_id_to_observer_map_[controller_id]->OnStateChanged( | |
| 138 mojom::VideoCaptureState::ENDED); | |
| 139 } | |
| 140 | |
| 141 DeleteVideoCaptureController(controller_id, false); | |
| 142 } | |
| 143 | |
| 144 void VideoCaptureHost::Start(int32_t device_id, | 121 void VideoCaptureHost::Start(int32_t device_id, |
| 145 int32_t session_id, | 122 int32_t session_id, |
| 146 const media::VideoCaptureParams& params, | 123 const media::VideoCaptureParams& params, |
| 147 mojom::VideoCaptureObserverPtr observer) { | 124 mojom::VideoCaptureObserverPtr observer) { |
| 148 DVLOG(1) << __func__ << " session_id=" << session_id | 125 DVLOG(1) << __func__ << " session_id=" << session_id |
| 149 << ", device_id=" << device_id << ", format=" | 126 << ", device_id=" << device_id << ", format=" |
| 150 << media::VideoCaptureFormat::ToString(params.requested_format); | 127 << media::VideoCaptureFormat::ToString(params.requested_format); |
| 151 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 128 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 152 | 129 |
| 153 DCHECK(!base::ContainsKey(device_id_to_observer_map_, device_id)); | 130 DCHECK(!base::ContainsKey(device_id_to_observer_map_, device_id)); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 DVLOG(1) << __func__ << " " << device_id; | 252 DVLOG(1) << __func__ << " " << device_id; |
| 276 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 253 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 277 media::VideoCaptureFormats formats_in_use; | 254 media::VideoCaptureFormats formats_in_use; |
| 278 if (!media_stream_manager_->video_capture_manager()->GetDeviceFormatsInUse( | 255 if (!media_stream_manager_->video_capture_manager()->GetDeviceFormatsInUse( |
| 279 session_id, &formats_in_use)) { | 256 session_id, &formats_in_use)) { |
| 280 DLOG(WARNING) << "Could not retrieve device format(s) in use"; | 257 DLOG(WARNING) << "Could not retrieve device format(s) in use"; |
| 281 } | 258 } |
| 282 callback.Run(formats_in_use); | 259 callback.Run(formats_in_use); |
| 283 } | 260 } |
| 284 | 261 |
| 262 void VideoCaptureHost::DoError(VideoCaptureControllerID controller_id) { |
| 263 DVLOG(1) << __func__; |
| 264 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 265 if (controllers_.find(controller_id) == controllers_.end()) |
| 266 return; |
| 267 |
| 268 if (base::ContainsKey(device_id_to_observer_map_, controller_id)) { |
| 269 device_id_to_observer_map_[controller_id]->OnStateChanged( |
| 270 mojom::VideoCaptureState::FAILED); |
| 271 } |
| 272 |
| 273 DeleteVideoCaptureController(controller_id, true); |
| 274 } |
| 275 |
| 276 void VideoCaptureHost::DoEnded(VideoCaptureControllerID controller_id) { |
| 277 DVLOG(1) << __func__; |
| 278 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 279 if (controllers_.find(controller_id) == controllers_.end()) |
| 280 return; |
| 281 |
| 282 if (base::ContainsKey(device_id_to_observer_map_, controller_id)) { |
| 283 device_id_to_observer_map_[controller_id]->OnStateChanged( |
| 284 mojom::VideoCaptureState::ENDED); |
| 285 } |
| 286 |
| 287 DeleteVideoCaptureController(controller_id, false); |
| 288 } |
| 289 |
| 285 void VideoCaptureHost::OnControllerAdded( | 290 void VideoCaptureHost::OnControllerAdded( |
| 286 int device_id, | 291 int device_id, |
| 287 const base::WeakPtr<VideoCaptureController>& controller) { | 292 const base::WeakPtr<VideoCaptureController>& controller) { |
| 288 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 293 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 289 VideoCaptureControllerID controller_id(device_id); | 294 VideoCaptureControllerID controller_id(device_id); |
| 290 auto it = controllers_.find(controller_id); | 295 auto it = controllers_.find(controller_id); |
| 291 if (it == controllers_.end()) { | 296 if (it == controllers_.end()) { |
| 292 if (controller) { | 297 if (controller) { |
| 293 media_stream_manager_->video_capture_manager()->StopCaptureForClient( | 298 media_stream_manager_->video_capture_manager()->StopCaptureForClient( |
| 294 controller.get(), controller_id, this, false); | 299 controller.get(), controller_id, this, false); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 325 const base::WeakPtr<VideoCaptureController> controller = it->second; | 330 const base::WeakPtr<VideoCaptureController> controller = it->second; |
| 326 controllers_.erase(it); | 331 controllers_.erase(it); |
| 327 if (!controller) | 332 if (!controller) |
| 328 return; | 333 return; |
| 329 | 334 |
| 330 media_stream_manager_->video_capture_manager()->StopCaptureForClient( | 335 media_stream_manager_->video_capture_manager()->StopCaptureForClient( |
| 331 controller.get(), controller_id, this, on_error); | 336 controller.get(), controller_id, this, on_error); |
| 332 } | 337 } |
| 333 | 338 |
| 334 } // namespace content | 339 } // namespace content |
| OLD | NEW |