mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 23:31:56 +00:00
Bug 1377015 - MediaCodecs::ContainsPrefix implementation and tests - r=rillian
Many video codecs use a suffix to specify level, profile and optional features, like "avc1.42E001" or "vp09.00.41.08". MediaCodecs::ContainsPrefix() can be used to facilitate codec identification from their prefix alone, e.g.: "avc1" or "vp09". MozReview-Commit-ID: D6kcjggXptS --HG-- extra : rebase_source : 3a60c01da1d91adf29f51ce3c32f8df60282c90a
This commit is contained in:
parent
9766f8a4eb
commit
7866e6fdb6
@ -107,6 +107,19 @@ MediaCodecs::ContainsAll(const MediaCodecs& aCodecs) const
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
MediaCodecs::ContainsPrefix(const nsAString& aCodecPrefix) const
|
||||
{
|
||||
const size_t prefixLength = aCodecPrefix.Length();
|
||||
for (const auto& myCodec : Range()) {
|
||||
if (myCodec.Length() >= prefixLength &&
|
||||
memcmp(myCodec.Data(), aCodecPrefix.Data(), prefixLength) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t
|
||||
MediaCodecs::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
|
||||
{
|
||||
|
@ -103,7 +103,7 @@ Maybe<MediaMIMEType> MakeMediaMIMEType(const nsACString& aType);
|
||||
Maybe<MediaMIMEType> MakeMediaMIMEType(const char* aType);
|
||||
|
||||
|
||||
// A list of codecs attached to a MediaExtendedMIMEType.
|
||||
// A list of case-sensitive codecs attached to a MediaExtendedMIMEType.
|
||||
class MediaCodecs
|
||||
{
|
||||
public:
|
||||
@ -132,9 +132,14 @@ public:
|
||||
return RangeType(mCodecs);
|
||||
};
|
||||
|
||||
// Does this list of codecs contain the given aCodec?
|
||||
bool Contains(const nsAString& aCodec) const;
|
||||
// Does this list of codecs contain *all* the codecs in the given list?
|
||||
bool ContainsAll(const MediaCodecs& aCodecs) const;
|
||||
|
||||
// Does this list of codecs contain a codec starting with the given prefix?
|
||||
bool ContainsPrefix(const nsAString& aCodecPrefix) const;
|
||||
|
||||
template <size_t N>
|
||||
bool operator==(const char (&aType)[N]) const
|
||||
{
|
||||
|
@ -94,6 +94,8 @@ TEST(MediaMIMETypes, MediaCodecs)
|
||||
EXPECT_TRUE(empty.AsString().EqualsLiteral(""));
|
||||
EXPECT_FALSE(empty.Contains(NS_LITERAL_STRING("")));
|
||||
EXPECT_FALSE(empty.Contains(NS_LITERAL_STRING("c1")));
|
||||
EXPECT_FALSE(empty.ContainsPrefix(NS_LITERAL_STRING("")));
|
||||
EXPECT_FALSE(empty.ContainsPrefix(NS_LITERAL_STRING("c1")));
|
||||
int iterations = 0;
|
||||
for (const auto& codec : empty.Range()) {
|
||||
++iterations;
|
||||
@ -106,6 +108,9 @@ TEST(MediaMIMETypes, MediaCodecs)
|
||||
EXPECT_TRUE(space.AsString().EqualsLiteral(" "));
|
||||
EXPECT_TRUE(space.Contains(NS_LITERAL_STRING("")));
|
||||
EXPECT_FALSE(space.Contains(NS_LITERAL_STRING("c1")));
|
||||
EXPECT_TRUE(space.ContainsPrefix(NS_LITERAL_STRING("")));
|
||||
EXPECT_FALSE(space.ContainsPrefix(NS_LITERAL_STRING("c")));
|
||||
EXPECT_FALSE(space.ContainsPrefix(NS_LITERAL_STRING("c1")));
|
||||
iterations = 0;
|
||||
for (const auto& codec : space.Range()) {
|
||||
++iterations;
|
||||
@ -118,6 +123,11 @@ TEST(MediaMIMETypes, MediaCodecs)
|
||||
EXPECT_TRUE(one.AsString().EqualsLiteral(" c1 "));
|
||||
EXPECT_FALSE(one.Contains(NS_LITERAL_STRING("")));
|
||||
EXPECT_TRUE(one.Contains(NS_LITERAL_STRING("c1")));
|
||||
EXPECT_TRUE(one.ContainsPrefix(NS_LITERAL_STRING("")));
|
||||
EXPECT_TRUE(one.ContainsPrefix(NS_LITERAL_STRING("c")));
|
||||
EXPECT_TRUE(one.ContainsPrefix(NS_LITERAL_STRING("c1")));
|
||||
EXPECT_FALSE(one.ContainsPrefix(NS_LITERAL_STRING("c1x")));
|
||||
EXPECT_FALSE(one.ContainsPrefix(NS_LITERAL_STRING("c1 ")));
|
||||
iterations = 0;
|
||||
for (const auto& codec : one.Range()) {
|
||||
++iterations;
|
||||
@ -131,6 +141,13 @@ TEST(MediaMIMETypes, MediaCodecs)
|
||||
EXPECT_FALSE(two.Contains(NS_LITERAL_STRING("")));
|
||||
EXPECT_TRUE(two.Contains(NS_LITERAL_STRING("c1")));
|
||||
EXPECT_TRUE(two.Contains(NS_LITERAL_STRING("c2")));
|
||||
EXPECT_TRUE(two.ContainsPrefix(NS_LITERAL_STRING("")));
|
||||
EXPECT_TRUE(two.ContainsPrefix(NS_LITERAL_STRING("c")));
|
||||
EXPECT_FALSE(two.ContainsPrefix(NS_LITERAL_STRING("1")));
|
||||
EXPECT_TRUE(two.ContainsPrefix(NS_LITERAL_STRING("c1")));
|
||||
EXPECT_TRUE(two.ContainsPrefix(NS_LITERAL_STRING("c2")));
|
||||
EXPECT_FALSE(two.ContainsPrefix(NS_LITERAL_STRING("c1x")));
|
||||
EXPECT_FALSE(two.ContainsPrefix(NS_LITERAL_STRING("c2x")));
|
||||
iterations = 0;
|
||||
for (const auto& codec : two.Range()) {
|
||||
++iterations;
|
||||
@ -229,6 +246,11 @@ TEST(MediaMIMETypes, MediaExtendedMIMEType)
|
||||
EXPECT_TRUE(type->Codecs() == "a,b");
|
||||
EXPECT_TRUE(type->Codecs().Contains(NS_LITERAL_STRING("a")));
|
||||
EXPECT_TRUE(type->Codecs().Contains(NS_LITERAL_STRING("b")));
|
||||
EXPECT_TRUE(type->Codecs().ContainsPrefix(NS_LITERAL_STRING("a")));
|
||||
EXPECT_TRUE(type->Codecs().ContainsPrefix(NS_LITERAL_STRING("b")));
|
||||
EXPECT_FALSE(type->Codecs().ContainsPrefix(NS_LITERAL_STRING("ab")));
|
||||
EXPECT_FALSE(type->Codecs().ContainsPrefix(NS_LITERAL_STRING("ba")));
|
||||
EXPECT_FALSE(type->Codecs().ContainsPrefix(NS_LITERAL_STRING("a,b")));
|
||||
EXPECT_TRUE(!!type->GetWidth());
|
||||
EXPECT_EQ(1024, *type->GetWidth());
|
||||
EXPECT_TRUE(!!type->GetHeight());
|
||||
|
Loading…
Reference in New Issue
Block a user