Shaka Packager SDK
Loading...
Searching...
No Matches
adaptation_set.h
1// Copyright 2017 Google LLC. All rights reserved.
2//
3// Use of this source code is governed by a BSD-style
4// license that can be found in the LICENSE file or at
5// https://developers.google.com/open-source/licenses/bsd
6//
8
9#ifndef PACKAGER_MPD_BASE_ADAPTATION_SET_H_
10#define PACKAGER_MPD_BASE_ADAPTATION_SET_H_
11
12#include <cstdint>
13#include <list>
14#include <map>
15#include <memory>
16#include <optional>
17#include <set>
18#include <string>
19#include <vector>
20
21#include <packager/mpd/base/media_info.pb.h>
22#include <packager/mpd/base/xml/xml_node.h>
23
24namespace shaka {
25
26class MediaInfo;
27class Representation;
28
29struct ContentProtectionElement;
30struct MpdOptions;
31
35 public:
36 // The role for this AdaptationSet. These values are used to add a Role
37 // element to the AdaptationSet with schemeIdUri=urn:mpeg:dash:role:2011.
38 // See ISO/IEC 23009-1:2012 section 5.8.5.5.
39 enum Role {
40 kRoleUnknown,
41 kRoleCaption,
42 kRoleSubtitle,
43 kRoleMain,
44 kRoleAlternate,
45 kRoleSupplementary,
46 kRoleCommentary,
47 kRoleDub,
48 kRoleDescription,
49 kRoleSign,
50 kRoleMetadata,
51 kRoleEnhancedAudioIntelligibility,
52 kRoleEmergency,
53 kRoleForcedSubtitle,
54 kRoleEasyreader,
55 kRoleKaraoke,
56 };
57
58 virtual ~AdaptationSet();
59
66 virtual Representation* AddRepresentation(const MediaInfo& media_info);
67
75 const Representation& representation);
76
86 virtual void AddContentProtectionElement(
87 const ContentProtectionElement& element);
88
100 virtual void UpdateContentProtectionPssh(const std::string& drm_uuid,
101 const std::string& pssh);
102
107 virtual void AddAccessibility(const std::string& scheme,
108 const std::string& value);
109
114 virtual void AddRole(Role role);
115
120 std::optional<xml::XmlNode> GetXml();
121
127 virtual void ForceSetSegmentAlignment(bool segment_alignment);
128
133 virtual void ForceSubsegmentStartswithSAP(uint32_t sap_value);
134
138 virtual void ForceStartwithSAP(uint32_t sap_value);
139
142 virtual void AddAdaptationSetSwitching(const AdaptationSet* adaptation_set);
143
145 bool has_id() const { return static_cast<bool>(id_); }
146
148 std::optional<uint32_t> SortIndex() const {
149 return index_.has_value() ? index_ : id_;
150 }
151
152 // Must be unique in the Period.
153 uint32_t id() const { return id_.value(); }
154
157 void set_id(uint32_t id) { id_ = id; }
158
170 void OnNewSegmentForRepresentation(uint32_t representation_id,
171 int64_t start_time,
172 int64_t duration);
173
186 void OnSetFrameRateForRepresentation(uint32_t representation_id,
187 int32_t frame_duration,
188 int32_t timescale);
189
192 virtual void AddTrickPlayReference(const AdaptationSet* adaptation_set);
193
194 // Return the list of Representations in this AdaptationSet.
195 const std::list<Representation*> GetRepresentations() const;
196
198 bool IsVideo() const;
199
201 const std::string& codec() const { return codec_; }
202
205 void set_codec(const std::string& codec) { codec_ = codec; };
206
208 uint32_t matrix_coefficients() const { return matrix_coefficients_; }
209
213 matrix_coefficients_ = matrix_coefficients;
214 };
215
217 uint32_t color_primaries() const { return color_primaries_; }
218
221 void set_color_primaries(const uint32_t& color_primaries) {
222 color_primaries_ = color_primaries;
223 };
224
226 uint32_t transfer_characteristics() const {
227 return transfer_characteristics_;
228 }
229
233 transfer_characteristics_ = transfer_characteristics;
234 };
235
237 const MediaInfo::ProtectedContent* protected_content() const {
238 return protected_content_;
239 };
240
243 void set_protected_content(const MediaInfo& media_info);
244
251 bool MatchAdaptationSet(const MediaInfo& media_info,
252 bool content_protection_in_adaptation_set);
253
257 bool SwitchableAdaptationSet(const AdaptationSet& adaptation_set);
258
259 protected:
266 AdaptationSet(const std::string& language,
267 const MpdOptions& mpd_options,
268 uint32_t* representation_counter);
269
270 private:
271 AdaptationSet(const AdaptationSet&) = delete;
272 AdaptationSet& operator=(const AdaptationSet&) = delete;
273
274 friend class Period;
275 friend class AdaptationSetTest;
276
277 // kSegmentAlignmentUnknown means that it is uncertain if the
278 // (sub)segments are aligned or not.
279 // kSegmentAlignmentTrue means that it is certain that the all the (current)
280 // segments added to the adaptation set are aligned.
281 // kSegmentAlignmentFalse means that it is it is certain that some segments
282 // are not aligned. This is useful to disable the computation for
283 // segment alignment, once it is certain that some segments are not aligned.
284 enum SegmentAligmentStatus {
285 kSegmentAlignmentUnknown,
286 kSegmentAlignmentTrue,
287 kSegmentAlignmentFalse
288 };
289
290 // This maps Representations (IDs) to a list of start times of the segments.
291 // e.g.
292 // If Representation 1 has start time 0, 100, 200 and Representation 2 has
293 // start times 0, 200, 400, then the map contains:
294 // 1 -> [0, 100, 200]
295 // 2 -> [0, 200, 400]
296 typedef std::map<uint32_t, std::list<int64_t>> RepresentationTimeline;
297
298 // Update AdaptationSet attributes for new MediaInfo.
299 void UpdateFromMediaInfo(const MediaInfo& media_info);
300
309 void CheckDynamicSegmentAlignment(uint32_t representation_id,
310 int64_t start_time,
311 int64_t duration);
312
313 // Checks representation_segment_start_times_ and sets segments_aligned_.
314 // Use this for static MPD, do not use for dynamic MPD.
315 void CheckStaticSegmentAlignment();
316
317 // Records the framerate of a Representation.
318 void RecordFrameRate(int32_t frame_duration, int32_t timescale);
319
320 std::list<ContentProtectionElement> content_protection_elements_;
321 // representation_id => Representation map. It also keeps the representations_
322 // sorted by default.
323 std::map<uint32_t, std::unique_ptr<Representation>> representation_map_;
324
325 uint32_t* const representation_counter_;
326
327 std::optional<uint32_t> id_;
328 const std::string language_;
329 const MpdOptions& mpd_options_;
330
331 // An array of adaptation sets this adaptation set can switch to.
332 std::vector<const AdaptationSet*> switchable_adaptation_sets_;
333
334 // Video widths and heights of Representations. Note that this is a set; if
335 // there is only 1 resolution, then @width & @height should be set, otherwise
336 // @maxWidth & @maxHeight should be set for DASH IOP.
337 std::set<uint32_t> video_widths_;
338 std::set<uint32_t> video_heights_;
339
340 // Video representations' frame rates.
341 // The frame rate notation for MPD is <integer>/<integer> (where the
342 // denominator is optional). This means the frame rate could be non-whole
343 // rational value, therefore the key is of type double.
344 // Value is <integer>/<integer> in string form.
345 // So, key == CalculatedValue(value)
346 std::map<double, std::string> video_frame_rates_;
347
348 // contentType attribute of AdaptationSet.
349 // Determined by examining the MediaInfo passed to AddRepresentation().
350 std::string content_type_;
351
352 // Codec of AdaptationSet.
353 std::string codec_;
354
355 // This does not have to be a set, it could be a list or vector because all we
356 // really care is whether there is more than one entry.
357 // Contains one entry if all the Representations have the same picture aspect
358 // ratio (@par attribute for AdaptationSet).
359 // There will be more than one entry if there are multiple picture aspect
360 // ratios.
361 // The @par attribute should only be set if there is exactly one entry
362 // in this set.
363 std::set<std::string> picture_aspect_ratio_;
364
365 // accessibilities of this AdaptationSet.
366 struct Accessibility {
367 std::string scheme;
368 std::string value;
369 };
370 std::vector<Accessibility> accessibilities_;
371
372 // The roles of this AdaptationSet.
373 std::set<Role> roles_;
374
375 // True iff all the segments are aligned.
376 SegmentAligmentStatus segments_aligned_ = kSegmentAlignmentUnknown;
377 bool force_set_segment_alignment_ = false;
378
379 // The stream access point for subsegment
380 uint8_t subsegment_start_with_sap_ = 0;
381
382 // The stream access point for segment
383 uint8_t start_with_sap_ = 0;
384
385 // Keeps track of segment start times of Representations.
386 // For static MPD, this will not be cleared, all the segment start times are
387 // stored in this. This should not out-of-memory for a reasonable length
388 // video and reasonable subsegment length.
389 // For dynamic MPD, the entries are deleted (see
390 // CheckDynamicSegmentAlignment() implementation comment) because storing the
391 // entire timeline is not reasonable and may cause an out-of-memory problem.
392 RepresentationTimeline representation_segment_start_times_;
393
394 // Record the original AdaptationSets the trick play stream belongs to. There
395 // can be more than one reference AdaptationSets as multiple streams e.g. SD
396 // and HD videos in different AdaptationSets can share the same trick play
397 // stream.
398 std::vector<const AdaptationSet*> trick_play_references_;
399
400 // Matrix Coefficients.
401 uint32_t matrix_coefficients_ = 0;
402 // Colour Primaries.
403 uint32_t color_primaries_ = 0;
404
405 // Transfer characteristics.
406 uint32_t transfer_characteristics_ = 0;
407
408 // the command-line index for this AdaptationSet
409 std::optional<uint32_t> index_;
410
411 // The label of this AdaptationSet.
412 std::string label_;
413
414 // ProtectedContent of this AdaptationSet.
415 MediaInfo::ProtectedContent* protected_content_;
416};
417
418} // namespace shaka
419
420#endif // PACKAGER_MPD_BASE_ADAPTATION_SET_H_
uint32_t transfer_characteristics() const
void OnNewSegmentForRepresentation(uint32_t representation_id, int64_t start_time, int64_t duration)
virtual Representation * AddRepresentation(const MediaInfo &media_info)
virtual void AddAccessibility(const std::string &scheme, const std::string &value)
virtual void AddContentProtectionElement(const ContentProtectionElement &element)
virtual void ForceStartwithSAP(uint32_t sap_value)
const MediaInfo::ProtectedContent * protected_content() const
Return ProtectedContent.
virtual void ForceSetSegmentAlignment(bool segment_alignment)
void OnSetFrameRateForRepresentation(uint32_t representation_id, int32_t frame_duration, int32_t timescale)
virtual Representation * CopyRepresentation(const Representation &representation)
void set_matrix_coefficients(const uint32_t &matrix_coefficients)
void set_color_primaries(const uint32_t &color_primaries)
virtual void ForceSubsegmentStartswithSAP(uint32_t sap_value)
bool MatchAdaptationSet(const MediaInfo &media_info, bool content_protection_in_adaptation_set)
std::optional< uint32_t > SortIndex() const
virtual void AddTrickPlayReference(const AdaptationSet *adaptation_set)
virtual void AddAdaptationSetSwitching(const AdaptationSet *adaptation_set)
std::optional< xml::XmlNode > GetXml()
const std::string & codec() const
uint32_t color_primaries() const
void set_protected_content(const MediaInfo &media_info)
uint32_t matrix_coefficients() const
void set_transfer_characteristics(const uint32_t &transfer_characteristics)
void set_codec(const std::string &codec)
bool SwitchableAdaptationSet(const AdaptationSet &adaptation_set)
virtual void UpdateContentProtectionPssh(const std::string &drm_uuid, const std::string &pssh)
virtual void AddRole(Role role)
void set_id(uint32_t id)
All the methods that are virtual are virtual for mocking.
Defines Mpd Options.
Definition mpd_options.h:24