From ae3da3772e96904b788d27567932f0828188b196 Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Fri, 16 Nov 2018 16:44:44 -0800 Subject: [PATCH] Use lower-case for Marlin ContentId This is required by Marlin specification. Also added unittests. Issue #381. Change-Id: Icae1213db4c0915720ed07e6b2bb768fa9156a5c --- packager/mpd/base/mpd_utils.cc | 3 +- packager/mpd/base/mpd_utils_unittest.cc | 119 ++++++++++++++++++++++++ packager/mpd/mpd.gyp | 1 + 3 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 packager/mpd/base/mpd_utils_unittest.cc diff --git a/packager/mpd/base/mpd_utils.cc b/packager/mpd/base/mpd_utils.cc index f00d85cc83..9c173413c1 100644 --- a/packager/mpd/base/mpd_utils.cc +++ b/packager/mpd/base/mpd_utils.cc @@ -319,7 +319,8 @@ Element GenerateMarlinContentIds(const std::string& key_id) { Element marlin_content_id; marlin_content_id.name = kMarlinContentIdName; marlin_content_id.content = - kMarlinContentIdPrefix + base::HexEncode(key_id.data(), key_id.size()); + kMarlinContentIdPrefix + + base::ToLowerASCII(base::HexEncode(key_id.data(), key_id.size())); Element marlin_content_ids; marlin_content_ids.name = kMarlinContentIdsName; diff --git a/packager/mpd/base/mpd_utils_unittest.cc b/packager/mpd/base/mpd_utils_unittest.cc new file mode 100644 index 0000000000..b82b8f0a69 --- /dev/null +++ b/packager/mpd/base/mpd_utils_unittest.cc @@ -0,0 +1,119 @@ +// Copyright 2018 Google LLC. 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 + +#include "packager/mpd/base/mpd_utils.h" + +#include +#include + +#include "packager/mpd/base/adaptation_set.h" +#include "packager/mpd/base/mpd_options.h" +#include "packager/mpd/test/mpd_builder_test_helper.h" +#include "packager/mpd/test/xml_compare.h" + +namespace shaka { +namespace { +const char kNoLanguage[] = ""; +} // namespace + +class TestableAdaptationSet : public AdaptationSet { + public: + TestableAdaptationSet(const MpdOptions& mpd_options, + uint32_t* representation_counter) + : AdaptationSet(kNoLanguage, mpd_options, representation_counter) {} +}; + +class MpdUtilsTest : public ::testing::Test { + public: + MpdUtilsTest() : adaptation_set_(mpd_options_, &representation_counter_) {} + + protected: + MpdOptions mpd_options_; + uint32_t representation_counter_ = 0; + TestableAdaptationSet adaptation_set_; +}; + +TEST_F(MpdUtilsTest, ContentProtectionGeneral) { + const char kMediaInfoWithContentProtection[] = + "video_info {" + " codec: 'avc1'" + " width: 1920" + " height: 1080" + " time_scale: 3000" + " frame_duration: 100" + "}" + "protected_content {" + " default_key_id: '0123456789\x3A\x3B\x3C\x3D\x3E\x3F'" + " content_protection_entry {" + " uuid: 'my_uuid'" + " pssh: 'my_pssh'" + " }" + "}" + "container_type: 1"; + const MediaInfo media_info = + ConvertToMediaInfo(kMediaInfoWithContentProtection); + + AddContentProtectionElements(media_info, &adaptation_set_); + ASSERT_TRUE(adaptation_set_.AddRepresentation(media_info)); + + const char kExpectedOutput[] = + "" + " " + " " + " bXlfcHNzaA==" + " " + " " + ""; + EXPECT_THAT(adaptation_set_.GetXml().get(), XmlNodeEqual(kExpectedOutput)); +} + +TEST_F(MpdUtilsTest, ContentProtectionMarlin) { + const char kMediaInfoWithContentProtection[] = + "video_info {" + " codec: 'avc1'" + " width: 1920" + " height: 1080" + " time_scale: 3000" + " frame_duration: 100" + "}" + "protected_content {" + " default_key_id: '0123456789\x3A\x3B\x3C\x3D\x3E\x3F'" + " content_protection_entry {" + " uuid: '5e629af5-38da-4063-8977-97ffbd9902d4'" + " }" + "}" + "container_type: 1"; + const MediaInfo media_info = + ConvertToMediaInfo(kMediaInfoWithContentProtection); + + AddContentProtectionElements(media_info, &adaptation_set_); + ASSERT_TRUE(adaptation_set_.AddRepresentation(media_info)); + + const char kExpectedOutput[] = + "" + " " + " " + " " + " " + " urn:marlin:kid:303132333435363738393a3b3c3d3e3f" + " " + " " + " " + " " + ""; + EXPECT_THAT(adaptation_set_.GetXml().get(), XmlNodeEqual(kExpectedOutput)); +} + +} // namespace shaka diff --git a/packager/mpd/mpd.gyp b/packager/mpd/mpd.gyp index d3d95834b3..4951563c53 100644 --- a/packager/mpd/mpd.gyp +++ b/packager/mpd/mpd.gyp @@ -100,6 +100,7 @@ 'base/adaptation_set_unittest.cc', 'base/bandwidth_estimator_unittest.cc', 'base/mpd_builder_unittest.cc', + 'base/mpd_utils_unittest.cc', 'base/period_unittest.cc', 'base/representation_unittest.cc', 'base/simple_mpd_notifier_unittest.cc',