2014-05-14 23:19:35 +00:00
|
|
|
// Copyright 2014 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
|
|
|
|
|
2014-08-21 22:40:44 +00:00
|
|
|
#include <gtest/gtest.h>
|
2014-05-14 23:19:35 +00:00
|
|
|
|
2014-08-21 22:40:44 +00:00
|
|
|
#include "media/base/muxer_util.h"
|
2014-05-14 23:19:35 +00:00
|
|
|
|
2014-09-19 20:41:13 +00:00
|
|
|
namespace edash_packager {
|
2014-05-14 23:19:35 +00:00
|
|
|
namespace media {
|
|
|
|
|
|
|
|
TEST(MuxerUtilTest, ValidateSegmentTemplate) {
|
|
|
|
EXPECT_FALSE(ValidateSegmentTemplate(""));
|
|
|
|
|
|
|
|
EXPECT_TRUE(ValidateSegmentTemplate("$Number$"));
|
|
|
|
EXPECT_TRUE(ValidateSegmentTemplate("$Time$"));
|
|
|
|
EXPECT_TRUE(ValidateSegmentTemplate("$Time$$Time$"));
|
|
|
|
EXPECT_TRUE(ValidateSegmentTemplate("foo$Time$goo"));
|
|
|
|
EXPECT_TRUE(ValidateSegmentTemplate("$Number$_$Number$"));
|
2014-06-27 23:07:36 +00:00
|
|
|
EXPECT_TRUE(ValidateSegmentTemplate("$Number$$Bandwidth$"));
|
|
|
|
EXPECT_TRUE(ValidateSegmentTemplate("$Time$$Bandwidth$"));
|
|
|
|
|
|
|
|
// Bandwidth without Number or Time should not be valid.
|
|
|
|
EXPECT_FALSE(ValidateSegmentTemplate("$Bandwidth$"));
|
2014-05-14 23:19:35 +00:00
|
|
|
|
|
|
|
// Escape sequence "$$".
|
|
|
|
EXPECT_TRUE(ValidateSegmentTemplate("foo$Time$__$$loo"));
|
|
|
|
EXPECT_TRUE(ValidateSegmentTemplate("foo$Time$$$"));
|
|
|
|
EXPECT_TRUE(ValidateSegmentTemplate("$$$Time$$$"));
|
|
|
|
|
|
|
|
// Missing $Number$ / $Time$.
|
|
|
|
EXPECT_FALSE(ValidateSegmentTemplate("$$"));
|
|
|
|
EXPECT_FALSE(ValidateSegmentTemplate("foo$$goo"));
|
|
|
|
|
|
|
|
// $Number$, $Time$ should not co-exist.
|
|
|
|
EXPECT_FALSE(ValidateSegmentTemplate("$Number$$Time$"));
|
|
|
|
EXPECT_FALSE(ValidateSegmentTemplate("foo$Number$_$Time$loo"));
|
|
|
|
|
2014-06-27 23:07:36 +00:00
|
|
|
// $RepresentationID$ not implemented yet.
|
2014-05-14 23:19:35 +00:00
|
|
|
EXPECT_FALSE(ValidateSegmentTemplate("$RepresentationID$__$Time$"));
|
|
|
|
|
|
|
|
// Unknown identifier.
|
|
|
|
EXPECT_FALSE(ValidateSegmentTemplate("$foo$$Time$"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MuxerUtilTest, ValidateSegmentTemplateWithFormatTag) {
|
|
|
|
EXPECT_TRUE(ValidateSegmentTemplate("$Time%01d$"));
|
|
|
|
EXPECT_TRUE(ValidateSegmentTemplate("$Time%05d$"));
|
|
|
|
EXPECT_FALSE(ValidateSegmentTemplate("$Time%1d$"));
|
|
|
|
EXPECT_FALSE(ValidateSegmentTemplate("$Time%$"));
|
|
|
|
EXPECT_FALSE(ValidateSegmentTemplate("$Time%01$"));
|
|
|
|
EXPECT_FALSE(ValidateSegmentTemplate("$Time%0xd$"));
|
|
|
|
EXPECT_FALSE(ValidateSegmentTemplate("$Time%03xd$"));
|
|
|
|
// $$ should not have any format tag.
|
|
|
|
EXPECT_FALSE(ValidateSegmentTemplate("$%01d$$Time$"));
|
|
|
|
// Format specifier edge cases.
|
|
|
|
EXPECT_TRUE(ValidateSegmentTemplate("$Time%00d$"));
|
|
|
|
EXPECT_TRUE(ValidateSegmentTemplate("$Time%005d$"));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MuxerUtilTest, GetSegmentName) {
|
|
|
|
const uint64 kSegmentStartTime = 180180;
|
|
|
|
const uint32 kSegmentIndex = 11;
|
2014-06-27 23:07:36 +00:00
|
|
|
const uint32 kBandwidth = 1234;
|
|
|
|
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) {
|
|
|
|
const uint64 kSegmentStartTime = 0;
|
|
|
|
const uint32 kSegmentIndex = 0;
|
2014-06-27 23:07:36 +00:00
|
|
|
const uint32 kBandwidth = 0;
|
|
|
|
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) {
|
2014-06-26 00:56:04 +00:00
|
|
|
const uint64 kSegmentStartTime = 1601599839840ULL;
|
2014-05-14 23:19:35 +00:00
|
|
|
const uint32 kSegmentIndex = 8888888;
|
2014-06-27 23:07:36 +00:00
|
|
|
const uint32 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
|
2014-09-19 20:41:13 +00:00
|
|
|
} // namespace edash_packager
|