DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
xml_node.h
1 // Copyright 2014 Google Inc. 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 //
7 // Classes to wrap XML operations. XmlNode is a generic wrapper class for
8 // XmlNode in libxml2. There are also MPD XML specific classes as well.
9 
10 #ifndef MPD_BASE_XML_XML_NODE_H_
11 #define MPD_BASE_XML_XML_NODE_H_
12 
13 #include <libxml/tree.h>
14 #include <stdint.h>
15 
16 #include <list>
17 
18 #include "packager/base/macros.h"
19 #include "packager/mpd/base/content_protection_element.h"
20 #include "packager/mpd/base/media_info.pb.h"
21 #include "packager/mpd/base/xml/scoped_xml_ptr.h"
22 
23 namespace shaka {
24 
25 struct SegmentInfo;
26 
27 namespace xml {
28 
32 class XmlNode {
33  public:
36  explicit XmlNode(const char* name);
37  virtual ~XmlNode();
38 
43  bool AddChild(scoped_xml_ptr<xmlNode> child);
44 
46  bool AddElements(const std::vector<Element>& elements);
47 
51  void SetStringAttribute(const char* attribute_name,
52  const std::string& attribute);
53 
57  void SetIntegerAttribute(const char* attribute_name, uint64_t number);
58 
62  void SetFloatingPointAttribute(const char* attribute_name, double number);
63 
66  void SetId(uint32_t id);
67 
74  void SetContent(const std::string& content);
75 
79  scoped_xml_ptr<xmlNode> PassScopedPtr();
80 
83  xmlNodePtr Release();
84 
86  xmlNodePtr GetRawPtr();
87 
88  private:
89  scoped_xml_ptr<xmlNode> node_;
90 
91  DISALLOW_COPY_AND_ASSIGN(XmlNode);
92 };
93 
98  public:
99  ~RepresentationBaseXmlNode() override;
100  bool AddContentProtectionElements(
101  const std::list<ContentProtectionElement>& content_protection_elements);
102 
103  protected:
104  explicit RepresentationBaseXmlNode(const char* name);
105 
106  private:
107  bool AddContentProtectionElement(
108  const ContentProtectionElement& content_protection_element);
109 
110  DISALLOW_COPY_AND_ASSIGN(RepresentationBaseXmlNode);
111 };
112 
115  public:
117  ~AdaptationSetXmlNode() override;
118 
121  void AddRoleElement(const std::string& scheme_id_uri,
122  const std::string& value);
123 
124  private:
125  DISALLOW_COPY_AND_ASSIGN(AdaptationSetXmlNode);
126 };
127 
130  public:
132  ~RepresentationXmlNode() override;
133 
141  bool AddVideoInfo(const MediaInfo::VideoInfo& video_info,
142  bool set_width,
143  bool set_height,
144  bool set_frame_rate);
145 
150  bool AddAudioInfo(const MediaInfo::AudioInfo& audio_info);
151 
156  bool AddVODOnlyInfo(const MediaInfo& media_info);
157 
160  bool AddLiveOnlyInfo(const MediaInfo& media_info,
161  const std::list<SegmentInfo>& segment_infos,
162  uint32_t start_number);
163 
164  private:
165  // Add AudioChannelConfiguration element. Note that it is a required element
166  // for audio Representations.
167  bool AddAudioChannelInfo(const MediaInfo::AudioInfo& audio_info);
168 
169  // Add audioSamplingRate attribute to this element, if present.
170  void AddAudioSamplingRateInfo(const MediaInfo::AudioInfo& audio_info);
171 
172  DISALLOW_COPY_AND_ASSIGN(RepresentationXmlNode);
173 };
174 
175 } // namespace xml
176 } // namespace shaka
177 #endif // MPD_BASE_XML_XML_NODE_H_
bool AddVideoInfo(const MediaInfo::VideoInfo &video_info, bool set_width, bool set_height, bool set_frame_rate)
Definition: xml_node.cc:216
RepresentationType in MPD.
Definition: xml_node.h:129
void SetFloatingPointAttribute(const char *attribute_name, double number)
Definition: xml_node.cc:119
AdaptationSetType specified in MPD.
Definition: xml_node.h:114
scoped_xml_ptr< xmlNode > PassScopedPtr()
Definition: xml_node.cc:137
XmlNode(const char *name)
Definition: xml_node.cc:55
bool AddVODOnlyInfo(const MediaInfo &media_info)
Definition: xml_node.cc:251
void SetStringAttribute(const char *attribute_name, const std::string &attribute)
Definition: xml_node.cc:104
bool AddChild(scoped_xml_ptr< xmlNode > child)
Definition: xml_node.cc:62
xmlNodePtr Release()
Definition: xml_node.cc:143
bool AddLiveOnlyInfo(const MediaInfo &media_info, const std::list< SegmentInfo > &segment_infos, uint32_t start_number)
Definition: xml_node.cc:298
void SetId(uint32_t id)
Definition: xml_node.cc:128
bool AddElements(const std::vector< Element > &elements)
Adds Elements to this node using the Element struct.
Definition: xml_node.cc:74
void SetIntegerAttribute(const char *attribute_name, uint64_t number)
Definition: xml_node.cc:111
void AddRoleElement(const std::string &scheme_id_uri, const std::string &value)
Definition: xml_node.cc:204
void SetContent(const std::string &content)
Definition: xml_node.cc:132
bool AddAudioInfo(const MediaInfo::AudioInfo &audio_info)
Definition: xml_node.cc:243
xmlNodePtr GetRawPtr()
Definition: xml_node.cc:149