From 731a2c2dc60b8a4ab7d16fd8ea532a53383b1e3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= Date: Mon, 30 Jul 2018 15:08:07 +0200 Subject: [PATCH] Convert webrtcvideoengine CVO tests away from cricket::VideoCapturer. Bug: webrtc:6353 Change-Id: I1f4f705cda4fdf88465395898e2588b2a19eebf3 Reviewed-on: https://webrtc-review.googlesource.com/83324 Reviewed-by: Magnus Jedvert Commit-Queue: Niels Moller Cr-Commit-Position: refs/heads/master@{#24142} --- media/engine/webrtcvideoengine_unittest.cc | 63 ++++++++++++++++------ 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/media/engine/webrtcvideoengine_unittest.cc b/media/engine/webrtcvideoengine_unittest.cc index cd8daf6de3..5361a95f4d 100644 --- a/media/engine/webrtcvideoengine_unittest.cc +++ b/media/engine/webrtcvideoengine_unittest.cc @@ -175,6 +175,15 @@ int GetMaxDefaultBitrateBps(size_t width, size_t height) { } } +class MockVideoSource : public rtc::VideoSourceInterface { + public: + MOCK_METHOD2(AddOrUpdateSink, + void(rtc::VideoSinkInterface* sink, + const rtc::VideoSinkWants& wants)); + MOCK_METHOD1(RemoveSink, + void(rtc::VideoSinkInterface* sink)); +}; + } // namespace #define EXPECT_FRAME_WAIT(c, w, h, t) \ @@ -300,9 +309,9 @@ TEST_F(WebRtcVideoEngineTest, SupportsVideoRotationHeaderExtension) { } TEST_F(WebRtcVideoEngineTest, CVOSetHeaderExtensionBeforeCapturer) { - // Allocate the capturer first to prevent early destruction before channel's + // Allocate the source first to prevent early destruction before channel's // dtor is called. - FakeVideoCapturerWithTaskQueue capturer; + testing::NiceMock video_source; encoder_factory_->AddSupportedVideoCodecType("VP8"); @@ -318,22 +327,30 @@ TEST_F(WebRtcVideoEngineTest, CVOSetHeaderExtensionBeforeCapturer) { RtpExtension(RtpExtension::kVideoRotationUri, id)); EXPECT_TRUE(channel->SetSendParameters(parameters)); + EXPECT_CALL( + video_source, + AddOrUpdateSink(testing::_, + Field(&rtc::VideoSinkWants::rotation_applied, false))); // Set capturer. - EXPECT_TRUE(channel->SetVideoSend(kSsrc, nullptr, &capturer)); + EXPECT_TRUE(channel->SetVideoSend(kSsrc, nullptr, &video_source)); // Verify capturer has turned off applying rotation. - EXPECT_FALSE(capturer.apply_rotation()); + testing::Mock::VerifyAndClear(&video_source); // Verify removing header extension turns on applying rotation. parameters.extensions.clear(); + EXPECT_CALL( + video_source, + AddOrUpdateSink(testing::_, + Field(&rtc::VideoSinkWants::rotation_applied, true))); + EXPECT_TRUE(channel->SetSendParameters(parameters)); - EXPECT_TRUE(capturer.apply_rotation()); } TEST_F(WebRtcVideoEngineTest, CVOSetHeaderExtensionBeforeAddSendStream) { - // Allocate the capturer first to prevent early destruction before channel's + // Allocate the source first to prevent early destruction before channel's // dtor is called. - FakeVideoCapturerWithTaskQueue capturer; + testing::NiceMock video_source; encoder_factory_->AddSupportedVideoCodecType("VP8"); @@ -348,15 +365,16 @@ TEST_F(WebRtcVideoEngineTest, CVOSetHeaderExtensionBeforeAddSendStream) { EXPECT_TRUE(channel->SetSendParameters(parameters)); EXPECT_TRUE(channel->AddSendStream(StreamParams::CreateLegacy(kSsrc))); - // Set capturer. - EXPECT_TRUE(channel->SetVideoSend(kSsrc, nullptr, &capturer)); - - // Verify capturer has turned off applying rotation. - EXPECT_FALSE(capturer.apply_rotation()); + // Set source. + EXPECT_CALL( + video_source, + AddOrUpdateSink(testing::_, + Field(&rtc::VideoSinkWants::rotation_applied, false))); + EXPECT_TRUE(channel->SetVideoSend(kSsrc, nullptr, &video_source)); } TEST_F(WebRtcVideoEngineTest, CVOSetHeaderExtensionAfterCapturer) { - FakeVideoCapturerWithTaskQueue capturer; + testing::NiceMock video_source; encoder_factory_->AddSupportedVideoCodecType("VP8"); encoder_factory_->AddSupportedVideoCodecType("VP9"); @@ -366,10 +384,14 @@ TEST_F(WebRtcVideoEngineTest, CVOSetHeaderExtensionAfterCapturer) { EXPECT_TRUE(channel->AddSendStream(StreamParams::CreateLegacy(kSsrc))); // Set capturer. - EXPECT_TRUE(channel->SetVideoSend(kSsrc, nullptr, &capturer)); + EXPECT_CALL( + video_source, + AddOrUpdateSink(testing::_, + Field(&rtc::VideoSinkWants::rotation_applied, true))); + EXPECT_TRUE(channel->SetVideoSend(kSsrc, nullptr, &video_source)); // Verify capturer has turned on applying rotation. - EXPECT_TRUE(capturer.apply_rotation()); + testing::Mock::VerifyAndClear(&video_source); // Add CVO extension. const int id = 1; @@ -380,15 +402,22 @@ TEST_F(WebRtcVideoEngineTest, CVOSetHeaderExtensionAfterCapturer) { RtpExtension(RtpExtension::kVideoRotationUri, id)); // Also remove the first codec to trigger a codec change as well. parameters.codecs.erase(parameters.codecs.begin()); + EXPECT_CALL( + video_source, + AddOrUpdateSink(testing::_, + Field(&rtc::VideoSinkWants::rotation_applied, false))); EXPECT_TRUE(channel->SetSendParameters(parameters)); // Verify capturer has turned off applying rotation. - EXPECT_FALSE(capturer.apply_rotation()); + testing::Mock::VerifyAndClear(&video_source); // Verify removing header extension turns on applying rotation. parameters.extensions.clear(); + EXPECT_CALL( + video_source, + AddOrUpdateSink(testing::_, + Field(&rtc::VideoSinkWants::rotation_applied, true))); EXPECT_TRUE(channel->SetSendParameters(parameters)); - EXPECT_TRUE(capturer.apply_rotation()); } TEST_F(WebRtcVideoEngineTest, SetSendFailsBeforeSettingCodecs) {