chromium/third_party/blink/renderer/platform/peerconnection/rtc_video_decoder_adapter_test.cc

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/platform/peerconnection/rtc_video_decoder_adapter.h"

#include <stdint.h>

#include <memory>
#include <utility>
#include <vector>

#include "base/check.h"
#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/task/sequenced_task_runner.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "media/base/decoder_status.h"
#include "media/base/media_switches.h"
#include "media/base/media_util.h"
#include "media/base/video_decoder.h"
#include "media/base/video_decoder_config.h"
#include "media/base/video_frame.h"
#include "media/base/video_types.h"
#include "media/video/mock_gpu_video_accelerator_factories.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/renderer/platform/peerconnection/resolution_monitor.h"
#include "third_party/blink/renderer/platform/webrtc/webrtc_video_utils.h"
#include "third_party/webrtc/api/video_codecs/video_codec.h"
#include "third_party/webrtc/api/video_codecs/vp9_profile.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"

_;
AtLeast;
DoAll;
Mock;
Return;
SaveArg;
StrictMock;

namespace blink {

namespace {

class FakeResolutionMonitor : public ResolutionMonitor {};

class MockVideoDecoder : public media::VideoDecoder {};

// Wraps a callback as a webrtc::DecodedImageCallback.
class DecodedImageCallback : public webrtc::DecodedImageCallback {};

class RTCVideoDecoderAdapterWrapper : public webrtc::VideoDecoder {};

}  // namespace

class RTCVideoDecoderAdapterTest : public ::testing::Test {};

TEST_F(RTCVideoDecoderAdapterTest, Create_UnknownFormat) {}

TEST_F(RTCVideoDecoderAdapterTest, Create_UnsupportedFormat) {}

TEST_F(RTCVideoDecoderAdapterTest, Lifecycle) {}

TEST_F(RTCVideoDecoderAdapterTest, InitializationFailure) {}

TEST_F(RTCVideoDecoderAdapterTest, Decode) {}

TEST_F(RTCVideoDecoderAdapterTest, Decode_Error) {}

TEST_F(RTCVideoDecoderAdapterTest, Decode_Hang_Short) {}

TEST_F(RTCVideoDecoderAdapterTest, Decode_Hang_Long) {}

TEST_F(RTCVideoDecoderAdapterTest, ReinitializesForHDRColorSpaceInitially) {}

TEST_F(RTCVideoDecoderAdapterTest, HandlesReinitializeFailure) {}

TEST_F(RTCVideoDecoderAdapterTest, HandlesFlushFailure) {}

TEST_F(RTCVideoDecoderAdapterTest, DecoderCountIsIncrementedByDecode) {}

TEST_F(RTCVideoDecoderAdapterTest, FallsBackForLowResolution) {}

#if BUILDFLAG(RTC_USE_H265)
TEST_F(RTCVideoDecoderAdapterTest, DoesNotFailForH256LowResolution) {
  // Make sure that low-resolution decode does not fail for H.265.
  SetSdpFormat(webrtc::SdpVideoFormat(
      webrtc::CodecTypeToPayloadString(webrtc::kVideoCodecH265)));
  ASSERT_TRUE(CreateAndInitialize(true, false));
  webrtc::VideoDecoder::Settings settings;
  settings.set_codec_type(webrtc::kVideoCodecH265);
  ASSERT_TRUE(adapter_wrapper_->Configure(settings));
  ASSERT_EQ(RegisterDecodeCompleteCallback(), WEBRTC_VIDEO_CODEC_OK);

  EXPECT_CALL(*video_decoder_, Decode_(_, _)).Times(1);

  ASSERT_EQ(Decode(0), WEBRTC_VIDEO_CODEC_OK);

  media_thread_.FlushForTesting();
}
#endif

TEST_F(RTCVideoDecoderAdapterTest, DoesNotFallBackForHighResolution) {}

TEST_F(RTCVideoDecoderAdapterTest, DecodesImageWithSingleSpatialLayer) {}

#if BUILDFLAG(IS_WIN)
TEST_F(RTCVideoDecoderAdapterTest, UseD3D11ToDecodeVP9kSVCStream) {
  video_decoder_->SetDecoderType(media::VideoDecoderType::kD3D11);
  ASSERT_TRUE(BasicSetup());
  SetSpatialIndex(2);
  EXPECT_CALL(*video_decoder_, Decode_(_, _))
      .WillOnce(
          base::test::RunOnceCallback<1>(media::DecoderStatus::Codes::kOk));

  ASSERT_EQ(Decode(0), WEBRTC_VIDEO_CODEC_OK);

  EXPECT_CALL(decoded_cb_, Run(_));
  FinishDecode(0);
  media_thread_.FlushForTesting();
}
#elif !(defined(ARCH_CPU_X86_FAMILY) && BUILDFLAG(IS_CHROMEOS))
// ChromeOS has the ability to decode VP9 kSVC Stream. Other cases should
// fallback to sw decoder.
TEST_F(RTCVideoDecoderAdapterTest,
       FallbackToSWSinceDecodeVP9kSVCStreamWithoutD3D11) {}
#endif  // BUILDFLAG(IS_WIN)

TEST_F(RTCVideoDecoderAdapterTest, FallbackToSWInAV1SVC) {}

}  // namespace blink