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

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

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

#include <stdint.h>

#include "base/check.h"
#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.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_factory.h"
#include "media/base/decoder_status.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/renderer/platform/peerconnection/rtc_video_decoder_stream_adapter.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;
ReturnRef;
SaveArg;
StrictMock;

namespace blink {

namespace {

struct TestParams {};

class MockVideoDecoder : public media::VideoDecoder {};

class MockDecoderFactory : public media::DecoderFactory {};

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

}  // namespace

class RTCVideoDecoderStreamAdapterTest
    : public ::testing::TestWithParam<TestParams> {};

TEST_P(RTCVideoDecoderStreamAdapterTest, Create_UnknownFormat) {}

TEST_P(RTCVideoDecoderStreamAdapterTest, FailInitIfNoHwNorSwDecoders) {}

TEST_P(RTCVideoDecoderStreamAdapterTest, FailInit_DecodeFails) {}

TEST_P(RTCVideoDecoderStreamAdapterTest, UnsupportedGpuConfigFailsImmediately) {}

TEST_P(RTCVideoDecoderStreamAdapterTest, MissingFramesRequestsKeyframe) {}

TEST_P(RTCVideoDecoderStreamAdapterTest, DecodeOneFrame) {}

TEST_P(RTCVideoDecoderStreamAdapterTest, SlowDecodingCausesReset) {}

TEST_P(RTCVideoDecoderStreamAdapterTest, ReallySlowDecodingCausesFallback) {}

TEST_P(RTCVideoDecoderStreamAdapterTest, WontForwardFramesAfterRelease) {}

TEST_P(RTCVideoDecoderStreamAdapterTest, LowResSelectsCorrectDecoder) {}

#if BUILDFLAG(IS_WIN)
TEST_P(RTCVideoDecoderStreamAdapterTest, UseD3D11ToDecodeVP9kSVCStream) {
  auto* decoder = decoder_factory_->decoder();
  EXPECT_TRUE(decoder->IsPlatformDecoder());
  SetSpatialIndex(2);
  decoder->SetDecoderType(media::VideoDecoderType::kD3D11);
  EXPECT_TRUE(BasicSetup());
  EXPECT_CALL(*decoder, Decode_(_, _))
      .WillOnce(
          base::test::RunOnceCallback<1>(media::DecoderStatus::Codes::kOk));
  EXPECT_EQ(Decode(0, false), WEBRTC_VIDEO_CODEC_OK);
  task_environment_.RunUntilIdle();
  EXPECT_CALL(decoded_cb_, Run(_));
  FinishDecode(0);
  EXPECT_TRUE(BasicTeardown());
}
#elif !(defined(ARCH_CPU_X86_FAMILY) && BUILDFLAG(IS_CHROMEOS))
// On ChromeOS, only based on x86(use VaapiDecoder) architecture has the ability
// to decode VP9 kSVC Stream. Other cases should fallback to sw decoder.
TEST_P(RTCVideoDecoderStreamAdapterTest,
       FallbackToSoftwareWhenDecodeVP9kSVCStream) {}
#endif  // BUILDFLAG(IS_WIN)

INSTANTIATE_TEST_SUITE_P();

}  // namespace blink