Shaka Packager SDK
Loading...
Searching...
No Matches
period.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_PERIOD_H_
10#define PACKAGER_MPD_BASE_PERIOD_H_
11
12#include <cstdint>
13#include <list>
14#include <map>
15#include <memory>
16#include <optional>
17#include <string>
18
19#include <packager/mpd/base/adaptation_set.h>
20#include <packager/mpd/base/media_info.pb.h>
21#include <packager/mpd/base/xml/xml_node.h>
22
23namespace shaka {
24
25struct MpdOptions;
26
29class Period {
30 public:
31 virtual ~Period();
32
43 // TODO(kqyang): Move |content_protection_in_adaptation_set| to Period
44 // constructor.
46 const MediaInfo& media_info,
47 bool content_protection_in_adaptation_set);
48
52 std::optional<xml::XmlNode> GetXml(bool output_period_duration);
53
55 const std::list<AdaptationSet*> GetAdaptationSets() const;
56
58 double start_time_in_seconds() const { return start_time_in_seconds_; }
59
61 double duration_seconds() const { return duration_seconds_; }
62
65 duration_seconds_ = duration_seconds;
66 }
67
69 const std::map<std::string, std::list<AdaptationSet*>>& trickplay_cache()
70 const {
71 return trickplay_cache_;
72 }
73
74 protected:
80 Period(uint32_t period_id,
82 const MpdOptions& mpd_options,
83 uint32_t* representation_counter);
84
85 private:
86 Period(const Period&) = delete;
87 Period& operator=(const Period&) = delete;
88
89 friend class MpdBuilder;
90 friend class PeriodTest;
91
92 // Calls AdaptationSet constructor. For mock injection.
93 virtual std::unique_ptr<AdaptationSet> NewAdaptationSet(
94 const std::string& lang,
95 const MpdOptions& options,
96 uint32_t* representation_counter);
97
98 // Helper function to set new AdaptationSet attributes.
99 bool SetNewAdaptationSetAttributes(
100 const std::string& language,
101 const MediaInfo& media_info,
102 const std::list<AdaptationSet*>& adaptation_sets,
103 bool content_protection_in_adaptation_set,
104 AdaptationSet* new_adaptation_set);
105
106 // If processing a trick play AdaptationSet, gets the original AdaptationSet
107 // which the trick play video belongs to.It is assumed that the corresponding
108 // AdaptationSet has been created before the trick play AdaptationSet.
109 // Returns the matching AdaptationSet if found, otherwise returns nullptr;
110 // If processing non-trick play AdaptationSet, gets the trick play
111 // AdaptationSet that belongs to current AdaptationSet from trick play cache.
112 // Returns nullptr if matching trick play AdaptationSet is not found.
113 AdaptationSet* FindMatchingAdaptationSetForTrickPlay(
114 const MediaInfo& media_info,
115 bool content_protection_in_adaptation_set,
116 std::string* adaptation_set_key);
117
118 // Returns AdaptationSet key without ':trickplay' in it for trickplay
119 // AdaptationSet.
120 std::string GetAdaptationSetKeyForTrickPlay(const MediaInfo& media_info);
121
122 // FindMatchingAdaptationSetForTrickPlay
123 const uint32_t id_;
124 const double start_time_in_seconds_;
125 double duration_seconds_ = 0;
126 const MpdOptions& mpd_options_;
127 uint32_t* const representation_counter_;
128 std::list<std::unique_ptr<AdaptationSet>> adaptation_sets_;
129 // AdaptationSets grouped by a specific adaptation set grouping key.
130 // AdaptationSets with the same key contain identical parameters except
131 // ContentProtection parameters. A single AdaptationSet would be created
132 // if they contain identical ContentProtection elements. This map is only
133 // useful when ContentProtection element is placed in AdaptationSet.
134 std::map<std::string, std::list<AdaptationSet*>> adaptation_set_list_map_;
135 // Contains Trickplay AdaptationSets grouped by specific adaptation set
136 // grouping key. These AdaptationSets still have not found reference
137 // AdaptationSet.
138 std::map<std::string, std::list<AdaptationSet*>> trickplay_cache_;
139};
140
141} // namespace shaka
142
143#endif // PACKAGER_MPD_BASE_PERIOD_H_
This class generates DASH MPDs (Media Presentation Descriptions).
Definition mpd_builder.h:37
double duration_seconds() const
Definition period.h:61
void set_duration_seconds(double duration_seconds)
Set period duration.
Definition period.h:64
virtual AdaptationSet * GetOrCreateAdaptationSet(const MediaInfo &media_info, bool content_protection_in_adaptation_set)
Definition period.cc:84
std::optional< xml::XmlNode > GetXml(bool output_period_duration)
Definition period.cc:127
double start_time_in_seconds() const
Definition period.h:58
const std::map< std::string, std::list< AdaptationSet * > > & trickplay_cache() const
Definition period.h:69
const std::list< AdaptationSet * > GetAdaptationSets() const
Definition period.cc:199
All the methods that are virtual are virtual for mocking.
Defines Mpd Options.
Definition mpd_options.h:24