tguilbert | 70d2a00a | 2017-04-25 00:30:44 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef MEDIA_BASE_RENDERER_FACTORY_SELECTOR_H_ |
| 6 | #define MEDIA_BASE_RENDERER_FACTORY_SELECTOR_H_ |
| 7 | |
tguilbert | 16d9d7d | 2017-05-05 03:24:42 | [diff] [blame] | 8 | #include "base/callback.h" |
tguilbert | 70d2a00a | 2017-04-25 00:30:44 | [diff] [blame] | 9 | #include "base/optional.h" |
| 10 | #include "media/base/renderer_factory.h" |
| 11 | |
| 12 | namespace media { |
| 13 | |
| 14 | // RendererFactorySelector owns RendererFactory instances used within WMPI. |
| 15 | // Its purpose is to aggregate the signals and centralize the logic behind |
| 16 | // choosing which RendererFactory should be used when creating a new Renderer. |
| 17 | class MEDIA_EXPORT RendererFactorySelector { |
| 18 | public: |
tguilbert | 16d9d7d | 2017-05-05 03:24:42 | [diff] [blame] | 19 | using QueryIsRemotingActiveCB = base::Callback<bool()>; |
Thomas Guilbert | 35a70ef | 2018-04-21 02:20:49 | [diff] [blame] | 20 | using QueryIsFlingingActiveCB = base::Callback<bool()>; |
tguilbert | 16d9d7d | 2017-05-05 03:24:42 | [diff] [blame] | 21 | |
tguilbert | 70d2a00a | 2017-04-25 00:30:44 | [diff] [blame] | 22 | enum FactoryType { |
| 23 | DEFAULT, // DefaultRendererFactory. |
| 24 | MOJO, // MojoRendererFactory. |
| 25 | MEDIA_PLAYER, // MediaPlayerRendererClientFactory. |
tguilbert | 16d9d7d | 2017-05-05 03:24:42 | [diff] [blame] | 26 | COURIER, // CourierRendererFactory. |
Thomas Guilbert | 35a70ef | 2018-04-21 02:20:49 | [diff] [blame] | 27 | FLINGING, // FlingingRendererClientFactory |
| 28 | FACTORY_TYPE_MAX = FLINGING, |
tguilbert | 70d2a00a | 2017-04-25 00:30:44 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | RendererFactorySelector(); |
| 32 | ~RendererFactorySelector(); |
| 33 | |
| 34 | // NOTE: There should be at most one factory per factory type. |
| 35 | void AddFactory(FactoryType type, std::unique_ptr<RendererFactory> factory); |
| 36 | |
| 37 | // Sets the base factory to be returned, when there are no signals telling us |
| 38 | // to select any specific factory. |
| 39 | // NOTE: |type| can be different than FactoryType::DEFAULT. DEFAULT is used to |
| 40 | // identify the DefaultRendererFactory, not to indicate that a factory should |
| 41 | // be used by default. |
| 42 | void SetBaseFactoryType(FactoryType type); |
| 43 | |
tguilbert | 75e2bf6 | 2017-04-26 20:13:12 | [diff] [blame] | 44 | // Updates |current_factory_| if necessary, and returns its value. |
| 45 | // NOTE: SetBaseFactoryType() must be called before calling this method. |
tguilbert | 70d2a00a | 2017-04-25 00:30:44 | [diff] [blame] | 46 | RendererFactory* GetCurrentFactory(); |
| 47 | |
tguilbert | 75e2bf6 | 2017-04-26 20:13:12 | [diff] [blame] | 48 | #if defined(OS_ANDROID) |
| 49 | // Sets whether we should be using the MEDIA_PLAYER factory instead of the |
| 50 | // base factory. |
| 51 | void SetUseMediaPlayer(bool use_media_player); |
| 52 | #endif |
| 53 | |
tguilbert | 16d9d7d | 2017-05-05 03:24:42 | [diff] [blame] | 54 | // Sets the callback to query whether we are currently remoting, and if we |
| 55 | // should temporarily use the COURIER factory. |
| 56 | void SetQueryIsRemotingActiveCB( |
| 57 | QueryIsRemotingActiveCB query_is_remoting_active_cb); |
tguilbert | 75e2bf6 | 2017-04-26 20:13:12 | [diff] [blame] | 58 | |
Thomas Guilbert | 35a70ef | 2018-04-21 02:20:49 | [diff] [blame] | 59 | // Sets the callback to query whether we are currently flinging media, and if |
| 60 | // we should temporarily use the FLINGING factory. |
| 61 | void SetQueryIsFlingingActiveCB( |
| 62 | QueryIsFlingingActiveCB query_is_flinging_active_cb); |
| 63 | |
tguilbert | 16d9d7d | 2017-05-05 03:24:42 | [diff] [blame] | 64 | private: |
tguilbert | 75e2bf6 | 2017-04-26 20:13:12 | [diff] [blame] | 65 | bool use_media_player_ = false; |
| 66 | |
tguilbert | 16d9d7d | 2017-05-05 03:24:42 | [diff] [blame] | 67 | QueryIsRemotingActiveCB query_is_remoting_active_cb_; |
Thomas Guilbert | 35a70ef | 2018-04-21 02:20:49 | [diff] [blame] | 68 | QueryIsFlingingActiveCB query_is_flinging_active_cb_; |
tguilbert | 75e2bf6 | 2017-04-26 20:13:12 | [diff] [blame] | 69 | |
tguilbert | 70d2a00a | 2017-04-25 00:30:44 | [diff] [blame] | 70 | base::Optional<FactoryType> base_factory_type_; |
| 71 | std::unique_ptr<RendererFactory> factories_[FACTORY_TYPE_MAX + 1]; |
| 72 | DISALLOW_COPY_AND_ASSIGN(RendererFactorySelector); |
| 73 | }; |
| 74 | |
| 75 | } // namespace media |
| 76 | |
| 77 | #endif // MEDIA_BASE_RENDERER_FACTORY_H_ |