| 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 <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 if (client) { | 171 if (client) { |
| 172 pending_clients_.remove(client); | 172 pending_clients_.remove(client); |
| 173 return; | 173 return; |
| 174 } | 174 } |
| 175 | 175 |
| 176 client = FindClient(id, event_handler, controller_clients_); | 176 client = FindClient(id, event_handler, controller_clients_); |
| 177 if (!client) | 177 if (!client) |
| 178 return; | 178 return; |
| 179 | 179 |
| 180 // Take back all buffers held by the |client|. | 180 // Take back all buffers held by the |client|. |
| 181 for (std::set<int>::iterator buffer_it = client->buffers.begin(); | 181 if (buffer_pool_) { |
| 182 buffer_it != client->buffers.end(); ++buffer_it) { | 182 for (std::set<int>::iterator buffer_it = client->buffers.begin(); |
| 183 int buffer_id = *buffer_it; | 183 buffer_it != client->buffers.end(); ++buffer_it) { |
| 184 buffer_pool_->RelinquishConsumerHold(buffer_id, 1); | 184 int buffer_id = *buffer_it; |
| 185 buffer_pool_->RelinquishConsumerHold(buffer_id, 1); |
| 186 } |
| 185 } | 187 } |
| 186 client->buffers.clear(); | 188 client->buffers.clear(); |
| 187 | 189 |
| 188 int session_id = client->parameters.session_id; | 190 int session_id = client->parameters.session_id; |
| 189 delete client; | 191 delete client; |
| 190 controller_clients_.remove(client); | 192 controller_clients_.remove(client); |
| 191 | 193 |
| 192 // No more clients. Stop device. | 194 // No more clients. Stop device. |
| 193 if (controller_clients_.empty() && | 195 if (controller_clients_.empty() && |
| 194 (state_ == VIDEO_CAPTURE_STATE_STARTED || | 196 (state_ == VIDEO_CAPTURE_STATE_STARTED || |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 PostStopping(); | 602 PostStopping(); |
| 601 } | 603 } |
| 602 } | 604 } |
| 603 | 605 |
| 604 void VideoCaptureController::SendFrameInfoAndBuffers(ControllerClient* client) { | 606 void VideoCaptureController::SendFrameInfoAndBuffers(ControllerClient* client) { |
| 605 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 607 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 606 DCHECK(frame_info_available_); | 608 DCHECK(frame_info_available_); |
| 607 client->event_handler->OnFrameInfo(client->controller_id, | 609 client->event_handler->OnFrameInfo(client->controller_id, |
| 608 frame_info_.width, frame_info_.height, | 610 frame_info_.width, frame_info_.height, |
| 609 frame_info_.frame_rate); | 611 frame_info_.frame_rate); |
| 612 if (!buffer_pool_) |
| 613 return; |
| 614 |
| 610 for (int buffer_id = 1; buffer_id <= buffer_pool_->count(); ++buffer_id) { | 615 for (int buffer_id = 1; buffer_id <= buffer_pool_->count(); ++buffer_id) { |
| 611 base::SharedMemoryHandle remote_handle = | 616 base::SharedMemoryHandle remote_handle = |
| 612 buffer_pool_->ShareToProcess(buffer_id, client->render_process_handle); | 617 buffer_pool_->ShareToProcess(buffer_id, client->render_process_handle); |
| 613 | 618 |
| 614 client->event_handler->OnBufferCreated(client->controller_id, | 619 client->event_handler->OnBufferCreated(client->controller_id, |
| 615 remote_handle, | 620 remote_handle, |
| 616 buffer_pool_->GetMemorySize(), | 621 buffer_pool_->GetMemorySize(), |
| 617 buffer_id); | 622 buffer_id); |
| 618 } | 623 } |
| 619 } | 624 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 648 | 653 |
| 649 // This function is called when all buffers have been returned to controller, | 654 // This function is called when all buffers have been returned to controller, |
| 650 // or when device is stopped. It decides whether the device needs to be | 655 // or when device is stopped. It decides whether the device needs to be |
| 651 // restarted. | 656 // restarted. |
| 652 void VideoCaptureController::PostStopping() { | 657 void VideoCaptureController::PostStopping() { |
| 653 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 658 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 654 DCHECK_EQ(state_, VIDEO_CAPTURE_STATE_STOPPING); | 659 DCHECK_EQ(state_, VIDEO_CAPTURE_STATE_STOPPING); |
| 655 | 660 |
| 656 // When clients still have some buffers, or device has not been stopped yet, | 661 // When clients still have some buffers, or device has not been stopped yet, |
| 657 // do nothing. | 662 // do nothing. |
| 658 if (buffer_pool_->IsAnyBufferHeldForConsumers() || device_in_use_) | 663 if ((buffer_pool_ && buffer_pool_->IsAnyBufferHeldForConsumers()) || |
| 664 device_in_use_) |
| 659 return; | 665 return; |
| 660 | 666 |
| 661 { | 667 { |
| 662 base::AutoLock lock(buffer_pool_lock_); | 668 base::AutoLock lock(buffer_pool_lock_); |
| 663 buffer_pool_ = NULL; | 669 buffer_pool_ = NULL; |
| 664 } | 670 } |
| 665 | 671 |
| 666 // No more client. Therefore the controller is stopped. | 672 // No more client. Therefore the controller is stopped. |
| 667 if (controller_clients_.empty() && pending_clients_.empty()) { | 673 if (controller_clients_.empty() && pending_clients_.empty()) { |
| 668 state_ = VIDEO_CAPTURE_STATE_STOPPED; | 674 state_ = VIDEO_CAPTURE_STATE_STOPPED; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 689 controller_clients_.push_back((*client_it)); | 695 controller_clients_.push_back((*client_it)); |
| 690 pending_clients_.erase(client_it++); | 696 pending_clients_.erase(client_it++); |
| 691 } | 697 } |
| 692 // Request the manager to start the actual capture. | 698 // Request the manager to start the actual capture. |
| 693 video_capture_manager_->Start(current_params_, this); | 699 video_capture_manager_->Start(current_params_, this); |
| 694 state_ = VIDEO_CAPTURE_STATE_STARTED; | 700 state_ = VIDEO_CAPTURE_STATE_STARTED; |
| 695 device_in_use_ = true; | 701 device_in_use_ = true; |
| 696 } | 702 } |
| 697 | 703 |
| 698 } // namespace content | 704 } // namespace content |
| OLD | NEW |