AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
MediaEndpoint.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 
16 #ifndef ALEXA_CLIENT_SDK_BLUETOOTHIMPLEMENTATIONS_BLUEZ_INCLUDE_BLUEZ_MEDIAENDPOINT_H_
17 #define ALEXA_CLIENT_SDK_BLUETOOTHIMPLEMENTATIONS_BLUEZ_INCLUDE_BLUEZ_MEDIAENDPOINT_H_
18 
19 #include <atomic>
20 #include <condition_variable>
21 #include <vector>
22 
26 
28 #include "BlueZ/BlueZUtils.h"
29 #include "BlueZ/MediaContext.h"
30 
31 #include <gio/gio.h>
32 #include <sbc/sbc.h>
33 
34 namespace alexaClientSDK {
35 namespace bluetoothImplementations {
36 namespace blueZ {
37 
43 class MediaEndpoint : public DBusObject<MediaEndpoint> {
44 public:
51  MediaEndpoint(std::shared_ptr<DBusConnection> connection, const std::string& endpointPath);
52 
56  ~MediaEndpoint() override;
57 
64  void onSetConfiguration(GVariant* arguments, GDBusMethodInvocation* invocation);
65 
74  void onSelectConfiguration(GVariant* arguments, GDBusMethodInvocation* invocation);
75 
82  void onClearConfiguration(GVariant* arguments, GDBusMethodInvocation* invocation);
83 
90  void onRelease(GVariant* arguments, GDBusMethodInvocation* invocation);
91 
100  const std::string& devicePath);
101 
108 
115 
122  std::shared_ptr<avsCommon::utils::bluetooth::FormattedAudioStreamAdapter> getAudioStream();
123 
124 private:
128  enum class OperatingMode {
132  INACTIVE,
133 
138  SINK,
139 
143  SOURCE,
144 
150  RELEASED
151  };
152 
158  std::string operatingModeToString(OperatingMode mode);
159 
163  void mediaThread();
164 
170  void setOperatingMode(OperatingMode mode);
171 
177  void abortStreaming();
178 
182  std::string m_endpointPath;
183 
187  std::string m_streamingDevicePath;
188 
192  bool m_operatingModeChanged;
193 
197  std::atomic<OperatingMode> m_operatingMode;
198 
202  std::vector<uint8_t> m_sbcBuffer;
203 
207  std::mutex m_mutex;
208 
212  std::mutex m_streamMutex;
213 
217  std::condition_variable m_modeChangeSignal;
218 
222  std::shared_ptr<avsCommon::utils::bluetooth::FormattedAudioStreamAdapter> m_ioStream;
223 
227  std::vector<uint8_t> m_ioBuffer;
228 
232  avsCommon::utils::AudioFormat m_audioFormat;
233 
238  std::shared_ptr<MediaContext> m_currentMediaContext;
239 
240  /*
241  * Dedicated thread for I/O.
242  */
243  std::thread m_thread;
244 };
245 
246 } // namespace blueZ
247 } // namespace bluetoothImplementations
248 } // namespace alexaClientSDK
249 
250 #endif // ALEXA_CLIENT_SDK_BLUETOOTHIMPLEMENTATIONS_BLUEZ_INCLUDE_BLUEZ_MEDIAENDPOINT_H_
void onMediaTransportStateChanged(avsCommon::utils::bluetooth::MediaStreamingState newState, const std::string &devicePath)
MediaEndpoint(std::shared_ptr< DBusConnection > connection, const std::string &endpointPath)
::std::string string
Definition: gtest-port.h:1097
MediaStreamingState
An Enum representing the current state of the stream.
Definition: MediaStreamingState.h:25
void onSelectConfiguration(GVariant *arguments, GDBusMethodInvocation *invocation)
void onClearConfiguration(GVariant *arguments, GDBusMethodInvocation *invocation)
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
void onSetConfiguration(GVariant *arguments, GDBusMethodInvocation *invocation)
void onRelease(GVariant *arguments, GDBusMethodInvocation *invocation)
std::shared_ptr< avsCommon::utils::bluetooth::FormattedAudioStreamAdapter > getAudioStream()

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