Shaka Packager SDK
period.h
1 // Copyright 2017 Google Inc. 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_PERIOD_H_
10 #define PACKAGER_MPD_BASE_PERIOD_H_
11 
12 #include <list>
13 #include <map>
14 
15 #include "packager/base/atomic_sequence_num.h"
16 #include "packager/mpd/base/adaptation_set.h"
17 #include "packager/mpd/base/media_info.pb.h"
18 #include "packager/mpd/base/xml/scoped_xml_ptr.h"
19 
20 namespace shaka {
21 
22 struct MpdOptions;
23 
24 namespace xml {
25 class XmlNode;
26 } // namespace xml
27 
30 class Period {
31  public:
32  virtual ~Period() = default;
33 
44  virtual AdaptationSet* GetOrCreateAdaptationSet(
45  const MediaInfo& media_info,
46  bool content_protection_in_adaptation_set);
47 
51  xml::scoped_xml_ptr<xmlNode> GetXml() const;
52 
54  const std::list<AdaptationSet*> GetAdaptationSets() const;
55 
57  double start_time_in_seconds() const { return start_time_in_seconds_; }
58 
60  void set_duration_seconds(double duration_seconds) {
61  duration_seconds_ = duration_seconds;
62  }
63 
64  protected:
72  Period(uint32_t period_id,
73  double start_time_in_seconds,
74  const MpdOptions& mpd_options,
75  base::AtomicSequenceNumber* adaptation_set_counter,
76  base::AtomicSequenceNumber* representation_counter);
77 
78  private:
79  Period(const Period&) = delete;
80  Period& operator=(const Period&) = delete;
81 
82  friend class MpdBuilder;
83  friend class PeriodTest;
84 
85  // Calls AdaptationSet constructor. For mock injection.
86  virtual std::unique_ptr<AdaptationSet> NewAdaptationSet(
87  uint32_t adaptation_set_id,
88  const std::string& lang,
89  const MpdOptions& options,
90  base::AtomicSequenceNumber* representation_counter);
91 
92  // Helper function to set new AdaptationSet attributes.
93  bool SetNewAdaptationSetAttributes(
94  const std::string& language,
95  const MediaInfo& media_info,
96  const std::list<AdaptationSet*>& adaptation_sets,
97  AdaptationSet* new_adaptation_set);
98 
99  // Gets the original AdaptationSet which the trick play video belongs
100  // to and returns the id of the original adapatation set.
101  // It is assumed that the corresponding AdaptationSet has been created before
102  // the trick play AdaptationSet.
103  // Returns true if main_adaptation_id is found, otherwise false;
104  bool FindOriginalAdaptationSetForTrickPlay(
105  const MediaInfo& media_info,
106  uint32_t* original_adaptation_set_id);
107 
108  const uint32_t id_;
109  const double start_time_in_seconds_;
110  double duration_seconds_ = 0;
111  const MpdOptions& mpd_options_;
112  base::AtomicSequenceNumber* const adaptation_set_counter_;
113  base::AtomicSequenceNumber* const representation_counter_;
114  // adaptation_id => Adaptation map. It also keeps the adaptation_sets_ sorted
115  // by default.
116  std::map<uint32_t, std::unique_ptr<AdaptationSet>> adaptation_set_map_;
117  // AdaptationSets grouped by a specific adaptation set grouping key.
118  // AdaptationSets with the same key contain identical parameters except
119  // ContentProtection parameters. A single AdaptationSet would be created
120  // if they contain identical ContentProtection elements. This map is only
121  // useful when ContentProtection element is placed in AdaptationSet.
122  std::map<std::string, std::list<AdaptationSet*>> adaptation_set_list_map_;
123 
124  // Tracks ProtectedContent in AdaptationSet.
125  class ProtectedAdaptationSetMap {
126  public:
127  ProtectedAdaptationSetMap() = default;
128  // Register the |adaptation_set| with associated |media_info| in the map.
129  void Register(const AdaptationSet& adaptation_set,
130  const MediaInfo& media_info);
131  // Check if the protected content associated with |adaptation_set| matches
132  // with the one in |media_info|.
133  bool Match(const AdaptationSet& adaptation_set,
134  const MediaInfo& media_info);
135  // Check if the two adaptation sets are switchable.
136  bool Switchable(const AdaptationSet& adaptation_set_a,
137  const AdaptationSet& adaptation_set_b);
138 
139  private:
140  ProtectedAdaptationSetMap(const ProtectedAdaptationSetMap&) = delete;
141  ProtectedAdaptationSetMap& operator=(const ProtectedAdaptationSetMap&) =
142  delete;
143 
144  // AdaptationSet id => ProtectedContent map.
145  std::map<uint32_t, MediaInfo::ProtectedContent> protected_content_map_;
146  };
147  ProtectedAdaptationSetMap protected_adaptation_set_map_;
148 };
149 
150 } // namespace shaka
151 
152 #endif // PACKAGER_MPD_BASE_PERIOD_H_
This class generates DASH MPDs (Media Presentation Descriptions).
Definition: mpd_builder.h:38
All the methods that are virtual are virtual for mocking.
void set_duration_seconds(double duration_seconds)
Set period duration.
Definition: period.h:60
double start_time_in_seconds() const
Definition: period.h:57
Defines Mpd Options.
Definition: mpd_options.h:25