| 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_controller.h" | 5 #include "content/browser/renderer_host/media/video_capture_controller.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 | 122 |
| 123 private: | 123 private: |
| 124 base::WeakPtr<VideoFrameReceiver> receiver_; | 124 base::WeakPtr<VideoFrameReceiver> receiver_; |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 } // anonymous namespace | 127 } // anonymous namespace |
| 128 | 128 |
| 129 struct VideoCaptureController::ControllerClient { | 129 struct VideoCaptureController::ControllerClient { |
| 130 ControllerClient(VideoCaptureControllerID id, | 130 ControllerClient(VideoCaptureControllerID id, |
| 131 VideoCaptureControllerEventHandler* handler, | 131 VideoCaptureControllerEventHandler* handler, |
| 132 base::ProcessHandle render_process, | |
| 133 media::VideoCaptureSessionId session_id, | 132 media::VideoCaptureSessionId session_id, |
| 134 const media::VideoCaptureParams& params) | 133 const media::VideoCaptureParams& params) |
| 135 : controller_id(id), | 134 : controller_id(id), |
| 136 event_handler(handler), | 135 event_handler(handler), |
| 137 render_process_handle(render_process), | |
| 138 session_id(session_id), | 136 session_id(session_id), |
| 139 parameters(params), | 137 parameters(params), |
| 140 session_closed(false), | 138 session_closed(false), |
| 141 paused(false) {} | 139 paused(false) {} |
| 142 | 140 |
| 143 ~ControllerClient() {} | 141 ~ControllerClient() {} |
| 144 | 142 |
| 145 // ID used for identifying this object. | 143 // ID used for identifying this object. |
| 146 const VideoCaptureControllerID controller_id; | 144 const VideoCaptureControllerID controller_id; |
| 147 VideoCaptureControllerEventHandler* const event_handler; | 145 VideoCaptureControllerEventHandler* const event_handler; |
| 148 | 146 |
| 149 // Handle to the render process that will receive the capture buffers. | |
| 150 const base::ProcessHandle render_process_handle; | |
| 151 const media::VideoCaptureSessionId session_id; | 147 const media::VideoCaptureSessionId session_id; |
| 152 const media::VideoCaptureParams parameters; | 148 const media::VideoCaptureParams parameters; |
| 153 | 149 |
| 154 // Buffers that are currently known to this client. | 150 // Buffers that are currently known to this client. |
| 155 std::set<int> known_buffers; | 151 std::set<int> known_buffers; |
| 156 | 152 |
| 157 // Buffers currently held by this client, and sync token callback to call when | 153 // Buffers currently held by this client, and sync token callback to call when |
| 158 // they are returned from the client. | 154 // they are returned from the client. |
| 159 typedef std::map<int, scoped_refptr<VideoFrame>> ActiveBufferMap; | 155 typedef std::map<int, scoped_refptr<VideoFrame>> ActiveBufferMap; |
| 160 ActiveBufferMap active_buffers; | 156 ActiveBufferMap active_buffers; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 this->GetWeakPtrForIOThread()), | 195 this->GetWeakPtrForIOThread()), |
| 200 buffer_pool_, | 196 buffer_pool_, |
| 201 base::Bind(&CreateGpuJpegDecoder, | 197 base::Bind(&CreateGpuJpegDecoder, |
| 202 base::Bind(&VideoFrameReceiver::OnIncomingCapturedVideoFrame, | 198 base::Bind(&VideoFrameReceiver::OnIncomingCapturedVideoFrame, |
| 203 this->GetWeakPtrForIOThread()))); | 199 this->GetWeakPtrForIOThread()))); |
| 204 } | 200 } |
| 205 | 201 |
| 206 void VideoCaptureController::AddClient( | 202 void VideoCaptureController::AddClient( |
| 207 VideoCaptureControllerID id, | 203 VideoCaptureControllerID id, |
| 208 VideoCaptureControllerEventHandler* event_handler, | 204 VideoCaptureControllerEventHandler* event_handler, |
| 209 base::ProcessHandle render_process, | |
| 210 media::VideoCaptureSessionId session_id, | 205 media::VideoCaptureSessionId session_id, |
| 211 const media::VideoCaptureParams& params) { | 206 const media::VideoCaptureParams& params) { |
| 212 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 207 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 213 DVLOG(1) << "VideoCaptureController::AddClient() -- id=" << id | 208 DVLOG(1) << "VideoCaptureController::AddClient() -- id=" << id |
| 214 << ", session_id=" << session_id | 209 << ", session_id=" << session_id |
| 215 << ", params.requested_format=" | 210 << ", params.requested_format=" |
| 216 << media::VideoCaptureFormat::ToString(params.requested_format); | 211 << media::VideoCaptureFormat::ToString(params.requested_format); |
| 217 | 212 |
| 218 // Check that requested VideoCaptureParams are valid and supported. If not, | 213 // Check that requested VideoCaptureParams are valid and supported. If not, |
| 219 // report an error immediately and punt. | 214 // report an error immediately and punt. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 235 // Signal error in case device is already in error state. | 230 // Signal error in case device is already in error state. |
| 236 if (state_ == VIDEO_CAPTURE_STATE_ERROR) { | 231 if (state_ == VIDEO_CAPTURE_STATE_ERROR) { |
| 237 event_handler->OnError(id); | 232 event_handler->OnError(id); |
| 238 return; | 233 return; |
| 239 } | 234 } |
| 240 | 235 |
| 241 // Do nothing if this client has called AddClient before. | 236 // Do nothing if this client has called AddClient before. |
| 242 if (FindClient(id, event_handler, controller_clients_)) | 237 if (FindClient(id, event_handler, controller_clients_)) |
| 243 return; | 238 return; |
| 244 | 239 |
| 245 std::unique_ptr<ControllerClient> client = base::MakeUnique<ControllerClient>( | 240 std::unique_ptr<ControllerClient> client = |
| 246 id, event_handler, render_process, session_id, params); | 241 base::MakeUnique<ControllerClient>(id, event_handler, session_id, params); |
| 247 // If we already have gotten frame_info from the device, repeat it to the new | 242 // If we already have gotten frame_info from the device, repeat it to the new |
| 248 // client. | 243 // client. |
| 249 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { | 244 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { |
| 250 controller_clients_.push_back(std::move(client)); | 245 controller_clients_.push_back(std::move(client)); |
| 251 return; | 246 return; |
| 252 } | 247 } |
| 253 } | 248 } |
| 254 | 249 |
| 255 int VideoCaptureController::RemoveClient( | 250 int VideoCaptureController::RemoveClient( |
| 256 VideoCaptureControllerID id, | 251 VideoCaptureControllerID id, |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 buffer_id_to_drop); | 496 buffer_id_to_drop); |
| 502 } | 497 } |
| 503 } | 498 } |
| 504 } | 499 } |
| 505 | 500 |
| 506 void VideoCaptureController::DoNewBufferOnIOThread( | 501 void VideoCaptureController::DoNewBufferOnIOThread( |
| 507 ControllerClient* client, | 502 ControllerClient* client, |
| 508 media::VideoCaptureDevice::Client::Buffer* buffer, | 503 media::VideoCaptureDevice::Client::Buffer* buffer, |
| 509 const scoped_refptr<media::VideoFrame>& frame) { | 504 const scoped_refptr<media::VideoFrame>& frame) { |
| 510 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 505 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 511 const int buffer_id = buffer->id(); | |
| 512 | |
| 513 DCHECK_EQ(media::VideoFrame::STORAGE_SHMEM, frame->storage_type()); | 506 DCHECK_EQ(media::VideoFrame::STORAGE_SHMEM, frame->storage_type()); |
| 514 | 507 |
| 515 base::SharedMemoryHandle remote_handle; | 508 const int buffer_id = buffer->id(); |
| 516 buffer_pool_->ShareToProcess(buffer_id, client->render_process_handle, | 509 mojo::ScopedSharedBufferHandle handle = |
| 517 &remote_handle); | 510 buffer_pool_->GetHandleForTransit(buffer_id); |
| 518 client->event_handler->OnBufferCreated(client->controller_id, remote_handle, | 511 client->event_handler->OnBufferCreated(client->controller_id, |
| 512 std::move(handle), |
| 519 buffer->mapped_size(), buffer_id); | 513 buffer->mapped_size(), buffer_id); |
| 520 } | 514 } |
| 521 | 515 |
| 522 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( | 516 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( |
| 523 VideoCaptureControllerID id, | 517 VideoCaptureControllerID id, |
| 524 VideoCaptureControllerEventHandler* handler, | 518 VideoCaptureControllerEventHandler* handler, |
| 525 const ControllerClients& clients) { | 519 const ControllerClients& clients) { |
| 526 for (const auto& client : clients) { | 520 for (const auto& client : clients) { |
| 527 if (client->controller_id == id && client->event_handler == handler) | 521 if (client->controller_id == id && client->event_handler == handler) |
| 528 return client.get(); | 522 return client.get(); |
| 529 } | 523 } |
| 530 return nullptr; | 524 return nullptr; |
| 531 } | 525 } |
| 532 | 526 |
| 533 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( | 527 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( |
| 534 int session_id, | 528 int session_id, |
| 535 const ControllerClients& clients) { | 529 const ControllerClients& clients) { |
| 536 for (const auto& client : clients) { | 530 for (const auto& client : clients) { |
| 537 if (client->session_id == session_id) | 531 if (client->session_id == session_id) |
| 538 return client.get(); | 532 return client.get(); |
| 539 } | 533 } |
| 540 return nullptr; | 534 return nullptr; |
| 541 } | 535 } |
| 542 | 536 |
| 543 } // namespace content | 537 } // namespace content |
| OLD | NEW |