| 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 <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 new VideoCaptureDeviceClient(this->GetWeakPtr(), buffer_pool_)); | 171 new VideoCaptureDeviceClient(this->GetWeakPtr(), buffer_pool_)); |
| 172 return result.Pass(); | 172 return result.Pass(); |
| 173 } | 173 } |
| 174 | 174 |
| 175 void VideoCaptureController::AddClient( | 175 void VideoCaptureController::AddClient( |
| 176 const VideoCaptureControllerID& id, | 176 const VideoCaptureControllerID& id, |
| 177 VideoCaptureControllerEventHandler* event_handler, | 177 VideoCaptureControllerEventHandler* event_handler, |
| 178 base::ProcessHandle render_process, | 178 base::ProcessHandle render_process, |
| 179 media::VideoCaptureSessionId session_id, | 179 media::VideoCaptureSessionId session_id, |
| 180 const media::VideoCaptureParams& params) { | 180 const media::VideoCaptureParams& params) { |
| 181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 181 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 182 DVLOG(1) << "VideoCaptureController::AddClient, id " << id.device_id | 182 DVLOG(1) << "VideoCaptureController::AddClient, id " << id.device_id |
| 183 << ", " << params.requested_format.frame_size.ToString() | 183 << ", " << params.requested_format.frame_size.ToString() |
| 184 << ", " << params.requested_format.frame_rate | 184 << ", " << params.requested_format.frame_rate |
| 185 << ", " << session_id | 185 << ", " << session_id |
| 186 << ")"; | 186 << ")"; |
| 187 | 187 |
| 188 // If this is the first client added to the controller, cache the parameters. | 188 // If this is the first client added to the controller, cache the parameters. |
| 189 if (!controller_clients_.size()) | 189 if (!controller_clients_.size()) |
| 190 video_capture_format_ = params.requested_format; | 190 video_capture_format_ = params.requested_format; |
| 191 | 191 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 205 // client. | 205 // client. |
| 206 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { | 206 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { |
| 207 controller_clients_.push_back(client); | 207 controller_clients_.push_back(client); |
| 208 return; | 208 return; |
| 209 } | 209 } |
| 210 } | 210 } |
| 211 | 211 |
| 212 int VideoCaptureController::RemoveClient( | 212 int VideoCaptureController::RemoveClient( |
| 213 const VideoCaptureControllerID& id, | 213 const VideoCaptureControllerID& id, |
| 214 VideoCaptureControllerEventHandler* event_handler) { | 214 VideoCaptureControllerEventHandler* event_handler) { |
| 215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 215 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 216 DVLOG(1) << "VideoCaptureController::RemoveClient, id " << id.device_id; | 216 DVLOG(1) << "VideoCaptureController::RemoveClient, id " << id.device_id; |
| 217 | 217 |
| 218 ControllerClient* client = FindClient(id, event_handler, controller_clients_); | 218 ControllerClient* client = FindClient(id, event_handler, controller_clients_); |
| 219 if (!client) | 219 if (!client) |
| 220 return kInvalidMediaCaptureSessionId; | 220 return kInvalidMediaCaptureSessionId; |
| 221 | 221 |
| 222 // Take back all buffers held by the |client|. | 222 // Take back all buffers held by the |client|. |
| 223 for (ControllerClient::ActiveBufferMap::iterator buffer_it = | 223 for (ControllerClient::ActiveBufferMap::iterator buffer_it = |
| 224 client->active_buffers.begin(); | 224 client->active_buffers.begin(); |
| 225 buffer_it != client->active_buffers.end(); | 225 buffer_it != client->active_buffers.end(); |
| 226 ++buffer_it) { | 226 ++buffer_it) { |
| 227 buffer_pool_->RelinquishConsumerHold(buffer_it->first, 1); | 227 buffer_pool_->RelinquishConsumerHold(buffer_it->first, 1); |
| 228 } | 228 } |
| 229 client->active_buffers.clear(); | 229 client->active_buffers.clear(); |
| 230 | 230 |
| 231 int session_id = client->session_id; | 231 int session_id = client->session_id; |
| 232 controller_clients_.remove(client); | 232 controller_clients_.remove(client); |
| 233 delete client; | 233 delete client; |
| 234 | 234 |
| 235 return session_id; | 235 return session_id; |
| 236 } | 236 } |
| 237 | 237 |
| 238 void VideoCaptureController::StopSession(int session_id) { | 238 void VideoCaptureController::StopSession(int session_id) { |
| 239 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 239 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 240 DVLOG(1) << "VideoCaptureController::StopSession, id " << session_id; | 240 DVLOG(1) << "VideoCaptureController::StopSession, id " << session_id; |
| 241 | 241 |
| 242 ControllerClient* client = FindClient(session_id, controller_clients_); | 242 ControllerClient* client = FindClient(session_id, controller_clients_); |
| 243 | 243 |
| 244 if (client) { | 244 if (client) { |
| 245 client->session_closed = true; | 245 client->session_closed = true; |
| 246 client->event_handler->OnEnded(client->controller_id); | 246 client->event_handler->OnEnded(client->controller_id); |
| 247 } | 247 } |
| 248 } | 248 } |
| 249 | 249 |
| 250 void VideoCaptureController::ReturnBuffer( | 250 void VideoCaptureController::ReturnBuffer( |
| 251 const VideoCaptureControllerID& id, | 251 const VideoCaptureControllerID& id, |
| 252 VideoCaptureControllerEventHandler* event_handler, | 252 VideoCaptureControllerEventHandler* event_handler, |
| 253 int buffer_id, | 253 int buffer_id, |
| 254 uint32 sync_point) { | 254 uint32 sync_point) { |
| 255 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 255 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 256 | 256 |
| 257 ControllerClient* client = FindClient(id, event_handler, controller_clients_); | 257 ControllerClient* client = FindClient(id, event_handler, controller_clients_); |
| 258 | 258 |
| 259 // If this buffer is not held by this client, or this client doesn't exist | 259 // If this buffer is not held by this client, or this client doesn't exist |
| 260 // in controller, do nothing. | 260 // in controller, do nothing. |
| 261 ControllerClient::ActiveBufferMap::iterator iter; | 261 ControllerClient::ActiveBufferMap::iterator iter; |
| 262 if (!client || (iter = client->active_buffers.find(buffer_id)) == | 262 if (!client || (iter = client->active_buffers.find(buffer_id)) == |
| 263 client->active_buffers.end()) { | 263 client->active_buffers.end()) { |
| 264 NOTREACHED(); | 264 NOTREACHED(); |
| 265 return; | 265 return; |
| 266 } | 266 } |
| 267 scoped_refptr<media::VideoFrame> frame = iter->second; | 267 scoped_refptr<media::VideoFrame> frame = iter->second; |
| 268 client->active_buffers.erase(iter); | 268 client->active_buffers.erase(iter); |
| 269 | 269 |
| 270 if (frame->format() == media::VideoFrame::NATIVE_TEXTURE) | 270 if (frame->format() == media::VideoFrame::NATIVE_TEXTURE) |
| 271 frame->mailbox_holder()->sync_point = sync_point; | 271 frame->mailbox_holder()->sync_point = sync_point; |
| 272 | 272 |
| 273 buffer_pool_->RelinquishConsumerHold(buffer_id, 1); | 273 buffer_pool_->RelinquishConsumerHold(buffer_id, 1); |
| 274 } | 274 } |
| 275 | 275 |
| 276 const media::VideoCaptureFormat& | 276 const media::VideoCaptureFormat& |
| 277 VideoCaptureController::GetVideoCaptureFormat() const { | 277 VideoCaptureController::GetVideoCaptureFormat() const { |
| 278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 278 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 279 return video_capture_format_; | 279 return video_capture_format_; |
| 280 } | 280 } |
| 281 | 281 |
| 282 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> | 282 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> |
| 283 VideoCaptureController::VideoCaptureDeviceClient::ReserveOutputBuffer( | 283 VideoCaptureController::VideoCaptureDeviceClient::ReserveOutputBuffer( |
| 284 media::VideoFrame::Format format, | 284 media::VideoFrame::Format format, |
| 285 const gfx::Size& size) { | 285 const gfx::Size& size) { |
| 286 return DoReserveOutputBuffer(format, size); | 286 return DoReserveOutputBuffer(format, size); |
| 287 } | 287 } |
| 288 | 288 |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 VideoCaptureController::~VideoCaptureController() { | 527 VideoCaptureController::~VideoCaptureController() { |
| 528 STLDeleteContainerPointers(controller_clients_.begin(), | 528 STLDeleteContainerPointers(controller_clients_.begin(), |
| 529 controller_clients_.end()); | 529 controller_clients_.end()); |
| 530 } | 530 } |
| 531 | 531 |
| 532 void VideoCaptureController::DoIncomingCapturedVideoFrameOnIOThread( | 532 void VideoCaptureController::DoIncomingCapturedVideoFrameOnIOThread( |
| 533 const scoped_refptr<media::VideoCaptureDevice::Client::Buffer>& buffer, | 533 const scoped_refptr<media::VideoCaptureDevice::Client::Buffer>& buffer, |
| 534 const media::VideoCaptureFormat& buffer_format, | 534 const media::VideoCaptureFormat& buffer_format, |
| 535 const scoped_refptr<media::VideoFrame>& frame, | 535 const scoped_refptr<media::VideoFrame>& frame, |
| 536 base::TimeTicks timestamp) { | 536 base::TimeTicks timestamp) { |
| 537 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 537 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 538 DCHECK_NE(buffer->id(), VideoCaptureBufferPool::kInvalidId); | 538 DCHECK_NE(buffer->id(), VideoCaptureBufferPool::kInvalidId); |
| 539 | 539 |
| 540 int count = 0; | 540 int count = 0; |
| 541 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { | 541 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { |
| 542 for (ControllerClients::iterator client_it = controller_clients_.begin(); | 542 for (ControllerClients::iterator client_it = controller_clients_.begin(); |
| 543 client_it != controller_clients_.end(); ++client_it) { | 543 client_it != controller_clients_.end(); ++client_it) { |
| 544 ControllerClient* client = *client_it; | 544 ControllerClient* client = *client_it; |
| 545 if (client->session_closed) | 545 if (client->session_closed) |
| 546 continue; | 546 continue; |
| 547 | 547 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 571 .second; | 571 .second; |
| 572 DCHECK(inserted) << "Unexpected duplicate buffer: " << buffer->id(); | 572 DCHECK(inserted) << "Unexpected duplicate buffer: " << buffer->id(); |
| 573 count++; | 573 count++; |
| 574 } | 574 } |
| 575 } | 575 } |
| 576 | 576 |
| 577 buffer_pool_->HoldForConsumers(buffer->id(), count); | 577 buffer_pool_->HoldForConsumers(buffer->id(), count); |
| 578 } | 578 } |
| 579 | 579 |
| 580 void VideoCaptureController::DoErrorOnIOThread() { | 580 void VideoCaptureController::DoErrorOnIOThread() { |
| 581 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 581 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 582 state_ = VIDEO_CAPTURE_STATE_ERROR; | 582 state_ = VIDEO_CAPTURE_STATE_ERROR; |
| 583 | 583 |
| 584 for (ControllerClients::iterator client_it = controller_clients_.begin(); | 584 for (ControllerClients::iterator client_it = controller_clients_.begin(); |
| 585 client_it != controller_clients_.end(); ++client_it) { | 585 client_it != controller_clients_.end(); ++client_it) { |
| 586 ControllerClient* client = *client_it; | 586 ControllerClient* client = *client_it; |
| 587 if (client->session_closed) | 587 if (client->session_closed) |
| 588 continue; | 588 continue; |
| 589 | 589 |
| 590 client->event_handler->OnError(client->controller_id); | 590 client->event_handler->OnError(client->controller_id); |
| 591 } | 591 } |
| 592 } | 592 } |
| 593 | 593 |
| 594 void VideoCaptureController::DoBufferDestroyedOnIOThread( | 594 void VideoCaptureController::DoBufferDestroyedOnIOThread( |
| 595 int buffer_id_to_drop) { | 595 int buffer_id_to_drop) { |
| 596 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 596 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 597 | 597 |
| 598 for (ControllerClients::iterator client_it = controller_clients_.begin(); | 598 for (ControllerClients::iterator client_it = controller_clients_.begin(); |
| 599 client_it != controller_clients_.end(); ++client_it) { | 599 client_it != controller_clients_.end(); ++client_it) { |
| 600 ControllerClient* client = *client_it; | 600 ControllerClient* client = *client_it; |
| 601 if (client->session_closed) | 601 if (client->session_closed) |
| 602 continue; | 602 continue; |
| 603 | 603 |
| 604 if (client->known_buffers.erase(buffer_id_to_drop)) { | 604 if (client->known_buffers.erase(buffer_id_to_drop)) { |
| 605 client->event_handler->OnBufferDestroyed(client->controller_id, | 605 client->event_handler->OnBufferDestroyed(client->controller_id, |
| 606 buffer_id_to_drop); | 606 buffer_id_to_drop); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 630 for (ControllerClients::const_iterator client_it = clients.begin(); | 630 for (ControllerClients::const_iterator client_it = clients.begin(); |
| 631 client_it != clients.end(); ++client_it) { | 631 client_it != clients.end(); ++client_it) { |
| 632 if ((*client_it)->session_id == session_id) { | 632 if ((*client_it)->session_id == session_id) { |
| 633 return *client_it; | 633 return *client_it; |
| 634 } | 634 } |
| 635 } | 635 } |
| 636 return NULL; | 636 return NULL; |
| 637 } | 637 } |
| 638 | 638 |
| 639 int VideoCaptureController::GetClientCount() { | 639 int VideoCaptureController::GetClientCount() { |
| 640 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 640 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 641 return controller_clients_.size(); | 641 return controller_clients_.size(); |
| 642 } | 642 } |
| 643 | 643 |
| 644 } // namespace content | 644 } // namespace content |
| OLD | NEW |