AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
AndroidSLESMediaPlayer.h
Go to the documentation of this file.
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 #ifndef ALEXA_CLIENT_SDK_MEDIAPLAYER_ANDROIDSLESMEDIAPLAYER_INCLUDE_ANDROIDSLESMEDIAPLAYER_ANDROIDSLESMEDIAPLAYER_H_
16 #define ALEXA_CLIENT_SDK_MEDIAPLAYER_ANDROIDSLESMEDIAPLAYER_INCLUDE_ANDROIDSLESMEDIAPLAYER_ANDROIDSLESMEDIAPLAYER_H_
17 
18 #include <unordered_set>
19 #include <vector>
20 
21 #include <SLES/OpenSLES.h>
22 
36 
40 
41 namespace alexaClientSDK {
42 namespace mediaPlayer {
43 namespace android {
44 
54 public:
64  static std::unique_ptr<AndroidSLESMediaPlayer> create(
65  std::shared_ptr<avsCommon::sdkInterfaces::HTTPContentFetcherInterfaceFactoryInterface> contentFetcherFactory,
66  std::shared_ptr<applicationUtilities::androidUtilities::AndroidSLESEngine> engine,
67  bool enableEqualizer,
69  const std::string& name = "AndroidMediaPlayer");
70 
74 
75  int getMinimumBandLevel() override;
76 
77  int getMaximumBandLevel() override;
79 
83  std::shared_ptr<avsCommon::avs::attachment::AttachmentReader> attachmentReader,
84  const avsCommon::utils::AudioFormat* format = nullptr,
88  std::shared_ptr<avsCommon::avs::attachment::AttachmentReader> attachmentReader,
89  std::chrono::milliseconds offsetAdjustment,
90  const avsCommon::utils::AudioFormat* format = nullptr,
94  const std::string& url,
95  std::chrono::milliseconds offset,
97  bool repeat = false,
98  const avsCommon::utils::mediaPlayer::PlaybackContext& playbackContext =
100 
102  std::shared_ptr<std::istream> stream,
103  bool repeat = false,
106  bool play(SourceId id) override;
107  bool stop(SourceId id) override;
108  bool pause(SourceId id) override;
109  bool resume(SourceId id) override;
110  std::chrono::milliseconds getOffset(SourceId id) override;
111  uint64_t getNumBytesBuffered() override;
113  SourceId id) override;
114  void addObserver(
115  std::shared_ptr<avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface> playerObserver) override;
116  void removeObserver(
117  std::shared_ptr<avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface> playerObserver) override;
119 
125  void onPrefetchStatusChange(SLuint32 event);
126 
131 
137  std::shared_ptr<avsCommon::sdkInterfaces::SpeakerInterface> getSpeaker();
138 
139 protected:
142  void doShutdown() override;
144 
145 private:
161  std::shared_ptr<avsCommon::sdkInterfaces::HTTPContentFetcherInterfaceFactoryInterface> contentFetcherFactory,
162  std::shared_ptr<avsCommon::sdkInterfaces::SpeakerInterface> speaker,
163  std::shared_ptr<applicationUtilities::androidUtilities::AndroidSLESEngine> engine,
164  std::shared_ptr<applicationUtilities::androidUtilities::AndroidSLESObject> outputMixObject,
165  std::shared_ptr<applicationUtilities::androidUtilities::AndroidSLESObject> playerObject,
166  SLEqualizerItf equalizer,
167  SLPlayItf playerInterface,
168  const PlaybackConfiguration& config,
169  const std::string& name);
170 
180  void onQueueEvent(AndroidSLESMediaQueue::QueueEvent event, const std::string& reason, const SourceId& id);
181 
188  bool registerPrefetchStatusCallback();
189 
199  SourceId configureNewRequest(
200  std::unique_ptr<FFmpegInputControllerInterface> inputController,
202  std::shared_ptr<avsCommon::utils::playlistParser::IterativePlaylistParserInterface> playlistParser = nullptr,
203  std::chrono::milliseconds offset = std::chrono::milliseconds(0));
204 
210  bool stopLocked();
211 
217  bool initializeEqualizer();
218 
225  std::chrono::milliseconds getOffsetLocked(SourceId id);
226 
240  static std::chrono::milliseconds computeDuration(size_t sizeBytes);
241 
249 
251  std::mutex m_requestMutex;
252 
254  std::mutex m_operationMutex;
255 
257  std::shared_ptr<avsCommon::sdkInterfaces::HTTPContentFetcherInterfaceFactoryInterface> m_contentFetcherFactory;
258 
260  SourceId m_sourceId;
261 
263  std::chrono::milliseconds m_initialOffset;
264 
266  std::shared_ptr<avsCommon::sdkInterfaces::SpeakerInterface> m_speaker;
267 
270  std::shared_ptr<applicationUtilities::androidUtilities::AndroidSLESEngine> m_engine;
271 
273  std::shared_ptr<applicationUtilities::androidUtilities::AndroidSLESObject> m_outputMixObject;
274 
276  std::shared_ptr<applicationUtilities::androidUtilities::AndroidSLESObject> m_playerObject;
277 
279  std::unordered_set<std::shared_ptr<avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface>> m_observers;
280 
282  SLEqualizerItf m_equalizer;
283 
285  std::vector<int> m_growingFrequenceBandMap;
286 
288  std::shared_ptr<acsdkEqualizer::EqualizerBandMapperInterface> m_bandMapper;
289 
291  int m_numberOfEqualizerBands;
292 
294  int m_minBandLevel;
295 
297  int m_maxBandLevel;
298 
300  SLPlayItf m_player;
301 
302  // The android media player configuration.
303  PlaybackConfiguration m_config;
304 
307  SLPrefetchStatusItf m_prefetchStatus;
308 
310  std::shared_ptr<AndroidSLESMediaQueue> m_mediaQueue;
311 
314  std::shared_ptr<avsCommon::utils::playlistParser::IterativePlaylistParserInterface> m_playlistParser;
315 
318  bool m_almostDone;
319 
322  bool m_hasShutdown;
323 };
324 
325 } // namespace android
326 } // namespace mediaPlayer
327 } // namespace alexaClientSDK
328 
329 #endif // ALEXA_CLIENT_SDK_MEDIAPLAYER_ANDROIDSLESMEDIAPLAYER_INCLUDE_ANDROIDSLESMEDIAPLAYER_ANDROIDSLESMEDIAPLAYER_H_
std::unordered_map< EqualizerBand, int, avsCommon::utils::functional::EnumClassHash > EqualizerBandLevelMap
A collection of bands with their level values. This is an alias for EqualizerBand to band level (int)...
Definition: EqualizerTypes.h:77
void addObserver(std::shared_ptr< avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface > playerObserver) override
std::chrono::milliseconds getOffset(SourceId id) override
void setEqualizerBandLevels(acsdkEqualizerInterfaces::EqualizerBandLevelMap bandLevelMap) override
SourceConfig emptySourceConfig()
Definition: SourceConfig.h:98
QueueEvent
Represent the event types that will be sent to the StatusCallback when the queue change state...
Definition: AndroidSLESMediaQueue.h:52
uint64_t SourceId
A type that identifies which source is currently being operated on. This must be unique across all in...
Definition: MediaPlayerInterface.h:69
::std::string string
Definition: gtest-port.h:1097
static std::unique_ptr< AndroidSLESMediaPlayer > create(std::shared_ptr< avsCommon::sdkInterfaces::HTTPContentFetcherInterfaceFactoryInterface > contentFetcherFactory, std::shared_ptr< applicationUtilities::androidUtilities::AndroidSLESEngine > engine, bool enableEqualizer, const PlaybackConfiguration &config=PlaybackConfiguration(), const std::string &name="AndroidMediaPlayer")
MediaType
Definition: MediaType.h:29
std::shared_ptr< avsCommon::sdkInterfaces::SpeakerInterface > getSpeaker()
avsCommon::utils::Optional< avsCommon::utils::mediaPlayer::MediaPlayerState > getMediaPlayerState(SourceId id) override
void removeObserver(std::shared_ptr< avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface > playerObserver) override
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
SourceId setSource(std::shared_ptr< avsCommon::avs::attachment::AttachmentReader > attachmentReader, const avsCommon::utils::AudioFormat *format=nullptr, const avsCommon::utils::mediaPlayer::SourceConfig &config=avsCommon::utils::mediaPlayer::emptySourceConfig()) override

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0