| 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 | |
| 64 } // anonymous namespace | 49 } // anonymous namespace |
| 65 | 50 |
| 66 struct VideoCaptureController::ControllerClient { | 51 struct VideoCaptureController::ControllerClient { |
| 67 ControllerClient(VideoCaptureControllerID id, | 52 ControllerClient(VideoCaptureControllerID id, |
| 68 VideoCaptureControllerEventHandler* handler, | 53 VideoCaptureControllerEventHandler* handler, |
| 69 media::VideoCaptureSessionId session_id, | 54 media::VideoCaptureSessionId session_id, |
| 70 const media::VideoCaptureParams& params) | 55 const media::VideoCaptureParams& params) |
| 71 : controller_id(id), | 56 : controller_id(id), |
| 72 event_handler(handler), | 57 event_handler(handler), |
| 73 session_id(session_id), | 58 session_id(session_id), |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 // because it contains the consumer hold. | 444 // because it contains the consumer hold. |
| 460 if (!buffer_context_iter->HasConsumers()) | 445 if (!buffer_context_iter->HasConsumers()) |
| 461 ReleaseBufferContext(buffer_context_iter); | 446 ReleaseBufferContext(buffer_context_iter); |
| 462 else | 447 else |
| 463 buffer_context_iter->set_is_retired(); | 448 buffer_context_iter->set_is_retired(); |
| 464 } | 449 } |
| 465 | 450 |
| 466 void VideoCaptureController::OnError() { | 451 void VideoCaptureController::OnError() { |
| 467 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 452 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 468 state_ = VIDEO_CAPTURE_STATE_ERROR; | 453 state_ = VIDEO_CAPTURE_STATE_ERROR; |
| 469 PerformForClientsWithOpenSession(base::Bind(&CallOnError)); | 454 |
| 455 for (const auto& client : controller_clients_) { |
| 456 if (client->session_closed) |
| 457 continue; |
| 458 client->event_handler->OnError(client->controller_id); |
| 459 } |
| 470 } | 460 } |
| 471 | 461 |
| 472 void VideoCaptureController::OnLog(const std::string& message) { | 462 void VideoCaptureController::OnLog(const std::string& message) { |
| 473 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 463 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 474 MediaStreamManager::SendMessageToNativeLog("Video capture: " + message); | 464 MediaStreamManager::SendMessageToNativeLog("Video capture: " + message); |
| 475 } | 465 } |
| 476 | 466 |
| 477 void VideoCaptureController::OnStarted() { | 467 void VideoCaptureController::OnStarted() { |
| 478 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 468 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 479 state_ = VIDEO_CAPTURE_STATE_STARTED; | 469 state_ = VIDEO_CAPTURE_STATE_STARTED; |
| 480 PerformForClientsWithOpenSession(base::Bind(&CallOnStarted)); | |
| 481 } | |
| 482 | 470 |
| 483 void VideoCaptureController::OnStartedUsingGpuDecode() { | 471 for (const auto& client : controller_clients_) { |
| 484 PerformForClientsWithOpenSession(base::Bind(&CallOnStartedUsingGpuDecode)); | 472 if (client->session_closed) |
| 473 continue; |
| 474 client->event_handler->OnStarted(client->controller_id); |
| 475 } |
| 485 } | 476 } |
| 486 | 477 |
| 487 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( | 478 VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( |
| 488 VideoCaptureControllerID id, | 479 VideoCaptureControllerID id, |
| 489 VideoCaptureControllerEventHandler* handler, | 480 VideoCaptureControllerEventHandler* handler, |
| 490 const ControllerClients& clients) { | 481 const ControllerClients& clients) { |
| 491 for (const auto& client : clients) { | 482 for (const auto& client : clients) { |
| 492 if (client->controller_id == id && client->event_handler == handler) | 483 if (client->controller_id == id && client->event_handler == handler) |
| 493 return client.get(); | 484 return client.get(); |
| 494 } | 485 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 buffer_context_iter->buffer_context_id()); | 540 buffer_context_iter->buffer_context_id()); |
| 550 if (entry_iter != std::end(client->known_buffer_context_ids)) { | 541 if (entry_iter != std::end(client->known_buffer_context_ids)) { |
| 551 client->known_buffer_context_ids.erase(entry_iter); | 542 client->known_buffer_context_ids.erase(entry_iter); |
| 552 client->event_handler->OnBufferDestroyed( | 543 client->event_handler->OnBufferDestroyed( |
| 553 client->controller_id, buffer_context_iter->buffer_context_id()); | 544 client->controller_id, buffer_context_iter->buffer_context_id()); |
| 554 } | 545 } |
| 555 } | 546 } |
| 556 buffer_contexts_.erase(buffer_context_iter); | 547 buffer_contexts_.erase(buffer_context_iter); |
| 557 } | 548 } |
| 558 | 549 |
| 559 void VideoCaptureController::PerformForClientsWithOpenSession( | |
| 560 EventHandlerAction action) { | |
| 561 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 562 for (const auto& client : controller_clients_) { | |
| 563 if (client->session_closed) | |
| 564 continue; | |
| 565 action.Run(client->event_handler, client->controller_id); | |
| 566 } | |
| 567 } | |
| 568 | |
| 569 } // namespace content | 550 } // namespace content |
| OLD | NEW |