henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 2 | * Copyright (c) 2008 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame^] | 11 | #include "media/base/video_common.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 12 | |
| 13 | #include "test/gtest.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 14 | |
| 15 | namespace cricket { |
| 16 | |
| 17 | TEST(VideoCommonTest, TestCanonicalFourCC) { |
| 18 | // Canonical fourccs are not changed. |
| 19 | EXPECT_EQ(FOURCC_I420, CanonicalFourCC(FOURCC_I420)); |
| 20 | // The special FOURCC_ANY value is not changed. |
| 21 | EXPECT_EQ(FOURCC_ANY, CanonicalFourCC(FOURCC_ANY)); |
| 22 | // Aliases are translated to the canonical equivalent. |
| 23 | EXPECT_EQ(FOURCC_I420, CanonicalFourCC(FOURCC_IYUV)); |
| 24 | EXPECT_EQ(FOURCC_I422, CanonicalFourCC(FOURCC_YU16)); |
| 25 | EXPECT_EQ(FOURCC_I444, CanonicalFourCC(FOURCC_YU24)); |
| 26 | EXPECT_EQ(FOURCC_YUY2, CanonicalFourCC(FOURCC_YUYV)); |
| 27 | EXPECT_EQ(FOURCC_YUY2, CanonicalFourCC(FOURCC_YUVS)); |
| 28 | EXPECT_EQ(FOURCC_UYVY, CanonicalFourCC(FOURCC_HDYC)); |
| 29 | EXPECT_EQ(FOURCC_UYVY, CanonicalFourCC(FOURCC_2VUY)); |
| 30 | EXPECT_EQ(FOURCC_MJPG, CanonicalFourCC(FOURCC_JPEG)); |
| 31 | EXPECT_EQ(FOURCC_MJPG, CanonicalFourCC(FOURCC_DMB1)); |
| 32 | EXPECT_EQ(FOURCC_BGGR, CanonicalFourCC(FOURCC_BA81)); |
| 33 | EXPECT_EQ(FOURCC_RAW, CanonicalFourCC(FOURCC_RGB3)); |
| 34 | EXPECT_EQ(FOURCC_24BG, CanonicalFourCC(FOURCC_BGR3)); |
| 35 | EXPECT_EQ(FOURCC_BGRA, CanonicalFourCC(FOURCC_CM32)); |
| 36 | EXPECT_EQ(FOURCC_RAW, CanonicalFourCC(FOURCC_CM24)); |
| 37 | } |
| 38 | |
| 39 | // Test conversion between interval and fps |
| 40 | TEST(VideoCommonTest, TestVideoFormatFps) { |
| 41 | EXPECT_EQ(VideoFormat::kMinimumInterval, VideoFormat::FpsToInterval(0)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 42 | EXPECT_EQ(rtc::kNumNanosecsPerSec / 20, VideoFormat::FpsToInterval(20)); |
| 43 | EXPECT_EQ(20, VideoFormat::IntervalToFps(rtc::kNumNanosecsPerSec / 20)); |
henrike@webrtc.org | 18e5911 | 2014-03-14 17:19:38 +0000 | [diff] [blame] | 44 | EXPECT_EQ(0, VideoFormat::IntervalToFps(0)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | // Test IsSize0x0 |
| 48 | TEST(VideoCommonTest, TestVideoFormatIsSize0x0) { |
| 49 | VideoFormat format; |
| 50 | EXPECT_TRUE(format.IsSize0x0()); |
| 51 | format.width = 320; |
| 52 | EXPECT_FALSE(format.IsSize0x0()); |
| 53 | } |
| 54 | |
| 55 | // Test ToString: print fourcc when it is printable. |
| 56 | TEST(VideoCommonTest, TestVideoFormatToString) { |
| 57 | VideoFormat format; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 58 | EXPECT_EQ("0x0x0", format.ToString()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 59 | |
| 60 | format.fourcc = FOURCC_I420; |
| 61 | format.width = 640; |
| 62 | format.height = 480; |
| 63 | format.interval = VideoFormat::FpsToInterval(20); |
| 64 | EXPECT_EQ("I420 640x480x20", format.ToString()); |
| 65 | |
| 66 | format.fourcc = FOURCC_ANY; |
| 67 | format.width = 640; |
| 68 | format.height = 480; |
| 69 | format.interval = VideoFormat::FpsToInterval(20); |
| 70 | EXPECT_EQ("640x480x20", format.ToString()); |
| 71 | } |
| 72 | |
| 73 | // Test comparison. |
| 74 | TEST(VideoCommonTest, TestVideoFormatCompare) { |
| 75 | VideoFormat format(640, 480, VideoFormat::FpsToInterval(20), FOURCC_I420); |
| 76 | VideoFormat format2; |
| 77 | EXPECT_NE(format, format2); |
| 78 | |
| 79 | // Same pixelrate, different fourcc. |
| 80 | format2 = format; |
| 81 | format2.fourcc = FOURCC_YUY2; |
| 82 | EXPECT_NE(format, format2); |
| 83 | EXPECT_FALSE(format.IsPixelRateLess(format2) || |
| 84 | format2.IsPixelRateLess(format2)); |
| 85 | |
| 86 | format2 = format; |
| 87 | format2.interval /= 2; |
| 88 | EXPECT_TRUE(format.IsPixelRateLess(format2)); |
| 89 | |
| 90 | format2 = format; |
| 91 | format2.width *= 2; |
| 92 | EXPECT_TRUE(format.IsPixelRateLess(format2)); |
| 93 | } |
| 94 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 95 | } // namespace cricket |