From 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:47:29 +0200 Subject: Adding upstream version 115.8.0esr. Signed-off-by: Daniel Baumann --- .../mediasource/gtest/TestContainerParser.cpp | 148 +++++++++++ .../gtest/TestExtractAV1CodecDetails.cpp | 290 +++++++++++++++++++++ .../gtest/TestExtractVPXCodecDetails.cpp | 141 ++++++++++ dom/media/mediasource/gtest/moz.build | 22 ++ 4 files changed, 601 insertions(+) create mode 100644 dom/media/mediasource/gtest/TestContainerParser.cpp create mode 100644 dom/media/mediasource/gtest/TestExtractAV1CodecDetails.cpp create mode 100644 dom/media/mediasource/gtest/TestExtractVPXCodecDetails.cpp create mode 100644 dom/media/mediasource/gtest/moz.build (limited to 'dom/media/mediasource/gtest') diff --git a/dom/media/mediasource/gtest/TestContainerParser.cpp b/dom/media/mediasource/gtest/TestContainerParser.cpp new file mode 100644 index 0000000000..dd5a87b64b --- /dev/null +++ b/dom/media/mediasource/gtest/TestContainerParser.cpp @@ -0,0 +1,148 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include +#include + +#include "ContainerParser.h" +#include "mozilla/ArrayUtils.h" +#include "mozilla/gtest/MozAssertions.h" + +using namespace mozilla; +using TimeUnit = mozilla::media::TimeUnit; + +TEST(ContainerParser, MIMETypes) +{ + const char* containerTypes[] = {"video/webm", "audio/webm", "video/mp4", + "audio/mp4", "audio/aac"}; + UniquePtr parser; + for (size_t i = 0; i < ArrayLength(containerTypes); ++i) { + Maybe containerType = + MakeMediaContainerType(containerTypes[i]); + ASSERT_TRUE(containerType.isSome()); + parser = ContainerParser::CreateForMIMEType(*containerType); + ASSERT_NE(parser, nullptr); + } +} + +already_AddRefed make_adts_header() { + const uint8_t test[] = {0xff, 0xf1, 0x50, 0x80, 0x03, 0x1f, 0xfc}; + RefPtr buffer(new MediaByteBuffer); + buffer->AppendElements(test, ArrayLength(test)); + return buffer.forget(); +} + +TEST(ContainerParser, ADTSHeader) +{ + UniquePtr parser; + parser = ContainerParser::CreateForMIMEType( + MediaContainerType(MEDIAMIMETYPE("audio/aac"))); + ASSERT_NE(parser, nullptr); + + // Audio data should have no gaps. + EXPECT_EQ(parser->GetRoundingError(), 0); + + // Test a valid header. + RefPtr header = make_adts_header(); + EXPECT_NS_SUCCEEDED(parser->IsInitSegmentPresent(MediaSpan(header))); + + // Test variations. + uint8_t save = header->ElementAt(1); + for (uint8_t i = 1; i < 3; ++i) { + // Set non-zero layer. + header->ReplaceElementAt(1, (header->ElementAt(1) & 0xf9) | (i << 1)); + EXPECT_FALSE(NS_SUCCEEDED(parser->IsInitSegmentPresent(MediaSpan(header)))) + << "Accepted non-zero layer in header."; + } + header->ReplaceElementAt(1, save); + save = header->ElementAt(2); + header->ReplaceElementAt(2, (header->ElementAt(2) & 0x3b) | (15 << 2)); + EXPECT_FALSE(NS_SUCCEEDED(parser->IsInitSegmentPresent(MediaSpan(header)))) + << "Accepted explicit frequency in header."; + header->ReplaceElementAt(2, save); + + // Test a short header. + header->SetLength(6); + EXPECT_FALSE(NS_SUCCEEDED(parser->IsInitSegmentPresent(MediaSpan(header)))) + << "Accepted too-short header."; + EXPECT_FALSE(NS_SUCCEEDED(parser->IsMediaSegmentPresent(MediaSpan(header)))) + << "Found media segment when there was just a partial header."; + + // Test a header with short data. + header = make_adts_header(); + header->AppendElements(1); + EXPECT_TRUE(NS_SUCCEEDED(parser->IsInitSegmentPresent(MediaSpan(header)))) + << "Rejected a valid header."; + EXPECT_TRUE(NS_SUCCEEDED(parser->IsMediaSegmentPresent(MediaSpan(header)))) + << "Rejected a one-byte media segment."; + + // Test parse results. + header = make_adts_header(); + EXPECT_FALSE(NS_SUCCEEDED(parser->IsMediaSegmentPresent(MediaSpan(header)))) + << "Found media segment when there was just a header."; + TimeUnit start; + TimeUnit end; + EXPECT_TRUE(NS_FAILED( + parser->ParseStartAndEndTimestamps(MediaSpan(header), start, end))); + + EXPECT_TRUE(parser->HasInitData()); + EXPECT_TRUE(parser->HasCompleteInitData()); + MediaByteBuffer* init = parser->InitData(); + ASSERT_NE(init, nullptr); + EXPECT_EQ(init->Length(), header->Length()); + + EXPECT_EQ(parser->InitSegmentRange(), + MediaByteRange(0, int64_t(header->Length()))); + // Media segment range should be empty here. + EXPECT_EQ(parser->MediaHeaderRange(), MediaByteRange()); + EXPECT_EQ(parser->MediaSegmentRange(), MediaByteRange()); +} + +TEST(ContainerParser, ADTSBlankMedia) +{ + UniquePtr parser; + parser = ContainerParser::CreateForMIMEType( + MediaContainerType(MEDIAMIMETYPE("audio/aac"))); + ASSERT_NE(parser, nullptr); + + // Audio data should have no gaps. + EXPECT_EQ(parser->GetRoundingError(), 0); + + // Test the header only. + RefPtr header = make_adts_header(); + EXPECT_NS_SUCCEEDED(parser->IsInitSegmentPresent(MediaSpan(header))); + + // Test with the correct length of (invalid) frame data. + size_t header_length = header->Length(); + size_t data_length = 24; + size_t frame_length = header_length + data_length; + header->AppendElements(data_length); + EXPECT_TRUE(NS_SUCCEEDED(parser->IsInitSegmentPresent(MediaSpan(header)))) + << "Rejected a valid header."; + EXPECT_TRUE(NS_SUCCEEDED(parser->IsMediaSegmentPresent(MediaSpan(header)))) + << "Rejected a full (but zeroed) media segment."; + TimeUnit start; + TimeUnit end; + // We don't report timestamps from ADTS. + EXPECT_TRUE(NS_FAILED( + parser->ParseStartAndEndTimestamps(MediaSpan(header), start, end))); + EXPECT_TRUE(start.IsZero()); + EXPECT_TRUE(end.IsZero()); + + // Verify the parser calculated header and packet data boundaries. + EXPECT_TRUE(parser->HasInitData()); + EXPECT_TRUE(parser->HasCompleteInitData()); + MediaByteBuffer* init = parser->InitData(); + ASSERT_NE(init, nullptr); + EXPECT_EQ(init->Length(), header_length) + << "Found incorrect init segment length."; + EXPECT_EQ(parser->InitSegmentRange(), + MediaByteRange(0, int64_t(header_length))); + // In ADTS the Media Header is the same as the Media Segment. + MediaByteRange expected_media = + MediaByteRange(int64_t(header_length), int64_t(frame_length)); + EXPECT_EQ(parser->MediaHeaderRange(), expected_media); + EXPECT_EQ(parser->MediaSegmentRange(), expected_media); +} diff --git a/dom/media/mediasource/gtest/TestExtractAV1CodecDetails.cpp b/dom/media/mediasource/gtest/TestExtractAV1CodecDetails.cpp new file mode 100644 index 0000000000..8683023204 --- /dev/null +++ b/dom/media/mediasource/gtest/TestExtractAV1CodecDetails.cpp @@ -0,0 +1,290 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include +#include + +#include "AOMDecoder.h" +#include "VideoUtils.h" + +namespace mozilla { +void PrintTo(const AOMDecoder::AV1SequenceInfo& aInfo, std::ostream* aStream) { + nsAutoCString formatted = nsAutoCString(); + formatted.AppendPrintf( + "av01.%01u.%02u%c.%02u.%01u.%01u%01u%01u.%02u.%02u.%02u.%01u (res: " + "%ux%u) operating points: [", + aInfo.mProfile, aInfo.mOperatingPoints[0].mLevel, + aInfo.mOperatingPoints[0].mTier == 1 ? 'H' : 'M', aInfo.mBitDepth, + aInfo.mMonochrome, aInfo.mSubsamplingX, aInfo.mSubsamplingY, + static_cast(aInfo.mChromaSamplePosition), + static_cast(aInfo.mColorSpace.mPrimaries), + static_cast(aInfo.mColorSpace.mTransfer), + static_cast(aInfo.mColorSpace.mMatrix), + static_cast(aInfo.mColorSpace.mRange), aInfo.mImage.Width(), + aInfo.mImage.Height()); + size_t opCount = aInfo.mOperatingPoints.Length(); + for (size_t i = 0; i < opCount; i++) { + const auto& op = aInfo.mOperatingPoints[i]; + formatted.AppendPrintf("{ layers: %x, level: %u, tier: %u }", op.mLayers, + op.mLevel, op.mTier); + if (i != opCount - 1) { + formatted.Append(", "); + } + } + formatted.Append("]"); + *aStream << formatted; +} +} // namespace mozilla + +using namespace mozilla; + +struct AV1TestData { + const char* mCodecParameterString; + const bool mExpectedValue; + const char* mComment; +}; + +TEST(ExtractAV1CodecDetails, TestInputData) +{ + AV1TestData tests[] = { + // Format is: + // av01.N.NN[MH].NN.B.BBN.NN.NN.NN.B + // where + // N = decimal digit + // [] = single character + // B = binary digit + // Field order: + // ... + // [.. + // ... + // .] + + // Format checks + {"av01.0.10M.08", true, "Minimum length"}, + {"av1.0.10M.08", false, "Invalid 4CC"}, + {"av01..10M.08", false, "Blank field"}, + {"av01.-1.10M.08", false, "Negative field"}, + {"av01.0.10M.8", false, "Missing leading zeros"}, + + // Field counts + {"av01", false, "0 of 4 required fields"}, + {"av01.0", false, "1 of 4 required fields"}, + {"av01.0.10", false, "2 of 4 required fields"}, + {"av01.0.10M", false, "3 of 4 required fields"}, + {"av01.0.10M.08.0", false, "5 fields, AV1 requires 4 or 10"}, + {"av01.0.10M.08.0.110.01.01.01", false, "9 fields, AV1 requires 4 or 10"}, + {"av01.0.10M.08.0.110.01.01.01.0", true, "Maximum fields"}, + {"av01.0.10M.08.0.110.01.01.01.0.0", false, "Too many fields"}, + + // "Comments" are allowed (unknown characters at the end of fields) + {"av01.0.10M.08this is ignored", true, "Minimum length with comment"}, + {"av01.0.10Mbad comment", false, "Comment before required field"}, + {"av01.0.10M.08.0.110.01.01.01.0also ignored", true, + "Maximum length with comment"}, + + // Begin field checks + + // -- Profile -- + // Main Profile (0) tested above + + // High Profile requires 4:4:4 chroma subsampling without monochrome + {"av01.1.10M.08", false, "High Profile (1) without parameters"}, + {"av01.1.10M.08.0.000.01.01.01.0", true, "High Profile (1)"}, + + // Professional requires either of: + // - 8bit or 10bit at 4:2:2 + // - 12bit at any subsampling + {"av01.2.10M.10.0.100.01.01.01.0", true, + "Professional Profile (2) 10-bit 4:2:2"}, + {"av01.2.10M.12.0.110.01.01.01.0", true, + "Professional Profile (2) 12-bit 4:2:0"}, + + {"av01.3.10M.12.0.000.01.01.01.0", false, "Invalid Profile 3"}, + + // -- Level -- + {"av01.0.00M.08", true, "Level 0 (2.1)"}, + // Level 4.2 (10) tested above + {"av01.0.14M.08", true, "Level 14 (5.2)"}, + {"av01.0.23M.08", true, "Level 23 (7.3)"}, + {"av01.0.24M.08", false, "Level 24 (Reserved)"}, + + // -- Tier -- + // Main tier tested above + {"av01.0.10H.08", true, "High tier"}, + + // -- Bit depth -- + // 8-bit tested above with Main and High Profiles + {"av01.0.10M.10", true, "Main 10-bit"}, + {"av01.1.10M.10.0.000.01.01.01.0", true, "High 10-bit"}, + {"av01.1.10M.12.0.000.01.01.01.0", false, "High 12-bit (Invalid)"}, + // Valid 12-bit tested for Professional Profile + + // -- Monochrome -- + // Monochrome off tested above + {"av01.0.10M.08.1.110.01.01.01.0", true, "Main 8-bit monochrome"}, + {"av01.1.10M.10.1.000.01.01.01.0", false, + "4:4:4 is incompatible with monochrome"}, + {"av01.2.10M.10.1.100.01.01.01.0", false, + "4:2:0 is incompatible with monochrome"}, + {"av01.2.10M.12.1.110.01.01.01.0", true, + "Professional 12-bit monochrome"}, + + // -- Chroma subsampling -- + // Field is parsed by digits + // where positions are [unknown, vertical, colocated] + {"av01.0.10M.08.0.112.01.01.01.0", true, "Chroma colocated"}, + // Main Profile, 4:2:0 tested above + {"av01.0.10M.08.0.100.01.01.01.0", false, + "4:2:2 not allowed on Main Profile"}, + // High Profile, 4:4:4 tested above + {"av01.1.10M.08.0.110.01.01.01.0", false, + "4:4:4 required on High Profile"}, + {"av01.2.10M.08.0.110.01.01.01.0", false, + "4:2:0 not allowed on 8-bit Professional"}, + // Professional Profile, 8-bit 4:2:2 tested above + // Professional Profile, 12-bit 4:2:0 tested above + {"av01.2.10M.12.0.100.01.01.01.0", true, "12-bit 4:2:2"}, + {"av01.2.10M.12.0.000.01.01.01.0", true, "12-bit 4:4:4"}, + + {"av01.2.10M.08.0.101.01.01.01.0", false, "Chroma position with 4:2:2"}, + {"av01.1.10M.08.0.001.01.01.01.0", false, "Chroma position with 4:4:4"}, + {"av01.0.10M.08.0.113.01.01.01.0", false, "Chroma position 3 (Reserved)"}, + + // -- Color primaries -- + // 0, 3, [13-21], >23 are reserved + // 1 (BT709) is tested above + {"av01.0.10M.10.0.110.09.16.09.0", true, + "Color space: BT2020/SMPTE2084/BT2020NCL"}, + {"av01.0.10M.10.0.110.00.16.09.0", false, "Primaries 0: Reserved"}, + {"av01.0.10M.10.0.110.03.16.09.0", false, "Primaries 3: Reserved"}, + {"av01.0.10M.10.0.110.13.16.09.0", false, "Primaries 13: Reserved"}, + {"av01.0.10M.10.0.110.21.16.09.0", false, "Primaries 21: Reserved"}, + {"av01.0.10M.10.0.110.22.16.09.0", true, "Primaries 22: EBU3213"}, + {"av01.0.10M.10.0.110.23.16.09.0", false, "Primaries 23: Reserved"}, + + // -- Transfer characteristics -- + // 0, 3, >19 are all reserved + // 1 (BT709) is tested above + // 16 (SMPTE2084) is tested above + {"av01.0.10M.10.0.110.09.14.09.0", true, + "Color space: BT2020/BT2020 10-bit/BT2020NCL"}, + {"av01.0.10M.10.0.110.09.00.09.0", false, "Transfer 0: Reserved"}, + {"av01.0.10M.10.0.110.09.03.09.0", false, "Transfer 3: Reserved"}, + {"av01.0.10M.10.0.110.09.20.09.0", false, "Transfer 20: Reserved"}, + + // -- Matrix coefficients -- + // 3, >15 are all reserved + // 1 (BT709) is tested above + // 9 (BT2020NCL) is tested above + {"av01.1.10M.10.0.000.01.13.00.1", true, "4:4:4 10-bit sRGB"}, + {"av01.1.10M.10.0.000.01.13.00.0", false, "sRGB requires full range"}, + {"av01.2.10M.10.0.100.01.13.00.1", false, + "Subsampling incompatible with sRGB"}, + {"av01.2.10M.12.0.000.01.13.00.1", true, "4:4:4 12-bit sRGB"}, + {"av01.2.10M.12.0.000.01.01.15.1", false, "Matrix 15: Reserved"}, + + // -- Color range -- + // Full range and limited range tested above + {"av01.0.10M.12.0.002.01.13.00.2", false, "Color range 2 invalid"}, + }; + + for (const auto& data : tests) { + auto info = AOMDecoder::CreateSequenceInfoFromCodecs( + NS_ConvertUTF8toUTF16(data.mCodecParameterString)); + nsAutoCString desc = nsAutoCString(data.mCodecParameterString, + strlen(data.mCodecParameterString)); + desc.AppendLiteral(" ("); + desc.Append(data.mComment, strlen(data.mComment)); + desc.AppendLiteral(")"); + EXPECT_EQ(info.isSome(), data.mExpectedValue) << desc; + + if (info.isSome()) { + AOMDecoder::AV1SequenceInfo inputInfo = info.value(); + inputInfo.mImage = gfx::IntSize(1920, 1080); + RefPtr buffer = new MediaByteBuffer(); + bool wroteSequenceHeader; + AOMDecoder::WriteAV1CBox(inputInfo, buffer, wroteSequenceHeader); + EXPECT_EQ(wroteSequenceHeader, data.mExpectedValue) << desc; + // Read equality test will fail also, don't clutter. + if (!wroteSequenceHeader) { + continue; + } + AOMDecoder::AV1SequenceInfo parsedInfo; + bool readSequenceHeader; + AOMDecoder::ReadAV1CBox(buffer, parsedInfo, readSequenceHeader); + EXPECT_EQ(wroteSequenceHeader, readSequenceHeader) << desc; + EXPECT_EQ(inputInfo, parsedInfo) << desc; + } + } +} + +TEST(ExtractAV1CodecDetails, TestParsingOutput) +{ + auto info = AOMDecoder::CreateSequenceInfoFromCodecs( + nsString(u"av01.0.14M.08.0.112.01.01.01.0")); + EXPECT_TRUE(info.isSome()); + + if (info.isSome()) { + EXPECT_EQ(info->mProfile, 0u); + EXPECT_EQ(info->mOperatingPoints.Length(), 1u); + EXPECT_EQ(info->mOperatingPoints[0].mLayers, 0u); + EXPECT_EQ(info->mOperatingPoints[0].mLevel, 14u); + EXPECT_EQ(info->mOperatingPoints[0].mTier, 0u); + EXPECT_EQ(info->mBitDepth, 8u); + EXPECT_EQ(info->mMonochrome, false); + EXPECT_EQ(info->mSubsamplingX, true); + EXPECT_EQ(info->mSubsamplingY, true); + EXPECT_EQ(info->mChromaSamplePosition, + AOMDecoder::ChromaSamplePosition::Colocated); + EXPECT_EQ(info->mColorSpace.mPrimaries, gfx::CICP::CP_BT709); + EXPECT_EQ(info->mColorSpace.mTransfer, gfx::CICP::TC_BT709); + EXPECT_EQ(info->mColorSpace.mMatrix, gfx::CICP::MC_BT709); + EXPECT_EQ(info->mColorSpace.mRange, gfx::ColorRange::LIMITED); + } + + info = AOMDecoder::CreateSequenceInfoFromCodecs( + nsString(u"av01.1.11H.10.0.000.07.07.07.1")); + EXPECT_TRUE(info.isSome()); + + if (info.isSome()) { + EXPECT_EQ(info->mProfile, 1u); + EXPECT_EQ(info->mOperatingPoints.Length(), 1u); + EXPECT_EQ(info->mOperatingPoints[0].mLayers, 0u); + EXPECT_EQ(info->mOperatingPoints[0].mLevel, 11u); + EXPECT_EQ(info->mOperatingPoints[0].mTier, 1u); + EXPECT_EQ(info->mBitDepth, 10u); + EXPECT_EQ(info->mMonochrome, false); + EXPECT_EQ(info->mSubsamplingX, false); + EXPECT_EQ(info->mSubsamplingY, false); + EXPECT_EQ(info->mChromaSamplePosition, + AOMDecoder::ChromaSamplePosition::Unknown); + EXPECT_EQ(info->mColorSpace.mPrimaries, gfx::CICP::CP_SMPTE240); + EXPECT_EQ(info->mColorSpace.mTransfer, gfx::CICP::TC_SMPTE240); + EXPECT_EQ(info->mColorSpace.mMatrix, gfx::CICP::MC_SMPTE240); + EXPECT_EQ(info->mColorSpace.mRange, gfx::ColorRange::FULL); + } + + info = AOMDecoder::CreateSequenceInfoFromCodecs( + nsString(u"av01.2.22H.12.1.110.10.08.04.1")); + EXPECT_TRUE(info.isSome()); + + if (info.isSome()) { + EXPECT_EQ(info->mProfile, 2u); + EXPECT_EQ(info->mOperatingPoints.Length(), 1u); + EXPECT_EQ(info->mOperatingPoints[0].mLayers, 0u); + EXPECT_EQ(info->mOperatingPoints[0].mLevel, 22u); + EXPECT_EQ(info->mOperatingPoints[0].mTier, 1u); + EXPECT_EQ(info->mBitDepth, 12u); + EXPECT_EQ(info->mMonochrome, true); + EXPECT_EQ(info->mSubsamplingX, true); + EXPECT_EQ(info->mSubsamplingY, true); + EXPECT_EQ(info->mChromaSamplePosition, + AOMDecoder::ChromaSamplePosition::Unknown); + EXPECT_EQ(info->mColorSpace.mPrimaries, gfx::CICP::CP_XYZ); + EXPECT_EQ(info->mColorSpace.mTransfer, gfx::CICP::TC_LINEAR); + EXPECT_EQ(info->mColorSpace.mMatrix, gfx::CICP::MC_FCC); + EXPECT_EQ(info->mColorSpace.mRange, gfx::ColorRange::FULL); + } +} diff --git a/dom/media/mediasource/gtest/TestExtractVPXCodecDetails.cpp b/dom/media/mediasource/gtest/TestExtractVPXCodecDetails.cpp new file mode 100644 index 0000000000..7e255e2dc7 --- /dev/null +++ b/dom/media/mediasource/gtest/TestExtractVPXCodecDetails.cpp @@ -0,0 +1,141 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include +#include + +#include "VideoUtils.h" + +using namespace mozilla; + +struct TestData { + const char16_t* const mCodecParameterString; + const bool mExpectedValue; + const char* const mComment; +}; + +TEST(ExtractVPXCodecDetails, TestInputData) +{ + TestData tests[] = { + // ..... + // ... + // + + // Format checks + {u"vp09.0.10.8", true, "Valid minimum length"}, + {u"vp9.00.10.08", false, "Invalid 4CC"}, + {u"vp09.00..08", false, "Blank field"}, + {u"vp09", false, "0 of 3 required fields"}, + {u"vp09.00", false, "1 of 3 required fields"}, + {u"vp09.00.10", false, "2 of 3 required fields"}, + + // Profiles + {u"vp09.00.10.08", true, "Profile 0"}, + {u"vp09.01.10.08", true, "Profile 1"}, + {u"vp09.02.10.10", true, "Profile 2"}, + {u"vp09.03.10.10", true, "Profile 3"}, + {u"vp09.-1.10.08", false, "Invalid profile < 0"}, + {u"vp09.04.10.08", false, "Invalid profile > 3"}, + + // Levels + {u"vp09.00.11.08", true, "Level 1.1"}, + {u"vp09.00.12.08", false, "Invalid level 1.2"}, + {u"vp09.00.52.08", true, "Level 5.2"}, + {u"vp09.00.64.08", false, "Level greater than max"}, + + // Bit depths + // - 8-bit tested in Profiles section + // - 10-bit tested in Profiles section + {u"vp09.02.10.12", true, "12-bit"}, + {u"vp09.00.10.07", false, "Invalid, 7-bit"}, + {u"vp09.02.10.11", false, "Invalid, 11-bit"}, + {u"vp09.02.10.13", false, "Invalid, 13-bit"}, + + // Chroma subsampling + {u"vp09.00.10.08.00", true, "4:2:0 vertical"}, + {u"vp09.00.10.08.01", true, "4:2:0 colocated"}, + {u"vp09.00.10.08.02", true, "4:2:2"}, + {u"vp09.00.10.08.03", true, "4:4:4"}, + {u"vp09.00.10.08.04", false, "Invalid chroma"}, + + // Color primaries + {u"vp09.00.10.08.01.00", false, "CP 0: Reserved"}, + {u"vp09.00.10.08.01.01", true, "CP 1: BT.709"}, + {u"vp09.00.10.08.01.03", false, "CP 3: Reserved"}, + {u"vp09.00.10.08.01.09", true, "CP 9: BT.2020"}, + {u"vp09.00.10.08.01.21", false, "CP 21: Reserved"}, + {u"vp09.00.10.08.01.22", true, "CP 22: EBU Tech 3213"}, + {u"vp09.00.10.08.01.23", false, "CP 23: Out of range"}, + + // Transfer characteristics + {u"vp09.00.10.08.01.01.00", false, "TC 0: Reserved"}, + {u"vp09.00.10.08.01.01.01", true, "TC 1: BT.709"}, + {u"vp09.00.10.08.01.01.03", false, "TC 3: Reserved"}, + {u"vp09.00.10.08.01.09.16", true, "TC 16: ST 2084"}, + {u"vp09.00.10.08.01.09.19", false, "TC 19: Out of range"}, + + // Matrix coefficients + {u"vp09.00.10.08.03.09.16.00", true, "MC 0: Identity"}, + {u"vp09.00.10.08.01.09.16.00", false, "MC 0: Identity without 4:4:4"}, + {u"vp09.00.10.08.01.09.16.01", true, "MC 1: BT.709"}, + {u"vp09.00.10.08.01.09.16.03", false, "MC 3: Reserved"}, + {u"vp09.00.10.08.01.09.16.09", true, "MC 9: BT.2020"}, + {u"vp09.00.10.08.01.09.16.15", false, "MC 15: Out of range"}, + + // Color range + {u"vp09.00.10.08.01.09.16.09.00", true, "Limited range"}, + {u"vp09.00.10.08.01.09.16.09.01", true, "Full range"}, + {u"vp09.00.10.08.01.09.16.09.02", false, "Invalid range value"}, + + {u"vp09.00.10.08.01.09.16.09.00.", false, "Extra ."}, + {u"vp09.00.10.08.01.09.16.09.00.00", false, "More than 9 fields"}, + }; + + for (const auto& data : tests) { + uint8_t profile = 0; + uint8_t level = 0; + uint8_t bitDepth = 0; + bool result = ExtractVPXCodecDetails(nsString(data.mCodecParameterString), + profile, level, bitDepth); + EXPECT_EQ(result, data.mExpectedValue) + << NS_ConvertUTF16toUTF8(data.mCodecParameterString).get() << " (" + << data.mComment << ")"; + } +} + +TEST(ExtractVPXCodecDetails, TestParsingOutput) +{ + uint8_t profile = 0; + uint8_t level = 0; + uint8_t bitDepth = 0; + uint8_t chromaSubsampling = 0; + VideoColorSpace colorSpace; + auto data = u"vp09.01.11.08"; + bool result = ExtractVPXCodecDetails(nsString(data), profile, level, bitDepth, + chromaSubsampling, colorSpace); + EXPECT_EQ(result, true); + EXPECT_EQ(profile, 1); + EXPECT_EQ(level, 11); + EXPECT_EQ(bitDepth, 8); + // Should keep spec defined default value. + EXPECT_EQ(chromaSubsampling, 1); + EXPECT_EQ(colorSpace.mPrimaries, gfx::CICP::CP_BT709); + EXPECT_EQ(colorSpace.mTransfer, gfx::CICP::TC_BT709); + EXPECT_EQ(colorSpace.mMatrix, gfx::CICP::MC_BT709); + EXPECT_EQ(colorSpace.mRange, gfx::ColorRange::LIMITED); + + data = u"vp09.02.10.10.01.09.16.09.01"; + result = ExtractVPXCodecDetails(nsString(data), profile, level, bitDepth, + chromaSubsampling, colorSpace); + EXPECT_EQ(result, true); + EXPECT_EQ(profile, 2); + EXPECT_EQ(level, 10); + EXPECT_EQ(bitDepth, 10); + EXPECT_EQ(chromaSubsampling, 1); + EXPECT_EQ(colorSpace.mPrimaries, gfx::CICP::CP_BT2020); + EXPECT_EQ(colorSpace.mTransfer, gfx::CICP::TC_SMPTE2084); + EXPECT_EQ(colorSpace.mMatrix, gfx::CICP::MC_BT2020_NCL); + EXPECT_EQ(colorSpace.mRange, gfx::ColorRange::FULL); +} diff --git a/dom/media/mediasource/gtest/moz.build b/dom/media/mediasource/gtest/moz.build new file mode 100644 index 0000000000..42ef6beb9b --- /dev/null +++ b/dom/media/mediasource/gtest/moz.build @@ -0,0 +1,22 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +UNIFIED_SOURCES += [ + "TestContainerParser.cpp", + "TestExtractVPXCodecDetails.cpp", +] + +if CONFIG["MOZ_AV1"]: + UNIFIED_SOURCES += [ + "TestExtractAV1CodecDetails.cpp", + ] + +LOCAL_INCLUDES += [ + "/dom/media", + "/dom/media/mediasource", +] + +FINAL_LIBRARY = "xul-gtest" -- cgit v1.2.3