tor-browser

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

internal_encoder_factory_unittest.cc (5296B)


      1 /*
      2 *  Copyright (c) 2021 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/engine/internal_encoder_factory.h"
     12 
     13 #include <memory>
     14 #include <optional>
     15 
     16 #include "api/environment/environment_factory.h"
     17 #include "api/video_codecs/sdp_video_format.h"
     18 #include "api/video_codecs/video_encoder.h"
     19 #include "api/video_codecs/video_encoder_factory.h"
     20 #include "media/base/media_constants.h"
     21 #include "test/gmock.h"
     22 #include "test/gtest.h"
     23 
     24 namespace webrtc {
     25 namespace {
     26 using ::testing::Contains;
     27 using ::testing::Field;
     28 using ::testing::Not;
     29 
     30 #ifdef RTC_ENABLE_VP9
     31 constexpr bool kVp9Enabled = true;
     32 #else
     33 constexpr bool kVp9Enabled = false;
     34 #endif
     35 #ifdef WEBRTC_USE_H264
     36 constexpr bool kH264Enabled = true;
     37 #else
     38 constexpr bool kH264Enabled = false;
     39 #endif
     40 constexpr bool kH265Enabled = false;
     41 
     42 constexpr VideoEncoderFactory::CodecSupport kSupported = {
     43    .is_supported = true,
     44    .is_power_efficient = false};
     45 constexpr VideoEncoderFactory::CodecSupport kUnsupported = {
     46    .is_supported = false,
     47    .is_power_efficient = false};
     48 
     49 MATCHER_P(Support, expected, "") {
     50  return arg.is_supported == expected.is_supported &&
     51         arg.is_power_efficient == expected.is_power_efficient;
     52 }
     53 
     54 TEST(InternalEncoderFactoryTest, Vp8) {
     55  InternalEncoderFactory factory;
     56  std::unique_ptr<VideoEncoder> encoder =
     57      factory.Create(CreateEnvironment(), SdpVideoFormat::VP8());
     58  EXPECT_TRUE(encoder);
     59 }
     60 
     61 TEST(InternalEncoderFactoryTest, Vp9Profile0) {
     62  InternalEncoderFactory factory;
     63  if (kVp9Enabled) {
     64    std::unique_ptr<VideoEncoder> encoder =
     65        factory.Create(CreateEnvironment(), SdpVideoFormat::VP9Profile0());
     66    EXPECT_TRUE(encoder);
     67  } else {
     68    EXPECT_THAT(factory.GetSupportedFormats(),
     69                Not(Contains(Field(&SdpVideoFormat::name, kVp9CodecName))));
     70  }
     71 }
     72 
     73 TEST(InternalEncoderFactoryTest, H264) {
     74  InternalEncoderFactory factory;
     75  if (kH264Enabled) {
     76    std::unique_ptr<VideoEncoder> encoder =
     77        factory.Create(CreateEnvironment(), SdpVideoFormat::H264());
     78    EXPECT_TRUE(encoder);
     79  } else {
     80    EXPECT_THAT(factory.GetSupportedFormats(),
     81                Not(Contains(Field(&SdpVideoFormat::name, kH264CodecName))));
     82  }
     83 }
     84 
     85 // At current stage H.265 is not supported by internal encoder factory.
     86 TEST(InternalEncoderFactoryTest, H265IsNotEnabled) {
     87  InternalEncoderFactory factory;
     88  std::unique_ptr<VideoEncoder> encoder =
     89      factory.Create(CreateEnvironment(), SdpVideoFormat(kH265CodecName));
     90  EXPECT_EQ(static_cast<bool>(encoder), kH265Enabled);
     91  EXPECT_THAT(factory.GetSupportedFormats(),
     92              Not(Contains(Field(&SdpVideoFormat::name, kH265CodecName))));
     93 }
     94 
     95 TEST(InternalEncoderFactoryTest, QueryCodecSupportWithScalabilityMode) {
     96  InternalEncoderFactory factory;
     97  // VP8 and VP9 supported for singles spatial layers.
     98  EXPECT_THAT(factory.QueryCodecSupport(SdpVideoFormat::VP8(), "L1T2"),
     99              Support(kSupported));
    100  EXPECT_THAT(factory.QueryCodecSupport(SdpVideoFormat::VP9Profile0(), "L1T3"),
    101              Support(kVp9Enabled ? kSupported : kUnsupported));
    102 
    103  // VP9 support for spatial layers.
    104  EXPECT_THAT(factory.QueryCodecSupport(SdpVideoFormat::VP9Profile0(), "L3T3"),
    105              Support(kVp9Enabled ? kSupported : kUnsupported));
    106 
    107  // Invalid scalability modes even though VP8 and H264 are supported.
    108  EXPECT_THAT(factory.QueryCodecSupport(SdpVideoFormat::H264(), "L2T2"),
    109              Support(kUnsupported));
    110  EXPECT_THAT(factory.QueryCodecSupport(SdpVideoFormat::VP8(), "L3T3"),
    111              Support(kUnsupported));
    112 }
    113 
    114 #if defined(RTC_USE_LIBAOM_AV1_ENCODER)
    115 TEST(InternalEncoderFactoryTest, Av1) {
    116  InternalEncoderFactory factory;
    117  EXPECT_THAT(factory.GetSupportedFormats(),
    118              Contains(Field(&SdpVideoFormat::name, kAv1CodecName)));
    119  EXPECT_TRUE(
    120      factory.Create(CreateEnvironment(), SdpVideoFormat::AV1Profile0()));
    121 }
    122 
    123 TEST(InternalEncoderFactoryTest, QueryCodecSupportNoScalabilityModeAv1) {
    124  InternalEncoderFactory factory;
    125  EXPECT_THAT(factory.QueryCodecSupport(SdpVideoFormat::AV1Profile0(),
    126                                        /*scalability_mode=*/std::nullopt),
    127              Support(kSupported));
    128 }
    129 
    130 TEST(InternalEncoderFactoryTest, QueryCodecSupportNoScalabilityMode) {
    131  InternalEncoderFactory factory;
    132  EXPECT_THAT(factory.QueryCodecSupport(SdpVideoFormat::VP8(),
    133                                        /*scalability_mode=*/std::nullopt),
    134              Support(kSupported));
    135  EXPECT_THAT(factory.QueryCodecSupport(SdpVideoFormat::VP9Profile0(),
    136                                        /*scalability_mode=*/std::nullopt),
    137              Support(kVp9Enabled ? kSupported : kUnsupported));
    138 }
    139 
    140 TEST(InternalEncoderFactoryTest, QueryCodecSupportWithScalabilityModeAv1) {
    141  InternalEncoderFactory factory;
    142  EXPECT_THAT(factory.QueryCodecSupport(SdpVideoFormat::AV1Profile0(), "L2T1"),
    143              Support(kSupported));
    144 }
    145 #endif  // defined(RTC_USE_LIBAOM_AV1_ENCODER)
    146 
    147 }  // namespace
    148 }  // namespace webrtc