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