blob: 0e29375b2aae72f3ba31543508179876ec40f703 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "media/base/videocommon.h"
12#include "rtc_base/gunit.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
14namespace cricket {
15
16TEST(VideoCommonTest, TestCanonicalFourCC) {
17 // Canonical fourccs are not changed.
18 EXPECT_EQ(FOURCC_I420, CanonicalFourCC(FOURCC_I420));
19 // The special FOURCC_ANY value is not changed.
20 EXPECT_EQ(FOURCC_ANY, CanonicalFourCC(FOURCC_ANY));
21 // Aliases are translated to the canonical equivalent.
22 EXPECT_EQ(FOURCC_I420, CanonicalFourCC(FOURCC_IYUV));
23 EXPECT_EQ(FOURCC_I422, CanonicalFourCC(FOURCC_YU16));
24 EXPECT_EQ(FOURCC_I444, CanonicalFourCC(FOURCC_YU24));
25 EXPECT_EQ(FOURCC_YUY2, CanonicalFourCC(FOURCC_YUYV));
26 EXPECT_EQ(FOURCC_YUY2, CanonicalFourCC(FOURCC_YUVS));
27 EXPECT_EQ(FOURCC_UYVY, CanonicalFourCC(FOURCC_HDYC));
28 EXPECT_EQ(FOURCC_UYVY, CanonicalFourCC(FOURCC_2VUY));
29 EXPECT_EQ(FOURCC_MJPG, CanonicalFourCC(FOURCC_JPEG));
30 EXPECT_EQ(FOURCC_MJPG, CanonicalFourCC(FOURCC_DMB1));
31 EXPECT_EQ(FOURCC_BGGR, CanonicalFourCC(FOURCC_BA81));
32 EXPECT_EQ(FOURCC_RAW, CanonicalFourCC(FOURCC_RGB3));
33 EXPECT_EQ(FOURCC_24BG, CanonicalFourCC(FOURCC_BGR3));
34 EXPECT_EQ(FOURCC_BGRA, CanonicalFourCC(FOURCC_CM32));
35 EXPECT_EQ(FOURCC_RAW, CanonicalFourCC(FOURCC_CM24));
36}
37
38// Test conversion between interval and fps
39TEST(VideoCommonTest, TestVideoFormatFps) {
40 EXPECT_EQ(VideoFormat::kMinimumInterval, VideoFormat::FpsToInterval(0));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000041 EXPECT_EQ(rtc::kNumNanosecsPerSec / 20, VideoFormat::FpsToInterval(20));
42 EXPECT_EQ(20, VideoFormat::IntervalToFps(rtc::kNumNanosecsPerSec / 20));
henrike@webrtc.org18e59112014-03-14 17:19:38 +000043 EXPECT_EQ(0, VideoFormat::IntervalToFps(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044}
45
46// Test IsSize0x0
47TEST(VideoCommonTest, TestVideoFormatIsSize0x0) {
48 VideoFormat format;
49 EXPECT_TRUE(format.IsSize0x0());
50 format.width = 320;
51 EXPECT_FALSE(format.IsSize0x0());
52}
53
54// Test ToString: print fourcc when it is printable.
55TEST(VideoCommonTest, TestVideoFormatToString) {
56 VideoFormat format;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000057 EXPECT_EQ("0x0x0", format.ToString());
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058
59 format.fourcc = FOURCC_I420;
60 format.width = 640;
61 format.height = 480;
62 format.interval = VideoFormat::FpsToInterval(20);
63 EXPECT_EQ("I420 640x480x20", format.ToString());
64
65 format.fourcc = FOURCC_ANY;
66 format.width = 640;
67 format.height = 480;
68 format.interval = VideoFormat::FpsToInterval(20);
69 EXPECT_EQ("640x480x20", format.ToString());
70}
71
72// Test comparison.
73TEST(VideoCommonTest, TestVideoFormatCompare) {
74 VideoFormat format(640, 480, VideoFormat::FpsToInterval(20), FOURCC_I420);
75 VideoFormat format2;
76 EXPECT_NE(format, format2);
77
78 // Same pixelrate, different fourcc.
79 format2 = format;
80 format2.fourcc = FOURCC_YUY2;
81 EXPECT_NE(format, format2);
82 EXPECT_FALSE(format.IsPixelRateLess(format2) ||
83 format2.IsPixelRateLess(format2));
84
85 format2 = format;
86 format2.interval /= 2;
87 EXPECT_TRUE(format.IsPixelRateLess(format2));
88
89 format2 = format;
90 format2.width *= 2;
91 EXPECT_TRUE(format.IsPixelRateLess(format2));
92}
93
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094} // namespace cricket