tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

video_common_unittest.cc (3309B)


      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 "rtc_base/time_utils.h"
     14 #include "test/gtest.h"
     15 
     16 namespace webrtc {
     17 
     18 TEST(VideoCommonTest, TestCanonicalFourCC) {
     19  // Canonical fourccs are not changed.
     20  EXPECT_EQ(FOURCC_I420, CanonicalFourCC(FOURCC_I420));
     21  // The special FOURCC_ANY value is not changed.
     22  EXPECT_EQ(FOURCC_ANY, CanonicalFourCC(FOURCC_ANY));
     23  // Aliases are translated to the canonical equivalent.
     24  EXPECT_EQ(FOURCC_I420, CanonicalFourCC(FOURCC_IYUV));
     25  EXPECT_EQ(FOURCC_I422, CanonicalFourCC(FOURCC_YU16));
     26  EXPECT_EQ(FOURCC_I444, CanonicalFourCC(FOURCC_YU24));
     27  EXPECT_EQ(FOURCC_YUY2, CanonicalFourCC(FOURCC_YUYV));
     28  EXPECT_EQ(FOURCC_YUY2, CanonicalFourCC(FOURCC_YUVS));
     29  EXPECT_EQ(FOURCC_UYVY, CanonicalFourCC(FOURCC_HDYC));
     30  EXPECT_EQ(FOURCC_UYVY, CanonicalFourCC(FOURCC_2VUY));
     31  EXPECT_EQ(FOURCC_MJPG, CanonicalFourCC(FOURCC_JPEG));
     32  EXPECT_EQ(FOURCC_MJPG, CanonicalFourCC(FOURCC_DMB1));
     33  EXPECT_EQ(FOURCC_BGGR, CanonicalFourCC(FOURCC_BA81));
     34  EXPECT_EQ(FOURCC_RAW, CanonicalFourCC(FOURCC_RGB3));
     35  EXPECT_EQ(FOURCC_24BG, CanonicalFourCC(FOURCC_BGR3));
     36  EXPECT_EQ(FOURCC_BGRA, CanonicalFourCC(FOURCC_CM32));
     37  EXPECT_EQ(FOURCC_RAW, CanonicalFourCC(FOURCC_CM24));
     38 }
     39 
     40 // Test conversion between interval and fps
     41 TEST(VideoCommonTest, TestVideoFormatFps) {
     42  EXPECT_EQ(VideoFormat::kMinimumInterval, VideoFormat::FpsToInterval(0));
     43  EXPECT_EQ(kNumNanosecsPerSec / 20, VideoFormat::FpsToInterval(20));
     44  EXPECT_EQ(20, VideoFormat::IntervalToFps(kNumNanosecsPerSec / 20));
     45  EXPECT_EQ(0, VideoFormat::IntervalToFps(0));
     46 }
     47 
     48 // Test IsSize0x0
     49 TEST(VideoCommonTest, TestVideoFormatIsSize0x0) {
     50  VideoFormat format;
     51  EXPECT_TRUE(format.IsSize0x0());
     52  format.width = 320;
     53  EXPECT_FALSE(format.IsSize0x0());
     54 }
     55 
     56 // Test ToString: print fourcc when it is printable.
     57 TEST(VideoCommonTest, TestVideoFormatToString) {
     58  VideoFormat format;
     59  EXPECT_EQ("0x0x0", format.ToString());
     60 
     61  format.fourcc = FOURCC_I420;
     62  format.width = 640;
     63  format.height = 480;
     64  format.interval = VideoFormat::FpsToInterval(20);
     65  EXPECT_EQ("I420 640x480x20", format.ToString());
     66 
     67  format.fourcc = FOURCC_ANY;
     68  format.width = 640;
     69  format.height = 480;
     70  format.interval = VideoFormat::FpsToInterval(20);
     71  EXPECT_EQ("640x480x20", format.ToString());
     72 }
     73 
     74 // Test comparison.
     75 TEST(VideoCommonTest, TestVideoFormatCompare) {
     76  VideoFormat format(640, 480, VideoFormat::FpsToInterval(20), FOURCC_I420);
     77  VideoFormat format2;
     78  EXPECT_NE(format, format2);
     79 
     80  // Same pixelrate, different fourcc.
     81  format2 = format;
     82  format2.fourcc = FOURCC_YUY2;
     83  EXPECT_NE(format, format2);
     84  EXPECT_FALSE(format.IsPixelRateLess(format2) ||
     85               format2.IsPixelRateLess(format2));
     86 
     87  format2 = format;
     88  format2.interval /= 2;
     89  EXPECT_TRUE(format.IsPixelRateLess(format2));
     90 
     91  format2 = format;
     92  format2.width *= 2;
     93  EXPECT_TRUE(format.IsPixelRateLess(format2));
     94 }
     95 
     96 }  // namespace webrtc