2014-02-14 23:21:05 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/mpd/base/xml/xml_node.h"
|
2013-11-18 21:01:48 +00:00
|
|
|
|
2017-09-25 19:18:50 +00:00
|
|
|
#include <gflags/gflags.h>
|
|
|
|
|
2014-09-30 23:52:58 +00:00
|
|
|
#include <limits>
|
2013-11-18 21:01:48 +00:00
|
|
|
#include <set>
|
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/base/logging.h"
|
2014-10-07 21:41:40 +00:00
|
|
|
#include "packager/base/macros.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/base/strings/string_number_conversions.h"
|
2016-08-17 17:41:40 +00:00
|
|
|
#include "packager/base/sys_byteorder.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/mpd/base/media_info.pb.h"
|
2016-09-29 22:02:21 +00:00
|
|
|
#include "packager/mpd/base/mpd_utils.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/mpd/base/segment_info.h"
|
2013-11-18 21:01:48 +00:00
|
|
|
|
2017-09-25 19:18:50 +00:00
|
|
|
DEFINE_bool(segment_template_constant_duration,
|
|
|
|
false,
|
|
|
|
"Generates SegmentTemplate@duration if all segments except the "
|
|
|
|
"last one has the same duration if this flag is set to true.");
|
|
|
|
|
2020-02-25 07:12:53 +00:00
|
|
|
DEFINE_bool(dash_add_last_segment_number_when_needed,
|
|
|
|
false,
|
|
|
|
"Adds a Supplemental Descriptor with @schemeIdUri "
|
|
|
|
"set to http://dashif.org/guidelines/last-segment-number with "
|
|
|
|
"the @value set to the last segment number.");
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2014-05-22 02:16:17 +00:00
|
|
|
|
2016-05-19 21:38:15 +00:00
|
|
|
using xml::XmlNode;
|
|
|
|
typedef MediaInfo::AudioInfo AudioInfo;
|
|
|
|
typedef MediaInfo::VideoInfo VideoInfo;
|
|
|
|
|
2013-11-18 21:01:48 +00:00
|
|
|
namespace {
|
2016-02-09 00:22:01 +00:00
|
|
|
const char kEC3Codec[] = "ec-3";
|
2013-11-18 21:01:48 +00:00
|
|
|
|
2014-09-19 20:41:13 +00:00
|
|
|
std::string RangeToString(const Range& range) {
|
2013-11-18 21:01:48 +00:00
|
|
|
return base::Uint64ToString(range.begin()) + "-" +
|
|
|
|
base::Uint64ToString(range.end());
|
|
|
|
}
|
|
|
|
|
2017-09-25 19:18:50 +00:00
|
|
|
// Check if segments are continuous and all segments except the last one are of
|
|
|
|
// the same duration.
|
|
|
|
bool IsTimelineConstantDuration(const std::list<SegmentInfo>& segment_infos,
|
|
|
|
uint32_t start_number) {
|
|
|
|
if (!FLAGS_segment_template_constant_duration)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
DCHECK(!segment_infos.empty());
|
|
|
|
if (segment_infos.size() > 2)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const SegmentInfo& first_segment = segment_infos.front();
|
|
|
|
if (first_segment.start_time != first_segment.duration * (start_number - 1))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (segment_infos.size() == 1)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
const SegmentInfo& last_segment = segment_infos.back();
|
|
|
|
if (last_segment.repeat != 0)
|
|
|
|
return false;
|
|
|
|
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t expected_last_segment_start_time =
|
2017-09-25 19:18:50 +00:00
|
|
|
first_segment.start_time +
|
|
|
|
first_segment.duration * (first_segment.repeat + 1);
|
|
|
|
return expected_last_segment_start_time == last_segment.start_time;
|
|
|
|
}
|
|
|
|
|
2014-05-22 02:16:17 +00:00
|
|
|
bool PopulateSegmentTimeline(const std::list<SegmentInfo>& segment_infos,
|
|
|
|
XmlNode* segment_timeline) {
|
2017-09-25 19:18:50 +00:00
|
|
|
for (const SegmentInfo& segment_info : segment_infos) {
|
2014-10-03 05:17:54 +00:00
|
|
|
XmlNode s_element("S");
|
2017-09-25 19:18:50 +00:00
|
|
|
s_element.SetIntegerAttribute("t", segment_info.start_time);
|
|
|
|
s_element.SetIntegerAttribute("d", segment_info.duration);
|
|
|
|
if (segment_info.repeat > 0)
|
|
|
|
s_element.SetIntegerAttribute("r", segment_info.repeat);
|
2014-05-22 02:16:17 +00:00
|
|
|
|
2014-10-03 05:17:54 +00:00
|
|
|
CHECK(segment_timeline->AddChild(s_element.PassScopedPtr()));
|
2014-05-22 02:16:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-18 19:05:11 +00:00
|
|
|
void CollectNamespaceFromName(const std::string& name,
|
|
|
|
std::set<std::string>* namespaces) {
|
|
|
|
const size_t pos = name.find(':');
|
|
|
|
if (pos != std::string::npos)
|
|
|
|
namespaces->insert(name.substr(0, pos));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TraverseAttrsAndCollectNamespaces(const xmlAttr* attr,
|
|
|
|
std::set<std::string>* namespaces) {
|
|
|
|
for (const xmlAttr* cur_attr = attr; cur_attr; cur_attr = cur_attr->next) {
|
|
|
|
CollectNamespaceFromName(reinterpret_cast<const char*>(cur_attr->name),
|
|
|
|
namespaces);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TraverseNodesAndCollectNamespaces(const xmlNode* node,
|
|
|
|
std::set<std::string>* namespaces) {
|
|
|
|
for (const xmlNode* cur_node = node; cur_node; cur_node = cur_node->next) {
|
|
|
|
CollectNamespaceFromName(reinterpret_cast<const char*>(cur_node->name),
|
|
|
|
namespaces);
|
|
|
|
|
|
|
|
TraverseNodesAndCollectNamespaces(cur_node->children, namespaces);
|
|
|
|
TraverseAttrsAndCollectNamespaces(cur_node->properties, namespaces);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-18 21:01:48 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace xml {
|
|
|
|
|
|
|
|
XmlNode::XmlNode(const char* name) : node_(xmlNewNode(NULL, BAD_CAST name)) {
|
|
|
|
DCHECK(name);
|
|
|
|
DCHECK(node_);
|
|
|
|
}
|
|
|
|
|
|
|
|
XmlNode::~XmlNode() {}
|
|
|
|
|
2015-11-17 00:06:17 +00:00
|
|
|
bool XmlNode::AddChild(scoped_xml_ptr<xmlNode> child) {
|
2013-11-18 21:01:48 +00:00
|
|
|
DCHECK(node_);
|
|
|
|
DCHECK(child);
|
|
|
|
if (!xmlAddChild(node_.get(), child.get()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Reaching here means the ownership of |child| transfered to |node_|.
|
|
|
|
// Release the pointer so that it doesn't get destructed in this scope.
|
2014-03-21 17:26:49 +00:00
|
|
|
ignore_result(child.release());
|
2013-11-18 21:01:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-15 21:57:47 +00:00
|
|
|
bool XmlNode::AddElements(const std::vector<Element>& elements) {
|
|
|
|
for (size_t element_index = 0; element_index < elements.size();
|
|
|
|
++element_index) {
|
|
|
|
const Element& child_element = elements[element_index];
|
|
|
|
XmlNode child_node(child_element.name.c_str());
|
|
|
|
for (std::map<std::string, std::string>::const_iterator attribute_it =
|
|
|
|
child_element.attributes.begin();
|
|
|
|
attribute_it != child_element.attributes.end(); ++attribute_it) {
|
|
|
|
child_node.SetStringAttribute(attribute_it->first.c_str(),
|
|
|
|
attribute_it->second);
|
|
|
|
}
|
2018-09-18 00:27:02 +00:00
|
|
|
|
|
|
|
// Note that somehow |SetContent| needs to be called before |AddElements|
|
|
|
|
// otherwise the added children will be overwritten by the content.
|
|
|
|
child_node.SetContent(child_element.content);
|
|
|
|
|
2015-07-15 21:57:47 +00:00
|
|
|
// Recursively set children for the child.
|
|
|
|
if (!child_node.AddElements(child_element.subelements))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!xmlAddChild(node_.get(), child_node.GetRawPtr())) {
|
|
|
|
LOG(ERROR) << "Failed to set child " << child_element.name
|
|
|
|
<< " to parent element "
|
|
|
|
<< reinterpret_cast<const char*>(node_->name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Reaching here means the ownership of |child_node| transfered to |node_|.
|
|
|
|
// Release the pointer so that it doesn't get destructed in this scope.
|
|
|
|
ignore_result(child_node.Release());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-18 21:01:48 +00:00
|
|
|
void XmlNode::SetStringAttribute(const char* attribute_name,
|
|
|
|
const std::string& attribute) {
|
|
|
|
DCHECK(node_);
|
|
|
|
DCHECK(attribute_name);
|
2014-05-22 02:16:17 +00:00
|
|
|
xmlSetProp(node_.get(), BAD_CAST attribute_name, BAD_CAST attribute.c_str());
|
2013-11-18 21:01:48 +00:00
|
|
|
}
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
void XmlNode::SetIntegerAttribute(const char* attribute_name, uint64_t number) {
|
2013-11-18 21:01:48 +00:00
|
|
|
DCHECK(node_);
|
|
|
|
DCHECK(attribute_name);
|
2014-05-22 02:16:17 +00:00
|
|
|
xmlSetProp(node_.get(),
|
2013-11-18 21:01:48 +00:00
|
|
|
BAD_CAST attribute_name,
|
|
|
|
BAD_CAST (base::Uint64ToString(number).c_str()));
|
|
|
|
}
|
|
|
|
|
2013-12-17 23:08:14 +00:00
|
|
|
void XmlNode::SetFloatingPointAttribute(const char* attribute_name,
|
|
|
|
double number) {
|
|
|
|
DCHECK(node_);
|
|
|
|
DCHECK(attribute_name);
|
2016-09-29 22:02:21 +00:00
|
|
|
xmlSetProp(node_.get(), BAD_CAST attribute_name,
|
2018-04-02 23:53:29 +00:00
|
|
|
BAD_CAST(base::DoubleToString(number).c_str()));
|
2013-12-17 23:08:14 +00:00
|
|
|
}
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
void XmlNode::SetId(uint32_t id) {
|
2013-12-17 23:08:14 +00:00
|
|
|
SetIntegerAttribute("id", id);
|
2013-11-18 21:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void XmlNode::SetContent(const std::string& content) {
|
|
|
|
DCHECK(node_);
|
|
|
|
xmlNodeSetContent(node_.get(), BAD_CAST content.c_str());
|
|
|
|
}
|
|
|
|
|
2018-09-18 19:05:11 +00:00
|
|
|
std::set<std::string> XmlNode::ExtractReferencedNamespaces() {
|
|
|
|
std::set<std::string> namespaces;
|
|
|
|
TraverseNodesAndCollectNamespaces(node_.get(), &namespaces);
|
|
|
|
return namespaces;
|
|
|
|
}
|
|
|
|
|
2015-11-17 00:06:17 +00:00
|
|
|
scoped_xml_ptr<xmlNode> XmlNode::PassScopedPtr() {
|
2015-01-27 22:35:01 +00:00
|
|
|
DVLOG(2) << "Passing node_.";
|
2013-11-18 21:01:48 +00:00
|
|
|
DCHECK(node_);
|
2016-08-17 17:41:40 +00:00
|
|
|
return std::move(node_);
|
2013-11-18 21:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
xmlNodePtr XmlNode::Release() {
|
2015-01-27 22:35:01 +00:00
|
|
|
DVLOG(2) << "Releasing node_.";
|
2013-11-18 21:01:48 +00:00
|
|
|
DCHECK(node_);
|
|
|
|
return node_.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
xmlNodePtr XmlNode::GetRawPtr() {
|
|
|
|
return node_.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
RepresentationBaseXmlNode::RepresentationBaseXmlNode(const char* name)
|
|
|
|
: XmlNode(name) {}
|
|
|
|
RepresentationBaseXmlNode::~RepresentationBaseXmlNode() {}
|
|
|
|
|
|
|
|
bool RepresentationBaseXmlNode::AddContentProtectionElements(
|
|
|
|
const std::list<ContentProtectionElement>& content_protection_elements) {
|
|
|
|
std::list<ContentProtectionElement>::const_iterator content_protection_it =
|
|
|
|
content_protection_elements.begin();
|
|
|
|
for (; content_protection_it != content_protection_elements.end();
|
|
|
|
++content_protection_it) {
|
|
|
|
if (!AddContentProtectionElement(*content_protection_it))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-12-13 23:48:54 +00:00
|
|
|
void RepresentationBaseXmlNode::AddSupplementalProperty(
|
|
|
|
const std::string& scheme_id_uri,
|
|
|
|
const std::string& value) {
|
2019-06-25 01:02:19 +00:00
|
|
|
AddDescriptor("SupplementalProperty", scheme_id_uri, value);
|
2016-12-13 23:48:54 +00:00
|
|
|
}
|
|
|
|
|
2017-03-21 23:14:46 +00:00
|
|
|
void RepresentationBaseXmlNode::AddEssentialProperty(
|
|
|
|
const std::string& scheme_id_uri,
|
|
|
|
const std::string& value) {
|
2019-06-25 01:02:19 +00:00
|
|
|
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());
|
2017-03-21 23:14:46 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 21:01:48 +00:00
|
|
|
bool RepresentationBaseXmlNode::AddContentProtectionElement(
|
|
|
|
const ContentProtectionElement& content_protection_element) {
|
|
|
|
XmlNode content_protection_node("ContentProtection");
|
|
|
|
|
2015-07-15 21:57:47 +00:00
|
|
|
// @value is an optional attribute.
|
|
|
|
if (!content_protection_element.value.empty()) {
|
|
|
|
content_protection_node.SetStringAttribute(
|
|
|
|
"value", content_protection_element.value);
|
|
|
|
}
|
2013-11-18 21:01:48 +00:00
|
|
|
content_protection_node.SetStringAttribute(
|
|
|
|
"schemeIdUri", content_protection_element.scheme_id_uri);
|
|
|
|
|
|
|
|
typedef std::map<std::string, std::string> AttributesMapType;
|
|
|
|
const AttributesMapType& additional_attributes =
|
|
|
|
content_protection_element.additional_attributes;
|
|
|
|
|
|
|
|
AttributesMapType::const_iterator attributes_it =
|
|
|
|
additional_attributes.begin();
|
|
|
|
for (; attributes_it != additional_attributes.end(); ++attributes_it) {
|
|
|
|
content_protection_node.SetStringAttribute(attributes_it->first.c_str(),
|
|
|
|
attributes_it->second);
|
|
|
|
}
|
|
|
|
|
2015-07-15 21:57:47 +00:00
|
|
|
if (!content_protection_node.AddElements(
|
|
|
|
content_protection_element.subelements)) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-11-18 21:01:48 +00:00
|
|
|
return AddChild(content_protection_node.PassScopedPtr());
|
|
|
|
}
|
|
|
|
|
|
|
|
AdaptationSetXmlNode::AdaptationSetXmlNode()
|
|
|
|
: RepresentationBaseXmlNode("AdaptationSet") {}
|
|
|
|
AdaptationSetXmlNode::~AdaptationSetXmlNode() {}
|
|
|
|
|
2019-06-13 06:01:16 +00:00
|
|
|
void AdaptationSetXmlNode::AddAccessibilityElement(
|
|
|
|
const std::string& scheme_id_uri,
|
|
|
|
const std::string& value) {
|
2019-06-25 01:02:19 +00:00
|
|
|
AddDescriptor("Accessibility", scheme_id_uri, value);
|
2019-06-13 06:01:16 +00:00
|
|
|
}
|
|
|
|
|
2015-06-26 23:00:41 +00:00
|
|
|
void AdaptationSetXmlNode::AddRoleElement(const std::string& scheme_id_uri,
|
|
|
|
const std::string& value) {
|
2019-06-25 01:02:19 +00:00
|
|
|
AddDescriptor("Role", scheme_id_uri, value);
|
2015-06-26 23:00:41 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 21:01:48 +00:00
|
|
|
RepresentationXmlNode::RepresentationXmlNode()
|
|
|
|
: RepresentationBaseXmlNode("Representation") {}
|
|
|
|
RepresentationXmlNode::~RepresentationXmlNode() {}
|
|
|
|
|
2016-01-05 00:33:53 +00:00
|
|
|
bool RepresentationXmlNode::AddVideoInfo(const VideoInfo& video_info,
|
|
|
|
bool set_width,
|
|
|
|
bool set_height,
|
|
|
|
bool set_frame_rate) {
|
2015-06-09 23:58:32 +00:00
|
|
|
if (!video_info.has_width() || !video_info.has_height()) {
|
|
|
|
LOG(ERROR) << "Missing width or height for adding a video info.";
|
|
|
|
return false;
|
2013-11-18 21:01:48 +00:00
|
|
|
}
|
|
|
|
|
2015-06-30 00:21:05 +00:00
|
|
|
if (video_info.has_pixel_width() && video_info.has_pixel_height()) {
|
|
|
|
SetStringAttribute("sar", base::IntToString(video_info.pixel_width()) +
|
|
|
|
":" +
|
|
|
|
base::IntToString(video_info.pixel_height()));
|
|
|
|
}
|
|
|
|
|
2016-01-05 00:33:53 +00:00
|
|
|
if (set_width)
|
|
|
|
SetIntegerAttribute("width", video_info.width());
|
|
|
|
if (set_height)
|
|
|
|
SetIntegerAttribute("height", video_info.height());
|
|
|
|
if (set_frame_rate) {
|
|
|
|
SetStringAttribute("frameRate",
|
|
|
|
base::IntToString(video_info.time_scale()) + "/" +
|
|
|
|
base::IntToString(video_info.frame_duration()));
|
|
|
|
}
|
2017-03-21 23:14:46 +00:00
|
|
|
|
|
|
|
if (video_info.has_playback_rate()) {
|
|
|
|
SetStringAttribute("maxPlayoutRate",
|
|
|
|
base::IntToString(video_info.playback_rate()));
|
|
|
|
// Since the trick play stream contains only key frames, there is no coding
|
|
|
|
// dependency on the main stream. Simply set the codingDependency to false.
|
|
|
|
// TODO(hmchen): propagate this attribute up to the AdaptationSet, since
|
|
|
|
// all are set to false.
|
|
|
|
SetStringAttribute("codingDependency", "false");
|
|
|
|
}
|
2013-11-18 21:01:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-09 23:58:32 +00:00
|
|
|
bool RepresentationXmlNode::AddAudioInfo(const AudioInfo& audio_info) {
|
|
|
|
if (!AddAudioChannelInfo(audio_info))
|
2013-11-18 21:01:48 +00:00
|
|
|
return false;
|
|
|
|
|
2015-06-09 23:58:32 +00:00
|
|
|
AddAudioSamplingRateInfo(audio_info);
|
2013-11-18 21:01:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RepresentationXmlNode::AddVODOnlyInfo(const MediaInfo& media_info) {
|
2018-04-17 17:42:45 +00:00
|
|
|
if (media_info.has_media_file_url()) {
|
2014-01-29 00:03:19 +00:00
|
|
|
XmlNode base_url("BaseURL");
|
2018-04-17 17:42:45 +00:00
|
|
|
base_url.SetContent(media_info.media_file_url());
|
2014-01-29 00:03:19 +00:00
|
|
|
|
|
|
|
if (!AddChild(base_url.PassScopedPtr()))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-18 21:01:48 +00:00
|
|
|
const bool need_segment_base = media_info.has_index_range() ||
|
2013-12-17 23:08:14 +00:00
|
|
|
media_info.has_init_range() ||
|
|
|
|
media_info.has_reference_time_scale();
|
2013-11-18 21:01:48 +00:00
|
|
|
|
|
|
|
if (need_segment_base) {
|
|
|
|
XmlNode segment_base("SegmentBase");
|
|
|
|
if (media_info.has_index_range()) {
|
|
|
|
segment_base.SetStringAttribute("indexRange",
|
|
|
|
RangeToString(media_info.index_range()));
|
|
|
|
}
|
|
|
|
|
2013-12-17 23:08:14 +00:00
|
|
|
if (media_info.has_reference_time_scale()) {
|
|
|
|
segment_base.SetIntegerAttribute("timescale",
|
|
|
|
media_info.reference_time_scale());
|
|
|
|
}
|
2013-11-18 21:01:48 +00:00
|
|
|
|
2018-01-03 00:10:54 +00:00
|
|
|
if (media_info.has_presentation_time_offset()) {
|
|
|
|
segment_base.SetIntegerAttribute("presentationTimeOffset",
|
|
|
|
media_info.presentation_time_offset());
|
|
|
|
}
|
|
|
|
|
2013-11-18 21:01:48 +00:00
|
|
|
if (media_info.has_init_range()) {
|
|
|
|
XmlNode initialization("Initialization");
|
|
|
|
initialization.SetStringAttribute("range",
|
|
|
|
RangeToString(media_info.init_range()));
|
|
|
|
|
|
|
|
if (!segment_base.AddChild(initialization.PassScopedPtr()))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!AddChild(segment_base.PassScopedPtr()))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-22 02:16:17 +00:00
|
|
|
bool RepresentationXmlNode::AddLiveOnlyInfo(
|
|
|
|
const MediaInfo& media_info,
|
2014-05-27 22:21:42 +00:00
|
|
|
const std::list<SegmentInfo>& segment_infos,
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t start_number) {
|
2014-05-22 02:16:17 +00:00
|
|
|
XmlNode segment_template("SegmentTemplate");
|
|
|
|
if (media_info.has_reference_time_scale()) {
|
|
|
|
segment_template.SetIntegerAttribute("timescale",
|
|
|
|
media_info.reference_time_scale());
|
|
|
|
}
|
|
|
|
|
2018-01-03 00:10:54 +00:00
|
|
|
if (media_info.has_presentation_time_offset()) {
|
|
|
|
segment_template.SetIntegerAttribute("presentationTimeOffset",
|
|
|
|
media_info.presentation_time_offset());
|
|
|
|
}
|
|
|
|
|
2018-04-17 17:42:45 +00:00
|
|
|
if (media_info.has_init_segment_url()) {
|
2014-05-22 02:16:17 +00:00
|
|
|
segment_template.SetStringAttribute("initialization",
|
2018-04-17 17:42:45 +00:00
|
|
|
media_info.init_segment_url());
|
2014-05-22 02:16:17 +00:00
|
|
|
}
|
|
|
|
|
2018-04-17 17:42:45 +00:00
|
|
|
if (media_info.has_segment_template_url()) {
|
|
|
|
segment_template.SetStringAttribute("media",
|
|
|
|
media_info.segment_template_url());
|
2018-03-17 01:47:25 +00:00
|
|
|
segment_template.SetIntegerAttribute("startNumber", start_number);
|
2014-05-27 22:21:42 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 19:18:50 +00:00
|
|
|
if (!segment_infos.empty()) {
|
|
|
|
// Don't use SegmentTimeline if all segments except the last one are of
|
|
|
|
// the same duration.
|
|
|
|
if (IsTimelineConstantDuration(segment_infos, start_number)) {
|
|
|
|
segment_template.SetIntegerAttribute("duration",
|
|
|
|
segment_infos.front().duration);
|
2020-02-25 07:12:53 +00:00
|
|
|
if (FLAGS_dash_add_last_segment_number_when_needed) {
|
|
|
|
uint32_t last_segment_number = start_number - 1;
|
|
|
|
for (const auto& segment_info_element : segment_infos)
|
|
|
|
last_segment_number += segment_info_element.repeat + 1;
|
|
|
|
|
|
|
|
AddSupplementalProperty(
|
|
|
|
"http://dashif.org/guidelines/last-segment-number",
|
|
|
|
std::to_string(last_segment_number));
|
|
|
|
}
|
2017-09-25 19:18:50 +00:00
|
|
|
} else {
|
|
|
|
XmlNode segment_timeline("SegmentTimeline");
|
|
|
|
if (!PopulateSegmentTimeline(segment_infos, &segment_timeline) ||
|
|
|
|
!segment_template.AddChild(segment_timeline.PassScopedPtr())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return AddChild(segment_template.PassScopedPtr());
|
2014-05-22 02:16:17 +00:00
|
|
|
}
|
|
|
|
|
2015-06-09 23:58:32 +00:00
|
|
|
bool RepresentationXmlNode::AddAudioChannelInfo(const AudioInfo& audio_info) {
|
2016-02-09 00:22:01 +00:00
|
|
|
std::string audio_channel_config_scheme;
|
|
|
|
std::string audio_channel_config_value;
|
|
|
|
|
|
|
|
if (audio_info.codec() == kEC3Codec) {
|
|
|
|
// Convert EC3 channel map into string of hexadecimal digits. Spec: DASH-IF
|
|
|
|
// Interoperability Points v3.0 9.2.1.2.
|
|
|
|
const uint16_t ec3_channel_map =
|
|
|
|
base::HostToNet16(audio_info.codec_specific_data().ec3_channel_map());
|
|
|
|
audio_channel_config_value =
|
|
|
|
base::HexEncode(&ec3_channel_map, sizeof(ec3_channel_map));
|
|
|
|
audio_channel_config_scheme =
|
|
|
|
"tag:dolby.com,2014:dash:audio_channel_configuration:2011";
|
|
|
|
} else {
|
|
|
|
audio_channel_config_value = base::UintToString(audio_info.num_channels());
|
|
|
|
audio_channel_config_scheme =
|
|
|
|
"urn:mpeg:dash:23003:3:audio_channel_configuration:2011";
|
|
|
|
}
|
|
|
|
|
2019-06-25 01:02:19 +00:00
|
|
|
return AddDescriptor("AudioChannelConfiguration", audio_channel_config_scheme,
|
|
|
|
audio_channel_config_value);
|
2013-11-18 21:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MPD expects one number for sampling frequency, or if it is a range it should
|
|
|
|
// be space separated.
|
|
|
|
void RepresentationXmlNode::AddAudioSamplingRateInfo(
|
2015-06-09 23:58:32 +00:00
|
|
|
const AudioInfo& audio_info) {
|
|
|
|
if (audio_info.has_sampling_frequency())
|
|
|
|
SetIntegerAttribute("audioSamplingRate", audio_info.sampling_frequency());
|
2013-11-18 21:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace xml
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|