Shaka Packager SDK
Loading...
Searching...
No Matches
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 <memory>
16#include <set>
17#include <string>
18#include <vector>
19
20#include <packager/macros/classes.h>
21#include <packager/mpd/base/content_protection_element.h>
22#include <packager/mpd/base/media_info.pb.h>
23
24typedef struct _xmlNode xmlNode;
25
26namespace shaka {
27
28class MpdBuilder;
29struct SegmentInfo;
30
31namespace xml {
32class XmlNode;
33} // namespace xml
34
35// Defined in tests under mpd/test/xml_compare.h
36bool XmlEqual(const std::string& xml1, const xml::XmlNode& xml2);
37
38namespace xml {
39
43class XmlNode {
44 public:
47 explicit XmlNode(const std::string& name);
49 virtual ~XmlNode();
50
51 XmlNode& operator=(XmlNode&&);
52
56 [[nodiscard]] bool AddChild(XmlNode child);
57
59 [[nodiscard]] bool AddElements(const std::vector<Element>& elements);
60
64 [[nodiscard]] bool SetStringAttribute(const std::string& attribute_name,
65 const std::string& attribute);
66
70 [[nodiscard]] bool SetIntegerAttribute(const std::string& attribute_name,
71 uint64_t number);
72
76 [[nodiscard]] bool SetFloatingPointAttribute(
77 const std::string& attribute_name,
78 double number);
79
82 [[nodiscard]] bool SetId(uint32_t id);
83
85 void AddContent(const std::string& content);
86
87 void AddUrlEncodedContent(const std::string& content);
88
95 void SetContent(const std::string& content);
96
97 void SetUrlEncodedContent(const std::string& content);
98
100 std::set<std::string> ExtractReferencedNamespaces() const;
101
104 std::string ToString(const std::string& comment) const;
105
110 bool GetAttribute(const std::string& name, std::string* value) const;
111
112 private:
113 friend bool shaka::XmlEqual(const std::string& xml1,
114 const xml::XmlNode& xml2);
115 xmlNode* GetRawPtr() const;
116
117 // Don't use xmlNode directly so we don't have to forward-declare a bunch of
118 // libxml types to define the scoped_xml_ptr type. This allows us to only
119 // include libxml headers in a few source files.
120 class Impl;
121 std::unique_ptr<Impl> impl_;
122
123 DISALLOW_COPY_AND_ASSIGN(XmlNode);
124};
125
130 public:
132 [[nodiscard]] bool AddContentProtectionElements(
133 const std::list<ContentProtectionElement>& content_protection_elements);
134
137 [[nodiscard]] bool AddSupplementalProperty(const std::string& scheme_id_uri,
138 const std::string& value);
139
142 [[nodiscard]] bool AddEssentialProperty(const std::string& scheme_id_uri,
143 const std::string& value);
144
145 protected:
146 explicit RepresentationBaseXmlNode(const std::string& name);
147
152 [[nodiscard]] bool AddDescriptor(const std::string& descriptor_name,
153 const std::string& scheme_id_uri,
154 const std::string& value);
155
156 private:
157 [[nodiscard]] bool AddContentProtectionElement(
158 const ContentProtectionElement& content_protection_element);
159
160 DISALLOW_COPY_AND_ASSIGN(RepresentationBaseXmlNode);
161};
162
165 public:
167 ~AdaptationSetXmlNode() override;
168
171 [[nodiscard]] bool AddAccessibilityElement(const std::string& scheme_id_uri,
172 const std::string& value);
173
176 [[nodiscard]] bool AddRoleElement(const std::string& scheme_id_uri,
177 const std::string& value);
178
180 [[nodiscard]] bool AddLabelElement(const std::string& value);
181
182 private:
183 DISALLOW_COPY_AND_ASSIGN(AdaptationSetXmlNode);
184};
185
188 public:
190 ~RepresentationXmlNode() override;
191
199 [[nodiscard]] bool AddVideoInfo(const MediaInfo::VideoInfo& video_info,
200 bool set_width,
201 bool set_height,
202 bool set_frame_rate);
203
208 [[nodiscard]] bool AddAudioInfo(const MediaInfo::AudioInfo& audio_info);
209
216 // duration of media segments. This is only used when use_segment_list
217 // is true.
219 [[nodiscard]] bool AddVODOnlyInfo(const MediaInfo& media_info,
220 bool use_segment_list,
221 double target_segment_duration);
222
225 [[nodiscard]] bool AddLiveOnlyInfo(
226 const MediaInfo& media_info,
227 const std::list<SegmentInfo>& segment_infos,
228 bool low_latency_dash_mode);
229
230 private:
231 // Add AudioChannelConfiguration element. Note that it is a required element
232 // for audio Representations.
233 [[nodiscard]] bool AddAudioChannelInfo(
234 const MediaInfo::AudioInfo& audio_info);
235
236 // Add audioSamplingRate attribute to this element, if present.
237 [[nodiscard]] bool AddAudioSamplingRateInfo(
238 const MediaInfo::AudioInfo& audio_info);
239
240 DISALLOW_COPY_AND_ASSIGN(RepresentationXmlNode);
241};
242
243} // namespace xml
244} // namespace shaka
245#endif // MPD_BASE_XML_XML_NODE_H_
AdaptationSetType specified in MPD.
Definition xml_node.h:164
bool AddAccessibilityElement(const std::string &scheme_id_uri, const std::string &value)
Definition xml_node.cc:359
bool AddLabelElement(const std::string &value)
Definition xml_node.cc:370
bool AddRoleElement(const std::string &scheme_id_uri, const std::string &value)
Definition xml_node.cc:365
bool AddDescriptor(const std::string &descriptor_name, const std::string &scheme_id_uri, const std::string &value)
Definition xml_node.cc:323
bool AddEssentialProperty(const std::string &scheme_id_uri, const std::string &value)
Definition xml_node.cc:317
bool AddSupplementalProperty(const std::string &scheme_id_uri, const std::string &value)
Definition xml_node.cc:311
RepresentationType in MPD.
Definition xml_node.h:187
bool AddVODOnlyInfo(const MediaInfo &media_info, bool use_segment_list, double target_segment_duration)
Definition xml_node.cc:422
bool AddLiveOnlyInfo(const MediaInfo &media_info, const std::list< SegmentInfo > &segment_infos, bool low_latency_dash_mode)
Definition xml_node.cc:494
bool AddAudioInfo(const MediaInfo::AudioInfo &audio_info)
Definition xml_node.cc:417
bool AddVideoInfo(const MediaInfo::VideoInfo &video_info, bool set_width, bool set_height, bool set_frame_rate)
Definition xml_node.cc:380
bool AddChild(XmlNode child)
Definition xml_node.cc:168
bool AddElements(const std::vector< Element > &elements)
Adds Elements to this node using the Element struct.
Definition xml_node.cc:179
std::set< std::string > ExtractReferencedNamespaces() const
Definition xml_node.cc:255
void AddContent(const std::string &content)
Similar to SetContent, but appends to the end of existing content.
Definition xml_node.cc:237
bool SetStringAttribute(const std::string &attribute_name, const std::string &attribute)
Definition xml_node.cc:211
void SetContent(const std::string &content)
Definition xml_node.cc:246
bool SetId(uint32_t id)
Definition xml_node.cc:233
bool SetIntegerAttribute(const std::string &attribute_name, uint64_t number)
Definition xml_node.cc:218
bool GetAttribute(const std::string &name, std::string *value) const
Definition xml_node.cc:285
std::string ToString(const std::string &comment) const
Definition xml_node.cc:261
bool SetFloatingPointAttribute(const std::string &attribute_name, double number)
Definition xml_node.cc:226
All the methods that are virtual are virtual for mocking.