Chromium Code Reviews| 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 28 matching lines...) Expand all Loading... | |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 static const int kInfiniteRatio = 99999; | 42 static const int kInfiniteRatio = 99999; |
| 43 | 43 |
| 44 #define UMA_HISTOGRAM_ASPECT_RATIO(name, width, height) \ | 44 #define UMA_HISTOGRAM_ASPECT_RATIO(name, width, height) \ |
| 45 UMA_HISTOGRAM_SPARSE_SLOWLY( \ | 45 UMA_HISTOGRAM_SPARSE_SLOWLY( \ |
| 46 name, \ | 46 name, \ |
| 47 (height) ? ((width) * 100) / (height) : kInfiniteRatio); | 47 (height) ? ((width) * 100) / (height) : kInfiniteRatio); |
| 48 | 48 |
| 49 class SyncTokenClientImpl : public VideoFrame::SyncTokenClient { | |
| 50 public: | |
| 51 explicit SyncTokenClientImpl(display_compositor::GLHelper* gl_helper) | |
| 52 : gl_helper_(gl_helper) {} | |
| 53 ~SyncTokenClientImpl() override {} | |
| 54 void GenerateSyncToken(gpu::SyncToken* sync_token) override { | |
| 55 gl_helper_->GenerateSyncToken(sync_token); | |
| 56 } | |
| 57 void WaitSyncToken(const gpu::SyncToken& sync_token) override { | |
| 58 gl_helper_->WaitSyncToken(sync_token); | |
| 59 } | |
| 60 | |
| 61 private: | |
| 62 display_compositor::GLHelper* gl_helper_; | |
| 63 }; | |
| 64 | |
| 65 void ReturnVideoFrame(const scoped_refptr<VideoFrame>& video_frame, | |
| 66 const gpu::SyncToken& sync_token) { | |
| 67 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 68 #if defined(OS_ANDROID) | |
| 69 NOTREACHED(); | |
| 70 #else | |
| 71 display_compositor::GLHelper* gl_helper = | |
| 72 ImageTransportFactory::GetInstance()->GetGLHelper(); | |
| 73 // UpdateReleaseSyncToken() creates a new sync_token using |gl_helper|, so | |
| 74 // wait the given |sync_token| using |gl_helper|. | |
| 75 if (gl_helper) { | |
| 76 gl_helper->WaitSyncToken(sync_token); | |
| 77 SyncTokenClientImpl client(gl_helper); | |
| 78 video_frame->UpdateReleaseSyncToken(&client); | |
| 79 } | |
| 80 #endif | |
| 81 } | |
| 82 | |
| 83 std::unique_ptr<media::VideoCaptureJpegDecoder> CreateGpuJpegDecoder( | 49 std::unique_ptr<media::VideoCaptureJpegDecoder> CreateGpuJpegDecoder( |
| 84 const media::VideoCaptureJpegDecoder::DecodeDoneCB& decode_done_cb) { | 50 const media::VideoCaptureJpegDecoder::DecodeDoneCB& decode_done_cb) { |
| 85 return base::MakeUnique<VideoCaptureGpuJpegDecoder>(decode_done_cb); | 51 return base::MakeUnique<VideoCaptureGpuJpegDecoder>(decode_done_cb); |
| 86 } | 52 } |
| 87 | 53 |
| 88 // Decorator for media::VideoFrameReceiver that forwards all incoming calls | 54 // Decorator for media::VideoFrameReceiver that forwards all incoming calls |
| 89 // to the Browser IO thread. | 55 // to the Browser IO thread. |
| 90 class VideoFrameReceiverOnIOThread : public media::VideoFrameReceiver { | 56 class VideoFrameReceiverOnIOThread : public media::VideoFrameReceiver { |
| 91 public: | 57 public: |
| 92 explicit VideoFrameReceiverOnIOThread( | 58 explicit VideoFrameReceiverOnIOThread( |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 // ID used for identifying this object. | 109 // ID used for identifying this object. |
| 144 const VideoCaptureControllerID controller_id; | 110 const VideoCaptureControllerID controller_id; |
| 145 VideoCaptureControllerEventHandler* const event_handler; | 111 VideoCaptureControllerEventHandler* const event_handler; |
| 146 | 112 |
| 147 const media::VideoCaptureSessionId session_id; | 113 const media::VideoCaptureSessionId session_id; |
| 148 const media::VideoCaptureParams parameters; | 114 const media::VideoCaptureParams parameters; |
| 149 | 115 |
| 150 // Buffers that are currently known to this client. | 116 // Buffers that are currently known to this client. |
| 151 std::set<int> known_buffers; | 117 std::set<int> known_buffers; |
| 152 | 118 |
| 153 // Buffers currently held by this client, and sync token callback to call when | 119 // Buffers currently held by this client. |
| 154 // they are returned from the client. | 120 std::set<int> buffers_in_use; |
|
miu
2016/12/02 23:29:32
Note on use of std::set/map/list/unordered_map: Th
chfremer
2016/12/03 00:30:35
Done.
| |
| 155 typedef std::map<int, scoped_refptr<VideoFrame>> ActiveBufferMap; | |
| 156 ActiveBufferMap active_buffers; | |
| 157 | 121 |
| 158 // State of capture session, controlled by VideoCaptureManager directly. This | 122 // State of capture session, controlled by VideoCaptureManager directly. This |
| 159 // transitions to true as soon as StopSession() occurs, at which point the | 123 // transitions to true as soon as StopSession() occurs, at which point the |
| 160 // client is sent an OnEnded() event. However, because the client retains a | 124 // client is sent an OnEnded() event. However, because the client retains a |
| 161 // VideoCaptureController* pointer, its ControllerClient entry lives on until | 125 // VideoCaptureController* pointer, its ControllerClient entry lives on until |
| 162 // it unregisters itself via RemoveClient(), which may happen asynchronously. | 126 // it unregisters itself via RemoveClient(), which may happen asynchronously. |
| 163 // | 127 // |
| 164 // TODO(nick): If we changed the semantics of VideoCaptureHost so that | 128 // TODO(nick): If we changed the semantics of VideoCaptureHost so that |
| 165 // OnEnded() events were processed synchronously (with the RemoveClient() done | 129 // OnEnded() events were processed synchronously (with the RemoveClient() done |
| 166 // implicitly), we could avoid tracking this state here in the Controller, and | 130 // implicitly), we could avoid tracking this state here in the Controller, and |
| 167 // simplify the code in both places. | 131 // simplify the code in both places. |
| 168 bool session_closed; | 132 bool session_closed; |
| 169 | 133 |
| 170 // Indicates whether the client is paused, if true, VideoCaptureController | 134 // Indicates whether the client is paused, if true, VideoCaptureController |
| 171 // stops updating its buffer. | 135 // stops updating its buffer. |
| 172 bool paused; | 136 bool paused; |
| 173 }; | 137 }; |
| 174 | 138 |
| 139 VideoCaptureController::BufferState::BufferState( | |
| 140 int buffer_id, | |
| 141 int frame_feedback_id, | |
| 142 media::ConsumerFeedbackObserver* consumer_feedback_observer, | |
| 143 const scoped_refptr<media::VideoCaptureBufferPool>& buffer_pool, | |
|
miu
2016/12/02 23:29:32
New smart pointer style guidelines: Both the |buff
chfremer
2016/12/03 00:30:35
Done.
| |
| 144 const scoped_refptr<media::VideoFrame>& frame) | |
| 145 : buffer_id_(buffer_id), | |
| 146 frame_feedback_id_(frame_feedback_id), | |
| 147 consumer_feedback_observer_(consumer_feedback_observer), | |
| 148 buffer_pool_(buffer_pool), | |
| 149 frame_(frame), | |
| 150 max_consumer_utilization_( | |
| 151 media::ConsumerFeedbackObserver::kNoUtilizationRecorded), | |
| 152 consumer_hold_count_(0) {} | |
| 153 | |
| 154 VideoCaptureController::BufferState::~BufferState() = default; | |
| 155 | |
| 156 VideoCaptureController::BufferState::BufferState( | |
| 157 const VideoCaptureController::BufferState& other) = default; | |
| 158 | |
| 159 void VideoCaptureController::BufferState::RecordConsumerUtilization( | |
| 160 double utilization) { | |
| 161 if (std::isfinite(utilization) && utilization >= 0.0) { | |
| 162 max_consumer_utilization_ = | |
| 163 std::max(max_consumer_utilization_, utilization); | |
| 164 } | |
| 165 } | |
| 166 | |
| 167 void VideoCaptureController::BufferState::IncreaseConsumerCount() { | |
| 168 if (consumer_hold_count_ == 0) | |
| 169 buffer_pool_->HoldForConsumers(buffer_id_, 1); | |
| 170 consumer_hold_count_++; | |
| 171 } | |
| 172 | |
| 173 void VideoCaptureController::BufferState::DecreaseConsumerCount() { | |
| 174 consumer_hold_count_--; | |
| 175 if (consumer_hold_count_ == 0) { | |
| 176 if (consumer_feedback_observer_ != nullptr && | |
| 177 max_consumer_utilization_ != | |
| 178 media::ConsumerFeedbackObserver::kNoUtilizationRecorded) { | |
| 179 consumer_feedback_observer_->OnConsumerReportingUtilization( | |
| 180 frame_feedback_id_, max_consumer_utilization_); | |
| 181 } | |
| 182 buffer_pool_->RelinquishConsumerHold(buffer_id_, 1); | |
| 183 max_consumer_utilization_ = | |
| 184 media::ConsumerFeedbackObserver::kNoUtilizationRecorded; | |
| 185 } | |
| 186 } | |
| 187 | |
| 188 bool VideoCaptureController::BufferState::HasZeroConsumerHoldCount() { | |
| 189 return consumer_hold_count_ == 0; | |
| 190 } | |
| 191 | |
| 192 void VideoCaptureController::BufferState::SetConsumerFeedbackObserver( | |
| 193 media::ConsumerFeedbackObserver* consumer_feedback_observer) { | |
| 194 consumer_feedback_observer_ = consumer_feedback_observer; | |
| 195 } | |
| 196 | |
| 175 VideoCaptureController::VideoCaptureController(int max_buffers) | 197 VideoCaptureController::VideoCaptureController(int max_buffers) |
| 176 : buffer_pool_(new media::VideoCaptureBufferPoolImpl( | 198 : buffer_pool_(new media::VideoCaptureBufferPoolImpl( |
| 177 base::MakeUnique<media::VideoCaptureBufferTrackerFactoryImpl>(), | 199 base::MakeUnique<media::VideoCaptureBufferTrackerFactoryImpl>(), |
| 178 max_buffers)), | 200 max_buffers)), |
| 201 consumer_feedback_observer_(nullptr), | |
| 179 state_(VIDEO_CAPTURE_STATE_STARTED), | 202 state_(VIDEO_CAPTURE_STATE_STARTED), |
| 180 has_received_frames_(false), | 203 has_received_frames_(false), |
| 181 weak_ptr_factory_(this) { | 204 weak_ptr_factory_(this) { |
| 182 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 205 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 183 } | 206 } |
| 184 | 207 |
| 185 base::WeakPtr<VideoCaptureController> | 208 base::WeakPtr<VideoCaptureController> |
| 186 VideoCaptureController::GetWeakPtrForIOThread() { | 209 VideoCaptureController::GetWeakPtrForIOThread() { |
| 187 return weak_ptr_factory_.GetWeakPtr(); | 210 return weak_ptr_factory_.GetWeakPtr(); |
| 188 } | 211 } |
| 189 | 212 |
| 213 void VideoCaptureController::SetConsumerFeedbackObserver( | |
| 214 std::unique_ptr<media::ConsumerFeedbackObserver> | |
| 215 consumer_feedback_observer) { | |
| 216 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 217 consumer_feedback_observer_ = std::move(consumer_feedback_observer); | |
| 218 // Update existing BufferState entries. | |
| 219 for (auto& entry : buffer_id_to_state_map_) | |
| 220 entry.second.SetConsumerFeedbackObserver(consumer_feedback_observer_.get()); | |
| 221 } | |
| 222 | |
| 190 std::unique_ptr<media::VideoCaptureDevice::Client> | 223 std::unique_ptr<media::VideoCaptureDevice::Client> |
| 191 VideoCaptureController::NewDeviceClient() { | 224 VideoCaptureController::NewDeviceClient() { |
| 192 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 225 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 193 return base::MakeUnique<media::VideoCaptureDeviceClient>( | 226 return base::MakeUnique<media::VideoCaptureDeviceClient>( |
| 194 base::MakeUnique<VideoFrameReceiverOnIOThread>( | 227 base::MakeUnique<VideoFrameReceiverOnIOThread>( |
| 195 this->GetWeakPtrForIOThread()), | 228 this->GetWeakPtrForIOThread()), |
| 196 buffer_pool_, | 229 buffer_pool_, |
| 197 base::Bind(&CreateGpuJpegDecoder, | 230 base::Bind(&CreateGpuJpegDecoder, |
| 198 base::Bind(&VideoFrameReceiver::OnIncomingCapturedVideoFrame, | 231 base::Bind(&VideoFrameReceiver::OnIncomingCapturedVideoFrame, |
| 199 this->GetWeakPtrForIOThread()))); | 232 this->GetWeakPtrForIOThread()))); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 252 VideoCaptureControllerID id, | 285 VideoCaptureControllerID id, |
| 253 VideoCaptureControllerEventHandler* event_handler) { | 286 VideoCaptureControllerEventHandler* event_handler) { |
| 254 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 287 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 255 DVLOG(1) << "VideoCaptureController::RemoveClient, id " << id; | 288 DVLOG(1) << "VideoCaptureController::RemoveClient, id " << id; |
| 256 | 289 |
| 257 ControllerClient* client = FindClient(id, event_handler, controller_clients_); | 290 ControllerClient* client = FindClient(id, event_handler, controller_clients_); |
| 258 if (!client) | 291 if (!client) |
| 259 return kInvalidMediaCaptureSessionId; | 292 return kInvalidMediaCaptureSessionId; |
| 260 | 293 |
| 261 // Take back all buffers held by the |client|. | 294 // Take back all buffers held by the |client|. |
| 262 for (const auto& buffer : client->active_buffers) | 295 for (const auto& buffer_id : client->buffers_in_use) |
| 263 buffer_pool_->RelinquishConsumerHold(buffer.first, 1); | 296 buffer_id_to_state_map_.at(buffer_id).DecreaseConsumerCount(); |
| 264 client->active_buffers.clear(); | 297 client->buffers_in_use.clear(); |
| 265 | 298 |
| 266 int session_id = client->session_id; | 299 int session_id = client->session_id; |
| 267 controller_clients_.remove_if( | 300 controller_clients_.remove_if( |
| 268 [client](const std::unique_ptr<ControllerClient>& ptr) { | 301 [client](const std::unique_ptr<ControllerClient>& ptr) { |
| 269 return ptr.get() == client; | 302 return ptr.get() == client; |
| 270 }); | 303 }); |
| 271 | 304 |
| 272 return session_id; | 305 return session_id; |
| 273 } | 306 } |
| 274 | 307 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 VideoCaptureControllerEventHandler* event_handler, | 379 VideoCaptureControllerEventHandler* event_handler, |
| 347 int buffer_id, | 380 int buffer_id, |
| 348 const gpu::SyncToken& sync_token, | 381 const gpu::SyncToken& sync_token, |
| 349 double consumer_resource_utilization) { | 382 double consumer_resource_utilization) { |
| 350 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 383 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 351 | 384 |
| 352 ControllerClient* client = FindClient(id, event_handler, controller_clients_); | 385 ControllerClient* client = FindClient(id, event_handler, controller_clients_); |
| 353 | 386 |
| 354 // If this buffer is not held by this client, or this client doesn't exist | 387 // If this buffer is not held by this client, or this client doesn't exist |
| 355 // in controller, do nothing. | 388 // in controller, do nothing. |
| 356 ControllerClient::ActiveBufferMap::iterator iter; | 389 if (!client || (client->buffers_in_use.find(buffer_id) == |
| 357 if (!client || (iter = client->active_buffers.find(buffer_id)) == | 390 client->buffers_in_use.end())) { |
| 358 client->active_buffers.end()) { | |
| 359 NOTREACHED(); | 391 NOTREACHED(); |
| 360 return; | 392 return; |
| 361 } | 393 } |
| 362 | 394 |
| 363 // Set the RESOURCE_UTILIZATION to the maximum of those provided by each | 395 BufferState& buffer_state = buffer_id_to_state_map_.at(buffer_id); |
| 364 // consumer (via separate calls to this method that refer to the same | 396 buffer_state.RecordConsumerUtilization(consumer_resource_utilization); |
| 365 // VideoFrame). The producer of this VideoFrame may check this value, after | 397 buffer_state.DecreaseConsumerCount(); |
| 366 // all consumer holds are relinquished, to make quality versus performance | 398 client->buffers_in_use.erase(buffer_id); |
| 367 // trade-off decisions. | |
| 368 scoped_refptr<VideoFrame> frame = iter->second; | |
| 369 if (std::isfinite(consumer_resource_utilization) && | |
| 370 consumer_resource_utilization >= 0.0) { | |
| 371 double resource_utilization = -1.0; | |
| 372 if (frame->metadata()->GetDouble(VideoFrameMetadata::RESOURCE_UTILIZATION, | |
| 373 &resource_utilization)) { | |
| 374 frame->metadata()->SetDouble(VideoFrameMetadata::RESOURCE_UTILIZATION, | |
| 375 std::max(consumer_resource_utilization, | |
| 376 resource_utilization)); | |
| 377 } else { | |
| 378 frame->metadata()->SetDouble(VideoFrameMetadata::RESOURCE_UTILIZATION, | |
| 379 consumer_resource_utilization); | |
| 380 } | |
| 381 } | |
| 382 | |
| 383 client->active_buffers.erase(iter); | |
| 384 buffer_pool_->RelinquishConsumerHold(buffer_id, 1); | |
| 385 | |
| 386 #if defined(OS_ANDROID) | |
| 387 DCHECK(!sync_token.HasData()); | |
| 388 #endif | |
| 389 if (sync_token.HasData()) | |
| 390 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 391 base::Bind(&ReturnVideoFrame, frame, sync_token)); | |
| 392 } | 399 } |
| 393 | 400 |
| 394 const media::VideoCaptureFormat& | 401 const media::VideoCaptureFormat& |
| 395 VideoCaptureController::GetVideoCaptureFormat() const { | 402 VideoCaptureController::GetVideoCaptureFormat() const { |
| 396 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 403 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 397 return video_capture_format_; | 404 return video_capture_format_; |
| 398 } | 405 } |
| 399 | 406 |
| 400 VideoCaptureController::~VideoCaptureController() { | 407 VideoCaptureController::~VideoCaptureController() { |
| 401 } | 408 } |
| 402 | 409 |
| 403 void VideoCaptureController::OnIncomingCapturedVideoFrame( | 410 void VideoCaptureController::OnIncomingCapturedVideoFrame( |
| 404 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer, | 411 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer, |
| 405 scoped_refptr<VideoFrame> frame) { | 412 scoped_refptr<VideoFrame> frame) { |
| 406 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 413 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 407 const int buffer_id = buffer->id(); | 414 const int buffer_id = buffer->id(); |
| 408 DCHECK_NE(buffer_id, media::VideoCaptureBufferPool::kInvalidId); | 415 DCHECK_NE(buffer_id, media::VideoCaptureBufferPool::kInvalidId); |
| 409 | 416 |
| 410 int count = 0; | 417 // Insert if not exists. |
| 418 const auto it = | |
| 419 buffer_id_to_state_map_ | |
| 420 .insert(std::make_pair( | |
| 421 buffer_id, BufferState(buffer_id, buffer->frame_feedback_id(), | |
| 422 consumer_feedback_observer_.get(), | |
| 423 buffer_pool_, frame))) | |
| 424 .first; | |
| 425 BufferState& buffer_state = it->second; | |
| 426 DCHECK(buffer_state.HasZeroConsumerHoldCount()); | |
| 427 | |
| 411 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { | 428 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { |
| 412 if (!frame->metadata()->HasKey(VideoFrameMetadata::FRAME_RATE)) { | 429 if (!frame->metadata()->HasKey(VideoFrameMetadata::FRAME_RATE)) { |
| 413 frame->metadata()->SetDouble(VideoFrameMetadata::FRAME_RATE, | 430 frame->metadata()->SetDouble(VideoFrameMetadata::FRAME_RATE, |
| 414 video_capture_format_.frame_rate); | 431 video_capture_format_.frame_rate); |
| 415 } | 432 } |
| 416 std::unique_ptr<base::DictionaryValue> metadata( | 433 std::unique_ptr<base::DictionaryValue> metadata( |
| 417 new base::DictionaryValue()); | 434 new base::DictionaryValue()); |
| 418 frame->metadata()->MergeInternalValuesInto(metadata.get()); | 435 frame->metadata()->MergeInternalValuesInto(metadata.get()); |
| 419 | 436 |
| 420 // Only I420 and Y16 pixel formats are currently supported. | 437 // Only I420 and Y16 pixel formats are currently supported. |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 435 if (client->session_closed || client->paused) | 452 if (client->session_closed || client->paused) |
| 436 continue; | 453 continue; |
| 437 | 454 |
| 438 // On the first use of a buffer on a client, share the memory handles. | 455 // On the first use of a buffer on a client, share the memory handles. |
| 439 const bool is_new_buffer = client->known_buffers.insert(buffer_id).second; | 456 const bool is_new_buffer = client->known_buffers.insert(buffer_id).second; |
| 440 if (is_new_buffer) | 457 if (is_new_buffer) |
| 441 DoNewBufferOnIOThread(client.get(), buffer.get(), frame); | 458 DoNewBufferOnIOThread(client.get(), buffer.get(), frame); |
| 442 | 459 |
| 443 client->event_handler->OnBufferReady(client->controller_id, buffer_id, | 460 client->event_handler->OnBufferReady(client->controller_id, buffer_id, |
| 444 frame); | 461 frame); |
| 445 const bool inserted = | 462 const bool inserted = client->buffers_in_use.insert(buffer_id).second; |
| 446 client->active_buffers.insert(std::make_pair(buffer_id, frame)) | |
| 447 .second; | |
| 448 DCHECK(inserted) << "Unexpected duplicate buffer: " << buffer_id; | 463 DCHECK(inserted) << "Unexpected duplicate buffer: " << buffer_id; |
| 449 count++; | 464 buffer_state.IncreaseConsumerCount(); |
| 450 } | 465 } |
| 451 } | 466 } |
| 452 | 467 |
| 453 if (!has_received_frames_) { | 468 if (!has_received_frames_) { |
| 454 UMA_HISTOGRAM_COUNTS("Media.VideoCapture.Width", | 469 UMA_HISTOGRAM_COUNTS("Media.VideoCapture.Width", |
| 455 frame->visible_rect().width()); | 470 frame->visible_rect().width()); |
| 456 UMA_HISTOGRAM_COUNTS("Media.VideoCapture.Height", | 471 UMA_HISTOGRAM_COUNTS("Media.VideoCapture.Height", |
| 457 frame->visible_rect().height()); | 472 frame->visible_rect().height()); |
| 458 UMA_HISTOGRAM_ASPECT_RATIO("Media.VideoCapture.AspectRatio", | 473 UMA_HISTOGRAM_ASPECT_RATIO("Media.VideoCapture.AspectRatio", |
| 459 frame->visible_rect().width(), | 474 frame->visible_rect().width(), |
| 460 frame->visible_rect().height()); | 475 frame->visible_rect().height()); |
| 461 double frame_rate = 0.0f; | 476 double frame_rate = 0.0f; |
| 462 if (!frame->metadata()->GetDouble(VideoFrameMetadata::FRAME_RATE, | 477 if (!frame->metadata()->GetDouble(VideoFrameMetadata::FRAME_RATE, |
| 463 &frame_rate)) { | 478 &frame_rate)) { |
| 464 frame_rate = video_capture_format_.frame_rate; | 479 frame_rate = video_capture_format_.frame_rate; |
| 465 } | 480 } |
| 466 UMA_HISTOGRAM_COUNTS("Media.VideoCapture.FrameRate", frame_rate); | 481 UMA_HISTOGRAM_COUNTS("Media.VideoCapture.FrameRate", frame_rate); |
| 467 has_received_frames_ = true; | 482 has_received_frames_ = true; |
| 468 } | 483 } |
| 469 | |
| 470 buffer_pool_->HoldForConsumers(buffer_id, count); | |
| 471 } | 484 } |
| 472 | 485 |
| 473 void VideoCaptureController::OnError() { | 486 void VideoCaptureController::OnError() { |
| 474 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 487 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 475 state_ = VIDEO_CAPTURE_STATE_ERROR; | 488 state_ = VIDEO_CAPTURE_STATE_ERROR; |
| 476 | 489 |
| 477 for (const auto& client : controller_clients_) { | 490 for (const auto& client : controller_clients_) { |
| 478 if (client->session_closed) | 491 if (client->session_closed) |
| 479 continue; | 492 continue; |
| 480 client->event_handler->OnError(client->controller_id); | 493 client->event_handler->OnError(client->controller_id); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 491 | 504 |
| 492 for (const auto& client : controller_clients_) { | 505 for (const auto& client : controller_clients_) { |
| 493 if (client->session_closed) | 506 if (client->session_closed) |
| 494 continue; | 507 continue; |
| 495 | 508 |
| 496 if (client->known_buffers.erase(buffer_id_to_drop)) { | 509 if (client->known_buffers.erase(buffer_id_to_drop)) { |
| 497 client->event_handler->OnBufferDestroyed(client->controller_id, | 510 client->event_handler->OnBufferDestroyed(client->controller_id, |
| 498 buffer_id_to_drop); | 511 buffer_id_to_drop); |
| 499 } | 512 } |
| 500 } | 513 } |
| 514 | |
| 515 buffer_id_to_state_map_.erase(buffer_id_to_drop); | |
| 501 } | 516 } |
| 502 | 517 |
| 503 void VideoCaptureController::DoNewBufferOnIOThread( | 518 void VideoCaptureController::DoNewBufferOnIOThread( |
| 504 ControllerClient* client, | 519 ControllerClient* client, |
| 505 media::VideoCaptureDevice::Client::Buffer* buffer, | 520 media::VideoCaptureDevice::Client::Buffer* buffer, |
| 506 const scoped_refptr<media::VideoFrame>& frame) { | 521 const scoped_refptr<media::VideoFrame>& frame) { |
| 507 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 522 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 508 DCHECK_EQ(media::VideoFrame::STORAGE_SHMEM, frame->storage_type()); | 523 DCHECK_EQ(media::VideoFrame::STORAGE_SHMEM, frame->storage_type()); |
| 509 | 524 |
| 510 const int buffer_id = buffer->id(); | 525 const int buffer_id = buffer->id(); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 530 int session_id, | 545 int session_id, |
| 531 const ControllerClients& clients) { | 546 const ControllerClients& clients) { |
| 532 for (const auto& client : clients) { | 547 for (const auto& client : clients) { |
| 533 if (client->session_id == session_id) | 548 if (client->session_id == session_id) |
| 534 return client.get(); | 549 return client.get(); |
| 535 } | 550 } |
| 536 return nullptr; | 551 return nullptr; |
| 537 } | 552 } |
| 538 | 553 |
| 539 } // namespace content | 554 } // namespace content |
| OLD | NEW |