| 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> |
| 11 #include <set> | 11 #include <set> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
| 17 #include "base/metrics/sparse_histogram.h" | 17 #include "base/metrics/sparse_histogram.h" |
| 18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 19 #include "components/display_compositor/gl_helper.h" | 19 #include "components/display_compositor/gl_helper.h" |
| 20 #include "content/browser/renderer_host/media/media_stream_manager.h" | 20 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 21 #include "content/browser/renderer_host/media/video_capture_manager.h" | 21 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 22 #include "content/common/video_capture.mojom.h" |
| 22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 23 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
| 24 #include "media/base/video_frame.h" | 25 #include "media/base/video_frame.h" |
| 25 #include "media/capture/video/video_capture_buffer_pool.h" | 26 #include "media/capture/video/video_capture_buffer_pool.h" |
| 26 #include "media/capture/video/video_capture_buffer_tracker_factory_impl.h" | 27 #include "media/capture/video/video_capture_buffer_tracker_factory_impl.h" |
| 27 #include "media/capture/video/video_capture_device_client.h" | 28 #include "media/capture/video/video_capture_device_client.h" |
| 28 #include "mojo/public/cpp/system/platform_handle.h" | 29 #include "mojo/public/cpp/system/platform_handle.h" |
| 29 | 30 |
| 30 #if !defined(OS_ANDROID) | 31 #if !defined(OS_ANDROID) |
| 31 #include "content/browser/compositor/image_transport_factory.h" | 32 #include "content/browser/compositor/image_transport_factory.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 87 |
| 87 // Indicates whether the client is paused, if true, VideoCaptureController | 88 // Indicates whether the client is paused, if true, VideoCaptureController |
| 88 // stops updating its buffer. | 89 // stops updating its buffer. |
| 89 bool paused; | 90 bool paused; |
| 90 }; | 91 }; |
| 91 | 92 |
| 92 VideoCaptureController::BufferContext::BufferContext( | 93 VideoCaptureController::BufferContext::BufferContext( |
| 93 int buffer_context_id, | 94 int buffer_context_id, |
| 94 int buffer_id, | 95 int buffer_id, |
| 95 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer, | 96 media::VideoFrameConsumerFeedbackObserver* consumer_feedback_observer, |
| 96 media::FrameBufferPool* frame_buffer_pool) | 97 mojo::ScopedSharedBufferHandle handle) |
| 97 : buffer_context_id_(buffer_context_id), | 98 : buffer_context_id_(buffer_context_id), |
| 98 buffer_id_(buffer_id), | 99 buffer_id_(buffer_id), |
| 99 is_retired_(false), | 100 is_retired_(false), |
| 100 frame_feedback_id_(0), | 101 frame_feedback_id_(0), |
| 101 consumer_feedback_observer_(consumer_feedback_observer), | 102 consumer_feedback_observer_(consumer_feedback_observer), |
| 102 frame_buffer_pool_(frame_buffer_pool), | 103 buffer_handle_(std::move(handle)), |
| 103 max_consumer_utilization_( | 104 max_consumer_utilization_( |
| 104 media::VideoFrameConsumerFeedbackObserver::kNoUtilizationRecorded), | 105 media::VideoFrameConsumerFeedbackObserver::kNoUtilizationRecorded), |
| 105 consumer_hold_count_(0) {} | 106 consumer_hold_count_(0) {} |
| 106 | 107 |
| 107 VideoCaptureController::BufferContext::~BufferContext() = default; | 108 VideoCaptureController::BufferContext::~BufferContext() = default; |
| 108 | 109 |
| 109 VideoCaptureController::BufferContext::BufferContext( | 110 VideoCaptureController::BufferContext::BufferContext( |
| 110 const VideoCaptureController::BufferContext& other) = default; | 111 VideoCaptureController::BufferContext&& other) = default; |
| 111 | 112 |
| 112 VideoCaptureController::BufferContext& VideoCaptureController::BufferContext:: | 113 VideoCaptureController::BufferContext& VideoCaptureController::BufferContext:: |
| 113 operator=(const BufferContext& other) = default; | 114 operator=(BufferContext&& other) = default; |
| 114 | 115 |
| 115 void VideoCaptureController::BufferContext::RecordConsumerUtilization( | 116 void VideoCaptureController::BufferContext::RecordConsumerUtilization( |
| 116 double utilization) { | 117 double utilization) { |
| 117 if (std::isfinite(utilization) && utilization >= 0.0) { | 118 if (std::isfinite(utilization) && utilization >= 0.0) { |
| 118 max_consumer_utilization_ = | 119 max_consumer_utilization_ = |
| 119 std::max(max_consumer_utilization_, utilization); | 120 std::max(max_consumer_utilization_, utilization); |
| 120 } | 121 } |
| 121 } | 122 } |
| 122 | 123 |
| 123 void VideoCaptureController::BufferContext::IncreaseConsumerCount() { | 124 void VideoCaptureController::BufferContext::IncreaseConsumerCount() { |
| 124 if (consumer_hold_count_ == 0) | |
| 125 if (frame_buffer_pool_ != nullptr) | |
| 126 frame_buffer_pool_->SetBufferHold(buffer_id_); | |
| 127 consumer_hold_count_++; | 125 consumer_hold_count_++; |
| 128 } | 126 } |
| 129 | 127 |
| 130 void VideoCaptureController::BufferContext::DecreaseConsumerCount() { | 128 void VideoCaptureController::BufferContext::DecreaseConsumerCount() { |
| 131 consumer_hold_count_--; | 129 consumer_hold_count_--; |
| 132 if (consumer_hold_count_ == 0) { | 130 if (consumer_hold_count_ == 0) { |
| 133 if (consumer_feedback_observer_ != nullptr && | 131 if (consumer_feedback_observer_ != nullptr && |
| 134 max_consumer_utilization_ != | 132 max_consumer_utilization_ != |
| 135 media::VideoFrameConsumerFeedbackObserver::kNoUtilizationRecorded) { | 133 media::VideoFrameConsumerFeedbackObserver::kNoUtilizationRecorded) { |
| 136 consumer_feedback_observer_->OnUtilizationReport( | 134 consumer_feedback_observer_->OnUtilizationReport( |
| 137 frame_feedback_id_, max_consumer_utilization_); | 135 frame_feedback_id_, max_consumer_utilization_); |
| 138 } | 136 } |
| 139 if (frame_buffer_pool_ != nullptr) | 137 buffer_read_permission_.reset(); |
| 140 frame_buffer_pool_->ReleaseBufferHold(buffer_id_); | |
| 141 max_consumer_utilization_ = | 138 max_consumer_utilization_ = |
| 142 media::VideoFrameConsumerFeedbackObserver::kNoUtilizationRecorded; | 139 media::VideoFrameConsumerFeedbackObserver::kNoUtilizationRecorded; |
| 143 } | 140 } |
| 144 } | 141 } |
| 145 | 142 |
| 146 bool VideoCaptureController::BufferContext::HasZeroConsumerHoldCount() { | 143 bool VideoCaptureController::BufferContext::HasZeroConsumerHoldCount() const { |
| 147 return consumer_hold_count_ == 0; | 144 return consumer_hold_count_ == 0; |
| 148 } | 145 } |
| 149 | 146 |
| 147 bool VideoCaptureController::BufferContext::HasConsumers() const { |
| 148 return consumer_hold_count_ > 0; |
| 149 } |
| 150 |
| 151 mojo::ScopedSharedBufferHandle |
| 152 VideoCaptureController::BufferContext::CreateHandleCopy() { |
| 153 return buffer_handle_->Clone(); |
| 154 } |
| 155 |
| 150 VideoCaptureController::VideoCaptureController() | 156 VideoCaptureController::VideoCaptureController() |
| 151 : frame_buffer_pool_(nullptr), | 157 : consumer_feedback_observer_(nullptr), |
| 152 consumer_feedback_observer_(nullptr), | |
| 153 state_(VIDEO_CAPTURE_STATE_STARTED), | 158 state_(VIDEO_CAPTURE_STATE_STARTED), |
| 154 has_received_frames_(false), | 159 has_received_frames_(false), |
| 155 weak_ptr_factory_(this) { | 160 weak_ptr_factory_(this) { |
| 156 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 161 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 157 } | 162 } |
| 158 | 163 |
| 159 VideoCaptureController::~VideoCaptureController() = default; | 164 VideoCaptureController::~VideoCaptureController() = default; |
| 160 | 165 |
| 161 base::WeakPtr<VideoCaptureController> | 166 base::WeakPtr<VideoCaptureController> |
| 162 VideoCaptureController::GetWeakPtrForIOThread() { | 167 VideoCaptureController::GetWeakPtrForIOThread() { |
| 163 return weak_ptr_factory_.GetWeakPtr(); | 168 return weak_ptr_factory_.GetWeakPtr(); |
| 164 } | 169 } |
| 165 | 170 |
| 166 void VideoCaptureController::SetFrameBufferPool( | |
| 167 std::unique_ptr<media::FrameBufferPool> frame_buffer_pool) { | |
| 168 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 169 frame_buffer_pool_ = std::move(frame_buffer_pool); | |
| 170 // Update existing BufferContext entries. | |
| 171 for (auto& entry : buffer_contexts_) | |
| 172 entry.set_frame_buffer_pool(frame_buffer_pool_.get()); | |
| 173 } | |
| 174 | |
| 175 void VideoCaptureController::SetConsumerFeedbackObserver( | 171 void VideoCaptureController::SetConsumerFeedbackObserver( |
| 176 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> | 172 std::unique_ptr<media::VideoFrameConsumerFeedbackObserver> |
| 177 consumer_feedback_observer) { | 173 consumer_feedback_observer) { |
| 178 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 174 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 179 consumer_feedback_observer_ = std::move(consumer_feedback_observer); | 175 consumer_feedback_observer_ = std::move(consumer_feedback_observer); |
| 180 // Update existing BufferContext entries. | 176 // Update existing BufferContext entries. |
| 181 for (auto& entry : buffer_contexts_) | 177 for (auto& entry : buffer_contexts_) |
| 182 entry.set_consumer_feedback_observer(consumer_feedback_observer_.get()); | 178 entry.set_consumer_feedback_observer(consumer_feedback_observer_.get()); |
| 183 } | 179 } |
| 184 | 180 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 OnClientFinishedConsumingBuffer(client, buffer_id, | 348 OnClientFinishedConsumingBuffer(client, buffer_id, |
| 353 consumer_resource_utilization); | 349 consumer_resource_utilization); |
| 354 } | 350 } |
| 355 | 351 |
| 356 const media::VideoCaptureFormat& VideoCaptureController::GetVideoCaptureFormat() | 352 const media::VideoCaptureFormat& VideoCaptureController::GetVideoCaptureFormat() |
| 357 const { | 353 const { |
| 358 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 354 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 359 return video_capture_format_; | 355 return video_capture_format_; |
| 360 } | 356 } |
| 361 | 357 |
| 362 void VideoCaptureController::OnIncomingCapturedVideoFrame( | 358 void VideoCaptureController::OnNewBufferHandle( |
| 363 media::VideoCaptureDevice::Client::Buffer buffer, | 359 int buffer_id, |
| 364 scoped_refptr<VideoFrame> frame) { | 360 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer::HandleProvider> |
| 361 handle_provider) { |
| 365 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 362 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 366 const int buffer_id_from_producer = buffer.id(); | 363 DCHECK(FindUnretiredBufferContextFromBufferId(buffer_id) == |
| 367 DCHECK_NE(buffer_id_from_producer, media::VideoCaptureBufferPool::kInvalidId); | 364 buffer_contexts_.end()); |
| 368 auto buffer_context_iter = | 365 buffer_contexts_.emplace_back( |
| 369 FindUnretiredBufferContextFromBufferId(buffer_id_from_producer); | 366 next_buffer_context_id_++, buffer_id, consumer_feedback_observer_.get(), |
| 370 if (buffer_context_iter == buffer_contexts_.end()) { | 367 handle_provider->GetHandleForInterProcessTransit()); |
| 371 // A new buffer has been shared with us. Create new BufferContext. | 368 } |
| 372 buffer_contexts_.emplace_back( | 369 |
| 373 next_buffer_context_id_++, buffer_id_from_producer, | 370 void VideoCaptureController::OnFrameReadyInBuffer( |
| 374 consumer_feedback_observer_.get(), frame_buffer_pool_.get()); | 371 int buffer_id, |
| 375 buffer_context_iter = buffer_contexts_.end() - 1; | 372 int frame_feedback_id, |
| 376 } | 373 std::unique_ptr< |
| 377 buffer_context_iter->set_frame_feedback_id(buffer.frame_feedback_id()); | 374 media::VideoCaptureDevice::Client::Buffer::ScopedAccessPermission> |
| 375 buffer_read_permission, |
| 376 media::mojom::VideoFrameInfoPtr frame_info) { |
| 377 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 378 DCHECK_NE(buffer_id, media::VideoCaptureBufferPool::kInvalidId); |
| 379 |
| 380 auto buffer_context_iter = FindUnretiredBufferContextFromBufferId(buffer_id); |
| 381 DCHECK(buffer_context_iter != buffer_contexts_.end()); |
| 382 buffer_context_iter->set_frame_feedback_id(frame_feedback_id); |
| 378 DCHECK(buffer_context_iter->HasZeroConsumerHoldCount()); | 383 DCHECK(buffer_context_iter->HasZeroConsumerHoldCount()); |
| 379 | 384 |
| 380 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { | 385 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { |
| 381 if (!frame->metadata()->HasKey(VideoFrameMetadata::FRAME_RATE)) { | |
| 382 frame->metadata()->SetDouble(VideoFrameMetadata::FRAME_RATE, | |
| 383 video_capture_format_.frame_rate); | |
| 384 } | |
| 385 std::unique_ptr<base::DictionaryValue> metadata = | |
| 386 frame->metadata()->CopyInternalValues(); | |
| 387 | |
| 388 // Only I420 and Y16 pixel formats are currently supported. | |
| 389 DCHECK(frame->format() == media::PIXEL_FORMAT_I420 || | |
| 390 frame->format() == media::PIXEL_FORMAT_Y16) | |
| 391 << "Unsupported pixel format: " | |
| 392 << media::VideoPixelFormatToString(frame->format()); | |
| 393 | |
| 394 // Sanity-checks to confirm |frame| is actually being backed by |buffer|. | |
| 395 auto buffer_access = | |
| 396 buffer.handle_provider()->GetHandleForInProcessAccess(); | |
| 397 DCHECK(frame->storage_type() == media::VideoFrame::STORAGE_SHMEM); | |
| 398 DCHECK(frame->data(media::VideoFrame::kYPlane) >= buffer_access->data() && | |
| 399 (frame->data(media::VideoFrame::kYPlane) < | |
| 400 (buffer_access->data() + buffer_access->mapped_size()))) | |
| 401 << "VideoFrame does not appear to be backed by Buffer"; | |
| 402 | |
| 403 const int buffer_context_id = buffer_context_iter->buffer_context_id(); | 386 const int buffer_context_id = buffer_context_iter->buffer_context_id(); |
| 404 for (const auto& client : controller_clients_) { | 387 for (const auto& client : controller_clients_) { |
| 405 if (client->session_closed || client->paused) | 388 if (client->session_closed || client->paused) |
| 406 continue; | 389 continue; |
| 407 | 390 |
| 408 // On the first use of a BufferContext on a client, share the memory | 391 // On the first use of a BufferContext for a particular client, call |
| 409 // handles. | 392 // OnBufferCreated(). |
| 410 auto known_buffers_entry_iter = std::find( | 393 auto known_buffers_entry_iter = std::find( |
| 411 std::begin(client->known_buffer_context_ids), | 394 std::begin(client->known_buffer_context_ids), |
| 412 std::end(client->known_buffer_context_ids), buffer_context_id); | 395 std::end(client->known_buffer_context_ids), buffer_context_id); |
| 413 bool is_new_buffer = false; | 396 bool is_new_buffer = false; |
| 414 if (known_buffers_entry_iter == | 397 if (known_buffers_entry_iter == |
| 415 std::end(client->known_buffer_context_ids)) { | 398 std::end(client->known_buffer_context_ids)) { |
| 416 client->known_buffer_context_ids.push_back(buffer_context_id); | 399 client->known_buffer_context_ids.push_back(buffer_context_id); |
| 417 is_new_buffer = true; | 400 is_new_buffer = true; |
| 418 } | 401 } |
| 419 if (is_new_buffer) { | 402 if (is_new_buffer) { |
| 420 mojo::ScopedSharedBufferHandle handle = | 403 size_t mapped_size = |
| 421 buffer.handle_provider()->GetHandleForInterProcessTransit(); | 404 media::VideoCaptureFormat(frame_info->coded_size, 0.0f, |
| 405 frame_info->pixel_format, |
| 406 frame_info->storage_type) |
| 407 .ImageAllocationSize(); |
| 422 client->event_handler->OnBufferCreated( | 408 client->event_handler->OnBufferCreated( |
| 423 client->controller_id, std::move(handle), | 409 client->controller_id, buffer_context_iter->CreateHandleCopy(), |
| 424 buffer_access->mapped_size(), buffer_context_id); | 410 mapped_size, buffer_context_id); |
| 425 } | 411 } |
| 412 |
| 426 client->event_handler->OnBufferReady(client->controller_id, | 413 client->event_handler->OnBufferReady(client->controller_id, |
| 427 buffer_context_id, frame); | 414 buffer_context_id, frame_info); |
| 428 | 415 |
| 429 auto buffers_in_use_entry_iter = | 416 auto buffers_in_use_entry_iter = |
| 430 std::find(std::begin(client->buffers_in_use), | 417 std::find(std::begin(client->buffers_in_use), |
| 431 std::end(client->buffers_in_use), buffer_context_id); | 418 std::end(client->buffers_in_use), buffer_context_id); |
| 432 if (buffers_in_use_entry_iter == std::end(client->buffers_in_use)) | 419 if (buffers_in_use_entry_iter == std::end(client->buffers_in_use)) |
| 433 client->buffers_in_use.push_back(buffer_context_id); | 420 client->buffers_in_use.push_back(buffer_context_id); |
| 434 else | 421 else |
| 435 DCHECK(false) << "Unexpected duplicate buffer: " << buffer_context_id; | 422 DCHECK(false) << "Unexpected duplicate buffer: " << buffer_context_id; |
| 423 |
| 436 buffer_context_iter->IncreaseConsumerCount(); | 424 buffer_context_iter->IncreaseConsumerCount(); |
| 437 } | 425 } |
| 426 if (buffer_context_iter->HasConsumers()) { |
| 427 buffer_context_iter->set_read_permission( |
| 428 std::move(buffer_read_permission)); |
| 429 } |
| 438 } | 430 } |
| 439 | 431 |
| 440 if (!has_received_frames_) { | 432 if (!has_received_frames_) { |
| 441 UMA_HISTOGRAM_COUNTS("Media.VideoCapture.Width", | 433 UMA_HISTOGRAM_COUNTS("Media.VideoCapture.Width", |
| 442 frame->visible_rect().width()); | 434 frame_info->coded_size.width()); |
| 443 UMA_HISTOGRAM_COUNTS("Media.VideoCapture.Height", | 435 UMA_HISTOGRAM_COUNTS("Media.VideoCapture.Height", |
| 444 frame->visible_rect().height()); | 436 frame_info->coded_size.height()); |
| 445 UMA_HISTOGRAM_ASPECT_RATIO("Media.VideoCapture.AspectRatio", | 437 UMA_HISTOGRAM_ASPECT_RATIO("Media.VideoCapture.AspectRatio", |
| 446 frame->visible_rect().width(), | 438 frame_info->coded_size.width(), |
| 447 frame->visible_rect().height()); | 439 frame_info->coded_size.height()); |
| 448 double frame_rate = 0.0f; | 440 double frame_rate = 0.0f; |
| 449 if (!frame->metadata()->GetDouble(VideoFrameMetadata::FRAME_RATE, | 441 media::VideoFrameMetadata metadata; |
| 450 &frame_rate)) { | 442 metadata.MergeInternalValuesFrom(*frame_info->metadata); |
| 443 if (!metadata.GetDouble(VideoFrameMetadata::FRAME_RATE, &frame_rate)) { |
| 451 frame_rate = video_capture_format_.frame_rate; | 444 frame_rate = video_capture_format_.frame_rate; |
| 452 } | 445 } |
| 453 UMA_HISTOGRAM_COUNTS("Media.VideoCapture.FrameRate", frame_rate); | 446 UMA_HISTOGRAM_COUNTS("Media.VideoCapture.FrameRate", frame_rate); |
| 454 has_received_frames_ = true; | 447 has_received_frames_ = true; |
| 455 } | 448 } |
| 456 } | 449 } |
| 457 | 450 |
| 451 void VideoCaptureController::OnBufferRetired(int buffer_id) { |
| 452 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 453 |
| 454 auto buffer_context_iter = FindUnretiredBufferContextFromBufferId(buffer_id); |
| 455 DCHECK(buffer_context_iter != buffer_contexts_.end()); |
| 456 |
| 457 // If there are any clients still using the buffer, we need to allow them |
| 458 // to finish up. We need to hold on to the BufferContext entry until then, |
| 459 // because it contains the consumer hold. |
| 460 if (buffer_context_iter->HasZeroConsumerHoldCount()) |
| 461 ReleaseBufferContext(buffer_context_iter); |
| 462 else |
| 463 buffer_context_iter->set_is_retired(); |
| 464 } |
| 465 |
| 458 void VideoCaptureController::OnError() { | 466 void VideoCaptureController::OnError() { |
| 459 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 467 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 460 state_ = VIDEO_CAPTURE_STATE_ERROR; | 468 state_ = VIDEO_CAPTURE_STATE_ERROR; |
| 461 | 469 |
| 462 for (const auto& client : controller_clients_) { | 470 for (const auto& client : controller_clients_) { |
| 463 if (client->session_closed) | 471 if (client->session_closed) |
| 464 continue; | 472 continue; |
| 465 client->event_handler->OnError(client->controller_id); | 473 client->event_handler->OnError(client->controller_id); |
| 466 } | 474 } |
| 467 } | 475 } |
| 468 | 476 |
| 469 void VideoCaptureController::OnLog(const std::string& message) { | 477 void VideoCaptureController::OnLog(const std::string& message) { |
| 470 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 478 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 471 MediaStreamManager::SendMessageToNativeLog("Video capture: " + message); | 479 MediaStreamManager::SendMessageToNativeLog("Video capture: " + message); |
| 472 } | 480 } |
| 473 | 481 |
| 474 void VideoCaptureController::OnBufferRetired(int buffer_id) { | |
| 475 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 476 | |
| 477 auto buffer_context_iter = FindUnretiredBufferContextFromBufferId(buffer_id); | |
| 478 DCHECK(buffer_context_iter != buffer_contexts_.end()); | |
| 479 | |
| 480 // If there are any clients still using the buffer, we need to allow them | |
| 481 // to finish up. We need to hold on to the BufferContext entry until then, | |
| 482 // because it contains the consumer hold. | |
| 483 if (buffer_context_iter->HasZeroConsumerHoldCount()) | |
| 484 ReleaseBufferContext(buffer_context_iter); | |
| 485 else | |
| 486 buffer_context_iter->set_is_retired(); | |
| 487 } | |
| 488 | |
| 489 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( | 482 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( |
| 490 VideoCaptureControllerID id, | 483 VideoCaptureControllerID id, |
| 491 VideoCaptureControllerEventHandler* handler, | 484 VideoCaptureControllerEventHandler* handler, |
| 492 const ControllerClients& clients) { | 485 const ControllerClients& clients) { |
| 493 for (const auto& client : clients) { | 486 for (const auto& client : clients) { |
| 494 if (client->controller_id == id && client->event_handler == handler) | 487 if (client->controller_id == id && client->event_handler == handler) |
| 495 return client.get(); | 488 return client.get(); |
| 496 } | 489 } |
| 497 return nullptr; | 490 return nullptr; |
| 498 } | 491 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 if (entry_iter != std::end(client->known_buffer_context_ids)) { | 545 if (entry_iter != std::end(client->known_buffer_context_ids)) { |
| 553 client->known_buffer_context_ids.erase(entry_iter); | 546 client->known_buffer_context_ids.erase(entry_iter); |
| 554 client->event_handler->OnBufferDestroyed( | 547 client->event_handler->OnBufferDestroyed( |
| 555 client->controller_id, buffer_context_iter->buffer_context_id()); | 548 client->controller_id, buffer_context_iter->buffer_context_id()); |
| 556 } | 549 } |
| 557 } | 550 } |
| 558 buffer_contexts_.erase(buffer_context_iter); | 551 buffer_contexts_.erase(buffer_context_iter); |
| 559 } | 552 } |
| 560 | 553 |
| 561 } // namespace content | 554 } // namespace content |
| OLD | NEW |