AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
AndroidSLESMediaQueue.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_ANDROIDSLESMEDIAQUEUE_H_
16 #define ALEXA_CLIENT_SDK_MEDIAPLAYER_ANDROIDSLESMEDIAPLAYER_INCLUDE_ANDROIDSLESMEDIAPLAYER_ANDROIDSLESMEDIAQUEUE_H_
17 
18 #include <array>
19 #include <atomic>
20 #include <chrono>
21 #include <mutex>
22 #include <vector>
23 
24 #include <SLES/OpenSLES_Android.h>
25 
28 
31 
32 namespace alexaClientSDK {
33 namespace mediaPlayer {
34 namespace android {
35 
48 public:
50 
52  enum class QueueEvent {
54  ERROR,
59  };
60 
68  using EventCallback = std::function<void(QueueEvent event, const std::string& reason)>;
69 
80  static std::unique_ptr<AndroidSLESMediaQueue> create(
81  std::shared_ptr<applicationUtilities::androidUtilities::AndroidSLESObject> queueObject,
82  std::unique_ptr<DecoderInterface> decoder,
83  EventCallback onStatusChanged,
84  const PlaybackConfiguration& playbackConfiguration);
85 
92  void onBufferFree();
93 
98 
104  size_t getNumBytesBuffered() const;
105 
111  size_t getNumBytesPlayed() const;
112 
114  static constexpr size_t NUMBER_OF_BUFFERS{4u};
115 
117  static constexpr size_t BUFFER_SIZE{131072u};
118 
119 private:
130  std::shared_ptr<applicationUtilities::androidUtilities::AndroidSLESObject> queueObject,
131  SLAndroidSimpleBufferQueueItf bufferQueue,
132  std::unique_ptr<DecoderInterface> decoder,
133  EventCallback callbackFunction);
134 
136  void fillBuffer();
137 
143  void fillAllBuffers(const PlaybackConfiguration& configuration);
144 
153  void enqueueSilence(const PlaybackConfiguration& configuration);
154 
157 
159  std::shared_ptr<applicationUtilities::androidUtilities::AndroidSLESObject> m_slObject;
160 
162  SLAndroidSimpleBufferQueueItf m_queueInterface;
163 
165  std::array<std::array<Byte, BUFFER_SIZE>, NUMBER_OF_BUFFERS> m_buffers;
166 
168  std::vector<size_t> m_bufferSizes;
169 
171  std::unique_ptr<DecoderInterface> m_decoder;
172 
174  size_t m_index;
175 
177  bool m_inputEof;
178 
180  bool m_failure;
181 
183  EventCallback m_eventCallback;
184 
186  std::atomic<size_t> m_bufferedWords;
187 
189  std::atomic<size_t> m_playedWords;
190 };
191 
192 } // namespace android
193 } // namespace mediaPlayer
194 } // namespace alexaClientSDK
195 
196 #endif // ALEXA_CLIENT_SDK_MEDIAPLAYER_ANDROIDSLESMEDIAPLAYER_INCLUDE_ANDROIDSLESMEDIAPLAYER_ANDROIDSLESMEDIAQUEUE_H_
QueueEvent
Represent the event types that will be sent to the StatusCallback when the queue change state...
Definition: AndroidSLESMediaQueue.h:52
uint8_t Byte
Represents one byte of data.
Definition: DecoderInterface.h:38
Single-thread executor implementation.
Definition: Executor.h:45
Sent when the queue encountered an unrecoverable error.
std::function< void(QueueEvent event, const std::string &reason)> EventCallback
Definition: AndroidSLESMediaQueue.h:68
static std::unique_ptr< AndroidSLESMediaQueue > create(std::shared_ptr< applicationUtilities::androidUtilities::AndroidSLESObject > queueObject, std::unique_ptr< DecoderInterface > decoder, EventCallback onStatusChanged, const PlaybackConfiguration &playbackConfiguration)
static constexpr size_t NUMBER_OF_BUFFERS
The number of buffers to use.
Definition: AndroidSLESMediaQueue.h:114
DecoderInterface::Byte Byte
Definition: AndroidSLESMediaQueue.h:49
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
static constexpr size_t BUFFER_SIZE
Buffer size for the decoded data. This has to be big enough to be used with the decoder.
Definition: AndroidSLESMediaQueue.h:117

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