From 15a4f0553ca206830dcf5e469a5818e02917674b Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Mon, 24 Jun 2019 18:02:19 -0700 Subject: [PATCH] Add a new utility function for XmlNode Add AddDescriptor function to add new descriptor nodes with schemeIdUri and value fields. Change-Id: I423e642939fdef99764a67da74d4efd4d32aefe8 --- packager/mpd/base/xml/xml_node.cc | 40 +++++++++++++------------------ packager/mpd/base/xml/xml_node.h | 8 +++++++ 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/packager/mpd/base/xml/xml_node.cc b/packager/mpd/base/xml/xml_node.cc index 92f7d69162..5143518366 100644 --- a/packager/mpd/base/xml/xml_node.cc +++ b/packager/mpd/base/xml/xml_node.cc @@ -237,19 +237,24 @@ bool RepresentationBaseXmlNode::AddContentProtectionElements( void RepresentationBaseXmlNode::AddSupplementalProperty( const std::string& scheme_id_uri, const std::string& value) { - XmlNode supplemental_property("SupplementalProperty"); - supplemental_property.SetStringAttribute("schemeIdUri", scheme_id_uri); - supplemental_property.SetStringAttribute("value", value); - AddChild(supplemental_property.PassScopedPtr()); + AddDescriptor("SupplementalProperty", scheme_id_uri, value); } void RepresentationBaseXmlNode::AddEssentialProperty( const std::string& scheme_id_uri, const std::string& value) { - XmlNode essential_property("EssentialProperty"); - essential_property.SetStringAttribute("schemeIdUri", scheme_id_uri); - essential_property.SetStringAttribute("value", value); - AddChild(essential_property.PassScopedPtr()); + AddDescriptor("EssentialProperty", scheme_id_uri, value); +} + +bool RepresentationBaseXmlNode::AddDescriptor( + const std::string& descriptor_name, + const std::string& scheme_id_uri, + const std::string& value) { + XmlNode descriptor(descriptor_name.c_str()); + descriptor.SetStringAttribute("schemeIdUri", scheme_id_uri); + if (!value.empty()) + descriptor.SetStringAttribute("value", value); + return AddChild(descriptor.PassScopedPtr()); } bool RepresentationBaseXmlNode::AddContentProtectionElement( @@ -289,19 +294,12 @@ AdaptationSetXmlNode::~AdaptationSetXmlNode() {} void AdaptationSetXmlNode::AddAccessibilityElement( const std::string& scheme_id_uri, const std::string& value) { - XmlNode accessibility("Accessibility"); - accessibility.SetStringAttribute("schemeIdUri", scheme_id_uri); - if (!value.empty()) - accessibility.SetStringAttribute("value", value); - AddChild(accessibility.PassScopedPtr()); + AddDescriptor("Accessibility", scheme_id_uri, value); } void AdaptationSetXmlNode::AddRoleElement(const std::string& scheme_id_uri, const std::string& value) { - XmlNode role("Role"); - role.SetStringAttribute("schemeIdUri", scheme_id_uri); - role.SetStringAttribute("value", value); - AddChild(role.PassScopedPtr()); + AddDescriptor("Role", scheme_id_uri, value); } RepresentationXmlNode::RepresentationXmlNode() @@ -461,12 +459,8 @@ bool RepresentationXmlNode::AddAudioChannelInfo(const AudioInfo& audio_info) { "urn:mpeg:dash:23003:3:audio_channel_configuration:2011"; } - XmlNode audio_channel_config("AudioChannelConfiguration"); - audio_channel_config.SetStringAttribute("schemeIdUri", - audio_channel_config_scheme); - audio_channel_config.SetStringAttribute("value", audio_channel_config_value); - - return AddChild(audio_channel_config.PassScopedPtr()); + return AddDescriptor("AudioChannelConfiguration", audio_channel_config_scheme, + audio_channel_config_value); } // MPD expects one number for sampling frequency, or if it is a range it should diff --git a/packager/mpd/base/xml/xml_node.h b/packager/mpd/base/xml/xml_node.h index 364622f7ea..976730d4d3 100644 --- a/packager/mpd/base/xml/xml_node.h +++ b/packager/mpd/base/xml/xml_node.h @@ -117,6 +117,14 @@ class RepresentationBaseXmlNode : public XmlNode { protected: explicit RepresentationBaseXmlNode(const char* name); + /// Add a Descriptor. + /// @param descriptor_name is the name of the descriptor. + /// @param scheme_id_uri is content of the schemeIdUri attribute. + /// @param value is the content of value attribute. + bool AddDescriptor(const std::string& descriptor_name, + const std::string& scheme_id_uri, + const std::string& value); + private: bool AddContentProtectionElement( const ContentProtectionElement& content_protection_element);