Shaka Packager SDK
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;
101  const std::list<ContentProtectionElement>& content_protection_elements);
102 
105  void AddSupplementalProperty(const std::string& scheme_id_uri,
106  const std::string& value);
107 
110  void AddEssentialProperty(const std::string& scheme_id_uri,
111  const std::string& value);
112 
113  protected:
114  explicit RepresentationBaseXmlNode(const char* name);
115 
116  private:
117  bool AddContentProtectionElement(
118  const ContentProtectionElement& content_protection_element);
119 
120  DISALLOW_COPY_AND_ASSIGN(RepresentationBaseXmlNode);
121 };
122 
125  public:
127  ~AdaptationSetXmlNode() override;
128 
131  void AddRoleElement(const std::string& scheme_id_uri,
132  const std::string& value);
133 
134  private:
135  DISALLOW_COPY_AND_ASSIGN(AdaptationSetXmlNode);
136 };
137 
140  public:
142  ~RepresentationXmlNode() override;
143 
151  bool AddVideoInfo(const MediaInfo::VideoInfo& video_info,
152  bool set_width,
153  bool set_height,
154  bool set_frame_rate);
155 
160  bool AddAudioInfo(const MediaInfo::AudioInfo& audio_info);
161 
166  bool AddVODOnlyInfo(const MediaInfo& media_info);
167 
170  bool AddLiveOnlyInfo(const MediaInfo& media_info,
171  const std::list<SegmentInfo>& segment_infos,
172  uint32_t start_number);
173 
174  private:
175  // Add AudioChannelConfiguration element. Note that it is a required element
176  // for audio Representations.
177  bool AddAudioChannelInfo(const MediaInfo::AudioInfo& audio_info);
178 
179  // Add audioSamplingRate attribute to this element, if present.
180  void AddAudioSamplingRateInfo(const MediaInfo::AudioInfo& audio_info);
181 
182  DISALLOW_COPY_AND_ASSIGN(RepresentationXmlNode);
183 };
184 
185 } // namespace xml
186 } // namespace shaka
187 #endif // MPD_BASE_XML_XML_NODE_H_
RepresentationType in MPD.
Definition: xml_node.h:139
void SetFloatingPointAttribute(const char *attribute_name, double number)
Definition: xml_node.cc:152
AdaptationSetType specified in MPD.
Definition: xml_node.h:124
scoped_xml_ptr< xmlNode > PassScopedPtr()
Definition: xml_node.cc:169
XmlNode(const char *name)
Definition: xml_node.cc:88
All the methods that are virtual are virtual for mocking.
void SetStringAttribute(const char *attribute_name, const std::string &attribute)
Definition: xml_node.cc:137
bool AddChild(scoped_xml_ptr< xmlNode > child)
Definition: xml_node.cc:95
xmlNodePtr Release()
Definition: xml_node.cc:175
void AddContentProtectionElements(const MediaInfo &media_info, Representation *parent)
Definition: mpd_utils.cc:369
void SetId(uint32_t id)
Definition: xml_node.cc:160
bool AddElements(const std::vector< Element > &elements)
Adds Elements to this node using the Element struct.
Definition: xml_node.cc:107
void SetIntegerAttribute(const char *attribute_name, uint64_t number)
Definition: xml_node.cc:144
void SetContent(const std::string &content)
Definition: xml_node.cc:164
xmlNodePtr GetRawPtr()
Definition: xml_node.cc:181