AlexaClientSDK  1.19.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::capabilityAgents::notifications::NotificationRenderer Class Reference

#include <NotificationRenderer.h>

Inheritance diagram for alexaClientSDK::capabilityAgents::notifications::NotificationRenderer:
Inheritance graph
[legend]
Collaboration diagram for alexaClientSDK::capabilityAgents::notifications::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< NotificationRendererObserverInterface > observer) override
 
void removeObserver (std::shared_ptr< 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::capabilityAgents::notifications::NotificationRendererInterface
virtual ~NotificationRendererInterface ()=default
 
- Public Member Functions inherited from alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerObserverInterface
virtual ~MediaPlayerObserverInterface ()=default
 
virtual void onPlaybackPaused (SourceId id, const MediaPlayerState &state)
 
virtual void onPlaybackResumed (SourceId id, const MediaPlayerState &state)
 
virtual void onBufferUnderrun (SourceId id, const MediaPlayerState &state)
 
virtual void onBufferRefilled (SourceId id, const MediaPlayerState &state)
 
virtual void onBufferingComplete (SourceId id, const MediaPlayerState &state)
 
virtual void onTags (SourceId id, std::unique_ptr< const VectorOfTags > vectorOfTags, const MediaPlayerState &state)
 
- 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< 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)
 Friend relationship to allow accessing State to convert it to a string for logging. More...
 

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::capabilityAgents::notifications::NotificationRenderer::addObserver ( std::shared_ptr< NotificationRendererObserverInterface observer)
overridevirtual

Add an observer to receive a notifications about rendering notification audio clips.

Parameters
observerThe observer to call back.

Implements alexaClientSDK::capabilityAgents::notifications::NotificationRendererInterface.

◆ cancelNotificationRendering()

bool alexaClientSDK::capabilityAgents::notifications::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::capabilityAgents::notifications::NotificationRendererInterface.

◆ create()

std::shared_ptr< NotificationRenderer > alexaClientSDK::capabilityAgents::notifications::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.

◆ doShutdown()

void alexaClientSDK::capabilityAgents::notifications::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::capabilityAgents::notifications::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::capabilityAgents::notifications::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::capabilityAgents::notifications::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::capabilityAgents::notifications::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::capabilityAgents::notifications::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::capabilityAgents::notifications::NotificationRenderer::onPlaybackStopped ( SourceId  id,
const avsCommon::utils::mediaPlayer::MediaPlayerState state 
)
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
idThe id of the source to which this callback corresponds to.
stateMetadata about the media player state

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

◆ removeObserver()

void alexaClientSDK::capabilityAgents::notifications::NotificationRenderer::removeObserver ( std::shared_ptr< NotificationRendererObserverInterface observer)
overridevirtual

Remove an observer from the set of observers to receive a notifications about rendering notification audio clips.

Parameters
observerThe observer to call back.

Implements alexaClientSDK::capabilityAgents::notifications::NotificationRendererInterface.

◆ renderNotification()

bool alexaClientSDK::capabilityAgents::notifications::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::capabilityAgents::notifications::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.19.0 - Copyright 2016-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0