| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/limits.h" | 5 #include "media/base/limits.h" |
| 6 #include "media/base/media_util.h" | 6 #include "media/base/media_util.h" |
| 7 #include "media/base/video_decoder_config.h" | 7 #include "media/base/video_decoder_config.h" |
| 8 #include "media/base/video_util.h" | 8 #include "media/base/video_util.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace media { | 11 namespace media { |
| 12 | 12 |
| 13 static const VideoPixelFormat kVideoFormat = PIXEL_FORMAT_YV12; | 13 static const VideoPixelFormat kVideoFormat = PIXEL_FORMAT_YV12; |
| 14 static const gfx::Size kCodedSize(320, 240); | 14 static const gfx::Size kCodedSize(320, 240); |
| 15 static const gfx::Rect kVisibleRect(320, 240); | 15 static const gfx::Rect kVisibleRect(320, 240); |
| 16 static const gfx::Size kNaturalSize(320, 240); | 16 static const gfx::Size kNaturalSize(320, 240); |
| 17 | 17 |
| 18 TEST(VideoDecoderConfigTest, Invalid_UnsupportedPixelFormat) { | 18 TEST(VideoDecoderConfigTest, Invalid_UnsupportedPixelFormat) { |
| 19 VideoDecoderConfig config(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, | 19 VideoDecoderConfig config(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, |
| 20 PIXEL_FORMAT_UNKNOWN, COLOR_SPACE_UNSPECIFIED, | 20 PIXEL_FORMAT_UNKNOWN, COLOR_SPACE_UNSPECIFIED, |
| 21 kCodedSize, kVisibleRect, kNaturalSize, | 21 kCodedSize, kVisibleRect, kNaturalSize, |
| 22 EmptyExtraData(), false); | 22 EmptyExtraData(), EncryptionScheme::unencrypted()); |
| 23 EXPECT_FALSE(config.IsValidConfig()); | 23 EXPECT_FALSE(config.IsValidConfig()); |
| 24 } | 24 } |
| 25 | 25 |
| 26 TEST(VideoDecoderConfigTest, Invalid_AspectRatioNumeratorZero) { | 26 TEST(VideoDecoderConfigTest, Invalid_AspectRatioNumeratorZero) { |
| 27 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), 0, 1); | 27 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), 0, 1); |
| 28 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_ANY, kVideoFormat, | 28 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_ANY, kVideoFormat, |
| 29 COLOR_SPACE_UNSPECIFIED, kCodedSize, kVisibleRect, | 29 COLOR_SPACE_UNSPECIFIED, kCodedSize, kVisibleRect, |
| 30 natural_size, EmptyExtraData(), false); | 30 natural_size, EmptyExtraData(), |
| 31 EncryptionScheme::unencrypted()); |
| 31 EXPECT_FALSE(config.IsValidConfig()); | 32 EXPECT_FALSE(config.IsValidConfig()); |
| 32 } | 33 } |
| 33 | 34 |
| 34 TEST(VideoDecoderConfigTest, Invalid_AspectRatioDenominatorZero) { | 35 TEST(VideoDecoderConfigTest, Invalid_AspectRatioDenominatorZero) { |
| 35 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), 1, 0); | 36 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), 1, 0); |
| 36 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_ANY, kVideoFormat, | 37 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_ANY, kVideoFormat, |
| 37 COLOR_SPACE_UNSPECIFIED, kCodedSize, kVisibleRect, | 38 COLOR_SPACE_UNSPECIFIED, kCodedSize, kVisibleRect, |
| 38 natural_size, EmptyExtraData(), false); | 39 natural_size, EmptyExtraData(), |
| 40 EncryptionScheme::unencrypted()); |
| 39 EXPECT_FALSE(config.IsValidConfig()); | 41 EXPECT_FALSE(config.IsValidConfig()); |
| 40 } | 42 } |
| 41 | 43 |
| 42 TEST(VideoDecoderConfigTest, Invalid_AspectRatioNumeratorNegative) { | 44 TEST(VideoDecoderConfigTest, Invalid_AspectRatioNumeratorNegative) { |
| 43 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), -1, 1); | 45 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), -1, 1); |
| 44 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_ANY, kVideoFormat, | 46 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_ANY, kVideoFormat, |
| 45 COLOR_SPACE_UNSPECIFIED, kCodedSize, kVisibleRect, | 47 COLOR_SPACE_UNSPECIFIED, kCodedSize, kVisibleRect, |
| 46 natural_size, EmptyExtraData(), false); | 48 natural_size, EmptyExtraData(), |
| 49 EncryptionScheme::unencrypted()); |
| 47 EXPECT_FALSE(config.IsValidConfig()); | 50 EXPECT_FALSE(config.IsValidConfig()); |
| 48 } | 51 } |
| 49 | 52 |
| 50 TEST(VideoDecoderConfigTest, Invalid_AspectRatioDenominatorNegative) { | 53 TEST(VideoDecoderConfigTest, Invalid_AspectRatioDenominatorNegative) { |
| 51 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), 1, -1); | 54 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), 1, -1); |
| 52 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_ANY, kVideoFormat, | 55 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_ANY, kVideoFormat, |
| 53 COLOR_SPACE_UNSPECIFIED, kCodedSize, kVisibleRect, | 56 COLOR_SPACE_UNSPECIFIED, kCodedSize, kVisibleRect, |
| 54 natural_size, EmptyExtraData(), false); | 57 natural_size, EmptyExtraData(), |
| 58 EncryptionScheme::unencrypted()); |
| 55 EXPECT_FALSE(config.IsValidConfig()); | 59 EXPECT_FALSE(config.IsValidConfig()); |
| 56 } | 60 } |
| 57 | 61 |
| 58 TEST(VideoDecoderConfigTest, Invalid_AspectRatioNumeratorTooLarge) { | 62 TEST(VideoDecoderConfigTest, Invalid_AspectRatioNumeratorTooLarge) { |
| 59 int width = kVisibleRect.size().width(); | 63 int width = kVisibleRect.size().width(); |
| 60 int num = ceil(static_cast<double>(limits::kMaxDimension + 1) / width); | 64 int num = ceil(static_cast<double>(limits::kMaxDimension + 1) / width); |
| 61 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), num, 1); | 65 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), num, 1); |
| 62 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_ANY, kVideoFormat, | 66 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_ANY, kVideoFormat, |
| 63 COLOR_SPACE_UNSPECIFIED, kCodedSize, kVisibleRect, | 67 COLOR_SPACE_UNSPECIFIED, kCodedSize, kVisibleRect, |
| 64 natural_size, EmptyExtraData(), false); | 68 natural_size, EmptyExtraData(), |
| 69 EncryptionScheme::unencrypted()); |
| 65 EXPECT_FALSE(config.IsValidConfig()); | 70 EXPECT_FALSE(config.IsValidConfig()); |
| 66 } | 71 } |
| 67 | 72 |
| 68 TEST(VideoDecoderConfigTest, Invalid_AspectRatioDenominatorTooLarge) { | 73 TEST(VideoDecoderConfigTest, Invalid_AspectRatioDenominatorTooLarge) { |
| 69 // Denominator is large enough that the natural size height will be zero. | 74 // Denominator is large enough that the natural size height will be zero. |
| 70 int den = 2 * kVisibleRect.size().width() + 1; | 75 int den = 2 * kVisibleRect.size().width() + 1; |
| 71 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), 1, den); | 76 gfx::Size natural_size = GetNaturalSize(kVisibleRect.size(), 1, den); |
| 72 EXPECT_EQ(0, natural_size.width()); | 77 EXPECT_EQ(0, natural_size.width()); |
| 73 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_ANY, kVideoFormat, | 78 VideoDecoderConfig config(kCodecVP8, VP8PROFILE_ANY, kVideoFormat, |
| 74 COLOR_SPACE_UNSPECIFIED, kCodedSize, kVisibleRect, | 79 COLOR_SPACE_UNSPECIFIED, kCodedSize, kVisibleRect, |
| 75 natural_size, EmptyExtraData(), false); | 80 natural_size, EmptyExtraData(), |
| 81 EncryptionScheme::unencrypted()); |
| 76 EXPECT_FALSE(config.IsValidConfig()); | 82 EXPECT_FALSE(config.IsValidConfig()); |
| 77 } | 83 } |
| 78 | 84 |
| 79 } // namespace media | 85 } // namespace media |
| OLD | NEW |