AlexaClientSDK  1.25.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 onPlaybackPaused (SourceId, const MediaPlayerState &)
 
virtual void onPlaybackResumed (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()

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()

std::shared_ptr< acsdkNotificationsInterfaces::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  id,
const avsCommon::utils::mediaPlayer::MediaPlayerState state 
)
overridevirtual

This is an indication to the observer that the MediaPlayer has read its first byte of data.

Parameters
idThe id of the source to which this callback corresponds to.
stateMetadata about the media player state

Implements alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface.

◆ 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  id,
const avsCommon::utils::mediaPlayer::ErrorType type,
std::string  error,
const avsCommon::utils::mediaPlayer::MediaPlayerState state 
)
overridevirtual

This is an indication to the observer that the MediaPlayer encountered an error. Errors can occur during playback.

Note
The observer must quickly return from this callback. Failure to do so could block the MediaPlayer from further processing.
Parameters
idThe id of the source to which this callback corresponds to.
typeThe type of error encountered by the MediaPlayerInterface.
errorThe error encountered by the MediaPlayerInterface.
stateMetadata about the media player state

Implements alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface.

◆ onPlaybackFinished()

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

This is an indication to the observer that the MediaPlayer finished the source.

Note
The observer must quickly return to quickly from this callback. Failure to do so could block the MediaPlayer from further processing.
Parameters
idThe id of the source to which this callback corresponds to.
stateMetadata about the media player state

Implements alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface.

◆ onPlaybackStarted()

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

This is an indication to the observer that the MediaPlayer has started playing the source specified by the id.

Note
The observer must quickly return to quickly from this callback. Failure to do so could block the MediaPlayer from further processing.
Parameters
idThe id of the source to which this callback corresponds to.
stateMetadata about the media player state

Implements alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface.

◆ onPlaybackStopped()

void alexaClientSDK::acsdkNotifications::NotificationRenderer::onPlaybackStopped ( SourceId  ,
const avsCommon::utils::mediaPlayer::MediaPlayerState  
)
overridevirtual

This is an indication to the observer that the MediaPlayer has stopped the source.

Note
The observer must quickly return from this callback. Failure to do so could block the MediaPlayer from further processing.
Parameters
SourceIdThe id of the source to which this callback corresponds to.
MediaPlayerStateMetadata about the media player state

Reimplemented from alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface.

◆ 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.

Emit a NotificationRenderer::State value to a stream.

Parameters
streamThe stream to emit the value to.
stateThe state to emit.
Returns
The stream that was emitted to, allowing chained stream operators.

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

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