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/mpd_utils.h"
|
2013-11-18 23:39:20 +00:00
|
|
|
|
2014-08-28 18:35:15 +00:00
|
|
|
#include <libxml/tree.h>
|
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/base/logging.h"
|
|
|
|
#include "packager/base/strings/string_number_conversions.h"
|
|
|
|
#include "packager/mpd/base/content_protection_element.h"
|
|
|
|
#include "packager/mpd/base/media_info.pb.h"
|
|
|
|
#include "packager/mpd/base/xml/scoped_xml_ptr.h"
|
2013-11-18 23:39:20 +00:00
|
|
|
|
2014-09-19 20:41:13 +00:00
|
|
|
namespace edash_packager {
|
2013-11-18 23:39:20 +00:00
|
|
|
|
|
|
|
bool HasVODOnlyFields(const MediaInfo& media_info) {
|
|
|
|
return media_info.has_init_range() || media_info.has_index_range() ||
|
2013-12-17 23:08:14 +00:00
|
|
|
media_info.has_media_file_name() ||
|
|
|
|
media_info.has_media_duration_seconds();
|
2013-11-18 23:39:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HasLiveOnlyFields(const MediaInfo& media_info) {
|
|
|
|
return media_info.has_init_segment_name() ||
|
2013-12-17 23:08:14 +00:00
|
|
|
media_info.has_segment_template() ||
|
|
|
|
media_info.has_segment_duration_seconds();
|
2013-11-18 23:39:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveDuplicateAttributes(
|
|
|
|
ContentProtectionElement* content_protection_element) {
|
|
|
|
DCHECK(content_protection_element);
|
|
|
|
typedef std::map<std::string, std::string> AttributesMap;
|
|
|
|
|
|
|
|
AttributesMap& attributes = content_protection_element->additional_attributes;
|
|
|
|
if (!content_protection_element->value.empty())
|
|
|
|
attributes.erase("value");
|
|
|
|
|
|
|
|
if (!content_protection_element->scheme_id_uri.empty())
|
|
|
|
attributes.erase("schemeIdUri");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GetCodecs(const MediaInfo& media_info) {
|
2015-06-09 23:58:32 +00:00
|
|
|
std::string video_codec;
|
|
|
|
if (media_info.has_video_info())
|
|
|
|
video_codec = media_info.video_info().codec();
|
|
|
|
|
|
|
|
std::string audio_codec;
|
|
|
|
if (media_info.has_audio_info())
|
|
|
|
audio_codec = media_info.audio_info().codec();
|
|
|
|
|
|
|
|
if (!video_codec.empty() && !audio_codec.empty()) {
|
|
|
|
return video_codec + "," + audio_codec;
|
|
|
|
} else if (!video_codec.empty()) {
|
|
|
|
return video_codec;
|
|
|
|
} else if (!audio_codec.empty()) {
|
|
|
|
return audio_codec;
|
2013-11-18 23:39:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2014-05-22 02:16:17 +00:00
|
|
|
std::string SecondsToXmlDuration(double seconds) {
|
2014-01-03 00:59:16 +00:00
|
|
|
return "PT" + base::DoubleToString(seconds) + "S";
|
2013-11-18 23:39:20 +00:00
|
|
|
}
|
|
|
|
|
2014-01-03 00:59:16 +00:00
|
|
|
bool GetDurationAttribute(xmlNodePtr node, float* duration) {
|
2013-11-18 23:39:20 +00:00
|
|
|
DCHECK(node);
|
|
|
|
DCHECK(duration);
|
|
|
|
static const char kDuration[] = "duration";
|
|
|
|
xml::ScopedXmlPtr<xmlChar>::type duration_value(
|
|
|
|
xmlGetProp(node, BAD_CAST kDuration));
|
|
|
|
|
|
|
|
if (!duration_value)
|
|
|
|
return false;
|
|
|
|
|
2014-01-03 00:59:16 +00:00
|
|
|
double duration_double_precision = 0.0;
|
|
|
|
if (!base::StringToDouble(reinterpret_cast<const char*>(duration_value.get()),
|
|
|
|
&duration_double_precision)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
*duration = static_cast<float>(duration_double_precision);
|
|
|
|
return true;
|
2013-11-18 23:39:20 +00:00
|
|
|
}
|
|
|
|
|
2014-06-06 08:52:06 +00:00
|
|
|
bool MoreThanOneTrue(bool b1, bool b2, bool b3) {
|
|
|
|
return (b1 && b2) || (b2 && b3) || (b3 && b1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AtLeastOneTrue(bool b1, bool b2, bool b3) { return b1 || b2 || b3; }
|
|
|
|
|
|
|
|
bool OnlyOneTrue(bool b1, bool b2, bool b3) {
|
|
|
|
return !MoreThanOneTrue(b1, b2, b3) && AtLeastOneTrue(b1, b2, b3);
|
|
|
|
}
|
|
|
|
|
2014-09-19 20:41:13 +00:00
|
|
|
} // namespace edash_packager
|