| 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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 // because it contains the consumer hold. | 456 // because it contains the consumer hold. |
| 442 if (!buffer_context_iter->HasConsumers()) | 457 if (!buffer_context_iter->HasConsumers()) |
| 443 ReleaseBufferContext(buffer_context_iter); | 458 ReleaseBufferContext(buffer_context_iter); |
| 444 else | 459 else |
| 445 buffer_context_iter->set_is_retired(); | 460 buffer_context_iter->set_is_retired(); |
| 446 } | 461 } |
| 447 | 462 |
| 448 void VideoCaptureController::OnError() { | 463 void VideoCaptureController::OnError() { |
| 449 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 464 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 450 state_ = VIDEO_CAPTURE_STATE_ERROR; | 465 state_ = VIDEO_CAPTURE_STATE_ERROR; |
| 451 | 466 PerformForClientsWithOpenSession(base::Bind(&CallOnError)); |
| 452 for (const auto& client : controller_clients_) { | |
| 453 if (client->session_closed) | |
| 454 continue; | |
| 455 client->event_handler->OnError(client->controller_id); | |
| 456 } | |
| 457 } | 467 } |
| 458 | 468 |
| 459 void VideoCaptureController::OnLog(const std::string& message) { | 469 void VideoCaptureController::OnLog(const std::string& message) { |
| 460 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 470 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 461 MediaStreamManager::SendMessageToNativeLog("Video capture: " + message); | 471 MediaStreamManager::SendMessageToNativeLog("Video capture: " + message); |
| 462 } | 472 } |
| 463 | 473 |
| 464 void VideoCaptureController::OnStarted() { | 474 void VideoCaptureController::OnStarted() { |
| 465 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 475 PerformForClientsWithOpenSession(base::Bind(&CallOnStarted)); |
| 476 } |
| 466 | 477 |
| 467 for (const auto& client : controller_clients_) { | 478 void VideoCaptureController::OnStartedUsingGpuDecode() { |
| 468 if (client->session_closed) | 479 PerformForClientsWithOpenSession(base::Bind(&CallOnStartedUsingGpuDecode)); |
| 469 continue; | |
| 470 client->event_handler->OnStarted(client->controller_id); | |
| 471 } | |
| 472 } | 480 } |
| 473 | 481 |
| 474 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( | 482 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( |
| 475 VideoCaptureControllerID id, | 483 VideoCaptureControllerID id, |
| 476 VideoCaptureControllerEventHandler* handler, | 484 VideoCaptureControllerEventHandler* handler, |
| 477 const ControllerClients& clients) { | 485 const ControllerClients& clients) { |
| 478 for (const auto& client : clients) { | 486 for (const auto& client : clients) { |
| 479 if (client->controller_id == id && client->event_handler == handler) | 487 if (client->controller_id == id && client->event_handler == handler) |
| 480 return client.get(); | 488 return client.get(); |
| 481 } | 489 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 buffer_context_iter->buffer_context_id()); | 544 buffer_context_iter->buffer_context_id()); |
| 537 if (entry_iter != std::end(client->known_buffer_context_ids)) { | 545 if (entry_iter != std::end(client->known_buffer_context_ids)) { |
| 538 client->known_buffer_context_ids.erase(entry_iter); | 546 client->known_buffer_context_ids.erase(entry_iter); |
| 539 client->event_handler->OnBufferDestroyed( | 547 client->event_handler->OnBufferDestroyed( |
| 540 client->controller_id, buffer_context_iter->buffer_context_id()); | 548 client->controller_id, buffer_context_iter->buffer_context_id()); |
| 541 } | 549 } |
| 542 } | 550 } |
| 543 buffer_contexts_.erase(buffer_context_iter); | 551 buffer_contexts_.erase(buffer_context_iter); |
| 544 } | 552 } |
| 545 | 553 |
| 554 void VideoCaptureController::PerformForClientsWithOpenSession( |
| 555 EventHandlerAction action) { |
| 556 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 557 for (const auto& client : controller_clients_) { |
| 558 if (client->session_closed) |
| 559 continue; |
| 560 action.Run(client->event_handler, client->controller_id); |
| 561 } |
| 562 } |
| 563 |
| 546 } // namespace content | 564 } // namespace content |
| OLD | NEW |