Shaka Packager SDK
Loading...
Searching...
No Matches
representation.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_REPRESENTATION_H_
10#define PACKAGER_MPD_BASE_REPRESENTATION_H_
11
12#include <cstdint>
13#include <list>
14#include <memory>
15#include <optional>
16
17#include <packager/mpd/base/bandwidth_estimator.h>
18#include <packager/mpd/base/media_info.pb.h>
19#include <packager/mpd/base/segment_info.h>
20#include <packager/mpd/base/xml/xml_node.h>
21
22namespace shaka {
23
24struct ContentProtectionElement;
25struct MpdOptions;
26
28 public:
31
36 virtual void OnNewSegmentForRepresentation(int64_t start_time,
37 int64_t duration) = 0;
38
43 virtual void OnSetFrameRateForRepresentation(int32_t frame_duration,
44 int32_t timescale) = 0;
45};
46
50 public:
51 enum SuppressFlag {
52 kSuppressWidth = 1,
53 kSuppressHeight = 2,
54 kSuppressFrameRate = 4,
55 };
56
57 virtual ~Representation();
58
62 bool Init();
63
74 virtual void AddContentProtectionElement(
75 const ContentProtectionElement& element);
76
88 virtual void UpdateContentProtectionPssh(const std::string& drm_uuid,
89 const std::string& pssh);
90
103 virtual void AddNewSegment(int64_t start_time,
104 int64_t duration,
105 uint64_t size,
106 int64_t segment_number);
107
116 virtual void UpdateCompletedSegment(int64_t duration, uint64_t size);
117
123 virtual void SetSampleDuration(int32_t sample_duration);
124
126 virtual const MediaInfo& GetMediaInfo() const;
127
129 std::optional<xml::XmlNode> GetXml();
130
139 void SuppressOnce(SuppressFlag flag);
140
142 void SetPresentationTimeOffset(double presentation_time_offset);
143
147
150 void SetSegmentDuration();
151
160 bool GetStartAndEndTimestamps(double* start_timestamp_seconds,
161 double* end_timestamp_seconds) const;
162
164 uint32_t id() const { return id_; }
165
166 void set_media_info(const MediaInfo& media_info) { media_info_ = media_info; }
167
168 protected:
177 Representation(
178 const MediaInfo& media_info,
179 const MpdOptions& mpd_options,
180 uint32_t representation_id,
181 std::unique_ptr<RepresentationStateChangeListener> state_change_listener);
182
186 Representation(
187 const Representation& representation,
188 std::unique_ptr<RepresentationStateChangeListener> state_change_listener);
189
190 private:
191 Representation(const Representation&) = delete;
192 Representation& operator=(const Representation&) = delete;
193
194 friend class AdaptationSet;
195 friend class RepresentationTest;
196
197 // Returns true if |media_info_| has required fields to generate a valid
198 // Representation. Otherwise returns false.
199 bool HasRequiredMediaInfoFields() const;
200
201 // Add a SegmentInfo. This function may insert an adjusted SegmentInfo if
202 // |allow_approximate_segment_timeline_| is set.
203 void AddSegmentInfo(int64_t start_time,
204 int64_t duration,
205 int64_t segment_number);
206
207 // Update the current SegmentInfo. This method is used to update the duration
208 // value after a low latency segment is complete, and the full segment
209 // duration is known.
210 void UpdateSegmentInfo(int64_t duration);
211
212 // Check if two timestamps are approximately equal if
213 // |allow_approximate_segment_timeline_| is set; Otherwise check whether the
214 // two times match.
215 bool ApproximiatelyEqual(int64_t time1, int64_t time2) const;
216
217 // Return adjusted duration if |allow_aproximate_segment_timeline_or_duration|
218 // is set; otherwise duration is returned without adjustment.
219 int64_t AdjustDuration(int64_t duration) const;
220
221 // Remove elements from |segment_infos_| for dynamic live profile. Increments
222 // |start_number_| by the number of segments removed.
223 void SlideWindow();
224
225 // Remove the first segment in |segment_info|.
226 void RemoveOldSegment(SegmentInfo* segment_info);
227
228 // Note: Because 'mimeType' is a required field for a valid MPD, these return
229 // strings.
230 std::string GetVideoMimeType() const;
231 std::string GetAudioMimeType() const;
232 std::string GetTextMimeType() const;
233
234 // Get Representation as string. For debugging.
235 std::string RepresentationAsString() const;
236
237 // Init() checks that only one of VideoInfo, AudioInfo, or TextInfo is set. So
238 // any logic using this can assume only one set.
239 MediaInfo media_info_;
240 std::list<ContentProtectionElement> content_protection_elements_;
241
242 int64_t current_buffer_depth_ = 0;
243 // TODO(kqyang): Address sliding window issue with multiple periods.
244 std::list<SegmentInfo> segment_infos_;
245 // A list to hold the file names of the segments to be removed temporarily.
246 // Once a file is actually removed, it is removed from the list.
247 std::list<std::string> segments_to_be_removed_;
248
249 const uint32_t id_;
250 std::string mime_type_;
251 std::string codecs_;
252 std::string supplemental_codecs_;
253 std::string supplemental_profiles_;
254 BandwidthEstimator bandwidth_estimator_;
255 const MpdOptions& mpd_options_;
256
257 // If this is not null, then Representation is responsible for calling the
258 // right methods at right timings.
259 std::unique_ptr<RepresentationStateChangeListener> state_change_listener_;
260
261 // Bit vector for tracking witch attributes should not be output.
262 int output_suppression_flags_ = 0;
263
264 // When set to true, allows segments to have slightly different durations (up
265 // to one sample).
266 const bool allow_approximate_segment_timeline_ = false;
267 // Segments with duration difference less than one frame duration are
268 // considered to have the same duration.
269 int32_t frame_duration_ = 0;
270};
271
272} // namespace shaka
273
274#endif // PACKAGER_MPD_BASE_REPRESENTATION_H_
virtual void OnSetFrameRateForRepresentation(int32_t frame_duration, int32_t timescale)=0
virtual void OnNewSegmentForRepresentation(int64_t start_time, int64_t duration)=0
virtual void AddContentProtectionElement(const ContentProtectionElement &element)
virtual void AddNewSegment(int64_t start_time, int64_t duration, uint64_t size, int64_t segment_number)
virtual void UpdateContentProtectionPssh(const std::string &drm_uuid, const std::string &pssh)
virtual void UpdateCompletedSegment(int64_t duration, uint64_t size)
void SuppressOnce(SuppressFlag flag)
virtual const MediaInfo & GetMediaInfo() const
virtual void SetSampleDuration(int32_t sample_duration)
bool GetStartAndEndTimestamps(double *start_timestamp_seconds, double *end_timestamp_seconds) const
uint32_t id() const
std::optional< xml::XmlNode > GetXml()
void SetPresentationTimeOffset(double presentation_time_offset)
Set @presentationTimeOffset in SegmentBase / SegmentTemplate.
All the methods that are virtual are virtual for mocking.