Ocean
AAudio.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_AUDIO_H
9 #define META_OCEAN_MEDIA_ANDROID_A_AUDIO_H
10 
13 
14 #include "ocean/media/Audio.h"
15 
16 #include <jni.h>
17 
18 #include <SLES/OpenSLES.h>
19 
20 namespace Ocean
21 {
22 
23 namespace Media
24 {
25 
26 namespace Android
27 {
28 
29 /**
30  * This class implements an Audio class for Android.
31  * @ingroup mediaandroid
32  */
33 class OCEAN_MEDIA_A_EXPORT AAudio final :
34  virtual public AMedium,
35  virtual public Audio
36 {
37  friend class ALibrary;
38 
39  public:
40 
41  /**
42  * Clones this movie medium and returns a new independent instance of this medium.
43  * @see Medium::clone()
44  */
45  MediumRef clone() const override;
46 
47  /**
48  * Starts the medium.
49  * @see Medium::start().
50  */
51  bool start() override;
52 
53  /**
54  * Pauses the medium.
55  * @see Medium::pause():
56  */
57  bool pause() override;
58 
59  /**
60  * Stops the medium.
61  * @see Medium::stop().
62  */
63  bool stop() override;
64 
65  /**
66  * Returns whether the medium is started currently.
67  * @see Medium::isStarted().
68  */
69  bool isStarted() const override;
70 
71  /**
72  * Returns the duration of the finite medium.
73  * @see FiniteMedium::duration().
74  */
75  double duration() const override;
76 
77  /**
78  * Returns the duration without speed consideration.
79  * @see FiniteMedium::normalDuration().
80  */
81  double normalDuration() const override;
82 
83  /**
84  * Returns the recent position of the finite medium.
85  * @see FiniteMedium::position().
86  */
87  double position() const override;
88 
89  /**
90  * Sets the recent position of the finite medium.
91  * @see FiniteMedium::setPosition().
92  */
93  bool setPosition(const double position) override;
94 
95  /**
96  * Returns the speed of the finite medium.
97  * @see FiniteMedium::speed().
98  */
99  float speed() const override;
100 
101  /**
102  * Sets the speed of the finite medium.
103  * @see FiniteMedium::setSpeed().
104  */
105  bool setSpeed(const float speed) override;
106 
107  /**
108  * Sets whether the medium has to be played in a loop.
109  * @see FiniteMedium::setLoop().
110  */
111  bool setLoop(const bool value) override;
112 
113  /**
114  * Returns the volume of the sound in db.
115  * @see SoundMedium::soundVolume().
116  */
117  float soundVolume() const override;
118 
119  /**
120  * Returns whether the sound medium is in a mute state.
121  * @see SoundMedium::soundMute().
122  */
123  bool soundMute() const override;
124 
125  /**
126  * Sets the volume of the sound in db.
127  * @see SoundMedium::setSoundVolume().
128  */
129  bool setSoundVolume(const float volume) override;
130 
131  /**
132  * Sets or un-sets the sound medium to a mute state.
133  * @see SoundMedium::setSoundMute().
134  */
135  bool setSoundMute(const bool mute) override;
136 
137  /**
138  * Returns the start timestamp.
139  * @see FiniteMedium::startTimestamp().
140  */
141  Timestamp startTimestamp() const override;
142 
143  /**
144  * Returns the pause timestamp.
145  * @see FiniteMedium::pauseTimestamp().
146  */
147  Timestamp pauseTimestamp() const override;
148 
149  /**
150  * Returns the stop timestamp.
151  * @see FiniteMedium::stopTimestamp().
152  */
153  Timestamp stopTimestamp() const override;
154 
155  protected:
156 
157  /**
158  * Creates a new medium by a given url.
159  * @param slEngineInterface The interface of the SL engine, must be valid
160  * @param url Url of the medium
161  */
162  explicit AAudio(const SLEngineItf& slEngineInterface, const std::string& url);
163 
164  /**
165  * Destructs the live video object.
166  */
167  ~AAudio() override;
168 
169  /**
170  * Initializes the audio and all corresponding resources.
171  * @param slEngineInterface The interface of the SL engine, must be valid
172  * @return True, if succeeded
173  */
174  bool initialize(const SLEngineItf& slEngineInterface);
175 
176  /**
177  * Releases the audio and all corresponding resources.
178  * @return True, if succeeded
179  */
180  bool release();
181 
182  /**
183  * The callback function for position events.
184  * @param slCaller The caller of the function
185  * @param slEvent The actual event
186  */
187  void callbackFunction(SLPlayItf slCaller, SLuint32 slEvent);
188 
189  /**
190  * The static callback function for position events.
191  * @param slCaller The caller of the function
192  * @param context The callback's context
193  * @param slEvent The actual event
194  */
195  static void staticCallbackFunction(SLPlayItf slCaller, void* context, SLuint32 slEvent);
196 
197  protected:
198 
199  /// Start timestamp.
200  Timestamp startTimestamp_ = Timestamp(false);
201 
202  /// Pause timestamp.
203  Timestamp pauseTimestamp_ = Timestamp(false);
204 
205  /// Stop timestamp.
206  Timestamp stopTimestamp_ = Timestamp(false);
207 
208  /// The SL player object.
209  SLObjectItf slPlayer_ = nullptr;
210 
211  /// The SL player interface.
212  SLPlayItf slPlayInterface_ = nullptr;
213 
214  /// The SL output mix object.
215  SLObjectItf slOutputMix_ = nullptr;
216 
217  /// The SL seek interface.
218  SLSeekItf slSeekInterface_ = nullptr;
219 
220  /// The SL volume interface.
221  SLVolumeItf slVolumeInterface_ = nullptr;
222 };
223 
224 }
225 
226 }
227 
228 }
229 
230 #endif // META_OCEAN_MEDIA_ANDROID_A_AUDIO_H
This class implements an Audio class for Android.
Definition: AAudio.h:36
bool stop() override
Stops the medium.
bool start() override
Starts the medium.
bool release()
Releases the audio and all corresponding resources.
bool isStarted() const override
Returns whether the medium is started currently.
double position() const override
Returns the recent position of the finite medium.
~AAudio() override
Destructs the live video object.
bool setPosition(const double position) override
Sets the recent position of the finite medium.
Timestamp startTimestamp() const override
Returns the start timestamp.
AAudio(const SLEngineItf &slEngineInterface, const std::string &url)
Creates a new medium by a given url.
static void staticCallbackFunction(SLPlayItf slCaller, void *context, SLuint32 slEvent)
The static callback function for position events.
bool setSoundMute(const bool mute) override
Sets or un-sets the sound medium to a mute state.
MediumRef clone() const override
Clones this movie medium and returns a new independent instance of this medium.
bool pause() override
Pauses the medium.
float soundVolume() const override
Returns the volume of the sound in db.
float speed() const override
Returns the speed of the finite medium.
double duration() const override
Returns the duration of the finite medium.
bool setSpeed(const float speed) override
Sets the speed of the finite medium.
Timestamp stopTimestamp() const override
Returns the stop timestamp.
double normalDuration() const override
Returns the duration without speed consideration.
Timestamp pauseTimestamp() const override
Returns the pause timestamp.
bool initialize(const SLEngineItf &slEngineInterface)
Initializes the audio and all corresponding resources.
void callbackFunction(SLPlayItf slCaller, SLuint32 slEvent)
The callback function for position events.
bool setSoundVolume(const float volume) override
Sets the volume of the sound in db.
bool soundMute() const override
Returns whether the sound medium is in a mute state.
bool setLoop(const bool value) override
Sets whether the medium has to be played in a loop.
This class implements the android library.
Definition: ALibrary.h:36
This class implements the base class for all Medium objects in the Android library.
Definition: AMedium.h:35
This class is the base class for all audio mediums.
Definition: Audio.h:38
This template class implements a object reference with an internal reference counter.
Definition: base/ObjectRef.h:58
This class implements a timestamp.
Definition: Timestamp.h:36
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15