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