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 21:01:48 +00:00
|
|
|
// Classes to wrap XML operations. XmlNode is a generic wrapper class for
|
|
|
|
// XmlNode in libxml2. There are also MPD XML specific classes as well.
|
2014-02-14 23:21:05 +00:00
|
|
|
|
2013-11-18 21:01:48 +00:00
|
|
|
#ifndef MPD_BASE_XML_XML_NODE_H_
|
|
|
|
#define MPD_BASE_XML_XML_NODE_H_
|
|
|
|
|
2014-09-30 23:52:58 +00:00
|
|
|
#include <stdint.h>
|
2014-08-28 18:35:15 +00:00
|
|
|
|
2013-11-18 21:01:48 +00:00
|
|
|
#include <list>
|
2018-09-18 19:05:11 +00:00
|
|
|
#include <set>
|
2020-11-10 00:32:58 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2013-11-18 21:01:48 +00:00
|
|
|
|
2020-11-10 00:32:58 +00:00
|
|
|
#include "packager/base/compiler_specific.h"
|
2016-08-17 17:41:40 +00:00
|
|
|
#include "packager/base/macros.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/mpd/base/content_protection_element.h"
|
|
|
|
#include "packager/mpd/base/media_info.pb.h"
|
2020-11-10 00:32:58 +00:00
|
|
|
|
|
|
|
typedef struct _xmlNode xmlNode;
|
2013-11-18 21:01:48 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2014-05-22 02:16:17 +00:00
|
|
|
|
2020-11-10 00:32:58 +00:00
|
|
|
class MpdBuilder;
|
2014-05-22 02:16:17 +00:00
|
|
|
struct SegmentInfo;
|
|
|
|
|
2020-11-10 00:32:58 +00:00
|
|
|
namespace xml {
|
|
|
|
class XmlNode;
|
|
|
|
} // namespace xml
|
|
|
|
|
|
|
|
// Defined in tests under mpd/test/xml_compare.h
|
|
|
|
bool XmlEqual(const std::string& xml1, const xml::XmlNode& xml2);
|
|
|
|
|
2013-11-18 21:01:48 +00:00
|
|
|
namespace xml {
|
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// These classes are wrapper classes for XML elements for generating MPD.
|
|
|
|
/// None of the pointer parameters should be NULL. None of the methods are meant
|
|
|
|
/// to be overridden.
|
2013-11-18 21:01:48 +00:00
|
|
|
class XmlNode {
|
|
|
|
public:
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Make an XML element.
|
|
|
|
/// @param name is the name of the element, which should not be NULL.
|
2020-11-10 00:32:58 +00:00
|
|
|
explicit XmlNode(const std::string& name);
|
|
|
|
XmlNode(XmlNode&&);
|
2013-11-18 21:01:48 +00:00
|
|
|
virtual ~XmlNode();
|
|
|
|
|
2020-11-10 00:32:58 +00:00
|
|
|
XmlNode& operator=(XmlNode&&);
|
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Add a child element to this element.
|
2020-11-10 00:32:58 +00:00
|
|
|
/// @param child is an XmlNode to add as a child for this element.
|
2014-02-06 21:20:36 +00:00
|
|
|
/// @return true on success, false otherwise.
|
2020-11-10 00:32:58 +00:00
|
|
|
bool AddChild(XmlNode child) WARN_UNUSED_RESULT;
|
2013-11-18 21:01:48 +00:00
|
|
|
|
2015-07-15 21:57:47 +00:00
|
|
|
/// Adds Elements to this node using the Element struct.
|
2020-11-10 00:32:58 +00:00
|
|
|
bool AddElements(const std::vector<Element>& elements) WARN_UNUSED_RESULT;
|
2015-07-15 21:57:47 +00:00
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Set a string attribute.
|
|
|
|
/// @param attribute_name The name (lhs) of the attribute.
|
|
|
|
/// @param attribute The value (rhs) of the attribute.
|
2020-11-10 00:32:58 +00:00
|
|
|
bool SetStringAttribute(const std::string& attribute_name,
|
|
|
|
const std::string& attribute) WARN_UNUSED_RESULT;
|
2013-11-18 21:01:48 +00:00
|
|
|
|
2015-06-17 01:37:23 +00:00
|
|
|
/// Sets an integer attribute.
|
2014-02-06 21:20:36 +00:00
|
|
|
/// @param attribute_name The name (lhs) of the attribute.
|
|
|
|
/// @param number The value (rhs) of the attribute.
|
2020-11-10 00:32:58 +00:00
|
|
|
bool SetIntegerAttribute(const std::string& attribute_name,
|
|
|
|
uint64_t number) WARN_UNUSED_RESULT;
|
2014-02-06 21:20:36 +00:00
|
|
|
|
|
|
|
/// Set a floating point number attribute.
|
|
|
|
/// @param attribute_name is the name of the attribute to set.
|
|
|
|
/// @param number is the value (rhs) of the attribute.
|
2020-11-10 00:32:58 +00:00
|
|
|
bool SetFloatingPointAttribute(const std::string& attribute_name,
|
|
|
|
double number) WARN_UNUSED_RESULT;
|
2013-11-18 21:01:48 +00:00
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Sets 'id=@a id' attribute.
|
|
|
|
/// @param id is the ID for this element.
|
2020-11-10 00:32:58 +00:00
|
|
|
bool SetId(uint32_t id) WARN_UNUSED_RESULT;
|
2013-11-18 21:01:48 +00:00
|
|
|
|
2020-10-08 21:46:37 +00:00
|
|
|
/// Similar to SetContent, but appends to the end of existing content.
|
|
|
|
void AddContent(const std::string& content);
|
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Set the contents of an XML element using a string.
|
2015-07-15 21:57:47 +00:00
|
|
|
/// This cannot set child elements because <> will become < and &rt;
|
|
|
|
/// This should be used to set the text for the element, e.g. setting
|
|
|
|
/// a URL for <BaseURL> element.
|
2014-02-06 21:20:36 +00:00
|
|
|
/// @param content is a string containing the text-encoded child elements to
|
|
|
|
/// be added to the element.
|
2013-11-18 21:01:48 +00:00
|
|
|
void SetContent(const std::string& content);
|
|
|
|
|
2018-09-18 19:05:11 +00:00
|
|
|
/// @return namespaces used in the node and its descendents.
|
2020-11-10 00:32:58 +00:00
|
|
|
std::set<std::string> ExtractReferencedNamespaces() const;
|
2018-09-18 19:05:11 +00:00
|
|
|
|
2020-11-10 00:32:58 +00:00
|
|
|
/// @param comment The body of a comment to add to the top of the XML.
|
|
|
|
/// @return A string containing the XML.
|
|
|
|
std::string ToString(const std::string& comment) const;
|
2013-11-18 21:01:48 +00:00
|
|
|
|
2020-11-10 00:32:58 +00:00
|
|
|
/// Gets the attribute with the given name.
|
|
|
|
/// @param name The name of the attribute to get.
|
|
|
|
/// @param value [OUT] where to put the resulting value.
|
|
|
|
/// @return True if the attribute exists, false if not.
|
|
|
|
bool GetAttribute(const std::string& name, std::string* value) const;
|
2013-11-18 21:01:48 +00:00
|
|
|
|
|
|
|
private:
|
2020-11-10 00:32:58 +00:00
|
|
|
friend bool shaka::XmlEqual(const std::string& xml1,
|
|
|
|
const xml::XmlNode& xml2);
|
|
|
|
xmlNode* GetRawPtr() const;
|
|
|
|
|
|
|
|
// Don't use xmlNode directly so we don't have to forward-declare a bunch of
|
|
|
|
// libxml types to define the scoped_xml_ptr type. This allows us to only
|
|
|
|
// include libxml headers in a few source files.
|
|
|
|
class Impl;
|
|
|
|
std::unique_ptr<Impl> impl_;
|
2013-11-18 21:01:48 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(XmlNode);
|
|
|
|
};
|
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// This corresponds to RepresentationBaseType in MPD. RepresentationBaseType is
|
|
|
|
/// not a concrete element type so this should not get instantiated on its own.
|
|
|
|
/// AdaptationSet and Representation are subtypes of this.
|
2013-11-18 21:01:48 +00:00
|
|
|
class RepresentationBaseXmlNode : public XmlNode {
|
|
|
|
public:
|
2015-07-22 23:40:45 +00:00
|
|
|
~RepresentationBaseXmlNode() override;
|
2013-11-18 21:01:48 +00:00
|
|
|
bool AddContentProtectionElements(
|
2020-11-10 00:32:58 +00:00
|
|
|
const std::list<ContentProtectionElement>& content_protection_elements)
|
|
|
|
WARN_UNUSED_RESULT;
|
2013-11-18 21:01:48 +00:00
|
|
|
|
2016-12-13 23:48:54 +00:00
|
|
|
/// @param scheme_id_uri is content of the schemeIdUri attribute.
|
|
|
|
/// @param value is the content of value attribute.
|
2020-11-10 00:32:58 +00:00
|
|
|
bool AddSupplementalProperty(const std::string& scheme_id_uri,
|
|
|
|
const std::string& value) WARN_UNUSED_RESULT;
|
2016-12-13 23:48:54 +00:00
|
|
|
|
2017-03-21 23:14:46 +00:00
|
|
|
/// @param scheme_id_uri is content of the schemeIdUri attribute.
|
|
|
|
/// @param value is the content of value attribute.
|
2020-11-10 00:32:58 +00:00
|
|
|
bool AddEssentialProperty(const std::string& scheme_id_uri,
|
|
|
|
const std::string& value) WARN_UNUSED_RESULT;
|
2017-03-21 23:14:46 +00:00
|
|
|
|
2013-11-18 21:01:48 +00:00
|
|
|
protected:
|
2020-11-10 00:32:58 +00:00
|
|
|
explicit RepresentationBaseXmlNode(const std::string& name);
|
2013-11-18 21:01:48 +00:00
|
|
|
|
2019-06-25 01:02:19 +00:00
|
|
|
/// Add a Descriptor.
|
|
|
|
/// @param descriptor_name is the name of the descriptor.
|
|
|
|
/// @param scheme_id_uri is content of the schemeIdUri attribute.
|
|
|
|
/// @param value is the content of value attribute.
|
|
|
|
bool AddDescriptor(const std::string& descriptor_name,
|
|
|
|
const std::string& scheme_id_uri,
|
2020-11-10 00:32:58 +00:00
|
|
|
const std::string& value) WARN_UNUSED_RESULT;
|
2019-06-25 01:02:19 +00:00
|
|
|
|
2013-11-18 21:01:48 +00:00
|
|
|
private:
|
|
|
|
bool AddContentProtectionElement(
|
2020-11-10 00:32:58 +00:00
|
|
|
const ContentProtectionElement& content_protection_element)
|
|
|
|
WARN_UNUSED_RESULT;
|
2013-11-18 21:01:48 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(RepresentationBaseXmlNode);
|
|
|
|
};
|
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// AdaptationSetType specified in MPD.
|
2013-11-18 21:01:48 +00:00
|
|
|
class AdaptationSetXmlNode : public RepresentationBaseXmlNode {
|
|
|
|
public:
|
|
|
|
AdaptationSetXmlNode();
|
2015-07-22 23:40:45 +00:00
|
|
|
~AdaptationSetXmlNode() override;
|
2013-11-18 21:01:48 +00:00
|
|
|
|
2019-06-13 06:01:16 +00:00
|
|
|
/// @param scheme_id_uri is content of the schemeIdUri attribute.
|
|
|
|
/// @param value is the content of value attribute.
|
2020-11-10 00:32:58 +00:00
|
|
|
bool AddAccessibilityElement(const std::string& scheme_id_uri,
|
|
|
|
const std::string& value) WARN_UNUSED_RESULT;
|
2019-06-13 06:01:16 +00:00
|
|
|
|
2015-06-26 23:00:41 +00:00
|
|
|
/// @param scheme_id_uri is content of the schemeIdUri attribute.
|
|
|
|
/// @param value is the content of value attribute.
|
2020-11-10 00:32:58 +00:00
|
|
|
bool AddRoleElement(const std::string& scheme_id_uri,
|
|
|
|
const std::string& value) WARN_UNUSED_RESULT;
|
2015-06-26 23:00:41 +00:00
|
|
|
|
2013-11-18 21:01:48 +00:00
|
|
|
private:
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(AdaptationSetXmlNode);
|
|
|
|
};
|
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// RepresentationType in MPD.
|
2013-11-18 21:01:48 +00:00
|
|
|
class RepresentationXmlNode : public RepresentationBaseXmlNode {
|
|
|
|
public:
|
|
|
|
RepresentationXmlNode();
|
2015-07-22 23:40:45 +00:00
|
|
|
~RepresentationXmlNode() override;
|
2013-11-18 21:01:48 +00:00
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Adds video metadata to the MPD.
|
2015-06-09 23:58:32 +00:00
|
|
|
/// @param video_info constains the VideoInfo for a Representation.
|
2016-01-05 00:33:53 +00:00
|
|
|
/// @param set_width is a flag for setting the width attribute.
|
|
|
|
/// @param set_height is a flag for setting the height attribute.
|
|
|
|
/// @param set_frame_rate is a flag for setting the frameRate attribute.
|
2014-02-06 21:20:36 +00:00
|
|
|
/// @return true if successfully set attributes and children elements (if
|
|
|
|
/// applicable), false otherwise.
|
2016-01-05 00:33:53 +00:00
|
|
|
bool AddVideoInfo(const MediaInfo::VideoInfo& video_info,
|
|
|
|
bool set_width,
|
|
|
|
bool set_height,
|
2020-11-10 00:32:58 +00:00
|
|
|
bool set_frame_rate) WARN_UNUSED_RESULT;
|
2014-02-06 21:20:36 +00:00
|
|
|
|
|
|
|
/// Adds audio metadata to the MPD.
|
2015-06-09 23:58:32 +00:00
|
|
|
/// @param audio_info constains the AudioInfos for a Representation.
|
2014-02-06 21:20:36 +00:00
|
|
|
/// @return true if successfully set attributes and children elements (if
|
|
|
|
/// applicable), false otherwise.
|
2020-11-10 00:32:58 +00:00
|
|
|
bool AddAudioInfo(const MediaInfo::AudioInfo& audio_info) WARN_UNUSED_RESULT;
|
2013-11-18 21:01:48 +00:00
|
|
|
|
2015-06-09 22:29:14 +00:00
|
|
|
/// Adds fields that are specific to VOD. This ignores @a media_info fields
|
|
|
|
/// for Live.
|
2014-02-06 21:20:36 +00:00
|
|
|
/// @param media_info is a MediaInfo with VOD information.
|
2021-05-25 19:08:58 +00:00
|
|
|
/// @param use_segment_list is a param that instructs the xml writer to
|
|
|
|
/// use SegmentList instead of SegmentBase.
|
|
|
|
/// @param target_segment_duration is a param that specifies the target
|
|
|
|
// duration of media segments. This is only used when use_segment_list
|
|
|
|
// is true.
|
2014-02-06 21:20:36 +00:00
|
|
|
/// @return true on success, false otherwise.
|
2021-05-25 19:08:58 +00:00
|
|
|
bool AddVODOnlyInfo(const MediaInfo& media_info,
|
|
|
|
bool use_segment_list,
|
|
|
|
double target_segment_duration) WARN_UNUSED_RESULT;
|
2013-11-18 21:01:48 +00:00
|
|
|
|
2014-05-27 22:21:42 +00:00
|
|
|
/// @param segment_infos is a set of SegmentInfos. This method assumes that
|
|
|
|
/// SegmentInfos are sorted by its start time.
|
2014-05-22 02:16:17 +00:00
|
|
|
bool AddLiveOnlyInfo(const MediaInfo& media_info,
|
2014-05-27 22:21:42 +00:00
|
|
|
const std::list<SegmentInfo>& segment_infos,
|
2021-08-25 15:38:05 +00:00
|
|
|
uint32_t start_number,
|
|
|
|
bool low_latency_dash_mode) WARN_UNUSED_RESULT;
|
2014-05-22 02:16:17 +00:00
|
|
|
|
2013-11-18 21:01:48 +00:00
|
|
|
private:
|
2015-06-09 23:58:32 +00:00
|
|
|
// Add AudioChannelConfiguration element. Note that it is a required element
|
|
|
|
// for audio Representations.
|
2020-11-10 00:32:58 +00:00
|
|
|
bool AddAudioChannelInfo(const MediaInfo::AudioInfo& audio_info)
|
|
|
|
WARN_UNUSED_RESULT;
|
2013-11-18 21:01:48 +00:00
|
|
|
|
2015-06-09 23:58:32 +00:00
|
|
|
// Add audioSamplingRate attribute to this element, if present.
|
2020-11-10 00:32:58 +00:00
|
|
|
bool AddAudioSamplingRateInfo(const MediaInfo::AudioInfo& audio_info)
|
|
|
|
WARN_UNUSED_RESULT;
|
2013-11-18 21:01:48 +00:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(RepresentationXmlNode);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace xml
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|
2013-11-18 21:01:48 +00:00
|
|
|
#endif // MPD_BASE_XML_XML_NODE_H_
|