1 /*
2 * Copyright (c) 2008 The WebRTC project authors. All Rights Reserved.
3 *
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.
9 */
10
11 #include "media/base/video_common.h"
12
13 #include "test/gtest.h"
14
15 namespace cricket {
16
TEST(VideoCommonTest,TestCanonicalFourCC)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
TEST(VideoCommonTest,TestVideoFormatFps)40 TEST(VideoCommonTest, TestVideoFormatFps) {
41 EXPECT_EQ(VideoFormat::kMinimumInterval, VideoFormat::FpsToInterval(0));
42 EXPECT_EQ(rtc::kNumNanosecsPerSec / 20, VideoFormat::FpsToInterval(20));
43 EXPECT_EQ(20, VideoFormat::IntervalToFps(rtc::kNumNanosecsPerSec / 20));
44 EXPECT_EQ(0, VideoFormat::IntervalToFps(0));
45 }
46
47 // Test IsSize0x0
TEST(VideoCommonTest,TestVideoFormatIsSize0x0)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.
TEST(VideoCommonTest,TestVideoFormatToString)56 TEST(VideoCommonTest, TestVideoFormatToString) {
57 VideoFormat format;
58 EXPECT_EQ("0x0x0", format.ToString());
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.
TEST(VideoCommonTest,TestVideoFormatCompare)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
TEST(VideoCommonTest,GreatestCommonDivisor)95 TEST(VideoCommonTest, GreatestCommonDivisor) {
96 EXPECT_EQ(GreatestCommonDivisor(0, 1000), 1000);
97 EXPECT_EQ(GreatestCommonDivisor(1, 1), 1);
98 EXPECT_EQ(GreatestCommonDivisor(8, 12), 4);
99 EXPECT_EQ(GreatestCommonDivisor(24, 54), 6);
100 }
101
TEST(VideoCommonTest,LeastCommonMultiple)102 TEST(VideoCommonTest, LeastCommonMultiple) {
103 EXPECT_EQ(LeastCommonMultiple(1, 1), 1);
104 EXPECT_EQ(LeastCommonMultiple(2, 3), 6);
105 EXPECT_EQ(LeastCommonMultiple(16, 32), 32);
106 }
107
108 } // namespace cricket
109