2016-03-25 08:40:15 +00:00
|
|
|
// Copyright 2016 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
|
|
|
|
|
|
|
|
#include <gmock/gmock.h>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2016-03-25 08:40:15 +00:00
|
|
|
#include "packager/base/base64.h"
|
2017-06-03 00:05:47 +00:00
|
|
|
#include "packager/base/files/file_path.h"
|
2016-03-25 08:40:15 +00:00
|
|
|
#include "packager/hls/base/mock_media_playlist.h"
|
|
|
|
#include "packager/hls/base/simple_hls_notifier.h"
|
2018-08-07 23:01:43 +00:00
|
|
|
#include "packager/media/base/fairplay_pssh_generator.h"
|
2017-04-04 20:57:50 +00:00
|
|
|
#include "packager/media/base/protection_system_specific_info.h"
|
2017-09-12 19:22:39 +00:00
|
|
|
#include "packager/media/base/raw_key_pssh_generator.h"
|
2017-10-17 23:03:08 +00:00
|
|
|
#include "packager/media/base/raw_key_source.h"
|
2016-06-24 00:22:37 +00:00
|
|
|
#include "packager/media/base/widevine_key_source.h"
|
2016-03-25 08:40:15 +00:00
|
|
|
#include "packager/media/base/widevine_pssh_data.pb.h"
|
2017-09-12 19:22:39 +00:00
|
|
|
#include "packager/media/base/widevine_pssh_generator.h"
|
2016-03-25 08:40:15 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2016-03-25 08:40:15 +00:00
|
|
|
namespace hls {
|
|
|
|
|
2018-02-02 17:14:46 +00:00
|
|
|
using ::testing::_;
|
|
|
|
using ::testing::ElementsAre;
|
2017-06-03 00:05:47 +00:00
|
|
|
using ::testing::Eq;
|
|
|
|
using ::testing::InSequence;
|
|
|
|
using ::testing::Mock;
|
2017-10-07 00:01:56 +00:00
|
|
|
using ::testing::Property;
|
2016-03-25 08:40:15 +00:00
|
|
|
using ::testing::Return;
|
|
|
|
using ::testing::StrEq;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
const char kMasterPlaylistName[] = "master.m3u8";
|
2018-01-17 23:43:41 +00:00
|
|
|
const char kDefaultLanguage[] = "en";
|
2017-11-12 22:56:25 +00:00
|
|
|
const char kEmptyKeyUri[] = "";
|
2018-08-07 23:01:43 +00:00
|
|
|
const char kFairPlayKeyUri[] = "skd://www.license.com/getkey?key_id=testing";
|
2017-11-12 22:56:25 +00:00
|
|
|
const char kIdentityKeyUri[] = "https://www.license.com/getkey?key_id=testing";
|
2017-06-30 20:42:46 +00:00
|
|
|
const HlsPlaylistType kVodPlaylist = HlsPlaylistType::kVod;
|
Fairplay key system support
Support generation of fairplay key system tag: "com.apple.streamingkeydelivery" when --pssh
includes fairplay key system id:
// Unofficial fairplay system id extracted from
// https://forums.developer.apple.com/thread/6185.
const uint8_t kFairplaySystemId[] = {0x29, 0x70, 0x1F, 0xE4, 0x3C, 0xC7,
0x4A, 0x34, 0x8C, 0x5B, 0xAE, 0x90,
0xC7, 0x43, 0x9A, 0x47};
Closes #258
2017-08-08 17:31:40 +00:00
|
|
|
const HlsPlaylistType kLivePlaylist = HlsPlaylistType::kLive;
|
2016-03-25 08:40:15 +00:00
|
|
|
|
|
|
|
class MockMasterPlaylist : public MasterPlaylist {
|
|
|
|
public:
|
2018-01-17 23:43:41 +00:00
|
|
|
MockMasterPlaylist()
|
|
|
|
: MasterPlaylist(kMasterPlaylistName, kDefaultLanguage) {}
|
2016-03-25 08:40:15 +00:00
|
|
|
|
2018-02-02 17:14:46 +00:00
|
|
|
MOCK_METHOD3(WriteMasterPlaylist,
|
|
|
|
bool(const std::string& prefix,
|
|
|
|
const std::string& output_dir,
|
|
|
|
const std::list<MediaPlaylist*>& playlists));
|
2016-03-25 08:40:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MockMediaPlaylistFactory : public MediaPlaylistFactory {
|
|
|
|
public:
|
2018-04-14 01:26:02 +00:00
|
|
|
MOCK_METHOD4(CreateMock,
|
|
|
|
MediaPlaylist*(const HlsParams& hls_params,
|
2016-04-20 22:23:19 +00:00
|
|
|
const std::string& file_name,
|
2016-03-25 08:40:15 +00:00
|
|
|
const std::string& name,
|
|
|
|
const std::string& group_id));
|
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
std::unique_ptr<MediaPlaylist> Create(const HlsParams& hls_params,
|
2016-08-17 17:41:40 +00:00
|
|
|
const std::string& file_name,
|
|
|
|
const std::string& name,
|
|
|
|
const std::string& group_id) override {
|
|
|
|
return std::unique_ptr<MediaPlaylist>(
|
2018-04-14 01:26:02 +00:00
|
|
|
CreateMock(hls_params, file_name, name, group_id));
|
2016-03-25 08:40:15 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-06-03 00:05:47 +00:00
|
|
|
const double kTestTimeShiftBufferDepth = 1800.0;
|
2016-03-25 08:40:15 +00:00
|
|
|
const char kTestPrefix[] = "http://testprefix.com/";
|
2017-09-08 17:52:48 +00:00
|
|
|
const char kEmptyPrefix[] = "";
|
2018-01-17 23:43:41 +00:00
|
|
|
const char kAnyOutputDir[] = "anything";
|
2016-03-25 08:40:15 +00:00
|
|
|
|
2016-04-16 22:58:47 +00:00
|
|
|
const uint64_t kAnyStartTime = 10;
|
|
|
|
const uint64_t kAnyDuration = 1000;
|
|
|
|
const uint64_t kAnySize = 2000;
|
|
|
|
|
2017-04-04 20:57:50 +00:00
|
|
|
const char kCencProtectionScheme[] = "cenc";
|
|
|
|
const char kSampleAesProtectionScheme[] = "cbca";
|
|
|
|
|
2016-03-25 08:40:15 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
class SimpleHlsNotifierTest : public ::testing::Test {
|
|
|
|
protected:
|
2017-06-30 20:42:46 +00:00
|
|
|
SimpleHlsNotifierTest() : SimpleHlsNotifierTest(kVodPlaylist) {}
|
2017-06-03 00:05:47 +00:00
|
|
|
|
2017-06-30 20:42:46 +00:00
|
|
|
SimpleHlsNotifierTest(HlsPlaylistType playlist_type)
|
2018-08-07 23:01:43 +00:00
|
|
|
: widevine_system_id_(std::begin(media::kWidevineSystemId),
|
|
|
|
std::end(media::kWidevineSystemId)),
|
|
|
|
common_system_id_(std::begin(media::kCommonSystemId),
|
|
|
|
std::end(media::kCommonSystemId)),
|
|
|
|
fairplay_system_id_(std::begin(media::kFairPlaySystemId),
|
|
|
|
std::end(media::kFairPlaySystemId)) {
|
2018-01-17 23:43:41 +00:00
|
|
|
hls_params_.playlist_type = kVodPlaylist;
|
|
|
|
hls_params_.time_shift_buffer_depth = kTestTimeShiftBufferDepth;
|
|
|
|
hls_params_.base_url = kTestPrefix;
|
|
|
|
hls_params_.key_uri = kEmptyKeyUri;
|
|
|
|
hls_params_.master_playlist_output =
|
|
|
|
std::string(kAnyOutputDir) + "/" + kMasterPlaylistName;
|
|
|
|
}
|
2016-03-25 08:40:15 +00:00
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
void InjectMediaPlaylistFactory(std::unique_ptr<MediaPlaylistFactory> factory,
|
2016-04-16 22:58:47 +00:00
|
|
|
SimpleHlsNotifier* notifier) {
|
2016-08-17 17:41:40 +00:00
|
|
|
notifier->media_playlist_factory_ = std::move(factory);
|
2016-04-16 22:58:47 +00:00
|
|
|
}
|
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
void InjectMasterPlaylist(std::unique_ptr<MasterPlaylist> playlist,
|
2016-04-16 22:58:47 +00:00
|
|
|
SimpleHlsNotifier* notifier) {
|
2016-08-17 17:41:40 +00:00
|
|
|
notifier->master_playlist_ = std::move(playlist);
|
2016-04-16 22:58:47 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
size_t NumRegisteredMediaPlaylists(const SimpleHlsNotifier& notifier) {
|
|
|
|
return notifier.stream_map_.size();
|
|
|
|
}
|
2016-03-25 08:40:15 +00:00
|
|
|
|
2017-04-04 20:57:50 +00:00
|
|
|
uint32_t SetupStream(const std::string& protection_scheme,
|
2017-05-01 20:38:58 +00:00
|
|
|
MockMediaPlaylist* mock_media_playlist,
|
|
|
|
SimpleHlsNotifier* notifier) {
|
2017-04-04 20:57:50 +00:00
|
|
|
MediaInfo media_info;
|
|
|
|
media_info.mutable_protected_content()->set_protection_scheme(
|
|
|
|
protection_scheme);
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<MockMasterPlaylist> mock_master_playlist(
|
2016-06-24 00:22:37 +00:00
|
|
|
new MockMasterPlaylist());
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<MockMediaPlaylistFactory> factory(
|
2016-06-24 00:22:37 +00:00
|
|
|
new MockMediaPlaylistFactory());
|
|
|
|
|
|
|
|
EXPECT_CALL(*mock_media_playlist, SetMediaInfo(_)).WillOnce(Return(true));
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_CALL(*factory, CreateMock(_, _, _, _))
|
2016-06-24 00:22:37 +00:00
|
|
|
.WillOnce(Return(mock_media_playlist));
|
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
InjectMasterPlaylist(std::move(mock_master_playlist), notifier);
|
|
|
|
InjectMediaPlaylistFactory(std::move(factory), notifier);
|
|
|
|
EXPECT_TRUE(notifier->Init());
|
2016-06-24 00:22:37 +00:00
|
|
|
uint32_t stream_id;
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_TRUE(notifier->NotifyNewStream(media_info, "playlist.m3u8", "name",
|
2016-06-24 00:22:37 +00:00
|
|
|
"groupid", &stream_id));
|
|
|
|
return stream_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<uint8_t> widevine_system_id_;
|
|
|
|
const std::vector<uint8_t> common_system_id_;
|
Fairplay key system support
Support generation of fairplay key system tag: "com.apple.streamingkeydelivery" when --pssh
includes fairplay key system id:
// Unofficial fairplay system id extracted from
// https://forums.developer.apple.com/thread/6185.
const uint8_t kFairplaySystemId[] = {0x29, 0x70, 0x1F, 0xE4, 0x3C, 0xC7,
0x4A, 0x34, 0x8C, 0x5B, 0xAE, 0x90,
0xC7, 0x43, 0x9A, 0x47};
Closes #258
2017-08-08 17:31:40 +00:00
|
|
|
const std::vector<uint8_t> fairplay_system_id_;
|
2018-01-17 23:43:41 +00:00
|
|
|
HlsParams hls_params_;
|
2016-03-25 08:40:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(SimpleHlsNotifierTest, Init) {
|
2018-01-17 23:43:41 +00:00
|
|
|
SimpleHlsNotifier notifier(hls_params_);
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_TRUE(notifier.Init());
|
2016-03-25 08:40:15 +00:00
|
|
|
}
|
|
|
|
|
2016-04-16 22:58:47 +00:00
|
|
|
// Verify that relative paths can be handled.
|
|
|
|
// For this test, since the prefix "anything/" matches, the prefix should be
|
|
|
|
// stripped.
|
2017-09-08 17:52:48 +00:00
|
|
|
TEST_F(SimpleHlsNotifierTest, RebaseSegmentUrl) {
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<MockMasterPlaylist> mock_master_playlist(
|
|
|
|
new MockMasterPlaylist());
|
|
|
|
std::unique_ptr<MockMediaPlaylistFactory> factory(
|
|
|
|
new MockMediaPlaylistFactory());
|
2016-04-16 22:58:47 +00:00
|
|
|
|
|
|
|
// Pointer released by SimpleHlsNotifier.
|
|
|
|
MockMediaPlaylist* mock_media_playlist =
|
2018-04-14 01:26:02 +00:00
|
|
|
new MockMediaPlaylist("playlist.m3u8", "", "");
|
2016-04-16 22:58:47 +00:00
|
|
|
|
2017-10-07 00:01:56 +00:00
|
|
|
EXPECT_CALL(*mock_media_playlist,
|
2018-04-17 17:42:45 +00:00
|
|
|
SetMediaInfo(Property(&MediaInfo::init_segment_url, StrEq(""))))
|
2017-10-07 00:01:56 +00:00
|
|
|
.WillOnce(Return(true));
|
2016-04-16 22:58:47 +00:00
|
|
|
|
|
|
|
// Verify that the common prefix is stripped for AddSegment().
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_CALL(
|
|
|
|
*mock_media_playlist,
|
|
|
|
AddSegment("http://testprefix.com/path/to/media1.ts", _, _, _, _));
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_CALL(*factory, CreateMock(_, StrEq("video_playlist.m3u8"),
|
|
|
|
StrEq("name"), StrEq("groupid")))
|
2016-04-16 22:58:47 +00:00
|
|
|
.WillOnce(Return(mock_media_playlist));
|
|
|
|
|
2018-01-17 23:43:41 +00:00
|
|
|
SimpleHlsNotifier notifier(hls_params_);
|
2017-05-01 20:38:58 +00:00
|
|
|
|
|
|
|
InjectMasterPlaylist(std::move(mock_master_playlist), ¬ifier);
|
|
|
|
InjectMediaPlaylistFactory(std::move(factory), ¬ifier);
|
|
|
|
|
|
|
|
EXPECT_TRUE(notifier.Init());
|
2016-04-16 22:58:47 +00:00
|
|
|
MediaInfo media_info;
|
|
|
|
uint32_t stream_id;
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_TRUE(notifier.NotifyNewStream(media_info, "video_playlist.m3u8",
|
|
|
|
"name", "groupid", &stream_id));
|
2016-04-16 22:58:47 +00:00
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_TRUE(notifier.NotifyNewSegment(stream_id, "anything/path/to/media1.ts",
|
|
|
|
kAnyStartTime, kAnyDuration, 0,
|
|
|
|
kAnySize));
|
2016-04-16 22:58:47 +00:00
|
|
|
}
|
|
|
|
|
2017-10-07 00:01:56 +00:00
|
|
|
TEST_F(SimpleHlsNotifierTest, RebaseInitSegmentUrl) {
|
|
|
|
std::unique_ptr<MockMasterPlaylist> mock_master_playlist(
|
|
|
|
new MockMasterPlaylist());
|
|
|
|
std::unique_ptr<MockMediaPlaylistFactory> factory(
|
|
|
|
new MockMediaPlaylistFactory());
|
|
|
|
|
|
|
|
// Pointer released by SimpleHlsNotifier.
|
|
|
|
MockMediaPlaylist* mock_media_playlist =
|
2018-04-14 01:26:02 +00:00
|
|
|
new MockMediaPlaylist("playlist.m3u8", "", "");
|
2017-10-07 00:01:56 +00:00
|
|
|
|
|
|
|
// Verify that the common prefix is stripped in init segment.
|
|
|
|
EXPECT_CALL(
|
|
|
|
*mock_media_playlist,
|
2018-04-17 17:42:45 +00:00
|
|
|
SetMediaInfo(Property(&MediaInfo::init_segment_url,
|
2017-10-07 00:01:56 +00:00
|
|
|
StrEq("http://testprefix.com/path/to/init.mp4"))))
|
|
|
|
.WillOnce(Return(true));
|
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_CALL(*factory, CreateMock(_, StrEq("video_playlist.m3u8"),
|
|
|
|
StrEq("name"), StrEq("groupid")))
|
2017-10-07 00:01:56 +00:00
|
|
|
.WillOnce(Return(mock_media_playlist));
|
|
|
|
|
2018-01-17 23:43:41 +00:00
|
|
|
SimpleHlsNotifier notifier(hls_params_);
|
2017-10-07 00:01:56 +00:00
|
|
|
|
|
|
|
InjectMasterPlaylist(std::move(mock_master_playlist), ¬ifier);
|
|
|
|
InjectMediaPlaylistFactory(std::move(factory), ¬ifier);
|
|
|
|
|
|
|
|
EXPECT_TRUE(notifier.Init());
|
|
|
|
MediaInfo media_info;
|
|
|
|
media_info.set_init_segment_name("anything/path/to/init.mp4");
|
|
|
|
uint32_t stream_id;
|
|
|
|
EXPECT_TRUE(notifier.NotifyNewStream(media_info, "video_playlist.m3u8",
|
|
|
|
"name", "groupid", &stream_id));
|
|
|
|
}
|
|
|
|
|
2017-09-08 17:52:48 +00:00
|
|
|
TEST_F(SimpleHlsNotifierTest, RebaseSegmentUrlRelativeToPlaylist) {
|
|
|
|
std::unique_ptr<MockMasterPlaylist> mock_master_playlist(
|
|
|
|
new MockMasterPlaylist());
|
|
|
|
std::unique_ptr<MockMediaPlaylistFactory> factory(
|
|
|
|
new MockMediaPlaylistFactory());
|
|
|
|
|
|
|
|
// Pointer released by SimpleHlsNotifier.
|
|
|
|
MockMediaPlaylist* mock_media_playlist =
|
2018-04-14 01:26:02 +00:00
|
|
|
new MockMediaPlaylist("video/playlist.m3u8", "", "");
|
2017-09-08 17:52:48 +00:00
|
|
|
|
2017-10-07 00:01:56 +00:00
|
|
|
// Verify that the init segment URL is relative to playlist path.
|
|
|
|
EXPECT_CALL(*mock_media_playlist,
|
2018-04-17 17:42:45 +00:00
|
|
|
SetMediaInfo(Property(&MediaInfo::init_segment_url,
|
2017-10-07 00:01:56 +00:00
|
|
|
StrEq("path/to/init.mp4"))))
|
|
|
|
.WillOnce(Return(true));
|
2017-09-08 17:52:48 +00:00
|
|
|
|
|
|
|
// Verify that the segment URL is relative to playlist path.
|
|
|
|
EXPECT_CALL(*mock_media_playlist,
|
2017-10-07 00:01:56 +00:00
|
|
|
AddSegment(StrEq("path/to/media1.m4s"), _, _, _, _));
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_CALL(*factory, CreateMock(_, StrEq("video/playlist.m3u8"),
|
|
|
|
StrEq("name"), StrEq("groupid")))
|
2017-09-08 17:52:48 +00:00
|
|
|
.WillOnce(Return(mock_media_playlist));
|
|
|
|
|
2018-01-17 23:43:41 +00:00
|
|
|
hls_params_.base_url = kEmptyPrefix;
|
|
|
|
SimpleHlsNotifier notifier(hls_params_);
|
2017-09-08 17:52:48 +00:00
|
|
|
|
|
|
|
InjectMasterPlaylist(std::move(mock_master_playlist), ¬ifier);
|
|
|
|
InjectMediaPlaylistFactory(std::move(factory), ¬ifier);
|
|
|
|
|
|
|
|
EXPECT_TRUE(notifier.Init());
|
|
|
|
MediaInfo media_info;
|
2017-10-07 00:01:56 +00:00
|
|
|
media_info.set_init_segment_name("anything/video/path/to/init.mp4");
|
2017-09-08 17:52:48 +00:00
|
|
|
uint32_t stream_id;
|
|
|
|
EXPECT_TRUE(notifier.NotifyNewStream(media_info, "video/playlist.m3u8",
|
|
|
|
"name", "groupid", &stream_id));
|
|
|
|
EXPECT_TRUE(
|
2017-10-07 00:01:56 +00:00
|
|
|
notifier.NotifyNewSegment(stream_id, "anything/video/path/to/media1.m4s",
|
2017-09-08 17:52:48 +00:00
|
|
|
kAnyStartTime, kAnyDuration, 0, kAnySize));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that when segment path's prefix and output dir match, then the
|
|
|
|
// prefix is stripped from segment path.
|
|
|
|
TEST_F(SimpleHlsNotifierTest, RebaseAbsoluteSegmentPrefixAndOutputDirMatch) {
|
2016-04-16 22:58:47 +00:00
|
|
|
const char kAbsoluteOutputDir[] = "/tmp/something/";
|
2018-01-17 23:43:41 +00:00
|
|
|
hls_params_.master_playlist_output =
|
|
|
|
std::string(kAbsoluteOutputDir) + kMasterPlaylistName;
|
|
|
|
SimpleHlsNotifier test_notifier(hls_params_);
|
2016-04-16 22:58:47 +00:00
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<MockMasterPlaylist> mock_master_playlist(
|
|
|
|
new MockMasterPlaylist());
|
|
|
|
std::unique_ptr<MockMediaPlaylistFactory> factory(
|
|
|
|
new MockMediaPlaylistFactory());
|
2016-04-16 22:58:47 +00:00
|
|
|
|
|
|
|
// Pointer released by SimpleHlsNotifier.
|
|
|
|
MockMediaPlaylist* mock_media_playlist =
|
2018-04-14 01:26:02 +00:00
|
|
|
new MockMediaPlaylist("playlist.m3u8", "", "");
|
2016-04-16 22:58:47 +00:00
|
|
|
|
2017-09-08 17:52:48 +00:00
|
|
|
EXPECT_CALL(*mock_media_playlist, SetMediaInfo(_)).WillOnce(Return(true));
|
2016-04-16 22:58:47 +00:00
|
|
|
|
|
|
|
// Verify that the output_dir is stripped and then kTestPrefix is prepended.
|
|
|
|
EXPECT_CALL(*mock_media_playlist,
|
2017-05-01 20:38:58 +00:00
|
|
|
AddSegment("http://testprefix.com/media1.ts", _, _, _, _));
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_CALL(*factory, CreateMock(_, StrEq("video_playlist.m3u8"),
|
|
|
|
StrEq("name"), StrEq("groupid")))
|
2016-04-16 22:58:47 +00:00
|
|
|
.WillOnce(Return(mock_media_playlist));
|
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
InjectMasterPlaylist(std::move(mock_master_playlist), &test_notifier);
|
|
|
|
InjectMediaPlaylistFactory(std::move(factory), &test_notifier);
|
2016-04-16 22:58:47 +00:00
|
|
|
EXPECT_TRUE(test_notifier.Init());
|
|
|
|
MediaInfo media_info;
|
|
|
|
uint32_t stream_id;
|
|
|
|
EXPECT_TRUE(test_notifier.NotifyNewStream(media_info, "video_playlist.m3u8",
|
|
|
|
"name", "groupid", &stream_id));
|
|
|
|
|
|
|
|
EXPECT_TRUE(
|
|
|
|
test_notifier.NotifyNewSegment(stream_id, "/tmp/something/media1.ts",
|
2017-05-01 20:38:58 +00:00
|
|
|
kAnyStartTime, kAnyDuration, 0, kAnySize));
|
2016-04-16 22:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the paths don't match at all and they are both absolute and completely
|
|
|
|
// different, then keep it as is.
|
|
|
|
TEST_F(SimpleHlsNotifierTest,
|
2017-09-08 17:52:48 +00:00
|
|
|
RebaseAbsoluteSegmentCompletelyDifferentDirectory) {
|
2016-04-16 22:58:47 +00:00
|
|
|
const char kAbsoluteOutputDir[] = "/tmp/something/";
|
2018-01-17 23:43:41 +00:00
|
|
|
hls_params_.master_playlist_output =
|
|
|
|
std::string(kAbsoluteOutputDir) + kMasterPlaylistName;
|
|
|
|
SimpleHlsNotifier test_notifier(hls_params_);
|
2016-04-16 22:58:47 +00:00
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<MockMasterPlaylist> mock_master_playlist(
|
|
|
|
new MockMasterPlaylist());
|
|
|
|
std::unique_ptr<MockMediaPlaylistFactory> factory(
|
|
|
|
new MockMediaPlaylistFactory());
|
2016-04-16 22:58:47 +00:00
|
|
|
|
|
|
|
// Pointer released by SimpleHlsNotifier.
|
|
|
|
MockMediaPlaylist* mock_media_playlist =
|
2018-04-14 01:26:02 +00:00
|
|
|
new MockMediaPlaylist("playlist.m3u8", "", "");
|
2016-04-16 22:58:47 +00:00
|
|
|
|
2017-09-08 17:52:48 +00:00
|
|
|
EXPECT_CALL(*mock_media_playlist, SetMediaInfo(_)).WillOnce(Return(true));
|
2017-06-03 00:05:47 +00:00
|
|
|
EXPECT_CALL(*mock_media_playlist,
|
|
|
|
AddSegment("http://testprefix.com//var/somewhereelse/media1.ts",
|
2017-05-01 20:38:58 +00:00
|
|
|
_, _, _, _));
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_CALL(*factory, CreateMock(_, StrEq("video_playlist.m3u8"),
|
|
|
|
StrEq("name"), StrEq("groupid")))
|
2016-04-16 22:58:47 +00:00
|
|
|
.WillOnce(Return(mock_media_playlist));
|
|
|
|
|
2016-08-17 17:41:40 +00:00
|
|
|
InjectMasterPlaylist(std::move(mock_master_playlist), &test_notifier);
|
|
|
|
InjectMediaPlaylistFactory(std::move(factory), &test_notifier);
|
2016-04-16 22:58:47 +00:00
|
|
|
EXPECT_TRUE(test_notifier.Init());
|
|
|
|
MediaInfo media_info;
|
|
|
|
media_info.set_segment_template("/var/somewhereelse/media$Number$.ts");
|
|
|
|
uint32_t stream_id;
|
|
|
|
EXPECT_TRUE(test_notifier.NotifyNewStream(media_info, "video_playlist.m3u8",
|
|
|
|
"name", "groupid", &stream_id));
|
|
|
|
EXPECT_TRUE(
|
|
|
|
test_notifier.NotifyNewSegment(stream_id, "/var/somewhereelse/media1.ts",
|
2017-05-01 20:38:58 +00:00
|
|
|
kAnyStartTime, kAnyDuration, 0, kAnySize));
|
2016-04-16 22:58:47 +00:00
|
|
|
}
|
|
|
|
|
2017-06-03 00:05:47 +00:00
|
|
|
TEST_F(SimpleHlsNotifierTest, Flush) {
|
2018-01-17 23:43:41 +00:00
|
|
|
SimpleHlsNotifier notifier(hls_params_);
|
2017-06-03 00:05:47 +00:00
|
|
|
std::unique_ptr<MockMasterPlaylist> mock_master_playlist(
|
|
|
|
new MockMasterPlaylist());
|
|
|
|
EXPECT_CALL(*mock_master_playlist,
|
2018-02-02 17:14:46 +00:00
|
|
|
WriteMasterPlaylist(StrEq(kTestPrefix), StrEq(kAnyOutputDir), _))
|
2017-06-03 00:05:47 +00:00
|
|
|
.WillOnce(Return(true));
|
2017-05-01 20:38:58 +00:00
|
|
|
InjectMasterPlaylist(std::move(mock_master_playlist), ¬ifier);
|
|
|
|
EXPECT_TRUE(notifier.Init());
|
|
|
|
EXPECT_TRUE(notifier.Flush());
|
2017-06-03 00:05:47 +00:00
|
|
|
}
|
|
|
|
|
2016-03-25 08:40:15 +00:00
|
|
|
TEST_F(SimpleHlsNotifierTest, NotifyNewStream) {
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<MockMasterPlaylist> mock_master_playlist(
|
|
|
|
new MockMasterPlaylist());
|
|
|
|
std::unique_ptr<MockMediaPlaylistFactory> factory(
|
|
|
|
new MockMediaPlaylistFactory());
|
2016-03-25 08:40:15 +00:00
|
|
|
|
|
|
|
// Pointer released by SimpleHlsNotifier.
|
2016-04-20 22:23:19 +00:00
|
|
|
MockMediaPlaylist* mock_media_playlist =
|
2018-04-14 01:26:02 +00:00
|
|
|
new MockMediaPlaylist("playlist.m3u8", "", "");
|
2016-03-25 08:40:15 +00:00
|
|
|
|
|
|
|
EXPECT_CALL(*mock_media_playlist, SetMediaInfo(_)).WillOnce(Return(true));
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_CALL(*factory, CreateMock(_, StrEq("video_playlist.m3u8"),
|
|
|
|
StrEq("name"), StrEq("groupid")))
|
2016-03-25 08:40:15 +00:00
|
|
|
.WillOnce(Return(mock_media_playlist));
|
|
|
|
|
2018-01-17 23:43:41 +00:00
|
|
|
SimpleHlsNotifier notifier(hls_params_);
|
2017-05-01 20:38:58 +00:00
|
|
|
|
|
|
|
InjectMasterPlaylist(std::move(mock_master_playlist), ¬ifier);
|
|
|
|
InjectMediaPlaylistFactory(std::move(factory), ¬ifier);
|
|
|
|
EXPECT_TRUE(notifier.Init());
|
2016-03-25 08:40:15 +00:00
|
|
|
MediaInfo media_info;
|
|
|
|
uint32_t stream_id;
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_TRUE(notifier.NotifyNewStream(media_info, "video_playlist.m3u8",
|
|
|
|
"name", "groupid", &stream_id));
|
|
|
|
EXPECT_EQ(1u, NumRegisteredMediaPlaylists(notifier));
|
2016-03-25 08:40:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SimpleHlsNotifierTest, NotifyNewSegment) {
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<MockMasterPlaylist> mock_master_playlist(
|
|
|
|
new MockMasterPlaylist());
|
|
|
|
std::unique_ptr<MockMediaPlaylistFactory> factory(
|
|
|
|
new MockMediaPlaylistFactory());
|
2016-03-25 08:40:15 +00:00
|
|
|
|
|
|
|
// Pointer released by SimpleHlsNotifier.
|
2016-04-20 22:23:19 +00:00
|
|
|
MockMediaPlaylist* mock_media_playlist =
|
2018-04-14 01:26:02 +00:00
|
|
|
new MockMediaPlaylist("playlist.m3u8", "", "");
|
2016-03-25 08:40:15 +00:00
|
|
|
|
|
|
|
EXPECT_CALL(*mock_media_playlist, SetMediaInfo(_)).WillOnce(Return(true));
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_CALL(*factory, CreateMock(_, _, _, _))
|
2016-03-25 08:40:15 +00:00
|
|
|
.WillOnce(Return(mock_media_playlist));
|
|
|
|
|
|
|
|
const uint64_t kStartTime = 1328;
|
|
|
|
const uint64_t kDuration = 398407;
|
|
|
|
const uint64_t kSize = 6595840;
|
|
|
|
const std::string segment_name = "segmentname";
|
|
|
|
EXPECT_CALL(*mock_media_playlist,
|
2017-06-03 00:05:47 +00:00
|
|
|
AddSegment(StrEq(kTestPrefix + segment_name), kStartTime,
|
2017-05-01 20:38:58 +00:00
|
|
|
kDuration, 203, kSize));
|
2017-06-03 00:05:47 +00:00
|
|
|
|
|
|
|
const double kLongestSegmentDuration = 11.3;
|
|
|
|
const uint32_t kTargetDuration = 12; // ceil(kLongestSegmentDuration).
|
|
|
|
EXPECT_CALL(*mock_media_playlist, GetLongestSegmentDuration())
|
|
|
|
.WillOnce(Return(kLongestSegmentDuration));
|
2016-03-25 08:40:15 +00:00
|
|
|
|
2018-01-17 23:43:41 +00:00
|
|
|
SimpleHlsNotifier notifier(hls_params_);
|
2017-06-03 00:05:47 +00:00
|
|
|
MockMasterPlaylist* mock_master_playlist_ptr = mock_master_playlist.get();
|
2017-05-01 20:38:58 +00:00
|
|
|
InjectMasterPlaylist(std::move(mock_master_playlist), ¬ifier);
|
|
|
|
InjectMediaPlaylistFactory(std::move(factory), ¬ifier);
|
|
|
|
EXPECT_TRUE(notifier.Init());
|
2016-03-25 08:40:15 +00:00
|
|
|
MediaInfo media_info;
|
|
|
|
uint32_t stream_id;
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_TRUE(notifier.NotifyNewStream(media_info, "playlist.m3u8", "name",
|
|
|
|
"groupid", &stream_id));
|
2016-03-25 08:40:15 +00:00
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_TRUE(notifier.NotifyNewSegment(stream_id, segment_name, kStartTime,
|
|
|
|
kDuration, 203, kSize));
|
2017-06-03 00:05:47 +00:00
|
|
|
|
|
|
|
Mock::VerifyAndClearExpectations(mock_master_playlist_ptr);
|
|
|
|
Mock::VerifyAndClearExpectations(mock_media_playlist);
|
|
|
|
|
|
|
|
EXPECT_CALL(*mock_master_playlist_ptr,
|
2018-02-02 17:14:46 +00:00
|
|
|
WriteMasterPlaylist(StrEq(kTestPrefix), StrEq(kAnyOutputDir),
|
|
|
|
ElementsAre(mock_media_playlist)))
|
2017-06-03 00:05:47 +00:00
|
|
|
.WillOnce(Return(true));
|
|
|
|
EXPECT_CALL(*mock_media_playlist, SetTargetDuration(kTargetDuration))
|
|
|
|
.Times(1);
|
|
|
|
EXPECT_CALL(*mock_media_playlist,
|
|
|
|
WriteToFile(StrEq(
|
|
|
|
base::FilePath::FromUTF8Unsafe(kAnyOutputDir)
|
|
|
|
.Append(base::FilePath::FromUTF8Unsafe("playlist.m3u8"))
|
|
|
|
.AsUTF8Unsafe())))
|
|
|
|
.WillOnce(Return(true));
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_TRUE(notifier.Flush());
|
2016-03-25 08:40:15 +00:00
|
|
|
}
|
|
|
|
|
2018-01-31 02:30:19 +00:00
|
|
|
TEST_F(SimpleHlsNotifierTest, NotifyKeyFrame) {
|
|
|
|
// Pointer released by SimpleHlsNotifier.
|
|
|
|
MockMediaPlaylist* mock_media_playlist =
|
2018-04-14 01:26:02 +00:00
|
|
|
new MockMediaPlaylist("playlist.m3u8", "", "");
|
2018-01-31 02:30:19 +00:00
|
|
|
SimpleHlsNotifier notifier(hls_params_);
|
|
|
|
const uint32_t stream_id =
|
|
|
|
SetupStream(kCencProtectionScheme, mock_media_playlist, ¬ifier);
|
|
|
|
|
|
|
|
const uint64_t kTimestamp = 12345;
|
|
|
|
const uint64_t kStartByteOffset = 888;
|
|
|
|
const uint64_t kSize = 555;
|
|
|
|
EXPECT_CALL(*mock_media_playlist,
|
|
|
|
AddKeyFrame(kTimestamp, kStartByteOffset, kSize));
|
|
|
|
EXPECT_TRUE(
|
|
|
|
notifier.NotifyKeyFrame(stream_id, kTimestamp, kStartByteOffset, kSize));
|
|
|
|
}
|
|
|
|
|
2016-03-25 08:40:15 +00:00
|
|
|
TEST_F(SimpleHlsNotifierTest, NotifyNewSegmentWithoutStreamsRegistered) {
|
2018-01-17 23:43:41 +00:00
|
|
|
SimpleHlsNotifier notifier(hls_params_);
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_TRUE(notifier.Init());
|
|
|
|
EXPECT_FALSE(notifier.NotifyNewSegment(1u, "anything", 0u, 0u, 0u, 0u));
|
2016-03-25 08:40:15 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 00:22:37 +00:00
|
|
|
TEST_F(SimpleHlsNotifierTest, NotifyEncryptionUpdateWidevine) {
|
2016-03-25 08:40:15 +00:00
|
|
|
// Pointer released by SimpleHlsNotifier.
|
2016-04-20 22:23:19 +00:00
|
|
|
MockMediaPlaylist* mock_media_playlist =
|
2018-04-14 01:26:02 +00:00
|
|
|
new MockMediaPlaylist("playlist.m3u8", "", "");
|
2018-01-17 23:43:41 +00:00
|
|
|
SimpleHlsNotifier notifier(hls_params_);
|
2017-04-04 20:57:50 +00:00
|
|
|
const uint32_t stream_id =
|
2017-05-01 20:38:58 +00:00
|
|
|
SetupStream(kSampleAesProtectionScheme, mock_media_playlist, ¬ifier);
|
2016-03-25 08:40:15 +00:00
|
|
|
|
2016-06-24 00:22:37 +00:00
|
|
|
const std::vector<uint8_t> iv(16, 0x45);
|
2016-03-25 08:40:15 +00:00
|
|
|
|
|
|
|
media::WidevinePsshData widevine_pssh_data;
|
|
|
|
widevine_pssh_data.set_provider("someprovider");
|
|
|
|
widevine_pssh_data.set_content_id("contentid");
|
|
|
|
const uint8_t kAnyKeyId[] = {
|
2017-05-01 20:38:58 +00:00
|
|
|
0x11, 0x22, 0x33, 0x44, 0x11, 0x22, 0x33, 0x44,
|
|
|
|
0x11, 0x22, 0x33, 0x44, 0x11, 0x22, 0x33, 0x44,
|
2016-03-25 08:40:15 +00:00
|
|
|
};
|
2017-04-04 20:57:50 +00:00
|
|
|
std::vector<uint8_t> any_key_id(kAnyKeyId, kAnyKeyId + arraysize(kAnyKeyId));
|
2016-03-25 08:40:15 +00:00
|
|
|
widevine_pssh_data.add_key_id()->assign(kAnyKeyId,
|
|
|
|
kAnyKeyId + arraysize(kAnyKeyId));
|
2016-05-19 23:43:13 +00:00
|
|
|
std::string widevine_pssh_data_str = widevine_pssh_data.SerializeAsString();
|
2017-04-04 20:57:50 +00:00
|
|
|
|
2016-05-19 23:43:13 +00:00
|
|
|
EXPECT_TRUE(!widevine_pssh_data_str.empty());
|
2016-03-25 08:40:15 +00:00
|
|
|
std::vector<uint8_t> pssh_data(widevine_pssh_data_str.begin(),
|
|
|
|
widevine_pssh_data_str.end());
|
|
|
|
|
2018-05-03 00:54:10 +00:00
|
|
|
media::PsshBoxBuilder pssh_builder;
|
|
|
|
pssh_builder.set_pssh_data(pssh_data);
|
|
|
|
pssh_builder.set_system_id(widevine_system_id_.data(),
|
|
|
|
widevine_system_id_.size());
|
|
|
|
pssh_builder.add_key_id(any_key_id);
|
2017-04-04 20:57:50 +00:00
|
|
|
|
2016-03-25 08:40:15 +00:00
|
|
|
const char kExpectedJson[] =
|
2018-05-04 21:26:39 +00:00
|
|
|
R"({"key_ids":["11223344112233441122334411223344"],)"
|
|
|
|
R"("provider":"someprovider","content_id":"Y29udGVudGlk"})";
|
2016-03-25 08:40:15 +00:00
|
|
|
std::string expected_json_base64;
|
|
|
|
base::Base64Encode(kExpectedJson, &expected_json_base64);
|
|
|
|
|
2017-04-04 20:57:50 +00:00
|
|
|
std::string expected_pssh_base64;
|
2018-05-03 00:54:10 +00:00
|
|
|
const std::vector<uint8_t> pssh_box = pssh_builder.CreateBox();
|
2017-04-04 20:57:50 +00:00
|
|
|
base::Base64Encode(std::string(pssh_box.begin(), pssh_box.end()),
|
|
|
|
&expected_pssh_base64);
|
|
|
|
|
|
|
|
EXPECT_CALL(*mock_media_playlist,
|
|
|
|
AddEncryptionInfo(
|
2017-05-01 20:38:58 +00:00
|
|
|
_, StrEq("data:text/plain;base64," + expected_json_base64),
|
|
|
|
StrEq(""), StrEq("0x45454545454545454545454545454545"),
|
|
|
|
StrEq("com.widevine"), _));
|
|
|
|
EXPECT_CALL(*mock_media_playlist,
|
|
|
|
AddEncryptionInfo(
|
|
|
|
_, StrEq("data:text/plain;base64," + expected_pssh_base64),
|
2017-04-04 20:57:50 +00:00
|
|
|
StrEq("0x11223344112233441122334411223344"),
|
|
|
|
StrEq("0x45454545454545454545454545454545"),
|
|
|
|
StrEq("urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"), _));
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_TRUE(notifier.NotifyEncryptionUpdate(
|
2017-04-04 20:57:50 +00:00
|
|
|
stream_id, any_key_id, widevine_system_id_, iv, pssh_box));
|
2016-03-25 08:40:15 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 00:22:37 +00:00
|
|
|
// Verify that key_ids in pssh is optional.
|
|
|
|
TEST_F(SimpleHlsNotifierTest, NotifyEncryptionUpdateWidevineNoKeyidsInPssh) {
|
|
|
|
// Pointer released by SimpleHlsNotifier.
|
|
|
|
MockMediaPlaylist* mock_media_playlist =
|
2018-04-14 01:26:02 +00:00
|
|
|
new MockMediaPlaylist("playlist.m3u8", "", "");
|
2018-01-17 23:43:41 +00:00
|
|
|
SimpleHlsNotifier notifier(hls_params_);
|
2017-04-04 20:57:50 +00:00
|
|
|
const uint32_t stream_id =
|
2017-05-01 20:38:58 +00:00
|
|
|
SetupStream(kSampleAesProtectionScheme, mock_media_playlist, ¬ifier);
|
2016-06-24 00:22:37 +00:00
|
|
|
|
|
|
|
const std::vector<uint8_t> iv(16, 0x45);
|
|
|
|
|
|
|
|
media::WidevinePsshData widevine_pssh_data;
|
|
|
|
widevine_pssh_data.set_provider("someprovider");
|
|
|
|
widevine_pssh_data.set_content_id("contentid");
|
|
|
|
std::string widevine_pssh_data_str = widevine_pssh_data.SerializeAsString();
|
|
|
|
EXPECT_TRUE(!widevine_pssh_data_str.empty());
|
|
|
|
std::vector<uint8_t> pssh_data(widevine_pssh_data_str.begin(),
|
|
|
|
widevine_pssh_data_str.end());
|
|
|
|
|
|
|
|
const char kExpectedJson[] =
|
2018-05-04 21:26:39 +00:00
|
|
|
R"({"key_ids":["11223344112233441122334411223344"],)"
|
|
|
|
R"("provider":"someprovider","content_id":"Y29udGVudGlk"})";
|
2016-06-24 00:22:37 +00:00
|
|
|
std::string expected_json_base64;
|
|
|
|
base::Base64Encode(kExpectedJson, &expected_json_base64);
|
|
|
|
|
2018-05-03 00:54:10 +00:00
|
|
|
media::PsshBoxBuilder pssh_builder;
|
|
|
|
pssh_builder.set_pssh_data(pssh_data);
|
|
|
|
pssh_builder.set_system_id(widevine_system_id_.data(),
|
|
|
|
widevine_system_id_.size());
|
2017-04-04 20:57:50 +00:00
|
|
|
|
|
|
|
std::string expected_pssh_base64;
|
2018-05-03 00:54:10 +00:00
|
|
|
const std::vector<uint8_t> pssh_box = pssh_builder.CreateBox();
|
2017-04-04 20:57:50 +00:00
|
|
|
base::Base64Encode(std::string(pssh_box.begin(), pssh_box.end()),
|
|
|
|
&expected_pssh_base64);
|
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_CALL(*mock_media_playlist,
|
|
|
|
AddEncryptionInfo(
|
|
|
|
_, StrEq("data:text/plain;base64," + expected_json_base64),
|
|
|
|
StrEq(""), StrEq("0x45454545454545454545454545454545"),
|
|
|
|
StrEq("com.widevine"), _));
|
|
|
|
EXPECT_CALL(*mock_media_playlist,
|
|
|
|
AddEncryptionInfo(
|
|
|
|
_, StrEq("data:text/plain;base64," + expected_pssh_base64),
|
|
|
|
StrEq("0x11223344112233441122334411223344"),
|
|
|
|
StrEq("0x45454545454545454545454545454545"),
|
|
|
|
StrEq("urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"), _));
|
2016-06-24 00:22:37 +00:00
|
|
|
const uint8_t kAnyKeyId[] = {
|
2017-05-01 20:38:58 +00:00
|
|
|
0x11, 0x22, 0x33, 0x44, 0x11, 0x22, 0x33, 0x44,
|
|
|
|
0x11, 0x22, 0x33, 0x44, 0x11, 0x22, 0x33, 0x44,
|
2016-06-24 00:22:37 +00:00
|
|
|
};
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_TRUE(notifier.NotifyEncryptionUpdate(
|
2016-06-24 00:22:37 +00:00
|
|
|
stream_id,
|
|
|
|
std::vector<uint8_t>(kAnyKeyId, kAnyKeyId + arraysize(kAnyKeyId)),
|
2017-04-04 20:57:50 +00:00
|
|
|
widevine_system_id_, iv, pssh_box));
|
2016-06-24 00:22:37 +00:00
|
|
|
}
|
2016-03-25 08:40:15 +00:00
|
|
|
|
2017-11-12 22:56:25 +00:00
|
|
|
TEST_F(SimpleHlsNotifierTest, NotifyEncryptionUpdateIdentityKey) {
|
2016-03-25 08:40:15 +00:00
|
|
|
// Pointer released by SimpleHlsNotifier.
|
2016-04-20 22:23:19 +00:00
|
|
|
MockMediaPlaylist* mock_media_playlist =
|
2018-04-14 01:26:02 +00:00
|
|
|
new MockMediaPlaylist("playlist.m3u8", "", "");
|
2018-01-17 23:43:41 +00:00
|
|
|
SimpleHlsNotifier notifier(hls_params_);
|
2017-04-04 20:57:50 +00:00
|
|
|
const uint32_t stream_id =
|
2017-05-01 20:38:58 +00:00
|
|
|
SetupStream(kSampleAesProtectionScheme, mock_media_playlist, ¬ifier);
|
2016-06-24 00:22:37 +00:00
|
|
|
|
|
|
|
const std::vector<uint8_t> key_id(16, 0x23);
|
|
|
|
const std::vector<uint8_t> iv(16, 0x45);
|
|
|
|
const std::vector<uint8_t> dummy_pssh_data(10, 'p');
|
|
|
|
|
|
|
|
std::string expected_key_uri_base64;
|
|
|
|
base::Base64Encode(std::string(key_id.begin(), key_id.end()),
|
|
|
|
&expected_key_uri_base64);
|
2016-03-25 08:40:15 +00:00
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_CALL(*mock_media_playlist,
|
|
|
|
AddEncryptionInfo(
|
|
|
|
_, StrEq("data:text/plain;base64," + expected_key_uri_base64),
|
|
|
|
StrEq(""), StrEq("0x45454545454545454545454545454545"),
|
|
|
|
StrEq("identity"), _));
|
|
|
|
EXPECT_TRUE(notifier.NotifyEncryptionUpdate(
|
2016-06-24 00:22:37 +00:00
|
|
|
stream_id, key_id, common_system_id_, iv, dummy_pssh_data));
|
|
|
|
}
|
2016-03-25 08:40:15 +00:00
|
|
|
|
2016-06-24 00:22:37 +00:00
|
|
|
// Verify that when there are multiple key IDs in PSSH, the key ID that is
|
|
|
|
// passed to NotifyEncryptionUpdate() is the first key ID in the json format.
|
|
|
|
// Also verify that content_id is optional.
|
|
|
|
TEST_F(SimpleHlsNotifierTest, WidevineMultipleKeyIdsNoContentIdInPssh) {
|
|
|
|
// Pointer released by SimpleHlsNotifier.
|
|
|
|
MockMediaPlaylist* mock_media_playlist =
|
2018-04-14 01:26:02 +00:00
|
|
|
new MockMediaPlaylist("playlist.m3u8", "", "");
|
2018-01-17 23:43:41 +00:00
|
|
|
SimpleHlsNotifier notifier(hls_params_);
|
2017-04-04 20:57:50 +00:00
|
|
|
uint32_t stream_id =
|
2017-05-01 20:38:58 +00:00
|
|
|
SetupStream(kSampleAesProtectionScheme, mock_media_playlist, ¬ifier);
|
2016-03-25 08:40:15 +00:00
|
|
|
|
|
|
|
std::vector<uint8_t> iv(16, 0x45);
|
|
|
|
|
|
|
|
media::WidevinePsshData widevine_pssh_data;
|
|
|
|
widevine_pssh_data.set_provider("someprovider");
|
|
|
|
const uint8_t kFirstKeyId[] = {
|
2017-05-01 20:38:58 +00:00
|
|
|
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
|
|
|
|
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
|
2016-03-25 08:40:15 +00:00
|
|
|
};
|
|
|
|
const uint8_t kSecondKeyId[] = {
|
2017-05-01 20:38:58 +00:00
|
|
|
0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
|
|
|
|
0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
|
2016-03-25 08:40:15 +00:00
|
|
|
};
|
2017-04-04 20:57:50 +00:00
|
|
|
std::vector<uint8_t> first_keyid(kFirstKeyId,
|
|
|
|
kFirstKeyId + arraysize(kFirstKeyId));
|
|
|
|
std::vector<uint8_t> second_keyid(kSecondKeyId,
|
|
|
|
kSecondKeyId + arraysize(kSecondKeyId));
|
|
|
|
|
2016-03-25 08:40:15 +00:00
|
|
|
widevine_pssh_data.add_key_id()->assign(kFirstKeyId,
|
|
|
|
kFirstKeyId + arraysize(kFirstKeyId));
|
|
|
|
widevine_pssh_data.add_key_id()->assign(
|
|
|
|
kSecondKeyId, kSecondKeyId + arraysize(kSecondKeyId));
|
2016-05-19 23:43:13 +00:00
|
|
|
std::string widevine_pssh_data_str = widevine_pssh_data.SerializeAsString();
|
|
|
|
EXPECT_TRUE(!widevine_pssh_data_str.empty());
|
2016-03-25 08:40:15 +00:00
|
|
|
std::vector<uint8_t> pssh_data(widevine_pssh_data_str.begin(),
|
|
|
|
widevine_pssh_data_str.end());
|
|
|
|
|
2018-05-03 00:54:10 +00:00
|
|
|
media::PsshBoxBuilder pssh_builder;
|
|
|
|
pssh_builder.set_pssh_data(pssh_data);
|
|
|
|
pssh_builder.set_system_id(widevine_system_id_.data(),
|
|
|
|
widevine_system_id_.size());
|
|
|
|
pssh_builder.add_key_id(first_keyid);
|
|
|
|
pssh_builder.add_key_id(second_keyid);
|
2017-04-04 20:57:50 +00:00
|
|
|
|
2016-03-25 08:40:15 +00:00
|
|
|
const char kExpectedJson[] =
|
2018-05-04 21:26:39 +00:00
|
|
|
R"({)"
|
|
|
|
R"("key_ids":["22222222222222222222222222222222",)"
|
|
|
|
R"("11111111111111111111111111111111"],)"
|
|
|
|
R"("provider":"someprovider"})";
|
2016-03-25 08:40:15 +00:00
|
|
|
std::string expected_json_base64;
|
|
|
|
base::Base64Encode(kExpectedJson, &expected_json_base64);
|
|
|
|
|
2017-04-04 20:57:50 +00:00
|
|
|
std::string expected_pssh_base64;
|
2018-05-03 00:54:10 +00:00
|
|
|
const std::vector<uint8_t> pssh_box = pssh_builder.CreateBox();
|
2017-04-04 20:57:50 +00:00
|
|
|
base::Base64Encode(std::string(pssh_box.begin(), pssh_box.end()),
|
|
|
|
&expected_pssh_base64);
|
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_CALL(*mock_media_playlist,
|
|
|
|
AddEncryptionInfo(
|
|
|
|
_, StrEq("data:text/plain;base64," + expected_json_base64),
|
|
|
|
StrEq(""), StrEq("0x45454545454545454545454545454545"),
|
|
|
|
StrEq("com.widevine"), _));
|
2017-04-04 20:57:50 +00:00
|
|
|
|
|
|
|
EXPECT_CALL(*mock_media_playlist,
|
|
|
|
AddEncryptionInfo(
|
2017-05-01 20:38:58 +00:00
|
|
|
_, StrEq("data:text/plain;base64," + expected_pssh_base64),
|
2017-04-04 20:57:50 +00:00
|
|
|
StrEq("0x22222222222222222222222222222222"),
|
|
|
|
StrEq("0x45454545454545454545454545454545"),
|
|
|
|
StrEq("urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"), _));
|
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_TRUE(notifier.NotifyEncryptionUpdate(
|
2016-03-25 08:40:15 +00:00
|
|
|
stream_id,
|
|
|
|
// Use the second key id here so that it will be thre first one in the
|
|
|
|
// key_ids array in the JSON.
|
2017-04-04 20:57:50 +00:00
|
|
|
second_keyid, widevine_system_id_, iv, pssh_box));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that the encryption scheme set in MediaInfo is passed to
|
|
|
|
// MediaPlaylist::AddEncryptionInfo().
|
|
|
|
TEST_F(SimpleHlsNotifierTest, EncryptionScheme) {
|
|
|
|
// Pointer released by SimpleHlsNotifier.
|
|
|
|
MockMediaPlaylist* mock_media_playlist =
|
2018-04-14 01:26:02 +00:00
|
|
|
new MockMediaPlaylist("playlist.m3u8", "", "");
|
2018-01-17 23:43:41 +00:00
|
|
|
hls_params_.key_uri = kIdentityKeyUri;
|
|
|
|
SimpleHlsNotifier notifier(hls_params_);
|
2017-04-04 20:57:50 +00:00
|
|
|
const uint32_t stream_id =
|
2017-05-01 20:38:58 +00:00
|
|
|
SetupStream(kCencProtectionScheme, mock_media_playlist, ¬ifier);
|
2017-04-04 20:57:50 +00:00
|
|
|
|
|
|
|
const std::vector<uint8_t> key_id(16, 0x23);
|
|
|
|
const std::vector<uint8_t> iv(16, 0x45);
|
|
|
|
const std::vector<uint8_t> dummy_pssh_data(10, 'p');
|
|
|
|
|
2017-11-12 22:56:25 +00:00
|
|
|
EXPECT_CALL(*mock_media_playlist,
|
|
|
|
AddEncryptionInfo(MediaPlaylist::EncryptionMethod::kSampleAesCenc,
|
|
|
|
StrEq(kIdentityKeyUri), StrEq(""),
|
|
|
|
StrEq("0x45454545454545454545454545454545"),
|
|
|
|
StrEq("identity"), _));
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_TRUE(notifier.NotifyEncryptionUpdate(
|
2017-04-04 20:57:50 +00:00
|
|
|
stream_id, key_id, common_system_id_, iv, dummy_pssh_data));
|
|
|
|
}
|
|
|
|
|
2018-08-07 23:01:43 +00:00
|
|
|
// Verify that the FairPlay systemID is correctly handled when constructing
|
Fairplay key system support
Support generation of fairplay key system tag: "com.apple.streamingkeydelivery" when --pssh
includes fairplay key system id:
// Unofficial fairplay system id extracted from
// https://forums.developer.apple.com/thread/6185.
const uint8_t kFairplaySystemId[] = {0x29, 0x70, 0x1F, 0xE4, 0x3C, 0xC7,
0x4A, 0x34, 0x8C, 0x5B, 0xAE, 0x90,
0xC7, 0x43, 0x9A, 0x47};
Closes #258
2017-08-08 17:31:40 +00:00
|
|
|
// encryption info.
|
2018-08-07 23:01:43 +00:00
|
|
|
TEST_F(SimpleHlsNotifierTest, NotifyEncryptionUpdateFairPlay) {
|
Fairplay key system support
Support generation of fairplay key system tag: "com.apple.streamingkeydelivery" when --pssh
includes fairplay key system id:
// Unofficial fairplay system id extracted from
// https://forums.developer.apple.com/thread/6185.
const uint8_t kFairplaySystemId[] = {0x29, 0x70, 0x1F, 0xE4, 0x3C, 0xC7,
0x4A, 0x34, 0x8C, 0x5B, 0xAE, 0x90,
0xC7, 0x43, 0x9A, 0x47};
Closes #258
2017-08-08 17:31:40 +00:00
|
|
|
// Pointer released by SimpleHlsNotifier.
|
|
|
|
MockMediaPlaylist* mock_media_playlist =
|
2018-04-14 01:26:02 +00:00
|
|
|
new MockMediaPlaylist("playlist.m3u8", "", "");
|
2018-01-17 23:43:41 +00:00
|
|
|
hls_params_.playlist_type = kLivePlaylist;
|
2018-08-07 23:01:43 +00:00
|
|
|
hls_params_.key_uri = kFairPlayKeyUri;
|
2018-01-17 23:43:41 +00:00
|
|
|
SimpleHlsNotifier notifier(hls_params_);
|
Fairplay key system support
Support generation of fairplay key system tag: "com.apple.streamingkeydelivery" when --pssh
includes fairplay key system id:
// Unofficial fairplay system id extracted from
// https://forums.developer.apple.com/thread/6185.
const uint8_t kFairplaySystemId[] = {0x29, 0x70, 0x1F, 0xE4, 0x3C, 0xC7,
0x4A, 0x34, 0x8C, 0x5B, 0xAE, 0x90,
0xC7, 0x43, 0x9A, 0x47};
Closes #258
2017-08-08 17:31:40 +00:00
|
|
|
const uint32_t stream_id =
|
|
|
|
SetupStream(kSampleAesProtectionScheme, mock_media_playlist, ¬ifier);
|
|
|
|
const std::vector<uint8_t> key_id(16, 0x12);
|
|
|
|
const std::vector<uint8_t> dummy_pssh_data(10, 'p');
|
|
|
|
|
|
|
|
EXPECT_CALL(
|
|
|
|
*mock_media_playlist,
|
2017-11-12 22:56:25 +00:00
|
|
|
AddEncryptionInfo(MediaPlaylist::EncryptionMethod::kSampleAes,
|
2018-08-07 23:01:43 +00:00
|
|
|
StrEq(kFairPlayKeyUri), StrEq(""), StrEq(""),
|
2017-11-12 22:56:25 +00:00
|
|
|
StrEq("com.apple.streamingkeydelivery"), StrEq("1")));
|
Fairplay key system support
Support generation of fairplay key system tag: "com.apple.streamingkeydelivery" when --pssh
includes fairplay key system id:
// Unofficial fairplay system id extracted from
// https://forums.developer.apple.com/thread/6185.
const uint8_t kFairplaySystemId[] = {0x29, 0x70, 0x1F, 0xE4, 0x3C, 0xC7,
0x4A, 0x34, 0x8C, 0x5B, 0xAE, 0x90,
0xC7, 0x43, 0x9A, 0x47};
Closes #258
2017-08-08 17:31:40 +00:00
|
|
|
EXPECT_TRUE(notifier.NotifyEncryptionUpdate(
|
|
|
|
stream_id, key_id, fairplay_system_id_, std::vector<uint8_t>(),
|
|
|
|
dummy_pssh_data));
|
|
|
|
}
|
|
|
|
|
2017-04-04 20:57:50 +00:00
|
|
|
// If using 'cenc' with Widevine, don't output the json form.
|
|
|
|
TEST_F(SimpleHlsNotifierTest, WidevineCencEncryptionScheme) {
|
|
|
|
// Pointer released by SimpleHlsNotifier.
|
|
|
|
MockMediaPlaylist* mock_media_playlist =
|
2018-04-14 01:26:02 +00:00
|
|
|
new MockMediaPlaylist("playlist.m3u8", "", "");
|
2018-01-17 23:43:41 +00:00
|
|
|
SimpleHlsNotifier notifier(hls_params_);
|
2017-04-04 20:57:50 +00:00
|
|
|
const uint32_t stream_id =
|
2017-05-01 20:38:58 +00:00
|
|
|
SetupStream(kCencProtectionScheme, mock_media_playlist, ¬ifier);
|
2017-04-04 20:57:50 +00:00
|
|
|
|
|
|
|
const std::vector<uint8_t> iv(16, 0x45);
|
|
|
|
|
|
|
|
media::WidevinePsshData widevine_pssh_data;
|
|
|
|
widevine_pssh_data.set_provider("someprovider");
|
|
|
|
widevine_pssh_data.set_content_id("contentid");
|
|
|
|
const uint8_t kAnyKeyId[] = {
|
2017-05-01 20:38:58 +00:00
|
|
|
0x11, 0x22, 0x33, 0x44, 0x11, 0x22, 0x33, 0x44,
|
|
|
|
0x11, 0x22, 0x33, 0x44, 0x11, 0x22, 0x33, 0x44,
|
2017-04-04 20:57:50 +00:00
|
|
|
};
|
|
|
|
std::vector<uint8_t> any_key_id(kAnyKeyId, kAnyKeyId + arraysize(kAnyKeyId));
|
|
|
|
widevine_pssh_data.add_key_id()->assign(kAnyKeyId,
|
|
|
|
kAnyKeyId + arraysize(kAnyKeyId));
|
|
|
|
std::string widevine_pssh_data_str = widevine_pssh_data.SerializeAsString();
|
|
|
|
|
|
|
|
EXPECT_TRUE(!widevine_pssh_data_str.empty());
|
|
|
|
std::vector<uint8_t> pssh_data(widevine_pssh_data_str.begin(),
|
|
|
|
widevine_pssh_data_str.end());
|
|
|
|
|
|
|
|
std::string expected_pssh_base64;
|
2018-05-03 00:54:10 +00:00
|
|
|
const std::vector<uint8_t> pssh_box = {'p', 's', 's', 'h'};
|
2017-04-04 20:57:50 +00:00
|
|
|
base::Base64Encode(std::string(pssh_box.begin(), pssh_box.end()),
|
|
|
|
&expected_pssh_base64);
|
|
|
|
|
|
|
|
EXPECT_CALL(*mock_media_playlist,
|
|
|
|
AddEncryptionInfo(
|
2017-05-01 20:38:58 +00:00
|
|
|
_, StrEq("data:text/plain;base64," + expected_pssh_base64),
|
2017-04-04 20:57:50 +00:00
|
|
|
StrEq("0x11223344112233441122334411223344"),
|
|
|
|
StrEq("0x45454545454545454545454545454545"),
|
|
|
|
StrEq("urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"), _));
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_TRUE(notifier.NotifyEncryptionUpdate(
|
2017-04-04 20:57:50 +00:00
|
|
|
stream_id, any_key_id, widevine_system_id_, iv, pssh_box));
|
2016-03-25 08:40:15 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 00:22:37 +00:00
|
|
|
TEST_F(SimpleHlsNotifierTest, WidevineNotifyEncryptionUpdateEmptyIv) {
|
2016-03-25 08:40:15 +00:00
|
|
|
// Pointer released by SimpleHlsNotifier.
|
2016-04-20 22:23:19 +00:00
|
|
|
MockMediaPlaylist* mock_media_playlist =
|
2018-04-14 01:26:02 +00:00
|
|
|
new MockMediaPlaylist("playlist.m3u8", "", "");
|
2018-01-17 23:43:41 +00:00
|
|
|
SimpleHlsNotifier notifier(hls_params_);
|
2017-04-04 20:57:50 +00:00
|
|
|
const uint32_t stream_id =
|
2017-05-01 20:38:58 +00:00
|
|
|
SetupStream(kSampleAesProtectionScheme, mock_media_playlist, ¬ifier);
|
2016-03-25 08:40:15 +00:00
|
|
|
|
|
|
|
media::WidevinePsshData widevine_pssh_data;
|
|
|
|
widevine_pssh_data.set_provider("someprovider");
|
|
|
|
widevine_pssh_data.set_content_id("contentid");
|
|
|
|
const uint8_t kAnyKeyId[] = {
|
2017-05-01 20:38:58 +00:00
|
|
|
0x11, 0x22, 0x33, 0x44, 0x11, 0x22, 0x33, 0x44,
|
|
|
|
0x11, 0x22, 0x33, 0x44, 0x11, 0x22, 0x33, 0x44,
|
2016-03-25 08:40:15 +00:00
|
|
|
};
|
2017-04-04 20:57:50 +00:00
|
|
|
std::vector<uint8_t> any_key_id(kAnyKeyId, kAnyKeyId + arraysize(kAnyKeyId));
|
2016-03-25 08:40:15 +00:00
|
|
|
widevine_pssh_data.add_key_id()->assign(kAnyKeyId,
|
|
|
|
kAnyKeyId + arraysize(kAnyKeyId));
|
2016-05-19 23:43:13 +00:00
|
|
|
std::string widevine_pssh_data_str = widevine_pssh_data.SerializeAsString();
|
|
|
|
EXPECT_TRUE(!widevine_pssh_data_str.empty());
|
2016-03-25 08:40:15 +00:00
|
|
|
std::vector<uint8_t> pssh_data(widevine_pssh_data_str.begin(),
|
|
|
|
widevine_pssh_data_str.end());
|
|
|
|
|
|
|
|
const char kExpectedJson[] =
|
2018-05-04 21:26:39 +00:00
|
|
|
R"({"key_ids":["11223344112233441122334411223344"],)"
|
|
|
|
R"("provider":"someprovider","content_id":"Y29udGVudGlk"})";
|
2016-03-25 08:40:15 +00:00
|
|
|
std::string expected_json_base64;
|
|
|
|
base::Base64Encode(kExpectedJson, &expected_json_base64);
|
|
|
|
|
2018-05-03 00:54:10 +00:00
|
|
|
media::PsshBoxBuilder pssh_builder;
|
|
|
|
pssh_builder.set_pssh_data(pssh_data);
|
|
|
|
pssh_builder.set_system_id(widevine_system_id_.data(),
|
|
|
|
widevine_system_id_.size());
|
|
|
|
pssh_builder.add_key_id(any_key_id);
|
2017-04-04 20:57:50 +00:00
|
|
|
|
|
|
|
EXPECT_CALL(*mock_media_playlist,
|
|
|
|
AddEncryptionInfo(
|
2017-06-16 19:21:52 +00:00
|
|
|
_, StrEq("data:text/plain;base64," + expected_json_base64),
|
|
|
|
StrEq(""), StrEq(""), StrEq("com.widevine"), StrEq("1")));
|
|
|
|
|
|
|
|
EXPECT_CALL(
|
|
|
|
*mock_media_playlist,
|
|
|
|
AddEncryptionInfo(
|
|
|
|
_,
|
|
|
|
StrEq("data:text/plain;base64,"
|
|
|
|
"AAAAS3Bzc2gAAAAA7e+"
|
|
|
|
"LqXnWSs6jyCfc1R0h7QAAACsSEBEiM0QRIjNEESIzRBEiM0QaDHNvb"
|
|
|
|
"WVwcm92aWRlciIJY29udGVudGlk"),
|
|
|
|
StrEq("0x11223344112233441122334411223344"), StrEq(""),
|
|
|
|
StrEq("urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"), StrEq("1")));
|
2018-05-03 00:54:10 +00:00
|
|
|
std::vector<uint8_t> pssh_as_vec = pssh_builder.CreateBox();
|
2017-04-04 20:57:50 +00:00
|
|
|
std::string pssh_in_string(pssh_as_vec.begin(), pssh_as_vec.end());
|
|
|
|
std::string base_64_encoded_pssh;
|
|
|
|
base::Base64Encode(pssh_in_string, &base_64_encoded_pssh);
|
|
|
|
LOG(INFO) << base_64_encoded_pssh;
|
|
|
|
|
2016-03-25 08:40:15 +00:00
|
|
|
std::vector<uint8_t> empty_iv;
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_TRUE(notifier.NotifyEncryptionUpdate(
|
2016-03-25 08:40:15 +00:00
|
|
|
stream_id,
|
|
|
|
std::vector<uint8_t>(kAnyKeyId, kAnyKeyId + arraysize(kAnyKeyId)),
|
2018-05-03 00:54:10 +00:00
|
|
|
widevine_system_id_, empty_iv, pssh_builder.CreateBox()));
|
2016-03-25 08:40:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SimpleHlsNotifierTest, NotifyEncryptionUpdateWithoutStreamsRegistered) {
|
|
|
|
std::vector<uint8_t> system_id;
|
|
|
|
std::vector<uint8_t> iv;
|
|
|
|
std::vector<uint8_t> pssh_data;
|
|
|
|
std::vector<uint8_t> key_id;
|
2018-01-17 23:43:41 +00:00
|
|
|
SimpleHlsNotifier notifier(hls_params_);
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_TRUE(notifier.Init());
|
|
|
|
EXPECT_FALSE(
|
|
|
|
notifier.NotifyEncryptionUpdate(1238u, key_id, system_id, iv, pssh_data));
|
2016-03-25 08:40:15 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 01:33:37 +00:00
|
|
|
TEST_F(SimpleHlsNotifierTest, NotifyCueEvent) {
|
|
|
|
// Pointer released by SimpleHlsNotifier.
|
|
|
|
MockMediaPlaylist* mock_media_playlist =
|
2018-04-14 01:26:02 +00:00
|
|
|
new MockMediaPlaylist("playlist.m3u8", "", "");
|
2018-01-17 23:43:41 +00:00
|
|
|
SimpleHlsNotifier notifier(hls_params_);
|
2018-01-12 01:33:37 +00:00
|
|
|
const uint32_t stream_id =
|
|
|
|
SetupStream(kCencProtectionScheme, mock_media_playlist, ¬ifier);
|
|
|
|
|
|
|
|
EXPECT_CALL(*mock_media_playlist, AddPlacementOpportunity());
|
|
|
|
const uint64_t kCueEventTimestamp = 12345;
|
|
|
|
EXPECT_TRUE(notifier.NotifyCueEvent(stream_id, kCueEventTimestamp));
|
|
|
|
}
|
|
|
|
|
2017-06-03 00:05:47 +00:00
|
|
|
class LiveOrEventSimpleHlsNotifierTest
|
|
|
|
: public SimpleHlsNotifierTest,
|
2017-06-30 20:42:46 +00:00
|
|
|
public ::testing::WithParamInterface<HlsPlaylistType> {
|
2017-06-03 00:05:47 +00:00
|
|
|
protected:
|
|
|
|
LiveOrEventSimpleHlsNotifierTest() : SimpleHlsNotifierTest(GetParam()) {
|
2017-06-30 20:42:46 +00:00
|
|
|
expected_playlist_type_ = GetParam();
|
2017-06-03 00:05:47 +00:00
|
|
|
}
|
|
|
|
|
2017-06-30 20:42:46 +00:00
|
|
|
HlsPlaylistType expected_playlist_type_;
|
2017-06-03 00:05:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(LiveOrEventSimpleHlsNotifierTest, NotifyNewSegment) {
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<MockMasterPlaylist> mock_master_playlist(
|
|
|
|
new MockMasterPlaylist());
|
2017-06-03 00:05:47 +00:00
|
|
|
std::unique_ptr<MockMediaPlaylistFactory> factory(
|
|
|
|
new MockMediaPlaylistFactory());
|
|
|
|
|
|
|
|
// Pointer released by SimpleHlsNotifier.
|
|
|
|
MockMediaPlaylist* mock_media_playlist =
|
2018-04-14 01:26:02 +00:00
|
|
|
new MockMediaPlaylist("playlist.m3u8", "", "");
|
2017-06-03 00:05:47 +00:00
|
|
|
|
|
|
|
EXPECT_CALL(*mock_media_playlist, SetMediaInfo(_)).WillOnce(Return(true));
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_CALL(*factory, CreateMock(_, _, _, _))
|
2017-06-03 00:05:47 +00:00
|
|
|
.WillOnce(Return(mock_media_playlist));
|
|
|
|
|
|
|
|
const uint64_t kStartTime = 1328;
|
|
|
|
const uint64_t kDuration = 398407;
|
|
|
|
const uint64_t kSize = 6595840;
|
|
|
|
const std::string segment_name = "segmentname";
|
|
|
|
EXPECT_CALL(*mock_media_playlist,
|
|
|
|
AddSegment(StrEq(kTestPrefix + segment_name), kStartTime,
|
2017-05-01 20:38:58 +00:00
|
|
|
kDuration, _, kSize));
|
2017-06-03 00:05:47 +00:00
|
|
|
|
|
|
|
const double kLongestSegmentDuration = 11.3;
|
|
|
|
const uint32_t kTargetDuration = 12; // ceil(kLongestSegmentDuration).
|
|
|
|
EXPECT_CALL(*mock_media_playlist, GetLongestSegmentDuration())
|
|
|
|
.WillOnce(Return(kLongestSegmentDuration));
|
|
|
|
|
2016-03-25 08:40:15 +00:00
|
|
|
EXPECT_CALL(*mock_master_playlist,
|
2018-02-02 17:14:46 +00:00
|
|
|
WriteMasterPlaylist(StrEq(kTestPrefix), StrEq(kAnyOutputDir), _))
|
2016-03-25 08:40:15 +00:00
|
|
|
.WillOnce(Return(true));
|
2017-06-03 00:05:47 +00:00
|
|
|
EXPECT_CALL(*mock_media_playlist, SetTargetDuration(kTargetDuration))
|
|
|
|
.Times(1);
|
|
|
|
EXPECT_CALL(*mock_media_playlist,
|
|
|
|
WriteToFile(StrEq(
|
|
|
|
base::FilePath::FromUTF8Unsafe(kAnyOutputDir)
|
|
|
|
.Append(base::FilePath::FromUTF8Unsafe("playlist.m3u8"))
|
|
|
|
.AsUTF8Unsafe())))
|
|
|
|
.WillOnce(Return(true));
|
|
|
|
|
2018-01-17 23:43:41 +00:00
|
|
|
hls_params_.playlist_type = GetParam();
|
|
|
|
SimpleHlsNotifier notifier(hls_params_);
|
2017-05-01 20:38:58 +00:00
|
|
|
InjectMasterPlaylist(std::move(mock_master_playlist), ¬ifier);
|
|
|
|
InjectMediaPlaylistFactory(std::move(factory), ¬ifier);
|
|
|
|
EXPECT_TRUE(notifier.Init());
|
2017-06-03 00:05:47 +00:00
|
|
|
MediaInfo media_info;
|
|
|
|
uint32_t stream_id;
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_TRUE(notifier.NotifyNewStream(media_info, "playlist.m3u8", "name",
|
|
|
|
"groupid", &stream_id));
|
2017-06-03 00:05:47 +00:00
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_TRUE(notifier.NotifyNewSegment(stream_id, segment_name, kStartTime,
|
|
|
|
kDuration, 0, kSize));
|
2017-06-03 00:05:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(LiveOrEventSimpleHlsNotifierTest, NotifyNewSegmentsWithMultipleStreams) {
|
|
|
|
const uint64_t kStartTime = 1328;
|
|
|
|
const uint64_t kDuration = 398407;
|
|
|
|
const uint64_t kSize = 6595840;
|
|
|
|
|
|
|
|
InSequence in_sequence;
|
|
|
|
|
|
|
|
std::unique_ptr<MockMasterPlaylist> mock_master_playlist(
|
|
|
|
new MockMasterPlaylist());
|
2016-08-17 17:41:40 +00:00
|
|
|
std::unique_ptr<MockMediaPlaylistFactory> factory(
|
|
|
|
new MockMediaPlaylistFactory());
|
2016-03-25 08:40:15 +00:00
|
|
|
|
2017-06-03 00:05:47 +00:00
|
|
|
// Pointer released by SimpleHlsNotifier.
|
|
|
|
MockMediaPlaylist* mock_media_playlist1 =
|
2018-04-14 01:26:02 +00:00
|
|
|
new MockMediaPlaylist("playlist1.m3u8", "", "");
|
2017-06-03 00:05:47 +00:00
|
|
|
MockMediaPlaylist* mock_media_playlist2 =
|
2018-04-14 01:26:02 +00:00
|
|
|
new MockMediaPlaylist("playlist2.m3u8", "", "");
|
2017-06-03 00:05:47 +00:00
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_CALL(*factory, CreateMock(_, StrEq("playlist1.m3u8"), _, _))
|
2017-06-03 00:05:47 +00:00
|
|
|
.WillOnce(Return(mock_media_playlist1));
|
|
|
|
EXPECT_CALL(*mock_media_playlist1, SetMediaInfo(_)).WillOnce(Return(true));
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_CALL(*factory, CreateMock(_, StrEq("playlist2.m3u8"), _, _))
|
2017-06-03 00:05:47 +00:00
|
|
|
.WillOnce(Return(mock_media_playlist2));
|
|
|
|
EXPECT_CALL(*mock_media_playlist2, SetMediaInfo(_)).WillOnce(Return(true));
|
|
|
|
|
2018-01-17 23:43:41 +00:00
|
|
|
hls_params_.playlist_type = GetParam();
|
|
|
|
SimpleHlsNotifier notifier(hls_params_);
|
2017-06-03 00:05:47 +00:00
|
|
|
MockMasterPlaylist* mock_master_playlist_ptr = mock_master_playlist.get();
|
2017-05-01 20:38:58 +00:00
|
|
|
InjectMasterPlaylist(std::move(mock_master_playlist), ¬ifier);
|
|
|
|
InjectMediaPlaylistFactory(std::move(factory), ¬ifier);
|
|
|
|
EXPECT_TRUE(notifier.Init());
|
2017-06-03 00:05:47 +00:00
|
|
|
|
|
|
|
MediaInfo media_info;
|
|
|
|
uint32_t stream_id1;
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_TRUE(notifier.NotifyNewStream(media_info, "playlist1.m3u8", "name",
|
2017-06-03 00:05:47 +00:00
|
|
|
"groupid", &stream_id1));
|
|
|
|
uint32_t stream_id2;
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_TRUE(notifier.NotifyNewStream(media_info, "playlist2.m3u8", "name",
|
2017-06-03 00:05:47 +00:00
|
|
|
"groupid", &stream_id2));
|
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_CALL(*mock_media_playlist1, AddSegment(_, _, _, _, _)).Times(1);
|
2017-06-03 00:05:47 +00:00
|
|
|
const double kLongestSegmentDuration = 11.3;
|
|
|
|
const uint32_t kTargetDuration = 12; // ceil(kLongestSegmentDuration).
|
|
|
|
EXPECT_CALL(*mock_media_playlist1, GetLongestSegmentDuration())
|
|
|
|
.WillOnce(Return(kLongestSegmentDuration));
|
|
|
|
|
|
|
|
// SetTargetDuration and update all playlists as target duration is updated.
|
|
|
|
EXPECT_CALL(*mock_media_playlist1, SetTargetDuration(kTargetDuration))
|
|
|
|
.Times(1);
|
|
|
|
EXPECT_CALL(*mock_media_playlist1,
|
|
|
|
WriteToFile(StrEq(
|
|
|
|
base::FilePath::FromUTF8Unsafe(kAnyOutputDir)
|
|
|
|
.Append(base::FilePath::FromUTF8Unsafe("playlist1.m3u8"))
|
|
|
|
.AsUTF8Unsafe())))
|
|
|
|
.WillOnce(Return(true));
|
|
|
|
EXPECT_CALL(*mock_media_playlist2, SetTargetDuration(kTargetDuration))
|
|
|
|
.Times(1);
|
|
|
|
EXPECT_CALL(*mock_media_playlist2,
|
|
|
|
WriteToFile(StrEq(
|
|
|
|
base::FilePath::FromUTF8Unsafe(kAnyOutputDir)
|
|
|
|
.Append(base::FilePath::FromUTF8Unsafe("playlist2.m3u8"))
|
|
|
|
.AsUTF8Unsafe())))
|
|
|
|
.WillOnce(Return(true));
|
2018-02-05 19:21:28 +00:00
|
|
|
EXPECT_CALL(
|
|
|
|
*mock_master_playlist_ptr,
|
|
|
|
WriteMasterPlaylist(
|
|
|
|
_, _, ElementsAre(mock_media_playlist1, mock_media_playlist2)))
|
|
|
|
.WillOnce(Return(true));
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_TRUE(notifier.NotifyNewSegment(stream_id1, "segment_name", kStartTime,
|
|
|
|
kDuration, 0, kSize));
|
2017-06-03 00:05:47 +00:00
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_CALL(*mock_media_playlist2, AddSegment(_, _, _, _, _)).Times(1);
|
2017-06-03 00:05:47 +00:00
|
|
|
EXPECT_CALL(*mock_media_playlist2, GetLongestSegmentDuration())
|
|
|
|
.WillOnce(Return(kLongestSegmentDuration));
|
|
|
|
// Not updating other playlists as target duration does not change.
|
|
|
|
EXPECT_CALL(*mock_media_playlist2,
|
|
|
|
WriteToFile(StrEq(
|
|
|
|
base::FilePath::FromUTF8Unsafe(kAnyOutputDir)
|
|
|
|
.Append(base::FilePath::FromUTF8Unsafe("playlist2.m3u8"))
|
|
|
|
.AsUTF8Unsafe())))
|
|
|
|
.WillOnce(Return(true));
|
2018-02-05 19:21:28 +00:00
|
|
|
EXPECT_CALL(*mock_master_playlist_ptr, WriteMasterPlaylist(_, _, _))
|
|
|
|
.WillOnce(Return(true));
|
2017-05-01 20:38:58 +00:00
|
|
|
EXPECT_TRUE(notifier.NotifyNewSegment(stream_id2, "segment_name", kStartTime,
|
|
|
|
kDuration, 0, kSize));
|
2016-03-25 08:40:15 +00:00
|
|
|
}
|
|
|
|
|
2017-06-03 00:05:47 +00:00
|
|
|
INSTANTIATE_TEST_CASE_P(PlaylistTypes,
|
|
|
|
LiveOrEventSimpleHlsNotifierTest,
|
2017-06-30 20:42:46 +00:00
|
|
|
::testing::Values(HlsPlaylistType::kLive,
|
|
|
|
HlsPlaylistType::kEvent));
|
2016-03-25 08:40:15 +00:00
|
|
|
} // namespace hls
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|