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/xml_node.h"
19 
20 namespace shaka {
21 
22 struct MpdOptions;
23 
26 class Period {
27  public:
28  virtual ~Period();
29 
40  // TODO(kqyang): Move |content_protection_in_adaptation_set| to Period
41  // constructor.
43  const MediaInfo& media_info,
44  bool content_protection_in_adaptation_set);
45 
49  base::Optional<xml::XmlNode> GetXml(bool output_period_duration);
50 
52  const std::list<AdaptationSet*> GetAdaptationSets() const;
53 
55  double start_time_in_seconds() const { return start_time_in_seconds_; }
56 
58  double duration_seconds() const { return duration_seconds_; }
59 
62  duration_seconds_ = duration_seconds;
63  }
64 
66  const std::map<std::string, std::list<AdaptationSet*>>& trickplay_cache()
67  const {
68  return trickplay_cache_;
69  }
70 
71  protected:
77  Period(uint32_t period_id,
78  double start_time_in_seconds,
79  const MpdOptions& mpd_options,
80  uint32_t* representation_counter);
81 
82  private:
83  Period(const Period&) = delete;
84  Period& operator=(const Period&) = delete;
85 
86  friend class MpdBuilder;
87  friend class PeriodTest;
88 
89  // Calls AdaptationSet constructor. For mock injection.
90  virtual std::unique_ptr<AdaptationSet> NewAdaptationSet(
91  const std::string& lang,
92  const MpdOptions& options,
93  uint32_t* representation_counter);
94 
95  // Helper function to set new AdaptationSet attributes.
96  bool SetNewAdaptationSetAttributes(
97  const std::string& language,
98  const MediaInfo& media_info,
99  const std::list<AdaptationSet*>& adaptation_sets,
100  bool content_protection_in_adaptation_set,
101  AdaptationSet* new_adaptation_set);
102 
103  // If processing a trick play AdaptationSet, gets the original AdaptationSet
104  // which the trick play video belongs to.It is assumed that the corresponding
105  // AdaptationSet has been created before the trick play AdaptationSet.
106  // Returns the matching AdaptationSet if found, otherwise returns nullptr;
107  // If processing non-trick play AdaptationSet, gets the trick play
108  // AdaptationSet that belongs to current AdaptationSet from trick play cache.
109  // Returns nullptr if matching trick play AdaptationSet is not found.
110  AdaptationSet* FindMatchingAdaptationSetForTrickPlay(
111  const MediaInfo& media_info,
112  bool content_protection_in_adaptation_set,
113  std::string* adaptation_set_key);
114 
115  // Returns AdaptationSet key without ':trickplay' in it for trickplay
116  // AdaptationSet.
117  std::string GetAdaptationSetKeyForTrickPlay(const MediaInfo& media_info);
118 
119  // FindMatchingAdaptationSetForTrickPlay
120  const uint32_t id_;
121  const double start_time_in_seconds_;
122  double duration_seconds_ = 0;
123  const MpdOptions& mpd_options_;
124  uint32_t* const representation_counter_;
125  std::list<std::unique_ptr<AdaptationSet>> adaptation_sets_;
126  // AdaptationSets grouped by a specific adaptation set grouping key.
127  // AdaptationSets with the same key contain identical parameters except
128  // ContentProtection parameters. A single AdaptationSet would be created
129  // if they contain identical ContentProtection elements. This map is only
130  // useful when ContentProtection element is placed in AdaptationSet.
131  std::map<std::string, std::list<AdaptationSet*>> adaptation_set_list_map_;
132  // Contains Trickplay AdaptationSets grouped by specific adaptation set
133  // grouping key. These AdaptationSets still have not found reference
134  // AdaptationSet.
135  std::map<std::string, std::list<AdaptationSet*>> trickplay_cache_;
136 
137  // Tracks ProtectedContent in AdaptationSet.
138  class ProtectedAdaptationSetMap {
139  public:
140  ProtectedAdaptationSetMap() = default;
141  // Register the |adaptation_set| with associated |media_info| in the map.
142  void Register(const AdaptationSet& adaptation_set,
143  const MediaInfo& media_info);
144  // Check if the protected content associated with |adaptation_set| matches
145  // with the one in |media_info|.
146  bool Match(const AdaptationSet& adaptation_set,
147  const MediaInfo& media_info,
148  bool content_protection_in_adaptation_set);
149  // Check if the two adaptation sets are switchable.
150  bool Switchable(const AdaptationSet& adaptation_set_a,
151  const AdaptationSet& adaptation_set_b);
152 
153  private:
154  ProtectedAdaptationSetMap(const ProtectedAdaptationSetMap&) = delete;
155  ProtectedAdaptationSetMap& operator=(const ProtectedAdaptationSetMap&) =
156  delete;
157 
158  // AdaptationSet => ProtectedContent map.
159  std::map<const AdaptationSet*, MediaInfo::ProtectedContent>
160  protected_content_map_;
161  };
162  ProtectedAdaptationSetMap protected_adaptation_set_map_;
163 };
164 
165 } // namespace shaka
166 
167 #endif // PACKAGER_MPD_BASE_PERIOD_H_
shaka::MpdOptions
Defines Mpd Options.
Definition: mpd_options.h:25
shaka::Period
Definition: period.h:26
shaka::Period::duration_seconds
double duration_seconds() const
Definition: period.h:58
shaka::AdaptationSet
Definition: adaptation_set.h:33
shaka
All the methods that are virtual are virtual for mocking.
Definition: gflags_hex_bytes.cc:11
shaka::Period::set_duration_seconds
void set_duration_seconds(double duration_seconds)
Set period duration.
Definition: period.h:61
shaka::Period::GetAdaptationSets
const std::list< AdaptationSet * > GetAdaptationSets() const
Definition: period.cc:160
shaka::Period::GetXml
base::Optional< xml::XmlNode > GetXml(bool output_period_duration)
Definition: period.cc:123
shaka::Period::Period
Period(uint32_t period_id, double start_time_in_seconds, const MpdOptions &mpd_options, uint32_t *representation_counter)
Definition: period.cc:65
shaka::Period::start_time_in_seconds
double start_time_in_seconds() const
Definition: period.h:55
shaka::MpdBuilder
This class generates DASH MPDs (Media Presentation Descriptions).
Definition: mpd_builder.h:36
shaka::Period::GetOrCreateAdaptationSet
virtual AdaptationSet * GetOrCreateAdaptationSet(const MediaInfo &media_info, bool content_protection_in_adaptation_set)
Definition: period.cc:74
shaka::Period::trickplay_cache
const std::map< std::string, std::list< AdaptationSet * > > & trickplay_cache() const
Definition: period.h:66