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 <stdint.h>
14 
15 #include <list>
16 #include <set>
17 #include <string>
18 #include <vector>
19 
20 #include "packager/base/compiler_specific.h"
21 #include "packager/base/macros.h"
22 #include "packager/mpd/base/content_protection_element.h"
23 #include "packager/mpd/base/media_info.pb.h"
24 
25 typedef struct _xmlNode xmlNode;
26 
27 namespace shaka {
28 
29 class MpdBuilder;
30 struct SegmentInfo;
31 
32 namespace xml {
33 class XmlNode;
34 } // namespace xml
35 
36 // Defined in tests under mpd/test/xml_compare.h
37 bool XmlEqual(const std::string& xml1, const xml::XmlNode& xml2);
38 
39 namespace xml {
40 
44 class XmlNode {
45  public:
48  explicit XmlNode(const std::string& name);
49  XmlNode(XmlNode&&);
50  virtual ~XmlNode();
51 
52  XmlNode& operator=(XmlNode&&);
53 
57  bool AddChild(XmlNode child) WARN_UNUSED_RESULT;
58 
60  bool AddElements(const std::vector<Element>& elements) WARN_UNUSED_RESULT;
61 
65  bool SetStringAttribute(const std::string& attribute_name,
66  const std::string& attribute) WARN_UNUSED_RESULT;
67 
71  bool SetIntegerAttribute(const std::string& attribute_name,
72  uint64_t number) WARN_UNUSED_RESULT;
73 
77  bool SetFloatingPointAttribute(const std::string& attribute_name,
78  double number) WARN_UNUSED_RESULT;
79 
82  bool SetId(uint32_t id) WARN_UNUSED_RESULT;
83 
85  void AddContent(const std::string& content);
86 
93  void SetContent(const std::string& content);
94 
96  std::set<std::string> ExtractReferencedNamespaces() const;
97 
100  std::string ToString(const std::string& comment) const;
101 
106  bool GetAttribute(const std::string& name, std::string* value) const;
107 
108  private:
109  friend bool shaka::XmlEqual(const std::string& xml1,
110  const xml::XmlNode& xml2);
111  xmlNode* GetRawPtr() const;
112 
113  // Don't use xmlNode directly so we don't have to forward-declare a bunch of
114  // libxml types to define the scoped_xml_ptr type. This allows us to only
115  // include libxml headers in a few source files.
116  class Impl;
117  std::unique_ptr<Impl> impl_;
118 
119  DISALLOW_COPY_AND_ASSIGN(XmlNode);
120 };
121 
126  public:
127  ~RepresentationBaseXmlNode() override;
128  bool AddContentProtectionElements(
129  const std::list<ContentProtectionElement>& content_protection_elements)
130  WARN_UNUSED_RESULT;
131 
134  bool AddSupplementalProperty(const std::string& scheme_id_uri,
135  const std::string& value) WARN_UNUSED_RESULT;
136 
139  bool AddEssentialProperty(const std::string& scheme_id_uri,
140  const std::string& value) WARN_UNUSED_RESULT;
141 
142  protected:
143  explicit RepresentationBaseXmlNode(const std::string& name);
144 
149  bool AddDescriptor(const std::string& descriptor_name,
150  const std::string& scheme_id_uri,
151  const std::string& value) WARN_UNUSED_RESULT;
152 
153  private:
154  bool AddContentProtectionElement(
155  const ContentProtectionElement& content_protection_element)
156  WARN_UNUSED_RESULT;
157 
158  DISALLOW_COPY_AND_ASSIGN(RepresentationBaseXmlNode);
159 };
160 
163  public:
165  ~AdaptationSetXmlNode() override;
166 
169  bool AddAccessibilityElement(const std::string& scheme_id_uri,
170  const std::string& value) WARN_UNUSED_RESULT;
171 
174  bool AddRoleElement(const std::string& scheme_id_uri,
175  const std::string& value) WARN_UNUSED_RESULT;
176 
177  private:
178  DISALLOW_COPY_AND_ASSIGN(AdaptationSetXmlNode);
179 };
180 
183  public:
185  ~RepresentationXmlNode() override;
186 
194  bool AddVideoInfo(const MediaInfo::VideoInfo& video_info,
195  bool set_width,
196  bool set_height,
197  bool set_frame_rate) WARN_UNUSED_RESULT;
198 
203  bool AddAudioInfo(const MediaInfo::AudioInfo& audio_info) WARN_UNUSED_RESULT;
204 
211  // duration of media segments. This is only used when use_segment_list
212  // is true.
214  bool AddVODOnlyInfo(const MediaInfo& media_info,
215  bool use_segment_list,
216  double target_segment_duration) WARN_UNUSED_RESULT;
217 
220  bool AddLiveOnlyInfo(const MediaInfo& media_info,
221  const std::list<SegmentInfo>& segment_infos,
222  uint32_t start_number) WARN_UNUSED_RESULT;
223 
224  private:
225  // Add AudioChannelConfiguration element. Note that it is a required element
226  // for audio Representations.
227  bool AddAudioChannelInfo(const MediaInfo::AudioInfo& audio_info)
228  WARN_UNUSED_RESULT;
229 
230  // Add audioSamplingRate attribute to this element, if present.
231  bool AddAudioSamplingRateInfo(const MediaInfo::AudioInfo& audio_info)
232  WARN_UNUSED_RESULT;
233 
234  DISALLOW_COPY_AND_ASSIGN(RepresentationXmlNode);
235 };
236 
237 } // namespace xml
238 } // namespace shaka
239 #endif // MPD_BASE_XML_XML_NODE_H_
shaka::xml::RepresentationXmlNode::AddVideoInfo
bool AddVideoInfo(const MediaInfo::VideoInfo &video_info, bool set_width, bool set_height, bool set_frame_rate) WARN_UNUSED_RESULT
Definition: xml_node.cc:338
shaka::xml::RepresentationXmlNode::AddAudioInfo
bool AddAudioInfo(const MediaInfo::AudioInfo &audio_info) WARN_UNUSED_RESULT
Definition: xml_node.cc:375
shaka
All the methods that are virtual are virtual for mocking.
Definition: gflags_hex_bytes.cc:11
shaka::xml::XmlNode::SetIntegerAttribute
bool SetIntegerAttribute(const std::string &attribute_name, uint64_t number) WARN_UNUSED_RESULT
Definition: xml_node.cc:191
shaka::xml::RepresentationXmlNode
RepresentationType in MPD.
Definition: xml_node.h:182
shaka::xml::XmlNode::SetId
bool SetId(uint32_t id) WARN_UNUSED_RESULT
Definition: xml_node.cc:205
shaka::xml::XmlNode::GetAttribute
bool GetAttribute(const std::string &name, std::string *value) const
Definition: xml_node.cc:249
shaka::xml::AdaptationSetXmlNode::AddRoleElement
bool AddRoleElement(const std::string &scheme_id_uri, const std::string &value) WARN_UNUSED_RESULT
Definition: xml_node.cc:329
shaka::xml::RepresentationBaseXmlNode
Definition: xml_node.h:125
shaka::xml::RepresentationXmlNode::AddVODOnlyInfo
bool AddVODOnlyInfo(const MediaInfo &media_info, bool use_segment_list, double target_segment_duration) WARN_UNUSED_RESULT
Definition: xml_node.cc:380
shaka::xml::RepresentationBaseXmlNode::AddDescriptor
bool AddDescriptor(const std::string &descriptor_name, const std::string &scheme_id_uri, const std::string &value) WARN_UNUSED_RESULT
Definition: xml_node.cc:287
shaka::xml::XmlNode::ToString
std::string ToString(const std::string &comment) const
Definition: xml_node.cc:225
shaka::xml::XmlNode
Definition: xml_node.h:44
shaka::xml::XmlNode::AddElements
bool AddElements(const std::vector< Element > &elements) WARN_UNUSED_RESULT
Adds Elements to this node using the Element struct.
Definition: xml_node.cc:152
shaka::xml::XmlNode::SetFloatingPointAttribute
bool SetFloatingPointAttribute(const std::string &attribute_name, double number) WARN_UNUSED_RESULT
Definition: xml_node.cc:198
shaka::xml::XmlNode::SetContent
void SetContent(const std::string &content)
Definition: xml_node.cc:214
shaka::xml::XmlNode::AddChild
bool AddChild(XmlNode child) WARN_UNUSED_RESULT
Definition: xml_node.cc:141
shaka::xml::AdaptationSetXmlNode
AdaptationSetType specified in MPD.
Definition: xml_node.h:162
shaka::xml::RepresentationXmlNode::AddLiveOnlyInfo
bool AddLiveOnlyInfo(const MediaInfo &media_info, const std::list< SegmentInfo > &segment_infos, uint32_t start_number) WARN_UNUSED_RESULT
Definition: xml_node.cc:460
shaka::xml::XmlNode::SetStringAttribute
bool SetStringAttribute(const std::string &attribute_name, const std::string &attribute) WARN_UNUSED_RESULT
Definition: xml_node.cc:184
shaka::xml::RepresentationBaseXmlNode::AddSupplementalProperty
bool AddSupplementalProperty(const std::string &scheme_id_uri, const std::string &value) WARN_UNUSED_RESULT
Definition: xml_node.cc:275
shaka::xml::RepresentationBaseXmlNode::AddEssentialProperty
bool AddEssentialProperty(const std::string &scheme_id_uri, const std::string &value) WARN_UNUSED_RESULT
Definition: xml_node.cc:281
shaka::xml::AdaptationSetXmlNode::AddAccessibilityElement
bool AddAccessibilityElement(const std::string &scheme_id_uri, const std::string &value) WARN_UNUSED_RESULT
Definition: xml_node.cc:323
shaka::xml::XmlNode::ExtractReferencedNamespaces
std::set< std::string > ExtractReferencedNamespaces() const
Definition: xml_node.cc:219
shaka::xml::XmlNode::XmlNode
XmlNode(const std::string &name)
Definition: xml_node.cc:130
shaka::ContentProtectionElement
Definition: content_protection_element.h:36
shaka::xml::XmlNode::AddContent
void AddContent(const std::string &content)
Similar to SetContent, but appends to the end of existing content.
Definition: xml_node.cc:209