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