blob: 6d929b1d4c737fcda778d0a352f3638e62b20430 [file] [log] [blame]
tguilbert70d2a00a2017-04-25 00:30:441// 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
tguilbert16d9d7d2017-05-05 03:24:428#include "base/callback.h"
tguilbert70d2a00a2017-04-25 00:30:449#include "base/optional.h"
10#include "media/base/renderer_factory.h"
11
12namespace 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.
17class MEDIA_EXPORT RendererFactorySelector {
18 public:
tguilbert16d9d7d2017-05-05 03:24:4219 using QueryIsRemotingActiveCB = base::Callback<bool()>;
Thomas Guilbert35a70ef2018-04-21 02:20:4920 using QueryIsFlingingActiveCB = base::Callback<bool()>;
tguilbert16d9d7d2017-05-05 03:24:4221
tguilbert70d2a00a2017-04-25 00:30:4422 enum FactoryType {
23 DEFAULT, // DefaultRendererFactory.
24 MOJO, // MojoRendererFactory.
25 MEDIA_PLAYER, // MediaPlayerRendererClientFactory.
tguilbert16d9d7d2017-05-05 03:24:4226 COURIER, // CourierRendererFactory.
Thomas Guilbert35a70ef2018-04-21 02:20:4927 FLINGING, // FlingingRendererClientFactory
28 FACTORY_TYPE_MAX = FLINGING,
tguilbert70d2a00a2017-04-25 00:30:4429 };
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
tguilbert75e2bf62017-04-26 20:13:1244 // Updates |current_factory_| if necessary, and returns its value.
45 // NOTE: SetBaseFactoryType() must be called before calling this method.
tguilbert70d2a00a2017-04-25 00:30:4446 RendererFactory* GetCurrentFactory();
47
tguilbert75e2bf62017-04-26 20:13:1248#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
tguilbert16d9d7d2017-05-05 03:24:4254 // 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);
tguilbert75e2bf62017-04-26 20:13:1258
Thomas Guilbert35a70ef2018-04-21 02:20:4959 // 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
tguilbert16d9d7d2017-05-05 03:24:4264 private:
tguilbert75e2bf62017-04-26 20:13:1265 bool use_media_player_ = false;
66
tguilbert16d9d7d2017-05-05 03:24:4267 QueryIsRemotingActiveCB query_is_remoting_active_cb_;
Thomas Guilbert35a70ef2018-04-21 02:20:4968 QueryIsFlingingActiveCB query_is_flinging_active_cb_;
tguilbert75e2bf62017-04-26 20:13:1269
tguilbert70d2a00a2017-04-25 00:30:4470 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_