2016-03-25 08:39:07 +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-06-15 20:00:28 +00:00
|
|
|
#include "packager/base/files/file_path.h"
|
2017-07-10 18:26:22 +00:00
|
|
|
#include "packager/file/file.h"
|
2016-03-25 08:39:07 +00:00
|
|
|
#include "packager/hls/base/master_playlist.h"
|
|
|
|
#include "packager/hls/base/media_playlist.h"
|
|
|
|
#include "packager/hls/base/mock_media_playlist.h"
|
2016-07-07 19:34:07 +00:00
|
|
|
#include "packager/version/version.h"
|
2016-03-25 08:39:07 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2016-03-25 08:39:07 +00:00
|
|
|
namespace hls {
|
|
|
|
|
2018-01-26 23:53:58 +00:00
|
|
|
using base::FilePath;
|
|
|
|
using ::testing::_;
|
2016-03-25 08:39:07 +00:00
|
|
|
using ::testing::AtLeast;
|
2017-06-14 19:25:17 +00:00
|
|
|
using ::testing::NotNull;
|
2016-03-25 08:39:07 +00:00
|
|
|
using ::testing::Return;
|
|
|
|
using ::testing::ReturnRef;
|
2017-06-14 19:25:17 +00:00
|
|
|
using ::testing::SetArgPointee;
|
2017-06-03 00:05:47 +00:00
|
|
|
using ::testing::StrEq;
|
2016-03-25 08:39:07 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
const char kDefaultMasterPlaylistName[] = "playlist.m3u8";
|
2018-11-20 00:09:24 +00:00
|
|
|
const char kDefaultAudioLanguage[] = "en";
|
|
|
|
const char kDefaultTextLanguage[] = "fr";
|
2017-06-14 19:25:17 +00:00
|
|
|
const uint32_t kWidth = 800;
|
|
|
|
const uint32_t kHeight = 600;
|
2018-01-26 23:53:58 +00:00
|
|
|
|
|
|
|
std::unique_ptr<MockMediaPlaylist> CreateVideoPlaylist(
|
|
|
|
const std::string& filename,
|
|
|
|
const std::string& codec,
|
2018-05-31 21:27:21 +00:00
|
|
|
uint64_t max_bitrate,
|
|
|
|
uint64_t avg_bitrate) {
|
2018-01-26 23:53:58 +00:00
|
|
|
const char kNoName[] = "";
|
|
|
|
const char kNoGroup[] = "";
|
|
|
|
|
|
|
|
std::unique_ptr<MockMediaPlaylist> playlist(
|
2018-04-14 01:26:02 +00:00
|
|
|
new MockMediaPlaylist(filename, kNoName, kNoGroup));
|
2018-01-26 23:53:58 +00:00
|
|
|
|
|
|
|
playlist->SetStreamTypeForTesting(
|
|
|
|
MediaPlaylist::MediaPlaylistStreamType::kVideo);
|
|
|
|
playlist->SetCodecForTesting(codec);
|
|
|
|
|
2018-05-31 21:27:21 +00:00
|
|
|
EXPECT_CALL(*playlist, MaxBitrate())
|
2018-01-26 23:53:58 +00:00
|
|
|
.Times(AtLeast(1))
|
2018-05-31 21:27:21 +00:00
|
|
|
.WillRepeatedly(Return(max_bitrate));
|
|
|
|
EXPECT_CALL(*playlist, AvgBitrate())
|
|
|
|
.Times(AtLeast(1))
|
|
|
|
.WillRepeatedly(Return(avg_bitrate));
|
2018-01-26 23:53:58 +00:00
|
|
|
EXPECT_CALL(*playlist, GetDisplayResolution(NotNull(), NotNull()))
|
|
|
|
.WillRepeatedly(DoAll(SetArgPointee<0>(kWidth), SetArgPointee<1>(kHeight),
|
|
|
|
Return(true)));
|
|
|
|
|
|
|
|
return playlist;
|
|
|
|
}
|
|
|
|
|
2018-02-02 22:45:52 +00:00
|
|
|
std::unique_ptr<MockMediaPlaylist> CreateIframePlaylist(
|
|
|
|
const std::string& filename,
|
|
|
|
const std::string& codec,
|
2018-05-31 21:27:21 +00:00
|
|
|
uint64_t max_bitrate,
|
|
|
|
uint64_t avg_bitrate) {
|
|
|
|
auto playlist =
|
|
|
|
CreateVideoPlaylist(filename, codec, max_bitrate, avg_bitrate);
|
2018-02-02 22:45:52 +00:00
|
|
|
playlist->SetStreamTypeForTesting(
|
|
|
|
MediaPlaylist::MediaPlaylistStreamType::kVideoIFramesOnly);
|
|
|
|
return playlist;
|
|
|
|
}
|
|
|
|
|
2018-01-26 23:53:58 +00:00
|
|
|
std::unique_ptr<MockMediaPlaylist> CreateAudioPlaylist(
|
|
|
|
const std::string& filename,
|
|
|
|
const std::string& name,
|
|
|
|
const std::string& group,
|
|
|
|
const std::string& codec,
|
|
|
|
const std::string& language,
|
|
|
|
uint64_t channels,
|
2018-05-31 21:27:21 +00:00
|
|
|
uint64_t max_bitrate,
|
|
|
|
uint64_t avg_bitrate) {
|
2018-01-26 23:53:58 +00:00
|
|
|
std::unique_ptr<MockMediaPlaylist> playlist(
|
2018-04-14 01:26:02 +00:00
|
|
|
new MockMediaPlaylist(filename, name, group));
|
2018-01-26 23:53:58 +00:00
|
|
|
|
|
|
|
EXPECT_CALL(*playlist, GetNumChannels()).WillRepeatedly(Return(channels));
|
|
|
|
|
|
|
|
playlist->SetStreamTypeForTesting(
|
|
|
|
MediaPlaylist::MediaPlaylistStreamType::kAudio);
|
|
|
|
playlist->SetCodecForTesting(codec);
|
2018-04-05 01:27:57 +00:00
|
|
|
playlist->SetLanguageForTesting(language);
|
2018-01-26 23:53:58 +00:00
|
|
|
|
2018-05-31 21:27:21 +00:00
|
|
|
EXPECT_CALL(*playlist, MaxBitrate())
|
|
|
|
.Times(AtLeast(1))
|
|
|
|
.WillRepeatedly(Return(max_bitrate));
|
|
|
|
EXPECT_CALL(*playlist, AvgBitrate())
|
2018-01-26 23:53:58 +00:00
|
|
|
.Times(AtLeast(1))
|
2018-05-31 21:27:21 +00:00
|
|
|
.WillRepeatedly(Return(avg_bitrate));
|
2018-11-28 00:10:07 +00:00
|
|
|
ON_CALL(*playlist, GetDisplayResolution(NotNull(), NotNull()))
|
|
|
|
.WillByDefault(Return(false));
|
2018-01-26 23:53:58 +00:00
|
|
|
|
|
|
|
return playlist;
|
|
|
|
}
|
2018-01-31 19:14:15 +00:00
|
|
|
|
2018-02-02 22:45:52 +00:00
|
|
|
std::unique_ptr<MockMediaPlaylist> CreateTextPlaylist(
|
|
|
|
const std::string& filename,
|
|
|
|
const std::string& name,
|
|
|
|
const std::string& group,
|
2018-02-26 20:13:28 +00:00
|
|
|
const std::string& codec,
|
2018-02-02 22:45:52 +00:00
|
|
|
const std::string& language) {
|
2018-01-31 19:14:15 +00:00
|
|
|
std::unique_ptr<MockMediaPlaylist> playlist(
|
2018-04-14 01:26:02 +00:00
|
|
|
new MockMediaPlaylist(filename, name, group));
|
2018-01-31 19:14:15 +00:00
|
|
|
|
|
|
|
playlist->SetStreamTypeForTesting(
|
|
|
|
MediaPlaylist::MediaPlaylistStreamType::kSubtitle);
|
2018-02-26 20:13:28 +00:00
|
|
|
playlist->SetCodecForTesting(codec);
|
2018-04-05 01:27:57 +00:00
|
|
|
playlist->SetLanguageForTesting(language);
|
2018-01-31 19:14:15 +00:00
|
|
|
|
|
|
|
return playlist;
|
|
|
|
}
|
2016-03-25 08:39:07 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
class MasterPlaylistTest : public ::testing::Test {
|
|
|
|
protected:
|
2017-06-15 20:00:28 +00:00
|
|
|
MasterPlaylistTest()
|
2018-11-20 00:09:24 +00:00
|
|
|
: master_playlist_(kDefaultMasterPlaylistName,
|
|
|
|
kDefaultAudioLanguage,
|
|
|
|
kDefaultTextLanguage),
|
2017-06-15 20:00:28 +00:00
|
|
|
test_output_dir_("memory://test_dir"),
|
|
|
|
master_playlist_path_(
|
|
|
|
FilePath::FromUTF8Unsafe(test_output_dir_)
|
|
|
|
.Append(FilePath::FromUTF8Unsafe(kDefaultMasterPlaylistName))
|
|
|
|
.AsUTF8Unsafe()) {}
|
2016-03-25 08:39:07 +00:00
|
|
|
|
2018-01-26 23:53:58 +00:00
|
|
|
void SetUp() override { SetPackagerVersionForTesting("test"); }
|
2016-03-25 08:39:07 +00:00
|
|
|
|
|
|
|
MasterPlaylist master_playlist_;
|
|
|
|
std::string test_output_dir_;
|
2017-06-15 20:00:28 +00:00
|
|
|
std::string master_playlist_path_;
|
2016-03-25 08:39:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(MasterPlaylistTest, WriteMasterPlaylistOneVideo) {
|
2018-05-31 21:27:21 +00:00
|
|
|
const uint64_t kMaxBitrate = 435889;
|
|
|
|
const uint64_t kAvgBitrate = 235889;
|
2018-01-26 23:53:58 +00:00
|
|
|
|
|
|
|
std::unique_ptr<MockMediaPlaylist> mock_playlist =
|
2018-05-31 21:27:21 +00:00
|
|
|
CreateVideoPlaylist("media1.m3u8", "avc1", kMaxBitrate, kAvgBitrate);
|
2016-03-25 08:39:07 +00:00
|
|
|
|
|
|
|
const char kBaseUrl[] = "http://myplaylistdomain.com/";
|
2018-02-02 17:14:46 +00:00
|
|
|
EXPECT_TRUE(master_playlist_.WriteMasterPlaylist(kBaseUrl, test_output_dir_,
|
|
|
|
{mock_playlist.get()}));
|
2016-03-25 08:39:07 +00:00
|
|
|
|
|
|
|
std::string actual;
|
2017-07-10 18:26:22 +00:00
|
|
|
ASSERT_TRUE(File::ReadFileToString(master_playlist_path_.c_str(), &actual));
|
2016-03-25 08:39:07 +00:00
|
|
|
|
|
|
|
const std::string expected =
|
|
|
|
"#EXTM3U\n"
|
2016-07-07 19:34:07 +00:00
|
|
|
"## Generated with https://github.com/google/shaka-packager version "
|
|
|
|
"test\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"\n"
|
2018-05-31 21:27:21 +00:00
|
|
|
"#EXT-X-STREAM-INF:BANDWIDTH=435889,AVERAGE-BANDWIDTH=235889,"
|
|
|
|
"CODECS=\"avc1\",RESOLUTION=800x600\n"
|
2016-03-25 08:39:07 +00:00
|
|
|
"http://myplaylistdomain.com/media1.m3u8\n";
|
|
|
|
|
|
|
|
ASSERT_EQ(expected, actual);
|
|
|
|
}
|
|
|
|
|
2018-02-02 22:45:52 +00:00
|
|
|
TEST_F(MasterPlaylistTest, WriteMasterPlaylistOneIframePlaylist) {
|
2018-05-31 21:27:21 +00:00
|
|
|
const uint64_t kMaxBitrate = 435889;
|
|
|
|
const uint64_t kAvgBitrate = 235889;
|
2018-02-02 22:45:52 +00:00
|
|
|
|
|
|
|
std::unique_ptr<MockMediaPlaylist> mock_playlist =
|
2018-05-31 21:27:21 +00:00
|
|
|
CreateIframePlaylist("media1.m3u8", "avc1", kMaxBitrate, kAvgBitrate);
|
2018-02-02 22:45:52 +00:00
|
|
|
|
|
|
|
const char kBaseUrl[] = "http://myplaylistdomain.com/";
|
|
|
|
EXPECT_TRUE(master_playlist_.WriteMasterPlaylist(kBaseUrl, test_output_dir_,
|
|
|
|
{mock_playlist.get()}));
|
|
|
|
|
|
|
|
std::string actual;
|
|
|
|
ASSERT_TRUE(File::ReadFileToString(master_playlist_path_.c_str(), &actual));
|
|
|
|
|
|
|
|
const std::string expected =
|
|
|
|
"#EXTM3U\n"
|
|
|
|
"## Generated with https://github.com/google/shaka-packager version "
|
|
|
|
"test\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"\n"
|
2018-05-31 21:27:21 +00:00
|
|
|
"#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=435889,AVERAGE-BANDWIDTH=235889,"
|
|
|
|
"CODECS=\"avc1\",RESOLUTION=800x600,"
|
|
|
|
"URI=\"http://myplaylistdomain.com/media1.m3u8\"\n";
|
2018-02-02 22:45:52 +00:00
|
|
|
|
|
|
|
ASSERT_EQ(expected, actual);
|
|
|
|
}
|
|
|
|
|
2016-03-25 08:39:07 +00:00
|
|
|
TEST_F(MasterPlaylistTest, WriteMasterPlaylistVideoAndAudio) {
|
2018-05-31 21:27:21 +00:00
|
|
|
const uint64_t kVideo1MaxBitrate = 300000;
|
|
|
|
const uint64_t kVideo1AvgBitrate = 200000;
|
|
|
|
const uint64_t kVideo2MaxBitrate = 700000;
|
|
|
|
const uint64_t kVideo2AvgBitrate = 400000;
|
2018-01-26 23:53:58 +00:00
|
|
|
|
2018-05-31 21:27:21 +00:00
|
|
|
const uint64_t kAudio1MaxBitrate = 50000;
|
|
|
|
const uint64_t kAudio1AvgBitrate = 40000;
|
|
|
|
const uint64_t kAudio2MaxBitrate = 60000;
|
|
|
|
const uint64_t kAudio2AvgBitrate = 30000;
|
2018-01-26 23:53:58 +00:00
|
|
|
|
|
|
|
const uint64_t kAudio1Channels = 2;
|
|
|
|
const uint64_t kAudio2Channels = 5;
|
|
|
|
|
2016-03-25 08:39:07 +00:00
|
|
|
// First video, sd.m3u8.
|
2018-05-31 21:27:21 +00:00
|
|
|
std::unique_ptr<MockMediaPlaylist> sd_video_playlist = CreateVideoPlaylist(
|
|
|
|
"sd.m3u8", "sdvideocodec", kVideo1MaxBitrate, kVideo1AvgBitrate);
|
2016-03-25 08:39:07 +00:00
|
|
|
|
|
|
|
// Second video, hd.m3u8.
|
2018-05-31 21:27:21 +00:00
|
|
|
std::unique_ptr<MockMediaPlaylist> hd_video_playlist = CreateVideoPlaylist(
|
|
|
|
"hd.m3u8", "hdvideocodec", kVideo2MaxBitrate, kVideo2AvgBitrate);
|
2016-03-25 08:39:07 +00:00
|
|
|
|
|
|
|
// First audio, english.m3u8.
|
2018-05-31 21:27:21 +00:00
|
|
|
std::unique_ptr<MockMediaPlaylist> english_playlist = CreateAudioPlaylist(
|
|
|
|
"eng.m3u8", "english", "audiogroup", "audiocodec", "en", kAudio1Channels,
|
|
|
|
kAudio1MaxBitrate, kAudio1AvgBitrate);
|
2016-03-25 08:39:07 +00:00
|
|
|
|
|
|
|
// Second audio, spanish.m3u8.
|
2018-05-31 21:27:21 +00:00
|
|
|
std::unique_ptr<MockMediaPlaylist> spanish_playlist = CreateAudioPlaylist(
|
|
|
|
"spa.m3u8", "espanol", "audiogroup", "audiocodec", "es", kAudio2Channels,
|
|
|
|
kAudio2MaxBitrate, kAudio2AvgBitrate);
|
2016-03-25 08:39:07 +00:00
|
|
|
|
|
|
|
const char kBaseUrl[] = "http://playlists.org/";
|
2018-02-02 17:14:46 +00:00
|
|
|
EXPECT_TRUE(master_playlist_.WriteMasterPlaylist(
|
|
|
|
kBaseUrl, test_output_dir_,
|
|
|
|
{sd_video_playlist.get(), hd_video_playlist.get(), english_playlist.get(),
|
|
|
|
spanish_playlist.get()}));
|
2016-03-25 08:39:07 +00:00
|
|
|
|
|
|
|
std::string actual;
|
2017-07-10 18:26:22 +00:00
|
|
|
ASSERT_TRUE(File::ReadFileToString(master_playlist_path_.c_str(), &actual));
|
2016-03-25 08:39:07 +00:00
|
|
|
|
|
|
|
const std::string expected =
|
|
|
|
"#EXTM3U\n"
|
2016-07-07 19:34:07 +00:00
|
|
|
"## Generated with https://github.com/google/shaka-packager version "
|
|
|
|
"test\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"\n"
|
2017-12-09 01:53:17 +00:00
|
|
|
"#EXT-X-MEDIA:TYPE=AUDIO,URI=\"http://playlists.org/eng.m3u8\","
|
|
|
|
"GROUP-ID=\"audiogroup\",LANGUAGE=\"en\",NAME=\"english\","
|
2018-01-17 23:43:41 +00:00
|
|
|
"DEFAULT=YES,AUTOSELECT=YES,CHANNELS=\"2\"\n"
|
2017-12-09 01:53:17 +00:00
|
|
|
"#EXT-X-MEDIA:TYPE=AUDIO,URI=\"http://playlists.org/spa.m3u8\","
|
|
|
|
"GROUP-ID=\"audiogroup\",LANGUAGE=\"es\",NAME=\"espanol\","
|
2018-01-17 23:43:41 +00:00
|
|
|
"AUTOSELECT=YES,CHANNELS=\"5\"\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"\n"
|
2018-05-31 21:27:21 +00:00
|
|
|
"#EXT-X-STREAM-INF:BANDWIDTH=360000,AVERAGE-BANDWIDTH=240000,"
|
|
|
|
"CODECS=\"sdvideocodec,audiocodec\","
|
2017-12-09 01:53:17 +00:00
|
|
|
"RESOLUTION=800x600,AUDIO=\"audiogroup\"\n"
|
2016-03-25 08:39:07 +00:00
|
|
|
"http://playlists.org/sd.m3u8\n"
|
2018-05-31 21:27:21 +00:00
|
|
|
"#EXT-X-STREAM-INF:BANDWIDTH=760000,AVERAGE-BANDWIDTH=440000,"
|
|
|
|
"CODECS=\"hdvideocodec,audiocodec\","
|
2017-12-09 01:53:17 +00:00
|
|
|
"RESOLUTION=800x600,AUDIO=\"audiogroup\"\n"
|
2016-03-25 08:39:07 +00:00
|
|
|
"http://playlists.org/hd.m3u8\n";
|
|
|
|
|
|
|
|
ASSERT_EQ(expected, actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(MasterPlaylistTest, WriteMasterPlaylistMultipleAudioGroups) {
|
2018-05-31 21:27:21 +00:00
|
|
|
const uint64_t kVideoMaxBitrate = 300000;
|
|
|
|
const uint64_t kVideoAvgBitrate = 200000;
|
2018-01-26 23:53:58 +00:00
|
|
|
|
2018-05-31 21:27:21 +00:00
|
|
|
const uint64_t kAudio1MaxBitrate = 50000;
|
|
|
|
const uint64_t kAudio1AvgBitrate = 40000;
|
|
|
|
const uint64_t kAudio2MaxBitrate = 100000;
|
|
|
|
const uint64_t kAudio2AvgBitrate = 70000;
|
2018-01-26 23:53:58 +00:00
|
|
|
|
|
|
|
const uint64_t kAudio1Channels = 1;
|
|
|
|
const uint64_t kAudio2Channels = 8;
|
|
|
|
|
|
|
|
// First video, sd.m3u8.
|
2018-05-31 21:27:21 +00:00
|
|
|
std::unique_ptr<MockMediaPlaylist> video_playlist = CreateVideoPlaylist(
|
|
|
|
"video.m3u8", "videocodec", kVideoMaxBitrate, kVideoAvgBitrate);
|
2016-03-25 08:39:07 +00:00
|
|
|
|
|
|
|
// First audio, eng_lo.m3u8.
|
2018-01-26 23:53:58 +00:00
|
|
|
std::unique_ptr<MockMediaPlaylist> eng_lo_playlist = CreateAudioPlaylist(
|
|
|
|
"eng_lo.m3u8", "english_lo", "audio_lo", "audiocodec_lo", "en",
|
2018-05-31 21:27:21 +00:00
|
|
|
kAudio1Channels, kAudio1MaxBitrate, kAudio1AvgBitrate);
|
2016-03-25 08:39:07 +00:00
|
|
|
|
2018-01-17 23:43:41 +00:00
|
|
|
// Second audio, eng_hi.m3u8.
|
2018-01-26 23:53:58 +00:00
|
|
|
std::unique_ptr<MockMediaPlaylist> eng_hi_playlist = CreateAudioPlaylist(
|
|
|
|
"eng_hi.m3u8", "english_hi", "audio_hi", "audiocodec_hi", "en",
|
2018-05-31 21:27:21 +00:00
|
|
|
kAudio2Channels, kAudio2MaxBitrate, kAudio2AvgBitrate);
|
2016-03-25 08:39:07 +00:00
|
|
|
|
|
|
|
const char kBaseUrl[] = "http://anydomain.com/";
|
2018-02-02 17:14:46 +00:00
|
|
|
EXPECT_TRUE(master_playlist_.WriteMasterPlaylist(
|
|
|
|
kBaseUrl, test_output_dir_,
|
|
|
|
{video_playlist.get(), eng_lo_playlist.get(), eng_hi_playlist.get()}));
|
2016-03-25 08:39:07 +00:00
|
|
|
|
|
|
|
std::string actual;
|
2017-07-10 18:26:22 +00:00
|
|
|
ASSERT_TRUE(File::ReadFileToString(master_playlist_path_.c_str(), &actual));
|
2016-03-25 08:39:07 +00:00
|
|
|
|
|
|
|
const std::string expected =
|
|
|
|
"#EXTM3U\n"
|
2016-07-07 19:34:07 +00:00
|
|
|
"## Generated with https://github.com/google/shaka-packager version "
|
|
|
|
"test\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"\n"
|
2017-12-09 01:53:17 +00:00
|
|
|
"#EXT-X-MEDIA:TYPE=AUDIO,URI=\"http://anydomain.com/eng_hi.m3u8\","
|
|
|
|
"GROUP-ID=\"audio_hi\",LANGUAGE=\"en\",NAME=\"english_hi\","
|
2018-01-17 23:43:41 +00:00
|
|
|
"DEFAULT=YES,AUTOSELECT=YES,CHANNELS=\"8\"\n"
|
2017-12-09 01:53:17 +00:00
|
|
|
"#EXT-X-MEDIA:TYPE=AUDIO,URI=\"http://anydomain.com/eng_lo.m3u8\","
|
|
|
|
"GROUP-ID=\"audio_lo\",LANGUAGE=\"en\",NAME=\"english_lo\","
|
2018-01-17 23:43:41 +00:00
|
|
|
"DEFAULT=YES,AUTOSELECT=YES,CHANNELS=\"1\"\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"\n"
|
2018-05-31 21:27:21 +00:00
|
|
|
"#EXT-X-STREAM-INF:BANDWIDTH=400000,AVERAGE-BANDWIDTH=270000,"
|
|
|
|
"CODECS=\"videocodec,audiocodec_hi\","
|
2017-12-09 01:53:17 +00:00
|
|
|
"RESOLUTION=800x600,AUDIO=\"audio_hi\"\n"
|
2016-03-25 08:39:07 +00:00
|
|
|
"http://anydomain.com/video.m3u8\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"\n"
|
2018-05-31 21:27:21 +00:00
|
|
|
"#EXT-X-STREAM-INF:BANDWIDTH=350000,AVERAGE-BANDWIDTH=240000,"
|
|
|
|
"CODECS=\"videocodec,audiocodec_lo\","
|
2017-12-09 01:53:17 +00:00
|
|
|
"RESOLUTION=800x600,AUDIO=\"audio_lo\"\n"
|
2016-03-25 08:39:07 +00:00
|
|
|
"http://anydomain.com/video.m3u8\n";
|
|
|
|
|
|
|
|
ASSERT_EQ(expected, actual);
|
|
|
|
}
|
|
|
|
|
2018-01-17 23:43:41 +00:00
|
|
|
TEST_F(MasterPlaylistTest, WriteMasterPlaylistSameAudioGroupSameLanguage) {
|
|
|
|
// First video, video.m3u8.
|
2018-01-26 23:53:58 +00:00
|
|
|
std::unique_ptr<MockMediaPlaylist> video_playlist =
|
2018-05-31 21:27:21 +00:00
|
|
|
CreateVideoPlaylist("video.m3u8", "videocodec", 300000, 200000);
|
2018-01-17 23:43:41 +00:00
|
|
|
|
|
|
|
// First audio, eng_lo.m3u8.
|
2018-01-26 23:53:58 +00:00
|
|
|
std::unique_ptr<MockMediaPlaylist> eng_lo_playlist = CreateAudioPlaylist(
|
2018-05-31 21:27:21 +00:00
|
|
|
"eng_lo.m3u8", "english", "audio", "audiocodec", "en", 1, 50000, 40000);
|
2018-01-17 23:43:41 +00:00
|
|
|
|
2018-01-26 23:53:58 +00:00
|
|
|
std::unique_ptr<MockMediaPlaylist> eng_hi_playlist = CreateAudioPlaylist(
|
2018-05-31 21:27:21 +00:00
|
|
|
"eng_hi.m3u8", "english", "audio", "audiocodec", "en", 8, 100000, 80000);
|
2018-01-17 23:43:41 +00:00
|
|
|
|
|
|
|
const char kBaseUrl[] = "http://anydomain.com/";
|
2018-02-02 17:14:46 +00:00
|
|
|
EXPECT_TRUE(master_playlist_.WriteMasterPlaylist(
|
|
|
|
kBaseUrl, test_output_dir_,
|
|
|
|
{video_playlist.get(), eng_lo_playlist.get(), eng_hi_playlist.get()}));
|
2018-01-17 23:43:41 +00:00
|
|
|
|
|
|
|
std::string actual;
|
|
|
|
ASSERT_TRUE(File::ReadFileToString(master_playlist_path_.c_str(), &actual));
|
|
|
|
|
|
|
|
const std::string expected =
|
|
|
|
"#EXTM3U\n"
|
|
|
|
"## Generated with https://github.com/google/shaka-packager version "
|
|
|
|
"test\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"\n"
|
2018-01-17 23:43:41 +00:00
|
|
|
"#EXT-X-MEDIA:TYPE=AUDIO,URI=\"http://anydomain.com/eng_lo.m3u8\","
|
|
|
|
"GROUP-ID=\"audio\",LANGUAGE=\"en\",NAME=\"english\","
|
|
|
|
"DEFAULT=YES,AUTOSELECT=YES,CHANNELS=\"1\"\n"
|
|
|
|
"#EXT-X-MEDIA:TYPE=AUDIO,URI=\"http://anydomain.com/eng_hi.m3u8\","
|
2018-02-02 17:52:31 +00:00
|
|
|
"GROUP-ID=\"audio\",LANGUAGE=\"en\",NAME=\"english\",CHANNELS=\"8\"\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"\n"
|
2018-05-31 21:27:21 +00:00
|
|
|
"#EXT-X-STREAM-INF:BANDWIDTH=400000,AVERAGE-BANDWIDTH=280000,"
|
|
|
|
"CODECS=\"videocodec,audiocodec\",RESOLUTION=800x600,AUDIO=\"audio\"\n"
|
2018-01-17 23:43:41 +00:00
|
|
|
"http://anydomain.com/video.m3u8\n";
|
|
|
|
|
|
|
|
ASSERT_EQ(expected, actual);
|
|
|
|
}
|
2018-01-31 19:14:15 +00:00
|
|
|
|
|
|
|
TEST_F(MasterPlaylistTest, WriteMasterPlaylistVideosAndTexts) {
|
|
|
|
// Video, sd.m3u8.
|
|
|
|
std::unique_ptr<MockMediaPlaylist> video1 =
|
2018-05-31 21:27:21 +00:00
|
|
|
CreateVideoPlaylist("sd.m3u8", "sdvideocodec", 300000, 200000);
|
2018-01-31 19:14:15 +00:00
|
|
|
|
|
|
|
// Video, hd.m3u8.
|
|
|
|
std::unique_ptr<MockMediaPlaylist> video2 =
|
2018-05-31 21:27:21 +00:00
|
|
|
CreateVideoPlaylist("hd.m3u8", "sdvideocodec", 600000, 500000);
|
2018-01-31 19:14:15 +00:00
|
|
|
|
|
|
|
// Text, eng.m3u8.
|
|
|
|
std::unique_ptr<MockMediaPlaylist> text_eng =
|
2018-02-26 20:13:28 +00:00
|
|
|
CreateTextPlaylist("eng.m3u8", "english", "textgroup", "textcodec", "en");
|
2018-01-31 19:14:15 +00:00
|
|
|
|
|
|
|
// Text, fr.m3u8.
|
|
|
|
std::unique_ptr<MockMediaPlaylist> text_fr =
|
2018-02-26 20:13:28 +00:00
|
|
|
CreateTextPlaylist("fr.m3u8", "french", "textgroup", "textcodec", "fr");
|
2018-01-31 19:14:15 +00:00
|
|
|
|
|
|
|
const char kBaseUrl[] = "http://playlists.org/";
|
2018-02-02 17:14:46 +00:00
|
|
|
EXPECT_TRUE(master_playlist_.WriteMasterPlaylist(
|
|
|
|
kBaseUrl, test_output_dir_,
|
|
|
|
{video1.get(), video2.get(), text_eng.get(), text_fr.get()}));
|
2018-01-31 19:14:15 +00:00
|
|
|
|
|
|
|
std::string actual;
|
|
|
|
ASSERT_TRUE(File::ReadFileToString(master_playlist_path_.c_str(), &actual));
|
|
|
|
|
|
|
|
const std::string expected =
|
|
|
|
"#EXTM3U\n"
|
|
|
|
"## Generated with https://github.com/google/shaka-packager version "
|
|
|
|
"test\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"\n"
|
2018-01-31 19:14:15 +00:00
|
|
|
"#EXT-X-MEDIA:TYPE=SUBTITLES,URI=\"http://playlists.org/eng.m3u8\","
|
2018-11-20 00:09:24 +00:00
|
|
|
"GROUP-ID=\"textgroup\",LANGUAGE=\"en\",NAME=\"english\","
|
2018-02-02 17:52:31 +00:00
|
|
|
"AUTOSELECT=YES\n"
|
2018-01-31 19:14:15 +00:00
|
|
|
"#EXT-X-MEDIA:TYPE=SUBTITLES,URI=\"http://playlists.org/fr.m3u8\","
|
2018-11-20 00:09:24 +00:00
|
|
|
"GROUP-ID=\"textgroup\",LANGUAGE=\"fr\",NAME=\"french\",DEFAULT=YES,"
|
|
|
|
"AUTOSELECT=YES\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"\n"
|
2018-05-31 21:27:21 +00:00
|
|
|
"#EXT-X-STREAM-INF:BANDWIDTH=300000,AVERAGE-BANDWIDTH=200000,"
|
|
|
|
"CODECS=\"sdvideocodec,textcodec\",RESOLUTION=800x600,"
|
|
|
|
"SUBTITLES=\"textgroup\"\n"
|
2018-01-31 19:14:15 +00:00
|
|
|
"http://playlists.org/sd.m3u8\n"
|
2018-05-31 21:27:21 +00:00
|
|
|
"#EXT-X-STREAM-INF:BANDWIDTH=600000,AVERAGE-BANDWIDTH=500000,"
|
|
|
|
"CODECS=\"sdvideocodec,textcodec\",RESOLUTION=800x600,"
|
|
|
|
"SUBTITLES=\"textgroup\"\n"
|
2018-01-31 19:14:15 +00:00
|
|
|
"http://playlists.org/hd.m3u8\n";
|
|
|
|
|
|
|
|
ASSERT_EQ(expected, actual);
|
|
|
|
}
|
|
|
|
|
2018-10-10 22:30:28 +00:00
|
|
|
TEST_F(MasterPlaylistTest, WriteMasterPlaylistVideoAndTextWithCharacteritics) {
|
|
|
|
// Video, sd.m3u8.
|
|
|
|
std::unique_ptr<MockMediaPlaylist> video =
|
|
|
|
CreateVideoPlaylist("sd.m3u8", "sdvideocodec", 300000, 200000);
|
|
|
|
|
|
|
|
// Text, eng.m3u8.
|
|
|
|
std::unique_ptr<MockMediaPlaylist> text =
|
|
|
|
CreateTextPlaylist("eng.m3u8", "english", "textgroup", "textcodec", "en");
|
|
|
|
text->SetCharacteristicsForTesting(std::vector<std::string>{
|
|
|
|
"public.accessibility.transcribes-spoken-dialog", "public.easy-to-read"});
|
|
|
|
|
|
|
|
const char kBaseUrl[] = "http://playlists.org/";
|
|
|
|
EXPECT_TRUE(master_playlist_.WriteMasterPlaylist(kBaseUrl, test_output_dir_,
|
|
|
|
{video.get(), text.get()}));
|
|
|
|
|
|
|
|
std::string actual;
|
|
|
|
ASSERT_TRUE(File::ReadFileToString(master_playlist_path_.c_str(), &actual));
|
|
|
|
|
|
|
|
const std::string expected =
|
|
|
|
"#EXTM3U\n"
|
|
|
|
"## Generated with https://github.com/google/shaka-packager version "
|
|
|
|
"test\n"
|
|
|
|
"\n"
|
|
|
|
"#EXT-X-MEDIA:TYPE=SUBTITLES,URI=\"http://playlists.org/eng.m3u8\","
|
2018-11-20 00:09:24 +00:00
|
|
|
"GROUP-ID=\"textgroup\",LANGUAGE=\"en\",NAME=\"english\",AUTOSELECT=YES,"
|
|
|
|
"CHARACTERISTICS=\""
|
2018-10-10 22:30:28 +00:00
|
|
|
"public.accessibility.transcribes-spoken-dialog,public.easy-to-read\"\n"
|
|
|
|
"\n"
|
|
|
|
"#EXT-X-STREAM-INF:BANDWIDTH=300000,AVERAGE-BANDWIDTH=200000,"
|
|
|
|
"CODECS=\"sdvideocodec,textcodec\",RESOLUTION=800x600,"
|
|
|
|
"SUBTITLES=\"textgroup\"\n"
|
|
|
|
"http://playlists.org/sd.m3u8\n";
|
|
|
|
|
|
|
|
ASSERT_EQ(expected, actual);
|
|
|
|
}
|
|
|
|
|
2018-01-31 19:14:15 +00:00
|
|
|
TEST_F(MasterPlaylistTest, WriteMasterPlaylistVideoAndTextGroups) {
|
|
|
|
// Video, sd.m3u8.
|
|
|
|
std::unique_ptr<MockMediaPlaylist> video =
|
2018-05-31 21:27:21 +00:00
|
|
|
CreateVideoPlaylist("sd.m3u8", "sdvideocodec", 300000, 200000);
|
2018-01-31 19:14:15 +00:00
|
|
|
|
|
|
|
// Text, eng.m3u8.
|
2018-02-26 20:13:28 +00:00
|
|
|
std::unique_ptr<MockMediaPlaylist> text_eng = CreateTextPlaylist(
|
|
|
|
"eng.m3u8", "english", "en-text-group", "textcodec", "en");
|
2018-01-31 19:14:15 +00:00
|
|
|
|
|
|
|
// Text, fr.m3u8.
|
2018-02-26 20:13:28 +00:00
|
|
|
std::unique_ptr<MockMediaPlaylist> text_fr = CreateTextPlaylist(
|
|
|
|
"fr.m3u8", "french", "fr-text-group", "textcodec", "fr");
|
2018-01-31 19:14:15 +00:00
|
|
|
|
|
|
|
const char kBaseUrl[] = "http://playlists.org/";
|
2018-02-02 17:14:46 +00:00
|
|
|
EXPECT_TRUE(master_playlist_.WriteMasterPlaylist(
|
|
|
|
kBaseUrl, test_output_dir_,
|
|
|
|
{video.get(), text_eng.get(), text_fr.get()}));
|
2018-01-31 19:14:15 +00:00
|
|
|
|
|
|
|
std::string actual;
|
|
|
|
ASSERT_TRUE(File::ReadFileToString(master_playlist_path_.c_str(), &actual));
|
|
|
|
|
|
|
|
const std::string expected =
|
|
|
|
"#EXTM3U\n"
|
|
|
|
"## Generated with https://github.com/google/shaka-packager version "
|
|
|
|
"test\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"\n"
|
2018-01-31 19:14:15 +00:00
|
|
|
"#EXT-X-MEDIA:TYPE=SUBTITLES,URI=\"http://playlists.org/eng.m3u8\","
|
2018-02-05 19:21:28 +00:00
|
|
|
"GROUP-ID=\"en-text-group\",LANGUAGE=\"en\",NAME=\"english\","
|
2018-11-20 00:09:24 +00:00
|
|
|
"AUTOSELECT=YES\n"
|
2018-01-31 19:14:15 +00:00
|
|
|
"#EXT-X-MEDIA:TYPE=SUBTITLES,URI=\"http://playlists.org/fr.m3u8\","
|
2018-02-05 19:21:28 +00:00
|
|
|
"GROUP-ID=\"fr-text-group\",LANGUAGE=\"fr\",NAME=\"french\","
|
2018-11-20 00:09:24 +00:00
|
|
|
"DEFAULT=YES,AUTOSELECT=YES\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"\n"
|
2018-05-31 21:27:21 +00:00
|
|
|
"#EXT-X-STREAM-INF:BANDWIDTH=300000,AVERAGE-BANDWIDTH=200000,"
|
|
|
|
"CODECS=\"sdvideocodec,textcodec\",RESOLUTION=800x600,"
|
|
|
|
"SUBTITLES=\"en-text-group\"\n"
|
2018-01-31 19:14:15 +00:00
|
|
|
"http://playlists.org/sd.m3u8\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"\n"
|
2018-05-31 21:27:21 +00:00
|
|
|
"#EXT-X-STREAM-INF:BANDWIDTH=300000,AVERAGE-BANDWIDTH=200000,"
|
|
|
|
"CODECS=\"sdvideocodec,textcodec\",RESOLUTION=800x600,"
|
|
|
|
"SUBTITLES=\"fr-text-group\"\n"
|
2018-01-31 19:14:15 +00:00
|
|
|
"http://playlists.org/sd.m3u8\n";
|
|
|
|
|
|
|
|
ASSERT_EQ(expected, actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(MasterPlaylistTest, WriteMasterPlaylistVideoAndAudioAndText) {
|
|
|
|
// Video, sd.m3u8.
|
|
|
|
std::unique_ptr<MockMediaPlaylist> video =
|
2018-05-31 21:27:21 +00:00
|
|
|
CreateVideoPlaylist("sd.m3u8", "sdvideocodec", 300000, 200000);
|
2018-01-31 19:14:15 +00:00
|
|
|
|
|
|
|
// Audio, english.m3u8.
|
|
|
|
std::unique_ptr<MockMediaPlaylist> audio = CreateAudioPlaylist(
|
2018-05-31 21:27:21 +00:00
|
|
|
"eng.m3u8", "english", "audiogroup", "audiocodec", "en", 2, 50000, 30000);
|
2018-01-31 19:14:15 +00:00
|
|
|
|
|
|
|
// Text, english.m3u8.
|
|
|
|
std::unique_ptr<MockMediaPlaylist> text =
|
2018-02-26 20:13:28 +00:00
|
|
|
CreateTextPlaylist("eng.m3u8", "english", "textgroup", "textcodec", "en");
|
2018-01-31 19:14:15 +00:00
|
|
|
|
|
|
|
const char kBaseUrl[] = "http://playlists.org/";
|
2018-02-02 17:14:46 +00:00
|
|
|
EXPECT_TRUE(master_playlist_.WriteMasterPlaylist(
|
|
|
|
kBaseUrl, test_output_dir_, {video.get(), audio.get(), text.get()}));
|
2018-01-31 19:14:15 +00:00
|
|
|
|
|
|
|
std::string actual;
|
|
|
|
ASSERT_TRUE(File::ReadFileToString(master_playlist_path_.c_str(), &actual));
|
|
|
|
|
|
|
|
const std::string expected =
|
|
|
|
"#EXTM3U\n"
|
|
|
|
"## Generated with https://github.com/google/shaka-packager version "
|
|
|
|
"test\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"\n"
|
2018-01-31 19:14:15 +00:00
|
|
|
"#EXT-X-MEDIA:TYPE=AUDIO,URI=\"http://playlists.org/eng.m3u8\","
|
|
|
|
"GROUP-ID=\"audiogroup\",LANGUAGE=\"en\",NAME=\"english\","
|
|
|
|
"DEFAULT=YES,AUTOSELECT=YES,CHANNELS=\"2\"\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"\n"
|
2018-01-31 19:14:15 +00:00
|
|
|
"#EXT-X-MEDIA:TYPE=SUBTITLES,URI=\"http://playlists.org/eng.m3u8\","
|
2018-11-20 00:09:24 +00:00
|
|
|
"GROUP-ID=\"textgroup\",LANGUAGE=\"en\",NAME=\"english\","
|
2018-02-02 17:52:31 +00:00
|
|
|
"AUTOSELECT=YES\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"\n"
|
2018-05-31 21:27:21 +00:00
|
|
|
"#EXT-X-STREAM-INF:BANDWIDTH=350000,AVERAGE-BANDWIDTH=230000,"
|
|
|
|
"CODECS=\"sdvideocodec,audiocodec,textcodec\",RESOLUTION=800x600,"
|
|
|
|
"AUDIO=\"audiogroup\",SUBTITLES=\"textgroup\"\n"
|
2018-01-31 19:14:15 +00:00
|
|
|
"http://playlists.org/sd.m3u8\n";
|
|
|
|
|
|
|
|
ASSERT_EQ(expected, actual);
|
|
|
|
}
|
|
|
|
|
2018-02-02 22:45:52 +00:00
|
|
|
TEST_F(MasterPlaylistTest, WriteMasterPlaylistMixedPlaylistsDifferentGroups) {
|
2018-01-31 19:14:15 +00:00
|
|
|
const uint64_t kAudioChannels = 2;
|
2018-05-31 21:27:21 +00:00
|
|
|
const uint64_t kAudioMaxBitrate = 50000;
|
|
|
|
const uint64_t kAudioAvgBitrate = 30000;
|
|
|
|
const uint64_t kVideoMaxBitrate = 300000;
|
|
|
|
const uint64_t kVideoAvgBitrate = 100000;
|
|
|
|
const uint64_t kIframeMaxBitrate = 100000;
|
|
|
|
const uint64_t kIframeAvgBitrate = 80000;
|
2018-01-31 19:14:15 +00:00
|
|
|
|
|
|
|
std::unique_ptr<MockMediaPlaylist> media_playlists[] = {
|
|
|
|
// AUDIO
|
|
|
|
CreateAudioPlaylist("audio-1.m3u8", "audio 1", "audio-group-1",
|
2018-05-31 21:27:21 +00:00
|
|
|
"audiocodec", "en", kAudioChannels, kAudioMaxBitrate,
|
|
|
|
kAudioAvgBitrate),
|
2018-01-31 19:14:15 +00:00
|
|
|
CreateAudioPlaylist("audio-2.m3u8", "audio 2", "audio-group-2",
|
2018-11-20 00:09:24 +00:00
|
|
|
"audiocodec", "fr", kAudioChannels, kAudioMaxBitrate,
|
2018-05-31 21:27:21 +00:00
|
|
|
kAudioAvgBitrate),
|
2018-01-31 19:14:15 +00:00
|
|
|
|
|
|
|
// SUBTITLES
|
2018-02-26 20:13:28 +00:00
|
|
|
CreateTextPlaylist("text-1.m3u8", "text 1", "text-group-1", "textcodec",
|
|
|
|
"en"),
|
|
|
|
CreateTextPlaylist("text-2.m3u8", "text 2", "text-group-2", "textcodec",
|
2018-11-20 00:09:24 +00:00
|
|
|
"fr"),
|
2018-01-31 19:14:15 +00:00
|
|
|
|
|
|
|
// VIDEO
|
2018-05-31 21:27:21 +00:00
|
|
|
CreateVideoPlaylist("video-1.m3u8", "sdvideocodec", kVideoMaxBitrate,
|
|
|
|
kVideoAvgBitrate),
|
|
|
|
CreateVideoPlaylist("video-2.m3u8", "sdvideocodec", kVideoMaxBitrate,
|
|
|
|
kVideoAvgBitrate),
|
2018-02-02 22:45:52 +00:00
|
|
|
|
|
|
|
// I-Frame
|
2018-05-31 21:27:21 +00:00
|
|
|
CreateIframePlaylist("iframe-1.m3u8", "sdvideocodec", kIframeMaxBitrate,
|
|
|
|
kIframeAvgBitrate),
|
|
|
|
CreateIframePlaylist("iframe-2.m3u8", "sdvideocodec", kIframeMaxBitrate,
|
|
|
|
kIframeAvgBitrate),
|
2018-01-31 19:14:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Add all the media playlists to the master playlist.
|
2018-02-02 17:14:46 +00:00
|
|
|
std::list<MediaPlaylist*> media_playlist_list;
|
2018-01-31 19:14:15 +00:00
|
|
|
for (const auto& media_playlist : media_playlists) {
|
2018-02-02 17:14:46 +00:00
|
|
|
media_playlist_list.push_back(media_playlist.get());
|
2018-01-31 19:14:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char kBaseUrl[] = "http://playlists.org/";
|
2018-02-02 17:14:46 +00:00
|
|
|
EXPECT_TRUE(master_playlist_.WriteMasterPlaylist(kBaseUrl, test_output_dir_,
|
|
|
|
media_playlist_list));
|
2018-01-31 19:14:15 +00:00
|
|
|
|
|
|
|
std::string actual;
|
|
|
|
ASSERT_TRUE(File::ReadFileToString(master_playlist_path_.c_str(), &actual));
|
|
|
|
|
|
|
|
const std::string expected =
|
|
|
|
"#EXTM3U\n"
|
|
|
|
"## Generated with https://github.com/google/shaka-packager version "
|
|
|
|
"test\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"\n"
|
2018-01-31 19:14:15 +00:00
|
|
|
"#EXT-X-MEDIA:TYPE=AUDIO,URI=\"http://playlists.org/audio-1.m3u8\","
|
|
|
|
"GROUP-ID=\"audio-group-1\",LANGUAGE=\"en\",NAME=\"audio 1\","
|
|
|
|
"DEFAULT=YES,AUTOSELECT=YES,CHANNELS=\"2\"\n"
|
|
|
|
"#EXT-X-MEDIA:TYPE=AUDIO,URI=\"http://playlists.org/audio-2.m3u8\","
|
2018-11-20 00:09:24 +00:00
|
|
|
"GROUP-ID=\"audio-group-2\",LANGUAGE=\"fr\",NAME=\"audio 2\","
|
|
|
|
"AUTOSELECT=YES,CHANNELS=\"2\"\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"\n"
|
2018-01-31 19:14:15 +00:00
|
|
|
"#EXT-X-MEDIA:TYPE=SUBTITLES,URI=\"http://playlists.org/text-1.m3u8\","
|
2018-02-05 19:21:28 +00:00
|
|
|
"GROUP-ID=\"text-group-1\",LANGUAGE=\"en\",NAME=\"text 1\","
|
2018-11-20 00:09:24 +00:00
|
|
|
"AUTOSELECT=YES\n"
|
2018-01-31 19:14:15 +00:00
|
|
|
"#EXT-X-MEDIA:TYPE=SUBTITLES,URI=\"http://playlists.org/text-2.m3u8\","
|
2018-11-20 00:09:24 +00:00
|
|
|
"GROUP-ID=\"text-group-2\",LANGUAGE=\"fr\",NAME=\"text 2\","
|
2018-02-05 19:21:28 +00:00
|
|
|
"DEFAULT=YES,AUTOSELECT=YES\n"
|
|
|
|
"\n"
|
2018-05-31 21:27:21 +00:00
|
|
|
"#EXT-X-STREAM-INF:BANDWIDTH=350000,AVERAGE-BANDWIDTH=130000,"
|
|
|
|
"CODECS=\"sdvideocodec,audiocodec,textcodec\",RESOLUTION=800x600,"
|
|
|
|
"AUDIO=\"audio-group-1\",SUBTITLES=\"text-group-1\"\n"
|
2018-01-31 19:14:15 +00:00
|
|
|
"http://playlists.org/video-1.m3u8\n"
|
2018-05-31 21:27:21 +00:00
|
|
|
"#EXT-X-STREAM-INF:BANDWIDTH=350000,AVERAGE-BANDWIDTH=130000,"
|
|
|
|
"CODECS=\"sdvideocodec,audiocodec,textcodec\",RESOLUTION=800x600,"
|
|
|
|
"AUDIO=\"audio-group-1\",SUBTITLES=\"text-group-1\"\n"
|
2018-01-31 19:14:15 +00:00
|
|
|
"http://playlists.org/video-2.m3u8\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"\n"
|
2018-05-31 21:27:21 +00:00
|
|
|
"#EXT-X-STREAM-INF:BANDWIDTH=350000,AVERAGE-BANDWIDTH=130000,"
|
|
|
|
"CODECS=\"sdvideocodec,audiocodec,textcodec\",RESOLUTION=800x600,"
|
|
|
|
"AUDIO=\"audio-group-1\",SUBTITLES=\"text-group-2\"\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"http://playlists.org/video-1.m3u8\n"
|
2018-05-31 21:27:21 +00:00
|
|
|
"#EXT-X-STREAM-INF:BANDWIDTH=350000,AVERAGE-BANDWIDTH=130000,"
|
|
|
|
"CODECS=\"sdvideocodec,audiocodec,textcodec\",RESOLUTION=800x600,"
|
|
|
|
"AUDIO=\"audio-group-1\",SUBTITLES=\"text-group-2\"\n"
|
2018-01-31 19:14:15 +00:00
|
|
|
"http://playlists.org/video-2.m3u8\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"\n"
|
2018-05-31 21:27:21 +00:00
|
|
|
"#EXT-X-STREAM-INF:BANDWIDTH=350000,AVERAGE-BANDWIDTH=130000,"
|
|
|
|
"CODECS=\"sdvideocodec,audiocodec,textcodec\",RESOLUTION=800x600,"
|
|
|
|
"AUDIO=\"audio-group-2\",SUBTITLES=\"text-group-1\"\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"http://playlists.org/video-1.m3u8\n"
|
2018-05-31 21:27:21 +00:00
|
|
|
"#EXT-X-STREAM-INF:BANDWIDTH=350000,AVERAGE-BANDWIDTH=130000,"
|
|
|
|
"CODECS=\"sdvideocodec,audiocodec,textcodec\",RESOLUTION=800x600,"
|
|
|
|
"AUDIO=\"audio-group-2\",SUBTITLES=\"text-group-1\"\n"
|
2018-01-31 19:14:15 +00:00
|
|
|
"http://playlists.org/video-2.m3u8\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"\n"
|
2018-05-31 21:27:21 +00:00
|
|
|
"#EXT-X-STREAM-INF:BANDWIDTH=350000,AVERAGE-BANDWIDTH=130000,"
|
|
|
|
"CODECS=\"sdvideocodec,audiocodec,textcodec\",RESOLUTION=800x600,"
|
|
|
|
"AUDIO=\"audio-group-2\",SUBTITLES=\"text-group-2\"\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"http://playlists.org/video-1.m3u8\n"
|
2018-05-31 21:27:21 +00:00
|
|
|
"#EXT-X-STREAM-INF:BANDWIDTH=350000,AVERAGE-BANDWIDTH=130000,"
|
|
|
|
"CODECS=\"sdvideocodec,audiocodec,textcodec\",RESOLUTION=800x600,"
|
|
|
|
"AUDIO=\"audio-group-2\",SUBTITLES=\"text-group-2\"\n"
|
2018-02-02 22:45:52 +00:00
|
|
|
"http://playlists.org/video-2.m3u8\n"
|
2018-02-05 19:21:28 +00:00
|
|
|
"\n"
|
2018-05-31 21:27:21 +00:00
|
|
|
"#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=100000,AVERAGE-BANDWIDTH=80000,"
|
|
|
|
"CODECS=\"sdvideocodec\",RESOLUTION=800x600,"
|
|
|
|
"URI=\"http://playlists.org/iframe-1.m3u8\"\n"
|
|
|
|
"#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=100000,AVERAGE-BANDWIDTH=80000,"
|
|
|
|
"CODECS=\"sdvideocodec\",RESOLUTION=800x600,"
|
|
|
|
"URI=\"http://playlists.org/iframe-2.m3u8\"\n";
|
2018-01-31 19:14:15 +00:00
|
|
|
|
|
|
|
ASSERT_EQ(expected, actual);
|
|
|
|
}
|
2018-11-28 00:10:07 +00:00
|
|
|
|
|
|
|
TEST_F(MasterPlaylistTest, WriteMasterPlaylistAudioOnly) {
|
|
|
|
const uint64_t kAudioChannels = 2;
|
|
|
|
const uint64_t kAudioMaxBitrate = 50000;
|
|
|
|
const uint64_t kAudioAvgBitrate = 30000;
|
|
|
|
|
|
|
|
std::unique_ptr<MockMediaPlaylist> media_playlists[] = {
|
|
|
|
// AUDIO
|
|
|
|
CreateAudioPlaylist("audio-1.m3u8", "audio 1", "audio-group-1",
|
|
|
|
"audiocodec", "en", kAudioChannels, kAudioMaxBitrate,
|
|
|
|
kAudioAvgBitrate),
|
|
|
|
CreateAudioPlaylist("audio-2.m3u8", "audio 2", "audio-group-2",
|
|
|
|
"audiocodec", "fr", kAudioChannels, kAudioMaxBitrate,
|
|
|
|
kAudioAvgBitrate),
|
|
|
|
};
|
|
|
|
|
|
|
|
// Add all the media playlists to the master playlist.
|
|
|
|
std::list<MediaPlaylist*> media_playlist_list;
|
|
|
|
for (const auto& media_playlist : media_playlists) {
|
|
|
|
media_playlist_list.push_back(media_playlist.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
const char kBaseUrl[] = "http://playlists.org/";
|
|
|
|
EXPECT_TRUE(master_playlist_.WriteMasterPlaylist(kBaseUrl, test_output_dir_,
|
|
|
|
media_playlist_list));
|
|
|
|
|
|
|
|
std::string actual;
|
|
|
|
ASSERT_TRUE(File::ReadFileToString(master_playlist_path_.c_str(), &actual));
|
|
|
|
|
|
|
|
const std::string expected =
|
|
|
|
"#EXTM3U\n"
|
|
|
|
"## Generated with https://github.com/google/shaka-packager version "
|
|
|
|
"test\n"
|
|
|
|
"\n"
|
|
|
|
"#EXT-X-MEDIA:TYPE=AUDIO,URI=\"http://playlists.org/audio-1.m3u8\","
|
|
|
|
"GROUP-ID=\"audio-group-1\",LANGUAGE=\"en\",NAME=\"audio 1\","
|
|
|
|
"DEFAULT=YES,AUTOSELECT=YES,CHANNELS=\"2\"\n"
|
|
|
|
"#EXT-X-MEDIA:TYPE=AUDIO,URI=\"http://playlists.org/audio-2.m3u8\","
|
|
|
|
"GROUP-ID=\"audio-group-2\",LANGUAGE=\"fr\",NAME=\"audio 2\","
|
|
|
|
"AUTOSELECT=YES,CHANNELS=\"2\"\n"
|
|
|
|
"\n"
|
|
|
|
"#EXT-X-STREAM-INF:BANDWIDTH=50000,AVERAGE-BANDWIDTH=30000,"
|
|
|
|
"CODECS=\"audiocodec\",AUDIO=\"audio-group-1\"\n"
|
|
|
|
"http://playlists.org/audio-1.m3u8\n"
|
|
|
|
"#EXT-X-STREAM-INF:BANDWIDTH=50000,AVERAGE-BANDWIDTH=30000,"
|
|
|
|
"CODECS=\"audiocodec\",AUDIO=\"audio-group-2\"\n"
|
|
|
|
"http://playlists.org/audio-2.m3u8\n";
|
|
|
|
|
|
|
|
ASSERT_EQ(expected, actual);
|
|
|
|
}
|
|
|
|
|
2016-03-25 08:39:07 +00:00
|
|
|
} // namespace hls
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|