| 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 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 | 17 |
| 18 VideoCaptureHost::VideoCaptureHost(MediaStreamManager* media_stream_manager) | 18 VideoCaptureHost::VideoCaptureHost(MediaStreamManager* media_stream_manager) |
| 19 : BrowserMessageFilter(VideoCaptureMsgStart), | 19 : BrowserMessageFilter(VideoCaptureMsgStart), |
| 20 BrowserAssociatedInterface(this, this), |
| 20 media_stream_manager_(media_stream_manager) { | 21 media_stream_manager_(media_stream_manager) { |
| 21 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 22 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 22 } | 23 } |
| 23 | 24 |
| 24 VideoCaptureHost::~VideoCaptureHost() {} | 25 VideoCaptureHost::~VideoCaptureHost() {} |
| 25 | 26 |
| 26 void VideoCaptureHost::OnChannelClosing() { | 27 void VideoCaptureHost::OnChannelClosing() { |
| 27 // Since the IPC sender is gone, close all requested VideoCaptureDevices. | 28 // Since the IPC sender is gone, close all requested VideoCaptureDevices. |
| 28 for (EntryMap::iterator it = entries_.begin(); it != entries_.end(); ) { | 29 for (auto it = controllers_.begin(); it != controllers_.end(); ) { |
| 29 const base::WeakPtr<VideoCaptureController>& controller = it->second; | 30 const base::WeakPtr<VideoCaptureController>& controller = it->second; |
| 30 if (controller) { | 31 if (controller) { |
| 31 const VideoCaptureControllerID controller_id(it->first); | 32 const VideoCaptureControllerID controller_id(it->first); |
| 32 media_stream_manager_->video_capture_manager()->StopCaptureForClient( | 33 media_stream_manager_->video_capture_manager()->StopCaptureForClient( |
| 33 controller.get(), controller_id, this, false); | 34 controller.get(), controller_id, this, false); |
| 34 ++it; | 35 ++it; |
| 35 } else { | 36 } else { |
| 36 // Remove the entry for this controller_id so that when the controller | 37 // Remove the entry for this controller_id so that when the controller |
| 37 // is added, the controller will be notified to stop for this client | 38 // is added, the controller will be notified to stop for this client |
| 38 // in DoControllerAdded. | 39 // in DoControllerAdded. |
| 39 entries_.erase(it++); | 40 controllers_.erase(it++); |
| 40 } | 41 } |
| 41 } | 42 } |
| 42 } | 43 } |
| 43 | 44 |
| 44 void VideoCaptureHost::OnDestruct() const { | 45 void VideoCaptureHost::OnDestruct() const { |
| 45 BrowserThread::DeleteOnIOThread::Destruct(this); | 46 BrowserThread::DeleteOnIOThread::Destruct(this); |
| 46 } | 47 } |
| 47 | 48 |
| 48 /////////////////////////////////////////////////////////////////////////////// | |
| 49 | |
| 50 // Implements VideoCaptureControllerEventHandler. | |
| 51 void VideoCaptureHost::OnError(VideoCaptureControllerID controller_id) { | 49 void VideoCaptureHost::OnError(VideoCaptureControllerID controller_id) { |
| 52 DVLOG(1) << "VideoCaptureHost::OnError"; | 50 DVLOG(1) << "VideoCaptureHost::OnError"; |
| 53 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 51 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 54 BrowserThread::PostTask( | 52 BrowserThread::PostTask( |
| 55 BrowserThread::IO, FROM_HERE, | 53 BrowserThread::IO, FROM_HERE, |
| 56 base::Bind(&VideoCaptureHost::DoError, this, controller_id)); | 54 base::Bind(&VideoCaptureHost::DoError, this, controller_id)); |
| 57 } | 55 } |
| 58 | 56 |
| 59 void VideoCaptureHost::OnBufferCreated(VideoCaptureControllerID controller_id, | 57 void VideoCaptureHost::OnBufferCreated(VideoCaptureControllerID controller_id, |
| 60 base::SharedMemoryHandle handle, | 58 base::SharedMemoryHandle handle, |
| 61 int length, | 59 int length, |
| 62 int buffer_id) { | 60 int buffer_id) { |
| 63 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 61 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 64 if (entries_.find(controller_id) == entries_.end()) | 62 if (controllers_.find(controller_id) == controllers_.end()) |
| 65 return; | 63 return; |
| 66 | 64 |
| 67 Send(new VideoCaptureMsg_NewBuffer(controller_id, handle, length, buffer_id)); | 65 Send(new VideoCaptureMsg_NewBuffer(controller_id, handle, length, buffer_id)); |
| 68 } | 66 } |
| 69 | 67 |
| 70 void VideoCaptureHost::OnBufferCreated2( | 68 void VideoCaptureHost::OnBufferCreated2( |
| 71 VideoCaptureControllerID controller_id, | 69 VideoCaptureControllerID controller_id, |
| 72 const std::vector<gfx::GpuMemoryBufferHandle>& handles, | 70 const std::vector<gfx::GpuMemoryBufferHandle>& handles, |
| 73 const gfx::Size& size, | 71 const gfx::Size& size, |
| 74 int buffer_id) { | 72 int buffer_id) { |
| 75 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 73 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 76 if (entries_.find(controller_id) == entries_.end()) | 74 if (controllers_.find(controller_id) == controllers_.end()) |
| 77 return; | 75 return; |
| 78 | 76 |
| 79 Send(new VideoCaptureMsg_NewBuffer2(controller_id, handles, size, buffer_id)); | 77 Send(new VideoCaptureMsg_NewBuffer2(controller_id, handles, size, buffer_id)); |
| 80 } | 78 } |
| 81 | 79 |
| 82 void VideoCaptureHost::OnBufferDestroyed(VideoCaptureControllerID controller_id, | 80 void VideoCaptureHost::OnBufferDestroyed(VideoCaptureControllerID controller_id, |
| 83 int buffer_id) { | 81 int buffer_id) { |
| 84 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 82 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 85 if (entries_.find(controller_id) == entries_.end()) | 83 if (controllers_.find(controller_id) == controllers_.end()) |
| 86 return; | 84 return; |
| 87 | 85 |
| 88 Send(new VideoCaptureMsg_FreeBuffer(controller_id, buffer_id)); | 86 Send(new VideoCaptureMsg_FreeBuffer(controller_id, buffer_id)); |
| 89 } | 87 } |
| 90 | 88 |
| 91 void VideoCaptureHost::OnBufferReady( | 89 void VideoCaptureHost::OnBufferReady( |
| 92 VideoCaptureControllerID controller_id, | 90 VideoCaptureControllerID controller_id, |
| 93 int buffer_id, | 91 int buffer_id, |
| 94 const scoped_refptr<media::VideoFrame>& video_frame) { | 92 const scoped_refptr<media::VideoFrame>& video_frame) { |
| 95 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 93 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 96 if (entries_.find(controller_id) == entries_.end()) | 94 if (controllers_.find(controller_id) == controllers_.end()) |
| 97 return; | 95 return; |
| 98 | 96 |
| 99 VideoCaptureMsg_BufferReady_Params params; | 97 VideoCaptureMsg_BufferReady_Params params; |
| 100 params.device_id = controller_id; | 98 params.device_id = controller_id; |
| 101 params.buffer_id = buffer_id; | 99 params.buffer_id = buffer_id; |
| 102 params.timestamp = video_frame->timestamp(); | 100 params.timestamp = video_frame->timestamp(); |
| 103 video_frame->metadata()->MergeInternalValuesInto(¶ms.metadata); | 101 video_frame->metadata()->MergeInternalValuesInto(¶ms.metadata); |
| 104 params.pixel_format = video_frame->format(); | 102 params.pixel_format = video_frame->format(); |
| 105 params.storage_type = video_frame->storage_type(); | 103 params.storage_type = video_frame->storage_type(); |
| 106 params.coded_size = video_frame->coded_size(); | 104 params.coded_size = video_frame->coded_size(); |
| 107 params.visible_rect = video_frame->visible_rect(); | 105 params.visible_rect = video_frame->visible_rect(); |
| 108 | 106 |
| 109 Send(new VideoCaptureMsg_BufferReady(params)); | 107 Send(new VideoCaptureMsg_BufferReady(params)); |
| 110 } | 108 } |
| 111 | 109 |
| 112 void VideoCaptureHost::OnEnded(VideoCaptureControllerID controller_id) { | 110 void VideoCaptureHost::OnEnded(VideoCaptureControllerID controller_id) { |
| 113 DVLOG(1) << "VideoCaptureHost::OnEnded"; | 111 DVLOG(1) << "VideoCaptureHost::OnEnded"; |
| 114 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 112 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 115 BrowserThread::PostTask( | 113 BrowserThread::PostTask( |
| 116 BrowserThread::IO, FROM_HERE, | 114 BrowserThread::IO, FROM_HERE, |
| 117 base::Bind(&VideoCaptureHost::DoEnded, this, controller_id)); | 115 base::Bind(&VideoCaptureHost::DoEnded, this, controller_id)); |
| 118 } | 116 } |
| 119 | 117 |
| 120 void VideoCaptureHost::DoError(VideoCaptureControllerID controller_id) { | 118 void VideoCaptureHost::DoError(VideoCaptureControllerID controller_id) { |
| 121 DVLOG(1) << "VideoCaptureHost::DoError"; | 119 DVLOG(1) << "VideoCaptureHost::DoError"; |
| 122 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 120 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 123 if (entries_.find(controller_id) == entries_.end()) | 121 if (controllers_.find(controller_id) == controllers_.end()) |
| 124 return; | 122 return; |
| 125 | 123 |
| 126 Send(new VideoCaptureMsg_StateChanged(controller_id, | 124 Send(new VideoCaptureMsg_StateChanged(controller_id, |
| 127 VIDEO_CAPTURE_STATE_ERROR)); | 125 VIDEO_CAPTURE_STATE_ERROR)); |
| 128 DeleteVideoCaptureController(controller_id, true); | 126 DeleteVideoCaptureController(controller_id, true); |
| 129 } | 127 } |
| 130 | 128 |
| 131 void VideoCaptureHost::DoEnded(VideoCaptureControllerID controller_id) { | 129 void VideoCaptureHost::DoEnded(VideoCaptureControllerID controller_id) { |
| 132 DVLOG(1) << "VideoCaptureHost::DoEnded"; | 130 DVLOG(1) << "VideoCaptureHost::DoEnded"; |
| 133 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 131 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 134 if (entries_.find(controller_id) == entries_.end()) | 132 if (controllers_.find(controller_id) == controllers_.end()) |
| 135 return; | 133 return; |
| 136 | 134 |
| 137 Send(new VideoCaptureMsg_StateChanged(controller_id, | 135 Send(new VideoCaptureMsg_StateChanged(controller_id, |
| 138 VIDEO_CAPTURE_STATE_ENDED)); | 136 VIDEO_CAPTURE_STATE_ENDED)); |
| 139 DeleteVideoCaptureController(controller_id, false); | 137 DeleteVideoCaptureController(controller_id, false); |
| 140 } | 138 } |
| 141 | 139 |
| 142 /////////////////////////////////////////////////////////////////////////////// | 140 /////////////////////////////////////////////////////////////////////////////// |
| 143 // IPC Messages handler. | 141 // IPC Messages handler. |
| 144 bool VideoCaptureHost::OnMessageReceived(const IPC::Message& message) { | 142 bool VideoCaptureHost::OnMessageReceived(const IPC::Message& message) { |
| 145 bool handled = true; | 143 bool handled = true; |
| 146 IPC_BEGIN_MESSAGE_MAP(VideoCaptureHost, message) | 144 IPC_BEGIN_MESSAGE_MAP(VideoCaptureHost, message) |
| 147 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Start, OnStartCapture) | 145 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Start, OnStartCapture) |
| 148 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Pause, OnPauseCapture) | |
| 149 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Resume, OnResumeCapture) | 146 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Resume, OnResumeCapture) |
| 150 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_RequestRefreshFrame, | |
| 151 OnRequestRefreshFrame) | |
| 152 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Stop, OnStopCapture) | |
| 153 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_BufferReady, | 147 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_BufferReady, |
| 154 OnRendererFinishedWithBuffer) | 148 OnRendererFinishedWithBuffer) |
| 155 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_GetDeviceSupportedFormats, | 149 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_GetDeviceSupportedFormats, |
| 156 OnGetDeviceSupportedFormats) | 150 OnGetDeviceSupportedFormats) |
| 157 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_GetDeviceFormatsInUse, | 151 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_GetDeviceFormatsInUse, |
| 158 OnGetDeviceFormatsInUse) | 152 OnGetDeviceFormatsInUse) |
| 159 IPC_MESSAGE_UNHANDLED(handled = false) | 153 IPC_MESSAGE_UNHANDLED(handled = false) |
| 160 IPC_END_MESSAGE_MAP() | 154 IPC_END_MESSAGE_MAP() |
| 161 | 155 |
| 162 return handled; | 156 return handled; |
| 163 } | 157 } |
| 164 | 158 |
| 165 void VideoCaptureHost::OnStartCapture(int device_id, | 159 void VideoCaptureHost::OnStartCapture(int device_id, |
| 166 media::VideoCaptureSessionId session_id, | 160 media::VideoCaptureSessionId session_id, |
| 167 const media::VideoCaptureParams& params) { | 161 const media::VideoCaptureParams& params) { |
| 168 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 162 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 169 DVLOG(1) << "VideoCaptureHost::OnStartCapture:" | 163 DVLOG(1) << "VideoCaptureHost::OnStartCapture:" |
| 170 << " session_id=" << session_id << ", device_id=" << device_id | 164 << " session_id=" << session_id << ", device_id=" << device_id |
| 171 << ", format=" | 165 << ", format=" |
| 172 << media::VideoCaptureFormat::ToString(params.requested_format) | 166 << media::VideoCaptureFormat::ToString(params.requested_format) |
| 173 << "@" << params.requested_format.frame_rate << " (" | 167 << "@" << params.requested_format.frame_rate << " (" |
| 174 << (params.resolution_change_policy == | 168 << (params.resolution_change_policy == |
| 175 media::RESOLUTION_POLICY_FIXED_RESOLUTION | 169 media::RESOLUTION_POLICY_FIXED_RESOLUTION |
| 176 ? "fixed resolution" | 170 ? "fixed resolution" |
| 177 : (params.resolution_change_policy == | 171 : (params.resolution_change_policy == |
| 178 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO | 172 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO |
| 179 ? "fixed aspect ratio" | 173 ? "fixed aspect ratio" |
| 180 : "variable resolution")) << ")"; | 174 : "variable resolution")) << ")"; |
| 181 VideoCaptureControllerID controller_id(device_id); | 175 VideoCaptureControllerID controller_id(device_id); |
| 182 if (entries_.find(controller_id) != entries_.end()) { | 176 if (controllers_.find(controller_id) != controllers_.end()) { |
| 183 Send(new VideoCaptureMsg_StateChanged(device_id, | 177 Send(new VideoCaptureMsg_StateChanged(device_id, |
| 184 VIDEO_CAPTURE_STATE_ERROR)); | 178 VIDEO_CAPTURE_STATE_ERROR)); |
| 185 return; | 179 return; |
| 186 } | 180 } |
| 187 | 181 |
| 188 entries_[controller_id] = base::WeakPtr<VideoCaptureController>(); | 182 controllers_[controller_id] = base::WeakPtr<VideoCaptureController>(); |
| 189 media_stream_manager_->video_capture_manager()->StartCaptureForClient( | 183 media_stream_manager_->video_capture_manager()->StartCaptureForClient( |
| 190 session_id, | 184 session_id, |
| 191 params, | 185 params, |
| 192 PeerHandle(), | 186 PeerHandle(), |
| 193 controller_id, | 187 controller_id, |
| 194 this, | 188 this, |
| 195 base::Bind(&VideoCaptureHost::OnControllerAdded, this, device_id)); | 189 base::Bind(&VideoCaptureHost::OnControllerAdded, this, device_id)); |
| 196 } | 190 } |
| 197 | 191 |
| 198 void VideoCaptureHost::OnControllerAdded( | |
| 199 int device_id, | |
| 200 const base::WeakPtr<VideoCaptureController>& controller) { | |
| 201 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 202 VideoCaptureControllerID controller_id(device_id); | |
| 203 EntryMap::iterator it = entries_.find(controller_id); | |
| 204 if (it == entries_.end()) { | |
| 205 if (controller) { | |
| 206 media_stream_manager_->video_capture_manager()->StopCaptureForClient( | |
| 207 controller.get(), controller_id, this, false); | |
| 208 } | |
| 209 return; | |
| 210 } | |
| 211 | |
| 212 if (!controller) { | |
| 213 Send(new VideoCaptureMsg_StateChanged(device_id, | |
| 214 VIDEO_CAPTURE_STATE_ERROR)); | |
| 215 entries_.erase(controller_id); | |
| 216 return; | |
| 217 } | |
| 218 | |
| 219 DCHECK(!it->second); | |
| 220 it->second = controller; | |
| 221 } | |
| 222 | |
| 223 void VideoCaptureHost::OnStopCapture(int device_id) { | |
| 224 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 225 DVLOG(1) << "VideoCaptureHost::OnStopCapture, device_id " << device_id; | |
| 226 | |
| 227 VideoCaptureControllerID controller_id(device_id); | |
| 228 | |
| 229 Send(new VideoCaptureMsg_StateChanged(device_id, | |
| 230 VIDEO_CAPTURE_STATE_STOPPED)); | |
| 231 DeleteVideoCaptureController(controller_id, false); | |
| 232 } | |
| 233 | |
| 234 void VideoCaptureHost::OnPauseCapture(int device_id) { | |
| 235 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 236 DVLOG(1) << "VideoCaptureHost::OnPauseCapture, device_id " << device_id; | |
| 237 | |
| 238 VideoCaptureControllerID controller_id(device_id); | |
| 239 EntryMap::iterator it = entries_.find(controller_id); | |
| 240 if (it == entries_.end() || !it->second) | |
| 241 return; | |
| 242 | |
| 243 media_stream_manager_->video_capture_manager()->PauseCaptureForClient( | |
| 244 it->second.get(), controller_id, this); | |
| 245 Send(new VideoCaptureMsg_StateChanged(device_id, VIDEO_CAPTURE_STATE_PAUSED)); | |
| 246 } | |
| 247 | |
| 248 void VideoCaptureHost::OnResumeCapture( | 192 void VideoCaptureHost::OnResumeCapture( |
| 249 int device_id, | 193 int device_id, |
| 250 media::VideoCaptureSessionId session_id, | 194 media::VideoCaptureSessionId session_id, |
| 251 const media::VideoCaptureParams& params) { | 195 const media::VideoCaptureParams& params) { |
| 196 DVLOG(1) << __func__ << " " << device_id; |
| 252 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 197 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 253 DVLOG(1) << "VideoCaptureHost::OnResumeCapture, device_id " << device_id; | |
| 254 | 198 |
| 255 VideoCaptureControllerID controller_id(device_id); | 199 VideoCaptureControllerID controller_id(device_id); |
| 256 EntryMap::iterator it = entries_.find(controller_id); | 200 auto it = controllers_.find(controller_id); |
| 257 if (it == entries_.end() || !it->second) | 201 if (it == controllers_.end() || !it->second) |
| 258 return; | 202 return; |
| 259 | 203 |
| 260 media_stream_manager_->video_capture_manager()->ResumeCaptureForClient( | 204 media_stream_manager_->video_capture_manager()->ResumeCaptureForClient( |
| 261 session_id, params, it->second.get(), controller_id, this); | 205 session_id, params, it->second.get(), controller_id, this); |
| 262 Send(new VideoCaptureMsg_StateChanged(device_id, | 206 Send(new VideoCaptureMsg_StateChanged(device_id, |
| 263 VIDEO_CAPTURE_STATE_RESUMED)); | 207 VIDEO_CAPTURE_STATE_RESUMED)); |
| 264 } | 208 } |
| 265 | 209 |
| 266 void VideoCaptureHost::OnRequestRefreshFrame(int device_id) { | |
| 267 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 268 DVLOG(1) << "VideoCaptureHost::OnRequestRefreshFrame, device_id " | |
| 269 << device_id; | |
| 270 | |
| 271 VideoCaptureControllerID controller_id(device_id); | |
| 272 EntryMap::iterator it = entries_.find(controller_id); | |
| 273 if (it == entries_.end()) | |
| 274 return; | |
| 275 | |
| 276 if (VideoCaptureController* controller = it->second.get()) { | |
| 277 media_stream_manager_->video_capture_manager() | |
| 278 ->RequestRefreshFrameForClient(controller); | |
| 279 } | |
| 280 } | |
| 281 | |
| 282 void VideoCaptureHost::OnRendererFinishedWithBuffer( | 210 void VideoCaptureHost::OnRendererFinishedWithBuffer( |
| 283 int device_id, | 211 int device_id, |
| 284 int buffer_id, | 212 int buffer_id, |
| 285 const gpu::SyncToken& sync_token, | 213 const gpu::SyncToken& sync_token, |
| 286 double consumer_resource_utilization) { | 214 double consumer_resource_utilization) { |
| 287 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 215 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 288 | 216 |
| 289 VideoCaptureControllerID controller_id(device_id); | 217 VideoCaptureControllerID controller_id(device_id); |
| 290 EntryMap::iterator it = entries_.find(controller_id); | 218 auto it = controllers_.find(controller_id); |
| 291 if (it != entries_.end()) { | 219 if (it != controllers_.end()) { |
| 292 const base::WeakPtr<VideoCaptureController>& controller = it->second; | 220 const base::WeakPtr<VideoCaptureController>& controller = it->second; |
| 293 if (controller) { | 221 if (controller) { |
| 294 controller->ReturnBuffer(controller_id, this, buffer_id, sync_token, | 222 controller->ReturnBuffer(controller_id, this, buffer_id, sync_token, |
| 295 consumer_resource_utilization); | 223 consumer_resource_utilization); |
| 296 } | 224 } |
| 297 } | 225 } |
| 298 } | 226 } |
| 299 | 227 |
| 300 void VideoCaptureHost::OnGetDeviceSupportedFormats( | 228 void VideoCaptureHost::OnGetDeviceSupportedFormats( |
| 301 int device_id, | 229 int device_id, |
| 302 media::VideoCaptureSessionId capture_session_id) { | 230 media::VideoCaptureSessionId session_id) { |
| 231 DVLOG(1) << __func__ << " " << device_id; |
| 303 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 232 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 304 DVLOG(1) << "VideoCaptureHost::OnGetDeviceFormats, capture_session_id " | |
| 305 << capture_session_id; | |
| 306 media::VideoCaptureFormats device_supported_formats; | 233 media::VideoCaptureFormats device_supported_formats; |
| 307 if (!media_stream_manager_->video_capture_manager() | 234 if (!media_stream_manager_->video_capture_manager() |
| 308 ->GetDeviceSupportedFormats(capture_session_id, | 235 ->GetDeviceSupportedFormats(session_id, |
| 309 &device_supported_formats)) { | 236 &device_supported_formats)) { |
| 310 DLOG(WARNING) | 237 DLOG(WARNING) |
| 311 << "Could not retrieve device supported formats for device_id=" | 238 << "Could not retrieve device supported formats for device_id=" |
| 312 << device_id << " capture_session_id=" << capture_session_id; | 239 << device_id << " session_id=" << session_id; |
| 313 } | 240 } |
| 314 Send(new VideoCaptureMsg_DeviceSupportedFormatsEnumerated( | 241 Send(new VideoCaptureMsg_DeviceSupportedFormatsEnumerated( |
| 315 device_id, device_supported_formats)); | 242 device_id, device_supported_formats)); |
| 316 } | 243 } |
| 317 | 244 |
| 318 void VideoCaptureHost::OnGetDeviceFormatsInUse( | 245 void VideoCaptureHost::OnGetDeviceFormatsInUse( |
| 319 int device_id, | 246 int device_id, |
| 320 media::VideoCaptureSessionId capture_session_id) { | 247 media::VideoCaptureSessionId session_id) { |
| 248 DVLOG(1) << __func__ << " " << device_id; |
| 321 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 249 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 322 DVLOG(1) << "VideoCaptureHost::OnGetDeviceFormatsInUse, capture_session_id " | |
| 323 << capture_session_id; | |
| 324 media::VideoCaptureFormats formats_in_use; | 250 media::VideoCaptureFormats formats_in_use; |
| 325 if (!media_stream_manager_->video_capture_manager()->GetDeviceFormatsInUse( | 251 if (!media_stream_manager_->video_capture_manager()->GetDeviceFormatsInUse( |
| 326 capture_session_id, &formats_in_use)) { | 252 session_id, &formats_in_use)) { |
| 327 DVLOG(1) << "Could not retrieve device format(s) in use for device_id=" | 253 DVLOG(1) << "Could not retrieve device format(s) in use for device_id=" |
| 328 << device_id << " capture_session_id=" << capture_session_id; | 254 << device_id << " session_id=" << session_id; |
| 329 } | 255 } |
| 330 Send(new VideoCaptureMsg_DeviceFormatsInUseReceived(device_id, | 256 Send(new VideoCaptureMsg_DeviceFormatsInUseReceived(device_id, |
| 331 formats_in_use)); | 257 formats_in_use)); |
| 332 } | 258 } |
| 333 | 259 |
| 260 void VideoCaptureHost::Stop(int32_t device_id) { |
| 261 DVLOG(1) << __func__ << " " << device_id; |
| 262 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 263 |
| 264 VideoCaptureControllerID controller_id(device_id); |
| 265 |
| 266 Send(new VideoCaptureMsg_StateChanged(device_id, |
| 267 VIDEO_CAPTURE_STATE_STOPPED)); |
| 268 DeleteVideoCaptureController(controller_id, false); |
| 269 } |
| 270 |
| 271 void VideoCaptureHost::Pause(int32_t device_id) { |
| 272 DVLOG(1) << __func__ << " " << device_id; |
| 273 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 274 |
| 275 VideoCaptureControllerID controller_id(device_id); |
| 276 auto it = controllers_.find(controller_id); |
| 277 if (it == controllers_.end() || !it->second) |
| 278 return; |
| 279 |
| 280 media_stream_manager_->video_capture_manager()->PauseCaptureForClient( |
| 281 it->second.get(), controller_id, this); |
| 282 Send(new VideoCaptureMsg_StateChanged(device_id, VIDEO_CAPTURE_STATE_PAUSED)); |
| 283 } |
| 284 |
| 285 void VideoCaptureHost::RequestRefreshFrame(int32_t device_id) { |
| 286 DVLOG(1) << __func__ << " " << device_id; |
| 287 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 288 |
| 289 VideoCaptureControllerID controller_id(device_id); |
| 290 auto it = controllers_.find(controller_id); |
| 291 if (it == controllers_.end()) |
| 292 return; |
| 293 |
| 294 if (VideoCaptureController* controller = it->second.get()) { |
| 295 media_stream_manager_->video_capture_manager() |
| 296 ->RequestRefreshFrameForClient(controller); |
| 297 } |
| 298 } |
| 299 |
| 300 void VideoCaptureHost::OnControllerAdded( |
| 301 int device_id, |
| 302 const base::WeakPtr<VideoCaptureController>& controller) { |
| 303 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 304 VideoCaptureControllerID controller_id(device_id); |
| 305 auto it = controllers_.find(controller_id); |
| 306 if (it == controllers_.end()) { |
| 307 if (controller) { |
| 308 media_stream_manager_->video_capture_manager()->StopCaptureForClient( |
| 309 controller.get(), controller_id, this, false); |
| 310 } |
| 311 return; |
| 312 } |
| 313 |
| 314 if (!controller) { |
| 315 Send(new VideoCaptureMsg_StateChanged(device_id, |
| 316 VIDEO_CAPTURE_STATE_ERROR)); |
| 317 controllers_.erase(controller_id); |
| 318 return; |
| 319 } |
| 320 |
| 321 DCHECK(!it->second); |
| 322 it->second = controller; |
| 323 } |
| 324 |
| 334 void VideoCaptureHost::DeleteVideoCaptureController( | 325 void VideoCaptureHost::DeleteVideoCaptureController( |
| 335 VideoCaptureControllerID controller_id, bool on_error) { | 326 VideoCaptureControllerID controller_id, bool on_error) { |
| 336 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 327 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 337 | 328 |
| 338 EntryMap::iterator it = entries_.find(controller_id); | 329 auto it = controllers_.find(controller_id); |
| 339 if (it == entries_.end()) | 330 if (it == controllers_.end()) |
| 340 return; | 331 return; |
| 341 | 332 |
| 342 if (it->second) { | 333 if (it->second) { |
| 343 media_stream_manager_->video_capture_manager()->StopCaptureForClient( | 334 media_stream_manager_->video_capture_manager()->StopCaptureForClient( |
| 344 it->second.get(), controller_id, this, on_error); | 335 it->second.get(), controller_id, this, on_error); |
| 345 } | 336 } |
| 346 entries_.erase(it); | 337 controllers_.erase(it); |
| 347 } | 338 } |
| 348 | 339 |
| 349 } // namespace content | 340 } // namespace content |
| OLD | NEW |