#pragma once #include #include "api/test/frame_generator_interface.h" #include #include #include #include #include #include #include "rtc_base/checks.h" #include "rtc_base/event.h" #include "rtc_base/synchronization/mutex.h" #include "gtest/gtest.h" namespace unity { namespace webrtc { using namespace ::webrtc; using namespace ::webrtc::test; // todo(kazuki):: move another header for CUDA platform constexpr int kNumCores = 1; constexpr size_t kMaxPayloadSize = 1440; const H264ProfileLevelId kProfileLevelId(H264Profile::kProfileBaseline, H264Level::kLevel3_1); VideoEncoder::Capabilities kCapabilities(); std::string kProfileLevelIdString(); VideoEncoder::Settings kSettings(); // todo(kazuki):: fix workaround #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-function" static void SetDefaultSettings(VideoCodec* codec_settings) { codec_settings->codecType = kVideoCodecH264; codec_settings->maxFramerate = 60; codec_settings->width = 1280; codec_settings->height = 720; // If frame dropping is false, we get a warning that bitrate can't // be controlled for RC_QUALITY_MODE; RC_BITRATE_MODE and RC_TIMESTAMP_MODE codec_settings->H264()->frameDroppingOn = true; codec_settings->startBitrate = 2000; codec_settings->maxBitrate = 4000; } #pragma clang diagnostic pop class VideoCodecTest : public testing::TestWithParam { public: VideoCodecTest() : encodedImageCallback_(this) , decodedImageCallback_(this) , lastInputFrameTimestamp_(0) { } virtual ~VideoCodecTest() override { } virtual std::unique_ptr CreateEncoder() = 0; virtual std::unique_ptr CreateDecoder() = 0; virtual std::unique_ptr CreateFrameGenerator( int width, int height, absl::optional type, absl::optional num_squares) = 0; virtual void ModifyCodecSettings(VideoCodec* codec_settings) = 0; void SetUp() override; void TearDown() override; VideoFrame NextInputFrame(); void ChangeFrameResolution(size_t width, size_t height); // Helper method for waiting a single encoded frame. bool WaitForEncodedFrame(EncodedImage* frame, CodecSpecificInfo* codec_specific_info); bool WaitForEncodedFrames(std::vector* frames, std::vector* codec_specific_info); // Helper method for waiting a single decoded frame. bool WaitForDecodedFrame(std::unique_ptr* frame, absl::optional* qp); protected: class FakeEncodedImageCallback : public EncodedImageCallback { public: explicit FakeEncodedImageCallback(VideoCodecTest* test) : _test(test) { } Result OnEncodedImage(const EncodedImage& frame, const CodecSpecificInfo* codec_specific_info) override; private: VideoCodecTest* _test; }; class FakeDecodedImageCallback : public DecodedImageCallback { public: explicit FakeDecodedImageCallback(VideoCodecTest* test) : _test(test) { } int32_t Decoded(VideoFrame& decodedImage) override { RTC_CHECK_NOTREACHED(); return -1; } void Decoded(VideoFrame& frame, absl::optional decode_time_ms, absl::optional qp) override; private: VideoCodecTest* _test; }; VideoCodec codecSettings_; std::unique_ptr encoder_; std::unique_ptr decoder_; std::unique_ptr inputFrameGenerator_; private: rtc::Event encodedFrameEvent_; rtc::Event decodedFrameEvent_; Mutex encodedFrameSection_; Mutex decodedFrameSection_; std::vector encodedFrames_; absl::optional decodedFrame_; std::vector codecSpecificInfos_; absl::optional decodedQp_; FakeEncodedImageCallback encodedImageCallback_; FakeDecodedImageCallback decodedImageCallback_; uint32_t lastInputFrameTimestamp_; }; } }