Shaka Packager SDK
xml_node.h
1 // Copyright 2014 Google LLC. 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 <cstdint>
14 #include <list>
15 #include <set>
16 #include <string>
17 #include <vector>
18 
19 #include <packager/macros/classes.h>
20 #include <packager/mpd/base/content_protection_element.h>
21 #include <packager/mpd/base/media_info.pb.h>
22 
23 typedef struct _xmlNode xmlNode;
24 
25 namespace shaka {
26 
27 class MpdBuilder;
28 struct SegmentInfo;
29 
30 namespace xml {
31 class XmlNode;
32 } // namespace xml
33 
34 // Defined in tests under mpd/test/xml_compare.h
35 bool XmlEqual(const std::string& xml1, const xml::XmlNode& xml2);
36 
37 namespace xml {
38 
42 class XmlNode {
43  public:
46  explicit XmlNode(const std::string& name);
47  XmlNode(XmlNode&&);
48  virtual ~XmlNode();
49 
50  XmlNode& operator=(XmlNode&&);
51 
55  [[nodiscard]] bool AddChild(XmlNode child);
56 
58  [[nodiscard]] bool AddElements(const std::vector<Element>& elements);
59 
63  [[nodiscard]] bool SetStringAttribute(const std::string& attribute_name,
64  const std::string& attribute);
65 
69  [[nodiscard]] bool SetIntegerAttribute(const std::string& attribute_name,
70  uint64_t number);
71 
75  [[nodiscard]] bool SetFloatingPointAttribute(
76  const std::string& attribute_name,
77  double number);
78 
81  [[nodiscard]] bool SetId(uint32_t id);
82 
84  void AddContent(const std::string& content);
85 
86  void AddUrlEncodedContent(const std::string& content);
87 
94  void SetContent(const std::string& content);
95 
96  void SetUrlEncodedContent(const std::string& content);
97 
99  std::set<std::string> ExtractReferencedNamespaces() const;
100 
103  std::string ToString(const std::string& comment) const;
104 
109  bool GetAttribute(const std::string& name, std::string* value) const;
110 
111  private:
112  friend bool shaka::XmlEqual(const std::string& xml1,
113  const xml::XmlNode& xml2);
114  xmlNode* GetRawPtr() const;
115 
116  // Don't use xmlNode directly so we don't have to forward-declare a bunch of
117  // libxml types to define the scoped_xml_ptr type. This allows us to only
118  // include libxml headers in a few source files.
119  class Impl;
120  std::unique_ptr<Impl> impl_;
121 
122  DISALLOW_COPY_AND_ASSIGN(XmlNode);
123 };
124 
129  public:
130  ~RepresentationBaseXmlNode() override;
131  [[nodiscard]] bool AddContentProtectionElements(
132  const std::list<ContentProtectionElement>& content_protection_elements);
133 
136  [[nodiscard]] bool AddSupplementalProperty(const std::string& scheme_id_uri,
137  const std::string& value);
138 
141  [[nodiscard]] bool AddEssentialProperty(const std::string& scheme_id_uri,
142  const std::string& value);
143 
144  protected:
145  explicit RepresentationBaseXmlNode(const std::string& name);
146 
151  [[nodiscard]] bool AddDescriptor(const std::string& descriptor_name,
152  const std::string& scheme_id_uri,
153  const std::string& value);
154 
155  private:
156  [[nodiscard]] bool AddContentProtectionElement(
157  const ContentProtectionElement& content_protection_element);
158 
159  DISALLOW_COPY_AND_ASSIGN(RepresentationBaseXmlNode);
160 };
161 
164  public:
166  ~AdaptationSetXmlNode() override;
167 
170  [[nodiscard]] bool AddAccessibilityElement(const std::string& scheme_id_uri,
171  const std::string& value);
172 
175  [[nodiscard]] bool AddRoleElement(const std::string& scheme_id_uri,
176  const std::string& value);
177 
179  [[nodiscard]] bool AddLabelElement(const std::string& value);
180 
181  private:
182  DISALLOW_COPY_AND_ASSIGN(AdaptationSetXmlNode);
183 };
184 
187  public:
189  ~RepresentationXmlNode() override;
190 
198  [[nodiscard]] bool AddVideoInfo(const MediaInfo::VideoInfo& video_info,
199  bool set_width,
200  bool set_height,
201  bool set_frame_rate);
202 
207  [[nodiscard]] bool AddAudioInfo(const MediaInfo::AudioInfo& audio_info);
208 
215  // duration of media segments. This is only used when use_segment_list
216  // is true.
218  [[nodiscard]] bool AddVODOnlyInfo(const MediaInfo& media_info,
219  bool use_segment_list,
220  double target_segment_duration);
221 
224  [[nodiscard]] bool AddLiveOnlyInfo(
225  const MediaInfo& media_info,
226  const std::list<SegmentInfo>& segment_infos,
227  bool low_latency_dash_mode);
228 
229  private:
230  // Add AudioChannelConfiguration element. Note that it is a required element
231  // for audio Representations.
232  [[nodiscard]] bool AddAudioChannelInfo(
233  const MediaInfo::AudioInfo& audio_info);
234 
235  // Add audioSamplingRate attribute to this element, if present.
236  [[nodiscard]] bool AddAudioSamplingRateInfo(
237  const MediaInfo::AudioInfo& audio_info);
238 
239  DISALLOW_COPY_AND_ASSIGN(RepresentationXmlNode);
240 };
241 
242 } // namespace xml
243 } // namespace shaka
244 #endif // MPD_BASE_XML_XML_NODE_H_
AdaptationSetType specified in MPD.
Definition: xml_node.h:163
bool AddAccessibilityElement(const std::string &scheme_id_uri, const std::string &value)
Definition: xml_node.cc:353
bool AddLabelElement(const std::string &value)
Definition: xml_node.cc:364
bool AddRoleElement(const std::string &scheme_id_uri, const std::string &value)
Definition: xml_node.cc:359
bool AddDescriptor(const std::string &descriptor_name, const std::string &scheme_id_uri, const std::string &value)
Definition: xml_node.cc:317
bool AddEssentialProperty(const std::string &scheme_id_uri, const std::string &value)
Definition: xml_node.cc:311
bool AddSupplementalProperty(const std::string &scheme_id_uri, const std::string &value)
Definition: xml_node.cc:305
RepresentationType in MPD.
Definition: xml_node.h:186
bool AddVODOnlyInfo(const MediaInfo &media_info, bool use_segment_list, double target_segment_duration)
Definition: xml_node.cc:416
bool AddLiveOnlyInfo(const MediaInfo &media_info, const std::list< SegmentInfo > &segment_infos, bool low_latency_dash_mode)
Definition: xml_node.cc:497
bool AddAudioInfo(const MediaInfo::AudioInfo &audio_info)
Definition: xml_node.cc:411
bool AddVideoInfo(const MediaInfo::VideoInfo &video_info, bool set_width, bool set_height, bool set_frame_rate)
Definition: xml_node.cc:374
bool AddChild(XmlNode child)
Definition: xml_node.cc:162
bool AddElements(const std::vector< Element > &elements)
Adds Elements to this node using the Element struct.
Definition: xml_node.cc:173
std::set< std::string > ExtractReferencedNamespaces() const
Definition: xml_node.cc:249
void AddContent(const std::string &content)
Similar to SetContent, but appends to the end of existing content.
Definition: xml_node.cc:231
bool SetStringAttribute(const std::string &attribute_name, const std::string &attribute)
Definition: xml_node.cc:205
void SetContent(const std::string &content)
Definition: xml_node.cc:240
bool SetId(uint32_t id)
Definition: xml_node.cc:227
XmlNode(const std::string &name)
Definition: xml_node.cc:151
bool SetIntegerAttribute(const std::string &attribute_name, uint64_t number)
Definition: xml_node.cc:212
bool GetAttribute(const std::string &name, std::string *value) const
Definition: xml_node.cc:279
std::string ToString(const std::string &comment) const
Definition: xml_node.cc:255
bool SetFloatingPointAttribute(const std::string &attribute_name, double number)
Definition: xml_node.cc:220
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66