2023-12-01 17:32:19 +00:00
|
|
|
// Copyright 2017 Google LLC. All rights reserved.
|
2017-12-14 21:30:16 +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/mpd/base/representation.h>
|
2017-12-14 21:30:16 +00:00
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
#include <cinttypes>
|
|
|
|
|
|
|
|
#include <absl/flags/declare.h>
|
|
|
|
#include <absl/flags/flag.h>
|
|
|
|
#include <absl/log/check.h>
|
|
|
|
#include <absl/strings/str_format.h>
|
2017-12-14 21:30:16 +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/flag_saver.h>
|
|
|
|
#include <packager/mpd/base/mpd_options.h>
|
|
|
|
#include <packager/mpd/test/mpd_builder_test_helper.h>
|
|
|
|
#include <packager/mpd/test/xml_compare.h>
|
2017-12-14 21:30:16 +00:00
|
|
|
|
2017-09-25 19:18:50 +00:00
|
|
|
using ::testing::Bool;
|
2017-12-14 21:30:16 +00:00
|
|
|
using ::testing::Not;
|
2017-09-25 19:18:50 +00:00
|
|
|
using ::testing::Values;
|
|
|
|
using ::testing::WithParamInterface;
|
2017-12-14 21:30:16 +00:00
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
ABSL_DECLARE_FLAG(bool, use_legacy_vp9_codec_string);
|
2018-06-06 01:31:21 +00:00
|
|
|
|
2017-12-14 21:30:16 +00:00
|
|
|
namespace shaka {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
const uint32_t kAnyRepresentationId = 1;
|
|
|
|
|
|
|
|
class MockRepresentationStateChangeListener
|
|
|
|
: public RepresentationStateChangeListener {
|
|
|
|
public:
|
|
|
|
MockRepresentationStateChangeListener() {}
|
|
|
|
~MockRepresentationStateChangeListener() {}
|
|
|
|
|
|
|
|
MOCK_METHOD2(OnNewSegmentForRepresentation,
|
2018-06-22 01:14:34 +00:00
|
|
|
void(int64_t start_time, int64_t duration));
|
2017-12-14 21:30:16 +00:00
|
|
|
|
|
|
|
MOCK_METHOD2(OnSetFrameRateForRepresentation,
|
2021-08-04 18:56:44 +00:00
|
|
|
void(int32_t frame_duration, int32_t timescale));
|
2017-12-14 21:30:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
class RepresentationTest : public ::testing::Test {
|
|
|
|
public:
|
|
|
|
// TODO(rkuroiwa): Once std::forward() is allowed by chromium style guide, use
|
|
|
|
// variadic template and std::forward() so that we don't need to copy the
|
|
|
|
// constructor signatures.
|
|
|
|
std::unique_ptr<Representation> CreateRepresentation(
|
|
|
|
const MediaInfo& media_info,
|
|
|
|
uint32_t representation_id,
|
|
|
|
std::unique_ptr<RepresentationStateChangeListener>
|
|
|
|
state_change_listener) {
|
|
|
|
return std::unique_ptr<Representation>(
|
|
|
|
new Representation(media_info, mpd_options_, representation_id,
|
|
|
|
std::move(state_change_listener)));
|
|
|
|
}
|
|
|
|
|
2018-01-03 00:10:54 +00:00
|
|
|
std::unique_ptr<Representation> CopyRepresentation(
|
|
|
|
const Representation& representation,
|
|
|
|
std::unique_ptr<RepresentationStateChangeListener>
|
|
|
|
state_change_listener) {
|
|
|
|
return std::unique_ptr<Representation>(
|
2018-01-29 18:37:50 +00:00
|
|
|
new Representation(representation, std::move(state_change_listener)));
|
2018-01-03 00:10:54 +00:00
|
|
|
}
|
|
|
|
|
2017-12-14 21:30:16 +00:00
|
|
|
std::unique_ptr<RepresentationStateChangeListener> NoListener() {
|
|
|
|
return std::unique_ptr<RepresentationStateChangeListener>();
|
|
|
|
}
|
|
|
|
|
2017-12-14 21:58:53 +00:00
|
|
|
protected:
|
2017-12-14 21:30:16 +00:00
|
|
|
MpdOptions mpd_options_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Verify that Representation::Init() works with all "required" fields of
|
|
|
|
// MedieInfo proto.
|
|
|
|
TEST_F(RepresentationTest, ValidMediaInfo) {
|
|
|
|
const char kTestMediaInfo[] =
|
|
|
|
"video_info {\n"
|
|
|
|
" codec: 'avc1'\n"
|
|
|
|
" width: 720\n"
|
|
|
|
" height: 480\n"
|
|
|
|
" time_scale: 10\n"
|
|
|
|
" frame_duration: 10\n"
|
|
|
|
" pixel_width: 1\n"
|
|
|
|
" pixel_height: 1\n"
|
|
|
|
"}\n"
|
|
|
|
"container_type: 1\n";
|
|
|
|
|
|
|
|
auto representation = CreateRepresentation(
|
|
|
|
ConvertToMediaInfo(kTestMediaInfo), kAnyRepresentationId, NoListener());
|
|
|
|
EXPECT_TRUE(representation->Init());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that if VideoInfo, AudioInfo, or TextInfo is not set, Init() fails.
|
|
|
|
TEST_F(RepresentationTest, VideoAudioTextInfoNotSet) {
|
|
|
|
const char kTestMediaInfo[] = "container_type: 1";
|
|
|
|
|
|
|
|
auto representation = CreateRepresentation(
|
|
|
|
ConvertToMediaInfo(kTestMediaInfo), kAnyRepresentationId, NoListener());
|
|
|
|
EXPECT_FALSE(representation->Init());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that if more than one of VideoInfo, AudioInfo, or TextInfo is set,
|
|
|
|
// then Init() fails.
|
|
|
|
TEST_F(RepresentationTest, VideoAndAudioInfoSet) {
|
|
|
|
const char kTestMediaInfo[] =
|
|
|
|
"video_info {\n"
|
|
|
|
" codec: 'avc1'\n"
|
|
|
|
" height: 480\n"
|
|
|
|
" time_scale: 10\n"
|
|
|
|
" frame_duration: 10\n"
|
|
|
|
" pixel_width: 1\n"
|
|
|
|
" pixel_height: 1\n"
|
|
|
|
"}\n"
|
|
|
|
"audio_info {\n"
|
|
|
|
" codec: 'mp4a.40.2'\n"
|
|
|
|
" sampling_frequency: 44100\n"
|
|
|
|
" time_scale: 1200\n"
|
|
|
|
" num_channels: 2\n"
|
|
|
|
"}\n"
|
|
|
|
"container_type: CONTAINER_MP4\n";
|
|
|
|
|
|
|
|
auto representation = CreateRepresentation(
|
|
|
|
ConvertToMediaInfo(kTestMediaInfo), kAnyRepresentationId, NoListener());
|
|
|
|
EXPECT_FALSE(representation->Init());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that Representation::Init() fails if a required field is missing.
|
|
|
|
TEST_F(RepresentationTest, InvalidMediaInfo) {
|
|
|
|
// Missing width.
|
|
|
|
const char kTestMediaInfo[] =
|
|
|
|
"video_info {\n"
|
|
|
|
" codec: 'avc1'\n"
|
|
|
|
" height: 480\n"
|
|
|
|
" time_scale: 10\n"
|
|
|
|
" frame_duration: 10\n"
|
|
|
|
" pixel_width: 1\n"
|
|
|
|
" pixel_height: 1\n"
|
|
|
|
"}\n"
|
|
|
|
"container_type: 1\n";
|
|
|
|
auto representation = CreateRepresentation(
|
|
|
|
ConvertToMediaInfo(kTestMediaInfo), kAnyRepresentationId, NoListener());
|
|
|
|
EXPECT_FALSE(representation->Init());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Basic check that the fields in video info are in the XML.
|
|
|
|
TEST_F(RepresentationTest, CheckVideoInfoReflectedInXml) {
|
|
|
|
const char kTestMediaInfo[] =
|
|
|
|
"video_info {\n"
|
|
|
|
" codec: 'avc1'\n"
|
|
|
|
" width: 1280\n"
|
|
|
|
" height: 720\n"
|
|
|
|
" time_scale: 10\n"
|
|
|
|
" frame_duration: 10\n"
|
|
|
|
" pixel_width: 1\n"
|
|
|
|
" pixel_height: 1\n"
|
|
|
|
"}\n"
|
|
|
|
"container_type: 1\n";
|
|
|
|
auto representation = CreateRepresentation(
|
|
|
|
ConvertToMediaInfo(kTestMediaInfo), kAnyRepresentationId, NoListener());
|
|
|
|
ASSERT_TRUE(representation->Init());
|
|
|
|
const char kExpectedOutput[] =
|
|
|
|
"<Representation id=\"1\" bandwidth=\"0\" "
|
|
|
|
" codecs=\"avc1\" mimeType=\"video/mp4\" "
|
|
|
|
" sar=\"1:1\" width=\"1280\" height=\"720\" "
|
|
|
|
" frameRate=\"10/10\"/>";
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation->GetXml(), XmlNodeEqual(kExpectedOutput));
|
2017-12-14 21:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(RepresentationTest, CheckVideoInfoVp8CodecInMp4) {
|
|
|
|
const char kTestMediaInfoCodecVp8[] =
|
|
|
|
"video_info {\n"
|
|
|
|
" codec: 'vp08.00.00.08.01.01.00.00'\n"
|
|
|
|
" width: 1280\n"
|
|
|
|
" height: 720\n"
|
|
|
|
" time_scale: 10\n"
|
|
|
|
" frame_duration: 10\n"
|
|
|
|
" pixel_width: 1\n"
|
|
|
|
" pixel_height: 1\n"
|
|
|
|
"}\n"
|
|
|
|
"container_type: 1\n";
|
|
|
|
auto representation =
|
|
|
|
CreateRepresentation(ConvertToMediaInfo(kTestMediaInfoCodecVp8),
|
|
|
|
kAnyRepresentationId, NoListener());
|
|
|
|
ASSERT_TRUE(representation->Init());
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation->GetXml(),
|
2017-12-14 21:30:16 +00:00
|
|
|
AttributeEqual("codecs", "vp08.00.00.08.01.01.00.00"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that vp8 codec string will be updated for backward compatibility
|
|
|
|
// support in webm.
|
|
|
|
TEST_F(RepresentationTest, CheckVideoInfoVp8CodecInWebm) {
|
|
|
|
const char kTestMediaInfoCodecVp8[] =
|
|
|
|
"video_info {\n"
|
|
|
|
" codec: 'vp08.00.00.08.01.01.00.00'\n"
|
|
|
|
" width: 1280\n"
|
|
|
|
" height: 720\n"
|
|
|
|
" time_scale: 10\n"
|
|
|
|
" frame_duration: 10\n"
|
|
|
|
" pixel_width: 1\n"
|
|
|
|
" pixel_height: 1\n"
|
|
|
|
"}\n"
|
|
|
|
"container_type: 3\n";
|
|
|
|
auto representation =
|
|
|
|
CreateRepresentation(ConvertToMediaInfo(kTestMediaInfoCodecVp8),
|
|
|
|
kAnyRepresentationId, NoListener());
|
|
|
|
ASSERT_TRUE(representation->Init());
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation->GetXml(), AttributeEqual("codecs", "vp8"));
|
2017-12-14 21:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(RepresentationTest, CheckVideoInfoVp9CodecInWebm) {
|
2018-06-06 01:31:21 +00:00
|
|
|
const char kTestMediaInfoCodecVp9[] =
|
|
|
|
"video_info {\n"
|
|
|
|
" codec: 'vp09.00.00.08.01.01.00.00'\n"
|
|
|
|
" width: 1280\n"
|
|
|
|
" height: 720\n"
|
|
|
|
" time_scale: 10\n"
|
|
|
|
" frame_duration: 10\n"
|
|
|
|
" pixel_width: 1\n"
|
|
|
|
" pixel_height: 1\n"
|
|
|
|
"}\n"
|
|
|
|
"container_type: 3\n";
|
|
|
|
auto representation =
|
|
|
|
CreateRepresentation(ConvertToMediaInfo(kTestMediaInfoCodecVp9),
|
|
|
|
kAnyRepresentationId, NoListener());
|
|
|
|
ASSERT_TRUE(representation->Init());
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation->GetXml(),
|
2018-06-06 01:31:21 +00:00
|
|
|
AttributeEqual("codecs", "vp09.00.00.08.01.01.00.00"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(RepresentationTest, CheckVideoInfoLegacyVp9CodecInWebm) {
|
2023-12-01 17:32:19 +00:00
|
|
|
FlagSaver<bool> saver(&FLAGS_use_legacy_vp9_codec_string);
|
|
|
|
absl::SetFlag(&FLAGS_use_legacy_vp9_codec_string, true);
|
2018-06-06 01:31:21 +00:00
|
|
|
|
2017-12-14 21:30:16 +00:00
|
|
|
const char kTestMediaInfoCodecVp9[] =
|
|
|
|
"video_info {\n"
|
|
|
|
" codec: 'vp09.00.00.08.01.01.00.00'\n"
|
|
|
|
" width: 1280\n"
|
|
|
|
" height: 720\n"
|
|
|
|
" time_scale: 10\n"
|
|
|
|
" frame_duration: 10\n"
|
|
|
|
" pixel_width: 1\n"
|
|
|
|
" pixel_height: 1\n"
|
|
|
|
"}\n"
|
|
|
|
"container_type: 3\n";
|
|
|
|
auto representation =
|
|
|
|
CreateRepresentation(ConvertToMediaInfo(kTestMediaInfoCodecVp9),
|
|
|
|
kAnyRepresentationId, NoListener());
|
|
|
|
ASSERT_TRUE(representation->Init());
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation->GetXml(), AttributeEqual("codecs", "vp9"));
|
2017-12-14 21:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure RepresentationStateChangeListener::OnNewSegmentForRepresentation()
|
|
|
|
// is called.
|
|
|
|
TEST_F(RepresentationTest,
|
|
|
|
RepresentationStateChangeListenerOnNewSegmentForRepresentation) {
|
|
|
|
const char kTestMediaInfo[] =
|
|
|
|
"video_info {\n"
|
|
|
|
" codec: 'avc1'\n"
|
|
|
|
" width: 720\n"
|
|
|
|
" height: 480\n"
|
|
|
|
" time_scale: 10\n"
|
|
|
|
" frame_duration: 10\n"
|
|
|
|
" pixel_width: 1\n"
|
|
|
|
" pixel_height: 1\n"
|
|
|
|
"}\n"
|
|
|
|
"container_type: 1\n";
|
|
|
|
|
2021-08-04 18:56:44 +00:00
|
|
|
const int64_t kStartTime = 199238;
|
|
|
|
const int64_t kDuration = 98;
|
2024-05-02 20:25:49 +00:00
|
|
|
const int64_t kSegmentNumber = 1;
|
|
|
|
|
2017-12-14 21:30:16 +00:00
|
|
|
std::unique_ptr<MockRepresentationStateChangeListener> listener(
|
|
|
|
new MockRepresentationStateChangeListener());
|
|
|
|
EXPECT_CALL(*listener, OnNewSegmentForRepresentation(kStartTime, kDuration));
|
|
|
|
auto representation =
|
|
|
|
CreateRepresentation(ConvertToMediaInfo(kTestMediaInfo),
|
|
|
|
kAnyRepresentationId, std::move(listener));
|
|
|
|
EXPECT_TRUE(representation->Init());
|
|
|
|
|
2024-05-02 20:25:49 +00:00
|
|
|
representation->AddNewSegment(kStartTime, kDuration, 10 /* any size */,
|
|
|
|
kSegmentNumber);
|
2017-12-14 21:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure
|
|
|
|
// RepresentationStateChangeListener::OnSetFrameRateForRepresentation()
|
|
|
|
// is called.
|
|
|
|
TEST_F(RepresentationTest,
|
|
|
|
RepresentationStateChangeListenerOnSetFrameRateForRepresentation) {
|
|
|
|
const char kTestMediaInfo[] =
|
|
|
|
"video_info {\n"
|
|
|
|
" codec: 'avc1'\n"
|
|
|
|
" width: 720\n"
|
|
|
|
" height: 480\n"
|
|
|
|
" time_scale: 1000\n"
|
|
|
|
" frame_duration: 10\n"
|
|
|
|
" pixel_width: 1\n"
|
|
|
|
" pixel_height: 1\n"
|
|
|
|
"}\n"
|
|
|
|
"container_type: 1\n";
|
|
|
|
|
2021-08-04 18:56:44 +00:00
|
|
|
const int32_t kTimeScale = 1000;
|
|
|
|
const int64_t kFrameDuration = 33;
|
2017-12-14 21:30:16 +00:00
|
|
|
std::unique_ptr<MockRepresentationStateChangeListener> listener(
|
|
|
|
new MockRepresentationStateChangeListener());
|
|
|
|
EXPECT_CALL(*listener,
|
|
|
|
OnSetFrameRateForRepresentation(kFrameDuration, kTimeScale));
|
|
|
|
auto representation =
|
|
|
|
CreateRepresentation(ConvertToMediaInfo(kTestMediaInfo),
|
|
|
|
kAnyRepresentationId, std::move(listener));
|
|
|
|
EXPECT_TRUE(representation->Init());
|
|
|
|
|
|
|
|
representation->SetSampleDuration(kFrameDuration);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(RepresentationTest, TtmlXmlMimeType) {
|
|
|
|
const char kTtmlXmlMediaInfo[] =
|
|
|
|
"text_info {\n"
|
2018-02-26 20:13:28 +00:00
|
|
|
" codec: 'ttml'\n"
|
2017-12-14 21:30:16 +00:00
|
|
|
"}\n"
|
|
|
|
"container_type: CONTAINER_TEXT\n";
|
|
|
|
|
|
|
|
auto representation =
|
|
|
|
CreateRepresentation(ConvertToMediaInfo(kTtmlXmlMediaInfo),
|
|
|
|
kAnyRepresentationId, NoListener());
|
|
|
|
ASSERT_TRUE(representation->Init());
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation->GetXml(),
|
2017-12-14 21:30:16 +00:00
|
|
|
AttributeEqual("mimeType", "application/ttml+xml"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(RepresentationTest, TtmlMp4MimeType) {
|
|
|
|
const char kTtmlMp4MediaInfo[] =
|
|
|
|
"text_info {\n"
|
2018-02-26 20:13:28 +00:00
|
|
|
" codec: 'ttml'\n"
|
2017-12-14 21:30:16 +00:00
|
|
|
"}\n"
|
|
|
|
"container_type: CONTAINER_MP4\n";
|
|
|
|
|
|
|
|
auto representation =
|
|
|
|
CreateRepresentation(ConvertToMediaInfo(kTtmlMp4MediaInfo),
|
|
|
|
kAnyRepresentationId, NoListener());
|
|
|
|
ASSERT_TRUE(representation->Init());
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation->GetXml(),
|
2017-12-14 21:30:16 +00:00
|
|
|
AttributeEqual("mimeType", "application/mp4"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(RepresentationTest, WebVttMimeType) {
|
|
|
|
const char kWebVttMediaInfo[] =
|
|
|
|
"text_info {\n"
|
2018-02-26 20:13:28 +00:00
|
|
|
" codec: 'wvtt'\n"
|
2017-12-14 21:30:16 +00:00
|
|
|
"}\n"
|
|
|
|
"container_type: CONTAINER_TEXT\n";
|
|
|
|
|
|
|
|
auto representation = CreateRepresentation(
|
|
|
|
ConvertToMediaInfo(kWebVttMediaInfo), kAnyRepresentationId, NoListener());
|
|
|
|
ASSERT_TRUE(representation->Init());
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation->GetXml(), AttributeEqual("mimeType", "text/vtt"));
|
2017-12-14 21:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that Suppress*() methods work.
|
|
|
|
TEST_F(RepresentationTest, SuppressRepresentationAttributes) {
|
|
|
|
const char kTestMediaInfo[] =
|
|
|
|
"video_info {\n"
|
|
|
|
" codec: 'avc1'\n"
|
|
|
|
" width: 720\n"
|
|
|
|
" height: 480\n"
|
|
|
|
" time_scale: 10\n"
|
|
|
|
" frame_duration: 10\n"
|
|
|
|
" pixel_width: 1\n"
|
|
|
|
" pixel_height: 1\n"
|
|
|
|
"}\n"
|
|
|
|
"container_type: 1\n";
|
|
|
|
|
|
|
|
auto representation = CreateRepresentation(
|
|
|
|
ConvertToMediaInfo(kTestMediaInfo), kAnyRepresentationId, NoListener());
|
|
|
|
|
|
|
|
representation->SuppressOnce(Representation::kSuppressWidth);
|
2020-11-10 00:32:58 +00:00
|
|
|
auto no_width = representation->GetXml();
|
|
|
|
EXPECT_THAT(no_width, Not(AttributeSet("width")));
|
|
|
|
EXPECT_THAT(no_width, AttributeEqual("height", "480"));
|
|
|
|
EXPECT_THAT(no_width, AttributeEqual("frameRate", "10/10"));
|
2017-12-14 21:30:16 +00:00
|
|
|
|
|
|
|
representation->SuppressOnce(Representation::kSuppressHeight);
|
2020-11-10 00:32:58 +00:00
|
|
|
auto no_height = representation->GetXml();
|
|
|
|
EXPECT_THAT(no_height, Not(AttributeSet("height")));
|
|
|
|
EXPECT_THAT(no_height, AttributeEqual("width", "720"));
|
|
|
|
EXPECT_THAT(no_height, AttributeEqual("frameRate", "10/10"));
|
2017-12-14 21:30:16 +00:00
|
|
|
|
|
|
|
representation->SuppressOnce(Representation::kSuppressFrameRate);
|
2020-11-10 00:32:58 +00:00
|
|
|
auto no_frame_rate = representation->GetXml();
|
|
|
|
EXPECT_THAT(no_frame_rate, Not(AttributeSet("frameRate")));
|
|
|
|
EXPECT_THAT(no_frame_rate, AttributeEqual("width", "720"));
|
|
|
|
EXPECT_THAT(no_frame_rate, AttributeEqual("height", "480"));
|
2017-12-14 21:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(RepresentationTest, CheckRepresentationId) {
|
|
|
|
const MediaInfo video_media_info = GetTestMediaInfo(kFileNameVideoMediaInfo1);
|
|
|
|
const uint32_t kRepresentationId = 1;
|
|
|
|
|
|
|
|
auto representation =
|
|
|
|
CreateRepresentation(video_media_info, kRepresentationId, NoListener());
|
|
|
|
EXPECT_TRUE(representation->Init());
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation->GetXml(),
|
2017-12-14 21:30:16 +00:00
|
|
|
AttributeEqual("id", std::to_string(kRepresentationId)));
|
|
|
|
}
|
|
|
|
|
2017-12-14 21:58:53 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Any number for {AdaptationSet,Representation} ID. Required to create
|
|
|
|
// either objects. Not checked in test.
|
|
|
|
const char kSElementTemplate[] =
|
2019-03-22 00:12:30 +00:00
|
|
|
"<S t=\"%" PRIu64 "\" d=\"%" PRIu64 "\" r=\"%d\"/>\n";
|
2017-12-14 21:58:53 +00:00
|
|
|
const char kSElementTemplateWithoutR[] =
|
|
|
|
"<S t=\"%" PRIu64 "\" d=\"%" PRIu64 "\"/>\n";
|
|
|
|
const int kDefaultStartNumber = 1;
|
2021-08-04 18:56:44 +00:00
|
|
|
const int32_t kDefaultTimeScale = 1000;
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kScaledTargetSegmentDuration = 10;
|
2018-11-14 20:47:48 +00:00
|
|
|
const double kTargetSegmentDurationInSeconds =
|
|
|
|
static_cast<double>(kScaledTargetSegmentDuration) / kDefaultTimeScale;
|
2021-08-04 18:56:44 +00:00
|
|
|
const int32_t kSampleDuration = 2;
|
2017-12-14 21:58:53 +00:00
|
|
|
|
|
|
|
std::string GetDefaultMediaInfo() {
|
|
|
|
const char kMediaInfo[] =
|
|
|
|
"video_info {\n"
|
|
|
|
" codec: 'avc1.010101'\n"
|
|
|
|
" width: 720\n"
|
|
|
|
" height: 480\n"
|
|
|
|
" time_scale: 10\n"
|
|
|
|
" frame_duration: 5\n"
|
|
|
|
" pixel_width: 1\n"
|
|
|
|
" pixel_height: 1\n"
|
|
|
|
"}\n"
|
|
|
|
"reference_time_scale: %u\n"
|
|
|
|
"container_type: 1\n"
|
2018-04-17 17:42:45 +00:00
|
|
|
"init_segment_url: 'init.mp4'\n"
|
|
|
|
"segment_template_url: '$Time$.mp4'\n";
|
2017-12-14 21:58:53 +00:00
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
return absl::StrFormat(kMediaInfo, kDefaultTimeScale);
|
2017-12-14 21:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
class SegmentTemplateTest : public RepresentationTest {
|
|
|
|
public:
|
|
|
|
void SetUp() override {
|
|
|
|
mpd_options_.mpd_type = MpdType::kDynamic;
|
2021-09-03 16:57:43 +00:00
|
|
|
mpd_options_.mpd_params.low_latency_dash_mode = false;
|
|
|
|
|
2017-12-14 21:58:53 +00:00
|
|
|
representation_ =
|
|
|
|
CreateRepresentation(ConvertToMediaInfo(GetDefaultMediaInfo()),
|
|
|
|
kAnyRepresentationId, NoListener());
|
|
|
|
ASSERT_TRUE(representation_->Init());
|
|
|
|
}
|
|
|
|
|
2018-06-22 01:14:34 +00:00
|
|
|
void AddSegments(int64_t start_time,
|
|
|
|
int64_t duration,
|
2017-12-14 21:58:53 +00:00
|
|
|
uint64_t size,
|
2019-03-22 00:12:30 +00:00
|
|
|
int repeat) {
|
2017-12-14 21:58:53 +00:00
|
|
|
DCHECK(representation_);
|
|
|
|
|
2024-05-02 20:25:49 +00:00
|
|
|
SegmentInfo s = {start_time, duration, repeat, segment_number_};
|
2017-12-14 21:58:53 +00:00
|
|
|
segment_infos_for_expected_out_.push_back(s);
|
2021-09-03 16:57:43 +00:00
|
|
|
|
|
|
|
if (mpd_options_.mpd_params.low_latency_dash_mode) {
|
|
|
|
// Low latency segments do not repeat, so create 1 new segment and return.
|
|
|
|
// At this point, only the first chunk of the low latency segment has been
|
|
|
|
// written. The bandwidth will be updated once the segment is fully
|
|
|
|
// written and the segment duration and size are known.
|
2024-05-02 20:25:49 +00:00
|
|
|
representation_->AddNewSegment(start_time, duration, size,
|
|
|
|
segment_number_++);
|
2021-09-03 16:57:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-14 21:58:53 +00:00
|
|
|
if (repeat == 0) {
|
|
|
|
expected_s_elements_ +=
|
2023-12-01 17:32:19 +00:00
|
|
|
absl::StrFormat(kSElementTemplateWithoutR, start_time, duration);
|
2017-12-14 21:58:53 +00:00
|
|
|
} else {
|
|
|
|
expected_s_elements_ +=
|
2023-12-01 17:32:19 +00:00
|
|
|
absl::StrFormat(kSElementTemplate, start_time, duration, repeat);
|
2017-12-14 21:58:53 +00:00
|
|
|
}
|
|
|
|
|
2019-03-22 00:12:30 +00:00
|
|
|
for (int i = 0; i < repeat + 1; ++i) {
|
2024-05-02 20:25:49 +00:00
|
|
|
representation_->AddNewSegment(start_time, duration, size,
|
|
|
|
segment_number_++);
|
2017-12-14 21:58:53 +00:00
|
|
|
start_time += duration;
|
|
|
|
bandwidth_estimator_.AddBlock(
|
|
|
|
size, static_cast<double>(duration) / kDefaultTimeScale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-03 16:57:43 +00:00
|
|
|
void UpdateSegment(int64_t duration, uint64_t size) {
|
|
|
|
DCHECK(representation_);
|
|
|
|
DCHECK(!segment_infos_for_expected_out_.empty());
|
|
|
|
|
|
|
|
segment_infos_for_expected_out_.back().duration = duration;
|
|
|
|
representation_->UpdateCompletedSegment(duration, size);
|
|
|
|
bandwidth_estimator_.AddBlock(
|
|
|
|
size, static_cast<double>(duration) / kDefaultTimeScale);
|
|
|
|
}
|
|
|
|
|
2017-12-14 21:58:53 +00:00
|
|
|
protected:
|
|
|
|
std::string ExpectedXml() {
|
|
|
|
const char kOutputTemplate[] =
|
|
|
|
"<Representation id=\"1\" bandwidth=\"%" PRIu64
|
|
|
|
"\" "
|
|
|
|
" codecs=\"avc1.010101\" mimeType=\"video/mp4\" sar=\"1:1\" "
|
|
|
|
" width=\"720\" height=\"480\" frameRate=\"10/5\">\n"
|
|
|
|
" <SegmentTemplate timescale=\"1000\" "
|
2018-03-17 01:47:25 +00:00
|
|
|
" initialization=\"init.mp4\" media=\"$Time$.mp4\" "
|
|
|
|
" startNumber=\"1\">\n"
|
2017-12-14 21:58:53 +00:00
|
|
|
" <SegmentTimeline>\n"
|
|
|
|
" %s\n"
|
|
|
|
" </SegmentTimeline>\n"
|
|
|
|
" </SegmentTemplate>\n"
|
|
|
|
"</Representation>\n";
|
2023-12-01 17:32:19 +00:00
|
|
|
return absl::StrFormat(kOutputTemplate, bandwidth_estimator_.Max(),
|
|
|
|
expected_s_elements_.c_str());
|
2017-12-14 21:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<Representation> representation_;
|
|
|
|
std::list<SegmentInfo> segment_infos_for_expected_out_;
|
|
|
|
std::string expected_s_elements_;
|
|
|
|
BandwidthEstimator bandwidth_estimator_;
|
2024-05-02 20:25:49 +00:00
|
|
|
int64_t segment_number_ = 1;
|
2017-12-14 21:58:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Estimate the bandwidth given the info from AddNewSegment().
|
|
|
|
TEST_F(SegmentTemplateTest, OneSegmentNormal) {
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kStartTime = 0;
|
|
|
|
const int64_t kDuration = 10;
|
2017-12-14 21:58:53 +00:00
|
|
|
const uint64_t kSize = 128;
|
|
|
|
AddSegments(kStartTime, kDuration, kSize, 0);
|
|
|
|
|
2017-09-25 19:18:50 +00:00
|
|
|
expected_s_elements_ = "<S t=\"0\" d=\"10\"/>";
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation_->GetXml(), XmlNodeEqual(ExpectedXml()));
|
2017-12-14 21:58:53 +00:00
|
|
|
}
|
|
|
|
|
2021-09-03 16:57:43 +00:00
|
|
|
TEST_F(SegmentTemplateTest, OneSegmentLowLatency) {
|
|
|
|
const int64_t kStartTime = 0;
|
|
|
|
const int64_t kChunkDuration = 5;
|
|
|
|
const uint64_t kChunkSize = 128;
|
|
|
|
const int64_t kSegmentDuration = kChunkDuration * 1000;
|
|
|
|
const uint64_t kSegmentSize = kChunkSize * 1000;
|
|
|
|
|
|
|
|
mpd_options_.mpd_params.low_latency_dash_mode = true;
|
|
|
|
mpd_options_.mpd_params.target_segment_duration =
|
|
|
|
kSegmentDuration / representation_->GetMediaInfo().reference_time_scale();
|
|
|
|
|
|
|
|
// Set values used in LL-DASH MPD attributes
|
|
|
|
representation_->SetSampleDuration(kChunkDuration);
|
|
|
|
representation_->SetAvailabilityTimeOffset();
|
|
|
|
representation_->SetSegmentDuration();
|
|
|
|
|
|
|
|
// Register segment after the first chunk is complete
|
|
|
|
AddSegments(kStartTime, kChunkDuration, kChunkSize, 0);
|
|
|
|
// Update SegmentInfo after the segment is complete
|
|
|
|
UpdateSegment(kSegmentDuration, kSegmentSize);
|
|
|
|
|
|
|
|
const char kOutputTemplate[] =
|
|
|
|
"<Representation id=\"1\" bandwidth=\"204800\" "
|
|
|
|
" codecs=\"avc1.010101\" mimeType=\"video/mp4\" sar=\"1:1\" "
|
|
|
|
" width=\"720\" height=\"480\" frameRate=\"10/5\">\n"
|
|
|
|
" <SegmentTemplate timescale=\"1000\" "
|
|
|
|
" duration=\"5000\" availabilityTimeOffset=\"4.995\" "
|
2023-07-05 21:33:51 +00:00
|
|
|
" availabilityTimeComplete=\"false\" initialization=\"init.mp4\" "
|
|
|
|
" media=\"$Time$.mp4\" startNumber=\"1\"/>\n"
|
2021-09-03 16:57:43 +00:00
|
|
|
"</Representation>\n";
|
|
|
|
EXPECT_THAT(representation_->GetXml(), XmlNodeEqual(kOutputTemplate));
|
|
|
|
}
|
|
|
|
|
2018-01-03 00:10:54 +00:00
|
|
|
TEST_F(SegmentTemplateTest, RepresentationClone) {
|
|
|
|
MediaInfo media_info = ConvertToMediaInfo(GetDefaultMediaInfo());
|
2018-04-17 17:42:45 +00:00
|
|
|
media_info.set_segment_template_url("$Number$.mp4");
|
2018-01-03 00:10:54 +00:00
|
|
|
representation_ =
|
|
|
|
CreateRepresentation(media_info, kAnyRepresentationId, NoListener());
|
|
|
|
ASSERT_TRUE(representation_->Init());
|
|
|
|
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kStartTime = 0;
|
|
|
|
const int64_t kDuration = 10;
|
2018-01-03 00:10:54 +00:00
|
|
|
const uint64_t kSize = 128;
|
|
|
|
AddSegments(kStartTime, kDuration, kSize, 0);
|
|
|
|
|
2018-01-29 18:37:50 +00:00
|
|
|
auto cloned_representation =
|
|
|
|
CopyRepresentation(*representation_, NoListener());
|
2024-05-02 20:25:49 +00:00
|
|
|
|
2018-01-03 00:10:54 +00:00
|
|
|
const char kExpectedXml[] =
|
|
|
|
"<Representation id=\"1\" bandwidth=\"0\" "
|
|
|
|
" codecs=\"avc1.010101\" mimeType=\"video/mp4\" sar=\"1:1\" "
|
|
|
|
" width=\"720\" height=\"480\" frameRate=\"10/5\">\n"
|
2018-01-29 18:37:50 +00:00
|
|
|
" <SegmentTemplate timescale=\"1000\" initialization=\"init.mp4\" "
|
2024-05-02 20:25:49 +00:00
|
|
|
" media=\"$Number$.mp4\" startNumber=\"1\">\n"
|
2018-01-03 00:10:54 +00:00
|
|
|
" </SegmentTemplate>\n"
|
|
|
|
"</Representation>\n";
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(cloned_representation->GetXml(), XmlNodeEqual(kExpectedXml));
|
2018-01-03 00:10:54 +00:00
|
|
|
}
|
|
|
|
|
2018-01-29 18:37:50 +00:00
|
|
|
TEST_F(SegmentTemplateTest, PresentationTimeOffset) {
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kStartTime = 0;
|
|
|
|
const int64_t kDuration = 10;
|
2018-01-05 02:31:27 +00:00
|
|
|
const uint64_t kSize = 128;
|
|
|
|
AddSegments(kStartTime, kDuration, kSize, 0);
|
2018-01-29 18:37:50 +00:00
|
|
|
|
|
|
|
const double kPresentationTimeOffsetSeconds = 2.3;
|
|
|
|
representation_->SetPresentationTimeOffset(kPresentationTimeOffsetSeconds);
|
|
|
|
|
|
|
|
const char kExpectedXml[] =
|
|
|
|
"<Representation id=\"1\" bandwidth=\"102400\" "
|
|
|
|
" codecs=\"avc1.010101\" mimeType=\"video/mp4\" sar=\"1:1\" "
|
|
|
|
" width=\"720\" height=\"480\" frameRate=\"10/5\">\n"
|
2018-04-09 18:47:29 +00:00
|
|
|
" <SegmentTemplate timescale=\"1000\" presentationTimeOffset=\"2300\""
|
2018-03-17 01:47:25 +00:00
|
|
|
" initialization=\"init.mp4\" media=\"$Time$.mp4\" startNumber=\"1\">\n"
|
2018-01-29 18:37:50 +00:00
|
|
|
" <SegmentTimeline>\n"
|
|
|
|
" <S t=\"0\" d=\"10\"/>\n"
|
2017-09-25 19:18:50 +00:00
|
|
|
" </SegmentTimeline>\n"
|
2018-01-29 18:37:50 +00:00
|
|
|
" </SegmentTemplate>\n"
|
|
|
|
"</Representation>\n";
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation_->GetXml(), XmlNodeEqual(kExpectedXml));
|
2018-01-05 02:31:27 +00:00
|
|
|
}
|
|
|
|
|
2018-01-29 18:37:50 +00:00
|
|
|
TEST_F(SegmentTemplateTest, GetStartAndEndTimestamps) {
|
|
|
|
double start_timestamp;
|
|
|
|
double end_timestamp;
|
|
|
|
// No segments.
|
|
|
|
EXPECT_FALSE(representation_->GetStartAndEndTimestamps(&start_timestamp,
|
|
|
|
&end_timestamp));
|
2018-01-05 02:31:27 +00:00
|
|
|
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kStartTime = 88;
|
|
|
|
const int64_t kDuration = 10;
|
2018-01-29 18:37:50 +00:00
|
|
|
const uint64_t kSize = 128;
|
|
|
|
AddSegments(kStartTime, kDuration, kSize, 0);
|
|
|
|
AddSegments(kStartTime + kDuration, kDuration, kSize, 2);
|
|
|
|
ASSERT_TRUE(representation_->GetStartAndEndTimestamps(&start_timestamp,
|
|
|
|
&end_timestamp));
|
|
|
|
EXPECT_EQ(static_cast<double>(kStartTime) / kDefaultTimeScale,
|
|
|
|
start_timestamp);
|
|
|
|
EXPECT_EQ(static_cast<double>(kStartTime + kDuration * 4) / kDefaultTimeScale,
|
|
|
|
end_timestamp);
|
2018-01-05 02:31:27 +00:00
|
|
|
}
|
|
|
|
|
2017-12-14 21:58:53 +00:00
|
|
|
TEST_F(SegmentTemplateTest, NormalRepeatedSegmentDuration) {
|
|
|
|
const uint64_t kSize = 256;
|
2018-06-22 01:14:34 +00:00
|
|
|
int64_t start_time = 0;
|
|
|
|
int64_t duration = 40000;
|
2019-03-22 00:12:30 +00:00
|
|
|
int repeat = 2;
|
2017-12-14 21:58:53 +00:00
|
|
|
AddSegments(start_time, duration, kSize, repeat);
|
|
|
|
|
|
|
|
start_time += duration * (repeat + 1);
|
|
|
|
duration = 54321;
|
|
|
|
repeat = 0;
|
|
|
|
AddSegments(start_time, duration, kSize, repeat);
|
|
|
|
|
|
|
|
start_time += duration * (repeat + 1);
|
|
|
|
duration = 12345;
|
|
|
|
repeat = 0;
|
|
|
|
AddSegments(start_time, duration, kSize, repeat);
|
|
|
|
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation_->GetXml(), XmlNodeEqual(ExpectedXml()));
|
2017-12-14 21:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SegmentTemplateTest, RepeatedSegmentsFromNonZeroStartTime) {
|
|
|
|
const uint64_t kSize = 100000;
|
2018-06-22 01:14:34 +00:00
|
|
|
int64_t start_time = 0;
|
|
|
|
int64_t duration = 100000;
|
2019-03-22 00:12:30 +00:00
|
|
|
int repeat = 2;
|
2017-12-14 21:58:53 +00:00
|
|
|
AddSegments(start_time, duration, kSize, repeat);
|
|
|
|
|
|
|
|
start_time += duration * (repeat + 1);
|
|
|
|
duration = 20000;
|
|
|
|
repeat = 3;
|
|
|
|
AddSegments(start_time, duration, kSize, repeat);
|
|
|
|
|
|
|
|
start_time += duration * (repeat + 1);
|
|
|
|
duration = 32123;
|
|
|
|
repeat = 3;
|
|
|
|
AddSegments(start_time, duration, kSize, repeat);
|
|
|
|
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation_->GetXml(), XmlNodeEqual(ExpectedXml()));
|
2017-12-14 21:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Segments not starting from 0.
|
|
|
|
// Start time is 10. Make sure r gets set correctly.
|
|
|
|
TEST_F(SegmentTemplateTest, NonZeroStartTime) {
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kStartTime = 10;
|
|
|
|
const int64_t kDuration = 22000;
|
2019-03-22 00:12:30 +00:00
|
|
|
const int kSize = 123456;
|
|
|
|
const int kRepeat = 1;
|
2017-12-14 21:58:53 +00:00
|
|
|
AddSegments(kStartTime, kDuration, kSize, kRepeat);
|
|
|
|
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation_->GetXml(), XmlNodeEqual(ExpectedXml()));
|
2017-12-14 21:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// There is a gap in the segments, but still valid.
|
|
|
|
TEST_F(SegmentTemplateTest, NonContiguousLiveInfo) {
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kStartTime = 10;
|
|
|
|
const int64_t kDuration = 22000;
|
2019-03-22 00:12:30 +00:00
|
|
|
const int kSize = 123456;
|
|
|
|
const int kRepeat = 0;
|
2017-12-14 21:58:53 +00:00
|
|
|
AddSegments(kStartTime, kDuration, kSize, kRepeat);
|
|
|
|
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kStartTimeOffset = 100;
|
2017-12-14 21:58:53 +00:00
|
|
|
AddSegments(kDuration + kStartTimeOffset, kDuration, kSize, kRepeat);
|
|
|
|
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation_->GetXml(), XmlNodeEqual(ExpectedXml()));
|
2017-12-14 21:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add segments out of order. Segments that start before the previous segment
|
|
|
|
// cannot be added.
|
|
|
|
TEST_F(SegmentTemplateTest, OutOfOrder) {
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kEarlierStartTime = 0;
|
|
|
|
const int64_t kLaterStartTime = 1000;
|
|
|
|
const int64_t kDuration = 1000;
|
2019-03-22 00:12:30 +00:00
|
|
|
const int kSize = 123456;
|
|
|
|
const int kRepeat = 0;
|
2017-12-14 21:58:53 +00:00
|
|
|
|
|
|
|
AddSegments(kLaterStartTime, kDuration, kSize, kRepeat);
|
|
|
|
AddSegments(kEarlierStartTime, kDuration, kSize, kRepeat);
|
|
|
|
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation_->GetXml(), XmlNodeEqual(ExpectedXml()));
|
2017-12-14 21:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// No segments should be overlapping.
|
|
|
|
TEST_F(SegmentTemplateTest, OverlappingSegments) {
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kEarlierStartTime = 0;
|
|
|
|
const int64_t kDuration = 1000;
|
2019-03-22 00:12:30 +00:00
|
|
|
const int kSize = 123456;
|
|
|
|
const int kRepeat = 0;
|
2017-12-14 21:58:53 +00:00
|
|
|
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kOverlappingSegmentStartTime = kDuration / 2;
|
2017-12-14 21:58:53 +00:00
|
|
|
CHECK_GT(kDuration, kOverlappingSegmentStartTime);
|
|
|
|
|
|
|
|
AddSegments(kEarlierStartTime, kDuration, kSize, kRepeat);
|
|
|
|
AddSegments(kOverlappingSegmentStartTime, kDuration, kSize, kRepeat);
|
|
|
|
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation_->GetXml(), XmlNodeEqual(ExpectedXml()));
|
2017-12-14 21:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Some segments can be overlapped due to rounding errors. As long as it falls
|
|
|
|
// in the range of rounding error defined inside MpdBuilder, the segment gets
|
|
|
|
// accepted.
|
|
|
|
TEST_F(SegmentTemplateTest, OverlappingSegmentsWithinErrorRange) {
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kEarlierStartTime = 0;
|
|
|
|
const int64_t kDuration = 1000;
|
2019-03-22 00:12:30 +00:00
|
|
|
const int kSize = 123456;
|
|
|
|
const int kRepeat = 0;
|
2017-12-14 21:58:53 +00:00
|
|
|
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kOverlappingSegmentStartTime = kDuration - 1;
|
2017-12-14 21:58:53 +00:00
|
|
|
CHECK_GT(kDuration, kOverlappingSegmentStartTime);
|
|
|
|
|
|
|
|
AddSegments(kEarlierStartTime, kDuration, kSize, kRepeat);
|
|
|
|
AddSegments(kOverlappingSegmentStartTime, kDuration, kSize, kRepeat);
|
|
|
|
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation_->GetXml(), XmlNodeEqual(ExpectedXml()));
|
2017-12-14 21:58:53 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 19:18:50 +00:00
|
|
|
class SegmentTimelineTestBase : public SegmentTemplateTest {
|
2017-12-14 21:58:53 +00:00
|
|
|
public:
|
|
|
|
void SetUp() override {
|
|
|
|
// The only diff with current GetDefaultMediaInfo() is that this uses
|
|
|
|
// $Number$ for segment template.
|
|
|
|
const char kMediaInfo[] =
|
|
|
|
"video_info {\n"
|
|
|
|
" codec: 'avc1.010101'\n"
|
|
|
|
" width: 720\n"
|
|
|
|
" height: 480\n"
|
|
|
|
" time_scale: 10\n"
|
|
|
|
" frame_duration: 2\n"
|
|
|
|
" pixel_width: 1\n"
|
|
|
|
" pixel_height: 1\n"
|
|
|
|
"}\n"
|
|
|
|
"reference_time_scale: %u\n"
|
|
|
|
"container_type: 1\n"
|
2018-04-17 17:42:45 +00:00
|
|
|
"init_segment_url: 'init.mp4'\n"
|
|
|
|
"segment_template_url: '$Number$.mp4'\n";
|
2017-12-14 21:58:53 +00:00
|
|
|
const std::string& number_template_media_info =
|
2023-12-01 17:32:19 +00:00
|
|
|
absl::StrFormat(kMediaInfo, kDefaultTimeScale);
|
2017-12-14 21:58:53 +00:00
|
|
|
mpd_options_.mpd_type = MpdType::kDynamic;
|
2018-11-14 20:47:48 +00:00
|
|
|
mpd_options_.mpd_params.target_segment_duration =
|
|
|
|
kTargetSegmentDurationInSeconds;
|
2017-12-14 21:58:53 +00:00
|
|
|
representation_ =
|
|
|
|
CreateRepresentation(ConvertToMediaInfo(number_template_media_info),
|
|
|
|
kAnyRepresentationId, NoListener());
|
|
|
|
ASSERT_TRUE(representation_->Init());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ExpectedXml(const std::string& expected_s_element,
|
|
|
|
int expected_start_number) {
|
|
|
|
const char kOutputTemplate[] =
|
|
|
|
"<Representation id=\"1\" bandwidth=\"%" PRIu64
|
|
|
|
"\" "
|
|
|
|
" codecs=\"avc1.010101\" mimeType=\"video/mp4\" sar=\"1:1\" "
|
|
|
|
" width=\"720\" height=\"480\" frameRate=\"10/2\">\n"
|
|
|
|
" <SegmentTemplate timescale=\"1000\" "
|
|
|
|
" initialization=\"init.mp4\" media=\"$Number$.mp4\" "
|
|
|
|
" startNumber=\"%d\">\n"
|
|
|
|
" <SegmentTimeline>\n"
|
|
|
|
" %s\n"
|
|
|
|
" </SegmentTimeline>\n"
|
|
|
|
" </SegmentTemplate>\n"
|
|
|
|
"</Representation>\n";
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
return absl::StrFormat(kOutputTemplate, bandwidth_estimator_.Max(),
|
|
|
|
expected_start_number, expected_s_element.c_str());
|
2017-12-14 21:58:53 +00:00
|
|
|
}
|
2017-09-25 19:18:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ApproximateSegmentTimelineTest : public SegmentTimelineTestBase,
|
|
|
|
public WithParamInterface<bool> {
|
|
|
|
public:
|
|
|
|
void SetUp() override {
|
|
|
|
allow_approximate_segment_timeline_ = GetParam();
|
|
|
|
mpd_options_.mpd_params.allow_approximate_segment_timeline =
|
|
|
|
allow_approximate_segment_timeline_;
|
|
|
|
SegmentTimelineTestBase::SetUp();
|
|
|
|
representation_->SetSampleDuration(kSampleDuration);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ExpectedXml(const std::string& expected_s_element) {
|
|
|
|
return SegmentTimelineTestBase::ExpectedXml(expected_s_element,
|
|
|
|
kDefaultStartNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool allow_approximate_segment_timeline_;
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(ApproximateSegmentTimelineTest, SegmentDurationAdjusted) {
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kStartTime = 0;
|
|
|
|
const int64_t kDurationSmaller =
|
2017-09-25 19:18:50 +00:00
|
|
|
kScaledTargetSegmentDuration - kSampleDuration / 2;
|
|
|
|
const uint64_t kSize = 128;
|
|
|
|
AddSegments(kStartTime, kDurationSmaller, kSize, 0);
|
|
|
|
|
|
|
|
std::string expected_s_elements;
|
|
|
|
if (allow_approximate_segment_timeline_) {
|
2023-12-01 17:32:19 +00:00
|
|
|
expected_s_elements = absl::StrFormat(kSElementTemplateWithoutR, kStartTime,
|
|
|
|
kScaledTargetSegmentDuration);
|
2017-09-25 19:18:50 +00:00
|
|
|
} else {
|
2023-12-01 17:32:19 +00:00
|
|
|
expected_s_elements = absl::StrFormat(kSElementTemplateWithoutR, kStartTime,
|
|
|
|
kDurationSmaller);
|
2017-09-25 19:18:50 +00:00
|
|
|
}
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation_->GetXml(),
|
2017-09-25 19:18:50 +00:00
|
|
|
XmlNodeEqual(ExpectedXml(expected_s_elements)));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(ApproximateSegmentTimelineTest,
|
|
|
|
SegmentDurationAdjustedWithNonZeroStartTime) {
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kStartTime = 12345;
|
|
|
|
const int64_t kDurationSmaller =
|
2017-09-25 19:18:50 +00:00
|
|
|
kScaledTargetSegmentDuration - kSampleDuration / 2;
|
|
|
|
const uint64_t kSize = 128;
|
|
|
|
|
|
|
|
AddSegments(kStartTime, kDurationSmaller, kSize, 0);
|
|
|
|
|
|
|
|
std::string expected_s_elements;
|
|
|
|
if (allow_approximate_segment_timeline_) {
|
2023-12-01 17:32:19 +00:00
|
|
|
expected_s_elements = absl::StrFormat(kSElementTemplateWithoutR, kStartTime,
|
|
|
|
kScaledTargetSegmentDuration);
|
2017-09-25 19:18:50 +00:00
|
|
|
} else {
|
2023-12-01 17:32:19 +00:00
|
|
|
expected_s_elements = absl::StrFormat(kSElementTemplateWithoutR, kStartTime,
|
|
|
|
kDurationSmaller);
|
2017-09-25 19:18:50 +00:00
|
|
|
}
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation_->GetXml(),
|
2017-09-25 19:18:50 +00:00
|
|
|
XmlNodeEqual(ExpectedXml(expected_s_elements)));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(ApproximateSegmentTimelineTest, SegmentsWithSimilarDurations) {
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kStartTime = 0;
|
|
|
|
const int64_t kDurationSmaller =
|
2017-09-25 19:18:50 +00:00
|
|
|
kScaledTargetSegmentDuration - kSampleDuration / 2;
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kDurationLarger =
|
2017-09-25 19:18:50 +00:00
|
|
|
kScaledTargetSegmentDuration + kSampleDuration / 2;
|
|
|
|
const uint64_t kSize = 128;
|
|
|
|
AddSegments(kStartTime, kDurationSmaller, kSize, 0);
|
|
|
|
AddSegments(kStartTime + kDurationSmaller, kDurationLarger, kSize, 0);
|
|
|
|
AddSegments(kStartTime + kDurationSmaller + kDurationLarger, kDurationSmaller,
|
|
|
|
kSize, 0);
|
|
|
|
|
|
|
|
std::string expected_s_elements;
|
|
|
|
if (allow_approximate_segment_timeline_) {
|
2019-03-22 00:12:30 +00:00
|
|
|
int kNumSegments = 3;
|
2017-09-25 19:18:50 +00:00
|
|
|
expected_s_elements =
|
2023-12-01 17:32:19 +00:00
|
|
|
absl::StrFormat(kSElementTemplate, kStartTime,
|
|
|
|
kScaledTargetSegmentDuration, kNumSegments - 1);
|
2017-09-25 19:18:50 +00:00
|
|
|
} else {
|
|
|
|
expected_s_elements =
|
2023-12-01 17:32:19 +00:00
|
|
|
absl::StrFormat(kSElementTemplateWithoutR, kStartTime,
|
|
|
|
kDurationSmaller) +
|
|
|
|
absl::StrFormat(kSElementTemplateWithoutR,
|
|
|
|
kStartTime + kDurationSmaller, kDurationLarger) +
|
|
|
|
absl::StrFormat(kSElementTemplateWithoutR,
|
|
|
|
kStartTime + kDurationSmaller + kDurationLarger,
|
|
|
|
kDurationSmaller);
|
2017-09-25 19:18:50 +00:00
|
|
|
}
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation_->GetXml(),
|
2017-09-25 19:18:50 +00:00
|
|
|
XmlNodeEqual(ExpectedXml(expected_s_elements)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// We assume the actual segment duration fluctuates around target segment
|
|
|
|
// duration; if it is not the case (which should not happen with our demuxer),
|
|
|
|
// this is how the output would look like.
|
|
|
|
TEST_P(ApproximateSegmentTimelineTest, SegmentsWithSimilarDurations2) {
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kStartTime = 0;
|
|
|
|
const int64_t kDurationLarger =
|
2017-09-25 19:18:50 +00:00
|
|
|
kScaledTargetSegmentDuration + kSampleDuration / 2;
|
|
|
|
const uint64_t kSize = 128;
|
|
|
|
AddSegments(kStartTime, kDurationLarger, kSize, 0);
|
|
|
|
AddSegments(kStartTime + kDurationLarger, kDurationLarger, kSize, 0);
|
|
|
|
AddSegments(kStartTime + 2 * kDurationLarger, kDurationLarger, kSize, 0);
|
|
|
|
|
|
|
|
std::string expected_s_elements;
|
|
|
|
if (allow_approximate_segment_timeline_) {
|
|
|
|
expected_s_elements =
|
2018-06-21 21:26:41 +00:00
|
|
|
"<S t=\"0\" d=\"10\" r=\"1\"/>"
|
|
|
|
"<S t=\"20\" d=\"13\"/>";
|
2017-09-25 19:18:50 +00:00
|
|
|
} else {
|
2019-03-22 00:12:30 +00:00
|
|
|
int kNumSegments = 3;
|
2023-12-01 17:32:19 +00:00
|
|
|
expected_s_elements = absl::StrFormat(kSElementTemplate, kStartTime,
|
|
|
|
kDurationLarger, kNumSegments - 1);
|
2017-09-25 19:18:50 +00:00
|
|
|
}
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation_->GetXml(),
|
2017-09-25 19:18:50 +00:00
|
|
|
XmlNodeEqual(ExpectedXml(expected_s_elements)));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(ApproximateSegmentTimelineTest, FillSmallGap) {
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kStartTime = 0;
|
|
|
|
const int64_t kDuration = kScaledTargetSegmentDuration;
|
|
|
|
const int64_t kGap = kSampleDuration / 2;
|
2017-09-25 19:18:50 +00:00
|
|
|
const uint64_t kSize = 128;
|
|
|
|
AddSegments(kStartTime, kDuration, kSize, 0);
|
|
|
|
AddSegments(kStartTime + kDuration + kGap, kDuration, kSize, 0);
|
|
|
|
AddSegments(kStartTime + 2 * kDuration + kGap, kDuration, kSize, 0);
|
|
|
|
|
|
|
|
std::string expected_s_elements;
|
|
|
|
if (allow_approximate_segment_timeline_) {
|
2019-03-22 00:12:30 +00:00
|
|
|
int kNumSegments = 3;
|
2023-12-01 17:32:19 +00:00
|
|
|
expected_s_elements = absl::StrFormat(kSElementTemplate, kStartTime,
|
|
|
|
kDuration, kNumSegments - 1);
|
2017-09-25 19:18:50 +00:00
|
|
|
} else {
|
|
|
|
expected_s_elements =
|
2023-12-01 17:32:19 +00:00
|
|
|
absl::StrFormat(kSElementTemplateWithoutR, kStartTime, kDuration) +
|
|
|
|
absl::StrFormat(kSElementTemplate, kStartTime + kDuration + kGap,
|
|
|
|
kDuration, 1 /* repeat */);
|
2017-09-25 19:18:50 +00:00
|
|
|
}
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation_->GetXml(),
|
2017-09-25 19:18:50 +00:00
|
|
|
XmlNodeEqual(ExpectedXml(expected_s_elements)));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(ApproximateSegmentTimelineTest, FillSmallOverlap) {
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kStartTime = 0;
|
|
|
|
const int64_t kDuration = kScaledTargetSegmentDuration;
|
|
|
|
const int64_t kOverlap = kSampleDuration / 2;
|
2017-09-25 19:18:50 +00:00
|
|
|
const uint64_t kSize = 128;
|
|
|
|
AddSegments(kStartTime, kDuration, kSize, 0);
|
|
|
|
AddSegments(kStartTime + kDuration - kOverlap, kDuration, kSize, 0);
|
|
|
|
AddSegments(kStartTime + 2 * kDuration - kOverlap, kDuration, kSize, 0);
|
|
|
|
|
|
|
|
std::string expected_s_elements;
|
|
|
|
if (allow_approximate_segment_timeline_) {
|
2019-03-22 00:12:30 +00:00
|
|
|
int kNumSegments = 3;
|
2023-12-01 17:32:19 +00:00
|
|
|
expected_s_elements = absl::StrFormat(kSElementTemplate, kStartTime,
|
|
|
|
kDuration, kNumSegments - 1);
|
2017-09-25 19:18:50 +00:00
|
|
|
} else {
|
|
|
|
expected_s_elements =
|
2023-12-01 17:32:19 +00:00
|
|
|
absl::StrFormat(kSElementTemplateWithoutR, kStartTime, kDuration) +
|
|
|
|
absl::StrFormat(kSElementTemplate, kStartTime + kDuration - kOverlap,
|
|
|
|
kDuration, 1 /* repeat */);
|
2017-09-25 19:18:50 +00:00
|
|
|
}
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation_->GetXml(),
|
2017-09-25 19:18:50 +00:00
|
|
|
XmlNodeEqual(ExpectedXml(expected_s_elements)));
|
|
|
|
}
|
|
|
|
|
2018-06-21 21:26:41 +00:00
|
|
|
// Check the segments are grouped correctly when sample duration is not
|
|
|
|
// available, which happens for text streams.
|
2022-03-07 19:56:34 +00:00
|
|
|
// See https://github.com/shaka-project/shaka-packager/issues/417 for the
|
|
|
|
// background.
|
2018-06-21 21:26:41 +00:00
|
|
|
TEST_P(ApproximateSegmentTimelineTest, NoSampleDuration) {
|
|
|
|
const char kMediaInfo[] =
|
|
|
|
"text_info {\n"
|
|
|
|
" codec: 'wvtt'\n"
|
|
|
|
"}\n"
|
|
|
|
"reference_time_scale: 1000\n"
|
|
|
|
"container_type: 1\n"
|
|
|
|
"init_segment_url: 'init.mp4'\n"
|
|
|
|
"segment_template_url: '$Number$.mp4'\n";
|
|
|
|
representation_ = CreateRepresentation(ConvertToMediaInfo(kMediaInfo),
|
|
|
|
kAnyRepresentationId, NoListener());
|
|
|
|
ASSERT_TRUE(representation_->Init());
|
|
|
|
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kStartTime = 0;
|
|
|
|
const int64_t kDuration = kScaledTargetSegmentDuration;
|
2018-06-21 21:26:41 +00:00
|
|
|
const uint64_t kSize = 128;
|
|
|
|
AddSegments(kStartTime, kDuration, kSize, 0);
|
|
|
|
AddSegments(kStartTime + kDuration, kDuration, kSize, 0);
|
|
|
|
AddSegments(kStartTime + 2 * kDuration, kDuration, kSize, 0);
|
|
|
|
|
|
|
|
const char kExpectedXml[] =
|
|
|
|
"<Representation id=\"1\" bandwidth=\"102400\" codecs=\"wvtt\""
|
|
|
|
" mimeType=\"application/mp4\">\n"
|
|
|
|
" <SegmentTemplate timescale=\"1000\" initialization=\"init.mp4\" "
|
|
|
|
" media=\"$Number$.mp4\" startNumber=\"1\">\n"
|
|
|
|
" <SegmentTimeline>\n"
|
|
|
|
" <S t=\"0\" d=\"10\" r=\"2\"/>\n"
|
|
|
|
" </SegmentTimeline>\n"
|
|
|
|
" </SegmentTemplate>\n"
|
|
|
|
"</Representation>\n";
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation_->GetXml(), XmlNodeEqual(kExpectedXml));
|
2018-06-21 21:26:41 +00:00
|
|
|
}
|
|
|
|
|
2017-09-25 19:18:50 +00:00
|
|
|
INSTANTIATE_TEST_CASE_P(ApproximateSegmentTimelineTest,
|
|
|
|
ApproximateSegmentTimelineTest,
|
|
|
|
Bool());
|
|
|
|
|
|
|
|
class TimeShiftBufferDepthTest : public SegmentTimelineTestBase,
|
2018-06-22 01:14:34 +00:00
|
|
|
public WithParamInterface<int64_t> {
|
2017-09-25 19:18:50 +00:00
|
|
|
public:
|
|
|
|
void SetUp() override {
|
|
|
|
initial_start_time_ = GetParam();
|
|
|
|
SegmentTimelineTestBase::SetUp();
|
|
|
|
}
|
2017-12-14 21:58:53 +00:00
|
|
|
|
|
|
|
MpdOptions* mutable_mpd_options() { return &mpd_options_; }
|
2017-09-25 19:18:50 +00:00
|
|
|
|
|
|
|
protected:
|
2018-06-22 01:14:34 +00:00
|
|
|
int64_t initial_start_time_;
|
2017-12-14 21:58:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// All segments have the same duration and size.
|
2017-09-25 19:18:50 +00:00
|
|
|
TEST_P(TimeShiftBufferDepthTest, Normal) {
|
2017-12-14 21:58:53 +00:00
|
|
|
const int kTimeShiftBufferDepth = 10; // 10 sec.
|
|
|
|
mutable_mpd_options()->mpd_params.time_shift_buffer_depth =
|
|
|
|
kTimeShiftBufferDepth;
|
|
|
|
|
|
|
|
// Trick to make every segment 1 second long.
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kDuration = kDefaultTimeScale;
|
2017-12-14 21:58:53 +00:00
|
|
|
const uint64_t kSize = 10000;
|
2019-03-22 00:12:30 +00:00
|
|
|
const int kRepeat = 1234;
|
|
|
|
const int kLength = kRepeat;
|
2017-12-14 21:58:53 +00:00
|
|
|
|
|
|
|
CHECK_EQ(kDuration / kDefaultTimeScale * kRepeat, kLength);
|
|
|
|
|
2017-09-25 19:18:50 +00:00
|
|
|
AddSegments(initial_start_time_, kDuration, kSize, kRepeat);
|
2017-12-14 21:58:53 +00:00
|
|
|
|
|
|
|
// There should only be the last 11 segments because timeshift is 10 sec and
|
|
|
|
// each segment is 1 sec and the latest segments start time is "current
|
|
|
|
// time" i.e., the latest segment does not count as part of timeshift buffer
|
|
|
|
// depth.
|
|
|
|
// Also note that S@r + 1 is the actual number of segments.
|
|
|
|
const int kExpectedRepeatsLeft = kTimeShiftBufferDepth;
|
2017-09-25 19:18:50 +00:00
|
|
|
const int kExpectedStartNumber = kRepeat - kExpectedRepeatsLeft + 1;
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
const std::string expected_s_element = absl::StrFormat(
|
2017-09-25 19:18:50 +00:00
|
|
|
kSElementTemplate,
|
|
|
|
initial_start_time_ + kDuration * (kRepeat - kExpectedRepeatsLeft),
|
2019-03-22 00:12:30 +00:00
|
|
|
kDuration, kExpectedRepeatsLeft);
|
2017-12-14 21:58:53 +00:00
|
|
|
EXPECT_THAT(
|
2020-11-10 00:32:58 +00:00
|
|
|
representation_->GetXml(),
|
2017-12-14 21:58:53 +00:00
|
|
|
XmlNodeEqual(ExpectedXml(expected_s_element, kExpectedStartNumber)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// TimeShiftBufferDepth is shorter than a segment. This should not discard the
|
|
|
|
// segment that can play TimeShiftBufferDepth.
|
|
|
|
// For example if TimeShiftBufferDepth = 1 min. and a 10 min segment was just
|
|
|
|
// added. Before that 9 min segment was added. The 9 min segment should not be
|
|
|
|
// removed from the MPD.
|
2017-09-25 19:18:50 +00:00
|
|
|
TEST_P(TimeShiftBufferDepthTest, TimeShiftBufferDepthShorterThanSegmentLength) {
|
2017-12-14 21:58:53 +00:00
|
|
|
const int kTimeShiftBufferDepth = 10; // 10 sec.
|
|
|
|
mutable_mpd_options()->mpd_params.time_shift_buffer_depth =
|
|
|
|
kTimeShiftBufferDepth;
|
|
|
|
|
|
|
|
// Each duration is a second longer than timeShiftBufferDepth.
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kDuration = kDefaultTimeScale * (kTimeShiftBufferDepth + 1);
|
2019-03-22 00:12:30 +00:00
|
|
|
const int kSize = 10000;
|
|
|
|
const int kRepeat = 1;
|
2017-12-14 21:58:53 +00:00
|
|
|
|
2017-09-25 19:18:50 +00:00
|
|
|
AddSegments(initial_start_time_, kDuration, kSize, kRepeat);
|
2017-12-14 21:58:53 +00:00
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
const std::string expected_s_element = absl::StrFormat(
|
2017-09-25 19:18:50 +00:00
|
|
|
kSElementTemplate, initial_start_time_, kDuration, kRepeat);
|
2017-12-14 21:58:53 +00:00
|
|
|
EXPECT_THAT(
|
2020-11-10 00:32:58 +00:00
|
|
|
representation_->GetXml(),
|
2017-12-14 21:58:53 +00:00
|
|
|
XmlNodeEqual(ExpectedXml(expected_s_element, kDefaultStartNumber)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// More generic version the normal test.
|
2017-09-25 19:18:50 +00:00
|
|
|
TEST_P(TimeShiftBufferDepthTest, Generic) {
|
2017-12-14 21:58:53 +00:00
|
|
|
const int kTimeShiftBufferDepth = 30;
|
|
|
|
mutable_mpd_options()->mpd_params.time_shift_buffer_depth =
|
|
|
|
kTimeShiftBufferDepth;
|
|
|
|
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kDuration = kDefaultTimeScale;
|
2019-03-22 00:12:30 +00:00
|
|
|
const int kSize = 10000;
|
|
|
|
const int kRepeat = 1000;
|
2017-12-14 21:58:53 +00:00
|
|
|
|
2017-09-25 19:18:50 +00:00
|
|
|
AddSegments(initial_start_time_, kDuration, kSize, kRepeat);
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t first_s_element_end_time =
|
2017-09-25 19:18:50 +00:00
|
|
|
initial_start_time_ + kDuration * (kRepeat + 1);
|
2017-12-14 21:58:53 +00:00
|
|
|
|
|
|
|
// Now add 2 kTimeShiftBufferDepth long segments.
|
|
|
|
const int kNumMoreSegments = 2;
|
|
|
|
const int kMoreSegmentsRepeat = kNumMoreSegments - 1;
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kTimeShiftBufferDepthDuration =
|
2017-12-14 21:58:53 +00:00
|
|
|
kDefaultTimeScale * kTimeShiftBufferDepth;
|
|
|
|
AddSegments(first_s_element_end_time, kTimeShiftBufferDepthDuration, kSize,
|
|
|
|
kMoreSegmentsRepeat);
|
|
|
|
|
|
|
|
// Expect only the latest S element with 2 segments.
|
|
|
|
const std::string expected_s_element =
|
2023-12-01 17:32:19 +00:00
|
|
|
absl::StrFormat(kSElementTemplate, first_s_element_end_time,
|
|
|
|
kTimeShiftBufferDepthDuration, kMoreSegmentsRepeat);
|
2017-12-14 21:58:53 +00:00
|
|
|
|
|
|
|
const int kExpectedRemovedSegments = kRepeat + 1;
|
|
|
|
EXPECT_THAT(
|
2020-11-10 00:32:58 +00:00
|
|
|
representation_->GetXml(),
|
2017-12-14 21:58:53 +00:00
|
|
|
XmlNodeEqual(ExpectedXml(
|
|
|
|
expected_s_element, kDefaultStartNumber + kExpectedRemovedSegments)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// More than 1 S element in the result.
|
|
|
|
// Adds 100 one-second segments. Then add 21 two-second segments.
|
|
|
|
// This should have all of the two-second segments and 60 one-second
|
|
|
|
// segments. Note that it expects 60 segments from the first S element because
|
|
|
|
// the most recent segment added does not count
|
2017-09-25 19:18:50 +00:00
|
|
|
TEST_P(TimeShiftBufferDepthTest, MoreThanOneS) {
|
2017-12-14 21:58:53 +00:00
|
|
|
const int kTimeShiftBufferDepth = 100;
|
|
|
|
mutable_mpd_options()->mpd_params.time_shift_buffer_depth =
|
|
|
|
kTimeShiftBufferDepth;
|
|
|
|
|
2019-03-22 00:12:30 +00:00
|
|
|
const int kSize = 20000;
|
2017-12-14 21:58:53 +00:00
|
|
|
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kOneSecondDuration = kDefaultTimeScale;
|
2019-03-22 00:12:30 +00:00
|
|
|
const int kOneSecondSegmentRepeat = 99;
|
2017-09-25 19:18:50 +00:00
|
|
|
AddSegments(initial_start_time_, kOneSecondDuration, kSize,
|
2017-12-14 21:58:53 +00:00
|
|
|
kOneSecondSegmentRepeat);
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t first_s_element_end_time =
|
2017-09-25 19:18:50 +00:00
|
|
|
initial_start_time_ + kOneSecondDuration * (kOneSecondSegmentRepeat + 1);
|
2017-12-14 21:58:53 +00:00
|
|
|
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kTwoSecondDuration = 2 * kDefaultTimeScale;
|
2019-03-22 00:12:30 +00:00
|
|
|
const int kTwoSecondSegmentRepeat = 20;
|
2017-12-14 21:58:53 +00:00
|
|
|
AddSegments(first_s_element_end_time, kTwoSecondDuration, kSize,
|
|
|
|
kTwoSecondSegmentRepeat);
|
|
|
|
|
2019-03-22 00:12:30 +00:00
|
|
|
const int kExpectedRemovedSegments =
|
2017-12-14 21:58:53 +00:00
|
|
|
(kOneSecondSegmentRepeat + 1 + kTwoSecondSegmentRepeat * 2) -
|
|
|
|
kTimeShiftBufferDepth;
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
std::string expected_s_element = absl::StrFormat(
|
2017-09-25 19:18:50 +00:00
|
|
|
kSElementTemplate,
|
|
|
|
initial_start_time_ + kOneSecondDuration * kExpectedRemovedSegments,
|
2017-12-14 21:58:53 +00:00
|
|
|
kOneSecondDuration, kOneSecondSegmentRepeat - kExpectedRemovedSegments);
|
|
|
|
expected_s_element +=
|
2023-12-01 17:32:19 +00:00
|
|
|
absl::StrFormat(kSElementTemplate, first_s_element_end_time,
|
|
|
|
kTwoSecondDuration, kTwoSecondSegmentRepeat);
|
2017-12-14 21:58:53 +00:00
|
|
|
|
|
|
|
EXPECT_THAT(
|
2020-11-10 00:32:58 +00:00
|
|
|
representation_->GetXml(),
|
2017-12-14 21:58:53 +00:00
|
|
|
XmlNodeEqual(ExpectedXml(
|
|
|
|
expected_s_element, kDefaultStartNumber + kExpectedRemovedSegments)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Edge case where the last segment in S element should still be in the MPD.
|
|
|
|
// Example:
|
|
|
|
// Assuming timescale = 1 so that duration of 1 means 1 second.
|
|
|
|
// TimeShiftBufferDepth is 9 sec and we currently have
|
|
|
|
// <S t=0 d=1.5 r=1 />
|
|
|
|
// <S t=3 d=2 r=3 />
|
|
|
|
// and we add another contiguous 2 second segment.
|
|
|
|
// Then the first S element's last segment should still be in the MPD.
|
2017-09-25 19:18:50 +00:00
|
|
|
TEST_P(TimeShiftBufferDepthTest, UseLastSegmentInS) {
|
2017-12-14 21:58:53 +00:00
|
|
|
const int kTimeShiftBufferDepth = 9;
|
|
|
|
mutable_mpd_options()->mpd_params.time_shift_buffer_depth =
|
|
|
|
kTimeShiftBufferDepth;
|
|
|
|
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kDuration1 = static_cast<int64_t>(kDefaultTimeScale * 1.5);
|
2019-03-22 00:12:30 +00:00
|
|
|
const int kSize = 20000;
|
|
|
|
const int kRepeat1 = 1;
|
2017-12-14 21:58:53 +00:00
|
|
|
|
2017-09-25 19:18:50 +00:00
|
|
|
AddSegments(initial_start_time_, kDuration1, kSize, kRepeat1);
|
2017-12-14 21:58:53 +00:00
|
|
|
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t first_s_element_end_time =
|
2017-09-25 19:18:50 +00:00
|
|
|
initial_start_time_ + kDuration1 * (kRepeat1 + 1);
|
2017-12-14 21:58:53 +00:00
|
|
|
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kTwoSecondDuration = 2 * kDefaultTimeScale;
|
2019-03-22 00:12:30 +00:00
|
|
|
const int kTwoSecondSegmentRepeat = 4;
|
2017-12-14 21:58:53 +00:00
|
|
|
|
|
|
|
AddSegments(first_s_element_end_time, kTwoSecondDuration, kSize,
|
|
|
|
kTwoSecondSegmentRepeat);
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
std::string expected_s_element = absl::StrFormat(
|
2017-12-14 21:58:53 +00:00
|
|
|
kSElementTemplateWithoutR,
|
2017-09-25 19:18:50 +00:00
|
|
|
initial_start_time_ + kDuration1, // Expect one segment removed.
|
2017-12-14 21:58:53 +00:00
|
|
|
kDuration1);
|
|
|
|
|
|
|
|
expected_s_element +=
|
2023-12-01 17:32:19 +00:00
|
|
|
absl::StrFormat(kSElementTemplate, first_s_element_end_time,
|
|
|
|
kTwoSecondDuration, kTwoSecondSegmentRepeat);
|
2020-11-10 00:32:58 +00:00
|
|
|
EXPECT_THAT(representation_->GetXml(),
|
2017-12-14 21:58:53 +00:00
|
|
|
XmlNodeEqual(ExpectedXml(expected_s_element, 2)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gap between S elements but both should be included.
|
2017-09-25 19:18:50 +00:00
|
|
|
TEST_P(TimeShiftBufferDepthTest, NormalGap) {
|
2017-12-14 21:58:53 +00:00
|
|
|
const int kTimeShiftBufferDepth = 10;
|
|
|
|
mutable_mpd_options()->mpd_params.time_shift_buffer_depth =
|
|
|
|
kTimeShiftBufferDepth;
|
|
|
|
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kDuration = kDefaultTimeScale;
|
2019-03-22 00:12:30 +00:00
|
|
|
const int kSize = 20000;
|
|
|
|
const int kRepeat = 6;
|
2017-12-14 21:58:53 +00:00
|
|
|
// CHECK here so that the when next S element is added with 1 segment, this S
|
|
|
|
// element doesn't go away.
|
|
|
|
CHECK_LT(kRepeat - 1u, static_cast<uint64_t>(kTimeShiftBufferDepth));
|
|
|
|
CHECK_EQ(kDuration, kDefaultTimeScale);
|
|
|
|
|
2017-09-25 19:18:50 +00:00
|
|
|
AddSegments(initial_start_time_, kDuration, kSize, kRepeat);
|
2017-12-14 21:58:53 +00:00
|
|
|
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t first_s_element_end_time =
|
2017-09-25 19:18:50 +00:00
|
|
|
initial_start_time_ + kDuration * (kRepeat + 1);
|
2017-12-14 21:58:53 +00:00
|
|
|
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t gap_s_element_start_time = first_s_element_end_time + 1;
|
2017-12-14 21:58:53 +00:00
|
|
|
AddSegments(gap_s_element_start_time, kDuration, kSize, /* no repeat */ 0);
|
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
std::string expected_s_element = absl::StrFormat(
|
2017-09-25 19:18:50 +00:00
|
|
|
kSElementTemplate, initial_start_time_, kDuration, kRepeat);
|
2023-12-01 17:32:19 +00:00
|
|
|
expected_s_element += absl::StrFormat(kSElementTemplateWithoutR,
|
|
|
|
gap_s_element_start_time, kDuration);
|
2017-12-14 21:58:53 +00:00
|
|
|
|
|
|
|
EXPECT_THAT(
|
2020-11-10 00:32:58 +00:00
|
|
|
representation_->GetXml(),
|
2017-12-14 21:58:53 +00:00
|
|
|
XmlNodeEqual(ExpectedXml(expected_s_element, kDefaultStartNumber)));
|
|
|
|
}
|
|
|
|
|
2019-03-22 00:12:30 +00:00
|
|
|
// Timeshift is based on segment duration not on segment time.
|
2017-09-25 19:18:50 +00:00
|
|
|
TEST_P(TimeShiftBufferDepthTest, HugeGap) {
|
2017-12-14 21:58:53 +00:00
|
|
|
const int kTimeShiftBufferDepth = 10;
|
|
|
|
mutable_mpd_options()->mpd_params.time_shift_buffer_depth =
|
|
|
|
kTimeShiftBufferDepth;
|
|
|
|
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kDuration = kDefaultTimeScale;
|
2019-03-22 00:12:30 +00:00
|
|
|
const int kSize = 20000;
|
|
|
|
const int kRepeat = 6;
|
2017-09-25 19:18:50 +00:00
|
|
|
AddSegments(initial_start_time_, kDuration, kSize, kRepeat);
|
2017-12-14 21:58:53 +00:00
|
|
|
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t first_s_element_end_time =
|
2017-09-25 19:18:50 +00:00
|
|
|
initial_start_time_ + kDuration * (kRepeat + 1);
|
2017-12-14 21:58:53 +00:00
|
|
|
|
|
|
|
// Big enough gap so first S element should not be there.
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t gap_s_element_start_time =
|
2017-12-14 21:58:53 +00:00
|
|
|
first_s_element_end_time +
|
|
|
|
(kTimeShiftBufferDepth + 1) * kDefaultTimeScale;
|
2019-03-22 00:12:30 +00:00
|
|
|
const int kSecondSElementRepeat = 9;
|
2017-12-14 21:58:53 +00:00
|
|
|
static_assert(
|
2018-06-22 01:14:34 +00:00
|
|
|
kSecondSElementRepeat < static_cast<int64_t>(kTimeShiftBufferDepth),
|
2017-12-14 21:58:53 +00:00
|
|
|
"second_s_element_repeat_must_be_less_than_time_shift_buffer_depth");
|
|
|
|
AddSegments(gap_s_element_start_time, kDuration, kSize,
|
|
|
|
kSecondSElementRepeat);
|
|
|
|
|
|
|
|
std::string expected_s_element =
|
2023-12-01 17:32:19 +00:00
|
|
|
absl::StrFormat(kSElementTemplateWithoutR,
|
|
|
|
initial_start_time_ + kRepeat * kDuration, kDuration) +
|
|
|
|
absl::StrFormat(kSElementTemplate, gap_s_element_start_time, kDuration,
|
|
|
|
kSecondSElementRepeat);
|
2019-03-22 00:12:30 +00:00
|
|
|
const int kExpectedRemovedSegments = kRepeat;
|
2017-12-14 21:58:53 +00:00
|
|
|
EXPECT_THAT(
|
2020-11-10 00:32:58 +00:00
|
|
|
representation_->GetXml(),
|
2017-12-14 21:58:53 +00:00
|
|
|
XmlNodeEqual(ExpectedXml(
|
|
|
|
expected_s_element, kDefaultStartNumber + kExpectedRemovedSegments)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if startNumber is working correctly.
|
2017-09-25 19:18:50 +00:00
|
|
|
TEST_P(TimeShiftBufferDepthTest, ManySegments) {
|
2017-12-14 21:58:53 +00:00
|
|
|
const int kTimeShiftBufferDepth = 1;
|
|
|
|
mutable_mpd_options()->mpd_params.time_shift_buffer_depth =
|
|
|
|
kTimeShiftBufferDepth;
|
|
|
|
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kDuration = kDefaultTimeScale;
|
2019-03-22 00:12:30 +00:00
|
|
|
const int kSize = 20000;
|
|
|
|
const int kRepeat = 10000;
|
|
|
|
const int kTotalNumSegments = kRepeat + 1;
|
2017-09-25 19:18:50 +00:00
|
|
|
AddSegments(initial_start_time_, kDuration, kSize, kRepeat);
|
2017-12-14 21:58:53 +00:00
|
|
|
|
|
|
|
const int kExpectedSegmentsLeft = kTimeShiftBufferDepth + 1;
|
|
|
|
const int kExpectedSegmentsRepeat = kExpectedSegmentsLeft - 1;
|
|
|
|
const int kExpectedRemovedSegments =
|
|
|
|
kTotalNumSegments - kExpectedSegmentsLeft;
|
2017-09-25 19:18:50 +00:00
|
|
|
const int kExpectedStartNumber =
|
|
|
|
kDefaultStartNumber + kExpectedRemovedSegments;
|
2017-12-14 21:58:53 +00:00
|
|
|
|
2023-12-01 17:32:19 +00:00
|
|
|
std::string expected_s_element = absl::StrFormat(
|
2017-09-25 19:18:50 +00:00
|
|
|
kSElementTemplate,
|
|
|
|
initial_start_time_ + kExpectedRemovedSegments * kDuration, kDuration,
|
2019-03-22 00:12:30 +00:00
|
|
|
kExpectedSegmentsRepeat);
|
2017-12-14 21:58:53 +00:00
|
|
|
EXPECT_THAT(
|
2020-11-10 00:32:58 +00:00
|
|
|
representation_->GetXml(),
|
2017-09-25 19:18:50 +00:00
|
|
|
XmlNodeEqual(ExpectedXml(expected_s_element, kExpectedStartNumber)));
|
2017-12-14 21:58:53 +00:00
|
|
|
}
|
|
|
|
|
2018-04-17 22:03:02 +00:00
|
|
|
INSTANTIATE_TEST_CASE_P(InitialStartTime,
|
|
|
|
TimeShiftBufferDepthTest,
|
|
|
|
Values(0, 1000));
|
2018-04-04 23:17:59 +00:00
|
|
|
|
2018-04-17 22:03:02 +00:00
|
|
|
namespace {
|
|
|
|
const int kTimeShiftBufferDepth = 2;
|
|
|
|
const int kNumPreservedSegmentsOutsideLiveWindow = 3;
|
|
|
|
const int kMaxNumSegmentsAvailable =
|
|
|
|
kTimeShiftBufferDepth + 1 + kNumPreservedSegmentsOutsideLiveWindow;
|
|
|
|
|
|
|
|
const char kSegmentTemplate[] = "memory://$Number$.mp4";
|
|
|
|
const char kSegmentTemplateUrl[] = "video/$Number$.mp4";
|
|
|
|
const char kStringPrintTemplate[] = "memory://%d.mp4";
|
|
|
|
|
2018-06-22 01:14:34 +00:00
|
|
|
const int64_t kInitialStartTime = 0;
|
|
|
|
const int64_t kDuration = kDefaultTimeScale;
|
2018-04-17 22:03:02 +00:00
|
|
|
const uint64_t kSize = 10;
|
|
|
|
const uint64_t kNoRepeat = 0;
|
|
|
|
} // namespace
|
2018-04-04 23:17:59 +00:00
|
|
|
|
2018-04-17 22:03:02 +00:00
|
|
|
class RepresentationDeleteSegmentsTest : public SegmentTimelineTestBase {
|
|
|
|
public:
|
|
|
|
void SetUp() override {
|
|
|
|
SegmentTimelineTestBase::SetUp();
|
2018-04-04 23:17:59 +00:00
|
|
|
|
2018-04-17 22:03:02 +00:00
|
|
|
// Create 100 files with the template.
|
|
|
|
for (int i = 1; i <= 100; ++i) {
|
2023-12-01 17:32:19 +00:00
|
|
|
File::WriteStringToFile(absl::StrFormat(kStringPrintTemplate, i).c_str(),
|
|
|
|
"dummy content");
|
2018-04-17 22:03:02 +00:00
|
|
|
}
|
2018-04-04 23:17:59 +00:00
|
|
|
|
2018-04-17 22:03:02 +00:00
|
|
|
MediaInfo media_info = ConvertToMediaInfo(GetDefaultMediaInfo());
|
|
|
|
media_info.set_segment_template(kSegmentTemplate);
|
|
|
|
media_info.set_segment_template_url(kSegmentTemplateUrl);
|
|
|
|
representation_ =
|
|
|
|
CreateRepresentation(media_info, kAnyRepresentationId, NoListener());
|
|
|
|
ASSERT_TRUE(representation_->Init());
|
2018-04-04 23:17:59 +00:00
|
|
|
|
2018-04-17 22:03:02 +00:00
|
|
|
mpd_options_.mpd_params.time_shift_buffer_depth = kTimeShiftBufferDepth;
|
|
|
|
mpd_options_.mpd_params.preserved_segments_outside_live_window =
|
|
|
|
kNumPreservedSegmentsOutsideLiveWindow;
|
2018-04-04 23:17:59 +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;
|
|
|
|
}
|
|
|
|
};
|
2018-04-04 23:17:59 +00:00
|
|
|
|
2018-04-17 22:03:02 +00:00
|
|
|
// Verify that no segments are deleted initially until there are more than
|
|
|
|
// |kMaxNumSegmentsAvailable| segments.
|
|
|
|
TEST_F(RepresentationDeleteSegmentsTest, NoSegmentsDeletedInitially) {
|
|
|
|
for (int i = 0; i < kMaxNumSegmentsAvailable; ++i) {
|
|
|
|
AddSegments(kInitialStartTime + i * kDuration, kDuration, kSize, kNoRepeat);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < kMaxNumSegmentsAvailable; ++i) {
|
2023-12-01 17:32:19 +00:00
|
|
|
EXPECT_FALSE(SegmentDeleted(absl::StrFormat(kStringPrintTemplate, i + 1)));
|
2018-04-17 22:03:02 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-04 23:17:59 +00:00
|
|
|
|
2018-04-17 22:03:02 +00:00
|
|
|
TEST_F(RepresentationDeleteSegmentsTest, OneSegmentDeleted) {
|
|
|
|
for (int i = 0; i <= kMaxNumSegmentsAvailable; ++i) {
|
|
|
|
AddSegments(kInitialStartTime + i * kDuration, kDuration, kSize, kNoRepeat);
|
|
|
|
}
|
2023-12-01 17:32:19 +00:00
|
|
|
EXPECT_FALSE(SegmentDeleted(absl::StrFormat(kStringPrintTemplate, 2)));
|
|
|
|
EXPECT_TRUE(SegmentDeleted(absl::StrFormat(kStringPrintTemplate, 1)));
|
2018-04-17 22:03:02 +00:00
|
|
|
}
|
2018-04-04 23:17:59 +00:00
|
|
|
|
2018-04-17 22:03:02 +00:00
|
|
|
// Verify that segments are deleted as expected with many non-repeating
|
|
|
|
// segments.
|
|
|
|
TEST_F(RepresentationDeleteSegmentsTest, ManyNonRepeatingSegments) {
|
|
|
|
int many_segments = 50;
|
|
|
|
for (int i = 0; i < many_segments; ++i) {
|
|
|
|
AddSegments(kInitialStartTime + i * kDuration, kDuration, kSize, kNoRepeat);
|
|
|
|
}
|
|
|
|
const int last_available_segment_index =
|
|
|
|
many_segments - kMaxNumSegmentsAvailable + 1;
|
2018-04-04 23:17:59 +00:00
|
|
|
EXPECT_FALSE(SegmentDeleted(
|
2023-12-01 17:32:19 +00:00
|
|
|
absl::StrFormat(kStringPrintTemplate, last_available_segment_index)));
|
|
|
|
EXPECT_TRUE(SegmentDeleted(
|
|
|
|
absl::StrFormat(kStringPrintTemplate, last_available_segment_index - 1)));
|
2018-04-17 22:03:02 +00:00
|
|
|
}
|
2018-04-04 23:17:59 +00:00
|
|
|
|
2018-04-17 22:03:02 +00:00
|
|
|
// Verify that segments are deleted as expected with many repeating segments.
|
|
|
|
TEST_F(RepresentationDeleteSegmentsTest, ManyRepeatingSegments) {
|
|
|
|
const int kLoops = 4;
|
2019-03-22 00:12:30 +00:00
|
|
|
const int kRepeat = 10;
|
2018-04-17 22:03:02 +00:00
|
|
|
for (int i = 0; i < kLoops; ++i) {
|
|
|
|
AddSegments(kInitialStartTime + i * kDuration * (kRepeat + 1), kDuration,
|
|
|
|
kSize, kRepeat);
|
|
|
|
}
|
|
|
|
const int kNumSegments = kLoops * (kRepeat + 1);
|
|
|
|
const int last_available_segment_index =
|
|
|
|
kNumSegments - kMaxNumSegmentsAvailable + 1;
|
2018-04-04 23:17:59 +00:00
|
|
|
EXPECT_FALSE(SegmentDeleted(
|
2023-12-01 17:32:19 +00:00
|
|
|
absl::StrFormat(kStringPrintTemplate, last_available_segment_index)));
|
|
|
|
EXPECT_TRUE(SegmentDeleted(
|
|
|
|
absl::StrFormat(kStringPrintTemplate, last_available_segment_index - 1)));
|
2018-04-04 23:17:59 +00:00
|
|
|
}
|
|
|
|
|
2017-12-14 21:30:16 +00:00
|
|
|
} // namespace shaka
|