AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
PlaylistEntry.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_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_PLAYLISTPARSER_PLAYLISTENTRY_H_
17 #define ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_PLAYLISTPARSER_PLAYLISTENTRY_H_
18 
19 #include <chrono>
20 #include <ostream>
21 #include <queue>
22 #include <string>
23 
26 
27 namespace alexaClientSDK {
28 namespace avsCommon {
29 namespace utils {
30 namespace playlistParser {
31 
33 typedef std::tuple<long, long> ByteRange;
34 
38 enum class PlaylistParseResult {
39 
41  FINISHED,
42 
47  ERROR,
48 
51 
52  // The playlist parsing was interrupted from a shutdown event
53  SHUTDOWN
54 };
55 
63  enum class Method {
65  NONE,
66 
68  AES_128,
69 
71  SAMPLE_AES
72  };
73 
78 
86  EncryptionInfo(Method method, std::string url, std::string initVector = std::string());
87 
93  bool isValid() const;
94 
97 
100 
103 
105  std::chrono::milliseconds totalDuration;
106 };
107 
115  enum class Type {
117  MEDIA_INFO,
118 
120  MEDIA_INIT_INFO,
121 
123  AUDIO_CONTENT
124  };
125 
132  static PlaylistEntry createErrorEntry(const std::string& url);
133 
140  static PlaylistEntry createShutdownEntry(const std::string& url);
141 
149  static PlaylistEntry createMediaInitInfo(std::string url, ByteRange byteRange = std::make_tuple(0, 0));
150 
163  std::string _url,
164  std::chrono::milliseconds _duration,
166  Type _type = Type::MEDIA_INFO,
167  ByteRange _byteRange = std::make_tuple(0, 0),
168  EncryptionInfo _encryptionInfo = EncryptionInfo(),
169  std::shared_ptr<avsCommon::sdkInterfaces::HTTPContentFetcherInterface> _contentFetcher = nullptr);
170 
174  bool hasValidByteRange() const;
175 
178 
181 
183  std::chrono::milliseconds duration;
184 
187 
189  ByteRange byteRange;
190 
193 
196  std::shared_ptr<avsCommon::sdkInterfaces::HTTPContentFetcherInterface> contentFetcher;
197 };
198 
200  return PlaylistEntry(
201  url, std::chrono::milliseconds(-1), PlaylistParseResult::ERROR, Type::MEDIA_INFO, std::make_tuple(0, 0));
202 }
203 
205  return PlaylistEntry(
206  url, std::chrono::milliseconds(-1), PlaylistParseResult::SHUTDOWN, Type::MEDIA_INFO, std::make_tuple(0, 0));
207 }
208 
210  auto duration = std::chrono::milliseconds(-1);
211  return PlaylistEntry(url, duration, PlaylistParseResult::STILL_ONGOING, Type::MEDIA_INIT_INFO, byteRange);
212 }
213 
214 inline EncryptionInfo::EncryptionInfo() : method(Method::NONE) {
215 }
216 
218  method(method),
219  keyURL(url),
220  initVector(initVector) {
221 }
222 
223 inline bool EncryptionInfo::isValid() const {
224  return (Method::NONE == method) || (Method::NONE != method && !keyURL.empty() && !initVector.empty());
225 }
226 
227 inline bool PlaylistEntry::hasValidByteRange() const {
228  long start, end;
229  std::tie(start, end) = byteRange;
230  return start >= 0 && end > 0;
231 }
232 
234  std::string _url,
235  std::chrono::milliseconds _duration,
237  Type _type,
238  ByteRange _byteRange,
239  EncryptionInfo _encryptionInfo,
240  std::shared_ptr<avsCommon::sdkInterfaces::HTTPContentFetcherInterface> _contentFetcher) :
241  type(_type),
242  url(_url),
243  duration(_duration),
244  parseResult(_parseResult),
245  byteRange(_byteRange),
246  encryptionInfo(_encryptionInfo),
247  contentFetcher(_contentFetcher) {
248 }
249 
250 } // namespace playlistParser
251 } // namespace utils
252 } // namespace avsCommon
253 } // namespace alexaClientSDK
254 
255 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_PLAYLISTPARSER_PLAYLISTENTRY_H_
std::chrono::milliseconds totalDuration
The total duration of the content from the playlist.
Definition: PlaylistEntry.h:105
Definition: PlaylistEntry.h:111
::std::string string
Definition: gtest-port.h:1097
std::shared_ptr< avsCommon::sdkInterfaces::HTTPContentFetcherInterface > contentFetcher
Definition: PlaylistEntry.h:196
EncryptionInfo encryptionInfo
EncryptionInfo of the media.
Definition: PlaylistEntry.h:192
std::tuple< long, long > ByteRange
Alias for holding start and end offsets of byte range of an URL to download.
Definition: PlaylistEntry.h:33
Method method
Encryption method.
Definition: PlaylistEntry.h:96
tuple make_tuple()
Definition: gtest-tuple.h:675
std::string initVector
The initilization vector used for encryption.
Definition: PlaylistEntry.h:102
static PlaylistEntry createErrorEntry(const std::string &url)
Definition: PlaylistEntry.h:199
Type type
Type of playlist entry.
Definition: PlaylistEntry.h:177
PlaylistParseResult parseResult
The latest parsing result.
Definition: PlaylistEntry.h:186
PlaylistParseResult
Definition: PlaylistEntry.h:38
static PlaylistEntry createShutdownEntry(const std::string &url)
Definition: PlaylistEntry.h:204
The playlist has been fully parsed successfully. This indicates that parsing of the playlist has comp...
PlaylistEntry(std::string _url, std::chrono::milliseconds _duration, avsCommon::utils::playlistParser::PlaylistParseResult _parseResult, Type _type=Type::MEDIA_INFO, ByteRange _byteRange=std::make_tuple(0, 0), EncryptionInfo _encryptionInfo=EncryptionInfo(), std::shared_ptr< avsCommon::sdkInterfaces::HTTPContentFetcherInterface > _contentFetcher=nullptr)
Definition: PlaylistEntry.h:233
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
ByteRange byteRange
ByteRange to download.
Definition: PlaylistEntry.h:189
bool hasValidByteRange() const
Definition: PlaylistEntry.h:227
std::chrono::milliseconds duration
The duration of the content if its known; INVALID_DURATION otherwise.
Definition: PlaylistEntry.h:183
type
Definition: upload.py:443
std::string keyURL
The URL of the encryption key.
Definition: PlaylistEntry.h:99
Type
Definition: PlaylistEntry.h:115
bool isValid() const
Definition: PlaylistEntry.h:223
std::string url
The URL for the entry.
Definition: PlaylistEntry.h:180
static PlaylistEntry createMediaInitInfo(std::string url, ByteRange byteRange=std::make_tuple(0, 0))
Definition: PlaylistEntry.h:209

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