2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2014 Google LLC. All rights reserved.
|
2014-05-14 23:19:35 +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
|
|
|
|
|
2014-08-21 22:40:44 +00:00
|
|
|
#include <gtest/gtest.h>
|
2014-05-14 23:19:35 +00:00
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/media/base/muxer_util.h"
|
2014-05-14 23:19:35 +00:00
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2014-05-14 23:19:35 +00:00
|
|
|
namespace media {
|
|
|
|
|
|
|
|
TEST(MuxerUtilTest, ValidateSegmentTemplate) {
|
2017-08-29 17:54:29 +00:00
|
|
|
EXPECT_NE(Status::OK, ValidateSegmentTemplate(""));
|
2014-05-14 23:19:35 +00:00
|
|
|
|
2017-08-29 17:54:29 +00:00
|
|
|
EXPECT_EQ(Status::OK, ValidateSegmentTemplate("$Number$"));
|
|
|
|
EXPECT_EQ(Status::OK, ValidateSegmentTemplate("$Time$"));
|
|
|
|
EXPECT_EQ(Status::OK, ValidateSegmentTemplate("$Time$$Time$"));
|
|
|
|
EXPECT_EQ(Status::OK, ValidateSegmentTemplate("foo$Time$goo"));
|
|
|
|
EXPECT_EQ(Status::OK, ValidateSegmentTemplate("$Number$_$Number$"));
|
|
|
|
EXPECT_EQ(Status::OK, ValidateSegmentTemplate("$Number$$Bandwidth$"));
|
|
|
|
EXPECT_EQ(Status::OK, ValidateSegmentTemplate("$Time$$Bandwidth$"));
|
2014-06-27 23:07:36 +00:00
|
|
|
|
|
|
|
// Bandwidth without Number or Time should not be valid.
|
2017-08-29 17:54:29 +00:00
|
|
|
EXPECT_NE(Status::OK, ValidateSegmentTemplate("$Bandwidth$"));
|
2014-05-14 23:19:35 +00:00
|
|
|
|
|
|
|
// Escape sequence "$$".
|
2017-08-29 17:54:29 +00:00
|
|
|
EXPECT_EQ(Status::OK, ValidateSegmentTemplate("foo$Time$__$$loo"));
|
|
|
|
EXPECT_EQ(Status::OK, ValidateSegmentTemplate("foo$Time$$$"));
|
|
|
|
EXPECT_EQ(Status::OK, ValidateSegmentTemplate("$$$Time$$$"));
|
2014-05-14 23:19:35 +00:00
|
|
|
|
|
|
|
// Missing $Number$ / $Time$.
|
2017-08-29 17:54:29 +00:00
|
|
|
EXPECT_NE(Status::OK, ValidateSegmentTemplate("$$"));
|
|
|
|
EXPECT_NE(Status::OK, ValidateSegmentTemplate("foo$$goo"));
|
2014-05-14 23:19:35 +00:00
|
|
|
|
|
|
|
// $Number$, $Time$ should not co-exist.
|
2017-08-29 17:54:29 +00:00
|
|
|
EXPECT_NE(Status::OK, ValidateSegmentTemplate("$Number$$Time$"));
|
|
|
|
EXPECT_NE(Status::OK, ValidateSegmentTemplate("foo$Number$_$Time$loo"));
|
2014-05-14 23:19:35 +00:00
|
|
|
|
2014-06-27 23:07:36 +00:00
|
|
|
// $RepresentationID$ not implemented yet.
|
2017-08-29 17:54:29 +00:00
|
|
|
EXPECT_NE(Status::OK, ValidateSegmentTemplate("$RepresentationID$__$Time$"));
|
2014-05-14 23:19:35 +00:00
|
|
|
|
|
|
|
// Unknown identifier.
|
2017-08-29 17:54:29 +00:00
|
|
|
EXPECT_NE(Status::OK, ValidateSegmentTemplate("$foo$$Time$"));
|
2014-05-14 23:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MuxerUtilTest, ValidateSegmentTemplateWithFormatTag) {
|
2017-08-29 17:54:29 +00:00
|
|
|
EXPECT_EQ(Status::OK, ValidateSegmentTemplate("$Time%01d$"));
|
|
|
|
EXPECT_EQ(Status::OK, ValidateSegmentTemplate("$Time%05d$"));
|
|
|
|
EXPECT_NE(Status::OK, ValidateSegmentTemplate("$Time%1d$"));
|
|
|
|
EXPECT_NE(Status::OK, ValidateSegmentTemplate("$Time%$"));
|
|
|
|
EXPECT_NE(Status::OK, ValidateSegmentTemplate("$Time%01$"));
|
|
|
|
EXPECT_NE(Status::OK, ValidateSegmentTemplate("$Time%0xd$"));
|
|
|
|
EXPECT_NE(Status::OK, ValidateSegmentTemplate("$Time%03xd$"));
|
2014-05-14 23:19:35 +00:00
|
|
|
// $$ should not have any format tag.
|
2017-08-29 17:54:29 +00:00
|
|
|
EXPECT_NE(Status::OK, ValidateSegmentTemplate("$%01d$$Time$"));
|
2014-05-14 23:19:35 +00:00
|
|
|
// Format specifier edge cases.
|
2017-08-29 17:54:29 +00:00
|
|
|
EXPECT_EQ(Status::OK, ValidateSegmentTemplate("$Time%00d$"));
|
|
|
|
EXPECT_EQ(Status::OK, ValidateSegmentTemplate("$Time%005d$"));
|
2014-05-14 23:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MuxerUtilTest, GetSegmentName) {
|
2021-08-04 18:56:44 +00:00
|
|
|
const int64_t kSegmentStartTime = 180180;
|
2014-09-30 21:52:21 +00:00
|
|
|
const uint32_t kSegmentIndex = 11;
|
|
|
|
const uint32_t kBandwidth = 1234;
|
2014-06-27 23:07:36 +00:00
|
|
|
EXPECT_EQ("12", GetSegmentName("$Number$",
|
|
|
|
kSegmentStartTime,
|
|
|
|
kSegmentIndex,
|
|
|
|
kBandwidth));
|
2014-05-14 23:19:35 +00:00
|
|
|
EXPECT_EQ("012",
|
2014-06-27 23:07:36 +00:00
|
|
|
GetSegmentName("$Number%03d$",
|
|
|
|
kSegmentStartTime,
|
|
|
|
kSegmentIndex,
|
|
|
|
kBandwidth));
|
2014-05-14 23:19:35 +00:00
|
|
|
EXPECT_EQ(
|
|
|
|
"12$foo$00012",
|
|
|
|
GetSegmentName(
|
2014-06-27 23:07:36 +00:00
|
|
|
"$Number%01d$$$foo$$$Number%05d$",
|
|
|
|
kSegmentStartTime,
|
|
|
|
kSegmentIndex,
|
|
|
|
kBandwidth));
|
2014-05-14 23:19:35 +00:00
|
|
|
|
|
|
|
EXPECT_EQ("180180",
|
2014-06-27 23:07:36 +00:00
|
|
|
GetSegmentName("$Time$",
|
|
|
|
kSegmentStartTime,
|
|
|
|
kSegmentIndex,
|
|
|
|
kBandwidth));
|
2014-05-14 23:19:35 +00:00
|
|
|
EXPECT_EQ("foo$_$18018000180180.m4s",
|
|
|
|
GetSegmentName("foo$$_$$$Time%01d$$Time%08d$.m4s",
|
|
|
|
kSegmentStartTime,
|
2014-06-27 23:07:36 +00:00
|
|
|
kSegmentIndex,
|
|
|
|
kBandwidth));
|
|
|
|
|
|
|
|
// Combo values.
|
|
|
|
EXPECT_EQ("12-1234",
|
|
|
|
GetSegmentName("$Number$-$Bandwidth$",
|
|
|
|
kSegmentStartTime,
|
|
|
|
kSegmentIndex,
|
|
|
|
kBandwidth));
|
|
|
|
EXPECT_EQ("012-001234",
|
|
|
|
GetSegmentName("$Number%03d$-$Bandwidth%06d$",
|
|
|
|
kSegmentStartTime,
|
|
|
|
kSegmentIndex,
|
|
|
|
kBandwidth));
|
|
|
|
|
2014-05-14 23:19:35 +00:00
|
|
|
// Format specifier edge cases.
|
|
|
|
EXPECT_EQ("12",
|
2014-06-27 23:07:36 +00:00
|
|
|
GetSegmentName("$Number%00d$",
|
|
|
|
kSegmentStartTime,
|
|
|
|
kSegmentIndex,
|
|
|
|
kBandwidth));
|
2014-05-14 23:19:35 +00:00
|
|
|
EXPECT_EQ("00012",
|
2014-06-27 23:07:36 +00:00
|
|
|
GetSegmentName("$Number%005d$",
|
|
|
|
kSegmentStartTime,
|
|
|
|
kSegmentIndex,
|
|
|
|
kBandwidth));
|
2014-05-14 23:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MuxerUtilTest, GetSegmentNameWithIndexZero) {
|
2021-08-04 18:56:44 +00:00
|
|
|
const int64_t kSegmentStartTime = 0;
|
2014-09-30 21:52:21 +00:00
|
|
|
const uint32_t kSegmentIndex = 0;
|
|
|
|
const uint32_t kBandwidth = 0;
|
2014-06-27 23:07:36 +00:00
|
|
|
EXPECT_EQ("1", GetSegmentName("$Number$",
|
|
|
|
kSegmentStartTime,
|
|
|
|
kSegmentIndex,
|
|
|
|
kBandwidth));
|
2014-05-14 23:19:35 +00:00
|
|
|
EXPECT_EQ("001",
|
2014-06-27 23:07:36 +00:00
|
|
|
GetSegmentName("$Number%03d$",
|
|
|
|
kSegmentStartTime,
|
|
|
|
kSegmentIndex,
|
|
|
|
kBandwidth));
|
2014-05-14 23:19:35 +00:00
|
|
|
|
2014-06-27 23:07:36 +00:00
|
|
|
EXPECT_EQ("0", GetSegmentName("$Time$",
|
|
|
|
kSegmentStartTime,
|
|
|
|
kSegmentIndex,
|
|
|
|
kBandwidth));
|
2014-05-14 23:19:35 +00:00
|
|
|
EXPECT_EQ("00000000.m4s",
|
2014-06-27 23:07:36 +00:00
|
|
|
GetSegmentName("$Time%08d$.m4s",
|
|
|
|
kSegmentStartTime,
|
|
|
|
kSegmentIndex,
|
|
|
|
kBandwidth));
|
2014-05-14 23:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MuxerUtilTest, GetSegmentNameLargeTime) {
|
2021-08-04 18:56:44 +00:00
|
|
|
const int64_t kSegmentStartTime = 1601599839840ULL;
|
2014-09-30 21:52:21 +00:00
|
|
|
const uint32_t kSegmentIndex = 8888888;
|
|
|
|
const uint32_t kBandwidth = 444444;
|
2014-05-14 23:19:35 +00:00
|
|
|
EXPECT_EQ("1601599839840",
|
2014-06-27 23:07:36 +00:00
|
|
|
GetSegmentName("$Time$",
|
|
|
|
kSegmentStartTime,
|
|
|
|
kSegmentIndex,
|
|
|
|
kBandwidth));
|
2014-05-14 23:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|