| 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 } | 140 } |
| 141 } | 141 } |
| 142 | 142 |
| 143 mojo::ScopedSharedBufferHandle | 143 mojo::ScopedSharedBufferHandle |
| 144 VideoCaptureController::BufferContext::CloneHandle() { | 144 VideoCaptureController::BufferContext::CloneHandle() { |
| 145 return buffer_handle_->Clone(); | 145 return buffer_handle_->Clone(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 VideoCaptureController::VideoCaptureController() | 148 VideoCaptureController::VideoCaptureController() |
| 149 : consumer_feedback_observer_(nullptr), | 149 : consumer_feedback_observer_(nullptr), |
| 150 state_(VIDEO_CAPTURE_STATE_STARTED), | 150 state_(VIDEO_CAPTURE_STATE_STARTING), |
| 151 has_received_frames_(false), | 151 has_received_frames_(false), |
| 152 weak_ptr_factory_(this) { | 152 weak_ptr_factory_(this) { |
| 153 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 153 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 154 } | 154 } |
| 155 | 155 |
| 156 VideoCaptureController::~VideoCaptureController() = default; | 156 VideoCaptureController::~VideoCaptureController() = default; |
| 157 | 157 |
| 158 base::WeakPtr<VideoCaptureController> | 158 base::WeakPtr<VideoCaptureController> |
| 159 VideoCaptureController::GetWeakPtrForIOThread() { | 159 VideoCaptureController::GetWeakPtrForIOThread() { |
| 160 return weak_ptr_factory_.GetWeakPtr(); | 160 return weak_ptr_factory_.GetWeakPtr(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 // Signal error in case device is already in error state. | 201 // Signal error in case device is already in error state. |
| 202 if (state_ == VIDEO_CAPTURE_STATE_ERROR) { | 202 if (state_ == VIDEO_CAPTURE_STATE_ERROR) { |
| 203 event_handler->OnError(id); | 203 event_handler->OnError(id); |
| 204 return; | 204 return; |
| 205 } | 205 } |
| 206 | 206 |
| 207 // Do nothing if this client has called AddClient before. | 207 // Do nothing if this client has called AddClient before. |
| 208 if (FindClient(id, event_handler, controller_clients_)) | 208 if (FindClient(id, event_handler, controller_clients_)) |
| 209 return; | 209 return; |
| 210 | 210 |
| 211 // If the device has reported OnStarted event, report it to this client here. |
| 212 if (state_ == VIDEO_CAPTURE_STATE_STARTED) |
| 213 event_handler->OnStarted(id); |
| 214 |
| 211 std::unique_ptr<ControllerClient> client = | 215 std::unique_ptr<ControllerClient> client = |
| 212 base::MakeUnique<ControllerClient>(id, event_handler, session_id, params); | 216 base::MakeUnique<ControllerClient>(id, event_handler, session_id, params); |
| 213 // If we already have gotten frame_info from the device, repeat it to the new | 217 // If we already have gotten frame_info from the device, repeat it to the new |
| 214 // client. | 218 // client. |
| 215 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { | 219 if (state_ != VIDEO_CAPTURE_STATE_ERROR) { |
| 216 controller_clients_.push_back(std::move(client)); | 220 controller_clients_.push_back(std::move(client)); |
| 217 return; | |
| 218 } | 221 } |
| 219 } | 222 } |
| 220 | 223 |
| 221 int VideoCaptureController::RemoveClient( | 224 int VideoCaptureController::RemoveClient( |
| 222 VideoCaptureControllerID id, | 225 VideoCaptureControllerID id, |
| 223 VideoCaptureControllerEventHandler* event_handler) { | 226 VideoCaptureControllerEventHandler* event_handler) { |
| 224 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 227 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 225 DVLOG(1) << "VideoCaptureController::RemoveClient, id " << id; | 228 DVLOG(1) << "VideoCaptureController::RemoveClient, id " << id; |
| 226 | 229 |
| 227 ControllerClient* client = FindClient(id, event_handler, controller_clients_); | 230 ControllerClient* client = FindClient(id, event_handler, controller_clients_); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 buffer_read_permission, | 370 buffer_read_permission, |
| 368 media::mojom::VideoFrameInfoPtr frame_info) { | 371 media::mojom::VideoFrameInfoPtr frame_info) { |
| 369 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 372 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 370 DCHECK_NE(buffer_id, media::VideoCaptureBufferPool::kInvalidId); | 373 DCHECK_NE(buffer_id, media::VideoCaptureBufferPool::kInvalidId); |
| 371 | 374 |
| 372 auto buffer_context_iter = FindUnretiredBufferContextFromBufferId(buffer_id); | 375 auto buffer_context_iter = FindUnretiredBufferContextFromBufferId(buffer_id); |
| 373 DCHECK(buffer_context_iter != buffer_contexts_.end()); | 376 DCHECK(buffer_context_iter != buffer_contexts_.end()); |
| 374 buffer_context_iter->set_frame_feedback_id(frame_feedback_id); | 377 buffer_context_iter->set_frame_feedback_id(frame_feedback_id); |
| 375 DCHECK(!buffer_context_iter->HasConsumers()); | 378 DCHECK(!buffer_context_iter->HasConsumers()); |
| 376 | 379 |
| 377 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { | 380 if (state_ != VIDEO_CAPTURE_STATE_ERROR) { |
| 378 const int buffer_context_id = buffer_context_iter->buffer_context_id(); | 381 const int buffer_context_id = buffer_context_iter->buffer_context_id(); |
| 379 for (const auto& client : controller_clients_) { | 382 for (const auto& client : controller_clients_) { |
| 380 if (client->session_closed || client->paused) | 383 if (client->session_closed || client->paused) |
| 381 continue; | 384 continue; |
| 382 | 385 |
| 383 // On the first use of a BufferContext for a particular client, call | 386 // On the first use of a BufferContext for a particular client, call |
| 384 // OnBufferCreated(). | 387 // OnBufferCreated(). |
| 385 if (!base::ContainsValue(client->known_buffer_context_ids, | 388 if (!base::ContainsValue(client->known_buffer_context_ids, |
| 386 buffer_context_id)) { | 389 buffer_context_id)) { |
| 387 client->known_buffer_context_ids.push_back(buffer_context_id); | 390 client->known_buffer_context_ids.push_back(buffer_context_id); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 } | 459 } |
| 457 } | 460 } |
| 458 | 461 |
| 459 void VideoCaptureController::OnLog(const std::string& message) { | 462 void VideoCaptureController::OnLog(const std::string& message) { |
| 460 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 463 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 461 MediaStreamManager::SendMessageToNativeLog("Video capture: " + message); | 464 MediaStreamManager::SendMessageToNativeLog("Video capture: " + message); |
| 462 } | 465 } |
| 463 | 466 |
| 464 void VideoCaptureController::OnStarted() { | 467 void VideoCaptureController::OnStarted() { |
| 465 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 468 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 469 state_ = VIDEO_CAPTURE_STATE_STARTED; |
| 466 | 470 |
| 467 for (const auto& client : controller_clients_) { | 471 for (const auto& client : controller_clients_) { |
| 468 if (client->session_closed) | 472 if (client->session_closed) |
| 469 continue; | 473 continue; |
| 470 client->event_handler->OnStarted(client->controller_id); | 474 client->event_handler->OnStarted(client->controller_id); |
| 471 } | 475 } |
| 472 } | 476 } |
| 473 | 477 |
| 474 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( | 478 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( |
| 475 VideoCaptureControllerID id, | 479 VideoCaptureControllerID id, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 if (entry_iter != std::end(client->known_buffer_context_ids)) { | 541 if (entry_iter != std::end(client->known_buffer_context_ids)) { |
| 538 client->known_buffer_context_ids.erase(entry_iter); | 542 client->known_buffer_context_ids.erase(entry_iter); |
| 539 client->event_handler->OnBufferDestroyed( | 543 client->event_handler->OnBufferDestroyed( |
| 540 client->controller_id, buffer_context_iter->buffer_context_id()); | 544 client->controller_id, buffer_context_iter->buffer_context_id()); |
| 541 } | 545 } |
| 542 } | 546 } |
| 543 buffer_contexts_.erase(buffer_context_iter); | 547 buffer_contexts_.erase(buffer_context_iter); |
| 544 } | 548 } |
| 545 | 549 |
| 546 } // namespace content | 550 } // namespace content |
| OLD | NEW |