2015-07-16 06:51:24 +00:00
|
|
|
// Copyright 2015 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
|
|
|
|
|
2018-01-18 01:26:03 +00:00
|
|
|
#include <gflags/gflags.h>
|
2017-12-14 01:00:11 +00:00
|
|
|
#include <gmock/gmock.h>
|
|
|
|
#include <google/protobuf/util/message_differencer.h>
|
2015-07-16 06:51:24 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include "packager/base/files/file_path.h"
|
2015-07-22 23:40:45 +00:00
|
|
|
#include "packager/base/files/file_util.h"
|
2015-07-16 06:51:24 +00:00
|
|
|
#include "packager/mpd/base/mock_mpd_builder.h"
|
|
|
|
#include "packager/mpd/base/mpd_builder.h"
|
|
|
|
#include "packager/mpd/base/mpd_options.h"
|
|
|
|
#include "packager/mpd/base/simple_mpd_notifier.h"
|
|
|
|
#include "packager/mpd/test/mpd_builder_test_helper.h"
|
|
|
|
|
2018-01-18 01:26:03 +00:00
|
|
|
DECLARE_int32(pto_adjustment);
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2015-07-16 06:51:24 +00:00
|
|
|
|
|
|
|
using ::testing::_;
|
2017-12-14 01:00:11 +00:00
|
|
|
using ::testing::Eq;
|
2018-01-03 00:10:54 +00:00
|
|
|
using ::testing::Ref;
|
2015-07-16 06:51:24 +00:00
|
|
|
using ::testing::Return;
|
2018-01-03 00:10:54 +00:00
|
|
|
using ::testing::ReturnRef;
|
2015-09-22 23:17:22 +00:00
|
|
|
using ::testing::StrEq;
|
2015-07-16 06:51:24 +00:00
|
|
|
|
|
|
|
namespace {
|
2018-01-03 00:10:54 +00:00
|
|
|
const uint32_t kDefaultPeriodId = 0u;
|
|
|
|
const double kDefaultPeriodStartTime = 0.0;
|
2015-07-22 06:57:21 +00:00
|
|
|
const uint32_t kDefaultAdaptationSetId = 0u;
|
2018-01-03 00:10:54 +00:00
|
|
|
const uint32_t kDefaultTimeScale = 10;
|
2017-12-14 01:00:11 +00:00
|
|
|
const bool kContentProtectionInAdaptationSet = true;
|
|
|
|
|
|
|
|
MATCHER_P(EqualsProto, message, "") {
|
|
|
|
return ::google::protobuf::util::MessageDifferencer::Equals(arg, message);
|
|
|
|
}
|
|
|
|
|
2015-07-16 06:51:24 +00:00
|
|
|
} // namespace
|
|
|
|
|
2016-12-21 23:28:56 +00:00
|
|
|
class SimpleMpdNotifierTest : public ::testing::Test {
|
2015-07-16 06:51:24 +00:00
|
|
|
protected:
|
|
|
|
SimpleMpdNotifierTest()
|
2018-01-03 00:10:54 +00:00
|
|
|
: default_mock_period_(
|
|
|
|
new MockPeriod(kDefaultPeriodId, kDefaultPeriodStartTime)),
|
2017-12-14 01:00:11 +00:00
|
|
|
default_mock_adaptation_set_(
|
2015-07-22 06:57:21 +00:00
|
|
|
new MockAdaptationSet(kDefaultAdaptationSetId)) {}
|
2015-07-16 06:51:24 +00:00
|
|
|
|
2015-07-22 23:40:45 +00:00
|
|
|
void SetUp() override {
|
2015-07-16 06:51:24 +00:00
|
|
|
ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path_));
|
2017-07-27 18:49:50 +00:00
|
|
|
empty_mpd_option_.mpd_params.mpd_output = temp_file_path_.AsUTF8Unsafe();
|
2017-12-14 01:00:11 +00:00
|
|
|
|
|
|
|
// Three valid media info. The actual data does not matter.
|
|
|
|
const char kValidMediaInfo[] =
|
|
|
|
"video_info {\n"
|
|
|
|
" codec: 'avc1'\n"
|
|
|
|
" width: 1280\n"
|
|
|
|
" height: 720\n"
|
|
|
|
" time_scale: 10\n"
|
|
|
|
" frame_duration: 10\n"
|
|
|
|
" pixel_width: 1\n"
|
|
|
|
" pixel_height: 1\n"
|
|
|
|
"}\n"
|
|
|
|
"container_type: 1\n";
|
|
|
|
valid_media_info1_ = ConvertToMediaInfo(kValidMediaInfo);
|
2018-01-03 00:10:54 +00:00
|
|
|
valid_media_info1_.set_reference_time_scale(kDefaultTimeScale);
|
2017-12-14 01:00:11 +00:00
|
|
|
valid_media_info2_ = valid_media_info1_;
|
|
|
|
valid_media_info2_.mutable_video_info()->set_width(960);
|
|
|
|
valid_media_info3_ = valid_media_info1_;
|
|
|
|
valid_media_info3_.mutable_video_info()->set_width(480);
|
2015-07-16 06:51:24 +00:00
|
|
|
}
|
|
|
|
|
2015-07-22 23:40:45 +00:00
|
|
|
void TearDown() override {
|
2015-07-16 06:51:24 +00:00
|
|
|
base::DeleteFile(temp_file_path_, false /* non recursive, just 1 file */);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetMpdBuilder(SimpleMpdNotifier* notifier,
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<MpdBuilder> mpd_builder) {
|
|
|
|
notifier->SetMpdBuilderForTesting(std::move(mpd_builder));
|
2015-07-16 06:51:24 +00:00
|
|
|
}
|
|
|
|
|
2017-12-14 01:00:11 +00:00
|
|
|
protected:
|
2017-07-27 18:49:50 +00:00
|
|
|
// Empty mpd options except with output path specified, so that
|
2015-07-22 06:57:21 +00:00
|
|
|
// WriteMpdToFile() doesn't crash.
|
2017-07-27 18:49:50 +00:00
|
|
|
MpdOptions empty_mpd_option_;
|
2015-07-16 06:51:24 +00:00
|
|
|
const std::vector<std::string> empty_base_urls_;
|
|
|
|
|
2017-12-14 01:00:11 +00:00
|
|
|
// Default mocks that can be used for the tests.
|
|
|
|
std::unique_ptr<MockPeriod> default_mock_period_;
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<MockAdaptationSet> default_mock_adaptation_set_;
|
2015-07-16 06:51:24 +00:00
|
|
|
|
2017-12-14 01:00:11 +00:00
|
|
|
// Three valid media info. The actual content does not matter.
|
|
|
|
MediaInfo valid_media_info1_;
|
|
|
|
MediaInfo valid_media_info2_;
|
|
|
|
MediaInfo valid_media_info3_;
|
|
|
|
|
2015-07-16 06:51:24 +00:00
|
|
|
private:
|
|
|
|
base::FilePath temp_file_path_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Verify NotifyNewContainer() works as expected for VOD.
|
2016-12-21 23:28:56 +00:00
|
|
|
TEST_F(SimpleMpdNotifierTest, NotifyNewContainer) {
|
2017-07-27 18:49:50 +00:00
|
|
|
SimpleMpdNotifier notifier(empty_mpd_option_);
|
2015-07-16 06:51:24 +00:00
|
|
|
|
|
|
|
const uint32_t kRepresentationId = 1u;
|
2016-12-21 23:28:56 +00:00
|
|
|
std::unique_ptr<MockMpdBuilder> mock_mpd_builder(new MockMpdBuilder());
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<MockRepresentation> mock_representation(
|
2015-07-16 06:51:24 +00:00
|
|
|
new MockRepresentation(kRepresentationId));
|
|
|
|
|
2018-01-03 00:10:54 +00:00
|
|
|
EXPECT_CALL(*mock_mpd_builder, GetOrCreatePeriod(_))
|
2017-12-14 01:00:11 +00:00
|
|
|
.WillOnce(Return(default_mock_period_.get()));
|
|
|
|
EXPECT_CALL(*default_mock_period_,
|
2017-12-19 20:02:28 +00:00
|
|
|
GetOrCreateAdaptationSet(EqualsProto(valid_media_info1_), _))
|
2015-07-16 06:51:24 +00:00
|
|
|
.WillOnce(Return(default_mock_adaptation_set_.get()));
|
2017-12-14 01:00:11 +00:00
|
|
|
EXPECT_CALL(*default_mock_adaptation_set_,
|
|
|
|
AddRepresentation(EqualsProto(valid_media_info1_)))
|
2015-07-16 06:51:24 +00:00
|
|
|
.WillOnce(Return(mock_representation.get()));
|
|
|
|
|
2015-09-10 23:01:00 +00:00
|
|
|
// This is for the Flush() below but adding expectation here because the next
|
2016-08-17 17:41:40 +00:00
|
|
|
// std::move(lines) the pointer.
|
2015-09-10 23:01:00 +00:00
|
|
|
EXPECT_CALL(*mock_mpd_builder, ToString(_)).WillOnce(Return(true));
|
2015-07-16 06:51:24 +00:00
|
|
|
|
|
|
|
uint32_t unused_container_id;
|
2016-08-17 17:41:40 +00:00
|
|
|
SetMpdBuilder(¬ifier, std::move(mock_mpd_builder));
|
2017-12-14 01:00:11 +00:00
|
|
|
EXPECT_TRUE(
|
|
|
|
notifier.NotifyNewContainer(valid_media_info1_, &unused_container_id));
|
2015-09-10 23:01:00 +00:00
|
|
|
EXPECT_TRUE(notifier.Flush());
|
2015-07-16 06:51:24 +00:00
|
|
|
}
|
|
|
|
|
2016-12-21 23:28:56 +00:00
|
|
|
TEST_F(SimpleMpdNotifierTest, NotifySampleDuration) {
|
2017-07-27 18:49:50 +00:00
|
|
|
SimpleMpdNotifier notifier(empty_mpd_option_);
|
2015-07-16 06:51:24 +00:00
|
|
|
|
|
|
|
const uint32_t kRepresentationId = 8u;
|
2016-12-21 23:28:56 +00:00
|
|
|
std::unique_ptr<MockMpdBuilder> mock_mpd_builder(new MockMpdBuilder());
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<MockRepresentation> mock_representation(
|
2015-07-16 06:51:24 +00:00
|
|
|
new MockRepresentation(kRepresentationId));
|
|
|
|
|
2018-01-03 00:10:54 +00:00
|
|
|
EXPECT_CALL(*mock_mpd_builder, GetOrCreatePeriod(_))
|
2017-12-14 01:00:11 +00:00
|
|
|
.WillOnce(Return(default_mock_period_.get()));
|
|
|
|
EXPECT_CALL(*default_mock_period_, GetOrCreateAdaptationSet(_, _))
|
2015-07-16 06:51:24 +00:00
|
|
|
.WillOnce(Return(default_mock_adaptation_set_.get()));
|
|
|
|
EXPECT_CALL(*default_mock_adaptation_set_, AddRepresentation(_))
|
|
|
|
.WillOnce(Return(mock_representation.get()));
|
|
|
|
|
|
|
|
uint32_t container_id;
|
2016-08-17 17:41:40 +00:00
|
|
|
SetMpdBuilder(¬ifier, std::move(mock_mpd_builder));
|
2017-12-14 01:00:11 +00:00
|
|
|
EXPECT_TRUE(notifier.NotifyNewContainer(valid_media_info1_, &container_id));
|
2015-07-16 06:51:24 +00:00
|
|
|
EXPECT_EQ(kRepresentationId, container_id);
|
|
|
|
|
|
|
|
const uint32_t kSampleDuration = 100;
|
|
|
|
EXPECT_CALL(*mock_representation, SetSampleDuration(kSampleDuration));
|
|
|
|
EXPECT_TRUE(
|
|
|
|
notifier.NotifySampleDuration(kRepresentationId, kSampleDuration));
|
|
|
|
}
|
|
|
|
|
2015-11-12 21:40:52 +00:00
|
|
|
// This test is mainly for tsan. Using both the notifier and the MpdBuilder.
|
|
|
|
// Although locks in MpdBuilder have been removed,
|
2016-05-20 21:28:13 +00:00
|
|
|
// https://github.com/google/shaka-packager/issues/45
|
2015-11-12 21:40:52 +00:00
|
|
|
// This issue identified a bug where using SimpleMpdNotifier with multiple
|
|
|
|
// threads causes a deadlock.
|
|
|
|
TEST_F(SimpleMpdNotifierTest, NotifyNewContainerAndSampleDurationNoMock) {
|
2017-07-27 18:49:50 +00:00
|
|
|
SimpleMpdNotifier notifier(empty_mpd_option_);
|
2015-11-12 21:40:52 +00:00
|
|
|
uint32_t container_id;
|
2017-12-14 01:00:11 +00:00
|
|
|
EXPECT_TRUE(notifier.NotifyNewContainer(valid_media_info1_, &container_id));
|
2015-11-12 21:40:52 +00:00
|
|
|
const uint32_t kAnySampleDuration = 1000;
|
2017-12-19 20:02:28 +00:00
|
|
|
EXPECT_TRUE(notifier.NotifySampleDuration(container_id, kAnySampleDuration));
|
2015-11-12 21:40:52 +00:00
|
|
|
EXPECT_TRUE(notifier.Flush());
|
|
|
|
}
|
|
|
|
|
2016-12-21 23:28:56 +00:00
|
|
|
TEST_F(SimpleMpdNotifierTest, NotifyNewSegment) {
|
2017-07-27 18:49:50 +00:00
|
|
|
SimpleMpdNotifier notifier(empty_mpd_option_);
|
2015-07-16 06:51:24 +00:00
|
|
|
|
|
|
|
const uint32_t kRepresentationId = 447834u;
|
2016-12-21 23:28:56 +00:00
|
|
|
std::unique_ptr<MockMpdBuilder> mock_mpd_builder(new MockMpdBuilder());
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<MockRepresentation> mock_representation(
|
2015-07-16 06:51:24 +00:00
|
|
|
new MockRepresentation(kRepresentationId));
|
|
|
|
|
2018-01-03 00:10:54 +00:00
|
|
|
EXPECT_CALL(*mock_mpd_builder, GetOrCreatePeriod(_))
|
2017-12-14 01:00:11 +00:00
|
|
|
.WillOnce(Return(default_mock_period_.get()));
|
|
|
|
EXPECT_CALL(*default_mock_period_, GetOrCreateAdaptationSet(_, _))
|
2015-07-16 06:51:24 +00:00
|
|
|
.WillOnce(Return(default_mock_adaptation_set_.get()));
|
|
|
|
EXPECT_CALL(*default_mock_adaptation_set_, AddRepresentation(_))
|
|
|
|
.WillOnce(Return(mock_representation.get()));
|
|
|
|
|
|
|
|
uint32_t container_id;
|
2016-08-17 17:41:40 +00:00
|
|
|
SetMpdBuilder(¬ifier, std::move(mock_mpd_builder));
|
2017-12-14 01:00:11 +00:00
|
|
|
EXPECT_TRUE(notifier.NotifyNewContainer(valid_media_info1_, &container_id));
|
2015-07-16 06:51:24 +00:00
|
|
|
EXPECT_EQ(kRepresentationId, container_id);
|
|
|
|
|
|
|
|
const uint64_t kStartTime = 0u;
|
|
|
|
const uint32_t kSegmentDuration = 100u;
|
|
|
|
const uint64_t kSegmentSize = 123456u;
|
|
|
|
EXPECT_CALL(*mock_representation,
|
|
|
|
AddNewSegment(kStartTime, kSegmentDuration, kSegmentSize));
|
|
|
|
|
|
|
|
EXPECT_TRUE(notifier.NotifyNewSegment(kRepresentationId, kStartTime,
|
|
|
|
kSegmentDuration, kSegmentSize));
|
|
|
|
}
|
|
|
|
|
2018-01-03 00:10:54 +00:00
|
|
|
TEST_F(SimpleMpdNotifierTest, NotifyCueEvent) {
|
|
|
|
SimpleMpdNotifier notifier(empty_mpd_option_);
|
|
|
|
|
|
|
|
const uint32_t kRepresentationId = 123u;
|
|
|
|
std::unique_ptr<MockMpdBuilder> mock_mpd_builder(new MockMpdBuilder());
|
|
|
|
MockMpdBuilder* mock_mpd_builder_ptr = mock_mpd_builder.get();
|
|
|
|
|
|
|
|
std::unique_ptr<MockPeriod> mock_period(
|
|
|
|
new MockPeriod(kDefaultPeriodId, kDefaultPeriodStartTime));
|
|
|
|
std::unique_ptr<MockAdaptationSet> mock_adaptation_set(
|
|
|
|
new MockAdaptationSet(kDefaultAdaptationSetId));
|
|
|
|
std::unique_ptr<MockRepresentation> mock_representation(
|
|
|
|
new MockRepresentation(kRepresentationId));
|
|
|
|
|
|
|
|
EXPECT_CALL(*mock_mpd_builder, GetOrCreatePeriod(Eq(0.0)))
|
|
|
|
.WillOnce(Return(mock_period.get()));
|
|
|
|
EXPECT_CALL(*mock_period,
|
|
|
|
GetOrCreateAdaptationSet(EqualsProto(valid_media_info1_), _))
|
|
|
|
.WillOnce(Return(mock_adaptation_set.get()));
|
|
|
|
EXPECT_CALL(*mock_adaptation_set, AddRepresentation(_))
|
|
|
|
.WillOnce(Return(mock_representation.get()));
|
|
|
|
|
|
|
|
uint32_t container_id;
|
|
|
|
SetMpdBuilder(¬ifier, std::move(mock_mpd_builder));
|
|
|
|
EXPECT_TRUE(notifier.NotifyNewContainer(valid_media_info1_, &container_id));
|
|
|
|
EXPECT_EQ(kRepresentationId, container_id);
|
|
|
|
|
|
|
|
const uint32_t kAnotherPeriodId = 2u;
|
|
|
|
const double kArbitraryPeriodStartTime = 100; // Value does not matter.
|
|
|
|
std::unique_ptr<MockPeriod> mock_period2(
|
|
|
|
new MockPeriod(kAnotherPeriodId, kArbitraryPeriodStartTime));
|
|
|
|
std::unique_ptr<MockAdaptationSet> mock_adaptation_set2(
|
|
|
|
new MockAdaptationSet(kDefaultAdaptationSetId));
|
|
|
|
std::unique_ptr<MockRepresentation> mock_representation2(
|
|
|
|
new MockRepresentation(kRepresentationId));
|
|
|
|
|
|
|
|
const uint64_t kCueEventTimestamp = 1000;
|
|
|
|
EXPECT_CALL(*mock_representation, GetMediaInfo())
|
|
|
|
.WillOnce(ReturnRef(valid_media_info1_));
|
|
|
|
EXPECT_CALL(*mock_mpd_builder_ptr,
|
|
|
|
GetOrCreatePeriod(Eq(kCueEventTimestamp / kDefaultTimeScale)))
|
|
|
|
.WillOnce(Return(mock_period2.get()));
|
|
|
|
EXPECT_CALL(*mock_period2,
|
|
|
|
GetOrCreateAdaptationSet(EqualsProto(valid_media_info1_), _))
|
|
|
|
.WillOnce(Return(mock_adaptation_set2.get()));
|
2018-01-18 01:26:03 +00:00
|
|
|
EXPECT_CALL(
|
|
|
|
*mock_adaptation_set2,
|
|
|
|
CopyRepresentationWithTimeOffset(
|
|
|
|
Ref(*mock_representation), kCueEventTimestamp + FLAGS_pto_adjustment))
|
2018-01-03 00:10:54 +00:00
|
|
|
.WillOnce(Return(mock_representation2.get()));
|
|
|
|
EXPECT_TRUE(notifier.NotifyCueEvent(container_id, kCueEventTimestamp));
|
|
|
|
}
|
|
|
|
|
2017-12-19 20:02:28 +00:00
|
|
|
TEST_F(SimpleMpdNotifierTest,
|
|
|
|
ContentProtectionInAdaptationSetUpdateEncryption) {
|
|
|
|
MpdOptions mpd_options = empty_mpd_option_;
|
|
|
|
mpd_options.mpd_params.generate_dash_if_iop_compliant_mpd =
|
|
|
|
kContentProtectionInAdaptationSet;
|
|
|
|
SimpleMpdNotifier notifier(mpd_options);
|
2015-07-16 06:51:24 +00:00
|
|
|
|
2017-12-19 20:02:28 +00:00
|
|
|
const uint32_t kRepresentationId = 447834u;
|
2016-12-21 23:28:56 +00:00
|
|
|
std::unique_ptr<MockMpdBuilder> mock_mpd_builder(new MockMpdBuilder());
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<MockRepresentation> mock_representation(
|
2015-07-16 06:51:24 +00:00
|
|
|
new MockRepresentation(kRepresentationId));
|
|
|
|
|
2018-01-03 00:10:54 +00:00
|
|
|
EXPECT_CALL(*mock_mpd_builder, GetOrCreatePeriod(_))
|
2017-12-14 01:00:11 +00:00
|
|
|
.WillOnce(Return(default_mock_period_.get()));
|
2017-12-19 20:02:28 +00:00
|
|
|
EXPECT_CALL(
|
|
|
|
*default_mock_period_,
|
|
|
|
GetOrCreateAdaptationSet(_, Eq(kContentProtectionInAdaptationSet)))
|
2015-07-16 06:51:24 +00:00
|
|
|
.WillOnce(Return(default_mock_adaptation_set_.get()));
|
|
|
|
EXPECT_CALL(*default_mock_adaptation_set_, AddRepresentation(_))
|
|
|
|
.WillOnce(Return(mock_representation.get()));
|
|
|
|
|
|
|
|
uint32_t container_id;
|
2016-08-17 17:41:40 +00:00
|
|
|
SetMpdBuilder(¬ifier, std::move(mock_mpd_builder));
|
2017-12-14 01:00:11 +00:00
|
|
|
EXPECT_TRUE(notifier.NotifyNewContainer(valid_media_info1_, &container_id));
|
2015-07-16 06:51:24 +00:00
|
|
|
|
2017-12-19 20:02:28 +00:00
|
|
|
::testing::Mock::VerifyAndClearExpectations(
|
|
|
|
default_mock_adaptation_set_.get());
|
|
|
|
|
|
|
|
// "psshsomethingelse" as uint8 array.
|
|
|
|
const uint8_t kBogusNewPssh[] = {0x70, 0x73, 0x73, 0x68, 0x73, 0x6f,
|
|
|
|
0x6d, 0x65, 0x74, 0x68, 0x69, 0x6e,
|
|
|
|
0x67, 0x65, 0x6c, 0x73, 0x65};
|
|
|
|
const std::vector<uint8_t> kBogusNewPsshVector(
|
|
|
|
kBogusNewPssh, kBogusNewPssh + arraysize(kBogusNewPssh));
|
|
|
|
const char kBogusNewPsshInBase64[] = "cHNzaHNvbWV0aGluZ2Vsc2U=";
|
|
|
|
|
|
|
|
EXPECT_CALL(*default_mock_adaptation_set_,
|
|
|
|
UpdateContentProtectionPssh(StrEq("myuuid"),
|
|
|
|
StrEq(kBogusNewPsshInBase64)));
|
|
|
|
EXPECT_TRUE(notifier.NotifyEncryptionUpdate(
|
|
|
|
container_id, "myuuid", std::vector<uint8_t>(), kBogusNewPsshVector));
|
2015-07-16 06:51:24 +00:00
|
|
|
}
|
|
|
|
|
2017-12-19 20:02:28 +00:00
|
|
|
TEST_F(SimpleMpdNotifierTest,
|
|
|
|
ContentProtectionNotInAdaptationSetUpdateEncryption) {
|
|
|
|
MpdOptions mpd_options = empty_mpd_option_;
|
|
|
|
mpd_options.mpd_params.generate_dash_if_iop_compliant_mpd =
|
|
|
|
!kContentProtectionInAdaptationSet;
|
|
|
|
SimpleMpdNotifier notifier(mpd_options);
|
|
|
|
|
2015-08-26 20:25:29 +00:00
|
|
|
const uint32_t kRepresentationId = 447834u;
|
2016-12-21 23:28:56 +00:00
|
|
|
std::unique_ptr<MockMpdBuilder> mock_mpd_builder(new MockMpdBuilder());
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<MockRepresentation> mock_representation(
|
2015-08-26 20:25:29 +00:00
|
|
|
new MockRepresentation(kRepresentationId));
|
|
|
|
|
2018-01-03 00:10:54 +00:00
|
|
|
EXPECT_CALL(*mock_mpd_builder, GetOrCreatePeriod(_))
|
2017-12-14 01:00:11 +00:00
|
|
|
.WillOnce(Return(default_mock_period_.get()));
|
2017-12-19 20:02:28 +00:00
|
|
|
EXPECT_CALL(
|
|
|
|
*default_mock_period_,
|
|
|
|
GetOrCreateAdaptationSet(_, Eq(!kContentProtectionInAdaptationSet)))
|
2015-08-26 20:25:29 +00:00
|
|
|
.WillOnce(Return(default_mock_adaptation_set_.get()));
|
|
|
|
EXPECT_CALL(*default_mock_adaptation_set_, AddRepresentation(_))
|
|
|
|
.WillOnce(Return(mock_representation.get()));
|
|
|
|
|
|
|
|
uint32_t container_id;
|
2016-08-17 17:41:40 +00:00
|
|
|
SetMpdBuilder(¬ifier, std::move(mock_mpd_builder));
|
2017-12-14 01:00:11 +00:00
|
|
|
EXPECT_TRUE(notifier.NotifyNewContainer(valid_media_info1_, &container_id));
|
2015-08-26 20:25:29 +00:00
|
|
|
|
|
|
|
::testing::Mock::VerifyAndClearExpectations(
|
|
|
|
default_mock_adaptation_set_.get());
|
|
|
|
|
|
|
|
// "psshsomethingelse" as uint8 array.
|
|
|
|
const uint8_t kBogusNewPssh[] = {0x70, 0x73, 0x73, 0x68, 0x73, 0x6f,
|
|
|
|
0x6d, 0x65, 0x74, 0x68, 0x69, 0x6e,
|
|
|
|
0x67, 0x65, 0x6c, 0x73, 0x65};
|
|
|
|
const std::vector<uint8_t> kBogusNewPsshVector(
|
|
|
|
kBogusNewPssh, kBogusNewPssh + arraysize(kBogusNewPssh));
|
|
|
|
const char kBogusNewPsshInBase64[] = "cHNzaHNvbWV0aGluZ2Vsc2U=";
|
|
|
|
|
|
|
|
EXPECT_CALL(*mock_representation,
|
2015-09-24 22:03:52 +00:00
|
|
|
UpdateContentProtectionPssh(StrEq("myuuid"),
|
|
|
|
StrEq(kBogusNewPsshInBase64)));
|
2015-08-26 20:25:29 +00:00
|
|
|
EXPECT_TRUE(notifier.NotifyEncryptionUpdate(
|
2015-09-24 22:03:52 +00:00
|
|
|
container_id, "myuuid", std::vector<uint8_t>(), kBogusNewPsshVector));
|
2015-08-26 20:25:29 +00:00
|
|
|
}
|
|
|
|
|
2017-12-14 01:00:11 +00:00
|
|
|
// Test multiple media info with some belongs to the same AdaptationSets.
|
|
|
|
TEST_F(SimpleMpdNotifierTest, MultipleMediaInfo) {
|
2017-07-27 18:49:50 +00:00
|
|
|
SimpleMpdNotifier notifier(empty_mpd_option_);
|
2016-12-21 23:28:56 +00:00
|
|
|
std::unique_ptr<MockMpdBuilder> mock_mpd_builder(new MockMpdBuilder());
|
2016-03-08 19:19:12 +00:00
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<MockAdaptationSet> adaptation_set1(new MockAdaptationSet(1));
|
|
|
|
std::unique_ptr<MockAdaptationSet> adaptation_set2(new MockAdaptationSet(2));
|
2016-03-08 19:19:12 +00:00
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<MockRepresentation> representation1(
|
|
|
|
new MockRepresentation(1));
|
|
|
|
std::unique_ptr<MockRepresentation> representation2(
|
|
|
|
new MockRepresentation(2));
|
|
|
|
std::unique_ptr<MockRepresentation> representation3(
|
|
|
|
new MockRepresentation(3));
|
2017-12-14 01:00:11 +00:00
|
|
|
|
2018-01-03 00:10:54 +00:00
|
|
|
EXPECT_CALL(*mock_mpd_builder, GetOrCreatePeriod(_))
|
|
|
|
.Times(3)
|
|
|
|
.WillRepeatedly(Return(default_mock_period_.get()));
|
2017-12-14 01:00:11 +00:00
|
|
|
|
|
|
|
EXPECT_CALL(*default_mock_period_,
|
|
|
|
GetOrCreateAdaptationSet(EqualsProto(valid_media_info1_), _))
|
|
|
|
.WillOnce(Return(adaptation_set1.get()));
|
|
|
|
EXPECT_CALL(*adaptation_set1,
|
|
|
|
AddRepresentation(EqualsProto(valid_media_info1_)))
|
2016-03-08 19:19:12 +00:00
|
|
|
.WillOnce(Return(representation1.get()));
|
2017-12-14 01:00:11 +00:00
|
|
|
// Return the same adaptation set for |valid_media_info2_| and
|
|
|
|
// |valid_media_info3_|. This results in AddRepresentation to be called twice
|
|
|
|
// on |adaptation_set2|.
|
|
|
|
EXPECT_CALL(*default_mock_period_,
|
|
|
|
GetOrCreateAdaptationSet(EqualsProto(valid_media_info2_), _))
|
|
|
|
.WillOnce(Return(adaptation_set2.get()));
|
|
|
|
EXPECT_CALL(*adaptation_set2,
|
|
|
|
AddRepresentation(EqualsProto(valid_media_info2_)))
|
2016-03-08 19:19:12 +00:00
|
|
|
.WillOnce(Return(representation2.get()));
|
2017-12-14 01:00:11 +00:00
|
|
|
EXPECT_CALL(*default_mock_period_,
|
|
|
|
GetOrCreateAdaptationSet(EqualsProto(valid_media_info3_), _))
|
|
|
|
.WillOnce(Return(adaptation_set2.get()));
|
|
|
|
EXPECT_CALL(*adaptation_set2,
|
|
|
|
AddRepresentation(EqualsProto(valid_media_info3_)))
|
|
|
|
.WillOnce(Return(representation3.get()));
|
2016-03-08 19:19:12 +00:00
|
|
|
|
|
|
|
uint32_t unused_container_id;
|
2016-08-17 17:41:40 +00:00
|
|
|
SetMpdBuilder(¬ifier, std::move(mock_mpd_builder));
|
2017-12-14 01:00:11 +00:00
|
|
|
EXPECT_TRUE(
|
|
|
|
notifier.NotifyNewContainer(valid_media_info1_, &unused_container_id));
|
|
|
|
EXPECT_TRUE(
|
|
|
|
notifier.NotifyNewContainer(valid_media_info2_, &unused_container_id));
|
|
|
|
EXPECT_TRUE(
|
|
|
|
notifier.NotifyNewContainer(valid_media_info3_, &unused_container_id));
|
2016-03-08 19:19:12 +00:00
|
|
|
}
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|