| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "media/base/renderer_factory_selector.h" | 5 #include "media/base/renderer_factory_selector.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 | 8 |
| 9 namespace media { | 9 namespace media { |
| 10 | 10 |
| 11 RendererFactorySelector::RendererFactorySelector() {} | 11 RendererFactorySelector::RendererFactorySelector() {} |
| 12 | 12 |
| 13 RendererFactorySelector::~RendererFactorySelector() {} | 13 RendererFactorySelector::~RendererFactorySelector() {} |
| 14 | 14 |
| 15 void RendererFactorySelector::AddFactory( | 15 void RendererFactorySelector::AddFactory( |
| 16 FactoryType type, | 16 FactoryType type, |
| 17 std::unique_ptr<RendererFactory> factory) { | 17 std::unique_ptr<RendererFactory> factory) { |
| 18 DCHECK(!factories_.count(type)); | 18 DCHECK(!factories_.count(type)); |
| 19 | 19 |
| 20 factories_.emplace(type, std::move(factory)); | 20 factories_.emplace(type, std::move(factory)); |
| 21 } | 21 } |
| 22 | 22 |
| 23 void RendererFactorySelector::SetBaseFactoryType(FactoryType type) { | 23 void RendererFactorySelector::SetBaseFactoryType(FactoryType type) { |
| 24 DCHECK(factories_.count(type)); | 24 DCHECK(factories_.count(type)); |
| 25 base_factory_type_ = type; | 25 base_factory_type_ = type; |
| 26 current_factory_needs_update_ = true; | 26 current_factory_needs_update_ = true; |
| 27 } | 27 } |
| 28 | 28 |
| 29 // For the moment, this method should only be called once or twice. | |
| 30 // This method will be regularly called whenever the logic in choosing a | |
| 31 // renderer type is moved out of the AdaptiveRendererFactory, into this method. | |
| 32 void RendererFactorySelector::UpdateCurrentFactory() { | 29 void RendererFactorySelector::UpdateCurrentFactory() { |
| 33 DCHECK_NE(base_factory_type_, FactoryType::UNKNOWN); | 30 DCHECK_NE(base_factory_type_, FactoryType::UNKNOWN); |
| 34 FactoryType next_factory_type = base_factory_type_; | 31 FactoryType next_factory_type = base_factory_type_; |
| 35 | 32 |
| 36 if (use_media_player_) | 33 if (use_media_player_) |
| 37 next_factory_type = FactoryType::MEDIA_PLAYER; | 34 next_factory_type = FactoryType::MEDIA_PLAYER; |
| 38 | 35 |
| 36 if (use_courier_cb_ && use_courier_cb_.Run()) |
| 37 next_factory_type = FactoryType::COURIER; |
| 38 |
| 39 auto it = factories_.find(next_factory_type); | 39 auto it = factories_.find(next_factory_type); |
| 40 | 40 |
| 41 if (it == factories_.end()) { | 41 if (it == factories_.end()) { |
| 42 NOTREACHED(); | 42 NOTREACHED(); |
| 43 return; | 43 return; |
| 44 } | 44 } |
| 45 | 45 |
| 46 DVLOG(1) << __func__ << " Selected factory type: " << it->first; | 46 DVLOG(1) << __func__ << " Selected factory type: " << it->first; |
| 47 current_factory_ = it->second.get(); | 47 current_factory_ = it->second.get(); |
| 48 | 48 |
| 49 current_factory_needs_update_ = false; | 49 // Update |current_factory_| every time if we are using the COURIER factory. |
| 50 current_factory_needs_update_ = !!use_courier_cb_; |
| 50 } | 51 } |
| 51 | 52 |
| 52 RendererFactory* RendererFactorySelector::GetCurrentFactory() { | 53 RendererFactory* RendererFactorySelector::GetCurrentFactory() { |
| 53 if (current_factory_needs_update_) | 54 if (current_factory_needs_update_) |
| 54 UpdateCurrentFactory(); | 55 UpdateCurrentFactory(); |
| 55 | 56 |
| 56 DCHECK(current_factory_); | 57 DCHECK(current_factory_); |
| 57 return current_factory_; | 58 return current_factory_; |
| 58 } | 59 } |
| 59 | 60 |
| 60 #if defined(OS_ANDROID) | 61 #if defined(OS_ANDROID) |
| 61 void RendererFactorySelector::SetUseMediaPlayer(bool use_media_player) { | 62 void RendererFactorySelector::SetUseMediaPlayer(bool use_media_player) { |
| 62 use_media_player_ = use_media_player; | 63 use_media_player_ = use_media_player; |
| 63 current_factory_needs_update_ = true; | 64 current_factory_needs_update_ = true; |
| 64 } | 65 } |
| 65 #endif | 66 #endif |
| 66 | 67 |
| 68 void RendererFactorySelector::SetUseCourierCB(UseCourierCB use_courier_cb) { |
| 69 DCHECK(!use_courier_cb_); |
| 70 use_courier_cb_ = use_courier_cb; |
| 71 current_factory_needs_update_ = true; |
| 72 } |
| 73 |
| 67 } // namespace media | 74 } // namespace media |
| OLD | NEW |