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-08-28 18:35:15 +00:00
|
|
|
#include <libxml/tree.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>
|
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/mpd/base/content_protection_element.h"
|
|
|
|
#include "packager/mpd/base/media_info.pb.h"
|
|
|
|
#include "packager/mpd/base/xml/scoped_xml_ptr.h"
|
2013-11-18 21:01:48 +00:00
|
|
|
|
2014-09-19 20:41:13 +00:00
|
|
|
namespace edash_packager {
|
2014-05-22 02:16:17 +00:00
|
|
|
|
|
|
|
struct SegmentInfo;
|
|
|
|
|
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.
|
2013-11-18 21:01:48 +00:00
|
|
|
explicit XmlNode(const char* name);
|
|
|
|
virtual ~XmlNode();
|
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Add a child element to this element.
|
|
|
|
/// @param child is a xmlNode to add as a child for this element. Ownership
|
|
|
|
/// of the child node is transferred.
|
|
|
|
/// @return true on success, false otherwise.
|
2013-11-18 21:01:48 +00:00
|
|
|
bool AddChild(ScopedXmlPtr<xmlNode>::type child);
|
|
|
|
|
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.
|
2013-11-18 21:01:48 +00:00
|
|
|
void SetStringAttribute(const char* attribute_name,
|
|
|
|
const std::string& attribute);
|
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Sets an interger attribute.
|
|
|
|
/// @param attribute_name The name (lhs) of the attribute.
|
|
|
|
/// @param number The value (rhs) of the attribute.
|
2014-09-30 21:52:21 +00:00
|
|
|
void SetIntegerAttribute(const char* attribute_name, uint64_t number);
|
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.
|
2013-12-17 23:08:14 +00:00
|
|
|
void SetFloatingPointAttribute(const char* attribute_name, double number);
|
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.
|
2014-09-30 21:52:21 +00:00
|
|
|
void SetId(uint32_t id);
|
2013-11-18 21:01:48 +00:00
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Set the contents of an XML element using a string.
|
|
|
|
/// Note: This function does not work well with AddChild(). Use either
|
|
|
|
/// AddChild() or SetContent() when setting the content of this node.
|
|
|
|
/// @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);
|
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Transfer the ownership of the xmlNodePtr. After calling this method, the
|
|
|
|
/// behavior of any methods, except the destructor, is undefined.
|
|
|
|
/// @return The resource of this object.
|
2013-11-18 21:01:48 +00:00
|
|
|
ScopedXmlPtr<xmlNode>::type PassScopedPtr();
|
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Release the xmlNodePtr of this object. After calling this method, the
|
|
|
|
/// behavior of any methods, except the destructor, is undefined.
|
2013-11-18 21:01:48 +00:00
|
|
|
xmlNodePtr Release();
|
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// @return Raw pointer to the element.
|
2013-11-18 21:01:48 +00:00
|
|
|
xmlNodePtr GetRawPtr();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ScopedXmlPtr<xmlNode>::type node_;
|
|
|
|
|
|
|
|
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:
|
|
|
|
virtual ~RepresentationBaseXmlNode();
|
|
|
|
bool AddContentProtectionElements(
|
|
|
|
const std::list<ContentProtectionElement>& content_protection_elements);
|
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Add a ContentProtection elements to this element.
|
|
|
|
/// @param media_info is a MediaInfo containing the ContentProtection
|
|
|
|
/// elements to add.
|
|
|
|
/// @return true on success, false otherwise.
|
2014-01-14 22:57:50 +00:00
|
|
|
bool AddContentProtectionElementsFromMediaInfo(const MediaInfo& media_info);
|
|
|
|
|
2013-11-18 21:01:48 +00:00
|
|
|
protected:
|
|
|
|
explicit RepresentationBaseXmlNode(const char* name);
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool AddContentProtectionElement(
|
|
|
|
const ContentProtectionElement& content_protection_element);
|
|
|
|
|
|
|
|
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();
|
|
|
|
virtual ~AdaptationSetXmlNode();
|
|
|
|
|
|
|
|
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:
|
|
|
|
typedef ::google::protobuf::RepeatedPtrField<MediaInfo_VideoInfo>
|
|
|
|
RepeatedVideoInfo;
|
|
|
|
|
|
|
|
typedef ::google::protobuf::RepeatedPtrField<MediaInfo_AudioInfo>
|
|
|
|
RepeatedAudioInfo;
|
|
|
|
|
|
|
|
RepresentationXmlNode();
|
|
|
|
virtual ~RepresentationXmlNode();
|
|
|
|
|
2014-02-06 21:20:36 +00:00
|
|
|
/// Adds video metadata to the MPD.
|
|
|
|
/// @param repeated_video_info constains the VideoInfos for Representation.
|
|
|
|
/// Input of size 0 is valid.
|
|
|
|
/// @return true if successfully set attributes and children elements (if
|
|
|
|
/// applicable), false otherwise.
|
2013-11-18 21:01:48 +00:00
|
|
|
bool AddVideoInfo(const RepeatedVideoInfo& repeated_video_info);
|
2014-02-06 21:20:36 +00:00
|
|
|
|
|
|
|
/// Adds audio metadata to the MPD.
|
|
|
|
/// @param repeated_audio_info constains the AudioInfos for Representation.
|
|
|
|
/// Input of size 0 is valid.
|
|
|
|
/// @return true if successfully set attributes and children elements (if
|
|
|
|
/// applicable), false otherwise.
|
2013-11-18 21:01:48 +00:00
|
|
|
bool AddAudioInfo(const RepeatedAudioInfo& repeated_audio_info);
|
|
|
|
|
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.
|
|
|
|
/// @return true on success, false otherwise.
|
2013-11-18 21:01:48 +00:00
|
|
|
bool AddVODOnlyInfo(const MediaInfo& media_info);
|
|
|
|
|
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,
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t start_number);
|
2014-05-22 02:16:17 +00:00
|
|
|
|
2013-11-18 21:01:48 +00:00
|
|
|
private:
|
|
|
|
// Add AudioChannelConfiguration elements. This will add multiple
|
2014-02-06 21:20:36 +00:00
|
|
|
// AudioChannelConfiguration if @a repeated_audio_info contains multiple
|
2013-11-18 21:01:48 +00:00
|
|
|
// distinct channel configs (e.g. 2 channels and 6 channels adds 2 elements).
|
|
|
|
bool AddAudioChannelInfo(const RepeatedAudioInfo& repeated_audio_info);
|
|
|
|
|
|
|
|
// Add audioSamplingRate attribute to this element.
|
|
|
|
void AddAudioSamplingRateInfo(const RepeatedAudioInfo& repeated_audio_info);
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(RepresentationXmlNode);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace xml
|
2014-09-19 20:41:13 +00:00
|
|
|
} // namespace edash_packager
|
2013-11-18 21:01:48 +00:00
|
|
|
#endif // MPD_BASE_XML_XML_NODE_H_
|