Alexa Auto SDK  2.0.0
ExternalMediaAdapter.h
1 /*
2  * Copyright 2017-2019 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 AACE_ALEXA_EXTERNAL_MEDIA_ADAPTER_H
17 #define AACE_ALEXA_EXTERNAL_MEDIA_ADAPTER_H
18 
19 #include <chrono>
20 #include <string>
21 
22 #include "AACE/Core/PlatformInterface.h"
23 #include "AACE/Audio/AudioOutput.h"
24 
25 #include "AlexaEngineInterfaces.h"
26 
29 namespace aace {
30 namespace alexa {
31 
32 class ExternalMediaAdapter : public aace::core::PlatformInterface {
33 public:
34  using DiscoveredPlayerInfo = ExternalMediaAdapterEngineInterface::DiscoveredPlayerInfo;
35  using MutedState = aace::audio::AudioOutput::MutedState;
36 
40  enum class PlayControlType
41  {
45  PAUSE,
49  RESUME,
53  NEXT,
57  PREVIOUS,
61  START_OVER,
65  FAST_FORWARD,
69  REWIND,
73  ENABLE_REPEAT_ONE,
77  ENABLE_REPEAT,
81  DISABLE_REPEAT,
85  ENABLE_SHUFFLE,
89  DISABLE_SHUFFLE,
93  FAVORITE,
97  UNFAVORITE
98  };
99 
103  enum class SupportedPlaybackOperation {
104  /*
105  * Play is supported (voice only)
106  */
107  PLAY,
108  /*
109  * Resume is supported
110  */
111  RESUME,
112  /*
113  * Pause is supported
114  */
115  PAUSE,
116  /*
117  * Stop is supported
118  */
119  STOP,
120  /*
121  * Next is supported
122  */
123  NEXT,
124  /*
125  * Previous is supported
126  */
127  PREVIOUS,
128  /*
129  * Start Over is supported
130  */
131  START_OVER,
132  /*
133  * Fast Forward is supported
134  */
135  FAST_FORWARD,
136  /*
137  * Rewind is supported
138  */
139  REWIND,
140  /*
141  * Enable Repeat is supported
142  */
143  ENABLE_REPEAT,
144  /*
145  * Enable Repeat One is supported
146  */
147  ENABLE_REPEAT_ONE,
148  /*
149  * Disbale Repeat is supported
150  */
151  DISABLE_REPEAT,
152  /*
153  * Enable Shuffle is supported
154  */
155  ENABLE_SHUFFLE,
156  /*
157  * Disable Shuffle is supported
158  */
159  DISABLE_SHUFFLE,
160  /*
161  * Favorite is supported
162  */
163  FAVORITE,
164  /*
165  * Unfavorite is supported
166  */
167  UNFAVORITE,
168  /*
169  * Seek is supported
170  */
171  SEEK,
172  /*
173  * Adjust Seek is supported
174  */
175  ADJUST_SEEK
176  };
177 
181  enum class Favorites {
185  FAVORITED,
189  UNFAVORITED,
193  NOT_RATED
194  };
195 
199  enum class MediaType {
203  TRACK,
207  PODCAST,
211  STATION,
215  AD,
219  SAMPLE,
223  OTHER
224  };
225 
229  enum class Navigation {
233  DEFAULT,
237  NONE,
241  FOREGROUND
242  };
243 
247  class SessionState {
248  public:
249  /*
250  * Default Constructor.
251  */
252  SessionState() = default;
253 
255  std::string endpointId;
256 
258  bool loggedIn;
259 
261  std::string userName;
262 
264  bool isGuest;
265 
267  bool launched;
268 
273  bool active;
274 
279  std::string accessToken;
280 
282  std::chrono::milliseconds tokenRefreshInterval;
283 
285  std::string playerCookie;
286 
288  std::string spiVersion;
289  };
290 
295  public:
297  PlaybackState() = default;
298 
300  std::string state;
301 
303  std::vector<SupportedPlaybackOperation> supportedOperations;
304 
306  std::chrono::milliseconds trackOffset;
307 
310 
313 
315  Favorites favorites;
316 
318  std::string type;
319 
321  std::string playbackSource;
322 
325  std::string playbackSourceId;
326 
328  std::string trackName;
329 
331  std::string trackId;
332 
335  std::string trackNumber;
336 
338  std::string artistName;
339 
342  std::string artistId;
343 
345  std::string albumName;
346 
349  std::string albumId;
350 
352  std::string tinyURL;
353 
355  std::string smallURL;
356 
358  std::string mediumURL;
359 
361  std::string largeURL;
362 
365  std::string coverId;
366 
369  std::string mediaProvider;
370 
372  MediaType mediaType;
373 
375  std::chrono::milliseconds duration;
376  };
377 
382  public:
384  ExternalMediaAdapterState() = default;
385 
388 
391  };
392 
397  public:
399  std::string localPlayerId;
402  };
403 
404 protected:
405  ExternalMediaAdapter() = default;
406 
407 public:
408  virtual ~ExternalMediaAdapter();
409 
426  virtual bool login( const std::string& localPlayerId, const std::string& accessToken, const std::string& userName, bool forceLogin, std::chrono::milliseconds tokenRefreshInterval ) = 0;
427 
436  virtual bool logout( const std::string& localPlayerId ) = 0;
437 
456  virtual bool play( const std::string& localPlayerId, const std::string& playContextToken, int64_t index, std::chrono::milliseconds offset, bool preload, Navigation navigation ) = 0;
457 
470  virtual bool playControl( const std::string& localPlayerId, PlayControlType controlType ) = 0;
471 
482  virtual bool seek( const std::string& localPlayerId, std::chrono::milliseconds offset ) = 0;
483 
494  virtual bool adjustSeek( const std::string& localPlayerId, std::chrono::milliseconds deltaOffset ) = 0;
495 
510  virtual bool authorize( const std::vector<AuthorizedPlayerInfo>& authorizedPlayers ) = 0;
511 
521  virtual bool getState( const std::string& localPlayerId, ExternalMediaAdapterState& state ) = 0;
522 
532  virtual bool volumeChanged( float volume ) = 0;
533 
543  virtual bool mutedStateChanged( MutedState state ) = 0;
544 
545  // ExternalMediaAdapterEngineInterface
546 
552  void reportDiscoveredPlayers( const std::vector<DiscoveredPlayerInfo>& discoveredPlayers );
553 
559  void requestToken( const std::string& localPlayerId );
560 
566  void loginComplete( const std::string& localPlayerId );
567 
573  void logoutComplete( const std::string& localPlayerId );
574 
582  void playerEvent( const std::string& localPlayerId, const std::string& eventName );
583 
597  void playerError( const std::string& localPlayerId, const std::string& errorName, long code, const std::string& description, bool fatal );
598 
604  void setFocus( const std::string& localPlayerId );
605 
606  void removeDiscoveredPlayer( const std::string& localPlayerId );
607 
614  void setEngineInterface( std::shared_ptr<aace::alexa::ExternalMediaAdapterEngineInterface> externalMediaAdapterEngineInterface );
615 
616 private:
617  std::weak_ptr<aace::alexa::ExternalMediaAdapterEngineInterface> m_externalMediaAdapterEngineInterface;
618 };
619 
620 inline std::ostream& operator<<(std::ostream& stream, const ExternalMediaAdapter::PlayControlType& requestType) {
621  switch (requestType) {
622  case ExternalMediaAdapter::PlayControlType::RESUME:
623  stream << "RESUME";
624  break;
625  case ExternalMediaAdapter::PlayControlType::PAUSE:
626  stream << "PAUSE";
627  break;
628  case ExternalMediaAdapter::PlayControlType::NEXT:
629  stream << "NEXT";
630  break;
631  case ExternalMediaAdapter::PlayControlType::PREVIOUS:
632  stream << "PREVIOUS";
633  break;
634  case ExternalMediaAdapter::PlayControlType::START_OVER:
635  stream << "START_OVER";
636  break;
637  case ExternalMediaAdapter::PlayControlType::FAST_FORWARD:
638  stream << "FAST_FORWARD";
639  break;
640  case ExternalMediaAdapter::PlayControlType::REWIND:
641  stream << "REWIND";
642  break;
643  case ExternalMediaAdapter::PlayControlType::ENABLE_REPEAT_ONE:
644  stream << "ENABLE_REPEAT_ONE";
645  break;
646  case ExternalMediaAdapter::PlayControlType::ENABLE_REPEAT:
647  stream << "ENABLE_REPEAT";
648  break;
649  case ExternalMediaAdapter::PlayControlType::DISABLE_REPEAT:
650  stream << "DISABLE_REPEAT";
651  break;
652  case ExternalMediaAdapter::PlayControlType::ENABLE_SHUFFLE:
653  stream << "ENABLE_SHUFFLE";
654  break;
655  case ExternalMediaAdapter::PlayControlType::DISABLE_SHUFFLE:
656  stream << "DISABLE_SHUFFLE";
657  break;
658  case ExternalMediaAdapter::PlayControlType::FAVORITE:
659  stream << "FAVORITE";
660  break;
661  case ExternalMediaAdapter::PlayControlType::UNFAVORITE:
662  stream << "UNFAVORITE";
663  break;
664  }
665  return stream;
666 }
667 
668 inline std::ostream& operator<<(std::ostream& stream, const ExternalMediaAdapter::SupportedPlaybackOperation& supportedPlaybackOperation) {
669  switch (supportedPlaybackOperation) {
670  case ExternalMediaAdapter::SupportedPlaybackOperation::PLAY:
671  stream << "PLAY";
672  break;
673  case ExternalMediaAdapter::SupportedPlaybackOperation::RESUME:
674  stream << "RESUME";
675  break;
676  case ExternalMediaAdapter::SupportedPlaybackOperation::PAUSE:
677  stream << "PAUSE";
678  break;
679  case ExternalMediaAdapter::SupportedPlaybackOperation::STOP:
680  stream << "STOP";
681  break;
682  case ExternalMediaAdapter::SupportedPlaybackOperation::NEXT:
683  stream << "NEXT";
684  break;
685  case ExternalMediaAdapter::SupportedPlaybackOperation::PREVIOUS:
686  stream << "PREVIOUS";
687  break;
688  case ExternalMediaAdapter::SupportedPlaybackOperation::START_OVER:
689  stream << "START_OVER";
690  break;
691  case ExternalMediaAdapter::SupportedPlaybackOperation::FAST_FORWARD:
692  stream << "FAST_FORWARD";
693  break;
694  case ExternalMediaAdapter::SupportedPlaybackOperation::REWIND:
695  stream << "REWIND";
696  break;
697  case ExternalMediaAdapter::SupportedPlaybackOperation::ENABLE_REPEAT:
698  stream << "ENABLE_REPEAT";
699  break;
700  case ExternalMediaAdapter::SupportedPlaybackOperation::ENABLE_REPEAT_ONE:
701  stream << "ENABLE_REPEAT_ONE";
702  break;
703  case ExternalMediaAdapter::SupportedPlaybackOperation::DISABLE_REPEAT:
704  stream << "DISABLE_REPEAT";
705  break;
706  case ExternalMediaAdapter::SupportedPlaybackOperation::ENABLE_SHUFFLE:
707  stream << "ENABLE_SHUFFLE";
708  break;
709  case ExternalMediaAdapter::SupportedPlaybackOperation::DISABLE_SHUFFLE:
710  stream << "DISABLE_SHUFFLE";
711  break;
712  case ExternalMediaAdapter::SupportedPlaybackOperation::FAVORITE:
713  stream << "FAVORITE";
714  break;
715  case ExternalMediaAdapter::SupportedPlaybackOperation::UNFAVORITE:
716  stream << "UNFAVORITE";
717  break;
718  case ExternalMediaAdapter::SupportedPlaybackOperation::SEEK:
719  stream << "SEEK";
720  break;
721  case ExternalMediaAdapter::SupportedPlaybackOperation::ADJUST_SEEK:
722  stream << "ADJUST_SEEK";
723  break;
724  }
725  return stream;
726 }
727 
728 inline std::ostream& operator<<(std::ostream& stream, const ExternalMediaAdapter::Favorites& favorites) {
729  switch (favorites) {
730  case ExternalMediaAdapter::Favorites::FAVORITED:
731  stream << "FAVORITED";
732  break;
733  case ExternalMediaAdapter::Favorites::UNFAVORITED:
734  stream << "UNFAVORITED";
735  break;
736  case ExternalMediaAdapter::Favorites::NOT_RATED:
737  stream << "NOT_RATED";
738  break;
739  }
740  return stream;
741 }
742 
743 inline std::ostream& operator<<(std::ostream& stream, const ExternalMediaAdapter::MediaType& mediaType) {
744  switch (mediaType) {
745  case ExternalMediaAdapter::MediaType::TRACK:
746  stream << "TRACK";
747  break;
748  case ExternalMediaAdapter::MediaType::PODCAST:
749  stream << "PODCAST";
750  break;
751  case ExternalMediaAdapter::MediaType::STATION:
752  stream << "STATION";
753  break;
754  case ExternalMediaAdapter::MediaType::AD:
755  stream << "AD";
756  break;
757  case ExternalMediaAdapter::MediaType::SAMPLE:
758  stream << "SAMPLE";
759  break;
760  case ExternalMediaAdapter::MediaType::OTHER:
761  stream << "OTHER";
762  break;
763  }
764  return stream;
765 }
766 
767 inline std::ostream& operator<<(std::ostream& stream, const ExternalMediaAdapter::Navigation& navigation) {
768  switch (navigation) {
769  case ExternalMediaAdapter::Navigation::DEFAULT:
770  stream << "DEFAULT";
771  break;
772  case ExternalMediaAdapter::Navigation::NONE:
773  stream << "NONE";
774  break;
775  case ExternalMediaAdapter::Navigation::FOREGROUND:
776  stream << "FOREGROUND";
777  break;
778  }
779  return stream;
780 }
781 
782 } // aace::alexa
783 } // aace
784 
785 #endif // AACE_ALEXA_EXTERNAL_MEDIA_ADAPTER_H
MutedState
Definition: AudioOutput.h:69
std::string artistId
Definition: ExternalMediaAdapter.h:342
std::string albumName
The display name of the currently playing album.
Definition: ExternalMediaAdapter.h:345
bool active
Definition: ExternalMediaAdapter.h:273
std::string trackId
The arbitrary identifier for currently playing trackid of the track as per the music provider...
Definition: ExternalMediaAdapter.h:331
std::chrono::milliseconds trackOffset
The offset of the track in milliseconds.
Definition: ExternalMediaAdapter.h:306
MediaType mediaType
The Media type enum value from {TRACK, PODCAST, STATION, AD, SAMPLE, OTHER} type of the media...
Definition: ExternalMediaAdapter.h:372
std::string playbackSourceId
Definition: ExternalMediaAdapter.h:325
std::string userName
The userName of the user currently logged in via a Login directive from the AVS.
Definition: ExternalMediaAdapter.h:261
Definition: PlatformInterface.h:29
Definition: ExternalMediaAdapter.h:396
Definition: ExternalMediaAdapter.h:247
std::string mediaProvider
Definition: ExternalMediaAdapter.h:369
std::vector< SupportedPlaybackOperation > supportedOperations
The set of states the default player can move into from its current state.
Definition: ExternalMediaAdapter.h:303
std::string type
The type of the media item. For now hard-coded to ExternalMediaAdapterMusicItem.
Definition: ExternalMediaAdapter.h:318
bool launched
Flag that identifies if an application has been launched or not.
Definition: ExternalMediaAdapter.h:267
std::string accessToken
Definition: ExternalMediaAdapter.h:279
Favorites favorites
The favorite status {"FAVORITED"/"UNFAVORITED"/"NOT_RATED"}.
Definition: ExternalMediaAdapter.h:315
Definition: AddressBook.h:26
std::string artistName
The display name for the currently playing artist.
Definition: ExternalMediaAdapter.h:338
std::string state
The state of the default player - IDLE/STOPPED/PLAYING...
Definition: ExternalMediaAdapter.h:300
std::string tinyURL
The URL for tiny cover art image resource} .
Definition: ExternalMediaAdapter.h:352
bool loggedIn
Flag that identifies if a user is currently logged in or not.
Definition: ExternalMediaAdapter.h:258
std::string trackNumber
Definition: ExternalMediaAdapter.h:335
std::string playbackSource
The display name for current playback context, e.g. playlist name.
Definition: ExternalMediaAdapter.h:321
std::string endpointId
The unique device endpoint.
Definition: ExternalMediaAdapter.h:255
std::chrono::milliseconds tokenRefreshInterval
The validity period of the token in milliseconds.
Definition: ExternalMediaAdapter.h:282
bool isGuest
Flag that identifies if the user currently logged in is a guest or not.
Definition: ExternalMediaAdapter.h:264
std::string coverId
Definition: ExternalMediaAdapter.h:365
SessionState sessionState
Variable to hold the session state.
Definition: ExternalMediaAdapter.h:387
std::string spiVersion
The only spiVersion that currently exists is "1.0".
Definition: ExternalMediaAdapter.h:288
PlaybackState playbackState
Variable to hold the playback state.
Definition: ExternalMediaAdapter.h:390
Definition: ExternalMediaAdapter.h:294
std::string largeURL
The URL for large cover art image resource} .
Definition: ExternalMediaAdapter.h:361
std::string localPlayerId
The opaque token that uniquely identifies the local external player app.
Definition: ExternalMediaAdapter.h:399
std::string playerCookie
A player may declare arbitrary information for itself.
Definition: ExternalMediaAdapter.h:285
bool shuffleEnabled
Bool to identify if shuffling is enabled or not.
Definition: ExternalMediaAdapter.h:309
std::chrono::milliseconds duration
Media item duration in milliseconds.
Definition: ExternalMediaAdapter.h:375
std::string trackName
The display name for the currently playing trackname of the track.
Definition: ExternalMediaAdapter.h:328
std::string smallURL
The URL for small cover art image resource} .
Definition: ExternalMediaAdapter.h:355
std::string mediumURL
The URL for medium cover art image resource} .
Definition: ExternalMediaAdapter.h:358
bool repeatEnabled
Bool to identify if looping of songs is enabled or not.
Definition: ExternalMediaAdapter.h:312
std::string albumId
Definition: ExternalMediaAdapter.h:349
bool authorized
Authorization status.
Definition: ExternalMediaAdapter.h:401

Alexa Auto SDK 2.0.0 - Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0