AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Public Types | Static Public Member Functions | Friends | List of all members
alexaClientSDK::acsdkNotifications::NotificationRenderer Class Reference

#include <NotificationRenderer.h>

Inheritance diagram for alexaClientSDK::acsdkNotifications::NotificationRenderer:
Inheritance graph
[legend]
Collaboration diagram for alexaClientSDK::acsdkNotifications::NotificationRenderer:
Collaboration graph
[legend]

Public Types

using SourceId = avsCommon::utils::mediaPlayer::MediaPlayerInterface::SourceId
 A type that identifies which source is currently being operated on. More...
 
- Public Types inherited from alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface
enum  TagType {
  TagType::STRING, TagType::UINT, TagType::INT, TagType::DOUBLE,
  TagType::BOOLEAN
}
 The different types of metadata "stream tags". More...
 
using SourceId = MediaPlayerInterface::SourceId
 A type that identifies which source is currently being operated on. More...
 
typedef std::vector< TagKeyValueTypeVectorOfTags
 

Public Member Functions

NotificationRendererInterface methods
void addObserver (std::shared_ptr< acsdkNotificationsInterfaces::NotificationRendererObserverInterface > observer) override
 
void removeObserver (std::shared_ptr< acsdkNotificationsInterfaces::NotificationRendererObserverInterface > observer) override
 
bool renderNotification (std::function< std::pair< std::unique_ptr< std::istream >, const avsCommon::utils::MediaType >()> audioFactory, const std::string &url) override
 
bool cancelNotificationRendering () override
 
MediaPlayerObserverInterface methods
void onFirstByteRead (SourceId sourceId, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
 
void onPlaybackStarted (SourceId sourceId, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
 
void onPlaybackStopped (SourceId sourceId, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
 
void onPlaybackFinished (SourceId sourceId, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
 
void onPlaybackError (SourceId sourceId, const avsCommon::utils::mediaPlayer::ErrorType &type, std::string error, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
 
RequiresShutdown methods
void doShutdown () override
 
ChannelObserverInterface methods
void onFocusChanged (alexaClientSDK::avsCommon::avs::FocusState newFocus, avsCommon::avs::MixingBehavior behavior) override
 
- Public Member Functions inherited from alexaClientSDK::acsdkNotificationsInterfaces::NotificationRendererInterface
virtual ~NotificationRendererInterface ()=default
 
virtual void addObserver (std::shared_ptr< NotificationRendererObserverInterface > observer)=0
 
virtual void removeObserver (std::shared_ptr< NotificationRendererObserverInterface > observer)=0
 
- Public Member Functions inherited from alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface
virtual ~MediaPlayerObserverInterface ()=default
 
virtual void onFirstByteRead (SourceId id, const MediaPlayerState &state)=0
 
virtual void onPlaybackStarted (SourceId id, const MediaPlayerState &state)=0
 
virtual void onPlaybackFinished (SourceId id, const MediaPlayerState &state)=0
 
virtual void onPlaybackError (SourceId id, const ErrorType &type, std::string error, const MediaPlayerState &state)=0
 
virtual void onPlaybackPaused (SourceId, const MediaPlayerState &)
 
virtual void onPlaybackResumed (SourceId, const MediaPlayerState &)
 
virtual void onPlaybackStopped (SourceId, const MediaPlayerState &)
 
virtual void onBufferUnderrun (SourceId, const MediaPlayerState &)
 
virtual void onBufferRefilled (SourceId, const MediaPlayerState &)
 
virtual void onBufferingComplete (SourceId, const MediaPlayerState &)
 
virtual void onSeeked (SourceId, const MediaPlayerState &, const MediaPlayerState &)
 
virtual void onTags (SourceId, std::unique_ptr< const VectorOfTags >, const MediaPlayerState &)
 
- Public Member Functions inherited from alexaClientSDK::avsCommon::utils::RequiresShutdown
 RequiresShutdown (const std::string &name)
 
virtual ~RequiresShutdown ()
 Destructor. More...
 
const std::string & name () const
 
void shutdown ()
 
bool isShutdown () const
 
- Public Member Functions inherited from alexaClientSDK::avsCommon::sdkInterfaces::ChannelObserverInterface
virtual ~ChannelObserverInterface ()=default
 

Static Public Member Functions

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)
 
static std::shared_ptr< NotificationRenderercreate (std::shared_ptr< avsCommon::utils::mediaPlayer::MediaPlayerInterface > mediaPlayer, std::shared_ptr< avsCommon::sdkInterfaces::FocusManagerInterface > focusManager)
 

Friends

std::ostream & operator<< (std::ostream &stream, const NotificationRenderer::State state)
 

Additional Inherited Members

Detailed Description

Implementation of NotificationRendererInterface using the MediaPlayerInterface

Member Typedef Documentation

◆ SourceId

A type that identifies which source is currently being operated on.

Member Function Documentation

◆ addObserver()

void alexaClientSDK::acsdkNotifications::NotificationRenderer::addObserver ( std::shared_ptr< acsdkNotificationsInterfaces::NotificationRendererObserverInterface observer)
override

◆ cancelNotificationRendering()

bool alexaClientSDK::acsdkNotifications::NotificationRenderer::cancelNotificationRendering ( )
overridevirtual

Cancel any ongoing rendering of a notification audio clip. Further render requests will be refused until an observer callback is made to indicate that rendering has finished (i.e. cancellation is complete).

Returns
Whether or not the cancellation was allowed.

Implements alexaClientSDK::acsdkNotificationsInterfaces::NotificationRendererInterface.

◆ create()

static std::shared_ptr<NotificationRenderer> alexaClientSDK::acsdkNotifications::NotificationRenderer::create ( std::shared_ptr< avsCommon::utils::mediaPlayer::MediaPlayerInterface mediaPlayer,
std::shared_ptr< avsCommon::sdkInterfaces::FocusManagerInterface focusManager 
)
static

Create a NotificationRenderer. The new NotificationRenderer starts life in the IDLE state, awaiting request to render notifications.

Parameters
mediaPlayerThe MediaPlayer instance to use to render audio.
focusManagerThe FocusManager instance to use to request audio focus.
Returns
The new NotificationRenderer, or null if the operation fails.

◆ createNotificationRendererInterface()

static std::shared_ptr<NotificationRendererInterface> alexaClientSDK::acsdkNotifications::NotificationRenderer::createNotificationRendererInterface ( const std::shared_ptr< acsdkApplicationAudioPipelineFactoryInterfaces::ApplicationAudioPipelineFactoryInterface > &  audioPipelineFactory,
acsdkManufactory::Annotated< avsCommon::sdkInterfaces::AudioFocusAnnotation, avsCommon::sdkInterfaces::FocusManagerInterface audioFocusManager,
const std::shared_ptr< acsdkShutdownManagerInterfaces::ShutdownNotifierInterface > &  shutdownNotifier 
)
static

Create a NotificationRenderer. The new NotificationRenderer starts life in the IDLE state, awaiting request to render notifications.

Parameters
audioPipelineFactoryThe ApplicationAudioPlayerInterface instance to use to create the notifications media player for rendering audio.
audioFocusManagerThe annotated FocusManager instance to use to request audio focus.
shutdownNotifierThe object to register with to receive notification when it is time to shutdown.
Returns
The new NotificationRenderer, or null if the operation fails.

◆ doShutdown()

void alexaClientSDK::acsdkNotifications::NotificationRenderer::doShutdown ( )
overridevirtual

Prepares/enables this object to be deleted. This should be the last function called on this object prior to deleting (or resetting) its shared_ptr.

Warning
  • Attempting to call functions on this object after calling shutdown() can result in undefined behavior.
  • Neglecting to call shutdown() on this object can result in resource leaks or other undefined behavior.

Implements alexaClientSDK::avsCommon::utils::RequiresShutdown.

◆ onFirstByteRead()

void alexaClientSDK::acsdkNotifications::NotificationRenderer::onFirstByteRead ( SourceId  sourceId,
const avsCommon::utils::mediaPlayer::MediaPlayerState state 
)
override

◆ onFocusChanged()

void alexaClientSDK::acsdkNotifications::NotificationRenderer::onFocusChanged ( alexaClientSDK::avsCommon::avs::FocusState  newFocus,
avsCommon::avs::MixingBehavior  behavior 
)
overridevirtual

Used to notify the observer of the Channel of focus changes. Once called, the client should make a user observable change only and return immediately. Any additional work that needs to be done should be done on a separate thread or after returning. "User observable change" here refers to events that the end user of the product can visibly see or hear. For example, Alexa speech or music playing would be examples of user observable changes. Other work, such as database storing, logging, or communicating via network should be done on a different thread. Not doing so could result in delays for other clients trying to access the Channel.

Parameters
newFocusThe new Focus of the channel.
behaviorThe mixingBehavior for the ChannelObserver to take as per the interrupt model
Note
when newFocus is FocusState::FOREGROUND, the MixingBehavior shall be guaranteed to be PRIMARY when newFocus is FocusState::NONE, the MixingBehavior shall be guaranteed to be MUST_STOP

Implements alexaClientSDK::avsCommon::sdkInterfaces::ChannelObserverInterface.

◆ onPlaybackError()

void alexaClientSDK::acsdkNotifications::NotificationRenderer::onPlaybackError ( SourceId  sourceId,
const avsCommon::utils::mediaPlayer::ErrorType type,
std::string  error,
const avsCommon::utils::mediaPlayer::MediaPlayerState state 
)
override

◆ onPlaybackFinished()

void alexaClientSDK::acsdkNotifications::NotificationRenderer::onPlaybackFinished ( SourceId  sourceId,
const avsCommon::utils::mediaPlayer::MediaPlayerState state 
)
override

◆ onPlaybackStarted()

void alexaClientSDK::acsdkNotifications::NotificationRenderer::onPlaybackStarted ( SourceId  sourceId,
const avsCommon::utils::mediaPlayer::MediaPlayerState state 
)
override

◆ onPlaybackStopped()

void alexaClientSDK::acsdkNotifications::NotificationRenderer::onPlaybackStopped ( SourceId  sourceId,
const avsCommon::utils::mediaPlayer::MediaPlayerState state 
)
override

◆ removeObserver()

void alexaClientSDK::acsdkNotifications::NotificationRenderer::removeObserver ( std::shared_ptr< acsdkNotificationsInterfaces::NotificationRendererObserverInterface observer)
override

◆ renderNotification()

bool alexaClientSDK::acsdkNotifications::NotificationRenderer::renderNotification ( std::function< std::pair< std::unique_ptr< std::istream >, const avsCommon::utils::MediaType >()>  audioFactory,
const std::string &  url 
)
overridevirtual

Render (play) a notification audio clip. If the asset at the specified url cannot be played for some reason, the default notification audio clip should be played, instead. If renderNotification is called while another rendering operation is in progress, this method fails and returns false.

Note
: Calling this method from a NotificationRendererObserverInterface callback will lead to a deadlock.
Parameters
audioFactoryA function that produces a pair of audio stream and media type char to play if the audio specified by url can not be played.
urlURL of the preferred audio asset to play.
Returns
Whether rendering the notification was initiated.

Implements alexaClientSDK::acsdkNotificationsInterfaces::NotificationRendererInterface.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  stream,
const NotificationRenderer::State  state 
)
friend

Friend relationship to allow accessing State to convert it to a string for logging.


The documentation for this class was generated from the following file:

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