blob: 3a943670fe61c019901a0fa4717e2f5626874fc5 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellander1afca732016-02-07 20:46:45 -08002 * Copyright (c) 2008 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellander1afca732016-02-07 20:46:45 -08004 * 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.org28e20752013-07-10 00:45:36 +00009 */
10
Steve Anton10542f22019-01-11 09:11:00 -080011#include "media/base/video_common.h"
Yves Gerey3e707812018-11-28 16:47:49 +010012
13#include "test/gtest.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000014
15namespace cricket {
16
17TEST(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
40TEST(VideoCommonTest, TestVideoFormatFps) {
41 EXPECT_EQ(VideoFormat::kMinimumInterval, VideoFormat::FpsToInterval(0));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000042 EXPECT_EQ(rtc::kNumNanosecsPerSec / 20, VideoFormat::FpsToInterval(20));
43 EXPECT_EQ(20, VideoFormat::IntervalToFps(rtc::kNumNanosecsPerSec / 20));
henrike@webrtc.org18e59112014-03-14 17:19:38 +000044 EXPECT_EQ(0, VideoFormat::IntervalToFps(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +000045}
46
47// Test IsSize0x0
48TEST(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.
56TEST(VideoCommonTest, TestVideoFormatToString) {
57 VideoFormat format;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000058 EXPECT_EQ("0x0x0", format.ToString());
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059
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.
74TEST(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.org28e20752013-07-10 00:45:36 +000095} // namespace cricket