16 #ifndef ALEXA_CLIENT_SDK_ACSDKAUDIOPLAYER_INCLUDE_ACSDKAUDIOPLAYER_AUDIOPLAYER_H_ 17 #define ALEXA_CLIENT_SDK_ACSDKAUDIOPLAYER_INCLUDE_ACSDKAUDIOPLAYER_AUDIOPLAYER_H_ 63 namespace acsdkAudioPlayer {
108 return "BUFFER_UNDERRUN";
112 return "unknown AudioPlayerState";
133 ,
public std::enable_shared_from_this<AudioPlayer> {
160 static std::shared_ptr<acsdkAudioPlayerInterfaces::AudioPlayerInterface> createAudioPlayerInterface(
161 const std::shared_ptr<avsCommon::utils::mediaPlayer::PooledMediaResourceProviderInterface>&
162 mediaResourceProvider,
163 const std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface>& messageSender,
167 const std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface>& contextManager,
168 const std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface>& exceptionSender,
169 const std::shared_ptr<avsCommon::sdkInterfaces::PlaybackRouterInterface>& playbackRouter,
170 const std::shared_ptr<captions::CaptionManagerInterface>& captionManager,
171 const std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface>&
metricRecorder,
172 const std::shared_ptr<acsdkShutdownManagerInterfaces::ShutdownNotifierInterface>& shutdownNotifier,
176 const std::shared_ptr<avsCommon::sdkInterfaces::RenderPlayerInfoCardsProviderRegistrarInterface>&
177 renderPlayerInfoCardsProviderRegistrar,
178 const std::shared_ptr<cryptoInterfaces::CryptoFactoryInterface>& cryptoFactory);
195 static std::shared_ptr<AudioPlayer> create(
196 std::shared_ptr<avsCommon::utils::mediaPlayer::PooledMediaResourceProviderInterface> mediaResourceProvider,
197 std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> messageSender,
198 std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface> focusManager,
199 std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface> contextManager,
200 std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface> exceptionSender,
201 std::shared_ptr<avsCommon::sdkInterfaces::PlaybackRouterInterface> playbackRouter,
202 std::shared_ptr<cryptoInterfaces::CryptoFactoryInterface> cryptoFactory,
203 std::shared_ptr<captions::CaptionManagerInterface> captionManager =
nullptr,
204 std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> metricRecorder =
nullptr);
214 void handleDirectiveImmediately(std::shared_ptr<avsCommon::avs::AVSDirective> directive)
override;
215 void preHandleDirective(std::shared_ptr<DirectiveInfo> info)
override;
216 void handleDirective(std::shared_ptr<DirectiveInfo> info)
override;
217 void cancelDirective(std::shared_ptr<DirectiveInfo> info)
override;
218 void onDeregistered()
override;
233 void onPlaybackError(
249 std::unique_ptr<const VectorOfTags> vectorOfTags,
255 void onReadyToProvideNextPlayer()
override;
260 void onProgressReportDelayElapsed()
override;
261 void onProgressReportIntervalElapsed()
override;
262 void onProgressReportIntervalUpdated()
override;
263 void requestProgress()
override;
268 void addObserver(std::shared_ptr<acsdkAudioPlayerInterfaces::AudioPlayerObserverInterface> observer)
override;
269 void removeObserver(std::shared_ptr<acsdkAudioPlayerInterfaces::AudioPlayerObserverInterface> observer)
override;
270 void stopPlayback()
override;
276 std::shared_ptr<avsCommon::sdkInterfaces::RenderPlayerInfoCardsObserverInterface> observer)
override;
282 bool localSeekTo(std::chrono::milliseconds location,
bool fromStart)
override;
287 std::chrono::milliseconds getAudioItemOffset()
override;
288 std::chrono::milliseconds getAudioItemDuration()
override;
293 std::unordered_set<std::shared_ptr<avsCommon::avs::CapabilityConfiguration>> getCapabilityConfigurations()
override;
298 void doShutdown()
override;
315 MessageRequestObserver(
316 std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> metricRecorder,
327 std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> mMetricRecorder;
332 struct PlayDirectiveInfo {
359 std::shared_ptr<avsCommon::utils::mediaPlayer::MediaPlayerInterface> mediaPlayer;
362 std::chrono::milliseconds initialOffset;
378 bool normalizationEnabled;
384 std::shared_ptr<const VectorOfTags> cachedMetadata;
387 std::vector<avsCommon::utils::audioAnalyzer::AudioAnalyzerState> analyzersData;
417 std::shared_ptr<avsCommon::utils::mediaPlayer::PooledMediaResourceProviderInterface> mediaResourceProvider,
418 std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> messageSender,
419 std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface> focusManager,
420 std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface> contextManager,
421 std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface> exceptionSender,
422 std::shared_ptr<avsCommon::sdkInterfaces::PlaybackRouterInterface> playbackRouter,
423 std::vector<std::shared_ptr<avsCommon::sdkInterfaces::ChannelVolumeInterface>> audioChannelVolumeInterfaces,
424 std::shared_ptr<cryptoInterfaces::CryptoFactoryInterface> cryptoFactory,
425 std::shared_ptr<captions::CaptionManagerInterface> captionManager =
nullptr,
426 std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> metricRecorder =
nullptr);
435 bool parseDirectivePayload(std::shared_ptr<DirectiveInfo> info, rapidjson::Document* document);
442 void preHandlePlayDirective(std::shared_ptr<DirectiveInfo> info);
449 void handlePlayDirective(std::shared_ptr<DirectiveInfo> info);
456 void handleStopDirective(std::shared_ptr<DirectiveInfo> info);
463 void handleClearQueueDirective(std::shared_ptr<DirectiveInfo> info);
470 void handleUpdateProgressReportIntervalDirective(std::shared_ptr<DirectiveInfo> info);
477 void removeDirective(std::shared_ptr<DirectiveInfo> info);
484 void setHandlingCompleted(std::shared_ptr<DirectiveInfo> info);
504 void executeProvideState(
bool sendToken =
false,
unsigned int stateRequestToken = 0);
562 void executeOnSeeked(
568 void handlePlaybackCompleted();
575 void callProgressTimer(std::function<
void()> call);
582 void setIsInProgress(
bool isInProgress);
592 void executeOnPlaybackError(
639 std::shared_ptr<const VectorOfTags> vectorOfTags,
645 void executeOnReadyToProvideNextPlayer();
652 void executePrePlay(std::shared_ptr<PlayDirectiveInfo> info);
670 void executeStop(
const std::string& messageId =
"",
bool startNextSong =
false);
684 void executeUpdateProgressReportInterval(std::chrono::milliseconds progressReportInterval);
694 void executeLocalOperationTimedout();
702 bool executeLocalSeekTo(std::chrono::milliseconds location,
bool fromStart);
709 std::chrono::milliseconds getDuration();
727 void sendEventWithTokenAndOffset(
729 bool includePlaybackReports =
false,
774 void sendPlaybackSeekedEvent(
786 void sendPlaybackFailedEvent(
814 void sendPlaybackQueueClearedEvent();
837 void sendStreamMetadataExtractedEvent(
839 std::shared_ptr<const VectorOfTags> vectorOfTags,
843 void notifyObserver();
850 void notifySeekActivity(
852 std::chrono::milliseconds offset);
856 std::chrono::milliseconds offset = std::chrono::milliseconds(-1));
868 std::chrono::milliseconds getOffset();
876 void attachPlaybackAttributesIfAvailable(
rapidjson::Value& parent, rapidjson::Document::AllocatorType& allocator);
884 void attachPlaybackReportsIfAvailable(
rapidjson::Value& parent, rapidjson::Document::AllocatorType& allocator);
898 void clearPlayQueue(
const bool stopCurrentPlayer);
906 void stopAndReleaseMediaPlayer(std::shared_ptr<PlayDirectiveInfo> playbackItem);
913 void releaseMediaPlayer(std::shared_ptr<PlayDirectiveInfo> playbackItem);
921 bool configureMediaPlayer(std::shared_ptr<PlayDirectiveInfo>& playbackItem);
929 bool isMessageInQueue(
const std::string& messageId);
937 bool executeStopDucking();
945 bool executeStartDucking();
1024 bool isPlaybackActive()
const;
1031 std::shared_ptr<avsCommon::utils::mediaPlayer::PooledMediaResourceProviderInterface> m_mediaResourceProvider;
1034 std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> m_messageSender;
1037 std::shared_ptr<avsCommon::sdkInterfaces::FocusManagerInterface> m_focusManager;
1040 std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface> m_contextManager;
1043 std::shared_ptr<avsCommon::sdkInterfaces::PlaybackRouterInterface> m_playbackRouter;
1046 std::shared_ptr<cryptoInterfaces::CryptoFactoryInterface> m_cryptoFactory;
1049 std::shared_ptr<captions::CaptionManagerInterface> m_captionManager;
1052 std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> m_metricRecorder;
1071 mutable std::mutex m_currentStateMutex;
1074 std::condition_variable m_currentStateConditionVariable;
1091 std::deque<std::shared_ptr<PlayDirectiveInfo>> m_audioPlayQueue;
1096 std::shared_ptr<PlayDirectiveInfo> m_currentlyPlaying;
1102 std::shared_ptr<PlayDirectiveInfo> m_itemPendingPlaybackStart;
1105 std::chrono::steady_clock::time_point m_bufferUnderrunTimestamp;
1115 std::chrono::milliseconds m_offset;
1118 std::unordered_set<std::shared_ptr<acsdkAudioPlayerInterfaces::AudioPlayerObserverInterface>> m_observers;
1121 std::shared_ptr<avsCommon::sdkInterfaces::RenderPlayerInfoCardsObserverInterface> m_renderPlayerObserver;
1127 bool m_playNextItemAfterStopped;
1133 bool m_isStopCalled;
1138 bool m_okToRequestNextTrack;
1159 bool m_isAcquireChannelRequestPending;
1164 std::unordered_set<std::shared_ptr<avsCommon::avs::CapabilityConfiguration>> m_capabilityConfigurations;
1182 bool m_isRecordingTimeToPlayback;
1185 bool m_isAutoProgressing;
1188 bool m_isLocalResumePending;
1191 std::promise<bool> m_localResumeSuccess;
1194 bool m_isStartingPlayback;
1197 bool m_isPausingPlayback;
1200 std::vector<std::shared_ptr<avsCommon::sdkInterfaces::ChannelVolumeInterface>> m_audioChannelVolumeInterfaces;
1223 #endif // ALEXA_CLIENT_SDK_ACSDKAUDIOPLAYER_INCLUDE_ACSDKAUDIOPLAYER_AUDIOPLAYER_H_ Definition: AudioFocusAnnotation.h:25
Definition: CapabilityAgent.h:47
MixingBehavior
Definition: MixingBehavior.h:25
Definition: CapabilityConfigurationInterface.h:32
Definition: NamespaceAndName.h:32
PlayBehavior
Used to determine how a client must handle queueing and playback of a stream.
Definition: PlayBehavior.h:29
Definition: MessageRequest.h:40
Indicates that an audio stream is pre-buffering, but is not ready to play.
::std::string string
Definition: gtest-port.h:1097
std::string playerStateToString(AudioPlayerState state)
Definition: AudioPlayer.h:95
Definition: DataPointDurationBuilder.h:30
Definition: AudioPlayer.h:122
Single-thread executor implementation.
Definition: Executor.h:45
Definition: EndpointCapabilitiesRegistrarInterface.h:35
The context of the AudioPlayer when the observer is notified of the PlayerActivity state change...
Definition: AudioPlayerObserverInterface.h:39
Definition: RequiresShutdown.h:32
Definition: AudioPlayerInterface.h:30
FocusState
Definition: FocusState.h:29
Definition: FocusManagerInterface.h:54
Indicates that audio is currently playing.
Initial state, prior to acting on the first Play directive, or after the current queue is finished...
Definition: LocalPlaybackHandlerInterface.h:30
static std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder
Metric recorder shared ptr.
Definition: BaseAPLCapabilityAgentTest.cpp:261
ClearBehavior
Used to determine clear queue behavior.
Definition: ClearBehavior.h:28
Definition: DefaultEndpointAnnotation.h:26
Indicates that playback has finished.
bool Value(const T &value, M matcher)
Definition: gmock-matchers.h:4347
Definition: Annotated.h:35
std::unordered_map< directiveRoutingRule::DirectiveRoutingRule, BlockingPolicy > DirectiveHandlerConfiguration
Definition: DirectiveHandlerConfiguration.h:32
PlaybackOperation
Definition: LocalPlaybackHandlerInterface.h:40
Indicates that the audio stream has been paused.
Definition: ProgressTimer.h:33
MixingBehavior
Definition: MixingBehavior.h:27
Definition: ProgressTimer.h:40
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
AudioPlayerState
Definition: AudioPlayer.h:68
ContentType
Definition: ContentType.h:25
type
Definition: upload.py:443
Definition: PlayRequestor.h:29
Status
Definition: MessageRequestObserverInterface.h:33
Definition: TimeUtils.h:34
PlayerActivity
Identifies the player state.
Definition: PlayerActivity.h:27
tuple message
Definition: gtest_output_test.py:331
Definition: RenderPlayerInfoCardsProviderInterface.h:30
SeekStatus
Enum representing Seek activities.
Definition: AudioPlayerObserverInterface.h:63
Struct which contains all the fields which define an audio item for a Play directive.
Definition: AudioItem.h:33