AlexaClientSDK  1.26.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
UrlContentToAttachmentConverter.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_PLAYLISTPARSER_INCLUDE_PLAYLISTPARSER_URLCONTENTTOATTACHMENTCONVERTER_H_
17 #define ALEXA_CLIENT_SDK_PLAYLISTPARSER_INCLUDE_PLAYLISTPARSER_URLCONTENTTOATTACHMENTCONVERTER_H_
18 
19 #include <atomic>
20 #include <memory>
21 
25 
30 
34 
35 namespace alexaClientSDK {
36 namespace playlistParser {
37 
42 public:
45  public:
49  virtual ~ErrorObserverInterface() = default;
50 
54  virtual void onError() = 0;
55  };
56 
59  public:
63  virtual ~WriteCompleteObserverInterface() = default;
64 
68  virtual void onWriteComplete() = 0;
69  };
70 
91  static std::shared_ptr<UrlContentToAttachmentConverter> create(
92  std::shared_ptr<avsCommon::sdkInterfaces::HTTPContentFetcherInterfaceFactoryInterface> contentFetcherFactory,
93  const std::string& url,
94  std::shared_ptr<ErrorObserverInterface> observer,
95  std::chrono::milliseconds startTime = std::chrono::milliseconds::zero(),
96  std::shared_ptr<WriteCompleteObserverInterface> writeCompleteObserver = nullptr,
97  size_t numOfReaders = 1);
98 
104  std::shared_ptr<avsCommon::avs::attachment::InProcessAttachment> getAttachment();
105 
111  std::chrono::milliseconds getStartStreamingPoint();
112 
118  std::chrono::milliseconds getDesiredStreamingPoint();
119 
120  void doShutdown() override;
121 
122 private:
137  std::shared_ptr<avsCommon::sdkInterfaces::HTTPContentFetcherInterfaceFactoryInterface> contentFetcherFactory,
138  const std::string& url,
139  std::shared_ptr<ErrorObserverInterface> observer,
140  std::chrono::milliseconds startTime,
141  std::shared_ptr<WriteCompleteObserverInterface> writeCompleteObserver,
142  size_t numOfReaders);
143 
144  void onPlaylistEntryParsed(int requestId, avsCommon::utils::playlistParser::PlaylistEntry playlistEntry) override;
145 
149  void notifyError();
150 
154  void notifyWriteComplete();
155 
163 
174  bool writeDecryptedUrlContentIntoStream(
175  std::string url,
176  std::vector<std::string> headers,
178  std::shared_ptr<avsCommon::sdkInterfaces::HTTPContentFetcherInterface> contentFetcher);
179 
189  bool download(
190  const std::string& url,
191  const std::vector<std::string>& headers,
192  std::shared_ptr<avsCommon::avs::attachment::AttachmentWriter> streamWriter,
193  std::shared_ptr<avsCommon::sdkInterfaces::HTTPContentFetcherInterface> contentFetcher);
194 
204  bool download(
205  const std::string& url,
206  const std::vector<std::string>& headers,
207  ByteVector* content,
208  std::shared_ptr<avsCommon::sdkInterfaces::HTTPContentFetcherInterface> contentFetcher);
209 
217  bool readContent(std::shared_ptr<avsCommon::avs::attachment::AttachmentReader> reader, ByteVector* content);
218 
225  bool shouldDecrypt(const avsCommon::utils::playlistParser::EncryptionInfo& encryptionInfo) const;
226 
230  void closeStreamWriter();
231 
233 
235  const std::chrono::milliseconds m_desiredStreamPoint;
236 
238  std::shared_ptr<avsCommon::sdkInterfaces::HTTPContentFetcherInterfaceFactoryInterface> m_contentFetcherFactory;
239 
241  std::shared_ptr<PlaylistParser> m_playlistParser;
242 
244  std::shared_ptr<avsCommon::avs::attachment::InProcessAttachment> m_stream;
245 
247  std::shared_ptr<avsCommon::avs::attachment::AttachmentWriter> m_streamWriter;
248 
250  std::shared_ptr<ErrorObserverInterface> m_observer;
251 
253  std::shared_ptr<WriteCompleteObserverInterface> m_writeCompleteObserver;
254 
256  std::mutex m_mutex;
257 
259  std::atomic<bool> m_shuttingDown;
260 
262  std::shared_ptr<ContentDecrypter> m_contentDecrypter;
263 
265  std::shared_ptr<Id3TagsRemover> m_id3TagsRemover;
266 
274  std::promise<std::chrono::milliseconds> m_startStreamingPointPromise;
277 
279  std::shared_future<std::chrono::milliseconds> m_startStreamingPointFuture;
280 
282  std::chrono::milliseconds m_runningTotal;
283 
285  bool m_startedStreaming;
287 
294  bool m_streamWriterClosed;
298 
306 };
307 
308 } // namespace playlistParser
309 } // namespace alexaClientSDK
310 
311 #endif // ALEXA_CLIENT_SDK_PLAYLISTPARSER_INCLUDE_PLAYLISTPARSER_URLCONTENTTOATTACHMENTCONVERTER_H_
alexaClientSDK::playlistParser::UrlContentToAttachmentConverter
Class that handles the streaming of urls containing media into Attachments.
Definition: UrlContentToAttachmentConverter.h:39
alexaClientSDK::avsCommon::utils::RequiresShutdown
Definition: RequiresShutdown.h:32
PlaylistParser.h
Id3TagsRemover.h
alexaClientSDK::playlistParser::UrlContentToAttachmentConverter::doShutdown
void doShutdown() override
Definition: UrlContentToAttachmentConverter.cpp:395
alexaClientSDK::playlistParser::UrlContentToAttachmentConverter::ErrorObserverInterface
Class to observe errors that arise from converting a URL to to an Attachment.
Definition: UrlContentToAttachmentConverter.h:44
InProcessAttachmentWriter.h
ContentDecrypter.h
alexaClientSDK::avsCommon::utils::playlistParser::EncryptionInfo
Definition: PlaylistEntry.h:59
alexaClientSDK::avsCommon::utils::threading::Executor
Definition: Executor.h:40
RequiresShutdown.h
Executor.h
alexaClientSDK::playlistParser::UrlContentToAttachmentConverter::WriteCompleteObserverInterface
Class to allow notification when writing to the attachment is complete.
Definition: UrlContentToAttachmentConverter.h:58
alexaClientSDK
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
InProcessAttachment.h
alexaClientSDK::playlistParser::UrlContentToAttachmentConverter::ErrorObserverInterface::onError
virtual void onError()=0
InProcessAttachmentReader.h
PlaylistParserObserverInterface.h
alexaClientSDK::avsCommon::utils::playlistParser::PlaylistParserObserverInterface
Definition: PlaylistParserObserverInterface.h:34
alexaClientSDK::playlistParser::UrlContentToAttachmentConverter::WriteCompleteObserverInterface::onWriteComplete
virtual void onWriteComplete()=0
alexaClientSDK::playlistParser::UrlContentToAttachmentConverter::create
static std::shared_ptr< UrlContentToAttachmentConverter > create(std::shared_ptr< avsCommon::sdkInterfaces::HTTPContentFetcherInterfaceFactoryInterface > contentFetcherFactory, const std::string &url, std::shared_ptr< ErrorObserverInterface > observer, std::chrono::milliseconds startTime=std::chrono::milliseconds::zero(), std::shared_ptr< WriteCompleteObserverInterface > writeCompleteObserver=nullptr, size_t numOfReaders=1)
Definition: UrlContentToAttachmentConverter.cpp:47
alexaClientSDK::playlistParser::UrlContentToAttachmentConverter::getAttachment
std::shared_ptr< avsCommon::avs::attachment::InProcessAttachment > getAttachment()
Definition: UrlContentToAttachmentConverter.cpp:67
alexaClientSDK::playlistParser::UrlContentToAttachmentConverter::ErrorObserverInterface::~ErrorObserverInterface
virtual ~ErrorObserverInterface()=default
alexaClientSDK::playlistParser::ByteVector
std::vector< unsigned char > ByteVector
Alias for bytes.
Definition: ContentDecrypter.h:35
alexaClientSDK::avsCommon::utils::playlistParser::PlaylistEntry
Definition: PlaylistEntry.h:111
alexaClientSDK::playlistParser::UrlContentToAttachmentConverter::getStartStreamingPoint
std::chrono::milliseconds getStartStreamingPoint()
Definition: UrlContentToAttachmentConverter.cpp:95
alexaClientSDK::playlistParser::UrlContentToAttachmentConverter::getDesiredStreamingPoint
std::chrono::milliseconds getDesiredStreamingPoint()
Definition: UrlContentToAttachmentConverter.cpp:99
alexaClientSDK::playlistParser::UrlContentToAttachmentConverter::WriteCompleteObserverInterface::~WriteCompleteObserverInterface
virtual ~WriteCompleteObserverInterface()=default
HTTPContentFetcherInterfaceFactoryInterface.h

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