| OLD | NEW | 
|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "media/base/video_codecs.h" | 5 #include "media/base/video_codecs.h" | 
| 6 | 6 | 
|  | 7 #include <set> | 
|  | 8 | 
|  | 9 #include "base/logging.h" | 
| 7 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" | 
| 8 | 11 | 
| 9 namespace media { | 12 namespace media { | 
| 10 | 13 | 
|  | 14 TEST(ParseVP9CodecId, NewStyleVP9CodecIDs) { | 
|  | 15   VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN; | 
|  | 16   uint8_t level = 0; | 
|  | 17   gfx::ColorSpace::TransferID eotf = gfx::ColorSpace::TransferID::INVALID; | 
|  | 18 | 
|  | 19   // Old style is not subset of new style. | 
|  | 20   EXPECT_FALSE(ParseNewStyleVp9CodecID("vp8", &profile, &level, &eotf)); | 
|  | 21   EXPECT_FALSE(ParseNewStyleVp9CodecID("vp9", &profile, &level, &eotf)); | 
|  | 22 | 
|  | 23   // Parsing should fail when first 4 required fields are not provided. | 
|  | 24   EXPECT_FALSE(ParseNewStyleVp9CodecID("vp09", &profile, &level, &eotf)); | 
|  | 25   EXPECT_FALSE(ParseNewStyleVp9CodecID("vp09.00", &profile, &level, &eotf)); | 
|  | 26   EXPECT_FALSE(ParseNewStyleVp9CodecID("vp09.00.01", &profile, &level, &eotf)); | 
|  | 27 | 
|  | 28   // Expect success when all required fields supplied (and valid). | 
|  | 29   // TrnasferID not specified by string, should default to 709. | 
|  | 30   EXPECT_TRUE( | 
|  | 31       ParseNewStyleVp9CodecID("vp09.00.01.08", &profile, &level, &eotf)); | 
|  | 32   EXPECT_EQ(VP9PROFILE_PROFILE0, profile); | 
|  | 33   EXPECT_EQ(1, level); | 
|  | 34   EXPECT_EQ(gfx::ColorSpace::TransferID::BT709, eotf); | 
|  | 35 | 
|  | 36   // Verify profile's 1 and 2 parse correctly. | 
|  | 37   EXPECT_TRUE( | 
|  | 38       ParseNewStyleVp9CodecID("vp09.01.01.08", &profile, &level, &eotf)); | 
|  | 39   EXPECT_EQ(VP9PROFILE_PROFILE1, profile); | 
|  | 40   EXPECT_TRUE( | 
|  | 41       ParseNewStyleVp9CodecID("vp09.02.01.08", &profile, &level, &eotf)); | 
|  | 42   EXPECT_EQ(VP9PROFILE_PROFILE2, profile); | 
|  | 43   EXPECT_TRUE( | 
|  | 44       ParseNewStyleVp9CodecID("vp09.03.01.08", &profile, &level, &eotf)); | 
|  | 45   EXPECT_EQ(VP9PROFILE_PROFILE3, profile); | 
|  | 46   // Profile 4 is not a thing. | 
|  | 47   EXPECT_FALSE( | 
|  | 48       ParseNewStyleVp9CodecID("vp09.04.01.08", &profile, &level, &eotf)); | 
|  | 49 | 
|  | 50   // Verify valid levels parse correctly. | 
|  | 51   const std::set<int> kValidVp9Levels = {1,  2,  3,  4,  5,  6,  11, | 
|  | 52                                          21, 31, 41, 51, 52, 61, 62}; | 
|  | 53   size_t num_valid_levels = 0; | 
|  | 54   for (int i = 0; i < 99; ++i) { | 
|  | 55     // Write "i" as the level. | 
|  | 56     char codec_string[14]; | 
|  | 57     snprintf(codec_string, 14, "vp09.00.%02d.08", i); | 
|  | 58     if (kValidVp9Levels.find(i) != kValidVp9Levels.end()) { | 
|  | 59       EXPECT_TRUE( | 
|  | 60           ParseNewStyleVp9CodecID(codec_string, &profile, &level, &eotf)); | 
|  | 61       EXPECT_EQ(VP9PROFILE_PROFILE0, profile); | 
|  | 62       EXPECT_EQ(i, level); | 
|  | 63       EXPECT_EQ(gfx::ColorSpace::TransferID::BT709, eotf); | 
|  | 64       num_valid_levels++; | 
|  | 65     } else { | 
|  | 66       EXPECT_FALSE( | 
|  | 67           ParseNewStyleVp9CodecID(codec_string, &profile, &level, &eotf)); | 
|  | 68     } | 
|  | 69   } | 
|  | 70   EXPECT_EQ(kValidVp9Levels.size(), num_valid_levels); | 
|  | 71 | 
|  | 72   // Verify bitdepths. Only 8, 10, 12 are valid. | 
|  | 73   EXPECT_TRUE(ParseNewStyleVp9CodecID("vp09.02.01.8", &profile, &level, &eotf)); | 
|  | 74   EXPECT_TRUE( | 
|  | 75       ParseNewStyleVp9CodecID("vp09.02.01.10", &profile, &level, &eotf)); | 
|  | 76   EXPECT_TRUE( | 
|  | 77       ParseNewStyleVp9CodecID("vp09.02.01.12", &profile, &level, &eotf)); | 
|  | 78   EXPECT_FALSE( | 
|  | 79       ParseNewStyleVp9CodecID("vp09.02.01.13", &profile, &level, &eotf)); | 
|  | 80 | 
|  | 81   // Verify a few color profiles. | 
|  | 82   // BT709 | 
|  | 83   EXPECT_TRUE( | 
|  | 84       ParseNewStyleVp9CodecID("vp09.02.01.10.01", &profile, &level, &eotf)); | 
|  | 85   // BT2020 | 
|  | 86   EXPECT_TRUE( | 
|  | 87       ParseNewStyleVp9CodecID("vp09.02.01.10.09", &profile, &level, &eotf)); | 
|  | 88   // 0 is invalid. | 
|  | 89   EXPECT_FALSE( | 
|  | 90       ParseNewStyleVp9CodecID("vp09.02.01.10.00", &profile, &level, &eotf)); | 
|  | 91   // 23 - 255 are reserved. | 
|  | 92   EXPECT_FALSE( | 
|  | 93       ParseNewStyleVp9CodecID("vp09.02.01.10.23", &profile, &level, &eotf)); | 
|  | 94 | 
|  | 95   // Verify a few common EOTFs parse correctly. | 
|  | 96   EXPECT_TRUE( | 
|  | 97       ParseNewStyleVp9CodecID("vp09.02.01.10.01.01", &profile, &level, &eotf)); | 
|  | 98   EXPECT_EQ(gfx::ColorSpace::TransferID::BT709, eotf); | 
|  | 99   EXPECT_TRUE( | 
|  | 100       ParseNewStyleVp9CodecID("vp09.02.01.10.01.04", &profile, &level, &eotf)); | 
|  | 101   EXPECT_EQ(gfx::ColorSpace::TransferID::GAMMA22, eotf); | 
|  | 102   EXPECT_TRUE( | 
|  | 103       ParseNewStyleVp9CodecID("vp09.02.01.10.01.06", &profile, &level, &eotf)); | 
|  | 104   EXPECT_EQ(gfx::ColorSpace::TransferID::SMPTE170M, eotf); | 
|  | 105   EXPECT_TRUE( | 
|  | 106       ParseNewStyleVp9CodecID("vp09.02.01.10.01.14", &profile, &level, &eotf)); | 
|  | 107   EXPECT_EQ(gfx::ColorSpace::TransferID::BT2020_10, eotf); | 
|  | 108   EXPECT_TRUE( | 
|  | 109       ParseNewStyleVp9CodecID("vp09.02.01.12.01.15", &profile, &level, &eotf)); | 
|  | 110   EXPECT_EQ(gfx::ColorSpace::TransferID::BT2020_12, eotf); | 
|  | 111   EXPECT_TRUE( | 
|  | 112       ParseNewStyleVp9CodecID("vp09.02.01.10.01.13", &profile, &level, &eotf)); | 
|  | 113   EXPECT_EQ(gfx::ColorSpace::TransferID::IEC61966_2_1, eotf); | 
|  | 114   EXPECT_TRUE( | 
|  | 115       ParseNewStyleVp9CodecID("vp09.02.01.10.01.16", &profile, &level, &eotf)); | 
|  | 116   EXPECT_EQ(gfx::ColorSpace::TransferID::SMPTEST2084, eotf); | 
|  | 117   // Verify 0 and 3 are reserved EOTF values. | 
|  | 118   EXPECT_FALSE( | 
|  | 119       ParseNewStyleVp9CodecID("vp09.02.01.08.01.00", &profile, &level, &eotf)); | 
|  | 120   EXPECT_FALSE( | 
|  | 121       ParseNewStyleVp9CodecID("vp09.02.01.08.01.03", &profile, &level, &eotf)); | 
|  | 122 | 
|  | 123   // Verify a few matrix coefficients. | 
|  | 124   EXPECT_TRUE(ParseNewStyleVp9CodecID("vp09.02.01.10.01.01.00", &profile, | 
|  | 125                                       &level, &eotf)); | 
|  | 126   EXPECT_TRUE(ParseNewStyleVp9CodecID("vp09.02.01.10.01.01.01", &profile, | 
|  | 127                                       &level, &eotf)); | 
|  | 128   EXPECT_TRUE(ParseNewStyleVp9CodecID("vp09.02.01.10.01.01.10", &profile, | 
|  | 129                                       &level, &eotf)); | 
|  | 130   // Values 12 - 255 reserved. | 
|  | 131   EXPECT_FALSE(ParseNewStyleVp9CodecID("vp09.02.01.10.01.01.12", &profile, | 
|  | 132                                        &level, &eotf)); | 
|  | 133 | 
|  | 134   // Verify full range flag (boolean 0 or 1). | 
|  | 135   EXPECT_TRUE(ParseNewStyleVp9CodecID("vp09.02.01.10.01.01.01.00", &profile, | 
|  | 136                                       &level, &eotf)); | 
|  | 137   EXPECT_TRUE(ParseNewStyleVp9CodecID("vp09.02.01.10.01.01.01.01", &profile, | 
|  | 138                                       &level, &eotf)); | 
|  | 139   EXPECT_FALSE(ParseNewStyleVp9CodecID("vp09.02.01.10.01.01.01.02", &profile, | 
|  | 140                                        &level, &eotf)); | 
|  | 141 | 
|  | 142   // Verify chrome subsampling values. | 
|  | 143   EXPECT_TRUE(ParseNewStyleVp9CodecID("vp09.02.01.10.01.01.01.00.00", &profile, | 
|  | 144                                       &level, &eotf)); | 
|  | 145   EXPECT_TRUE(ParseNewStyleVp9CodecID("vp09.02.01.10.01.01.01.00.01", &profile, | 
|  | 146                                       &level, &eotf)); | 
|  | 147   EXPECT_TRUE(ParseNewStyleVp9CodecID("vp09.02.01.10.01.01.01.00.02", &profile, | 
|  | 148                                       &level, &eotf)); | 
|  | 149   EXPECT_TRUE(ParseNewStyleVp9CodecID("vp09.02.01.10.01.01.01.00.03", &profile, | 
|  | 150                                       &level, &eotf)); | 
|  | 151   // Values 4 - 7 are reserved. | 
|  | 152   EXPECT_FALSE(ParseNewStyleVp9CodecID("vp09.02.01.10.01.01.01.00.04", &profile, | 
|  | 153                                        &level, &eotf)); | 
|  | 154 } | 
|  | 155 | 
| 11 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 156 #if BUILDFLAG(ENABLE_HEVC_DEMUXING) | 
| 12 TEST(ParseHEVCCodecIdTest, InvalidHEVCCodecIds) { | 157 TEST(ParseHEVCCodecIdTest, InvalidHEVCCodecIds) { | 
| 13   VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN; | 158   VideoCodecProfile profile = VIDEO_CODEC_PROFILE_UNKNOWN; | 
| 14   uint8_t level_idc = 0; | 159   uint8_t level_idc = 0; | 
| 15 | 160 | 
| 16   // Both hev1 and hvc1 should be supported | 161   // Both hev1 and hvc1 should be supported | 
| 17   EXPECT_TRUE(ParseHEVCCodecId("hev1.1.6.L93.B0", &profile, &level_idc)); | 162   EXPECT_TRUE(ParseHEVCCodecId("hev1.1.6.L93.B0", &profile, &level_idc)); | 
| 18   EXPECT_EQ(profile, HEVCPROFILE_MAIN); | 163   EXPECT_EQ(profile, HEVCPROFILE_MAIN); | 
| 19   EXPECT_EQ(level_idc, 93); | 164   EXPECT_EQ(level_idc, 93); | 
| 20   EXPECT_TRUE(ParseHEVCCodecId("hvc1.1.6.L93.B0", &profile, &level_idc)); | 165   EXPECT_TRUE(ParseHEVCCodecId("hvc1.1.6.L93.B0", &profile, &level_idc)); | 
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 209   EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe.5.7", &profile, &level_id)); | 354   EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe.5.7", &profile, &level_id)); | 
| 210   EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe.5.7.", &profile, &level_id)); | 355   EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe.5.7.", &profile, &level_id)); | 
| 211   EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe.5.7..", &profile, &level_id)); | 356   EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe.5.7..", &profile, &level_id)); | 
| 212   EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe.5.7...", &profile, &level_id)); | 357   EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe.5.7...", &profile, &level_id)); | 
| 213   EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe..5", &profile, &level_id)); | 358   EXPECT_FALSE(ParseDolbyVisionCodecId("dvhe..5", &profile, &level_id)); | 
| 214 #endif | 359 #endif | 
| 215 } | 360 } | 
| 216 #endif | 361 #endif | 
| 217 | 362 | 
| 218 }  // namespace media | 363 }  // namespace media | 
| OLD | NEW | 
|---|