AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
NotificationRenderer.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 ACSDKNOTIFICATIONS_NOTIFICATIONRENDERER_H_
17 #define ACSDKNOTIFICATIONS_NOTIFICATIONRENDERER_H_
18 
19 #include <mutex>
20 #include <unordered_set>
21 
34 
35 namespace alexaClientSDK {
36 namespace acsdkNotifications {
37 
39 static const constexpr char* NOTIFICATIONS_MEDIA_PLAYER_NAME = "NotificationsMediaPlayer";
40 
50  , public std::enable_shared_from_this<NotificationRenderer> {
51 public:
54 
66  static std::shared_ptr<NotificationRendererInterface> createNotificationRendererInterface(
67  const std::shared_ptr<acsdkApplicationAudioPipelineFactoryInterfaces::ApplicationAudioPipelineFactoryInterface>&
68  audioPipelineFactory,
72  const std::shared_ptr<acsdkShutdownManagerInterfaces::ShutdownNotifierInterface>& shutdownNotifier);
73 
83  static std::shared_ptr<NotificationRenderer> create(
84  std::shared_ptr<avsCommon::utils::mediaPlayer::MediaPlayerInterface> mediaPlayer,
85  std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface> focusManager);
86 
89  void addObserver(
90  std::shared_ptr<acsdkNotificationsInterfaces::NotificationRendererObserverInterface> observer) override;
91  void removeObserver(
92  std::shared_ptr<acsdkNotificationsInterfaces::NotificationRendererObserverInterface> observer) override;
93  bool renderNotification(
94  std::function<std::pair<std::unique_ptr<std::istream>, const avsCommon::utils::MediaType>()> audioFactory,
95  const std::string& url) override;
96  bool cancelNotificationRendering() override;
98 
101  void onFirstByteRead(SourceId sourceId, const avsCommon::utils::mediaPlayer::MediaPlayerState& state) override;
102  void onPlaybackStarted(SourceId sourceId, const avsCommon::utils::mediaPlayer::MediaPlayerState& state) override;
103  void onPlaybackStopped(SourceId sourceId, const avsCommon::utils::mediaPlayer::MediaPlayerState& state) override;
105  void onPlaybackError(
106  SourceId sourceId,
108  std::string error,
111 
114  void doShutdown() override;
116 
120  override;
122 
123 private:
132  enum class State {
137  IDLE,
145  RENDERING_PREFERRED,
152  RENDERING_DEFAULT,
157  CANCELLING,
163  NOTIFYING
164  };
165 
174  std::shared_ptr<avsCommon::utils::mediaPlayer::MediaPlayerInterface> mediaPlayer,
175  std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface> focusManager);
176 
184  void onRenderingFinished(SourceId sourceId);
185 
192  bool setState(State newState);
193 
201  bool setStateLocked(State newState);
202 
211  bool verifyRenderingLocked(const std::string& caller, SourceId sourceId);
212 
214  std::shared_ptr<avsCommon::utils::mediaPlayer::MediaPlayerInterface> m_mediaPlayer;
215 
218  std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface> m_focusManager;
219 
222  avsCommon::avs::FocusState m_focusState;
223 
226  std::unordered_set<std::shared_ptr<acsdkNotificationsInterfaces::NotificationRendererObserverInterface>>
227  m_observers;
228 
230  std::mutex m_mutex;
231 
233  std::condition_variable m_wakeTrigger;
234 
236  State m_state;
237 
240  std::function<std::pair<std::unique_ptr<std::istream>, const avsCommon::utils::MediaType>()> m_audioFactory;
241 
244  SourceId m_sourceId;
245 
248  std::future<void> m_renderFallbackFuture;
249 
258 
261  friend std::ostream& operator<<(std::ostream& stream, const NotificationRenderer::State state);
262 };
263 
264 } // namespace acsdkNotifications
265 } // namespace alexaClientSDK
266 
267 #endif // ACSDKNOTIFICATIONS_NOTIFICATIONRENDERER_H_
bool renderNotification(std::function< std::pair< std::unique_ptr< std::istream >, const avsCommon::utils::MediaType >()> audioFactory, const std::string &url) override
MixingBehavior
Definition: MixingBehavior.h:25
void onPlaybackFinished(SourceId sourceId, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
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
Single-thread executor implementation.
Definition: Executor.h:45
MediaType
Definition: MediaType.h:29
static const constexpr char * NOTIFICATIONS_MEDIA_PLAYER_NAME
String to identify the notifications media player to render audio.
Definition: NotificationRenderer.h:39
void onPlaybackStopped(SourceId sourceId, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
FocusState
Definition: FocusState.h:29
friend std::ostream & operator<<(std::ostream &stream, const NotificationRenderer::State state)
void onPlaybackStarted(SourceId sourceId, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
static std::shared_ptr< NotificationRendererInterface > createNotificationRendererInterface(const std::shared_ptr< acsdkApplicationAudioPipelineFactoryInterfaces::ApplicationAudioPipelineFactoryInterface > &audioPipelineFactory, acsdkManufactory::Annotated< avsCommon::sdkInterfaces::AudioFocusAnnotation, avsCommon::sdkInterfaces::FocusManagerInterface > audioFocusManager, const std::shared_ptr< acsdkShutdownManagerInterfaces::ShutdownNotifierInterface > &shutdownNotifier)
void onFocusChanged(alexaClientSDK::avsCommon::avs::FocusState newFocus, avsCommon::avs::MixingBehavior behavior) override
MediaPlayerInterface::SourceId SourceId
A type that identifies which source is currently being operated on.
Definition: MediaPlayerObserverInterface.h:49
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
void onPlaybackError(SourceId sourceId, const avsCommon::utils::mediaPlayer::ErrorType &type, std::string error, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
void onFirstByteRead(SourceId sourceId, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
static std::shared_ptr< NotificationRenderer > create(std::shared_ptr< avsCommon::utils::mediaPlayer::MediaPlayerInterface > mediaPlayer, std::shared_ptr< avsCommon::sdkInterfaces::FocusManagerInterface > focusManager)
type
Definition: upload.py:443
ErrorType
Identifies the specific type of error in a PlaybackFailed event.
Definition: ErrorTypes.h:28
void addObserver(std::shared_ptr< acsdkNotificationsInterfaces::NotificationRendererObserverInterface > observer) override
void removeObserver(std::shared_ptr< acsdkNotificationsInterfaces::NotificationRendererObserverInterface > observer) 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