tor-browser

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

internal_decoder_factory_unittest.cc (6336B)


      1 /*
      2 *  Copyright (c) 2016 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_decoder_factory.h"
     12 
     13 #include <memory>
     14 
     15 #include "api/environment/environment.h"
     16 #include "api/environment/environment_factory.h"
     17 #include "api/video_codecs/sdp_video_format.h"
     18 #include "api/video_codecs/video_decoder.h"
     19 #include "api/video_codecs/video_decoder_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 #ifdef RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY
     41 constexpr bool kDav1dIsIncluded = true;
     42 #else
     43 constexpr bool kDav1dIsIncluded = false;
     44 #endif
     45 constexpr bool kH265Enabled = false;
     46 
     47 constexpr VideoDecoderFactory::CodecSupport kSupported = {
     48    .is_supported = true,
     49    .is_power_efficient = false};
     50 constexpr VideoDecoderFactory::CodecSupport kUnsupported = {
     51    .is_supported = false,
     52    .is_power_efficient = false};
     53 
     54 MATCHER_P(Support, expected, "") {
     55  return arg.is_supported == expected.is_supported &&
     56         arg.is_power_efficient == expected.is_power_efficient;
     57 }
     58 
     59 TEST(InternalDecoderFactoryTest, Vp8) {
     60  const Environment env = CreateEnvironment();
     61  InternalDecoderFactory factory;
     62  std::unique_ptr<VideoDecoder> decoder =
     63      factory.Create(env, SdpVideoFormat::VP8());
     64  EXPECT_TRUE(decoder);
     65 }
     66 
     67 TEST(InternalDecoderFactoryTest, Vp9Profile0) {
     68  const Environment env = CreateEnvironment();
     69  InternalDecoderFactory factory;
     70  std::unique_ptr<VideoDecoder> decoder =
     71      factory.Create(env, SdpVideoFormat::VP9Profile0());
     72  EXPECT_EQ(static_cast<bool>(decoder), kVp9Enabled);
     73 }
     74 
     75 TEST(InternalDecoderFactoryTest, Vp9Profile1) {
     76  const Environment env = CreateEnvironment();
     77  InternalDecoderFactory factory;
     78  std::unique_ptr<VideoDecoder> decoder =
     79      factory.Create(env, SdpVideoFormat::VP9Profile1());
     80  EXPECT_EQ(static_cast<bool>(decoder), kVp9Enabled);
     81 }
     82 
     83 TEST(InternalDecoderFactoryTest, H264) {
     84  const Environment env = CreateEnvironment();
     85  InternalDecoderFactory factory;
     86  std::unique_ptr<VideoDecoder> decoder =
     87      factory.Create(env, SdpVideoFormat::H264());
     88  EXPECT_EQ(static_cast<bool>(decoder), kH264Enabled);
     89 }
     90 
     91 TEST(InternalDecoderFactoryTest, Av1Profile0) {
     92  const Environment env = CreateEnvironment();
     93  InternalDecoderFactory factory;
     94  if (kDav1dIsIncluded) {
     95    EXPECT_THAT(factory.GetSupportedFormats(),
     96                Contains(Field(&SdpVideoFormat::name, kAv1CodecName)));
     97    EXPECT_TRUE(factory.Create(env, SdpVideoFormat::AV1Profile0()));
     98  } else {
     99    EXPECT_THAT(factory.GetSupportedFormats(),
    100                Not(Contains(Field(&SdpVideoFormat::name, kAv1CodecName))));
    101  }
    102 }
    103 
    104 // At current stage since internal H.265 decoder is not implemented,
    105 TEST(InternalDecoderFactoryTest, H265IsNotEnabled) {
    106  const Environment env = CreateEnvironment();
    107  InternalDecoderFactory factory;
    108  std::unique_ptr<VideoDecoder> decoder =
    109      factory.Create(env, SdpVideoFormat(kH265CodecName));
    110  EXPECT_EQ(static_cast<bool>(decoder), kH265Enabled);
    111 }
    112 
    113 #if defined(RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY)
    114 TEST(InternalDecoderFactoryTest, Av1) {
    115  InternalDecoderFactory factory;
    116  EXPECT_THAT(factory.GetSupportedFormats(),
    117              Contains(Field(&SdpVideoFormat::name, kAv1CodecName)));
    118 }
    119 #endif
    120 
    121 TEST(InternalDecoderFactoryTest, Av1Profile1_Dav1dDecoderTrialEnabled) {
    122  const Environment env = CreateEnvironment();
    123  InternalDecoderFactory factory;
    124  std::unique_ptr<VideoDecoder> decoder =
    125      factory.Create(env, SdpVideoFormat::AV1Profile1());
    126  EXPECT_EQ(static_cast<bool>(decoder), kDav1dIsIncluded);
    127 }
    128 
    129 TEST(InternalDecoderFactoryTest, QueryCodecSupportNoReferenceScaling) {
    130  InternalDecoderFactory factory;
    131  EXPECT_THAT(factory.QueryCodecSupport(SdpVideoFormat::VP8(),
    132                                        /*reference_scaling=*/false),
    133              Support(kSupported));
    134  EXPECT_THAT(factory.QueryCodecSupport(SdpVideoFormat::VP9Profile0(),
    135                                        /*reference_scaling=*/false),
    136              Support(kVp9Enabled ? kSupported : kUnsupported));
    137  EXPECT_THAT(factory.QueryCodecSupport(SdpVideoFormat::VP9Profile1(),
    138                                        /*reference_scaling=*/false),
    139              Support(kVp9Enabled ? kSupported : kUnsupported));
    140 
    141 #if defined(RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY)
    142  EXPECT_THAT(factory.QueryCodecSupport(SdpVideoFormat::AV1Profile0(),
    143                                        /*reference_scaling=*/false),
    144              Support(kSupported));
    145  EXPECT_THAT(factory.QueryCodecSupport(SdpVideoFormat::AV1Profile1(),
    146                                        /*reference_scaling=*/false),
    147              Support(kSupported));
    148 
    149 #endif
    150 }
    151 
    152 TEST(InternalDecoderFactoryTest, QueryCodecSupportReferenceScaling) {
    153  InternalDecoderFactory factory;
    154  // VP9 and AV1 support for spatial layers.
    155  EXPECT_THAT(factory.QueryCodecSupport(SdpVideoFormat::VP9Profile0(),
    156                                        /*reference_scaling=*/true),
    157              Support(kVp9Enabled ? kSupported : kUnsupported));
    158 #if defined(RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY)
    159  EXPECT_THAT(factory.QueryCodecSupport(SdpVideoFormat::AV1Profile0(),
    160                                        /*reference_scaling=*/true),
    161              Support(kSupported));
    162 #endif
    163 
    164  // Invalid config even though VP8 and H264 are supported.
    165  EXPECT_THAT(factory.QueryCodecSupport(SdpVideoFormat::H264(),
    166                                        /*reference_scaling=*/true),
    167              Support(kUnsupported));
    168  EXPECT_THAT(factory.QueryCodecSupport(SdpVideoFormat::VP8(),
    169                                        /*reference_scaling=*/true),
    170              Support(kUnsupported));
    171 }
    172 
    173 }  // namespace
    174 }  // namespace webrtc