AlexaClientSDK  1.26.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
CaptionManager.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 ALEXA_CLIENT_SDK_CAPTIONS_IMPLEMENTATION_INCLUDE_CAPTIONS_CAPTIONMANAGER_H_
17 #define ALEXA_CLIENT_SDK_CAPTIONS_IMPLEMENTATION_INCLUDE_CAPTIONS_CAPTIONMANAGER_H_
18 
19 #include <atomic>
20 #include <mutex>
21 #include <unordered_map>
22 
25 
26 #include <Captions/CaptionFrame.h>
28 #include <Captions/CaptionLine.h>
33 
34 namespace alexaClientSDK {
35 namespace captions {
36 
60  , public std::enable_shared_from_this<CaptionManager> {
61 public:
70  static std::shared_ptr<CaptionManager> create(
71  std::shared_ptr<CaptionParserInterface> parser,
72  std::shared_ptr<TimingAdapterFactory> timingAdapterFactory = nullptr);
73 
76  void doShutdown() override;
78 
81  void onCaption(CaptionFrame::MediaPlayerSourceId sourceId, const CaptionData& captionData) override;
82  void setCaptionPresenter(const std::shared_ptr<CaptionPresenterInterface>& presenter) override;
83  void setMediaPlayers(
84  const std::vector<std::shared_ptr<avsCommon::utils::mediaPlayer::MediaPlayerInterface>>& mediaPlayers) override;
85  void addMediaPlayer(
86  const std::shared_ptr<avsCommon::utils::mediaPlayer::MediaPlayerInterface>& mediaPlayer) override;
87  void removeMediaPlayer(
88  const std::shared_ptr<avsCommon::utils::mediaPlayer::MediaPlayerInterface>& mediaPlayer) override;
89  bool isEnabled() const override;
91 
94  void onParsed(const CaptionFrame& captionFrame) override;
96 
99  void onPlaybackStarted(
102  void onPlaybackFinished(
105  void onPlaybackError(
108  std::string error,
110  void onPlaybackPaused(
113  void onPlaybackResumed(
116  void onPlaybackStopped(
121  const avsCommon::utils::mediaPlayer::MediaPlayerState& state) override{};
123 
124 private:
132  std::shared_ptr<CaptionParserInterface> parser,
133  std::shared_ptr<TimingAdapterFactory> timingAdapterFactory);
134 
141  void logMediaStateNotHandled(
142  const std::string& event,
143  const std::string& reason,
145 
152  std::unordered_map<CaptionFrame::MediaPlayerSourceId, std::shared_ptr<CaptionTimingAdapterInterface>>
153  m_timingAdaptersBySourceIds;
154 
156  std::shared_ptr<CaptionPresenterInterface> m_presenter;
157 
159  std::shared_ptr<CaptionParserInterface> m_parser;
160 
162  std::shared_ptr<TimingAdapterFactory> m_timingFactory;
163 
165  std::vector<std::shared_ptr<avsCommon::utils::mediaPlayer::MediaPlayerInterface>> m_mediaPlayers;
166 
168  std::mutex m_mutex;
169 };
170 
171 } // namespace captions
172 } // namespace alexaClientSDK
173 
174 #endif // ALEXA_CLIENT_SDK_CAPTIONS_IMPLEMENTATION_INCLUDE_CAPTIONS_CAPTIONMANAGER_H_
void setCaptionPresenter(const std::shared_ptr< CaptionPresenterInterface > &presenter) override
Definition: CaptionManager.cpp:99
void onPlaybackPaused(CaptionFrame::MediaPlayerSourceId id, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
Definition: CaptionManager.cpp:354
void onPlaybackResumed(CaptionFrame::MediaPlayerSourceId id, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
Definition: CaptionManager.cpp:366
void removeMediaPlayer(const std::shared_ptr< avsCommon::utils::mediaPlayer::MediaPlayerInterface > &mediaPlayer) override
Definition: CaptionManager.cpp:160
Definition: CaptionManagerInterface.h:32
void addMediaPlayer(const std::shared_ptr< avsCommon::utils::mediaPlayer::MediaPlayerInterface > &mediaPlayer) override
Definition: CaptionManager.cpp:135
static std::shared_ptr< CaptionManager > create(std::shared_ptr< CaptionParserInterface > parser, std::shared_ptr< TimingAdapterFactory > timingAdapterFactory=nullptr)
Definition: CaptionManager.cpp:50
Definition: CaptionFrame.h:33
Definition: CaptionData.h:30
void onCaption(CaptionFrame::MediaPlayerSourceId sourceId, const CaptionData &captionData) override
Definition: CaptionManager.cpp:89
void onPlaybackStopped(CaptionFrame::MediaPlayerSourceId id, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
Definition: CaptionManager.cpp:378
void onPlaybackStarted(CaptionFrame::MediaPlayerSourceId id, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
Definition: CaptionManager.cpp:309
void onPlaybackError(CaptionFrame::MediaPlayerSourceId id, const avsCommon::utils::mediaPlayer::ErrorType &type, std::string error, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
Definition: CaptionManager.cpp:336
void onPlaybackFinished(CaptionFrame::MediaPlayerSourceId id, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
Definition: CaptionManager.cpp:321
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
void onFirstByteRead(CaptionFrame::MediaPlayerSourceId id, const avsCommon::utils::mediaPlayer::MediaPlayerState &state) override
Definition: CaptionManager.h:119
avsCommon::utils::mediaPlayer::MediaPlayerInterface::SourceId MediaPlayerSourceId
Type alias to the media player source ID.
Definition: CaptionFrame.h:36
void setMediaPlayers(const std::vector< std::shared_ptr< avsCommon::utils::mediaPlayer::MediaPlayerInterface >> &mediaPlayers) override
Definition: CaptionManager.cpp:105
ErrorType
Identifies the specific type of error in a PlaybackFailed event.
Definition: ErrorTypes.h:27
Definition: CaptionFrameParseListenerInterface.h:27
Definition: CaptionManager.h:55
void doShutdown() override
Definition: CaptionManager.cpp:68
bool isEnabled() const override
Definition: CaptionManager.cpp:196
void onParsed(const CaptionFrame &captionFrame) override
Definition: CaptionManager.cpp:206

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