AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
ExternalMediaAdapterHandler.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_ACSDKEXTERNALMEDIAPLAYER_INCLUDE_ACSDKEXTERNALMEDIAPLAYER_EXTERNALMEDIAADAPTERHANDLER_H_
17 #define ALEXA_CLIENT_SDK_ACSDKEXTERNALMEDIAPLAYER_INCLUDE_ACSDKEXTERNALMEDIAPLAYER_EXTERNALMEDIAADAPTERHANDLER_H_
18 
19 #include <functional>
20 #include <memory>
21 #include <mutex>
22 #include <set>
23 #include <string>
24 #include <unordered_map>
25 #include <vector>
26 
31 #include <rapidjson/document.h>
32 
35 
36 namespace alexaClientSDK {
37 namespace acsdkExternalMediaPlayer {
38 
43 public:
47  bool authorized;
52 };
53 
61  , public std::enable_shared_from_this<ExternalMediaAdapterHandler> {
62 protected:
69 
75  bool initializeAdapterHandler(
76  std::shared_ptr<alexaClientSDK::avsCommon::sdkInterfaces::SpeakerManagerInterface> speakerManager);
77 
84  bool validatePlayer(const std::string& localPlayerId, bool checkAuthorized = true);
85 
94  std::string createExternalMediaPlayerEvent(
95  const std::string& localPlayerId,
96  const std::string& event,
97  bool includePlaybackSessionId = false,
98  std::function<void(rapidjson::Value::Object&, rapidjson::Value::AllocatorType&)> createPayload =
99  [](rapidjson::Value::Object& v, rapidjson::Value::AllocatorType& a) {});
100 
105  void reportDiscoveredPlayers(
106  const std::vector<acsdkExternalMediaPlayerInterfaces::DiscoveredPlayerInfo>& discoveredPlayers);
107 
113  bool removeDiscoveredPlayer(const std::string& localPlayerId);
114 
117 
123  virtual bool handleAuthorization(const AuthorizedPlayerInfo& authorizedPlayer) = 0;
124 
134  virtual bool handleLogin(
135  const std::string& localPlayerId,
136  const std::string& accessToken,
137  const std::string& userName,
138  bool forceLogin,
139  std::chrono::milliseconds tokenRefreshInterval) = 0;
140 
146  virtual bool handleLogout(const std::string& localPlayerId) = 0;
147 
153  virtual bool handlePlay(const ExternalMediaAdapterHandlerInterface::PlayParams& params) = 0;
154 
163  virtual bool handlePlayControl(
164  const std::string& localPlayerId,
166  const std::string& playbackTarget) = 0;
167 
175  virtual bool handleSeek(const std::string& localPlayerId, std::chrono::milliseconds offset) = 0;
176 
183  virtual bool handleAdjustSeek(const std::string& localPlayerId, std::chrono::milliseconds deltaOffset) = 0;
184 
192  virtual bool handleGetAdapterState(
193  const std::string& localPlayerId,
195 
201  virtual std::chrono::milliseconds handleGetOffset(const std::string& localPlayerId);
202 
207  virtual void handleSetVolume(int8_t volume) = 0;
208 
213  virtual void handleSetMute(bool mute) = 0;
215 
217  virtual void doShutdown() override;
218 
220  std::weak_ptr<acsdkExternalMediaPlayerInterfaces::ExternalMediaPlayerInterface> m_externalMediaPlayer;
221 
222 public:
225  std::vector<acsdkExternalMediaPlayerInterfaces::PlayerInfo> updatePlayerInfo(
226  const std::vector<acsdkExternalMediaPlayerInterfaces::PlayerInfo>& playerList) override;
227  bool login(
228  const std::string& localPlayerId,
229  const std::string& accessToken,
230  const std::string& userName,
231  bool forceLogin,
232  std::chrono::milliseconds tokenRefreshInterval) override;
233  bool logout(const std::string& localPlayerId) override;
234  bool play(const PlayParams& params) override;
235  bool playControl(
236  const std::string& localPlayerId,
238  const std::string& playbackTarget) override;
239  bool seek(const std::string& localPlayerId, std::chrono::milliseconds offset) override;
240  bool adjustSeek(const std::string& localPlayerId, std::chrono::milliseconds deltaOffset) override;
241  acsdkExternalMediaPlayerInterfaces::AdapterState getAdapterState(const std::string& localPlayerId) override;
242  std::vector<acsdkExternalMediaPlayerInterfaces::AdapterState> getAdapterStates() override;
243  std::chrono::milliseconds getOffset(const std::string& localPlayerId) override;
244  void setExternalMediaPlayer(const std::shared_ptr<acsdkExternalMediaPlayerInterfaces::ExternalMediaPlayerInterface>
245  externalMediaPlayer) override;
247 
250  void onSpeakerSettingsChanged(
251  const Source& source,
255 
256 private:
258  std::unordered_map<std::string, acsdkExternalMediaPlayerInterfaces::PlayerInfo> m_playerInfoMap;
259 
261  bool m_muted;
262 
264  int8_t m_volume;
265 
267  std::mutex m_mutex;
268 
271 
273  std::condition_variable m_attemptedSetFocusPlayerInFocusCondition;
274 };
275 
276 } // namespace acsdkExternalMediaPlayer
277 } // namespace alexaClientSDK
278 
279 #endif // ALEXA_CLIENT_SDK_ACSDKEXTERNALMEDIAPLAYER_INCLUDE_ACSDKEXTERNALMEDIAPLAYER_EXTERNALMEDIAADAPTERHANDLER_H_
std::string localPlayerId
The opaque token that uniquely identifies the local external player app.
Definition: ExternalMediaAdapterHandler.h:45
RequestType
Definition: ExternalMediaAdapterInterface.h:32
::std::string string
Definition: gtest-port.h:1097
Single-thread executor implementation.
Definition: Executor.h:45
Definition: ExternalMediaAdapterHandler.h:42
Definition: ExternalMediaAdapterInterface.h:495
PlayParams is a struct that contains the parameters for the play method.
Definition: ExternalMediaAdapterHandlerInterface.h:61
bool authorized
Authorization status.
Definition: ExternalMediaAdapterHandler.h:47
ExternalMediaAdapterHandlerInterface::PlayParams PlayParams
Definition: ExternalMediaAdapterHandlerTest.cpp:35
std::weak_ptr< acsdkExternalMediaPlayerInterfaces::ExternalMediaPlayerInterface > m_externalMediaPlayer
The pointer to the external media player object.
Definition: ExternalMediaAdapterHandler.h:220
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
std::string defaultSkillToken
An opaque token for the domain or skill that is associated with this player.
Definition: ExternalMediaAdapterHandler.h:49
type
Definition: upload.py:443
Source
Indicates whether the source of the call is from an AVS Directive or through a Local API call...
Definition: SpeakerManagerObserverInterface.h:35
std::string playerId
The playerId that identifies this player.
Definition: ExternalMediaAdapterHandler.h:51

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