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