Ocean
AMedium.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_MEDIA_ANDROID_A_MEDIUM_H
9 #define META_OCEAN_MEDIA_ANDROID_A_MEDIUM_H
10 
12 
13 #include "ocean/base/Singleton.h"
14 
15 #include "ocean/media/Medium.h"
16 
17 #include <jni.h>
18 
19 #include <SLES/OpenSLES.h>
20 
21 namespace Ocean
22 {
23 
24 namespace Media
25 {
26 
27 namespace Android
28 {
29 
30 /**
31  * This class implements the base class for all Medium objects in the Android library.
32  * @ingroup mediaandroid
33  */
34 class OCEAN_MEDIA_A_EXPORT AMedium : virtual public Medium
35 {
36  friend class ALibrary;
37 
38  public:
39 
40  /**
41  * Definition of the interface for Noise Suppressor (NS).
42  */
43  static constexpr SLInterfaceID_ slEffectTypeNoiseSuppressorId_ = {0x58b4b260, 0x8e06, 0x11e0, 0xaa8e, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}};
44 
45  /**
46  * Definition of the interface for Acoustic Echo Canceler (AEC).
47  */
48  static constexpr SLInterfaceID_ slEffectTypeAcousticEchoCancelerId_ = {0x7b491460, 0x8d4d, 0x11e0, 0xbd61, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}};
49 
50  protected:
51 
52  /**
53  * This manager holds all effects available in the engine.
54  */
55  class EffectManager final : public Singleton<EffectManager>
56  {
57  friend class Singleton<EffectManager>;
58  friend class ALibrary;
59 
60  protected:
61 
62  /**
63  * This class holds the two interfaces of a OpenSL engine effect.
64  */
66  {
67  public:
68 
69  /**
70  * Creates a new effect object.
71  * @param slEffectTypeId The id of the effect type
72  * @param slEffectImplementationId The id of the effect implementation
73  */
74  EngineEffect(const SLInterfaceID slEffectTypeId, const SLInterfaceID slEffectImplementationId);
75 
76  public:
77 
78  /// The id of the effect type.
79  SLInterfaceID slEffectTypeId_ = nullptr;
80 
81  /// The id of the effect implementation.
82  SLInterfaceID slEffectImplementationId_ = nullptr;
83  };
84 
85  /**
86  * Definition of a map mapping effect names to effect objects.
87  */
88  typedef std::unordered_map<std::string, EngineEffect> EngineEffectMap;
89 
90  public:
91 
92  /**
93  * Returns whether the engine has a specifc effect.
94  * @param effectName The name of the effect to check.
95  * @param slEffectTypeId The resulting type id of the requested effect
96  * @param slEffectImplementationId The resulting implementation id of the requested effect
97  * @return True, if so
98  */
99  bool effectIds(const std::string& effectName, SLInterfaceID& slEffectTypeId, SLInterfaceID& slEffectImplementationId) const;
100 
101  protected:
102 
103  /**
104  * Default constructor.
105  */
106  EffectManager() = default;
107 
108  /**
109  * Initializes the manager.
110  * @param slEngine The SL engine to be used, must be valid
111  */
112  void initialize(const SLObjectItf& slEngine);
113 
114  protected:
115 
116  /// The map mapping effect names to effect interfaces.
118 
119  /// The manager's lock.
120  mutable Lock lock_;
121  };
122 
123  public:
124 
125  /**
126  * Returns whether two interface ids are identical.
127  * @param interfaceId0 The first interface id, must be valid
128  * @param interfaceId1 The second interface id, must be valid
129  * @return True, if so
130  */
131  static bool areInterfaceIdsIdentical(const SLInterfaceID& interfaceId0, const SLInterfaceID& interfaceId1);
132 
133  /**
134  * Returns the hex string of an interface id,
135  * @param interfaceId The id of the interface
136  * @return The resulting string
137  */
138  static std::string toAString(const SLInterfaceID& interfaceId);
139 
140  protected:
141 
142  /**
143  * Creates a new medium by a given url.
144  * @param url The URL of the medium
145  */
146  explicit AMedium(const std::string& url);
147 };
148 
149 }
150 
151 }
152 
153 }
154 
155 #endif // META_OCEAN_MEDIA_ANDROID_A_MEDIUM_H
This class implements a recursive lock object.
Definition: Lock.h:31
This class implements the android library.
Definition: ALibrary.h:36
This class holds the two interfaces of a OpenSL engine effect.
Definition: AMedium.h:66
EngineEffect(const SLInterfaceID slEffectTypeId, const SLInterfaceID slEffectImplementationId)
Creates a new effect object.
This manager holds all effects available in the engine.
Definition: AMedium.h:56
EffectManager()=default
Default constructor.
bool effectIds(const std::string &effectName, SLInterfaceID &slEffectTypeId, SLInterfaceID &slEffectImplementationId) const
Returns whether the engine has a specifc effect.
EngineEffectMap engineEffectMap_
The map mapping effect names to effect interfaces.
Definition: AMedium.h:117
void initialize(const SLObjectItf &slEngine)
Initializes the manager.
Lock lock_
The manager's lock.
Definition: AMedium.h:120
std::unordered_map< std::string, EngineEffect > EngineEffectMap
Definition of a map mapping effect names to effect objects.
Definition: AMedium.h:88
This class implements the base class for all Medium objects in the Android library.
Definition: AMedium.h:35
static std::string toAString(const SLInterfaceID &interfaceId)
Returns the hex string of an interface id,.
AMedium(const std::string &url)
Creates a new medium by a given url.
static bool areInterfaceIdsIdentical(const SLInterfaceID &interfaceId0, const SLInterfaceID &interfaceId1)
Returns whether two interface ids are identical.
This is the base class for all mediums.
Definition: Medium.h:48
This template class is the base class for all singleton objects.
Definition: Singleton.h:71
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15