2014-02-14 23:21:05 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
//
|
2013-11-18 23:48:14 +00:00
|
|
|
// This file contains the MpdBuilder, AdaptationSet, and Representation class
|
|
|
|
// declarations.
|
|
|
|
// http://goo.gl/UrsSlF
|
2015-03-23 19:55:58 +00:00
|
|
|
//
|
2015-07-16 06:51:24 +00:00
|
|
|
/// All the methods that are virtual are virtual for mocking.
|
2015-03-23 19:55:58 +00:00
|
|
|
/// NOTE: Inclusion of this module will cause xmlInitParser and xmlCleanupParser
|
|
|
|
/// to be called at static initialization / deinitialization time.
|
|
|
|
|
2013-11-18 23:48:14 +00:00
|
|
|
#ifndef MPD_BASE_MPD_BUILDER_H_
|
|
|
|
#define MPD_BASE_MPD_BUILDER_H_
|
|
|
|
|
2014-09-30 23:52:58 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2013-11-18 23:48:14 +00:00
|
|
|
#include <list>
|
2015-06-17 01:37:23 +00:00
|
|
|
#include <map>
|
|
|
|
#include <set>
|
2013-11-18 23:48:14 +00:00
|
|
|
#include <string>
|
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/base/atomic_sequence_num.h"
|
|
|
|
#include "packager/base/gtest_prod_util.h"
|
|
|
|
#include "packager/base/stl_util.h"
|
|
|
|
#include "packager/mpd/base/bandwidth_estimator.h"
|
|
|
|
#include "packager/mpd/base/content_protection_element.h"
|
|
|
|
#include "packager/mpd/base/media_info.pb.h"
|
2014-12-13 00:13:48 +00:00
|
|
|
#include "packager/mpd/base/mpd_options.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/mpd/base/segment_info.h"
|
|
|
|
#include "packager/mpd/base/xml/scoped_xml_ptr.h"
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2014-01-31 19:02:30 +00:00
|
|
|
// TODO(rkuroiwa): For classes with |id_|, consider removing the field and let
|
|
|
|
// the MPD (XML) generation functions take care of assigning an ID to each
|
|
|
|
// element.
|
2014-09-19 20:41:13 +00:00
|
|
|
namespace edash_packager {
|
|
|
|
|
|
|
|
namespace media {
|
|
|
|
class File;
|
|
|
|
} // namespace media
|
2013-11-18 23:48:14 +00:00
|
|
|
|
|
|
|
class AdaptationSet;
|
|
|
|
class Representation;
|
|
|
|
|
|
|
|
namespace xml {
|
|
|
|
|
|
|
|
class XmlNode;
|
2014-05-22 02:16:17 +00:00
|
|
|
class RepresentationXmlNode;
|
2013-11-18 23:48:14 +00:00
|
|
|
|
|
|
|
} // namespace xml
|
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// This class generates DASH MPDs (Media Presentation Descriptions).
|
2013-11-18 23:48:14 +00:00
|
|
|
class MpdBuilder {
|
|
|
|
public:
|
|
|
|
enum MpdType {
|
|
|
|
kStatic = 0,
|
|
|
|
kDynamic
|
|
|
|
};
|
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Constructs MpdBuilder.
|
|
|
|
/// @param type indicates whether the MPD should be for VOD or live content
|
|
|
|
/// (kStatic for VOD profile, or kDynamic for live profile).
|
2014-05-22 02:16:17 +00:00
|
|
|
MpdBuilder(MpdType type, const MpdOptions& mpd_options);
|
2015-07-16 06:51:24 +00:00
|
|
|
virtual ~MpdBuilder();
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Add <BaseURL> entry to the MPD.
|
|
|
|
/// @param base_url URL for <BaseURL> entry.
|
2013-11-18 23:48:14 +00:00
|
|
|
void AddBaseUrl(const std::string& base_url);
|
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Adds <AdaptationSet> to the MPD.
|
2015-06-26 23:00:41 +00:00
|
|
|
/// @param lang is the language of the AdaptationSet. This can be empty for
|
|
|
|
/// videos, for example.
|
2014-02-06 21:20:36 +00:00
|
|
|
/// @return The new adaptation set, which is owned by this instance.
|
2015-07-16 06:51:24 +00:00
|
|
|
virtual AdaptationSet* AddAdaptationSet(const std::string& lang);
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2014-01-31 19:02:30 +00:00
|
|
|
/// Write the MPD to specified file.
|
|
|
|
/// @param[out] output_file is MPD destination. output_file will be
|
|
|
|
/// flushed but not closed.
|
|
|
|
/// @return true on success, false otherwise.
|
|
|
|
bool WriteMpdToFile(media::File* output_file);
|
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Writes the MPD to the given string.
|
|
|
|
/// @param[out] output is an output string where the MPD gets written.
|
|
|
|
/// @return true on success, false otherwise.
|
2015-07-16 06:51:24 +00:00
|
|
|
virtual bool ToString(std::string* output);
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2014-05-19 21:30:58 +00:00
|
|
|
/// @return The mpd type.
|
2015-07-16 06:51:24 +00:00
|
|
|
MpdType type() const { return type_; }
|
2014-05-19 21:30:58 +00:00
|
|
|
|
2014-12-16 01:32:19 +00:00
|
|
|
/// Adjusts the fields of MediaInfo so that paths are relative to the
|
|
|
|
/// specified MPD path.
|
|
|
|
/// @param mpd_path is the file path of the MPD file.
|
|
|
|
/// @param media_info is the MediaInfo object to be updated with relative
|
|
|
|
/// paths.
|
|
|
|
static void MakePathsRelativeToMpd(const std::string& mpd_path,
|
|
|
|
MediaInfo* media_info);
|
|
|
|
|
2013-11-18 23:48:14 +00:00
|
|
|
private:
|
2014-06-26 01:33:09 +00:00
|
|
|
// DynamicMpdBuilderTest needs to set availabilityStartTime so that the test
|
|
|
|
// doesn't need to depend on current time.
|
2014-05-22 02:16:17 +00:00
|
|
|
friend class DynamicMpdBuilderTest;
|
|
|
|
|
2013-11-18 23:48:14 +00:00
|
|
|
bool ToStringImpl(std::string* output);
|
|
|
|
|
2014-01-31 19:02:30 +00:00
|
|
|
// This is a helper method for writing out MPDs, called from WriteMpdToFile()
|
|
|
|
// and ToString().
|
|
|
|
template <typename OutputType>
|
|
|
|
bool WriteMpdToOutput(OutputType* output);
|
|
|
|
|
2013-11-18 23:48:14 +00:00
|
|
|
// Returns the document pointer to the MPD. This must be freed by the caller
|
|
|
|
// using appropriate xmlDocPtr freeing function.
|
|
|
|
// On failure, this returns NULL.
|
|
|
|
xmlDocPtr GenerateMpd();
|
|
|
|
|
2014-06-26 01:33:09 +00:00
|
|
|
// Set MPD attributes common to all profiles. Uses non-zero |mpd_options_| to
|
|
|
|
// set attributes for the MPD.
|
|
|
|
void AddCommonMpdInfo(xml::XmlNode* mpd_node);
|
|
|
|
|
2013-11-18 23:48:14 +00:00
|
|
|
// Adds 'static' MPD attributes and elements to |mpd_node|. This assumes that
|
|
|
|
// the first child element is a Period element.
|
|
|
|
void AddStaticMpdInfo(xml::XmlNode* mpd_node);
|
2014-05-22 02:16:17 +00:00
|
|
|
|
|
|
|
// Same as AddStaticMpdInfo() but for 'dynamic' MPDs.
|
|
|
|
void AddDynamicMpdInfo(xml::XmlNode* mpd_node);
|
|
|
|
|
2014-01-03 00:59:16 +00:00
|
|
|
float GetStaticMpdDuration(xml::XmlNode* mpd_node);
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2014-06-26 01:33:09 +00:00
|
|
|
// Set MPD attributes for dynamic profile MPD. Uses non-zero |mpd_options_| as
|
|
|
|
// well as various calculations to set attributes for the MPD.
|
|
|
|
void SetDynamicMpdAttributes(xml::XmlNode* mpd_node);
|
|
|
|
|
|
|
|
// Gets the earliest, normalized segment timestamp. Returns true if
|
|
|
|
// successful, false otherwise.
|
|
|
|
bool GetEarliestTimestamp(double* timestamp_seconds);
|
2014-05-22 02:16:17 +00:00
|
|
|
|
2013-11-18 23:48:14 +00:00
|
|
|
MpdType type_;
|
2014-05-27 22:21:42 +00:00
|
|
|
MpdOptions mpd_options_;
|
2013-11-18 23:48:14 +00:00
|
|
|
std::list<AdaptationSet*> adaptation_sets_;
|
|
|
|
::STLElementDeleter<std::list<AdaptationSet*> > adaptation_sets_deleter_;
|
|
|
|
|
|
|
|
std::list<std::string> base_urls_;
|
2014-06-26 01:33:09 +00:00
|
|
|
std::string availability_start_time_;
|
2013-11-18 23:48:14 +00:00
|
|
|
|
|
|
|
base::AtomicSequenceNumber adaptation_set_counter_;
|
|
|
|
base::AtomicSequenceNumber representation_counter_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(MpdBuilder);
|
|
|
|
};
|
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// AdaptationSet class provides methods to add Representations and
|
|
|
|
/// <ContentProtection> elements to the AdaptationSet element.
|
2013-11-18 23:48:14 +00:00
|
|
|
class AdaptationSet {
|
|
|
|
public:
|
2015-06-26 23:00:41 +00:00
|
|
|
// The role for this AdaptationSet. These values are used to add a Role
|
|
|
|
// element to the AdaptationSet with schemeIdUri=urn:mpeg:dash:role:2011.
|
|
|
|
// See ISO/IEC 23009-1:2012 section 5.8.5.5.
|
|
|
|
enum Role {
|
|
|
|
kRoleCaption,
|
|
|
|
kRoleSubtitle,
|
|
|
|
kRoleMain,
|
|
|
|
kRoleAlternate,
|
|
|
|
kRoleSupplementary,
|
|
|
|
kRoleCommentary,
|
|
|
|
kRoleDub
|
|
|
|
};
|
|
|
|
|
2015-07-16 06:51:24 +00:00
|
|
|
virtual ~AdaptationSet();
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Create a Representation instance using @a media_info.
|
|
|
|
/// @param media_info is a MediaInfo object used to initialize the returned
|
2015-10-29 20:58:36 +00:00
|
|
|
/// Representation instance. It may contain only one of VideoInfo,
|
|
|
|
/// AudioInfo, or TextInfo, i.e. VideoInfo XOR AudioInfo XOR TextInfo.
|
2014-02-06 21:20:36 +00:00
|
|
|
/// @return On success, returns a pointer to Representation. Otherwise returns
|
|
|
|
/// NULL. The returned pointer is owned by the AdaptationSet instance.
|
2015-07-16 06:51:24 +00:00
|
|
|
virtual Representation* AddRepresentation(const MediaInfo& media_info);
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Add a ContenProtection element to the adaptation set.
|
2015-07-15 21:57:47 +00:00
|
|
|
/// AdaptationSet does not add <ContentProtection> elements
|
|
|
|
/// automatically to itself even if @a media_info.protected_content is
|
|
|
|
/// populated. This is because some MPDs should have the elements at
|
|
|
|
/// AdaptationSet level and some at Representation level.
|
2014-02-06 21:20:36 +00:00
|
|
|
/// @param element contains the ContentProtection element contents.
|
|
|
|
/// If @a element has {value, schemeIdUri} set and has
|
|
|
|
/// {“value”, “schemeIdUri”} as key for @a additional_attributes,
|
|
|
|
/// then the former is used.
|
2015-07-22 06:57:21 +00:00
|
|
|
virtual void AddContentProtectionElement(
|
|
|
|
const ContentProtectionElement& element);
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2015-09-24 22:03:52 +00:00
|
|
|
/// Update the 'cenc:pssh' element for @a drm_uuid ContentProtection element.
|
2015-08-26 20:25:29 +00:00
|
|
|
/// If the element does not exist, this will add one.
|
2015-09-24 22:03:52 +00:00
|
|
|
/// @param drm_uuid is the UUID of the DRM for encryption.
|
2015-08-26 20:25:29 +00:00
|
|
|
/// @param pssh is the content of <cenc:pssh> element.
|
|
|
|
/// Note that DASH IF IOP mentions that this should be base64 encoded
|
|
|
|
/// string of the whole pssh box.
|
2015-09-24 22:03:52 +00:00
|
|
|
/// @attention This might get removed once DASH IF IOP specification makes a
|
|
|
|
/// a clear guideline on how to handle key rotation. Also to get
|
|
|
|
/// this working with shaka-player, this method *DOES NOT* update
|
|
|
|
/// the PSSH element. Instead, it removes the element regardless of
|
|
|
|
/// the content of @a pssh.
|
|
|
|
virtual void UpdateContentProtectionPssh(const std::string& drm_uuid,
|
|
|
|
const std::string& pssh);
|
2015-08-26 20:25:29 +00:00
|
|
|
|
2015-06-26 23:00:41 +00:00
|
|
|
/// Set the Role element for this AdaptationSet.
|
|
|
|
/// The Role element's is schemeIdUri='urn:mpeg:dash:role:2011'.
|
|
|
|
/// See ISO/IEC 23009-1:2012 section 5.8.5.5.
|
|
|
|
/// @param role of this AdaptationSet.
|
2015-08-05 23:00:02 +00:00
|
|
|
virtual void AddRole(Role role);
|
2015-06-26 23:00:41 +00:00
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Makes a copy of AdaptationSet xml element with its child Representation
|
|
|
|
/// and ContentProtection elements.
|
2015-11-17 00:06:17 +00:00
|
|
|
/// @return On success returns a non-NULL scoped_xml_ptr. Otherwise returns a
|
|
|
|
/// NULL scoped_xml_ptr.
|
|
|
|
xml::scoped_xml_ptr<xmlNode> GetXml();
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2015-07-13 17:44:52 +00:00
|
|
|
/// Forces the (sub)segmentAlignment field to be set to @a segment_alignment.
|
|
|
|
/// Use this if you are certain that the (sub)segments are alinged/unaligned
|
|
|
|
/// for the AdaptationSet.
|
|
|
|
/// @param segment_alignment is the value used for (sub)segmentAlignment
|
|
|
|
/// attribute.
|
2015-10-29 20:58:36 +00:00
|
|
|
virtual void ForceSetSegmentAlignment(bool segment_alignment);
|
2015-07-13 17:44:52 +00:00
|
|
|
|
2015-07-10 19:45:37 +00:00
|
|
|
/// Sets the AdaptationSet@group attribute.
|
|
|
|
/// Passing a negative value to this method will unset the attribute.
|
|
|
|
/// Note that group=0 is a special group, as mentioned in the DASH MPD
|
|
|
|
/// specification.
|
|
|
|
/// @param group_number is the value of AdaptatoinSet@group.
|
2015-07-22 06:57:21 +00:00
|
|
|
virtual void SetGroup(int group_number);
|
|
|
|
|
|
|
|
/// @return Returns the value for group. If not set, returns a negative value.
|
|
|
|
virtual int Group() const;
|
2015-07-10 19:45:37 +00:00
|
|
|
|
2013-11-18 23:48:14 +00:00
|
|
|
// Must be unique in the Period.
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t id() const { return id_; }
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2015-07-13 17:44:52 +00:00
|
|
|
/// Notifies the AdaptationSet instance that a new (sub)segment was added to
|
|
|
|
/// the Representation with @a representation_id.
|
|
|
|
/// This must be called every time a (sub)segment is added to a
|
|
|
|
/// Representation in this AdaptationSet.
|
|
|
|
/// If a Representation is constructed using AddRepresentation() this
|
|
|
|
/// is called automatically whenever Representation::AddNewSegment() is
|
|
|
|
/// is called.
|
|
|
|
/// @param representation_id is the id of the Representation with a new
|
|
|
|
/// segment.
|
|
|
|
/// @param start_time is the start time of the new segment.
|
|
|
|
/// @param duration is the duration of the new segment.
|
|
|
|
void OnNewSegmentForRepresentation(uint32_t representation_id,
|
|
|
|
uint64_t start_time,
|
|
|
|
uint64_t duration);
|
|
|
|
|
2015-07-31 19:38:50 +00:00
|
|
|
/// Notifies the AdaptationSet instance that the sample duration for the
|
|
|
|
/// Representation was set.
|
|
|
|
/// The frame duration for a video Representation might not be specified when
|
|
|
|
/// a Representation is created (by calling AddRepresentation()).
|
|
|
|
/// This should be used to notify this instance that the frame rate for a
|
|
|
|
/// Represenatation has been set.
|
|
|
|
/// This method is called automatically when
|
|
|
|
/// Represenatation::SetSampleDuration() is called if the Represenatation
|
|
|
|
/// instance was created using AddRepresentation().
|
|
|
|
/// @param representation_id is the id of the Representation.
|
|
|
|
/// @frame_duration is the duration of a frame in the Representation.
|
|
|
|
/// @param timescale is the timescale of the Representation.
|
|
|
|
void OnSetFrameRateForRepresentation(uint32_t representation_id,
|
|
|
|
uint32_t frame_duration,
|
|
|
|
uint32_t timescale);
|
|
|
|
|
2015-07-16 06:51:24 +00:00
|
|
|
protected:
|
|
|
|
/// @param adaptation_set_id is an ID number for this AdaptationSet.
|
|
|
|
/// @param lang is the language of this AdaptationSet. Mainly relevant for
|
|
|
|
/// audio.
|
|
|
|
/// @param mpd_options is the options for this MPD.
|
|
|
|
/// @param mpd_type is the type of this MPD.
|
|
|
|
/// @param representation_counter is a Counter for assigning ID numbers to
|
|
|
|
/// Representation. It can not be NULL.
|
|
|
|
AdaptationSet(uint32_t adaptation_set_id,
|
|
|
|
const std::string& lang,
|
|
|
|
const MpdOptions& mpd_options,
|
|
|
|
MpdBuilder::MpdType mpd_type,
|
|
|
|
base::AtomicSequenceNumber* representation_counter);
|
|
|
|
|
2013-11-18 23:48:14 +00:00
|
|
|
private:
|
2015-10-29 22:48:13 +00:00
|
|
|
friend class MpdBuilder;
|
|
|
|
template <MpdBuilder::MpdType type>
|
|
|
|
friend class MpdBuilderTest;
|
|
|
|
|
2015-07-13 17:44:52 +00:00
|
|
|
// kSegmentAlignmentUnknown means that it is uncertain if the
|
|
|
|
// (sub)segments are aligned or not.
|
|
|
|
// kSegmentAlignmentTrue means that it is certain that the all the (current)
|
|
|
|
// segments added to the adaptation set are aligned.
|
|
|
|
// kSegmentAlignmentFalse means that it is it is certain that some segments
|
|
|
|
// are not aligned. This is useful to disable the computation for
|
|
|
|
// segment alignment, once it is certain that some segments are not aligned.
|
|
|
|
enum SegmentAligmentStatus {
|
|
|
|
kSegmentAlignmentUnknown,
|
|
|
|
kSegmentAlignmentTrue,
|
|
|
|
kSegmentAlignmentFalse
|
|
|
|
};
|
|
|
|
|
|
|
|
// This maps Representations (IDs) to a list of start times of the segments.
|
|
|
|
// e.g.
|
|
|
|
// If Representation 1 has start time 0, 100, 200 and Representation 2 has
|
|
|
|
// start times 0, 200, 400, then the map contains:
|
|
|
|
// 1 -> [0, 100, 200]
|
|
|
|
// 2 -> [0, 200, 400]
|
|
|
|
typedef std::map<uint32_t, std::list<uint64_t> > RepresentationTimeline;
|
|
|
|
|
2014-06-26 01:33:09 +00:00
|
|
|
// Gets the earliest, normalized segment timestamp. Returns true if
|
|
|
|
// successful, false otherwise.
|
|
|
|
bool GetEarliestTimestamp(double* timestamp_seconds);
|
|
|
|
|
2015-07-13 17:44:52 +00:00
|
|
|
/// Called from OnNewSegmentForRepresentation(). Checks whether the segments
|
|
|
|
/// are aligned. Sets segments_aligned_.
|
2015-08-05 21:44:35 +00:00
|
|
|
/// This is only for Live. For VOD, CheckVodSegmentAlignment() should be used.
|
2015-07-13 17:44:52 +00:00
|
|
|
/// @param representation_id is the id of the Representation with a new
|
|
|
|
/// segment.
|
|
|
|
/// @param start_time is the start time of the new segment.
|
|
|
|
/// @param duration is the duration of the new segment.
|
2015-08-05 21:44:35 +00:00
|
|
|
void CheckLiveSegmentAlignment(uint32_t representation_id,
|
|
|
|
uint64_t start_time,
|
|
|
|
uint64_t duration);
|
|
|
|
|
|
|
|
// Checks representation_segment_start_times_ and sets segments_aligned_.
|
|
|
|
// Use this for VOD, do not use for Live.
|
|
|
|
void CheckVodSegmentAlignment();
|
2015-07-13 17:44:52 +00:00
|
|
|
|
2015-07-31 19:38:50 +00:00
|
|
|
// Records the framerate of a Representation.
|
|
|
|
void RecordFrameRate(uint32_t frame_duration, uint32_t timescale);
|
|
|
|
|
2013-11-18 23:48:14 +00:00
|
|
|
std::list<ContentProtectionElement> content_protection_elements_;
|
|
|
|
std::list<Representation*> representations_;
|
|
|
|
::STLElementDeleter<std::list<Representation*> > representations_deleter_;
|
|
|
|
|
|
|
|
base::AtomicSequenceNumber* const representation_counter_;
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
const uint32_t id_;
|
2015-02-02 17:26:09 +00:00
|
|
|
const std::string lang_;
|
2014-05-27 22:21:42 +00:00
|
|
|
const MpdOptions& mpd_options_;
|
2015-07-13 17:44:52 +00:00
|
|
|
const MpdBuilder::MpdType mpd_type_;
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2015-07-10 19:45:37 +00:00
|
|
|
// The group attribute for the AdaptationSet. If the value is negative,
|
|
|
|
// no group number is specified.
|
|
|
|
// Note that group 0 is a special group number.
|
|
|
|
int group_;
|
|
|
|
|
2015-06-17 01:37:23 +00:00
|
|
|
// Video widths and heights of Representations. Note that this is a set; if
|
|
|
|
// there is only 1 resolution, then @width & @height should be set, otherwise
|
|
|
|
// @maxWidth & @maxHeight should be set for DASH IOP.
|
|
|
|
std::set<uint32_t> video_widths_;
|
|
|
|
std::set<uint32_t> video_heights_;
|
|
|
|
|
|
|
|
// Video representations' frame rates.
|
|
|
|
// The frame rate notation for MPD is <integer>/<integer> (where the
|
|
|
|
// denominator is optional). This means the frame rate could be non-whole
|
|
|
|
// rational value, therefore the key is of type double.
|
|
|
|
// Value is <integer>/<integer> in string form.
|
|
|
|
// So, key == CalculatedValue(value)
|
|
|
|
std::map<double, std::string> video_frame_rates_;
|
|
|
|
|
2015-06-23 17:21:44 +00:00
|
|
|
// contentType attribute of AdaptationSet.
|
|
|
|
// Determined by examining the MediaInfo passed to AddRepresentation().
|
|
|
|
std::string content_type_;
|
|
|
|
|
2015-06-30 00:21:05 +00:00
|
|
|
// This does not have to be a set, it could be a list or vector because all we
|
|
|
|
// really care is whether there is more than one entry.
|
|
|
|
// Contains one entry if all the Representations have the same picture aspect
|
|
|
|
// ratio (@par attribute for AdaptationSet).
|
|
|
|
// There will be more than one entry if there are multiple picture aspect
|
|
|
|
// ratios.
|
|
|
|
// The @par attribute should only be set if there is exactly one entry
|
|
|
|
// in this set.
|
|
|
|
std::set<std::string> picture_aspect_ratio_;
|
|
|
|
|
2015-06-26 23:00:41 +00:00
|
|
|
// The roles of this AdaptationSet.
|
|
|
|
std::set<Role> roles_;
|
|
|
|
|
2015-07-13 17:44:52 +00:00
|
|
|
// True iff all the segments are aligned.
|
|
|
|
SegmentAligmentStatus segments_aligned_;
|
|
|
|
bool force_set_segment_alignment_;
|
|
|
|
|
|
|
|
// Keeps track of segment start times of Representations.
|
2015-08-05 21:44:35 +00:00
|
|
|
// For VOD, this will not be cleared, all the segment start times are
|
|
|
|
// stored in this. This should not out-of-memory for a reasonable length
|
|
|
|
// video and reasonable subsegment length.
|
|
|
|
// For Live, the entries are deleted (see CheckLiveSegmentAlignment()
|
|
|
|
// implementation comment) because storing the entire timeline is not
|
|
|
|
// reasonable and may cause an out-of-memory problem.
|
2015-07-13 17:44:52 +00:00
|
|
|
RepresentationTimeline representation_segment_start_times_;
|
|
|
|
|
2013-11-18 23:48:14 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(AdaptationSet);
|
|
|
|
};
|
|
|
|
|
2015-07-13 17:44:52 +00:00
|
|
|
class RepresentationStateChangeListener {
|
|
|
|
public:
|
|
|
|
RepresentationStateChangeListener() {}
|
|
|
|
virtual ~RepresentationStateChangeListener() {}
|
|
|
|
|
|
|
|
/// Notifies the instance that a new (sub)segment was added to
|
|
|
|
/// the Representation.
|
|
|
|
/// @param start_time is the start time of the new segment.
|
|
|
|
/// @param duration is the duration of the new segment.
|
|
|
|
virtual void OnNewSegmentForRepresentation(uint64_t start_time,
|
|
|
|
uint64_t duration) = 0;
|
2015-07-31 19:38:50 +00:00
|
|
|
|
|
|
|
/// Notifies the instance that the frame rate was set for the
|
|
|
|
/// Representation.
|
|
|
|
/// @param frame_duration is the duration of a frame.
|
|
|
|
/// @param timescale is the timescale of the Representation.
|
|
|
|
virtual void OnSetFrameRateForRepresentation(uint32_t frame_duration,
|
|
|
|
uint32_t timescale) = 0;
|
2015-07-13 17:44:52 +00:00
|
|
|
};
|
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Representation class contains references to a single media stream, as
|
|
|
|
/// well as optional ContentProtection elements for that stream.
|
2013-11-18 23:48:14 +00:00
|
|
|
class Representation {
|
|
|
|
public:
|
2015-07-16 06:51:24 +00:00
|
|
|
virtual ~Representation();
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Tries to initialize the instance. If this does not succeed, the instance
|
|
|
|
/// should not be used.
|
|
|
|
/// @return true on success, false otherwise.
|
2014-01-03 00:59:16 +00:00
|
|
|
bool Init();
|
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Add a ContenProtection element to the representation.
|
2015-07-15 21:57:47 +00:00
|
|
|
/// Representation does not add <ContentProtection> elements
|
|
|
|
/// automatically to itself even if @a media_info passed to
|
|
|
|
/// AdaptationSet::AddRepresentation() has @a media_info.protected_content
|
|
|
|
/// populated. This is because some MPDs should have the elements at
|
|
|
|
/// AdaptationSet level and some at Representation level.
|
2014-02-06 21:20:36 +00:00
|
|
|
/// @param element contains the ContentProtection element contents.
|
|
|
|
/// If @a element has {value, schemeIdUri} set and has
|
|
|
|
/// {“value”, “schemeIdUri”} as key for @a additional_attributes,
|
|
|
|
/// then the former is used.
|
2015-07-16 06:51:24 +00:00
|
|
|
virtual void AddContentProtectionElement(
|
|
|
|
const ContentProtectionElement& element);
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2015-09-24 22:03:52 +00:00
|
|
|
/// Update the 'cenc:pssh' element for @a drm_uuid ContentProtection element.
|
2015-08-26 20:25:29 +00:00
|
|
|
/// If the element does not exist, this will add one.
|
2015-09-24 22:03:52 +00:00
|
|
|
/// @param drm_uuid is the UUID of the DRM for encryption.
|
2015-08-26 20:25:29 +00:00
|
|
|
/// @param pssh is the content of <cenc:pssh> element.
|
|
|
|
/// Note that DASH IF IOP mentions that this should be base64 encoded
|
|
|
|
/// string of the whole pssh box.
|
|
|
|
/// @attention This might get removed once DASH IF IOP specification makes a
|
2015-09-24 22:03:52 +00:00
|
|
|
/// a clear guideline on how to handle key rotation. Also to get
|
|
|
|
/// this working with shaka-player, this method *DOES NOT* update
|
|
|
|
/// the PSSH element. Instead, it removes the element regardless of
|
|
|
|
/// the content of @a pssh.
|
|
|
|
virtual void UpdateContentProtectionPssh(const std::string& drm_uuid,
|
|
|
|
const std::string& pssh);
|
2015-08-26 20:25:29 +00:00
|
|
|
|
2015-07-13 17:44:52 +00:00
|
|
|
/// Add a media (sub)segment to the representation.
|
|
|
|
/// AdaptationSet@{subSegmentAlignment,segmentAlignment} cannot be set
|
|
|
|
/// if this is not called for all Representations.
|
|
|
|
/// @param start_time is the start time for the (sub)segment, in units of the
|
2014-02-06 21:20:36 +00:00
|
|
|
/// stream's time scale.
|
|
|
|
/// @param duration is the duration of the segment, in units of the stream's
|
|
|
|
/// time scale.
|
2014-05-22 02:16:17 +00:00
|
|
|
/// @param size of the segment in bytes.
|
2015-07-16 06:51:24 +00:00
|
|
|
virtual void AddNewSegment(uint64_t start_time,
|
|
|
|
uint64_t duration,
|
|
|
|
uint64_t size);
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2015-06-15 21:12:42 +00:00
|
|
|
/// Set the sample duration of this Representation.
|
2015-07-31 19:38:50 +00:00
|
|
|
/// Sample duration is not available right away especially for live. This
|
2015-06-15 21:12:42 +00:00
|
|
|
/// allows setting the sample duration after the Representation has been
|
|
|
|
/// initialized.
|
|
|
|
/// @param sample_duration is the duration of a sample.
|
2015-07-16 06:51:24 +00:00
|
|
|
virtual void SetSampleDuration(uint32_t sample_duration);
|
2015-06-15 21:12:42 +00:00
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// @return Copy of <Representation>.
|
2015-11-17 00:06:17 +00:00
|
|
|
xml::scoped_xml_ptr<xmlNode> GetXml();
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// @return ID number for <Representation>.
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t id() const { return id_; }
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2015-07-16 06:51:24 +00:00
|
|
|
protected:
|
2014-05-27 22:21:42 +00:00
|
|
|
/// @param media_info is a MediaInfo containing information on the media.
|
|
|
|
/// @a media_info.bandwidth is required for 'static' profile. If @a
|
|
|
|
/// media_info.bandwidth is not present in 'dynamic' profile, this
|
|
|
|
/// tries to estimate it using the info passed to AddNewSegment().
|
2015-07-13 17:44:52 +00:00
|
|
|
/// @param mpd_options is options for the entire MPD.
|
2014-05-27 22:21:42 +00:00
|
|
|
/// @param representation_id is the numeric ID for the <Representation>.
|
2015-07-13 17:44:52 +00:00
|
|
|
/// @param state_change_listener is an event handler for state changes to
|
|
|
|
/// the representation. If null, no event handler registered.
|
|
|
|
Representation(
|
|
|
|
const MediaInfo& media_info,
|
|
|
|
const MpdOptions& mpd_options,
|
|
|
|
uint32_t representation_id,
|
|
|
|
scoped_ptr<RepresentationStateChangeListener> state_change_listener);
|
2014-05-27 22:21:42 +00:00
|
|
|
|
2015-07-16 06:51:24 +00:00
|
|
|
private:
|
|
|
|
friend class AdaptationSet;
|
2015-10-29 22:48:13 +00:00
|
|
|
template <MpdBuilder::MpdType type>
|
|
|
|
friend class MpdBuilderTest;
|
2015-07-16 06:51:24 +00:00
|
|
|
|
2014-05-22 02:16:17 +00:00
|
|
|
bool AddLiveInfo(xml::RepresentationXmlNode* representation);
|
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
// Returns true if |media_info_| has required fields to generate a valid
|
|
|
|
// Representation. Otherwise returns false.
|
2014-01-03 00:59:16 +00:00
|
|
|
bool HasRequiredMediaInfoFields();
|
|
|
|
|
2014-05-22 02:16:17 +00:00
|
|
|
// Return false if the segment should be considered a new segment. True if the
|
|
|
|
// segment is contiguous.
|
2014-09-30 21:52:21 +00:00
|
|
|
bool IsContiguous(uint64_t start_time,
|
|
|
|
uint64_t duration,
|
|
|
|
uint64_t size) const;
|
2014-05-22 02:16:17 +00:00
|
|
|
|
2014-05-27 22:21:42 +00:00
|
|
|
// Remove elements from |segment_infos_| if
|
|
|
|
// mpd_options_.time_shift_buffer_depth is specified. Increments
|
|
|
|
// |start_number_| by the number of segments removed.
|
|
|
|
void SlideWindow();
|
|
|
|
|
2014-01-03 00:59:16 +00:00
|
|
|
// Note: Because 'mimeType' is a required field for a valid MPD, these return
|
|
|
|
// strings.
|
|
|
|
std::string GetVideoMimeType() const;
|
|
|
|
std::string GetAudioMimeType() const;
|
2015-10-29 20:58:36 +00:00
|
|
|
std::string GetTextMimeType() const;
|
2014-01-03 00:59:16 +00:00
|
|
|
|
2014-06-26 01:33:09 +00:00
|
|
|
// Gets the earliest, normalized segment timestamp. Returns true if
|
|
|
|
// successful, false otherwise.
|
|
|
|
bool GetEarliestTimestamp(double* timestamp_seconds);
|
|
|
|
|
2015-10-29 20:58:36 +00:00
|
|
|
// Init() checks that only one of VideoInfo, AudioInfo, or TextInfo is set. So
|
|
|
|
// any logic using this can assume only one set.
|
2013-11-18 23:48:14 +00:00
|
|
|
MediaInfo media_info_;
|
|
|
|
std::list<ContentProtectionElement> content_protection_elements_;
|
2014-05-22 02:16:17 +00:00
|
|
|
std::list<SegmentInfo> segment_infos_;
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
const uint32_t id_;
|
2014-01-03 00:59:16 +00:00
|
|
|
std::string mime_type_;
|
|
|
|
std::string codecs_;
|
2014-05-22 02:16:17 +00:00
|
|
|
BandwidthEstimator bandwidth_estimator_;
|
2014-06-26 01:33:09 +00:00
|
|
|
const MpdOptions& mpd_options_;
|
2014-05-27 22:21:42 +00:00
|
|
|
|
|
|
|
// startNumber attribute for SegmentTemplate.
|
|
|
|
// Starts from 1.
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t start_number_;
|
2013-11-18 23:48:14 +00:00
|
|
|
|
2015-07-13 17:44:52 +00:00
|
|
|
// If this is not null, then Representation is responsible for calling the
|
|
|
|
// right methods at right timings.
|
|
|
|
scoped_ptr<RepresentationStateChangeListener> state_change_listener_;
|
|
|
|
|
2013-11-18 23:48:14 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(Representation);
|
|
|
|
};
|
|
|
|
|
2014-09-19 20:41:13 +00:00
|
|
|
} // namespace edash_packager
|
2013-11-18 23:48:14 +00:00
|
|
|
|
|
|
|
#endif // MPD_BASE_MPD_BUILDER_H_
|