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