| 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 namespace content { | 39 namespace content { |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 static const int kInfiniteRatio = 99999; | 43 static const int kInfiniteRatio = 99999; |
| 44 | 44 |
| 45 #define UMA_HISTOGRAM_ASPECT_RATIO(name, width, height) \ | 45 #define UMA_HISTOGRAM_ASPECT_RATIO(name, width, height) \ |
| 46 UMA_HISTOGRAM_SPARSE_SLOWLY( \ | 46 UMA_HISTOGRAM_SPARSE_SLOWLY( \ |
| 47 name, (height) ? ((width)*100) / (height) : kInfiniteRatio); | 47 name, (height) ? ((width)*100) / (height) : kInfiniteRatio); |
| 48 | 48 |
| 49 void CallOnError(VideoCaptureControllerEventHandler* client, |
| 50 VideoCaptureControllerID id) { |
| 51 client->OnError(id); |
| 52 } |
| 53 |
| 54 void CallOnStarted(VideoCaptureControllerEventHandler* client, |
| 55 VideoCaptureControllerID id) { |
| 56 client->OnStarted(id); |
| 57 } |
| 58 |
| 59 void CallOnStartedUsingGpuDecode(VideoCaptureControllerEventHandler* client, |
| 60 VideoCaptureControllerID id) { |
| 61 client->OnStartedUsingGpuDecode(id); |
| 62 } |
| 63 |
| 49 } // anonymous namespace | 64 } // anonymous namespace |
| 50 | 65 |
| 51 struct VideoCaptureController::ControllerClient { | 66 struct VideoCaptureController::ControllerClient { |
| 52 ControllerClient(VideoCaptureControllerID id, | 67 ControllerClient(VideoCaptureControllerID id, |
| 53 VideoCaptureControllerEventHandler* handler, | 68 VideoCaptureControllerEventHandler* handler, |
| 54 media::VideoCaptureSessionId session_id, | 69 media::VideoCaptureSessionId session_id, |
| 55 const media::VideoCaptureParams& params) | 70 const media::VideoCaptureParams& params) |
| 56 : controller_id(id), | 71 : controller_id(id), |
| 57 event_handler(handler), | 72 event_handler(handler), |
| 58 session_id(session_id), | 73 session_id(session_id), |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 const size_t mapped_size = | 406 const size_t mapped_size = |
| 392 media::VideoCaptureFormat(frame_info->coded_size, 0.0f, | 407 media::VideoCaptureFormat(frame_info->coded_size, 0.0f, |
| 393 frame_info->pixel_format, | 408 frame_info->pixel_format, |
| 394 frame_info->storage_type) | 409 frame_info->storage_type) |
| 395 .ImageAllocationSize(); | 410 .ImageAllocationSize(); |
| 396 client->event_handler->OnBufferCreated( | 411 client->event_handler->OnBufferCreated( |
| 397 client->controller_id, buffer_context_iter->CloneHandle(), | 412 client->controller_id, buffer_context_iter->CloneHandle(), |
| 398 mapped_size, buffer_context_id); | 413 mapped_size, buffer_context_id); |
| 399 } | 414 } |
| 400 | 415 |
| 401 client->event_handler->OnBufferReady(client->controller_id, | |
| 402 buffer_context_id, frame_info); | |
| 403 | |
| 404 if (!base::ContainsValue(client->buffers_in_use, buffer_context_id)) | 416 if (!base::ContainsValue(client->buffers_in_use, buffer_context_id)) |
| 405 client->buffers_in_use.push_back(buffer_context_id); | 417 client->buffers_in_use.push_back(buffer_context_id); |
| 406 else | 418 else |
| 407 NOTREACHED() << "Unexpected duplicate buffer: " << buffer_context_id; | 419 NOTREACHED() << "Unexpected duplicate buffer: " << buffer_context_id; |
| 408 | 420 |
| 409 buffer_context_iter->IncreaseConsumerCount(); | 421 buffer_context_iter->IncreaseConsumerCount(); |
| 422 client->event_handler->OnBufferReady(client->controller_id, |
| 423 buffer_context_id, frame_info); |
| 410 } | 424 } |
| 411 if (buffer_context_iter->HasConsumers()) { | 425 if (buffer_context_iter->HasConsumers()) { |
| 412 buffer_context_iter->set_read_permission( | 426 buffer_context_iter->set_read_permission( |
| 413 std::move(buffer_read_permission)); | 427 std::move(buffer_read_permission)); |
| 414 } | 428 } |
| 415 } | 429 } |
| 416 | 430 |
| 417 if (!has_received_frames_) { | 431 if (!has_received_frames_) { |
| 418 UMA_HISTOGRAM_COUNTS("Media.VideoCapture.Width", | 432 UMA_HISTOGRAM_COUNTS("Media.VideoCapture.Width", |
| 419 frame_info->coded_size.width()); | 433 frame_info->coded_size.width()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 444 // because it contains the consumer hold. | 458 // because it contains the consumer hold. |
| 445 if (!buffer_context_iter->HasConsumers()) | 459 if (!buffer_context_iter->HasConsumers()) |
| 446 ReleaseBufferContext(buffer_context_iter); | 460 ReleaseBufferContext(buffer_context_iter); |
| 447 else | 461 else |
| 448 buffer_context_iter->set_is_retired(); | 462 buffer_context_iter->set_is_retired(); |
| 449 } | 463 } |
| 450 | 464 |
| 451 void VideoCaptureController::OnError() { | 465 void VideoCaptureController::OnError() { |
| 452 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 466 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 453 state_ = VIDEO_CAPTURE_STATE_ERROR; | 467 state_ = VIDEO_CAPTURE_STATE_ERROR; |
| 454 | 468 PerformForClientsWithOpenSession(base::Bind(&CallOnError)); |
| 455 for (const auto& client : controller_clients_) { | |
| 456 if (client->session_closed) | |
| 457 continue; | |
| 458 client->event_handler->OnError(client->controller_id); | |
| 459 } | |
| 460 } | 469 } |
| 461 | 470 |
| 462 void VideoCaptureController::OnLog(const std::string& message) { | 471 void VideoCaptureController::OnLog(const std::string& message) { |
| 463 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 472 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 464 MediaStreamManager::SendMessageToNativeLog("Video capture: " + message); | 473 MediaStreamManager::SendMessageToNativeLog("Video capture: " + message); |
| 465 } | 474 } |
| 466 | 475 |
| 467 void VideoCaptureController::OnStarted() { | 476 void VideoCaptureController::OnStarted() { |
| 468 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 477 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 469 state_ = VIDEO_CAPTURE_STATE_STARTED; | 478 state_ = VIDEO_CAPTURE_STATE_STARTED; |
| 479 PerformForClientsWithOpenSession(base::Bind(&CallOnStarted)); |
| 480 } |
| 470 | 481 |
| 471 for (const auto& client : controller_clients_) { | 482 void VideoCaptureController::OnStartedUsingGpuDecode() { |
| 472 if (client->session_closed) | 483 PerformForClientsWithOpenSession(base::Bind(&CallOnStartedUsingGpuDecode)); |
| 473 continue; | |
| 474 client->event_handler->OnStarted(client->controller_id); | |
| 475 } | |
| 476 } | 484 } |
| 477 | 485 |
| 478 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( | 486 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( |
| 479 VideoCaptureControllerID id, | 487 VideoCaptureControllerID id, |
| 480 VideoCaptureControllerEventHandler* handler, | 488 VideoCaptureControllerEventHandler* handler, |
| 481 const ControllerClients& clients) { | 489 const ControllerClients& clients) { |
| 482 for (const auto& client : clients) { | 490 for (const auto& client : clients) { |
| 483 if (client->controller_id == id && client->event_handler == handler) | 491 if (client->controller_id == id && client->event_handler == handler) |
| 484 return client.get(); | 492 return client.get(); |
| 485 } | 493 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 buffer_context_iter->buffer_context_id()); | 548 buffer_context_iter->buffer_context_id()); |
| 541 if (entry_iter != std::end(client->known_buffer_context_ids)) { | 549 if (entry_iter != std::end(client->known_buffer_context_ids)) { |
| 542 client->known_buffer_context_ids.erase(entry_iter); | 550 client->known_buffer_context_ids.erase(entry_iter); |
| 543 client->event_handler->OnBufferDestroyed( | 551 client->event_handler->OnBufferDestroyed( |
| 544 client->controller_id, buffer_context_iter->buffer_context_id()); | 552 client->controller_id, buffer_context_iter->buffer_context_id()); |
| 545 } | 553 } |
| 546 } | 554 } |
| 547 buffer_contexts_.erase(buffer_context_iter); | 555 buffer_contexts_.erase(buffer_context_iter); |
| 548 } | 556 } |
| 549 | 557 |
| 558 void VideoCaptureController::PerformForClientsWithOpenSession( |
| 559 EventHandlerAction action) { |
| 560 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 561 for (const auto& client : controller_clients_) { |
| 562 if (client->session_closed) |
| 563 continue; |
| 564 action.Run(client->event_handler, client->controller_id); |
| 565 } |
| 566 } |
| 567 |
| 550 } // namespace content | 568 } // namespace content |
| OLD | NEW |