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/optional.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  // TODO(kqyang): Move |content_protection_in_adaptation_set| to Period
45  // constructor.
46  virtual AdaptationSet* GetOrCreateAdaptationSet(
47  const MediaInfo& media_info,
48  bool content_protection_in_adaptation_set);
49 
53  xml::scoped_xml_ptr<xmlNode> GetXml(bool output_period_duration);
54 
56  const std::list<AdaptationSet*> GetAdaptationSets() const;
57 
59  double start_time_in_seconds() const { return start_time_in_seconds_; }
60 
62  double duration_seconds() const { return duration_seconds_; }
63 
65  void set_duration_seconds(double duration_seconds) {
66  duration_seconds_ = duration_seconds;
67  }
68 
69  protected:
75  Period(uint32_t period_id,
76  double start_time_in_seconds,
77  const MpdOptions& mpd_options,
78  uint32_t* representation_counter);
79 
80  private:
81  Period(const Period&) = delete;
82  Period& operator=(const Period&) = delete;
83 
84  friend class MpdBuilder;
85  friend class PeriodTest;
86 
87  // Calls AdaptationSet constructor. For mock injection.
88  virtual std::unique_ptr<AdaptationSet> NewAdaptationSet(
89  const std::string& lang,
90  const MpdOptions& options,
91  uint32_t* representation_counter);
92 
93  // Helper function to set new AdaptationSet attributes.
94  bool SetNewAdaptationSetAttributes(
95  const std::string& language,
96  const MediaInfo& media_info,
97  const std::list<AdaptationSet*>& adaptation_sets,
98  AdaptationSet* new_adaptation_set);
99 
100  // Gets the original AdaptationSet which the trick play video belongs to.
101  // It is assumed that the corresponding AdaptationSet has been created before
102  // the trick play AdaptationSet.
103  // Returns the original AdaptationSet if found, otherwise returns nullptr;
104  const AdaptationSet* FindOriginalAdaptationSetForTrickPlay(
105  const MediaInfo& media_info);
106 
107  const uint32_t id_;
108  const double start_time_in_seconds_;
109  double duration_seconds_ = 0;
110  const MpdOptions& mpd_options_;
111  uint32_t* const representation_counter_;
112  std::list<std::unique_ptr<AdaptationSet>> adaptation_sets_;
113  // AdaptationSets grouped by a specific adaptation set grouping key.
114  // AdaptationSets with the same key contain identical parameters except
115  // ContentProtection parameters. A single AdaptationSet would be created
116  // if they contain identical ContentProtection elements. This map is only
117  // useful when ContentProtection element is placed in AdaptationSet.
118  std::map<std::string, std::list<AdaptationSet*>> adaptation_set_list_map_;
119 
120  // Tracks ProtectedContent in AdaptationSet.
121  class ProtectedAdaptationSetMap {
122  public:
123  ProtectedAdaptationSetMap() = default;
124  // Register the |adaptation_set| with associated |media_info| in the map.
125  void Register(const AdaptationSet& adaptation_set,
126  const MediaInfo& media_info);
127  // Check if the protected content associated with |adaptation_set| matches
128  // with the one in |media_info|.
129  bool Match(const AdaptationSet& adaptation_set,
130  const MediaInfo& media_info);
131  // Check if the two adaptation sets are switchable.
132  bool Switchable(const AdaptationSet& adaptation_set_a,
133  const AdaptationSet& adaptation_set_b);
134 
135  private:
136  ProtectedAdaptationSetMap(const ProtectedAdaptationSetMap&) = delete;
137  ProtectedAdaptationSetMap& operator=(const ProtectedAdaptationSetMap&) =
138  delete;
139 
140  // AdaptationSet => ProtectedContent map.
141  std::map<const AdaptationSet*, MediaInfo::ProtectedContent>
142  protected_content_map_;
143  };
144  ProtectedAdaptationSetMap protected_adaptation_set_map_;
145 };
146 
147 } // namespace shaka
148 
149 #endif // PACKAGER_MPD_BASE_PERIOD_H_
This class generates DASH MPDs (Media Presentation Descriptions).
Definition: mpd_builder.h:37
All the methods that are virtual are virtual for mocking.
double duration_seconds() const
Definition: period.h:62
void set_duration_seconds(double duration_seconds)
Set period duration.
Definition: period.h:65
double start_time_in_seconds() const
Definition: period.h:59
Defines Mpd Options.
Definition: mpd_options.h:25