2023-12-01 17:32:19 +00:00
|
|
|
// Copyright 2016 Google LLC. All rights reserved.
|
2016-03-25 08:35:44 +00:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
#include <packager/hls/base/media_playlist.h>
|
|
|
|
|
|
|
|
#include <absl/strings/str_format.h>
|
2016-03-25 08:35:44 +00:00
|
|
|
#include <gmock/gmock.h>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
#include <packager/file.h>
|
|
|
|
#include <packager/file/file_closer.h>
|
|
|
|
#include <packager/file/file_test_util.h>
|
|
|
|
#include <packager/version/version.h>
|
2016-03-25 08:35:44 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2016-03-25 08:35:44 +00:00
|
|
|
namespace hls {
|
|
|
|
|
|
|
|
using ::testing::_;
|
2018-10-10 22:30:28 +00:00
|
|
|
using ::testing::ElementsAreArray;
|
2016-03-25 08:35:44 +00:00
|
|
|
using ::testing::ReturnArg;
|
2019-05-15 05:54:28 +00:00
|
|
|
using ::testing::Values;
|
|
|
|
using ::testing::WithParamInterface;
|
2016-03-25 08:35:44 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
const char kDefaultPlaylistFileName[] = "default_playlist.m3u8";
|
2017-06-03 00:05:47 +00:00
|
|
|
const double kTimeShiftBufferDepth = 20;
|
2021-08-04 18:56:44 +00:00
|
|
|
const int64_t kTimeScale = 90000;
|
2017-06-03 00:05:47 +00:00
|
|
|
const uint64_t kMBytes = 1000000;
|
2017-05-01 20:38:58 +00:00
|
|
|
const uint64_t kZeroByteOffset = 0;
|
2016-03-25 08:35:44 +00:00
|
|
|
|
|
|
|
MATCHER_P(MatchesString, expected_string, "") {
|
|
|
|
const std::string arg_string(static_cast<const char*>(arg));
|
|
|
|
*result_listener << "which is " << arg_string.size()
|
|
|
|
<< " long and the content is " << arg_string;
|
|
|
|
return expected_string == std::string(static_cast<const char*>(arg));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
class MediaPlaylistTest : public ::testing::Test {
|
|
|
|
protected:
|
2017-06-30 20:42:46 +00:00
|
|
|
MediaPlaylistTest() : MediaPlaylistTest(HlsPlaylistType::kVod) {}
|
2017-06-03 00:05:47 +00:00
|
|
|
|
2017-06-30 20:42:46 +00:00
|
|
|
MediaPlaylistTest(HlsPlaylistType type)
|
2016-03-25 08:35:44 +00:00
|
|
|
: default_file_name_(kDefaultPlaylistFileName),
|
|
|
|
default_name_("default_name"),
|
2018-04-14 01:26:02 +00:00
|
|
|
default_group_id_("default_group_id") {
|
2018-04-17 22:03:02 +00:00
|
|
|
hls_params_.playlist_type = type;
|
|
|
|
hls_params_.time_shift_buffer_depth = kTimeShiftBufferDepth;
|
|
|
|
media_playlist_.reset(new MediaPlaylist(hls_params_, default_file_name_,
|
2018-04-14 01:26:02 +00:00
|
|
|
default_name_, default_group_id_));
|
|
|
|
}
|
2016-03-25 08:35:44 +00:00
|
|
|
|
|
|
|
void SetUp() override {
|
2016-07-07 19:34:07 +00:00
|
|
|
SetPackagerVersionForTesting("test");
|
|
|
|
|
2016-03-25 08:35:44 +00:00
|
|
|
MediaInfo::VideoInfo* video_info =
|
|
|
|
valid_video_media_info_.mutable_video_info();
|
|
|
|
video_info->set_codec("avc1");
|
2017-06-03 00:05:47 +00:00
|
|
|
video_info->set_time_scale(kTimeScale);
|
2016-03-25 08:35:44 +00:00
|
|
|
video_info->set_frame_duration(3000);
|
|
|
|
video_info->set_width(1280);
|
|
|
|
video_info->set_height(720);
|
|
|
|
video_info->set_pixel_width(1);
|
|
|
|
video_info->set_pixel_height(1);
|
2017-06-03 00:05:47 +00:00
|
|
|
|
|
|
|
valid_video_media_info_.set_reference_time_scale(kTimeScale);
|
2016-03-25 08:35:44 +00:00
|
|
|
}
|
|
|
|
|
2018-04-17 22:03:02 +00:00
|
|
|
HlsParams* mutable_hls_params() { return &hls_params_; }
|
|
|
|
|
2016-03-25 08:35:44 +00:00
|
|
|
const std::string default_file_name_;
|
|
|
|
const std::string default_name_;
|
|
|
|
const std::string default_group_id_;
|
2018-04-17 22:03:02 +00:00
|
|
|
HlsParams hls_params_;
|
2018-04-14 01:26:02 +00:00
|
|
|
std::unique_ptr<MediaPlaylist> media_playlist_;
|
2016-03-25 08:35:44 +00:00
|
|
|
|
|
|
|
MediaInfo valid_video_media_info_;
|
|
|
|
};
|
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
class MediaPlaylistMultiSegmentTest : public MediaPlaylistTest {
|
|
|
|
protected:
|
|
|
|
MediaPlaylistMultiSegmentTest() : MediaPlaylistTest() {}
|
|
|
|
// This constructor is for Live and Event playlist tests.
|
2017-06-30 20:42:46 +00:00
|
|
|
MediaPlaylistMultiSegmentTest(HlsPlaylistType type)
|
2017-05-01 20:38:58 +00:00
|
|
|
: MediaPlaylistTest(type) {}
|
|
|
|
|
|
|
|
void SetUp() override {
|
|
|
|
MediaPlaylistTest::SetUp();
|
|
|
|
// This is just set to be consistent with the multisegment format and used
|
|
|
|
// as a switch in MediaPlaylist.
|
|
|
|
// The template string doesn't really matter.
|
2018-04-17 17:42:45 +00:00
|
|
|
valid_video_media_info_.set_segment_template_url("file$Number$.ts");
|
2017-05-01 20:38:58 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class MediaPlaylistSingleSegmentTest : public MediaPlaylistTest {
|
|
|
|
protected:
|
|
|
|
MediaPlaylistSingleSegmentTest() : MediaPlaylistTest() {}
|
|
|
|
};
|
|
|
|
|
2016-03-25 08:35:44 +00:00
|
|
|
// Verify that SetMediaInfo() fails if timescale is not present.
|
2017-05-01 20:38:58 +00:00
|
|
|
TEST_F(MediaPlaylistMultiSegmentTest, NoTimeScale) {
|
2016-03-25 08:35:44 +00:00
|
|
|
MediaInfo media_info;
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_FALSE(media_playlist_->SetMediaInfo(media_info));
|
2016-03-25 08:35:44 +00:00
|
|
|
}
|
|
|
|
|
2018-01-31 19:14:15 +00:00
|
|
|
TEST_F(MediaPlaylistMultiSegmentTest, SetMediaInfoText) {
|
2016-03-25 08:35:44 +00:00
|
|
|
MediaInfo media_info;
|
2017-06-03 00:05:47 +00:00
|
|
|
media_info.set_reference_time_scale(kTimeScale);
|
2016-03-25 08:35:44 +00:00
|
|
|
MediaInfo::TextInfo* text_info = media_info.mutable_text_info();
|
2018-02-26 20:13:28 +00:00
|
|
|
text_info->set_codec("wvtt");
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_TRUE(media_playlist_->SetMediaInfo(media_info));
|
2016-03-25 08:35:44 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
TEST_F(MediaPlaylistMultiSegmentTest, SetMediaInfo) {
|
2016-03-25 08:35:44 +00:00
|
|
|
MediaInfo media_info;
|
2017-06-03 00:05:47 +00:00
|
|
|
media_info.set_reference_time_scale(kTimeScale);
|
2016-03-25 08:35:44 +00:00
|
|
|
MediaInfo::VideoInfo* video_info = media_info.mutable_video_info();
|
|
|
|
video_info->set_width(1280);
|
|
|
|
video_info->set_height(720);
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_TRUE(media_playlist_->SetMediaInfo(media_info));
|
2016-03-25 08:35:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that AddSegment works (not crash).
|
2017-05-01 20:38:58 +00:00
|
|
|
TEST_F(MediaPlaylistMultiSegmentTest, AddSegment) {
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
|
|
|
media_playlist_->AddSegment("file1.ts", 900000, 0, kZeroByteOffset, 1000000);
|
2017-05-01 20:38:58 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 20:25:36 +00:00
|
|
|
// Verify that it returns the display resolution.
|
|
|
|
TEST_F(MediaPlaylistMultiSegmentTest, GetDisplayResolution) {
|
|
|
|
// A real case using sintel video.
|
|
|
|
MediaInfo media_info;
|
|
|
|
media_info.set_reference_time_scale(kTimeScale);
|
|
|
|
MediaInfo::VideoInfo* video_info = media_info.mutable_video_info();
|
|
|
|
video_info->set_width(1920);
|
|
|
|
video_info->set_height(818);
|
|
|
|
video_info->set_pixel_width(1636);
|
|
|
|
video_info->set_pixel_height(1635);
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(media_info));
|
2017-07-13 20:25:36 +00:00
|
|
|
uint32_t width = 0;
|
|
|
|
uint32_t height = 0;
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_TRUE(media_playlist_->GetDisplayResolution(&width, &height));
|
2017-07-13 20:25:36 +00:00
|
|
|
EXPECT_EQ(1921u, width);
|
|
|
|
EXPECT_EQ(818u, height);
|
|
|
|
}
|
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
TEST_F(MediaPlaylistSingleSegmentTest, InitRange) {
|
|
|
|
const std::string kExpectedOutput =
|
|
|
|
"#EXTM3U\n"
|
|
|
|
"#EXT-X-VERSION:6\n"
|
2022-03-07 19:56:34 +00:00
|
|
|
"## Generated with https://github.com/shaka-project/shaka-packager "
|
|
|
|
"version test\n"
|
2017-05-01 20:38:58 +00:00
|
|
|
"#EXT-X-TARGETDURATION:0\n"
|
|
|
|
"#EXT-X-PLAYLIST-TYPE:VOD\n"
|
2017-07-14 00:13:30 +00:00
|
|
|
"#EXT-X-MAP:URI=\"file.mp4\",BYTERANGE=\"501@0\"\n"
|
2017-05-01 20:38:58 +00:00
|
|
|
"#EXT-X-ENDLIST\n";
|
2018-04-17 17:42:45 +00:00
|
|
|
valid_video_media_info_.set_media_file_url("file.mp4");
|
2017-05-01 20:38:58 +00:00
|
|
|
valid_video_media_info_.mutable_init_range()->set_begin(0);
|
|
|
|
valid_video_media_info_.mutable_init_range()->set_end(500);
|
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
2017-05-01 20:38:58 +00:00
|
|
|
const char kMemoryFilePath[] = "memory://media.m3u8";
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_TRUE(media_playlist_->WriteToFile(kMemoryFilePath));
|
2017-05-01 20:38:58 +00:00
|
|
|
ASSERT_FILE_STREQ(kMemoryFilePath, kExpectedOutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(MediaPlaylistSingleSegmentTest, InitRangeWithOffset) {
|
|
|
|
const std::string kExpectedOutput =
|
|
|
|
"#EXTM3U\n"
|
|
|
|
"#EXT-X-VERSION:6\n"
|
2022-03-07 19:56:34 +00:00
|
|
|
"## Generated with https://github.com/shaka-project/shaka-packager "
|
|
|
|
"version test\n"
|
2017-05-01 20:38:58 +00:00
|
|
|
"#EXT-X-TARGETDURATION:0\n"
|
|
|
|
"#EXT-X-PLAYLIST-TYPE:VOD\n"
|
2017-07-14 00:13:30 +00:00
|
|
|
"#EXT-X-MAP:URI=\"file.mp4\",BYTERANGE=\"485@16\"\n"
|
2017-05-01 20:38:58 +00:00
|
|
|
"#EXT-X-ENDLIST\n";
|
2018-04-17 17:42:45 +00:00
|
|
|
valid_video_media_info_.set_media_file_url("file.mp4");
|
2017-05-01 20:38:58 +00:00
|
|
|
valid_video_media_info_.mutable_init_range()->set_begin(16);
|
|
|
|
valid_video_media_info_.mutable_init_range()->set_end(500);
|
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
2017-05-01 20:38:58 +00:00
|
|
|
const char kMemoryFilePath[] = "memory://media.m3u8";
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_TRUE(media_playlist_->WriteToFile(kMemoryFilePath));
|
2017-05-01 20:38:58 +00:00
|
|
|
ASSERT_FILE_STREQ(kMemoryFilePath, kExpectedOutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Closest to the normal use case where there is an init range and then
|
2018-02-26 20:13:28 +00:00
|
|
|
// subsegment ranges. There is index range between the subsegment and init
|
|
|
|
// range.
|
2017-05-01 20:38:58 +00:00
|
|
|
TEST_F(MediaPlaylistSingleSegmentTest, AddSegmentByteRange) {
|
|
|
|
const std::string kExpectedOutput =
|
|
|
|
"#EXTM3U\n"
|
|
|
|
"#EXT-X-VERSION:6\n"
|
2022-03-07 19:56:34 +00:00
|
|
|
"## Generated with https://github.com/shaka-project/shaka-packager "
|
|
|
|
"version test\n"
|
2017-05-01 20:38:58 +00:00
|
|
|
"#EXT-X-TARGETDURATION:10\n"
|
|
|
|
"#EXT-X-PLAYLIST-TYPE:VOD\n"
|
2017-07-14 00:13:30 +00:00
|
|
|
"#EXT-X-MAP:URI=\"file.mp4\",BYTERANGE=\"501@0\"\n"
|
2017-05-01 20:38:58 +00:00
|
|
|
"#EXTINF:10.000,\n"
|
|
|
|
"#EXT-X-BYTERANGE:1000000@1000\n"
|
|
|
|
"file.mp4\n"
|
|
|
|
"#EXTINF:10.000,\n"
|
|
|
|
"#EXT-X-BYTERANGE:2000000\n"
|
|
|
|
"file.mp4\n"
|
|
|
|
"#EXT-X-ENDLIST\n";
|
2018-04-17 17:42:45 +00:00
|
|
|
valid_video_media_info_.set_media_file_url("file.mp4");
|
2017-05-01 20:38:58 +00:00
|
|
|
valid_video_media_info_.mutable_init_range()->set_begin(0);
|
|
|
|
valid_video_media_info_.mutable_init_range()->set_end(500);
|
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
|
|
|
media_playlist_->AddSegment("file.mp4", 0, 10 * kTimeScale, 1000,
|
|
|
|
1 * kMBytes);
|
|
|
|
media_playlist_->AddSegment("file.mp4", 10 * kTimeScale, 10 * kTimeScale,
|
|
|
|
1001000, 2 * kMBytes);
|
2017-05-01 20:38:58 +00:00
|
|
|
|
|
|
|
const char kMemoryFilePath[] = "memory://media.m3u8";
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_TRUE(media_playlist_->WriteToFile(kMemoryFilePath));
|
2017-05-01 20:38:58 +00:00
|
|
|
ASSERT_FILE_STREQ(kMemoryFilePath, kExpectedOutput);
|
2016-03-25 08:35:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that AddEncryptionInfo works (not crash).
|
2017-05-01 20:38:58 +00:00
|
|
|
TEST_F(MediaPlaylistMultiSegmentTest, AddEncryptionInfo) {
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
|
|
|
media_playlist_->AddEncryptionInfo(
|
|
|
|
MediaPlaylist::EncryptionMethod::kSampleAes, "http://example.com", "",
|
|
|
|
"0xabcedf", "", "");
|
2016-03-25 08:35:44 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
TEST_F(MediaPlaylistMultiSegmentTest, WriteToFile) {
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
2017-06-03 00:05:47 +00:00
|
|
|
const char kExpectedOutput[] =
|
2016-03-25 08:35:44 +00:00
|
|
|
"#EXTM3U\n"
|
2017-03-14 00:02:23 +00:00
|
|
|
"#EXT-X-VERSION:6\n"
|
2022-03-07 19:56:34 +00:00
|
|
|
"## Generated with https://github.com/shaka-project/shaka-packager "
|
|
|
|
"version test\n"
|
2016-04-20 22:23:19 +00:00
|
|
|
"#EXT-X-TARGETDURATION:0\n"
|
|
|
|
"#EXT-X-PLAYLIST-TYPE:VOD\n"
|
|
|
|
"#EXT-X-ENDLIST\n";
|
2016-03-25 08:35:44 +00:00
|
|
|
|
2017-06-03 00:05:47 +00:00
|
|
|
const char kMemoryFilePath[] = "memory://media.m3u8";
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_TRUE(media_playlist_->WriteToFile(kMemoryFilePath));
|
2017-06-03 00:05:47 +00:00
|
|
|
ASSERT_FILE_STREQ(kMemoryFilePath, kExpectedOutput);
|
2016-03-25 08:35:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If bitrate (bandwidth) is not set in the MediaInfo, use it.
|
2017-05-01 20:38:58 +00:00
|
|
|
TEST_F(MediaPlaylistMultiSegmentTest, UseBitrateInMediaInfo) {
|
2016-03-25 08:35:44 +00:00
|
|
|
valid_video_media_info_.set_bandwidth(8191);
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
2018-05-31 21:27:21 +00:00
|
|
|
EXPECT_EQ(8191u, media_playlist_->MaxBitrate());
|
2016-03-25 08:35:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If bitrate (bandwidth) is not set in the MediaInfo, then calculate from the
|
|
|
|
// segments.
|
2017-05-01 20:38:58 +00:00
|
|
|
TEST_F(MediaPlaylistMultiSegmentTest, GetBitrateFromSegments) {
|
2016-03-25 08:35:44 +00:00
|
|
|
valid_video_media_info_.clear_bandwidth();
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
2016-03-25 08:35:44 +00:00
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
media_playlist_->AddSegment("file1.ts", 0, 10 * kTimeScale, kZeroByteOffset,
|
|
|
|
kMBytes);
|
|
|
|
media_playlist_->AddSegment("file2.ts", 10 * kTimeScale, 20 * kTimeScale,
|
|
|
|
kZeroByteOffset, 5 * kMBytes);
|
2016-03-25 08:35:44 +00:00
|
|
|
|
2018-05-31 21:27:21 +00:00
|
|
|
EXPECT_EQ(2000000u, media_playlist_->MaxBitrate());
|
2018-06-22 23:19:30 +00:00
|
|
|
EXPECT_EQ(1600000u, media_playlist_->AvgBitrate());
|
2016-03-25 08:35:44 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
TEST_F(MediaPlaylistMultiSegmentTest, GetLongestSegmentDuration) {
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
2016-03-25 08:35:44 +00:00
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
media_playlist_->AddSegment("file1.ts", 0, 10 * kTimeScale, kZeroByteOffset,
|
|
|
|
kMBytes);
|
|
|
|
media_playlist_->AddSegment("file2.ts", 10 * kTimeScale, 30 * kTimeScale,
|
|
|
|
kZeroByteOffset, 5 * kMBytes);
|
|
|
|
media_playlist_->AddSegment("file3.ts", 40 * kTimeScale, 14 * kTimeScale,
|
|
|
|
kZeroByteOffset, 3 * kMBytes);
|
2016-03-25 08:35:44 +00:00
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_NEAR(30.0, media_playlist_->GetLongestSegmentDuration(), 0.01);
|
2016-03-25 08:35:44 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
TEST_F(MediaPlaylistMultiSegmentTest, SetTargetDuration) {
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
|
|
|
media_playlist_->SetTargetDuration(20);
|
2017-05-01 20:38:58 +00:00
|
|
|
const std::string kExpectedOutput =
|
|
|
|
"#EXTM3U\n"
|
|
|
|
"#EXT-X-VERSION:6\n"
|
2022-03-07 19:56:34 +00:00
|
|
|
"## Generated with https://github.com/shaka-project/shaka-packager "
|
|
|
|
"version test\n"
|
2017-05-01 20:38:58 +00:00
|
|
|
"#EXT-X-TARGETDURATION:20\n"
|
|
|
|
"#EXT-X-PLAYLIST-TYPE:VOD\n"
|
|
|
|
"#EXT-X-ENDLIST\n";
|
2016-03-25 08:35:44 +00:00
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
const char kMemoryFilePath[] = "memory://media.m3u8";
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_TRUE(media_playlist_->WriteToFile(kMemoryFilePath));
|
2017-05-01 20:38:58 +00:00
|
|
|
ASSERT_FILE_STREQ(kMemoryFilePath, kExpectedOutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(MediaPlaylistMultiSegmentTest, WriteToFileWithSegments) {
|
|
|
|
valid_video_media_info_.set_reference_time_scale(90000);
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
2017-05-01 20:38:58 +00:00
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
media_playlist_->AddSegment("file1.ts", 0, 10 * kTimeScale, kZeroByteOffset,
|
|
|
|
kMBytes);
|
|
|
|
media_playlist_->AddSegment("file2.ts", 10 * kTimeScale, 30 * kTimeScale,
|
|
|
|
kZeroByteOffset, 5 * kMBytes);
|
2017-06-03 00:05:47 +00:00
|
|
|
const char kExpectedOutput[] =
|
2016-03-25 08:35:44 +00:00
|
|
|
"#EXTM3U\n"
|
2017-03-14 00:02:23 +00:00
|
|
|
"#EXT-X-VERSION:6\n"
|
2022-03-07 19:56:34 +00:00
|
|
|
"## Generated with https://github.com/shaka-project/shaka-packager "
|
|
|
|
"version test\n"
|
2016-03-25 08:35:44 +00:00
|
|
|
"#EXT-X-TARGETDURATION:30\n"
|
2016-04-20 22:23:19 +00:00
|
|
|
"#EXT-X-PLAYLIST-TYPE:VOD\n"
|
|
|
|
"#EXTINF:10.000,\n"
|
2016-03-25 08:35:44 +00:00
|
|
|
"file1.ts\n"
|
2016-04-20 22:23:19 +00:00
|
|
|
"#EXTINF:30.000,\n"
|
|
|
|
"file2.ts\n"
|
|
|
|
"#EXT-X-ENDLIST\n";
|
2016-03-25 08:35:44 +00:00
|
|
|
|
2017-06-03 00:05:47 +00:00
|
|
|
const char kMemoryFilePath[] = "memory://media.m3u8";
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_TRUE(media_playlist_->WriteToFile(kMemoryFilePath));
|
2017-06-03 00:05:47 +00:00
|
|
|
ASSERT_FILE_STREQ(kMemoryFilePath, kExpectedOutput);
|
2018-01-12 01:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(MediaPlaylistMultiSegmentTest,
|
|
|
|
WriteToFileWithSegmentsAndPlacementOpportunity) {
|
|
|
|
valid_video_media_info_.set_reference_time_scale(90000);
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
2018-01-12 01:33:37 +00:00
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
media_playlist_->AddSegment("file1.ts", 0, 10 * kTimeScale, kZeroByteOffset,
|
|
|
|
kMBytes);
|
|
|
|
media_playlist_->AddPlacementOpportunity();
|
|
|
|
media_playlist_->AddSegment("file2.ts", 10 * kTimeScale, 30 * kTimeScale,
|
|
|
|
kZeroByteOffset, 5 * kMBytes);
|
2018-01-12 01:33:37 +00:00
|
|
|
const char kExpectedOutput[] =
|
|
|
|
"#EXTM3U\n"
|
|
|
|
"#EXT-X-VERSION:6\n"
|
2022-03-07 19:56:34 +00:00
|
|
|
"## Generated with https://github.com/shaka-project/shaka-packager "
|
|
|
|
"version test\n"
|
2018-01-12 01:33:37 +00:00
|
|
|
"#EXT-X-TARGETDURATION:30\n"
|
|
|
|
"#EXT-X-PLAYLIST-TYPE:VOD\n"
|
|
|
|
"#EXTINF:10.000,\n"
|
|
|
|
"file1.ts\n"
|
|
|
|
"#EXT-X-PLACEMENT-OPPORTUNITY\n"
|
|
|
|
"#EXTINF:30.000,\n"
|
|
|
|
"file2.ts\n"
|
|
|
|
"#EXT-X-ENDLIST\n";
|
|
|
|
|
|
|
|
const char kMemoryFilePath[] = "memory://media.m3u8";
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_TRUE(media_playlist_->WriteToFile(kMemoryFilePath));
|
2018-01-12 01:33:37 +00:00
|
|
|
ASSERT_FILE_STREQ(kMemoryFilePath, kExpectedOutput);
|
2016-03-25 08:35:44 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
TEST_F(MediaPlaylistMultiSegmentTest, WriteToFileWithEncryptionInfo) {
|
|
|
|
valid_video_media_info_.set_reference_time_scale(90000);
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
|
|
|
|
|
|
|
media_playlist_->AddEncryptionInfo(
|
|
|
|
MediaPlaylist::EncryptionMethod::kSampleAes, "http://example.com", "",
|
|
|
|
"0x12345678", "com.widevine", "1/2/4");
|
|
|
|
media_playlist_->AddSegment("file1.ts", 0, 10 * kTimeScale, kZeroByteOffset,
|
|
|
|
kMBytes);
|
|
|
|
media_playlist_->AddSegment("file2.ts", 10 * kTimeScale, 30 * kTimeScale,
|
|
|
|
kZeroByteOffset, 5 * kMBytes);
|
2017-06-03 00:05:47 +00:00
|
|
|
const char kExpectedOutput[] =
|
2016-03-25 08:35:44 +00:00
|
|
|
"#EXTM3U\n"
|
2017-03-14 00:02:23 +00:00
|
|
|
"#EXT-X-VERSION:6\n"
|
2022-03-07 19:56:34 +00:00
|
|
|
"## Generated with https://github.com/shaka-project/shaka-packager "
|
|
|
|
"version test\n"
|
2016-03-25 08:35:44 +00:00
|
|
|
"#EXT-X-TARGETDURATION:30\n"
|
2016-04-20 22:23:19 +00:00
|
|
|
"#EXT-X-PLAYLIST-TYPE:VOD\n"
|
2016-03-25 08:35:44 +00:00
|
|
|
"#EXT-X-KEY:METHOD=SAMPLE-AES,"
|
|
|
|
"URI=\"http://example.com\",IV=0x12345678,KEYFORMATVERSIONS=\"1/2/4\","
|
|
|
|
"KEYFORMAT=\"com.widevine\"\n"
|
2016-04-20 22:23:19 +00:00
|
|
|
"#EXTINF:10.000,\n"
|
2016-03-25 08:35:44 +00:00
|
|
|
"file1.ts\n"
|
2016-04-20 22:23:19 +00:00
|
|
|
"#EXTINF:30.000,\n"
|
|
|
|
"file2.ts\n"
|
|
|
|
"#EXT-X-ENDLIST\n";
|
2016-03-25 08:35:44 +00:00
|
|
|
|
2017-06-03 00:05:47 +00:00
|
|
|
const char kMemoryFilePath[] = "memory://media.m3u8";
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_TRUE(media_playlist_->WriteToFile(kMemoryFilePath));
|
2017-06-03 00:05:47 +00:00
|
|
|
ASSERT_FILE_STREQ(kMemoryFilePath, kExpectedOutput);
|
2016-03-25 08:35:44 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
TEST_F(MediaPlaylistMultiSegmentTest, WriteToFileWithEncryptionInfoEmptyIv) {
|
|
|
|
valid_video_media_info_.set_reference_time_scale(90000);
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
|
|
|
|
|
|
|
media_playlist_->AddEncryptionInfo(
|
|
|
|
MediaPlaylist::EncryptionMethod::kSampleAes, "http://example.com", "", "",
|
|
|
|
"com.widevine", "");
|
|
|
|
media_playlist_->AddSegment("file1.ts", 0, 10 * kTimeScale, kZeroByteOffset,
|
|
|
|
kMBytes);
|
|
|
|
media_playlist_->AddSegment("file2.ts", 10 * kTimeScale, 30 * kTimeScale,
|
|
|
|
kZeroByteOffset, 5 * kMBytes);
|
2017-06-03 00:05:47 +00:00
|
|
|
const char kExpectedOutput[] =
|
2016-03-25 08:35:44 +00:00
|
|
|
"#EXTM3U\n"
|
2017-03-14 00:02:23 +00:00
|
|
|
"#EXT-X-VERSION:6\n"
|
2022-03-07 19:56:34 +00:00
|
|
|
"## Generated with https://github.com/shaka-project/shaka-packager "
|
|
|
|
"version test\n"
|
2016-03-25 08:35:44 +00:00
|
|
|
"#EXT-X-TARGETDURATION:30\n"
|
2016-04-20 22:23:19 +00:00
|
|
|
"#EXT-X-PLAYLIST-TYPE:VOD\n"
|
2016-03-25 08:35:44 +00:00
|
|
|
"#EXT-X-KEY:METHOD=SAMPLE-AES,"
|
|
|
|
"URI=\"http://example.com\",KEYFORMAT=\"com.widevine\"\n"
|
2016-04-20 22:23:19 +00:00
|
|
|
"#EXTINF:10.000,\n"
|
2016-03-25 08:35:44 +00:00
|
|
|
"file1.ts\n"
|
2016-04-20 22:23:19 +00:00
|
|
|
"#EXTINF:30.000,\n"
|
|
|
|
"file2.ts\n"
|
|
|
|
"#EXT-X-ENDLIST\n";
|
2016-03-25 08:35:44 +00:00
|
|
|
|
2017-06-03 00:05:47 +00:00
|
|
|
const char kMemoryFilePath[] = "memory://media.m3u8";
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_TRUE(media_playlist_->WriteToFile(kMemoryFilePath));
|
2017-06-03 00:05:47 +00:00
|
|
|
ASSERT_FILE_STREQ(kMemoryFilePath, kExpectedOutput);
|
2016-03-25 08:35:44 +00:00
|
|
|
}
|
|
|
|
|
2016-06-29 21:24:40 +00:00
|
|
|
// Verify that EXT-X-DISCONTINUITY is inserted before EXT-X-KEY.
|
2017-05-01 20:38:58 +00:00
|
|
|
TEST_F(MediaPlaylistMultiSegmentTest, WriteToFileWithClearLead) {
|
|
|
|
valid_video_media_info_.set_reference_time_scale(90000);
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
2016-06-29 21:24:40 +00:00
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
media_playlist_->AddSegment("file1.ts", 0, 10 * kTimeScale, kZeroByteOffset,
|
|
|
|
kMBytes);
|
2016-06-29 21:24:40 +00:00
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
media_playlist_->AddEncryptionInfo(
|
|
|
|
MediaPlaylist::EncryptionMethod::kSampleAes, "http://example.com", "",
|
|
|
|
"0x12345678", "com.widevine", "1/2/4");
|
|
|
|
media_playlist_->AddSegment("file2.ts", 10 * kTimeScale, 30 * kTimeScale,
|
|
|
|
kZeroByteOffset, 5 * kMBytes);
|
2017-06-03 00:05:47 +00:00
|
|
|
const char kExpectedOutput[] =
|
2016-06-29 21:24:40 +00:00
|
|
|
"#EXTM3U\n"
|
2017-03-14 00:02:23 +00:00
|
|
|
"#EXT-X-VERSION:6\n"
|
2022-03-07 19:56:34 +00:00
|
|
|
"## Generated with https://github.com/shaka-project/shaka-packager "
|
|
|
|
"version test\n"
|
2016-06-29 21:24:40 +00:00
|
|
|
"#EXT-X-TARGETDURATION:30\n"
|
|
|
|
"#EXT-X-PLAYLIST-TYPE:VOD\n"
|
|
|
|
"#EXTINF:10.000,\n"
|
|
|
|
"file1.ts\n"
|
|
|
|
"#EXT-X-DISCONTINUITY\n"
|
|
|
|
"#EXT-X-KEY:METHOD=SAMPLE-AES,"
|
|
|
|
"URI=\"http://example.com\",IV=0x12345678,KEYFORMATVERSIONS=\"1/2/4\","
|
|
|
|
"KEYFORMAT=\"com.widevine\"\n"
|
|
|
|
"#EXTINF:30.000,\n"
|
|
|
|
"file2.ts\n"
|
|
|
|
"#EXT-X-ENDLIST\n";
|
|
|
|
|
2017-06-03 00:05:47 +00:00
|
|
|
const char kMemoryFilePath[] = "memory://media.m3u8";
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_TRUE(media_playlist_->WriteToFile(kMemoryFilePath));
|
2017-06-03 00:05:47 +00:00
|
|
|
ASSERT_FILE_STREQ(kMemoryFilePath, kExpectedOutput);
|
2016-06-29 21:24:40 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
TEST_F(MediaPlaylistMultiSegmentTest, GetLanguage) {
|
2017-03-10 23:18:42 +00:00
|
|
|
MediaInfo media_info;
|
2017-06-03 00:05:47 +00:00
|
|
|
media_info.set_reference_time_scale(kTimeScale);
|
2017-03-10 23:18:42 +00:00
|
|
|
|
|
|
|
// Check conversions from long to short form.
|
|
|
|
media_info.mutable_audio_info()->set_language("eng");
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(media_info));
|
|
|
|
EXPECT_EQ("en", media_playlist_->language()); // short form
|
2017-03-10 23:18:42 +00:00
|
|
|
|
|
|
|
media_info.mutable_audio_info()->set_language("eng-US");
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(media_info));
|
|
|
|
EXPECT_EQ("en-US", media_playlist_->language()); // region preserved
|
2017-03-10 23:18:42 +00:00
|
|
|
|
|
|
|
media_info.mutable_audio_info()->set_language("apa");
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(media_info));
|
|
|
|
EXPECT_EQ("apa", media_playlist_->language()); // no short form exists
|
2017-03-10 23:18:42 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 01:53:17 +00:00
|
|
|
TEST_F(MediaPlaylistMultiSegmentTest, GetNumChannels) {
|
|
|
|
MediaInfo media_info;
|
|
|
|
media_info.set_reference_time_scale(kTimeScale);
|
|
|
|
|
|
|
|
// Returns 0 by default if not audio.
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_EQ(0, media_playlist_->GetNumChannels());
|
2017-12-09 01:53:17 +00:00
|
|
|
|
|
|
|
media_info.mutable_audio_info()->set_num_channels(2);
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(media_info));
|
|
|
|
EXPECT_EQ(2, media_playlist_->GetNumChannels());
|
2017-12-09 01:53:17 +00:00
|
|
|
|
|
|
|
media_info.mutable_audio_info()->set_num_channels(8);
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(media_info));
|
|
|
|
EXPECT_EQ(8, media_playlist_->GetNumChannels());
|
2017-12-09 01:53:17 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 05:02:49 +00:00
|
|
|
TEST_F(MediaPlaylistMultiSegmentTest, GetEC3JocComplexity) {
|
|
|
|
MediaInfo media_info;
|
|
|
|
media_info.set_reference_time_scale(kTimeScale);
|
|
|
|
|
|
|
|
// Returns 0 by default if not audio.
|
|
|
|
EXPECT_EQ(0, media_playlist_->GetEC3JocComplexity());
|
|
|
|
|
|
|
|
media_info.mutable_audio_info()->mutable_codec_specific_data()->
|
|
|
|
set_ec3_joc_complexity(16);
|
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(media_info));
|
|
|
|
EXPECT_EQ(16, media_playlist_->GetEC3JocComplexity());
|
|
|
|
|
|
|
|
media_info.mutable_audio_info()->mutable_codec_specific_data()->
|
|
|
|
set_ec3_joc_complexity(6);
|
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(media_info));
|
|
|
|
EXPECT_EQ(6, media_playlist_->GetEC3JocComplexity());
|
|
|
|
}
|
|
|
|
|
2020-07-04 21:55:28 +00:00
|
|
|
TEST_F(MediaPlaylistMultiSegmentTest, GetAC4ImsFlag) {
|
|
|
|
MediaInfo media_info;
|
|
|
|
media_info.set_reference_time_scale(kTimeScale);
|
|
|
|
|
|
|
|
// Returns false by default if not audio.
|
|
|
|
EXPECT_EQ(false, media_playlist_->GetAC4ImsFlag());
|
|
|
|
|
|
|
|
media_info.mutable_audio_info()->mutable_codec_specific_data()->
|
|
|
|
set_ac4_ims_flag(false);
|
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(media_info));
|
|
|
|
EXPECT_EQ(false, media_playlist_->GetAC4ImsFlag());
|
|
|
|
|
|
|
|
media_info.mutable_audio_info()->mutable_codec_specific_data()->
|
|
|
|
set_ac4_ims_flag(true);
|
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(media_info));
|
|
|
|
EXPECT_EQ(true, media_playlist_->GetAC4ImsFlag());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(MediaPlaylistMultiSegmentTest, GetAC4CbiFlag) {
|
|
|
|
MediaInfo media_info;
|
|
|
|
media_info.set_reference_time_scale(kTimeScale);
|
|
|
|
|
|
|
|
// Returns false by default if not audio.
|
|
|
|
EXPECT_EQ(false, media_playlist_->GetAC4CbiFlag());
|
|
|
|
|
|
|
|
media_info.mutable_audio_info()->mutable_codec_specific_data()->
|
|
|
|
set_ac4_cbi_flag(false);
|
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(media_info));
|
|
|
|
EXPECT_EQ(false, media_playlist_->GetAC4CbiFlag());
|
|
|
|
|
|
|
|
media_info.mutable_audio_info()->mutable_codec_specific_data()->
|
|
|
|
set_ac4_cbi_flag(true);
|
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(media_info));
|
|
|
|
EXPECT_EQ(true, media_playlist_->GetAC4CbiFlag());
|
|
|
|
}
|
|
|
|
|
2018-10-10 22:30:28 +00:00
|
|
|
TEST_F(MediaPlaylistMultiSegmentTest, Characteristics) {
|
|
|
|
MediaInfo media_info;
|
|
|
|
media_info.set_reference_time_scale(kTimeScale);
|
|
|
|
|
|
|
|
static const char* kCharacteristics[] = {"some.characteristic",
|
|
|
|
"another.characteristic"};
|
|
|
|
|
|
|
|
media_info.add_hls_characteristics(kCharacteristics[0]);
|
|
|
|
media_info.add_hls_characteristics(kCharacteristics[1]);
|
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(media_info));
|
|
|
|
EXPECT_THAT(media_playlist_->characteristics(),
|
|
|
|
ElementsAreArray(kCharacteristics));
|
|
|
|
}
|
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
TEST_F(MediaPlaylistMultiSegmentTest, InitSegment) {
|
|
|
|
valid_video_media_info_.set_reference_time_scale(90000);
|
2018-04-17 17:42:45 +00:00
|
|
|
valid_video_media_info_.set_init_segment_url("init_segment.mp4");
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
2017-03-14 00:02:23 +00:00
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
media_playlist_->AddSegment("file1.mp4", 0, 10 * kTimeScale, kZeroByteOffset,
|
|
|
|
kMBytes);
|
|
|
|
media_playlist_->AddSegment("file2.mp4", 10 * kTimeScale, 30 * kTimeScale,
|
|
|
|
kZeroByteOffset, 5 * kMBytes);
|
2017-03-14 00:02:23 +00:00
|
|
|
|
2017-06-03 00:05:47 +00:00
|
|
|
const char kExpectedOutput[] =
|
2017-03-14 00:02:23 +00:00
|
|
|
"#EXTM3U\n"
|
|
|
|
"#EXT-X-VERSION:6\n"
|
2022-03-07 19:56:34 +00:00
|
|
|
"## Generated with https://github.com/shaka-project/shaka-packager "
|
|
|
|
"version test\n"
|
2017-03-14 00:02:23 +00:00
|
|
|
"#EXT-X-TARGETDURATION:30\n"
|
|
|
|
"#EXT-X-PLAYLIST-TYPE:VOD\n"
|
|
|
|
"#EXT-X-MAP:URI=\"init_segment.mp4\"\n"
|
|
|
|
"#EXTINF:10.000,\n"
|
|
|
|
"file1.mp4\n"
|
|
|
|
"#EXTINF:30.000,\n"
|
|
|
|
"file2.mp4\n"
|
|
|
|
"#EXT-X-ENDLIST\n";
|
|
|
|
|
2017-06-03 00:05:47 +00:00
|
|
|
const char kMemoryFilePath[] = "memory://media.m3u8";
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_TRUE(media_playlist_->WriteToFile(kMemoryFilePath));
|
2017-06-03 00:05:47 +00:00
|
|
|
ASSERT_FILE_STREQ(kMemoryFilePath, kExpectedOutput);
|
2017-03-14 00:02:23 +00:00
|
|
|
}
|
|
|
|
|
2017-04-04 20:57:50 +00:00
|
|
|
// Verify that kSampleAesCenc is handled correctly.
|
2017-05-01 20:38:58 +00:00
|
|
|
TEST_F(MediaPlaylistMultiSegmentTest, SampleAesCenc) {
|
|
|
|
valid_video_media_info_.set_reference_time_scale(90000);
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
2017-04-04 20:57:50 +00:00
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
media_playlist_->AddEncryptionInfo(
|
2017-04-04 20:57:50 +00:00
|
|
|
MediaPlaylist::EncryptionMethod::kSampleAesCenc, "http://example.com", "",
|
|
|
|
"0x12345678", "com.widevine", "1/2/4");
|
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
media_playlist_->AddSegment("file1.ts", 0, 10 * kTimeScale, kZeroByteOffset,
|
|
|
|
kMBytes);
|
|
|
|
media_playlist_->AddSegment("file2.ts", 10 * kTimeScale, 30 * kTimeScale,
|
|
|
|
kZeroByteOffset, 5 * kMBytes);
|
2017-06-03 00:05:47 +00:00
|
|
|
const char kExpectedOutput[] =
|
2017-04-04 20:57:50 +00:00
|
|
|
"#EXTM3U\n"
|
|
|
|
"#EXT-X-VERSION:6\n"
|
2022-03-07 19:56:34 +00:00
|
|
|
"## Generated with https://github.com/shaka-project/shaka-packager "
|
|
|
|
"version test\n"
|
2017-04-04 20:57:50 +00:00
|
|
|
"#EXT-X-TARGETDURATION:30\n"
|
|
|
|
"#EXT-X-PLAYLIST-TYPE:VOD\n"
|
2018-01-12 02:09:06 +00:00
|
|
|
"#EXT-X-KEY:METHOD=SAMPLE-AES-CTR,"
|
2017-04-04 20:57:50 +00:00
|
|
|
"URI=\"http://example.com\",IV=0x12345678,KEYFORMATVERSIONS=\"1/2/4\","
|
|
|
|
"KEYFORMAT=\"com.widevine\"\n"
|
|
|
|
"#EXTINF:10.000,\n"
|
|
|
|
"file1.ts\n"
|
|
|
|
"#EXTINF:30.000,\n"
|
|
|
|
"file2.ts\n"
|
|
|
|
"#EXT-X-ENDLIST\n";
|
|
|
|
|
2017-06-03 00:05:47 +00:00
|
|
|
const char kMemoryFilePath[] = "memory://media.m3u8";
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_TRUE(media_playlist_->WriteToFile(kMemoryFilePath));
|
2017-06-03 00:05:47 +00:00
|
|
|
ASSERT_FILE_STREQ(kMemoryFilePath, kExpectedOutput);
|
2017-04-04 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
TEST_F(MediaPlaylistMultiSegmentTest, MultipleEncryptionInfo) {
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
2017-04-04 20:57:50 +00:00
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
media_playlist_->AddEncryptionInfo(
|
|
|
|
MediaPlaylist::EncryptionMethod::kSampleAes, "http://example.com", "",
|
|
|
|
"0x12345678", "com.widevine", "1/2/4");
|
2017-04-04 20:57:50 +00:00
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
media_playlist_->AddEncryptionInfo(
|
2017-04-04 20:57:50 +00:00
|
|
|
MediaPlaylist::EncryptionMethod::kSampleAes, "http://mydomain.com",
|
|
|
|
"0xfedc", "0x12345678", "com.widevine.someother", "1");
|
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
media_playlist_->AddSegment("file1.ts", 0, 10 * kTimeScale, kZeroByteOffset,
|
|
|
|
kMBytes);
|
|
|
|
media_playlist_->AddSegment("file2.ts", 10 * kTimeScale, 30 * kTimeScale,
|
|
|
|
kZeroByteOffset, 5 * kMBytes);
|
2017-06-03 00:05:47 +00:00
|
|
|
const char kExpectedOutput[] =
|
2017-04-04 20:57:50 +00:00
|
|
|
"#EXTM3U\n"
|
|
|
|
"#EXT-X-VERSION:6\n"
|
2022-03-07 19:56:34 +00:00
|
|
|
"## Generated with https://github.com/shaka-project/shaka-packager "
|
|
|
|
"version test\n"
|
2017-04-04 20:57:50 +00:00
|
|
|
"#EXT-X-TARGETDURATION:30\n"
|
|
|
|
"#EXT-X-PLAYLIST-TYPE:VOD\n"
|
|
|
|
"#EXT-X-KEY:METHOD=SAMPLE-AES,"
|
|
|
|
"URI=\"http://example.com\",IV=0x12345678,KEYFORMATVERSIONS=\"1/2/4\","
|
|
|
|
"KEYFORMAT=\"com.widevine\"\n"
|
|
|
|
"#EXT-X-KEY:METHOD=SAMPLE-AES,"
|
|
|
|
"URI=\"http://mydomain.com\",KEYID=0xfedc,IV=0x12345678,"
|
|
|
|
"KEYFORMATVERSIONS=\"1\","
|
|
|
|
"KEYFORMAT=\"com.widevine.someother\"\n"
|
|
|
|
"#EXTINF:10.000,\n"
|
|
|
|
"file1.ts\n"
|
|
|
|
"#EXTINF:30.000,\n"
|
|
|
|
"file2.ts\n"
|
|
|
|
"#EXT-X-ENDLIST\n";
|
|
|
|
|
2017-06-03 00:05:47 +00:00
|
|
|
const char kMemoryFilePath[] = "memory://media.m3u8";
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_TRUE(media_playlist_->WriteToFile(kMemoryFilePath));
|
2017-06-03 00:05:47 +00:00
|
|
|
ASSERT_FILE_STREQ(kMemoryFilePath, kExpectedOutput);
|
|
|
|
}
|
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
class LiveMediaPlaylistTest : public MediaPlaylistMultiSegmentTest {
|
2017-06-03 00:05:47 +00:00
|
|
|
protected:
|
|
|
|
LiveMediaPlaylistTest()
|
2017-06-30 20:42:46 +00:00
|
|
|
: MediaPlaylistMultiSegmentTest(HlsPlaylistType::kLive) {}
|
2017-06-03 00:05:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(LiveMediaPlaylistTest, Basic) {
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
2017-06-03 00:05:47 +00:00
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
media_playlist_->AddSegment("file1.ts", 0, 10 * kTimeScale, kZeroByteOffset,
|
|
|
|
kMBytes);
|
|
|
|
media_playlist_->AddSegment("file2.ts", 10 * kTimeScale, 20 * kTimeScale,
|
|
|
|
kZeroByteOffset, 2 * kMBytes);
|
2017-06-03 00:05:47 +00:00
|
|
|
const char kExpectedOutput[] =
|
|
|
|
"#EXTM3U\n"
|
|
|
|
"#EXT-X-VERSION:6\n"
|
2022-03-07 19:56:34 +00:00
|
|
|
"## Generated with https://github.com/shaka-project/shaka-packager "
|
|
|
|
"version test\n"
|
2017-06-03 00:05:47 +00:00
|
|
|
"#EXT-X-TARGETDURATION:20\n"
|
|
|
|
"#EXTINF:10.000,\n"
|
|
|
|
"file1.ts\n"
|
|
|
|
"#EXTINF:20.000,\n"
|
|
|
|
"file2.ts\n";
|
|
|
|
|
|
|
|
const char kMemoryFilePath[] = "memory://media.m3u8";
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_TRUE(media_playlist_->WriteToFile(kMemoryFilePath));
|
2017-06-03 00:05:47 +00:00
|
|
|
ASSERT_FILE_STREQ(kMemoryFilePath, kExpectedOutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(LiveMediaPlaylistTest, TimeShifted) {
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
|
|
|
|
|
|
|
media_playlist_->AddSegment("file1.ts", 0, 10 * kTimeScale, kZeroByteOffset,
|
|
|
|
kMBytes);
|
|
|
|
media_playlist_->AddSegment("file2.ts", 10 * kTimeScale, 20 * kTimeScale,
|
|
|
|
kZeroByteOffset, 2 * kMBytes);
|
|
|
|
media_playlist_->AddSegment("file3.ts", 30 * kTimeScale, 20 * kTimeScale,
|
|
|
|
kZeroByteOffset, 2 * kMBytes);
|
2017-06-03 00:05:47 +00:00
|
|
|
const char kExpectedOutput[] =
|
|
|
|
"#EXTM3U\n"
|
|
|
|
"#EXT-X-VERSION:6\n"
|
2022-03-07 19:56:34 +00:00
|
|
|
"## Generated with https://github.com/shaka-project/shaka-packager "
|
|
|
|
"version test\n"
|
2017-06-03 00:05:47 +00:00
|
|
|
"#EXT-X-TARGETDURATION:20\n"
|
|
|
|
"#EXT-X-MEDIA-SEQUENCE:1\n"
|
|
|
|
"#EXTINF:20.000,\n"
|
|
|
|
"file2.ts\n"
|
|
|
|
"#EXTINF:20.000,\n"
|
|
|
|
"file3.ts\n";
|
|
|
|
|
|
|
|
const char kMemoryFilePath[] = "memory://media.m3u8";
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_TRUE(media_playlist_->WriteToFile(kMemoryFilePath));
|
2017-06-03 00:05:47 +00:00
|
|
|
ASSERT_FILE_STREQ(kMemoryFilePath, kExpectedOutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(LiveMediaPlaylistTest, TimeShiftedWithEncryptionInfo) {
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
2017-06-03 00:05:47 +00:00
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
media_playlist_->AddEncryptionInfo(
|
|
|
|
MediaPlaylist::EncryptionMethod::kSampleAes, "http://example.com", "",
|
|
|
|
"0x12345678", "com.widevine", "1/2/4");
|
|
|
|
media_playlist_->AddEncryptionInfo(
|
2017-06-03 00:05:47 +00:00
|
|
|
MediaPlaylist::EncryptionMethod::kSampleAes, "http://mydomain.com",
|
|
|
|
"0xfedc", "0x12345678", "com.widevine.someother", "1");
|
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
media_playlist_->AddSegment("file1.ts", 0, 10 * kTimeScale, kZeroByteOffset,
|
|
|
|
kMBytes);
|
|
|
|
media_playlist_->AddSegment("file2.ts", 10 * kTimeScale, 20 * kTimeScale,
|
|
|
|
kZeroByteOffset, 2 * kMBytes);
|
|
|
|
media_playlist_->AddSegment("file3.ts", 30 * kTimeScale, 20 * kTimeScale,
|
|
|
|
kZeroByteOffset, 2 * kMBytes);
|
2017-06-03 00:05:47 +00:00
|
|
|
const char kExpectedOutput[] =
|
|
|
|
"#EXTM3U\n"
|
|
|
|
"#EXT-X-VERSION:6\n"
|
2022-03-07 19:56:34 +00:00
|
|
|
"## Generated with https://github.com/shaka-project/shaka-packager "
|
|
|
|
"version test\n"
|
2017-06-03 00:05:47 +00:00
|
|
|
"#EXT-X-TARGETDURATION:20\n"
|
|
|
|
"#EXT-X-MEDIA-SEQUENCE:1\n"
|
|
|
|
"#EXT-X-KEY:METHOD=SAMPLE-AES,"
|
|
|
|
"URI=\"http://example.com\",IV=0x12345678,KEYFORMATVERSIONS=\"1/2/4\","
|
|
|
|
"KEYFORMAT=\"com.widevine\"\n"
|
|
|
|
"#EXT-X-KEY:METHOD=SAMPLE-AES,"
|
|
|
|
"URI=\"http://mydomain.com\",KEYID=0xfedc,IV=0x12345678,"
|
|
|
|
"KEYFORMATVERSIONS=\"1\","
|
|
|
|
"KEYFORMAT=\"com.widevine.someother\"\n"
|
|
|
|
"#EXTINF:20.000,\n"
|
|
|
|
"file2.ts\n"
|
|
|
|
"#EXTINF:20.000,\n"
|
|
|
|
"file3.ts\n";
|
|
|
|
|
|
|
|
const char kMemoryFilePath[] = "memory://media.m3u8";
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_TRUE(media_playlist_->WriteToFile(kMemoryFilePath));
|
2017-06-03 00:05:47 +00:00
|
|
|
ASSERT_FILE_STREQ(kMemoryFilePath, kExpectedOutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(LiveMediaPlaylistTest, TimeShiftedWithEncryptionInfoShifted) {
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
2017-06-03 00:05:47 +00:00
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
media_playlist_->AddSegment("file1.ts", 0, 10 * kTimeScale, kZeroByteOffset,
|
|
|
|
kMBytes);
|
2017-06-20 23:30:03 +00:00
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
media_playlist_->AddEncryptionInfo(
|
|
|
|
MediaPlaylist::EncryptionMethod::kSampleAes, "http://example.com", "",
|
|
|
|
"0x12345678", "com.widevine", "1/2/4");
|
|
|
|
media_playlist_->AddEncryptionInfo(
|
2017-06-03 00:05:47 +00:00
|
|
|
MediaPlaylist::EncryptionMethod::kSampleAes, "http://mydomain.com",
|
|
|
|
"0xfedc", "0x12345678", "com.widevine.someother", "1");
|
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
media_playlist_->AddSegment("file2.ts", 10 * kTimeScale, 20 * kTimeScale,
|
|
|
|
kZeroByteOffset, 2 * kMBytes);
|
2017-06-03 00:05:47 +00:00
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
media_playlist_->AddEncryptionInfo(
|
|
|
|
MediaPlaylist::EncryptionMethod::kSampleAes, "http://example.com", "",
|
|
|
|
"0x22345678", "com.widevine", "1/2/4");
|
|
|
|
media_playlist_->AddEncryptionInfo(
|
2017-06-03 00:05:47 +00:00
|
|
|
MediaPlaylist::EncryptionMethod::kSampleAes, "http://mydomain.com",
|
|
|
|
"0xfedd", "0x22345678", "com.widevine.someother", "1");
|
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
media_playlist_->AddSegment("file3.ts", 30 * kTimeScale, 20 * kTimeScale,
|
|
|
|
kZeroByteOffset, 2 * kMBytes);
|
2017-06-03 00:05:47 +00:00
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
media_playlist_->AddEncryptionInfo(
|
|
|
|
MediaPlaylist::EncryptionMethod::kSampleAes, "http://example.com", "",
|
|
|
|
"0x32345678", "com.widevine", "1/2/4");
|
|
|
|
media_playlist_->AddEncryptionInfo(
|
2017-06-03 00:05:47 +00:00
|
|
|
MediaPlaylist::EncryptionMethod::kSampleAes, "http://mydomain.com",
|
|
|
|
"0xfede", "0x32345678", "com.widevine.someother", "1");
|
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
media_playlist_->AddSegment("file4.ts", 50 * kTimeScale, 20 * kTimeScale,
|
|
|
|
kZeroByteOffset, 2 * kMBytes);
|
2017-06-03 00:05:47 +00:00
|
|
|
const char kExpectedOutput[] =
|
|
|
|
"#EXTM3U\n"
|
|
|
|
"#EXT-X-VERSION:6\n"
|
2022-03-07 19:56:34 +00:00
|
|
|
"## Generated with https://github.com/shaka-project/shaka-packager "
|
|
|
|
"version test\n"
|
2017-06-03 00:05:47 +00:00
|
|
|
"#EXT-X-TARGETDURATION:20\n"
|
2017-06-20 23:30:03 +00:00
|
|
|
"#EXT-X-MEDIA-SEQUENCE:2\n"
|
2017-06-03 00:05:47 +00:00
|
|
|
"#EXT-X-DISCONTINUITY-SEQUENCE:1\n"
|
|
|
|
"#EXT-X-KEY:METHOD=SAMPLE-AES,"
|
|
|
|
"URI=\"http://example.com\",IV=0x22345678,KEYFORMATVERSIONS=\"1/2/4\","
|
|
|
|
"KEYFORMAT=\"com.widevine\"\n"
|
|
|
|
"#EXT-X-KEY:METHOD=SAMPLE-AES,"
|
|
|
|
"URI=\"http://mydomain.com\",KEYID=0xfedd,IV=0x22345678,"
|
|
|
|
"KEYFORMATVERSIONS=\"1\","
|
|
|
|
"KEYFORMAT=\"com.widevine.someother\"\n"
|
|
|
|
"#EXTINF:20.000,\n"
|
2017-06-20 23:30:03 +00:00
|
|
|
"file3.ts\n"
|
2017-06-03 00:05:47 +00:00
|
|
|
"#EXT-X-KEY:METHOD=SAMPLE-AES,"
|
|
|
|
"URI=\"http://example.com\",IV=0x32345678,KEYFORMATVERSIONS=\"1/2/4\","
|
|
|
|
"KEYFORMAT=\"com.widevine\"\n"
|
|
|
|
"#EXT-X-KEY:METHOD=SAMPLE-AES,"
|
|
|
|
"URI=\"http://mydomain.com\",KEYID=0xfede,IV=0x32345678,"
|
|
|
|
"KEYFORMATVERSIONS=\"1\","
|
|
|
|
"KEYFORMAT=\"com.widevine.someother\"\n"
|
|
|
|
"#EXTINF:20.000,\n"
|
2017-06-20 23:30:03 +00:00
|
|
|
"file4.ts\n";
|
2017-06-03 00:05:47 +00:00
|
|
|
|
|
|
|
const char kMemoryFilePath[] = "memory://media.m3u8";
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_TRUE(media_playlist_->WriteToFile(kMemoryFilePath));
|
2017-06-03 00:05:47 +00:00
|
|
|
ASSERT_FILE_STREQ(kMemoryFilePath, kExpectedOutput);
|
|
|
|
}
|
|
|
|
|
2017-05-01 20:38:58 +00:00
|
|
|
class EventMediaPlaylistTest : public MediaPlaylistMultiSegmentTest {
|
2017-06-03 00:05:47 +00:00
|
|
|
protected:
|
|
|
|
EventMediaPlaylistTest()
|
2017-06-30 20:42:46 +00:00
|
|
|
: MediaPlaylistMultiSegmentTest(HlsPlaylistType::kEvent) {}
|
2017-06-03 00:05:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(EventMediaPlaylistTest, Basic) {
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
2017-06-03 00:05:47 +00:00
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
media_playlist_->AddSegment("file1.ts", 0, 10 * kTimeScale, kZeroByteOffset,
|
|
|
|
kMBytes);
|
|
|
|
media_playlist_->AddSegment("file2.ts", 10 * kTimeScale, 20 * kTimeScale,
|
|
|
|
kZeroByteOffset, 2 * kMBytes);
|
2017-06-03 00:05:47 +00:00
|
|
|
const char kExpectedOutput[] =
|
|
|
|
"#EXTM3U\n"
|
|
|
|
"#EXT-X-VERSION:6\n"
|
2022-03-07 19:56:34 +00:00
|
|
|
"## Generated with https://github.com/shaka-project/shaka-packager "
|
|
|
|
"version test\n"
|
2017-06-03 00:05:47 +00:00
|
|
|
"#EXT-X-TARGETDURATION:20\n"
|
|
|
|
"#EXT-X-PLAYLIST-TYPE:EVENT\n"
|
|
|
|
"#EXTINF:10.000,\n"
|
|
|
|
"file1.ts\n"
|
|
|
|
"#EXTINF:20.000,\n"
|
|
|
|
"file2.ts\n";
|
|
|
|
|
|
|
|
const char kMemoryFilePath[] = "memory://media.m3u8";
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_TRUE(media_playlist_->WriteToFile(kMemoryFilePath));
|
2017-06-03 00:05:47 +00:00
|
|
|
ASSERT_FILE_STREQ(kMemoryFilePath, kExpectedOutput);
|
2017-04-04 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
2018-01-30 03:17:21 +00:00
|
|
|
class IFrameMediaPlaylistTest : public MediaPlaylistTest {};
|
|
|
|
|
|
|
|
TEST_F(IFrameMediaPlaylistTest, MediaPlaylistType) {
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
2018-01-30 03:17:21 +00:00
|
|
|
EXPECT_EQ(MediaPlaylist::MediaPlaylistStreamType::kVideo,
|
2018-04-14 01:26:02 +00:00
|
|
|
media_playlist_->stream_type());
|
|
|
|
media_playlist_->AddKeyFrame(0, 1000, 2345);
|
2018-01-30 03:17:21 +00:00
|
|
|
// Playlist stream type is updated to I-Frames only after seeing
|
|
|
|
// |AddKeyFrame|.
|
|
|
|
EXPECT_EQ(MediaPlaylist::MediaPlaylistStreamType::kVideoIFramesOnly,
|
2018-04-14 01:26:02 +00:00
|
|
|
media_playlist_->stream_type());
|
2018-01-30 03:17:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(IFrameMediaPlaylistTest, SingleSegment) {
|
2018-04-17 17:42:45 +00:00
|
|
|
valid_video_media_info_.set_media_file_url("file.mp4");
|
2018-01-30 03:17:21 +00:00
|
|
|
valid_video_media_info_.mutable_init_range()->set_begin(0);
|
|
|
|
valid_video_media_info_.mutable_init_range()->set_end(500);
|
|
|
|
|
2018-04-14 01:26:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
|
|
|
media_playlist_->AddKeyFrame(0, 1000, 2345);
|
|
|
|
media_playlist_->AddKeyFrame(2 * kTimeScale, 5000, 6345);
|
|
|
|
media_playlist_->AddSegment("file.mp4", 0, 10 * kTimeScale, kZeroByteOffset,
|
|
|
|
kMBytes);
|
|
|
|
media_playlist_->AddKeyFrame(11 * kTimeScale, kMBytes + 1000, 2345);
|
|
|
|
media_playlist_->AddKeyFrame(15 * kTimeScale, kMBytes + 3345, 12345);
|
|
|
|
media_playlist_->AddSegment("file.mp4", 10 * kTimeScale, 10 * kTimeScale,
|
|
|
|
1001000, 2 * kMBytes);
|
2018-01-30 03:17:21 +00:00
|
|
|
|
|
|
|
const char kExpectedOutput[] =
|
|
|
|
"#EXTM3U\n"
|
|
|
|
"#EXT-X-VERSION:6\n"
|
2022-03-07 19:56:34 +00:00
|
|
|
"## Generated with https://github.com/shaka-project/shaka-packager "
|
|
|
|
"version test\n"
|
2018-05-23 17:24:57 +00:00
|
|
|
"#EXT-X-TARGETDURATION:9\n"
|
2018-01-30 03:17:21 +00:00
|
|
|
"#EXT-X-PLAYLIST-TYPE:VOD\n"
|
|
|
|
"#EXT-X-I-FRAMES-ONLY\n"
|
|
|
|
"#EXT-X-MAP:URI=\"file.mp4\",BYTERANGE=\"501@0\"\n"
|
|
|
|
"#EXTINF:2.000,\n"
|
|
|
|
"#EXT-X-BYTERANGE:2345@1000\n"
|
|
|
|
"file.mp4\n"
|
|
|
|
"#EXTINF:9.000,\n"
|
|
|
|
"#EXT-X-BYTERANGE:6345@5000\n"
|
|
|
|
"file.mp4\n"
|
|
|
|
"#EXTINF:4.000,\n"
|
|
|
|
"#EXT-X-BYTERANGE:2345@1001000\n"
|
|
|
|
"file.mp4\n"
|
|
|
|
"#EXTINF:5.000,\n"
|
|
|
|
"#EXT-X-BYTERANGE:12345\n"
|
|
|
|
"file.mp4\n"
|
|
|
|
"#EXT-X-ENDLIST\n";
|
|
|
|
|
|
|
|
const char kMemoryFilePath[] = "memory://media.m3u8";
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_TRUE(media_playlist_->WriteToFile(kMemoryFilePath));
|
2018-01-30 03:17:21 +00:00
|
|
|
ASSERT_FILE_STREQ(kMemoryFilePath, kExpectedOutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(IFrameMediaPlaylistTest, MultiSegment) {
|
|
|
|
valid_video_media_info_.set_reference_time_scale(90000);
|
2018-04-14 01:26:02 +00:00
|
|
|
valid_video_media_info_.set_segment_template_url("file$Number$.ts");
|
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
|
|
|
|
|
|
|
media_playlist_->AddKeyFrame(0, 1000, 2345);
|
|
|
|
media_playlist_->AddKeyFrame(2 * kTimeScale, 5000, 6345);
|
|
|
|
media_playlist_->AddSegment("file1.ts", 0, 10 * kTimeScale, kZeroByteOffset,
|
|
|
|
kMBytes);
|
|
|
|
media_playlist_->AddKeyFrame(11 * kTimeScale, 1000, 2345);
|
|
|
|
media_playlist_->AddKeyFrame(15 * kTimeScale, 3345, 12345);
|
|
|
|
media_playlist_->AddSegment("file2.ts", 10 * kTimeScale, 30 * kTimeScale,
|
|
|
|
kZeroByteOffset, 5 * kMBytes);
|
2018-01-30 03:17:21 +00:00
|
|
|
|
|
|
|
const char kExpectedOutput[] =
|
|
|
|
"#EXTM3U\n"
|
|
|
|
"#EXT-X-VERSION:6\n"
|
2022-03-07 19:56:34 +00:00
|
|
|
"## Generated with https://github.com/shaka-project/shaka-packager "
|
|
|
|
"version test\n"
|
2018-01-30 03:17:21 +00:00
|
|
|
"#EXT-X-TARGETDURATION:25\n"
|
|
|
|
"#EXT-X-PLAYLIST-TYPE:VOD\n"
|
|
|
|
"#EXT-X-I-FRAMES-ONLY\n"
|
|
|
|
"#EXTINF:2.000,\n"
|
|
|
|
"#EXT-X-BYTERANGE:2345@1000\n"
|
|
|
|
"file1.ts\n"
|
|
|
|
"#EXTINF:9.000,\n"
|
|
|
|
"#EXT-X-BYTERANGE:6345@5000\n"
|
|
|
|
"file1.ts\n"
|
|
|
|
"#EXTINF:4.000,\n"
|
|
|
|
"#EXT-X-BYTERANGE:2345@1000\n"
|
|
|
|
"file2.ts\n"
|
|
|
|
"#EXTINF:25.000,\n"
|
|
|
|
"#EXT-X-BYTERANGE:12345\n"
|
|
|
|
"file2.ts\n"
|
|
|
|
"#EXT-X-ENDLIST\n";
|
|
|
|
|
|
|
|
const char kMemoryFilePath[] = "memory://media.m3u8";
|
2018-04-14 01:26:02 +00:00
|
|
|
EXPECT_TRUE(media_playlist_->WriteToFile(kMemoryFilePath));
|
2018-01-30 03:17:21 +00:00
|
|
|
ASSERT_FILE_STREQ(kMemoryFilePath, kExpectedOutput);
|
|
|
|
}
|
|
|
|
|
2018-05-16 17:56:22 +00:00
|
|
|
TEST_F(IFrameMediaPlaylistTest, MultiSegmentWithPlacementOpportunity) {
|
|
|
|
valid_video_media_info_.set_reference_time_scale(90000);
|
|
|
|
valid_video_media_info_.set_segment_template_url("file$Number$.ts");
|
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
|
|
|
|
|
|
|
media_playlist_->AddKeyFrame(0, 1000, 2345);
|
|
|
|
media_playlist_->AddKeyFrame(2 * kTimeScale, 5000, 6345);
|
|
|
|
media_playlist_->AddSegment("file1.ts", 0, 10 * kTimeScale, kZeroByteOffset,
|
|
|
|
kMBytes);
|
|
|
|
media_playlist_->AddPlacementOpportunity();
|
|
|
|
media_playlist_->AddKeyFrame(11 * kTimeScale, 1000, 2345);
|
|
|
|
media_playlist_->AddKeyFrame(15 * kTimeScale, 3345, 12345);
|
|
|
|
media_playlist_->AddSegment("file2.ts", 10 * kTimeScale, 30 * kTimeScale,
|
|
|
|
kZeroByteOffset, 5 * kMBytes);
|
|
|
|
|
|
|
|
const char kExpectedOutput[] =
|
|
|
|
"#EXTM3U\n"
|
|
|
|
"#EXT-X-VERSION:6\n"
|
2022-03-07 19:56:34 +00:00
|
|
|
"## Generated with https://github.com/shaka-project/shaka-packager "
|
|
|
|
"version test\n"
|
2018-05-16 17:56:22 +00:00
|
|
|
"#EXT-X-TARGETDURATION:25\n"
|
|
|
|
"#EXT-X-PLAYLIST-TYPE:VOD\n"
|
|
|
|
"#EXT-X-I-FRAMES-ONLY\n"
|
|
|
|
"#EXTINF:2.000,\n"
|
|
|
|
"#EXT-X-BYTERANGE:2345@1000\n"
|
|
|
|
"file1.ts\n"
|
|
|
|
"#EXTINF:9.000,\n"
|
|
|
|
"#EXT-X-BYTERANGE:6345@5000\n"
|
|
|
|
"file1.ts\n"
|
|
|
|
"#EXT-X-PLACEMENT-OPPORTUNITY\n"
|
|
|
|
"#EXTINF:4.000,\n"
|
|
|
|
"#EXT-X-BYTERANGE:2345@1000\n"
|
|
|
|
"file2.ts\n"
|
|
|
|
"#EXTINF:25.000,\n"
|
|
|
|
"#EXT-X-BYTERANGE:12345\n"
|
|
|
|
"file2.ts\n"
|
|
|
|
"#EXT-X-ENDLIST\n";
|
|
|
|
|
|
|
|
const char kMemoryFilePath[] = "memory://media.m3u8";
|
|
|
|
EXPECT_TRUE(media_playlist_->WriteToFile(kMemoryFilePath));
|
|
|
|
ASSERT_FILE_STREQ(kMemoryFilePath, kExpectedOutput);
|
|
|
|
}
|
|
|
|
|
2018-04-17 22:03:02 +00:00
|
|
|
namespace {
|
|
|
|
const int kNumPreservedSegmentsOutsideLiveWindow = 3;
|
|
|
|
const int kMaxNumSegmentsAvailable =
|
|
|
|
kTimeShiftBufferDepth + 1 + kNumPreservedSegmentsOutsideLiveWindow;
|
|
|
|
|
2019-08-07 23:14:45 +00:00
|
|
|
const char kSegmentTemplateNumber[] = "memory://$Number$.mp4";
|
|
|
|
const char kSegmentTemplateNumberUrl[] = "video/$Number$.mp4";
|
2018-04-17 22:03:02 +00:00
|
|
|
const char kStringPrintTemplate[] = "memory://%d.mp4";
|
|
|
|
const char kIgnoredSegmentName[] = "ignored_segment_name";
|
|
|
|
|
2019-08-07 23:14:45 +00:00
|
|
|
const char kSegmentTemplateTime[] = "memory://$Time$.mp4";
|
|
|
|
const char kSegmentTemplateTimeUrl[] = "video/$Time$.mp4";
|
|
|
|
|
2021-08-04 18:56:44 +00:00
|
|
|
const int64_t kInitialStartTime = 0;
|
|
|
|
const int64_t kDuration = kTimeScale;
|
2018-04-17 22:03:02 +00:00
|
|
|
} // namespace
|
|
|
|
|
2019-08-07 23:14:45 +00:00
|
|
|
class MediaPlaylistDeleteSegmentsTest
|
|
|
|
: public LiveMediaPlaylistTest,
|
|
|
|
public WithParamInterface<std::pair<std::string, std::string>> {
|
2018-04-17 22:03:02 +00:00
|
|
|
public:
|
|
|
|
void SetUp() override {
|
|
|
|
LiveMediaPlaylistTest::SetUp();
|
|
|
|
|
2019-08-07 23:14:45 +00:00
|
|
|
std::tie(segment_template_, segment_template_url_) = GetParam();
|
|
|
|
|
2018-04-17 22:03:02 +00:00
|
|
|
// Create 100 files with the template.
|
2019-08-07 23:14:45 +00:00
|
|
|
for (int i = 0; i < 100; ++i) {
|
|
|
|
File::WriteStringToFile(GetSegmentName(i).c_str(), "dummy content");
|
2018-04-17 22:03:02 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 23:14:45 +00:00
|
|
|
valid_video_media_info_.set_segment_template(segment_template_);
|
|
|
|
valid_video_media_info_.set_segment_template_url(segment_template_url_);
|
2018-04-17 22:03:02 +00:00
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
|
|
|
|
|
|
|
mutable_hls_params()->preserved_segments_outside_live_window =
|
|
|
|
kNumPreservedSegmentsOutsideLiveWindow;
|
|
|
|
}
|
|
|
|
|
2019-08-07 23:14:45 +00:00
|
|
|
int GetTime(int index) const { return kInitialStartTime + index * kDuration; }
|
|
|
|
|
|
|
|
std::string GetSegmentName(int index) {
|
|
|
|
if (segment_template_.find("$Time$") != std::string::npos)
|
2023-12-01 17:32:19 +00:00
|
|
|
return absl::StrFormat(kStringPrintTemplate, GetTime(index));
|
|
|
|
return absl::StrFormat(kStringPrintTemplate, index + 1);
|
2019-08-07 23:14:45 +00:00
|
|
|
}
|
|
|
|
|
2018-04-17 22:03:02 +00:00
|
|
|
bool SegmentDeleted(const std::string& segment_name) {
|
|
|
|
std::unique_ptr<File, FileCloser> file_closer(
|
|
|
|
File::Open(segment_name.c_str(), "r"));
|
|
|
|
return file_closer.get() == nullptr;
|
|
|
|
}
|
2019-08-07 23:14:45 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::string segment_template_;
|
|
|
|
std::string segment_template_url_;
|
2018-04-17 22:03:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Verify that no segments are deleted initially until there are more than
|
|
|
|
// |kMaxNumSegmentsAvailable| segments.
|
2019-08-07 23:14:45 +00:00
|
|
|
TEST_P(MediaPlaylistDeleteSegmentsTest, NoSegmentsDeletedInitially) {
|
2018-04-17 22:03:02 +00:00
|
|
|
for (int i = 0; i < kMaxNumSegmentsAvailable; ++i) {
|
2019-08-07 23:14:45 +00:00
|
|
|
media_playlist_->AddSegment(kIgnoredSegmentName, GetTime(i), kDuration,
|
2018-04-17 22:03:02 +00:00
|
|
|
kZeroByteOffset, kMBytes);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < kMaxNumSegmentsAvailable; ++i) {
|
2019-08-07 23:14:45 +00:00
|
|
|
EXPECT_FALSE(SegmentDeleted(GetSegmentName(i)));
|
2018-04-17 22:03:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-07 23:14:45 +00:00
|
|
|
TEST_P(MediaPlaylistDeleteSegmentsTest, OneSegmentDeleted) {
|
2018-04-17 22:03:02 +00:00
|
|
|
for (int i = 0; i <= kMaxNumSegmentsAvailable; ++i) {
|
2019-08-07 23:14:45 +00:00
|
|
|
media_playlist_->AddSegment(kIgnoredSegmentName, GetTime(i), kDuration,
|
2018-04-17 22:03:02 +00:00
|
|
|
kZeroByteOffset, kMBytes);
|
|
|
|
}
|
2019-08-07 23:14:45 +00:00
|
|
|
EXPECT_FALSE(SegmentDeleted(GetSegmentName(1)));
|
|
|
|
EXPECT_TRUE(SegmentDeleted(GetSegmentName(0)));
|
2018-04-17 22:03:02 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 23:14:45 +00:00
|
|
|
TEST_P(MediaPlaylistDeleteSegmentsTest, ManySegments) {
|
2018-04-17 22:03:02 +00:00
|
|
|
int many_segments = 50;
|
|
|
|
for (int i = 0; i < many_segments; ++i) {
|
2019-08-07 23:14:45 +00:00
|
|
|
media_playlist_->AddSegment(kIgnoredSegmentName, GetTime(i), kDuration,
|
2018-04-17 22:03:02 +00:00
|
|
|
kZeroByteOffset, kMBytes);
|
|
|
|
}
|
|
|
|
const int last_available_segment_index =
|
2019-08-07 23:14:45 +00:00
|
|
|
many_segments - kMaxNumSegmentsAvailable;
|
|
|
|
EXPECT_FALSE(SegmentDeleted(GetSegmentName(last_available_segment_index)));
|
|
|
|
EXPECT_TRUE(SegmentDeleted(GetSegmentName(last_available_segment_index - 1)));
|
2018-04-17 22:03:02 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 23:14:45 +00:00
|
|
|
INSTANTIATE_TEST_CASE_P(
|
|
|
|
TimeOrNumber,
|
|
|
|
MediaPlaylistDeleteSegmentsTest,
|
|
|
|
Values(std::make_pair(kSegmentTemplateNumber, kSegmentTemplateNumberUrl),
|
|
|
|
std::make_pair(kSegmentTemplateTime, kSegmentTemplateTimeUrl)));
|
|
|
|
|
2019-05-15 05:54:28 +00:00
|
|
|
class MediaPlaylistCodecTest
|
|
|
|
: public MediaPlaylistTest,
|
|
|
|
public WithParamInterface<std::pair<std::string, std::string>> {};
|
|
|
|
|
|
|
|
TEST_P(MediaPlaylistCodecTest, AdjustVideoCodec) {
|
|
|
|
std::string input_codec, expected_output_codec;
|
|
|
|
std::tie(input_codec, expected_output_codec) = GetParam();
|
|
|
|
|
|
|
|
valid_video_media_info_.mutable_video_info()->set_codec(input_codec);
|
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(valid_video_media_info_));
|
|
|
|
ASSERT_EQ(media_playlist_->codec(), expected_output_codec);
|
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(
|
|
|
|
Codecs,
|
|
|
|
MediaPlaylistCodecTest,
|
|
|
|
Values(std::make_pair("avc1.4d401e", "avc1.4d401e"),
|
|
|
|
// Replace avc3 with avc1.
|
|
|
|
std::make_pair("avc3.4d401e", "avc1.4d401e"),
|
|
|
|
std::make_pair("hvc1.2.4.L63.90", "hvc1.2.4.L63.90"),
|
|
|
|
// Replace hev1 with hvc1.
|
|
|
|
std::make_pair("hev1.2.4.L63.90", "hvc1.2.4.L63.90"),
|
2019-10-01 01:22:21 +00:00
|
|
|
std::make_pair("dvh1.05.08", "dvh1.05.08"),
|
2019-05-15 05:54:28 +00:00
|
|
|
// Replace dvhe with dvh1.
|
2019-10-01 01:22:21 +00:00
|
|
|
std::make_pair("dvhe.05.08", "dvh1.05.08")));
|
|
|
|
|
|
|
|
struct VideoRangeTestData {
|
|
|
|
std::string codec;
|
|
|
|
int transfer_characteristics;
|
|
|
|
std::string expected_video_range;
|
|
|
|
};
|
|
|
|
|
|
|
|
class MediaPlaylistVideoRangeTest
|
|
|
|
: public MediaPlaylistTest,
|
|
|
|
public WithParamInterface<VideoRangeTestData> {};
|
|
|
|
|
|
|
|
TEST_P(MediaPlaylistVideoRangeTest, GetVideoRange) {
|
|
|
|
const VideoRangeTestData& test_data = GetParam();
|
|
|
|
MediaInfo media_info;
|
|
|
|
media_info.set_reference_time_scale(kTimeScale);
|
|
|
|
MediaInfo::VideoInfo* video_info = media_info.mutable_video_info();
|
|
|
|
video_info->set_codec(test_data.codec);
|
|
|
|
video_info->set_transfer_characteristics(test_data.transfer_characteristics);
|
|
|
|
ASSERT_TRUE(media_playlist_->SetMediaInfo(media_info));
|
|
|
|
EXPECT_EQ(test_data.expected_video_range, media_playlist_->GetVideoRange());
|
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(VideoRanges,
|
|
|
|
MediaPlaylistVideoRangeTest,
|
|
|
|
Values(VideoRangeTestData{"hvc1.2.4.L63.90", 0, ""},
|
|
|
|
VideoRangeTestData{"hvc1.2.4.L63.90", 1, "SDR"},
|
|
|
|
VideoRangeTestData{"hvc1.2.4.L63.90", 16, "PQ"},
|
|
|
|
VideoRangeTestData{"hvc1.2.4.L63.90", 18, "PQ"},
|
|
|
|
VideoRangeTestData{"dvh1.05.08", 0, "PQ"}));
|
2019-05-15 05:54:28 +00:00
|
|
|
|
2016-03-25 08:35:44 +00:00
|
|
|
} // namespace hls
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|