Shaka Packager SDK
representation.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_REPRESENTATION_H_
10 #define PACKAGER_MPD_BASE_REPRESENTATION_H_
11 
12 #include "packager/mpd/base/bandwidth_estimator.h"
13 #include "packager/mpd/base/media_info.pb.h"
14 #include "packager/mpd/base/segment_info.h"
15 #include "packager/mpd/base/xml/scoped_xml_ptr.h"
16 
17 #include <stdint.h>
18 
19 #include <list>
20 #include <memory>
21 
22 namespace shaka {
23 
24 struct ContentProtectionElement;
25 struct MpdOptions;
26 
27 namespace xml {
28 class XmlNode;
29 class RepresentationXmlNode;
30 } // namespace xml
31 
33  public:
36 
41  virtual void OnNewSegmentForRepresentation(uint64_t start_time,
42  uint64_t duration) = 0;
43 
48  virtual void OnSetFrameRateForRepresentation(uint32_t frame_duration,
49  uint32_t timescale) = 0;
50 };
51 
55  public:
56  enum SuppressFlag {
57  kSuppressWidth = 1,
58  kSuppressHeight = 2,
59  kSuppressFrameRate = 4,
60  };
61 
62  virtual ~Representation();
63 
67  bool Init();
68 
79  virtual void AddContentProtectionElement(
80  const ContentProtectionElement& element);
81 
93  virtual void UpdateContentProtectionPssh(const std::string& drm_uuid,
94  const std::string& pssh);
95 
104  virtual void AddNewSegment(uint64_t start_time,
105  uint64_t duration,
106  uint64_t size);
107 
113  virtual void SetSampleDuration(uint32_t sample_duration);
114 
116  virtual const MediaInfo& GetMediaInfo() const;
117 
119  xml::scoped_xml_ptr<xmlNode> GetXml();
120 
129  void SuppressOnce(SuppressFlag flag);
130 
133  bool GetEarliestTimestamp(double* timestamp_seconds) const;
134 
136  float GetDurationSeconds() const;
137 
139  uint32_t id() const { return id_; }
140 
141  protected:
151  const MediaInfo& media_info,
152  const MpdOptions& mpd_options,
153  uint32_t representation_id,
154  std::unique_ptr<RepresentationStateChangeListener> state_change_listener);
155 
162  const Representation& representation,
163  uint64_t presentation_time_offset,
164  std::unique_ptr<RepresentationStateChangeListener> state_change_listener);
165 
166  private:
167  Representation(const Representation&) = delete;
168  Representation& operator=(const Representation&) = delete;
169 
170  friend class AdaptationSet;
171  friend class RepresentationTest;
172 
173  // Returns true if |media_info_| has required fields to generate a valid
174  // Representation. Otherwise returns false.
175  bool HasRequiredMediaInfoFields() const;
176 
177  // Return false if the segment should be considered a new segment. True if the
178  // segment is contiguous.
179  bool IsContiguous(uint64_t start_time,
180  uint64_t duration,
181  uint64_t size) const;
182 
183  // Remove elements from |segment_infos_| for dynamic live profile. Increments
184  // |start_number_| by the number of segments removed.
185  void SlideWindow();
186 
187  // Note: Because 'mimeType' is a required field for a valid MPD, these return
188  // strings.
189  std::string GetVideoMimeType() const;
190  std::string GetAudioMimeType() const;
191  std::string GetTextMimeType() const;
192 
193  // Init() checks that only one of VideoInfo, AudioInfo, or TextInfo is set. So
194  // any logic using this can assume only one set.
195  MediaInfo media_info_;
196  std::list<ContentProtectionElement> content_protection_elements_;
197  // TODO(kqyang): Address sliding window issue with multiple periods.
198  std::list<SegmentInfo> segment_infos_;
199 
200  const uint32_t id_;
201  std::string mime_type_;
202  std::string codecs_;
203  BandwidthEstimator bandwidth_estimator_;
204  const MpdOptions& mpd_options_;
205 
206  // startNumber attribute for SegmentTemplate.
207  // Starts from 1.
208  uint32_t start_number_;
209 
210  // If this is not null, then Representation is responsible for calling the
211  // right methods at right timings.
212  std::unique_ptr<RepresentationStateChangeListener> state_change_listener_;
213 
214  // Bit vector for tracking witch attributes should not be output.
215  int output_suppression_flags_;
216 };
217 
218 } // namespace shaka
219 
220 #endif // PACKAGER_MPD_BASE_REPRESENTATION_H_
uint32_t id() const
All the methods that are virtual are virtual for mocking.
Defines Mpd Options.
Definition: mpd_options.h:25