| /* |
| * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. |
| * |
| * Use of this source code is governed by a BSD-style license |
| * that can be found in the LICENSE file in the root of the source |
| * tree. An additional intellectual property rights grant can be found |
| * in the file PATENTS. All contributing project authors may |
| * be found in the AUTHORS file in the root of the source tree. |
| */ |
| |
| #include <algorithm> |
| #include <map> |
| #include <memory> |
| #include <vector> |
| |
| #include "webrtc/api/video_codecs/video_encoder.h" |
| #include "webrtc/call/flexfec_receive_stream.h" |
| #include "webrtc/common_video/h264/profile_level_id.h" |
| #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
| #include "webrtc/media/base/mediaconstants.h" |
| #include "webrtc/media/base/rtputils.h" |
| #include "webrtc/media/base/testutils.h" |
| #include "webrtc/media/base/videoengine_unittest.h" |
| #include "webrtc/media/engine/constants.h" |
| #include "webrtc/media/engine/fakewebrtccall.h" |
| #include "webrtc/media/engine/fakewebrtcvideoengine.h" |
| #include "webrtc/media/engine/simulcast.h" |
| #include "webrtc/media/engine/webrtcvideoengine.h" |
| #include "webrtc/media/engine/webrtcvoiceengine.h" |
| #include "webrtc/rtc_base/arraysize.h" |
| #include "webrtc/rtc_base/gunit.h" |
| #include "webrtc/rtc_base/stringutils.h" |
| #include "webrtc/test/field_trial.h" |
| |
| using webrtc::RtpExtension; |
| |
| namespace { |
| static const int kDefaultQpMax = 56; |
| |
| static const uint8_t kRedRtxPayloadType = 125; |
| |
| static const uint32_t kSsrcs1[] = {1}; |
| static const uint32_t kSsrcs3[] = {1, 2, 3}; |
| static const uint32_t kRtxSsrcs1[] = {4}; |
| static const uint32_t kFlexfecSsrc = 5; |
| static const uint32_t kIncomingUnsignalledSsrc = 0xC0FFEE; |
| static const uint32_t kDefaultRecvSsrc = 0; |
| |
| static const char kUnsupportedExtensionName[] = |
| "urn:ietf:params:rtp-hdrext:unsupported"; |
| |
| cricket::VideoCodec RemoveFeedbackParams(cricket::VideoCodec&& codec) { |
| codec.feedback_params = cricket::FeedbackParams(); |
| return codec; |
| } |
| |
| void VerifyCodecHasDefaultFeedbackParams(const cricket::VideoCodec& codec) { |
| EXPECT_TRUE(codec.HasFeedbackParam(cricket::FeedbackParam( |
| cricket::kRtcpFbParamNack, cricket::kParamValueEmpty))); |
| EXPECT_TRUE(codec.HasFeedbackParam(cricket::FeedbackParam( |
| cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli))); |
| EXPECT_TRUE(codec.HasFeedbackParam(cricket::FeedbackParam( |
| cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty))); |
| EXPECT_TRUE(codec.HasFeedbackParam(cricket::FeedbackParam( |
| cricket::kRtcpFbParamTransportCc, cricket::kParamValueEmpty))); |
| EXPECT_TRUE(codec.HasFeedbackParam(cricket::FeedbackParam( |
| cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir))); |
| } |
| |
| // Return true if any codec in |codecs| is an RTX codec with associated payload |
| // type |payload_type|. |
| bool HasRtxCodec(const std::vector<cricket::VideoCodec>& codecs, |
| int payload_type) { |
| for (const cricket::VideoCodec& codec : codecs) { |
| int associated_payload_type; |
| if (cricket::CodecNamesEq(codec.name.c_str(), "rtx") && |
| codec.GetParam(cricket::kCodecParamAssociatedPayloadType, |
| &associated_payload_type) && |
| associated_payload_type == payload_type) { |
| return true; |
| } |
| } |
| return false; |
| } |
| |
| // TODO(nisse): Duplicated in call.cc. |
| const int* FindKeyByValue(const std::map<int, int>& m, int v) { |
| for (const auto& kv : m) { |
| if (kv.second == v) |
| return &kv.first; |
| } |
| return nullptr; |
| } |
| |
| bool HasRtxReceiveAssociation( |
| const webrtc::VideoReceiveStream::Config& config, |
| int payload_type) { |
| return FindKeyByValue(config.rtp.rtx_associated_payload_types, |
| payload_type) != nullptr; |
| } |
| |
| // Check that there's an Rtx payload type for each decoder. |
| bool VerifyRtxReceiveAssociations( |
| const webrtc::VideoReceiveStream::Config& config) { |
| for (const auto& decoder : config.decoders) { |
| if (!HasRtxReceiveAssociation(config, decoder.payload_type)) |
| return false; |
| } |
| return true; |
| } |
| |
| rtc::scoped_refptr<webrtc::VideoFrameBuffer> CreateBlackFrameBuffer( |
| int width, |
| int height) { |
| rtc::scoped_refptr<webrtc::I420Buffer> buffer = |
| webrtc::I420Buffer::Create(width, height); |
| webrtc::I420Buffer::SetBlack(buffer); |
| return buffer; |
| } |
| |
| void VerifySendStreamHasRtxTypes(const webrtc::VideoSendStream::Config& config, |
| const std::map<int, int>& rtx_types) { |
| std::map<int, int>::const_iterator it; |
| it = rtx_types.find(config.encoder_settings.payload_type); |
| EXPECT_TRUE(it != rtx_types.end() && |
| it->second == config.rtp.rtx.payload_type); |
| |
| if (config.rtp.ulpfec.red_rtx_payload_type != -1) { |
| it = rtx_types.find(config.rtp.ulpfec.red_payload_type); |
| EXPECT_TRUE(it != rtx_types.end() && |
| it->second == config.rtp.ulpfec.red_rtx_payload_type); |
| } |
| } |
| |
| cricket::MediaConfig GetMediaConfig() { |
| cricket::MediaConfig media_config; |
| media_config.video.enable_cpu_overuse_detection = false; |
| return media_config; |
| } |
| |
| } // namespace |
| |
| namespace cricket { |
| class WebRtcVideoEngineTest : public ::testing::Test { |
| public: |
| WebRtcVideoEngineTest() : WebRtcVideoEngineTest("") {} |
| explicit WebRtcVideoEngineTest(const char* field_trials) |
| : override_field_trials_(field_trials), |
| call_(webrtc::Call::Create(webrtc::Call::Config(&event_log_))), |
| engine_() { |
| std::vector<VideoCodec> engine_codecs = engine_.codecs(); |
| RTC_DCHECK(!engine_codecs.empty()); |
| bool codec_set = false; |
| for (const cricket::VideoCodec& codec : engine_codecs) { |
| if (codec.name == "rtx") { |
| int associated_payload_type; |
| if (codec.GetParam(kCodecParamAssociatedPayloadType, |
| &associated_payload_type)) { |
| default_apt_rtx_types_[associated_payload_type] = codec.id; |
| } |
| } else if (!codec_set && codec.name != "red" && codec.name != "ulpfec") { |
| default_codec_ = codec; |
| codec_set = true; |
| } |
| } |
| |
| RTC_DCHECK(codec_set); |
| } |
| |
| protected: |
| // Find the codec in the engine with the given name. The codec must be |
| // present. |
| cricket::VideoCodec GetEngineCodec(const std::string& name); |
| |
| VideoMediaChannel* SetUpForExternalEncoderFactory( |
| cricket::WebRtcVideoEncoderFactory* encoder_factory); |
| |
| VideoMediaChannel* SetUpForExternalDecoderFactory( |
| cricket::WebRtcVideoDecoderFactory* decoder_factory, |
| const std::vector<VideoCodec>& codecs); |
| |
| void TestExtendedEncoderOveruse(bool use_external_encoder); |
| |
| webrtc::test::ScopedFieldTrials override_field_trials_; |
| webrtc::RtcEventLogNullImpl event_log_; |
| // Used in WebRtcVideoEngineVoiceTest, but defined here so it's properly |
| // initialized when the constructor is called. |
| std::unique_ptr<webrtc::Call> call_; |
| WebRtcVideoEngine engine_; |
| VideoCodec default_codec_; |
| std::map<int, int> default_apt_rtx_types_; |
| }; |
| |
| TEST_F(WebRtcVideoEngineTest, AnnouncesVp9AccordingToBuildFlags) { |
| bool claims_vp9_support = false; |
| for (const cricket::VideoCodec& codec : engine_.codecs()) { |
| if (codec.name == "VP9") { |
| claims_vp9_support = true; |
| break; |
| } |
| } |
| #if defined(RTC_DISABLE_VP9) |
| EXPECT_FALSE(claims_vp9_support); |
| #else |
| EXPECT_TRUE(claims_vp9_support); |
| #endif // defined(RTC_DISABLE_VP9) |
| } |
| |
| TEST_F(WebRtcVideoEngineTest, DefaultRtxCodecHasAssociatedPayloadTypeSet) { |
| std::vector<VideoCodec> engine_codecs = engine_.codecs(); |
| for (size_t i = 0; i < engine_codecs.size(); ++i) { |
| if (engine_codecs[i].name != kRtxCodecName) |
| continue; |
| int associated_payload_type; |
| EXPECT_TRUE(engine_codecs[i].GetParam(kCodecParamAssociatedPayloadType, |
| &associated_payload_type)); |
| EXPECT_EQ(default_codec_.id, associated_payload_type); |
| return; |
| } |
| FAIL() << "No RTX codec found among default codecs."; |
| } |
| |
| TEST_F(WebRtcVideoEngineTest, SupportsTimestampOffsetHeaderExtension) { |
| RtpCapabilities capabilities = engine_.GetCapabilities(); |
| ASSERT_FALSE(capabilities.header_extensions.empty()); |
| for (const RtpExtension& extension : capabilities.header_extensions) { |
| if (extension.uri == RtpExtension::kTimestampOffsetUri) { |
| EXPECT_EQ(RtpExtension::kTimestampOffsetDefaultId, extension.id); |
| return; |
| } |
| } |
| FAIL() << "Timestamp offset extension not in header-extension list."; |
| } |
| |
| TEST_F(WebRtcVideoEngineTest, SupportsAbsoluteSenderTimeHeaderExtension) { |
| RtpCapabilities capabilities = engine_.GetCapabilities(); |
| ASSERT_FALSE(capabilities.header_extensions.empty()); |
| for (const RtpExtension& extension : capabilities.header_extensions) { |
| if (extension.uri == RtpExtension::kAbsSendTimeUri) { |
| EXPECT_EQ(RtpExtension::kAbsSendTimeDefaultId, extension.id); |
| return; |
| } |
| } |
| FAIL() << "Absolute Sender Time extension not in header-extension list."; |
| } |
| |
| TEST_F(WebRtcVideoEngineTest, SupportsTransportSequenceNumberHeaderExtension) { |
| RtpCapabilities capabilities = engine_.GetCapabilities(); |
| ASSERT_FALSE(capabilities.header_extensions.empty()); |
| for (const RtpExtension& extension : capabilities.header_extensions) { |
| if (extension.uri == RtpExtension::kTransportSequenceNumberUri) { |
| EXPECT_EQ(RtpExtension::kTransportSequenceNumberDefaultId, extension.id); |
| return; |
| } |
| } |
| FAIL() << "Transport sequence number extension not in header-extension list."; |
| } |
| |
| TEST_F(WebRtcVideoEngineTest, SupportsVideoRotationHeaderExtension) { |
| RtpCapabilities capabilities = engine_.GetCapabilities(); |
| ASSERT_FALSE(capabilities.header_extensions.empty()); |
| for (const RtpExtension& extension : capabilities.header_extensions) { |
| if (extension.uri == RtpExtension::kVideoRotationUri) { |
| EXPECT_EQ(RtpExtension::kVideoRotationDefaultId, extension.id); |
| return; |
| } |
| } |
| FAIL() << "Video Rotation extension not in header-extension list."; |
| } |
| |
| TEST_F(WebRtcVideoEngineTest, CVOSetHeaderExtensionBeforeCapturer) { |
| // Allocate the capturer first to prevent early destruction before channel's |
| // dtor is called. |
| cricket::FakeVideoCapturer capturer; |
| |
| cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| encoder_factory.AddSupportedVideoCodecType("VP8"); |
| |
| std::unique_ptr<VideoMediaChannel> channel( |
| SetUpForExternalEncoderFactory(&encoder_factory)); |
| EXPECT_TRUE(channel->AddSendStream(StreamParams::CreateLegacy(kSsrc))); |
| |
| // Add CVO extension. |
| const int id = 1; |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(GetEngineCodec("VP8")); |
| parameters.extensions.push_back( |
| RtpExtension(RtpExtension::kVideoRotationUri, id)); |
| EXPECT_TRUE(channel->SetSendParameters(parameters)); |
| |
| // Set capturer. |
| EXPECT_TRUE(channel->SetVideoSend(kSsrc, true, nullptr, &capturer)); |
| |
| // Verify capturer has turned off applying rotation. |
| EXPECT_FALSE(capturer.apply_rotation()); |
| |
| // Verify removing header extension turns on applying rotation. |
| parameters.extensions.clear(); |
| 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 |
| // dtor is called. |
| cricket::FakeVideoCapturer capturer; |
| |
| cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| encoder_factory.AddSupportedVideoCodecType("VP8"); |
| |
| std::unique_ptr<VideoMediaChannel> channel( |
| SetUpForExternalEncoderFactory(&encoder_factory)); |
| // Add CVO extension. |
| const int id = 1; |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(GetEngineCodec("VP8")); |
| parameters.extensions.push_back( |
| RtpExtension(RtpExtension::kVideoRotationUri, id)); |
| EXPECT_TRUE(channel->SetSendParameters(parameters)); |
| EXPECT_TRUE(channel->AddSendStream(StreamParams::CreateLegacy(kSsrc))); |
| |
| // Set capturer. |
| EXPECT_TRUE(channel->SetVideoSend(kSsrc, true, nullptr, &capturer)); |
| |
| // Verify capturer has turned off applying rotation. |
| EXPECT_FALSE(capturer.apply_rotation()); |
| } |
| |
| TEST_F(WebRtcVideoEngineTest, CVOSetHeaderExtensionAfterCapturer) { |
| cricket::FakeVideoCapturer capturer; |
| |
| cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| encoder_factory.AddSupportedVideoCodecType("VP8"); |
| encoder_factory.AddSupportedVideoCodecType("VP9"); |
| |
| std::unique_ptr<VideoMediaChannel> channel( |
| SetUpForExternalEncoderFactory(&encoder_factory)); |
| EXPECT_TRUE(channel->AddSendStream(StreamParams::CreateLegacy(kSsrc))); |
| |
| // Set capturer. |
| EXPECT_TRUE(channel->SetVideoSend(kSsrc, true, nullptr, &capturer)); |
| |
| // Verify capturer has turned on applying rotation. |
| EXPECT_TRUE(capturer.apply_rotation()); |
| |
| // Add CVO extension. |
| const int id = 1; |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(GetEngineCodec("VP8")); |
| parameters.codecs.push_back(GetEngineCodec("VP9")); |
| parameters.extensions.push_back( |
| RtpExtension(RtpExtension::kVideoRotationUri, id)); |
| // Also remove the first codec to trigger a codec change as well. |
| parameters.codecs.erase(parameters.codecs.begin()); |
| EXPECT_TRUE(channel->SetSendParameters(parameters)); |
| |
| // Verify capturer has turned off applying rotation. |
| EXPECT_FALSE(capturer.apply_rotation()); |
| |
| // Verify removing header extension turns on applying rotation. |
| parameters.extensions.clear(); |
| EXPECT_TRUE(channel->SetSendParameters(parameters)); |
| EXPECT_TRUE(capturer.apply_rotation()); |
| } |
| |
| TEST_F(WebRtcVideoEngineTest, SetSendFailsBeforeSettingCodecs) { |
| engine_.Init(); |
| std::unique_ptr<VideoMediaChannel> channel( |
| engine_.CreateChannel(call_.get(), GetMediaConfig(), VideoOptions())); |
| |
| EXPECT_TRUE(channel->AddSendStream(StreamParams::CreateLegacy(123))); |
| |
| EXPECT_FALSE(channel->SetSend(true)) |
| << "Channel should not start without codecs."; |
| EXPECT_TRUE(channel->SetSend(false)) |
| << "Channel should be stoppable even without set codecs."; |
| } |
| |
| TEST_F(WebRtcVideoEngineTest, GetStatsWithoutSendCodecsSetDoesNotCrash) { |
| engine_.Init(); |
| std::unique_ptr<VideoMediaChannel> channel( |
| engine_.CreateChannel(call_.get(), GetMediaConfig(), VideoOptions())); |
| EXPECT_TRUE(channel->AddSendStream(StreamParams::CreateLegacy(123))); |
| VideoMediaInfo info; |
| channel->GetStats(&info); |
| } |
| |
| TEST_F(WebRtcVideoEngineTest, UseExternalFactoryForVp8WhenSupported) { |
| cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| encoder_factory.AddSupportedVideoCodecType("VP8"); |
| |
| std::unique_ptr<VideoMediaChannel> channel( |
| SetUpForExternalEncoderFactory(&encoder_factory)); |
| channel->OnReadyToSend(true); |
| |
| EXPECT_TRUE( |
| channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
| EXPECT_EQ(0, encoder_factory.GetNumCreatedEncoders()); |
| EXPECT_TRUE(channel->SetSend(true)); |
| cricket::FakeVideoCapturer capturer; |
| EXPECT_TRUE(channel->SetVideoSend(kSsrc, true, nullptr, &capturer)); |
| EXPECT_EQ(cricket::CS_RUNNING, |
| capturer.Start(capturer.GetSupportedFormats()->front())); |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| // Sending one frame will have allocate the encoder. |
| ASSERT_TRUE(encoder_factory.WaitForCreatedVideoEncoders(1)); |
| EXPECT_TRUE_WAIT(encoder_factory.encoders()[0]->GetNumEncodedFrames() > 0, |
| kTimeout); |
| |
| int num_created_encoders = encoder_factory.GetNumCreatedEncoders(); |
| EXPECT_EQ(num_created_encoders, 1); |
| |
| // Setting codecs of the same type should not reallocate any encoders |
| // (expecting a no-op). |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(GetEngineCodec("VP8")); |
| EXPECT_TRUE(channel->SetSendParameters(parameters)); |
| EXPECT_EQ(num_created_encoders, encoder_factory.GetNumCreatedEncoders()); |
| |
| // Remove stream previously added to free the external encoder instance. |
| EXPECT_TRUE(channel->RemoveSendStream(kSsrc)); |
| EXPECT_EQ(0u, encoder_factory.encoders().size()); |
| } |
| |
| // Test that when an external encoder factory supports a codec we don't |
| // internally support, we still add an RTX codec for it. |
| // TODO(deadbeef): Currently this test is only effective if WebRTC is |
| // built with no internal H264 support. This test should be updated |
| // if/when we start adding RTX codecs for unrecognized codec names. |
| TEST_F(WebRtcVideoEngineTest, RtxCodecAddedForExternalCodec) { |
| using webrtc::H264::ProfileLevelIdToString; |
| using webrtc::H264::ProfileLevelId; |
| using webrtc::H264::kLevel1; |
| cricket::VideoCodec h264_constrained_baseline("H264"); |
| h264_constrained_baseline.params[kH264FmtpProfileLevelId] = |
| *ProfileLevelIdToString( |
| ProfileLevelId(webrtc::H264::kProfileConstrainedBaseline, kLevel1)); |
| cricket::VideoCodec h264_constrained_high("H264"); |
| h264_constrained_high.params[kH264FmtpProfileLevelId] = |
| *ProfileLevelIdToString( |
| ProfileLevelId(webrtc::H264::kProfileConstrainedHigh, kLevel1)); |
| cricket::VideoCodec h264_high("H264"); |
| h264_high.params[kH264FmtpProfileLevelId] = *ProfileLevelIdToString( |
| ProfileLevelId(webrtc::H264::kProfileHigh, kLevel1)); |
| |
| cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| encoder_factory.AddSupportedVideoCodec(h264_constrained_baseline); |
| encoder_factory.AddSupportedVideoCodec(h264_constrained_high); |
| encoder_factory.AddSupportedVideoCodec(h264_high); |
| engine_.SetExternalEncoderFactory(&encoder_factory); |
| engine_.Init(); |
| |
| // First figure out what payload types the test codecs got assigned. |
| const std::vector<cricket::VideoCodec> codecs = engine_.codecs(); |
| // Now search for RTX codecs for them. Expect that they all have associated |
| // RTX codecs. |
| EXPECT_TRUE(HasRtxCodec( |
| codecs, FindMatchingCodec(codecs, h264_constrained_baseline)->id)); |
| EXPECT_TRUE(HasRtxCodec( |
| codecs, FindMatchingCodec(codecs, h264_constrained_high)->id)); |
| EXPECT_TRUE(HasRtxCodec( |
| codecs, FindMatchingCodec(codecs, h264_high)->id)); |
| } |
| |
| void WebRtcVideoEngineTest::TestExtendedEncoderOveruse( |
| bool use_external_encoder) { |
| cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| encoder_factory.AddSupportedVideoCodecType("VP8"); |
| std::unique_ptr<VideoMediaChannel> channel; |
| FakeCall* fake_call = new FakeCall(webrtc::Call::Config(&event_log_)); |
| call_.reset(fake_call); |
| if (use_external_encoder) { |
| channel.reset(SetUpForExternalEncoderFactory(&encoder_factory)); |
| } else { |
| engine_.Init(); |
| channel.reset( |
| engine_.CreateChannel(call_.get(), GetMediaConfig(), VideoOptions())); |
| } |
| ASSERT_TRUE( |
| channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(GetEngineCodec("VP8")); |
| EXPECT_TRUE(channel->SetSendParameters(parameters)); |
| EXPECT_TRUE(channel->SetSend(true)); |
| FakeVideoSendStream* stream = fake_call->GetVideoSendStreams()[0]; |
| |
| EXPECT_EQ(use_external_encoder, |
| stream->GetConfig().encoder_settings.full_overuse_time); |
| // Remove stream previously added to free the external encoder instance. |
| EXPECT_TRUE(channel->RemoveSendStream(kSsrc)); |
| } |
| |
| TEST_F(WebRtcVideoEngineTest, EnablesFullEncoderTimeForExternalEncoders) { |
| TestExtendedEncoderOveruse(true); |
| } |
| |
| TEST_F(WebRtcVideoEngineTest, DisablesFullEncoderTimeForNonExternalEncoders) { |
| TestExtendedEncoderOveruse(false); |
| } |
| |
| #if !defined(RTC_DISABLE_VP9) |
| TEST_F(WebRtcVideoEngineTest, CanConstructDecoderForVp9EncoderFactory) { |
| cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| encoder_factory.AddSupportedVideoCodecType("VP9"); |
| |
| std::unique_ptr<VideoMediaChannel> channel( |
| SetUpForExternalEncoderFactory(&encoder_factory)); |
| |
| EXPECT_TRUE( |
| channel->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
| } |
| #endif // !defined(RTC_DISABLE_VP9) |
| |
| TEST_F(WebRtcVideoEngineTest, PropagatesInputFrameTimestamp) { |
| cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| encoder_factory.AddSupportedVideoCodecType("VP8"); |
| FakeCall* fake_call = new FakeCall(webrtc::Call::Config(&event_log_)); |
| call_.reset(fake_call); |
| std::unique_ptr<VideoMediaChannel> channel( |
| SetUpForExternalEncoderFactory(&encoder_factory)); |
| |
| EXPECT_TRUE( |
| channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
| |
| FakeVideoCapturer capturer; |
| EXPECT_TRUE(channel->SetVideoSend(kSsrc, true, nullptr, &capturer)); |
| capturer.Start(cricket::VideoFormat(1280, 720, |
| cricket::VideoFormat::FpsToInterval(60), |
| cricket::FOURCC_I420)); |
| channel->SetSend(true); |
| |
| FakeVideoSendStream* stream = fake_call->GetVideoSendStreams()[0]; |
| |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| int64_t last_timestamp = stream->GetLastTimestamp(); |
| for (int i = 0; i < 10; i++) { |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| int64_t timestamp = stream->GetLastTimestamp(); |
| int64_t interval = timestamp - last_timestamp; |
| |
| // Precision changes from nanosecond to millisecond. |
| // Allow error to be no more than 1. |
| EXPECT_NEAR(cricket::VideoFormat::FpsToInterval(60) / 1E6, interval, 1); |
| |
| last_timestamp = timestamp; |
| } |
| |
| capturer.Start(cricket::VideoFormat(1280, 720, |
| cricket::VideoFormat::FpsToInterval(30), |
| cricket::FOURCC_I420)); |
| |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| last_timestamp = stream->GetLastTimestamp(); |
| for (int i = 0; i < 10; i++) { |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| int64_t timestamp = stream->GetLastTimestamp(); |
| int64_t interval = timestamp - last_timestamp; |
| |
| // Precision changes from nanosecond to millisecond. |
| // Allow error to be no more than 1. |
| EXPECT_NEAR(cricket::VideoFormat::FpsToInterval(30) / 1E6, interval, 1); |
| |
| last_timestamp = timestamp; |
| } |
| |
| // Remove stream previously added to free the external encoder instance. |
| EXPECT_TRUE(channel->RemoveSendStream(kSsrc)); |
| } |
| |
| cricket::VideoCodec WebRtcVideoEngineTest::GetEngineCodec( |
| const std::string& name) { |
| for (const cricket::VideoCodec& engine_codec : engine_.codecs()) { |
| if (CodecNamesEq(name, engine_codec.name)) |
| return engine_codec; |
| } |
| // This point should never be reached. |
| ADD_FAILURE() << "Unrecognized codec name: " << name; |
| return cricket::VideoCodec(); |
| } |
| |
| VideoMediaChannel* WebRtcVideoEngineTest::SetUpForExternalEncoderFactory( |
| cricket::WebRtcVideoEncoderFactory* encoder_factory) { |
| engine_.SetExternalEncoderFactory(encoder_factory); |
| engine_.Init(); |
| |
| VideoMediaChannel* channel = |
| engine_.CreateChannel(call_.get(), GetMediaConfig(), VideoOptions()); |
| cricket::VideoSendParameters parameters; |
| // We need to look up the codec in the engine to get the correct payload type. |
| for (const VideoCodec& codec : encoder_factory->supported_codecs()) |
| parameters.codecs.push_back(GetEngineCodec(codec.name)); |
| |
| EXPECT_TRUE(channel->SetSendParameters(parameters)); |
| |
| return channel; |
| } |
| |
| VideoMediaChannel* WebRtcVideoEngineTest::SetUpForExternalDecoderFactory( |
| cricket::WebRtcVideoDecoderFactory* decoder_factory, |
| const std::vector<VideoCodec>& codecs) { |
| engine_.SetExternalDecoderFactory(decoder_factory); |
| engine_.Init(); |
| |
| VideoMediaChannel* channel = |
| engine_.CreateChannel(call_.get(), GetMediaConfig(), VideoOptions()); |
| cricket::VideoRecvParameters parameters; |
| parameters.codecs = codecs; |
| EXPECT_TRUE(channel->SetRecvParameters(parameters)); |
| |
| return channel; |
| } |
| |
| TEST_F(WebRtcVideoEngineTest, UsesSimulcastAdapterForVp8Factories) { |
| cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| encoder_factory.AddSupportedVideoCodecType("VP8"); |
| |
| std::unique_ptr<VideoMediaChannel> channel( |
| SetUpForExternalEncoderFactory(&encoder_factory)); |
| |
| std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs3); |
| |
| EXPECT_TRUE( |
| channel->AddSendStream(CreateSimStreamParams("cname", ssrcs))); |
| EXPECT_TRUE(channel->SetSend(true)); |
| |
| cricket::FakeVideoCapturer capturer; |
| EXPECT_TRUE(channel->SetVideoSend(ssrcs.front(), true, nullptr, &capturer)); |
| EXPECT_EQ(cricket::CS_RUNNING, |
| capturer.Start(capturer.GetSupportedFormats()->front())); |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| |
| ASSERT_TRUE(encoder_factory.WaitForCreatedVideoEncoders(2)); |
| |
| // Verify that encoders are configured for simulcast through adapter |
| // (increasing resolution and only configured to send one stream each). |
| int prev_width = -1; |
| for (size_t i = 0; i < encoder_factory.encoders().size(); ++i) { |
| ASSERT_TRUE(encoder_factory.encoders()[i]->WaitForInitEncode()); |
| webrtc::VideoCodec codec_settings = |
| encoder_factory.encoders()[i]->GetCodecSettings(); |
| EXPECT_EQ(0, codec_settings.numberOfSimulcastStreams); |
| EXPECT_GT(codec_settings.width, prev_width); |
| prev_width = codec_settings.width; |
| } |
| |
| EXPECT_TRUE(channel->SetVideoSend(ssrcs.front(), true, nullptr, nullptr)); |
| |
| channel.reset(); |
| ASSERT_EQ(0u, encoder_factory.encoders().size()); |
| } |
| |
| TEST_F(WebRtcVideoEngineTest, ChannelWithExternalH264CanChangeToInternalVp8) { |
| cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| encoder_factory.AddSupportedVideoCodecType("H264"); |
| |
| std::unique_ptr<VideoMediaChannel> channel( |
| SetUpForExternalEncoderFactory(&encoder_factory)); |
| |
| EXPECT_TRUE( |
| channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
| ASSERT_EQ(1u, encoder_factory.encoders().size()); |
| |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(GetEngineCodec("VP8")); |
| EXPECT_TRUE(channel->SetSendParameters(parameters)); |
| ASSERT_EQ(0u, encoder_factory.encoders().size()); |
| } |
| |
| TEST_F(WebRtcVideoEngineTest, |
| DontUseExternalEncoderFactoryForUnsupportedCodecs) { |
| cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| encoder_factory.AddSupportedVideoCodecType("H264"); |
| |
| engine_.SetExternalEncoderFactory(&encoder_factory); |
| engine_.Init(); |
| |
| std::unique_ptr<VideoMediaChannel> channel( |
| engine_.CreateChannel(call_.get(), GetMediaConfig(), VideoOptions())); |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(GetEngineCodec("VP8")); |
| EXPECT_TRUE(channel->SetSendParameters(parameters)); |
| |
| EXPECT_TRUE( |
| channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
| // Make sure DestroyVideoEncoder was called on the factory. |
| ASSERT_EQ(0u, encoder_factory.encoders().size()); |
| } |
| |
| TEST_F(WebRtcVideoEngineTest, |
| UsesSimulcastAdapterForVp8WithCombinedVP8AndH264Factory) { |
| cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| encoder_factory.AddSupportedVideoCodecType("VP8"); |
| encoder_factory.AddSupportedVideoCodecType("H264"); |
| |
| engine_.SetExternalEncoderFactory(&encoder_factory); |
| engine_.Init(); |
| |
| std::unique_ptr<VideoMediaChannel> channel( |
| engine_.CreateChannel(call_.get(), GetMediaConfig(), VideoOptions())); |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(GetEngineCodec("VP8")); |
| EXPECT_TRUE(channel->SetSendParameters(parameters)); |
| |
| std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs3); |
| |
| EXPECT_TRUE( |
| channel->AddSendStream(CreateSimStreamParams("cname", ssrcs))); |
| EXPECT_TRUE(channel->SetSend(true)); |
| |
| // Send a fake frame, or else the media engine will configure the simulcast |
| // encoder adapter at a low-enough size that it'll only create a single |
| // encoder layer. |
| cricket::FakeVideoCapturer capturer; |
| EXPECT_TRUE(channel->SetVideoSend(ssrcs.front(), true, nullptr, &capturer)); |
| EXPECT_EQ(cricket::CS_RUNNING, |
| capturer.Start(capturer.GetSupportedFormats()->front())); |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| |
| ASSERT_TRUE(encoder_factory.WaitForCreatedVideoEncoders(2)); |
| ASSERT_TRUE(encoder_factory.encoders()[0]->WaitForInitEncode()); |
| EXPECT_EQ(webrtc::kVideoCodecVP8, |
| encoder_factory.encoders()[0]->GetCodecSettings().codecType); |
| |
| channel.reset(); |
| // Make sure DestroyVideoEncoder was called on the factory. |
| EXPECT_EQ(0u, encoder_factory.encoders().size()); |
| } |
| |
| TEST_F(WebRtcVideoEngineTest, |
| DestroysNonSimulcastEncoderFromCombinedVP8AndH264Factory) { |
| cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| encoder_factory.AddSupportedVideoCodecType("VP8"); |
| encoder_factory.AddSupportedVideoCodecType("H264"); |
| |
| engine_.SetExternalEncoderFactory(&encoder_factory); |
| engine_.Init(); |
| |
| std::unique_ptr<VideoMediaChannel> channel( |
| engine_.CreateChannel(call_.get(), GetMediaConfig(), VideoOptions())); |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(GetEngineCodec("H264")); |
| EXPECT_TRUE(channel->SetSendParameters(parameters)); |
| |
| EXPECT_TRUE( |
| channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
| ASSERT_EQ(1u, encoder_factory.encoders().size()); |
| |
| // Send a frame of 720p. This should trigger a "real" encoder initialization. |
| cricket::VideoFormat format( |
| 1280, 720, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420); |
| cricket::FakeVideoCapturer capturer; |
| EXPECT_TRUE(channel->SetVideoSend(kSsrc, true, nullptr, &capturer)); |
| EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(format)); |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| ASSERT_TRUE(encoder_factory.encoders()[0]->WaitForInitEncode()); |
| EXPECT_EQ(webrtc::kVideoCodecH264, |
| encoder_factory.encoders()[0]->GetCodecSettings().codecType); |
| |
| channel.reset(); |
| // Make sure DestroyVideoEncoder was called on the factory. |
| ASSERT_EQ(0u, encoder_factory.encoders().size()); |
| } |
| |
| TEST_F(WebRtcVideoEngineTest, SimulcastDisabledForH264) { |
| cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| encoder_factory.AddSupportedVideoCodecType("H264"); |
| |
| std::unique_ptr<VideoMediaChannel> channel( |
| SetUpForExternalEncoderFactory(&encoder_factory)); |
| |
| const std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs3); |
| EXPECT_TRUE( |
| channel->AddSendStream(cricket::CreateSimStreamParams("cname", ssrcs))); |
| |
| // Send a frame of 720p. This should trigger a "real" encoder initialization. |
| cricket::VideoFormat format( |
| 1280, 720, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420); |
| cricket::FakeVideoCapturer capturer; |
| EXPECT_TRUE(channel->SetVideoSend(ssrcs[0], true, nullptr, &capturer)); |
| EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(format)); |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| |
| ASSERT_EQ(1u, encoder_factory.encoders().size()); |
| FakeWebRtcVideoEncoder* encoder = encoder_factory.encoders()[0]; |
| ASSERT_TRUE(encoder_factory.encoders()[0]->WaitForInitEncode()); |
| EXPECT_EQ(webrtc::kVideoCodecH264, encoder->GetCodecSettings().codecType); |
| EXPECT_EQ(1u, encoder->GetCodecSettings().numberOfSimulcastStreams); |
| EXPECT_TRUE(channel->SetVideoSend(ssrcs[0], true, nullptr, nullptr)); |
| } |
| |
| // Test that the FlexFEC field trial properly alters the output of |
| // WebRtcVideoEngine::codecs(), for an existing |engine_| object. |
| // |
| // TODO(brandtr): Remove this test, when the FlexFEC field trial is gone. |
| TEST_F(WebRtcVideoEngineTest, |
| Flexfec03SupportedAsInternalCodecBehindFieldTrial) { |
| auto is_flexfec = [](const VideoCodec& codec) { |
| if (codec.name == "flexfec-03") |
| return true; |
| return false; |
| }; |
| |
| // FlexFEC is not active without field trial. |
| engine_.Init(); |
| const std::vector<VideoCodec> codecs_before = engine_.codecs(); |
| EXPECT_EQ(codecs_before.end(), std::find_if(codecs_before.begin(), |
| codecs_before.end(), is_flexfec)); |
| |
| // FlexFEC is active with field trial. |
| webrtc::test::ScopedFieldTrials override_field_trials_( |
| "WebRTC-FlexFEC-03-Advertised/Enabled/"); |
| const std::vector<VideoCodec> codecs_after = engine_.codecs(); |
| EXPECT_NE(codecs_after.end(), |
| std::find_if(codecs_after.begin(), codecs_after.end(), is_flexfec)); |
| } |
| |
| // Test that external codecs are added to the end of the supported codec list. |
| TEST_F(WebRtcVideoEngineTest, ReportSupportedExternalCodecs) { |
| cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| encoder_factory.AddSupportedVideoCodecType("FakeExternalCodec"); |
| engine_.SetExternalEncoderFactory(&encoder_factory); |
| engine_.Init(); |
| |
| std::vector<cricket::VideoCodec> codecs(engine_.codecs()); |
| ASSERT_GE(codecs.size(), 2u); |
| cricket::VideoCodec internal_codec = codecs.front(); |
| cricket::VideoCodec external_codec = codecs.back(); |
| |
| // The external codec will appear last in the vector. |
| EXPECT_EQ("VP8", internal_codec.name); |
| EXPECT_EQ("FakeExternalCodec", external_codec.name); |
| } |
| |
| // Test that an external codec that was added after the engine was initialized |
| // does show up in the codec list after it was added. |
| TEST_F(WebRtcVideoEngineTest, ReportSupportedExternalCodecsWithAddedCodec) { |
| // Set up external encoder factory with first codec, and initialize engine. |
| cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| encoder_factory.AddSupportedVideoCodecType("FakeExternalCodec1"); |
| engine_.SetExternalEncoderFactory(&encoder_factory); |
| engine_.Init(); |
| |
| // The first external codec will appear last in the vector. |
| std::vector<cricket::VideoCodec> codecs_before(engine_.codecs()); |
| EXPECT_EQ("FakeExternalCodec1", codecs_before.back().name); |
| |
| // Add second codec. |
| encoder_factory.AddSupportedVideoCodecType("FakeExternalCodec2"); |
| std::vector<cricket::VideoCodec> codecs_after(engine_.codecs()); |
| EXPECT_EQ(codecs_before.size() + 1, codecs_after.size()); |
| EXPECT_EQ("FakeExternalCodec2", codecs_after.back().name); |
| } |
| |
| TEST_F(WebRtcVideoEngineTest, RegisterExternalDecodersIfSupported) { |
| cricket::FakeWebRtcVideoDecoderFactory decoder_factory; |
| decoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8); |
| cricket::VideoRecvParameters parameters; |
| parameters.codecs.push_back(GetEngineCodec("VP8")); |
| |
| std::unique_ptr<VideoMediaChannel> channel( |
| SetUpForExternalDecoderFactory(&decoder_factory, parameters.codecs)); |
| |
| EXPECT_TRUE( |
| channel->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
| ASSERT_EQ(1u, decoder_factory.decoders().size()); |
| |
| // Setting codecs of the same type should not reallocate the decoder. |
| EXPECT_TRUE(channel->SetRecvParameters(parameters)); |
| EXPECT_EQ(1, decoder_factory.GetNumCreatedDecoders()); |
| |
| // Remove stream previously added to free the external decoder instance. |
| EXPECT_TRUE(channel->RemoveRecvStream(kSsrc)); |
| EXPECT_EQ(0u, decoder_factory.decoders().size()); |
| } |
| |
| // Verifies that we can set up decoders that are not internally supported. |
| TEST_F(WebRtcVideoEngineTest, RegisterExternalH264DecoderIfSupported) { |
| // TODO(pbos): Do not assume that encoder/decoder support is symmetric. We |
| // can't even query the WebRtcVideoDecoderFactory for supported codecs. |
| // For now we add a FakeWebRtcVideoEncoderFactory to add H264 to supported |
| // codecs. |
| cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| encoder_factory.AddSupportedVideoCodecType("H264"); |
| engine_.SetExternalEncoderFactory(&encoder_factory); |
| cricket::FakeWebRtcVideoDecoderFactory decoder_factory; |
| decoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecH264); |
| std::vector<cricket::VideoCodec> codecs; |
| codecs.push_back(GetEngineCodec("H264")); |
| |
| std::unique_ptr<VideoMediaChannel> channel( |
| SetUpForExternalDecoderFactory(&decoder_factory, codecs)); |
| |
| EXPECT_TRUE( |
| channel->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
| ASSERT_EQ(1u, decoder_factory.decoders().size()); |
| } |
| |
| class WebRtcVideoChannelBaseTest |
| : public VideoMediaChannelTest<WebRtcVideoEngine, WebRtcVideoChannel> { |
| protected: |
| typedef VideoMediaChannelTest<WebRtcVideoEngine, WebRtcVideoChannel> Base; |
| |
| cricket::VideoCodec GetEngineCodec(const std::string& name) { |
| for (const cricket::VideoCodec& engine_codec : engine_.codecs()) { |
| if (CodecNamesEq(name, engine_codec.name)) |
| return engine_codec; |
| } |
| // This point should never be reached. |
| ADD_FAILURE() << "Unrecognized codec name: " << name; |
| return cricket::VideoCodec(); |
| } |
| |
| cricket::VideoCodec DefaultCodec() override { return GetEngineCodec("VP8"); } |
| }; |
| |
| // Verifies that id given in stream params is passed to the decoder factory. |
| TEST_F(WebRtcVideoEngineTest, StreamParamsIdPassedToDecoderFactory) { |
| cricket::FakeWebRtcVideoDecoderFactory decoder_factory; |
| decoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8); |
| cricket::VideoRecvParameters parameters; |
| parameters.codecs.push_back(GetEngineCodec("VP8")); |
| |
| std::unique_ptr<VideoMediaChannel> channel( |
| SetUpForExternalDecoderFactory(&decoder_factory, parameters.codecs)); |
| |
| StreamParams sp = cricket::StreamParams::CreateLegacy(kSsrc); |
| sp.id = "FakeStreamParamsId"; |
| EXPECT_TRUE(channel->AddRecvStream(sp)); |
| EXPECT_EQ(1u, decoder_factory.decoders().size()); |
| |
| std::vector<cricket::VideoDecoderParams> params = decoder_factory.params(); |
| ASSERT_EQ(1u, params.size()); |
| EXPECT_EQ(sp.id, params[0].receive_stream_id); |
| } |
| |
| TEST_F(WebRtcVideoEngineTest, DISABLED_RecreatesEncoderOnContentTypeChange) { |
| cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| encoder_factory.AddSupportedVideoCodecType("VP8"); |
| std::unique_ptr<FakeCall> fake_call( |
| new FakeCall(webrtc::Call::Config(&event_log_))); |
| std::unique_ptr<VideoMediaChannel> channel( |
| SetUpForExternalEncoderFactory(&encoder_factory)); |
| ASSERT_TRUE( |
| channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
| cricket::VideoCodec codec = GetEngineCodec("VP8"); |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(codec); |
| channel->OnReadyToSend(true); |
| channel->SetSend(true); |
| ASSERT_TRUE(channel->SetSendParameters(parameters)); |
| |
| cricket::FakeVideoCapturer capturer; |
| VideoOptions options; |
| EXPECT_TRUE(channel->SetVideoSend(kSsrc, true, &options, &capturer)); |
| |
| EXPECT_EQ(cricket::CS_RUNNING, |
| capturer.Start(capturer.GetSupportedFormats()->front())); |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| ASSERT_TRUE(encoder_factory.WaitForCreatedVideoEncoders(1)); |
| EXPECT_EQ(webrtc::kRealtimeVideo, |
| encoder_factory.encoders().back()->GetCodecSettings().mode); |
| |
| EXPECT_TRUE(channel->SetVideoSend(kSsrc, true, &options, &capturer)); |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| // No change in content type, keep current encoder. |
| EXPECT_EQ(1, encoder_factory.GetNumCreatedEncoders()); |
| |
| options.is_screencast.emplace(true); |
| EXPECT_TRUE(channel->SetVideoSend(kSsrc, true, &options, &capturer)); |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| // Change to screen content, recreate encoder. For the simulcast encoder |
| // adapter case, this will result in two calls since InitEncode triggers a |
| // a new instance. |
| ASSERT_TRUE(encoder_factory.WaitForCreatedVideoEncoders(2)); |
| EXPECT_EQ(webrtc::kScreensharing, |
| encoder_factory.encoders().back()->GetCodecSettings().mode); |
| |
| EXPECT_TRUE(channel->SetVideoSend(kSsrc, true, &options, &capturer)); |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| // Still screen content, no need to update encoder. |
| EXPECT_EQ(2, encoder_factory.GetNumCreatedEncoders()); |
| |
| options.is_screencast.emplace(false); |
| options.video_noise_reduction.emplace(false); |
| EXPECT_TRUE(channel->SetVideoSend(kSsrc, true, &options, &capturer)); |
| // Change back to regular video content, update encoder. Also change |
| // a non |is_screencast| option just to verify it doesn't affect recreation. |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| ASSERT_TRUE(encoder_factory.WaitForCreatedVideoEncoders(3)); |
| EXPECT_EQ(webrtc::kRealtimeVideo, |
| encoder_factory.encoders().back()->GetCodecSettings().mode); |
| |
| // Remove stream previously added to free the external encoder instance. |
| EXPECT_TRUE(channel->RemoveSendStream(kSsrc)); |
| EXPECT_EQ(0u, encoder_factory.encoders().size()); |
| } |
| |
| #define WEBRTC_BASE_TEST(test) \ |
| TEST_F(WebRtcVideoChannelBaseTest, test) { Base::test(); } |
| |
| #define WEBRTC_DISABLED_BASE_TEST(test) \ |
| TEST_F(WebRtcVideoChannelBaseTest, DISABLED_##test) { Base::test(); } |
| |
| WEBRTC_BASE_TEST(SetSend); |
| WEBRTC_BASE_TEST(SetSendWithoutCodecs); |
| WEBRTC_BASE_TEST(SetSendSetsTransportBufferSizes); |
| |
| WEBRTC_BASE_TEST(GetStats); |
| WEBRTC_BASE_TEST(GetStatsMultipleRecvStreams); |
| WEBRTC_BASE_TEST(GetStatsMultipleSendStreams); |
| |
| WEBRTC_BASE_TEST(SetSendBandwidth); |
| |
| WEBRTC_BASE_TEST(SetSendSsrc); |
| WEBRTC_BASE_TEST(SetSendSsrcAfterSetCodecs); |
| |
| WEBRTC_BASE_TEST(SetSink); |
| |
| WEBRTC_BASE_TEST(AddRemoveSendStreams); |
| |
| WEBRTC_BASE_TEST(SimulateConference); |
| |
| WEBRTC_DISABLED_BASE_TEST(AddRemoveCapturer); |
| |
| WEBRTC_BASE_TEST(RemoveCapturerWithoutAdd); |
| |
| WEBRTC_BASE_TEST(AddRemoveCapturerMultipleSources); |
| |
| WEBRTC_BASE_TEST(RejectEmptyStreamParams); |
| |
| WEBRTC_BASE_TEST(MultipleSendStreams); |
| |
| TEST_F(WebRtcVideoChannelBaseTest, SendAndReceiveVp8Vga) { |
| SendAndReceive(GetEngineCodec("VP8")); |
| } |
| |
| TEST_F(WebRtcVideoChannelBaseTest, SendAndReceiveVp8Qvga) { |
| SendAndReceive(GetEngineCodec("VP8")); |
| } |
| |
| TEST_F(WebRtcVideoChannelBaseTest, SendAndReceiveVp8SvcQqvga) { |
| SendAndReceive(GetEngineCodec("VP8")); |
| } |
| |
| TEST_F(WebRtcVideoChannelBaseTest, TwoStreamsSendAndReceive) { |
| // Set a high bitrate to not be downscaled by VP8 due to low initial start |
| // bitrates. This currently happens at <250k, and two streams sharing 300k |
| // initially will use QVGA instead of VGA. |
| // TODO(pbos): Set up the quality scaler so that both senders reliably start |
| // at QVGA, then verify that instead. |
| cricket::VideoCodec codec = GetEngineCodec("VP8"); |
| codec.params[kCodecParamStartBitrate] = "1000000"; |
| Base::TwoStreamsSendAndReceive(codec); |
| } |
| |
| class WebRtcVideoChannelTest : public WebRtcVideoEngineTest { |
| public: |
| WebRtcVideoChannelTest() : WebRtcVideoChannelTest("") {} |
| explicit WebRtcVideoChannelTest(const char* field_trials) |
| : WebRtcVideoEngineTest(field_trials), last_ssrc_(0) {} |
| void SetUp() override { |
| fake_call_.reset(new FakeCall(webrtc::Call::Config(&event_log_))); |
| engine_.Init(); |
| channel_.reset(engine_.CreateChannel(fake_call_.get(), GetMediaConfig(), |
| VideoOptions())); |
| channel_->OnReadyToSend(true); |
| last_ssrc_ = 123; |
| send_parameters_.codecs = engine_.codecs(); |
| recv_parameters_.codecs = engine_.codecs(); |
| ASSERT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| } |
| |
| protected: |
| FakeVideoSendStream* AddSendStream() { |
| return AddSendStream(StreamParams::CreateLegacy(++last_ssrc_)); |
| } |
| |
| FakeVideoSendStream* AddSendStream(const StreamParams& sp) { |
| size_t num_streams = fake_call_->GetVideoSendStreams().size(); |
| EXPECT_TRUE(channel_->AddSendStream(sp)); |
| std::vector<FakeVideoSendStream*> streams = |
| fake_call_->GetVideoSendStreams(); |
| EXPECT_EQ(num_streams + 1, streams.size()); |
| return streams[streams.size() - 1]; |
| } |
| |
| std::vector<FakeVideoSendStream*> GetFakeSendStreams() { |
| return fake_call_->GetVideoSendStreams(); |
| } |
| |
| FakeVideoReceiveStream* AddRecvStream() { |
| return AddRecvStream(StreamParams::CreateLegacy(++last_ssrc_)); |
| } |
| |
| FakeVideoReceiveStream* AddRecvStream(const StreamParams& sp) { |
| size_t num_streams = fake_call_->GetVideoReceiveStreams().size(); |
| EXPECT_TRUE(channel_->AddRecvStream(sp)); |
| std::vector<FakeVideoReceiveStream*> streams = |
| fake_call_->GetVideoReceiveStreams(); |
| EXPECT_EQ(num_streams + 1, streams.size()); |
| return streams[streams.size() - 1]; |
| } |
| |
| void SetSendCodecsShouldWorkForBitrates(const char* min_bitrate_kbps, |
| int expected_min_bitrate_bps, |
| const char* start_bitrate_kbps, |
| int expected_start_bitrate_bps, |
| const char* max_bitrate_kbps, |
| int expected_max_bitrate_bps) { |
| auto& codecs = send_parameters_.codecs; |
| codecs.clear(); |
| codecs.push_back(GetEngineCodec("VP8")); |
| codecs[0].params[kCodecParamMinBitrate] = min_bitrate_kbps; |
| codecs[0].params[kCodecParamStartBitrate] = start_bitrate_kbps; |
| codecs[0].params[kCodecParamMaxBitrate] = max_bitrate_kbps; |
| EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| |
| EXPECT_EQ(expected_min_bitrate_bps, |
| fake_call_->GetConfig().bitrate_config.min_bitrate_bps); |
| EXPECT_EQ(expected_start_bitrate_bps, |
| fake_call_->GetConfig().bitrate_config.start_bitrate_bps); |
| EXPECT_EQ(expected_max_bitrate_bps, |
| fake_call_->GetConfig().bitrate_config.max_bitrate_bps); |
| } |
| |
| void TestSetSendRtpHeaderExtensions(const std::string& ext_uri) { |
| // Enable extension. |
| const int id = 1; |
| cricket::VideoSendParameters parameters = send_parameters_; |
| parameters.extensions.push_back(RtpExtension(ext_uri, id)); |
| EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| FakeVideoSendStream* send_stream = |
| AddSendStream(cricket::StreamParams::CreateLegacy(123)); |
| |
| // Verify the send extension id. |
| ASSERT_EQ(1u, send_stream->GetConfig().rtp.extensions.size()); |
| EXPECT_EQ(id, send_stream->GetConfig().rtp.extensions[0].id); |
| EXPECT_EQ(ext_uri, send_stream->GetConfig().rtp.extensions[0].uri); |
| // Verify call with same set of extensions returns true. |
| EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| // Verify that SetSendRtpHeaderExtensions doesn't implicitly add them for |
| // receivers. |
| EXPECT_TRUE(AddRecvStream(cricket::StreamParams::CreateLegacy(123)) |
| ->GetConfig() |
| .rtp.extensions.empty()); |
| |
| // Verify that existing RTP header extensions can be removed. |
| EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
| send_stream = fake_call_->GetVideoSendStreams()[0]; |
| EXPECT_TRUE(send_stream->GetConfig().rtp.extensions.empty()); |
| |
| // Verify that adding receive RTP header extensions adds them for existing |
| // streams. |
| EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| send_stream = fake_call_->GetVideoSendStreams()[0]; |
| ASSERT_EQ(1u, send_stream->GetConfig().rtp.extensions.size()); |
| EXPECT_EQ(id, send_stream->GetConfig().rtp.extensions[0].id); |
| EXPECT_EQ(ext_uri, send_stream->GetConfig().rtp.extensions[0].uri); |
| } |
| |
| void TestSetRecvRtpHeaderExtensions(const std::string& ext_uri) { |
| // Enable extension. |
| const int id = 1; |
| cricket::VideoRecvParameters parameters = recv_parameters_; |
| parameters.extensions.push_back(RtpExtension(ext_uri, id)); |
| EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
| |
| FakeVideoReceiveStream* recv_stream = |
| AddRecvStream(cricket::StreamParams::CreateLegacy(123)); |
| |
| // Verify the recv extension id. |
| ASSERT_EQ(1u, recv_stream->GetConfig().rtp.extensions.size()); |
| EXPECT_EQ(id, recv_stream->GetConfig().rtp.extensions[0].id); |
| EXPECT_EQ(ext_uri, recv_stream->GetConfig().rtp.extensions[0].uri); |
| // Verify call with same set of extensions returns true. |
| EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
| |
| // Verify that SetRecvRtpHeaderExtensions doesn't implicitly add them for |
| // senders. |
| EXPECT_TRUE(AddSendStream(cricket::StreamParams::CreateLegacy(123)) |
| ->GetConfig() |
| .rtp.extensions.empty()); |
| |
| // Verify that existing RTP header extensions can be removed. |
| EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); |
| ASSERT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()); |
| recv_stream = fake_call_->GetVideoReceiveStreams()[0]; |
| EXPECT_TRUE(recv_stream->GetConfig().rtp.extensions.empty()); |
| |
| // Verify that adding receive RTP header extensions adds them for existing |
| // streams. |
| EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
| recv_stream = fake_call_->GetVideoReceiveStreams()[0]; |
| ASSERT_EQ(1u, recv_stream->GetConfig().rtp.extensions.size()); |
| EXPECT_EQ(id, recv_stream->GetConfig().rtp.extensions[0].id); |
| EXPECT_EQ(ext_uri, recv_stream->GetConfig().rtp.extensions[0].uri); |
| } |
| |
| void TestExtensionFilter(const std::vector<std::string>& extensions, |
| const std::string& expected_extension) { |
| cricket::VideoSendParameters parameters = send_parameters_; |
| int expected_id = -1; |
| int id = 1; |
| for (const std::string& extension : extensions) { |
| if (extension == expected_extension) |
| expected_id = id; |
| parameters.extensions.push_back(RtpExtension(extension, id++)); |
| } |
| EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| FakeVideoSendStream* send_stream = |
| AddSendStream(cricket::StreamParams::CreateLegacy(123)); |
| |
| // Verify that only one of them has been set, and that it is the one with |
| // highest priority (transport sequence number). |
| ASSERT_EQ(1u, send_stream->GetConfig().rtp.extensions.size()); |
| EXPECT_EQ(expected_id, send_stream->GetConfig().rtp.extensions[0].id); |
| EXPECT_EQ(expected_extension, |
| send_stream->GetConfig().rtp.extensions[0].uri); |
| } |
| |
| void TestDegradationPreference(bool resolution_scaling_enabled, |
| bool fps_scaling_enabled); |
| |
| void TestCpuAdaptation(bool enable_overuse, bool is_screenshare); |
| void TestReceiverLocalSsrcConfiguration(bool receiver_first); |
| void TestReceiveUnsignaledSsrcPacket(uint8_t payload_type, |
| bool expect_created_receive_stream); |
| |
| FakeVideoSendStream* SetDenoisingOption( |
| uint32_t ssrc, |
| cricket::FakeVideoCapturer* capturer, |
| bool enabled) { |
| cricket::VideoOptions options; |
| options.video_noise_reduction = rtc::Optional<bool>(enabled); |
| EXPECT_TRUE(channel_->SetVideoSend(ssrc, true, &options, capturer)); |
| // Options only take effect on the next frame. |
| EXPECT_TRUE(capturer->CaptureFrame()); |
| |
| return fake_call_->GetVideoSendStreams().back(); |
| } |
| |
| FakeVideoSendStream* SetUpSimulcast(bool enabled, bool with_rtx) { |
| const int kRtxSsrcOffset = 0xDEADBEEF; |
| last_ssrc_ += 3; |
| std::vector<uint32_t> ssrcs; |
| std::vector<uint32_t> rtx_ssrcs; |
| uint32_t num_streams = enabled ? 3 : 1; |
| for (uint32_t i = 0; i < num_streams; ++i) { |
| uint32_t ssrc = last_ssrc_ + i; |
| ssrcs.push_back(ssrc); |
| if (with_rtx) { |
| rtx_ssrcs.push_back(ssrc + kRtxSsrcOffset); |
| } |
| } |
| if (with_rtx) { |
| return AddSendStream( |
| cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs)); |
| } |
| return AddSendStream(CreateSimStreamParams("cname", ssrcs)); |
| } |
| |
| int GetMaxEncoderBitrate() { |
| std::vector<FakeVideoSendStream*> streams = |
| fake_call_->GetVideoSendStreams(); |
| EXPECT_EQ(1u, streams.size()); |
| FakeVideoSendStream* stream = streams[streams.size() - 1]; |
| EXPECT_EQ(1, stream->GetEncoderConfig().number_of_streams); |
| return stream->GetVideoStreams()[0].max_bitrate_bps; |
| } |
| |
| void SetAndExpectMaxBitrate(int global_max, |
| int stream_max, |
| int expected_encoder_bitrate) { |
| VideoSendParameters limited_send_params = send_parameters_; |
| limited_send_params.max_bandwidth_bps = global_max; |
| EXPECT_TRUE(channel_->SetSendParameters(limited_send_params)); |
| webrtc::RtpParameters parameters = |
| channel_->GetRtpSendParameters(last_ssrc_); |
| EXPECT_EQ(1UL, parameters.encodings.size()); |
| parameters.encodings[0].max_bitrate_bps = rtc::Optional<int>(stream_max); |
| EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters)); |
| // Read back the parameteres and verify they have the correct value |
| parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| EXPECT_EQ(1UL, parameters.encodings.size()); |
| EXPECT_EQ(rtc::Optional<int>(stream_max), |
| parameters.encodings[0].max_bitrate_bps); |
| // Verify that the new value propagated down to the encoder |
| EXPECT_EQ(expected_encoder_bitrate, GetMaxEncoderBitrate()); |
| } |
| |
| std::unique_ptr<FakeCall> fake_call_; |
| std::unique_ptr<VideoMediaChannel> channel_; |
| cricket::VideoSendParameters send_parameters_; |
| cricket::VideoRecvParameters recv_parameters_; |
| uint32_t last_ssrc_; |
| }; |
| |
| TEST_F(WebRtcVideoChannelTest, SetsSyncGroupFromSyncLabel) { |
| const uint32_t kVideoSsrc = 123; |
| const std::string kSyncLabel = "AvSyncLabel"; |
| |
| cricket::StreamParams sp = cricket::StreamParams::CreateLegacy(kVideoSsrc); |
| sp.sync_label = kSyncLabel; |
| EXPECT_TRUE(channel_->AddRecvStream(sp)); |
| |
| EXPECT_EQ(1, fake_call_->GetVideoReceiveStreams().size()); |
| EXPECT_EQ(kSyncLabel, |
| fake_call_->GetVideoReceiveStreams()[0]->GetConfig().sync_group) |
| << "SyncGroup should be set based on sync_label"; |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, RecvStreamWithSimAndRtx) { |
| cricket::VideoSendParameters parameters; |
| parameters.codecs = engine_.codecs(); |
| EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| EXPECT_TRUE(channel_->SetSend(true)); |
| parameters.conference_mode = true; |
| EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| |
| // Send side. |
| const std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs1); |
| const std::vector<uint32_t> rtx_ssrcs = MAKE_VECTOR(kRtxSsrcs1); |
| FakeVideoSendStream* send_stream = AddSendStream( |
| cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs)); |
| |
| ASSERT_EQ(rtx_ssrcs.size(), send_stream->GetConfig().rtp.rtx.ssrcs.size()); |
| for (size_t i = 0; i < rtx_ssrcs.size(); ++i) |
| EXPECT_EQ(rtx_ssrcs[i], send_stream->GetConfig().rtp.rtx.ssrcs[i]); |
| |
| // Receiver side. |
| FakeVideoReceiveStream* recv_stream = AddRecvStream( |
| cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs)); |
| EXPECT_FALSE( |
| recv_stream->GetConfig().rtp.rtx_associated_payload_types.empty()); |
| EXPECT_TRUE(VerifyRtxReceiveAssociations(recv_stream->GetConfig())) |
| << "RTX should be mapped for all decoders/payload types."; |
| EXPECT_TRUE(HasRtxReceiveAssociation(recv_stream->GetConfig(), |
| GetEngineCodec("red").id)) |
| << "RTX should be mapped for the RED payload type"; |
| |
| EXPECT_EQ(rtx_ssrcs[0], recv_stream->GetConfig().rtp.rtx_ssrc); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, RecvStreamWithRtx) { |
| // Setup one channel with an associated RTX stream. |
| cricket::StreamParams params = |
| cricket::StreamParams::CreateLegacy(kSsrcs1[0]); |
| params.AddFidSsrc(kSsrcs1[0], kRtxSsrcs1[0]); |
| FakeVideoReceiveStream* recv_stream = AddRecvStream(params); |
| EXPECT_EQ(kRtxSsrcs1[0], recv_stream->GetConfig().rtp.rtx_ssrc); |
| |
| EXPECT_TRUE(VerifyRtxReceiveAssociations(recv_stream->GetConfig())) |
| << "RTX should be mapped for all decoders/payload types."; |
| EXPECT_TRUE(HasRtxReceiveAssociation(recv_stream->GetConfig(), |
| GetEngineCodec("red").id)) |
| << "RTX should be mapped for the RED payload type"; |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, RecvStreamNoRtx) { |
| // Setup one channel without an associated RTX stream. |
| cricket::StreamParams params = |
| cricket::StreamParams::CreateLegacy(kSsrcs1[0]); |
| FakeVideoReceiveStream* recv_stream = AddRecvStream(params); |
| ASSERT_EQ(0U, recv_stream->GetConfig().rtp.rtx_ssrc); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, NoHeaderExtesionsByDefault) { |
| FakeVideoSendStream* send_stream = |
| AddSendStream(cricket::StreamParams::CreateLegacy(kSsrcs1[0])); |
| ASSERT_TRUE(send_stream->GetConfig().rtp.extensions.empty()); |
| |
| FakeVideoReceiveStream* recv_stream = |
| AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrcs1[0])); |
| ASSERT_TRUE(recv_stream->GetConfig().rtp.extensions.empty()); |
| } |
| |
| // Test support for RTP timestamp offset header extension. |
| TEST_F(WebRtcVideoChannelTest, SendRtpTimestampOffsetHeaderExtensions) { |
| TestSetSendRtpHeaderExtensions(RtpExtension::kTimestampOffsetUri); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, RecvRtpTimestampOffsetHeaderExtensions) { |
| TestSetRecvRtpHeaderExtensions(RtpExtension::kTimestampOffsetUri); |
| } |
| |
| // Test support for absolute send time header extension. |
| TEST_F(WebRtcVideoChannelTest, SendAbsoluteSendTimeHeaderExtensions) { |
| TestSetSendRtpHeaderExtensions(RtpExtension::kAbsSendTimeUri); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, RecvAbsoluteSendTimeHeaderExtensions) { |
| TestSetRecvRtpHeaderExtensions(RtpExtension::kAbsSendTimeUri); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, FiltersExtensionsPicksTransportSeqNum) { |
| // Enable three redundant extensions. |
| std::vector<std::string> extensions; |
| extensions.push_back(RtpExtension::kAbsSendTimeUri); |
| extensions.push_back(RtpExtension::kTimestampOffsetUri); |
| extensions.push_back(RtpExtension::kTransportSequenceNumberUri); |
| TestExtensionFilter(extensions, RtpExtension::kTransportSequenceNumberUri); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, FiltersExtensionsPicksAbsSendTime) { |
| // Enable two redundant extensions. |
| std::vector<std::string> extensions; |
| extensions.push_back(RtpExtension::kAbsSendTimeUri); |
| extensions.push_back(RtpExtension::kTimestampOffsetUri); |
| TestExtensionFilter(extensions, RtpExtension::kAbsSendTimeUri); |
| } |
| |
| // Test support for transport sequence number header extension. |
| TEST_F(WebRtcVideoChannelTest, SendTransportSequenceNumberHeaderExtensions) { |
| TestSetSendRtpHeaderExtensions(RtpExtension::kTransportSequenceNumberUri); |
| } |
| TEST_F(WebRtcVideoChannelTest, RecvTransportSequenceNumberHeaderExtensions) { |
| TestSetRecvRtpHeaderExtensions(RtpExtension::kTransportSequenceNumberUri); |
| } |
| |
| // Test support for video rotation header extension. |
| TEST_F(WebRtcVideoChannelTest, SendVideoRotationHeaderExtensions) { |
| TestSetSendRtpHeaderExtensions(RtpExtension::kVideoRotationUri); |
| } |
| TEST_F(WebRtcVideoChannelTest, RecvVideoRotationHeaderExtensions) { |
| TestSetRecvRtpHeaderExtensions(RtpExtension::kVideoRotationUri); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, IdenticalSendExtensionsDoesntRecreateStream) { |
| const int kAbsSendTimeId = 1; |
| const int kVideoRotationId = 2; |
| send_parameters_.extensions.push_back( |
| RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeId)); |
| send_parameters_.extensions.push_back( |
| RtpExtension(RtpExtension::kVideoRotationUri, kVideoRotationId)); |
| |
| EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| FakeVideoSendStream* send_stream = |
| AddSendStream(cricket::StreamParams::CreateLegacy(123)); |
| |
| EXPECT_EQ(1, fake_call_->GetNumCreatedSendStreams()); |
| ASSERT_EQ(2u, send_stream->GetConfig().rtp.extensions.size()); |
| |
| // Setting the same extensions (even if in different order) shouldn't |
| // reallocate the stream. |
| std::reverse(send_parameters_.extensions.begin(), |
| send_parameters_.extensions.end()); |
| EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| |
| EXPECT_EQ(1, fake_call_->GetNumCreatedSendStreams()); |
| |
| // Setting different extensions should recreate the stream. |
| send_parameters_.extensions.resize(1); |
| EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| |
| EXPECT_EQ(2, fake_call_->GetNumCreatedSendStreams()); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, IdenticalRecvExtensionsDoesntRecreateStream) { |
| const int kTOffsetId = 1; |
| const int kAbsSendTimeId = 2; |
| const int kVideoRotationId = 3; |
| recv_parameters_.extensions.push_back( |
| RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeId)); |
| recv_parameters_.extensions.push_back( |
| RtpExtension(RtpExtension::kTimestampOffsetUri, kTOffsetId)); |
| recv_parameters_.extensions.push_back( |
| RtpExtension(RtpExtension::kVideoRotationUri, kVideoRotationId)); |
| |
| EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); |
| FakeVideoReceiveStream* recv_stream = |
| AddRecvStream(cricket::StreamParams::CreateLegacy(123)); |
| |
| EXPECT_EQ(1, fake_call_->GetNumCreatedReceiveStreams()); |
| ASSERT_EQ(3u, recv_stream->GetConfig().rtp.extensions.size()); |
| |
| // Setting the same extensions (even if in different order) shouldn't |
| // reallocate the stream. |
| std::reverse(recv_parameters_.extensions.begin(), |
| recv_parameters_.extensions.end()); |
| EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); |
| |
| EXPECT_EQ(1, fake_call_->GetNumCreatedReceiveStreams()); |
| |
| // Setting different extensions should recreate the stream. |
| recv_parameters_.extensions.resize(1); |
| EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); |
| |
| EXPECT_EQ(2, fake_call_->GetNumCreatedReceiveStreams()); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, |
| SetSendRtpHeaderExtensionsExcludeUnsupportedExtensions) { |
| const int kUnsupportedId = 1; |
| const int kTOffsetId = 2; |
| |
| send_parameters_.extensions.push_back( |
| RtpExtension(kUnsupportedExtensionName, kUnsupportedId)); |
| send_parameters_.extensions.push_back( |
| RtpExtension(RtpExtension::kTimestampOffsetUri, kTOffsetId)); |
| EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| FakeVideoSendStream* send_stream = |
| AddSendStream(cricket::StreamParams::CreateLegacy(123)); |
| |
| // Only timestamp offset extension is set to send stream, |
| // unsupported rtp extension is ignored. |
| ASSERT_EQ(1u, send_stream->GetConfig().rtp.extensions.size()); |
| EXPECT_STREQ(RtpExtension::kTimestampOffsetUri, |
| send_stream->GetConfig().rtp.extensions[0].uri.c_str()); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, |
| SetRecvRtpHeaderExtensionsExcludeUnsupportedExtensions) { |
| const int kUnsupportedId = 1; |
| const int kTOffsetId = 2; |
| |
| recv_parameters_.extensions.push_back( |
| RtpExtension(kUnsupportedExtensionName, kUnsupportedId)); |
| recv_parameters_.extensions.push_back( |
| RtpExtension(RtpExtension::kTimestampOffsetUri, kTOffsetId)); |
| EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); |
| FakeVideoReceiveStream* recv_stream = |
| AddRecvStream(cricket::StreamParams::CreateLegacy(123)); |
| |
| // Only timestamp offset extension is set to receive stream, |
| // unsupported rtp extension is ignored. |
| ASSERT_EQ(1u, recv_stream->GetConfig().rtp.extensions.size()); |
| EXPECT_STREQ(RtpExtension::kTimestampOffsetUri, |
| recv_stream->GetConfig().rtp.extensions[0].uri.c_str()); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, SetSendRtpHeaderExtensionsRejectsIncorrectIds) { |
| const int kIncorrectIds[] = {-2, -1, 0, 15, 16}; |
| for (size_t i = 0; i < arraysize(kIncorrectIds); ++i) { |
| send_parameters_.extensions.push_back( |
| RtpExtension(RtpExtension::kTimestampOffsetUri, kIncorrectIds[i])); |
| EXPECT_FALSE(channel_->SetSendParameters(send_parameters_)) |
| << "Bad extension id '" << kIncorrectIds[i] << "' accepted."; |
| } |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, SetRecvRtpHeaderExtensionsRejectsIncorrectIds) { |
| const int kIncorrectIds[] = {-2, -1, 0, 15, 16}; |
| for (size_t i = 0; i < arraysize(kIncorrectIds); ++i) { |
| recv_parameters_.extensions.push_back( |
| RtpExtension(RtpExtension::kTimestampOffsetUri, kIncorrectIds[i])); |
| EXPECT_FALSE(channel_->SetRecvParameters(recv_parameters_)) |
| << "Bad extension id '" << kIncorrectIds[i] << "' accepted."; |
| } |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, SetSendRtpHeaderExtensionsRejectsDuplicateIds) { |
| const int id = 1; |
| send_parameters_.extensions.push_back( |
| RtpExtension(RtpExtension::kTimestampOffsetUri, id)); |
| send_parameters_.extensions.push_back( |
| RtpExtension(RtpExtension::kAbsSendTimeUri, id)); |
| EXPECT_FALSE(channel_->SetSendParameters(send_parameters_)); |
| |
| // Duplicate entries are also not supported. |
| send_parameters_.extensions.clear(); |
| send_parameters_.extensions.push_back( |
| RtpExtension(RtpExtension::kTimestampOffsetUri, id)); |
| send_parameters_.extensions.push_back(send_parameters_.extensions.back()); |
| EXPECT_FALSE(channel_->SetSendParameters(send_parameters_)); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, SetRecvRtpHeaderExtensionsRejectsDuplicateIds) { |
| const int id = 1; |
| recv_parameters_.extensions.push_back( |
| RtpExtension(RtpExtension::kTimestampOffsetUri, id)); |
| recv_parameters_.extensions.push_back( |
| RtpExtension(RtpExtension::kAbsSendTimeUri, id)); |
| EXPECT_FALSE(channel_->SetRecvParameters(recv_parameters_)); |
| |
| // Duplicate entries are also not supported. |
| recv_parameters_.extensions.clear(); |
| recv_parameters_.extensions.push_back( |
| RtpExtension(RtpExtension::kTimestampOffsetUri, id)); |
| recv_parameters_.extensions.push_back(recv_parameters_.extensions.back()); |
| EXPECT_FALSE(channel_->SetRecvParameters(recv_parameters_)); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, AddRecvStreamOnlyUsesOneReceiveStream) { |
| EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); |
| EXPECT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, RtcpIsCompoundByDefault) { |
| FakeVideoReceiveStream* stream = AddRecvStream(); |
| EXPECT_EQ(webrtc::RtcpMode::kCompound, stream->GetConfig().rtp.rtcp_mode); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, RembIsEnabledByDefault) { |
| FakeVideoReceiveStream* stream = AddRecvStream(); |
| EXPECT_TRUE(stream->GetConfig().rtp.remb); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, TransportCcIsEnabledByDefault) { |
| FakeVideoReceiveStream* stream = AddRecvStream(); |
| EXPECT_TRUE(stream->GetConfig().rtp.transport_cc); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, RembCanBeEnabledAndDisabled) { |
| FakeVideoReceiveStream* stream = AddRecvStream(); |
| EXPECT_TRUE(stream->GetConfig().rtp.remb); |
| |
| // Verify that REMB is turned off when send(!) codecs without REMB are set. |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(RemoveFeedbackParams(GetEngineCodec("VP8"))); |
| EXPECT_TRUE(parameters.codecs[0].feedback_params.params().empty()); |
| EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| stream = fake_call_->GetVideoReceiveStreams()[0]; |
| EXPECT_FALSE(stream->GetConfig().rtp.remb); |
| |
| // Verify that REMB is turned on when setting default codecs since the |
| // default codecs have REMB enabled. |
| parameters.codecs = engine_.codecs(); |
| EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| stream = fake_call_->GetVideoReceiveStreams()[0]; |
| EXPECT_TRUE(stream->GetConfig().rtp.remb); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, TransportCcCanBeEnabledAndDisabled) { |
| FakeVideoReceiveStream* stream = AddRecvStream(); |
| EXPECT_TRUE(stream->GetConfig().rtp.transport_cc); |
| |
| // Verify that transport cc feedback is turned off when send(!) codecs without |
| // transport cc feedback are set. |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(RemoveFeedbackParams(GetEngineCodec("VP8"))); |
| EXPECT_TRUE(parameters.codecs[0].feedback_params.params().empty()); |
| EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| stream = fake_call_->GetVideoReceiveStreams()[0]; |
| EXPECT_FALSE(stream->GetConfig().rtp.transport_cc); |
| |
| // Verify that transport cc feedback is turned on when setting default codecs |
| // since the default codecs have transport cc feedback enabled. |
| parameters.codecs = engine_.codecs(); |
| EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| stream = fake_call_->GetVideoReceiveStreams()[0]; |
| EXPECT_TRUE(stream->GetConfig().rtp.transport_cc); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, NackIsEnabledByDefault) { |
| VerifyCodecHasDefaultFeedbackParams(default_codec_); |
| |
| cricket::VideoSendParameters parameters; |
| parameters.codecs = engine_.codecs(); |
| EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| EXPECT_TRUE(channel_->SetSend(true)); |
| |
| // Send side. |
| FakeVideoSendStream* send_stream = |
| AddSendStream(cricket::StreamParams::CreateLegacy(1)); |
| EXPECT_GT(send_stream->GetConfig().rtp.nack.rtp_history_ms, 0); |
| |
| // Receiver side. |
| FakeVideoReceiveStream* recv_stream = |
| AddRecvStream(cricket::StreamParams::CreateLegacy(1)); |
| EXPECT_GT(recv_stream->GetConfig().rtp.nack.rtp_history_ms, 0); |
| |
| // Nack history size should match between sender and receiver. |
| EXPECT_EQ(send_stream->GetConfig().rtp.nack.rtp_history_ms, |
| recv_stream->GetConfig().rtp.nack.rtp_history_ms); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, NackCanBeEnabledAndDisabled) { |
| FakeVideoSendStream* send_stream = AddSendStream(); |
| FakeVideoReceiveStream* recv_stream = AddRecvStream(); |
| |
| EXPECT_GT(recv_stream->GetConfig().rtp.nack.rtp_history_ms, 0); |
| EXPECT_GT(send_stream->GetConfig().rtp.nack.rtp_history_ms, 0); |
| |
| // Verify that NACK is turned off when send(!) codecs without NACK are set. |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(RemoveFeedbackParams(GetEngineCodec("VP8"))); |
| EXPECT_TRUE(parameters.codecs[0].feedback_params.params().empty()); |
| EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| recv_stream = fake_call_->GetVideoReceiveStreams()[0]; |
| EXPECT_EQ(0, recv_stream->GetConfig().rtp.nack.rtp_history_ms); |
| send_stream = fake_call_->GetVideoSendStreams()[0]; |
| EXPECT_EQ(0, send_stream->GetConfig().rtp.nack.rtp_history_ms); |
| |
| // Verify that NACK is turned on when setting default codecs since the |
| // default codecs have NACK enabled. |
| parameters.codecs = engine_.codecs(); |
| EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| recv_stream = fake_call_->GetVideoReceiveStreams()[0]; |
| EXPECT_GT(recv_stream->GetConfig().rtp.nack.rtp_history_ms, 0); |
| send_stream = fake_call_->GetVideoSendStreams()[0]; |
| EXPECT_GT(send_stream->GetConfig().rtp.nack.rtp_history_ms, 0); |
| } |
| |
| // This test verifies that new frame sizes reconfigures encoders even though not |
| // (yet) sending. The purpose of this is to permit encoding as quickly as |
| // possible once we start sending. Likely the frames being input are from the |
| // same source that will be sent later, which just means that we're ready |
| // earlier. |
| TEST_F(WebRtcVideoChannelTest, ReconfiguresEncodersWhenNotSending) { |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(GetEngineCodec("VP8")); |
| ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| channel_->SetSend(false); |
| |
| FakeVideoSendStream* stream = AddSendStream(); |
| |
| // No frames entered. |
| std::vector<webrtc::VideoStream> streams = stream->GetVideoStreams(); |
| EXPECT_EQ(0u, streams[0].width); |
| EXPECT_EQ(0u, streams[0].height); |
| |
| cricket::FakeVideoCapturer capturer; |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, &capturer)); |
| VideoFormat capture_format = capturer.GetSupportedFormats()->front(); |
| EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format)); |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| |
| // Frame entered, should be reconfigured to new dimensions. |
| streams = stream->GetVideoStreams(); |
| EXPECT_EQ(capture_format.width, streams[0].width); |
| EXPECT_EQ(capture_format.height, streams[0].height); |
| |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, UsesCorrectSettingsForScreencast) { |
| static const int kScreenshareMinBitrateKbps = 800; |
| cricket::VideoCodec codec = GetEngineCodec("VP8"); |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(codec); |
| EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| AddSendStream(); |
| |
| cricket::FakeVideoCapturer capturer; |
| VideoOptions min_bitrate_options; |
| min_bitrate_options.screencast_min_bitrate_kbps = |
| rtc::Optional<int>(kScreenshareMinBitrateKbps); |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, &min_bitrate_options, |
| &capturer)); |
| cricket::VideoFormat capture_format_hd = |
| capturer.GetSupportedFormats()->front(); |
| EXPECT_EQ(1280, capture_format_hd.width); |
| EXPECT_EQ(720, capture_format_hd.height); |
| EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format_hd)); |
| |
| EXPECT_TRUE(channel_->SetSend(true)); |
| |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
| FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
| |
| EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
| |
| // Verify non-screencast settings. |
| webrtc::VideoEncoderConfig encoder_config = |
| send_stream->GetEncoderConfig().Copy(); |
| EXPECT_EQ(webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo, |
| encoder_config.content_type); |
| std::vector<webrtc::VideoStream> streams = send_stream->GetVideoStreams(); |
| EXPECT_EQ(capture_format_hd.width, streams.front().width); |
| EXPECT_EQ(capture_format_hd.height, streams.front().height); |
| EXPECT_EQ(0, encoder_config.min_transmit_bitrate_bps) |
| << "Non-screenshare shouldn't use min-transmit bitrate."; |
| |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); |
| EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
| VideoOptions screencast_options; |
| screencast_options.is_screencast = rtc::Optional<bool>(true); |
| EXPECT_TRUE( |
| channel_->SetVideoSend(last_ssrc_, true, &screencast_options, &capturer)); |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| // Send stream recreated after option change. |
| ASSERT_EQ(2, fake_call_->GetNumCreatedSendStreams()); |
| send_stream = fake_call_->GetVideoSendStreams().front(); |
| EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
| |
| // Verify screencast settings. |
| encoder_config = send_stream->GetEncoderConfig().Copy(); |
| EXPECT_EQ(webrtc::VideoEncoderConfig::ContentType::kScreen, |
| encoder_config.content_type); |
| EXPECT_EQ(kScreenshareMinBitrateKbps * 1000, |
| encoder_config.min_transmit_bitrate_bps); |
| |
| streams = send_stream->GetVideoStreams(); |
| EXPECT_EQ(capture_format_hd.width, streams.front().width); |
| EXPECT_EQ(capture_format_hd.height, streams.front().height); |
| EXPECT_TRUE(streams[0].temporal_layer_thresholds_bps.empty()); |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, |
| ConferenceModeScreencastConfiguresTemporalLayer) { |
| static const int kConferenceScreencastTemporalBitrateBps = |
| ScreenshareLayerConfig::GetDefault().tl0_bitrate_kbps * 1000; |
| send_parameters_.conference_mode = true; |
| channel_->SetSendParameters(send_parameters_); |
| |
| AddSendStream(); |
| VideoOptions options; |
| options.is_screencast = rtc::Optional<bool>(true); |
| cricket::FakeVideoCapturer capturer; |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, &options, &capturer)); |
| cricket::VideoFormat capture_format_hd = |
| capturer.GetSupportedFormats()->front(); |
| EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format_hd)); |
| |
| EXPECT_TRUE(channel_->SetSend(true)); |
| |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
| FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
| |
| webrtc::VideoEncoderConfig encoder_config = |
| send_stream->GetEncoderConfig().Copy(); |
| |
| // Verify screencast settings. |
| encoder_config = send_stream->GetEncoderConfig().Copy(); |
| EXPECT_EQ(webrtc::VideoEncoderConfig::ContentType::kScreen, |
| encoder_config.content_type); |
| |
| std::vector<webrtc::VideoStream> streams = send_stream->GetVideoStreams(); |
| ASSERT_EQ(1u, streams.size()); |
| ASSERT_EQ(1u, streams[0].temporal_layer_thresholds_bps.size()); |
| EXPECT_EQ(kConferenceScreencastTemporalBitrateBps, |
| streams[0].temporal_layer_thresholds_bps[0]); |
| |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, SuspendBelowMinBitrateDisabledByDefault) { |
| FakeVideoSendStream* stream = AddSendStream(); |
| EXPECT_FALSE(stream->GetConfig().suspend_below_min_bitrate); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, SetMediaConfigSuspendBelowMinBitrate) { |
| MediaConfig media_config = GetMediaConfig(); |
| media_config.video.suspend_below_min_bitrate = true; |
| |
| channel_.reset( |
| engine_.CreateChannel(fake_call_.get(), media_config, VideoOptions())); |
| channel_->OnReadyToSend(true); |
| |
| channel_->SetSendParameters(send_parameters_); |
| |
| FakeVideoSendStream* stream = AddSendStream(); |
| EXPECT_TRUE(stream->GetConfig().suspend_below_min_bitrate); |
| |
| media_config.video.suspend_below_min_bitrate = false; |
| channel_.reset( |
| engine_.CreateChannel(fake_call_.get(), media_config, VideoOptions())); |
| channel_->OnReadyToSend(true); |
| |
| channel_->SetSendParameters(send_parameters_); |
| |
| stream = AddSendStream(); |
| EXPECT_FALSE(stream->GetConfig().suspend_below_min_bitrate); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, Vp8DenoisingEnabledByDefault) { |
| FakeVideoSendStream* stream = AddSendStream(); |
| webrtc::VideoCodecVP8 vp8_settings; |
| ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; |
| EXPECT_TRUE(vp8_settings.denoisingOn); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, VerifyVp8SpecificSettings) { |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(GetEngineCodec("VP8")); |
| ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| |
| // Single-stream settings should apply with RTX as well (verifies that we |
| // check number of regular SSRCs and not StreamParams::ssrcs which contains |
| // both RTX and regular SSRCs). |
| FakeVideoSendStream* stream = SetUpSimulcast(false, true); |
| |
| cricket::FakeVideoCapturer capturer; |
| EXPECT_EQ(cricket::CS_RUNNING, |
| capturer.Start(capturer.GetSupportedFormats()->front())); |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, &capturer)); |
| channel_->SetSend(true); |
| |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| |
| webrtc::VideoCodecVP8 vp8_settings; |
| ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; |
| EXPECT_TRUE(vp8_settings.denoisingOn) |
| << "VP8 denoising should be on by default."; |
| |
| stream = SetDenoisingOption(last_ssrc_, &capturer, false); |
| |
| ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; |
| EXPECT_FALSE(vp8_settings.denoisingOn); |
| EXPECT_TRUE(vp8_settings.automaticResizeOn); |
| EXPECT_TRUE(vp8_settings.frameDroppingOn); |
| |
| stream = SetDenoisingOption(last_ssrc_, &capturer, true); |
| |
| ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; |
| EXPECT_TRUE(vp8_settings.denoisingOn); |
| EXPECT_TRUE(vp8_settings.automaticResizeOn); |
| EXPECT_TRUE(vp8_settings.frameDroppingOn); |
| |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); |
| stream = SetUpSimulcast(true, false); |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, &capturer)); |
| channel_->SetSend(true); |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| |
| EXPECT_EQ(3, stream->GetVideoStreams().size()); |
| ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; |
| // Autmatic resize off when using simulcast. |
| EXPECT_FALSE(vp8_settings.automaticResizeOn); |
| EXPECT_TRUE(vp8_settings.frameDroppingOn); |
| |
| // In screen-share mode, denoising is forced off and simulcast disabled. |
| VideoOptions options; |
| options.is_screencast = rtc::Optional<bool>(true); |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, &options, &capturer)); |
| |
| stream = SetDenoisingOption(last_ssrc_, &capturer, false); |
| |
| EXPECT_EQ(1, stream->GetVideoStreams().size()); |
| ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; |
| EXPECT_FALSE(vp8_settings.denoisingOn); |
| // Resizing and frame dropping always off for screen sharing. |
| EXPECT_FALSE(vp8_settings.automaticResizeOn); |
| EXPECT_FALSE(vp8_settings.frameDroppingOn); |
| |
| stream = SetDenoisingOption(last_ssrc_, &capturer, true); |
| |
| ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; |
| EXPECT_FALSE(vp8_settings.denoisingOn); |
| EXPECT_FALSE(vp8_settings.automaticResizeOn); |
| EXPECT_FALSE(vp8_settings.frameDroppingOn); |
| |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); |
| } |
| |
| // Test that setting the same options doesn't result in the encoder being |
| // reconfigured. |
| TEST_F(WebRtcVideoChannelTest, SetIdenticalOptionsDoesntReconfigureEncoder) { |
| VideoOptions options; |
| cricket::FakeVideoCapturer capturer; |
| |
| AddSendStream(); |
| EXPECT_EQ(cricket::CS_RUNNING, |
| capturer.Start(capturer.GetSupportedFormats()->front())); |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(GetEngineCodec("VP8")); |
| ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
| |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, &options, &capturer)); |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, &options, &capturer)); |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| // Expect 1 reconfigurations at this point from the initial configuration. |
| EXPECT_EQ(1, send_stream->num_encoder_reconfigurations()); |
| |
| // Set the options one more time and expect no additional reconfigurations. |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, &options, &capturer)); |
| EXPECT_EQ(1, send_stream->num_encoder_reconfigurations()); |
| |
| // Change |options| and expect 2 reconfigurations. |
| options.video_noise_reduction = rtc::Optional<bool>(true); |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, &options, &capturer)); |
| EXPECT_EQ(2, send_stream->num_encoder_reconfigurations()); |
| |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); |
| } |
| |
| class Vp9SettingsTest : public WebRtcVideoChannelTest { |
| public: |
| Vp9SettingsTest() : Vp9SettingsTest("") {} |
| explicit Vp9SettingsTest(const char* field_trials) |
| : WebRtcVideoChannelTest(field_trials) { |
| encoder_factory_.AddSupportedVideoCodecType("VP9"); |
| } |
| virtual ~Vp9SettingsTest() {} |
| |
| protected: |
| void SetUp() override { |
| engine_.SetExternalEncoderFactory(&encoder_factory_); |
| |
| WebRtcVideoChannelTest::SetUp(); |
| } |
| |
| void TearDown() override { |
| // Remove references to encoder_factory_ since this will be destroyed |
| // before channel_ and engine_. |
| ASSERT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| } |
| |
| cricket::FakeWebRtcVideoEncoderFactory encoder_factory_; |
| }; |
| |
| TEST_F(Vp9SettingsTest, VerifyVp9SpecificSettings) { |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(GetEngineCodec("VP9")); |
| ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| |
| FakeVideoSendStream* stream = SetUpSimulcast(false, false); |
| |
| cricket::FakeVideoCapturer capturer; |
| EXPECT_EQ(cricket::CS_RUNNING, |
| capturer.Start(capturer.GetSupportedFormats()->front())); |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, &capturer)); |
| channel_->SetSend(true); |
| |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| |
| webrtc::VideoCodecVP9 vp9_settings; |
| ASSERT_TRUE(stream->GetVp9Settings(&vp9_settings)) << "No VP9 config set."; |
| EXPECT_TRUE(vp9_settings.denoisingOn) |
| << "VP9 denoising should be on by default."; |
| |
| stream = SetDenoisingOption(last_ssrc_, &capturer, false); |
| |
| ASSERT_TRUE(stream->GetVp9Settings(&vp9_settings)) << "No VP9 config set."; |
| EXPECT_FALSE(vp9_settings.denoisingOn); |
| // Frame dropping always on for real time video. |
| EXPECT_TRUE(vp9_settings.frameDroppingOn); |
| |
| stream = SetDenoisingOption(last_ssrc_, &capturer, true); |
| |
| ASSERT_TRUE(stream->GetVp9Settings(&vp9_settings)) << "No VP9 config set."; |
| EXPECT_TRUE(vp9_settings.denoisingOn); |
| EXPECT_TRUE(vp9_settings.frameDroppingOn); |
| |
| // In screen-share mode, denoising is forced off. |
| VideoOptions options; |
| options.is_screencast = rtc::Optional<bool>(true); |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, &options, &capturer)); |
| |
| stream = SetDenoisingOption(last_ssrc_, &capturer, false); |
| |
| ASSERT_TRUE(stream->GetVp9Settings(&vp9_settings)) << "No VP9 config set."; |
| EXPECT_FALSE(vp9_settings.denoisingOn); |
| // Frame dropping always off for screen sharing. |
| EXPECT_FALSE(vp9_settings.frameDroppingOn); |
| |
| stream = SetDenoisingOption(last_ssrc_, &capturer, false); |
| |
| ASSERT_TRUE(stream->GetVp9Settings(&vp9_settings)) << "No VP9 config set."; |
| EXPECT_FALSE(vp9_settings.denoisingOn); |
| EXPECT_FALSE(vp9_settings.frameDroppingOn); |
| |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); |
| } |
| |
| class Vp9SettingsTestWithFieldTrial : public Vp9SettingsTest { |
| public: |
| explicit Vp9SettingsTestWithFieldTrial(const char* field_trials) |
| : Vp9SettingsTest(field_trials) {} |
| |
| protected: |
| void VerifySettings(int num_spatial_layers, int num_temporal_layers) { |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(GetEngineCodec("VP9")); |
| ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| |
| FakeVideoSendStream* stream = SetUpSimulcast(false, false); |
| |
| cricket::FakeVideoCapturer capturer; |
| EXPECT_EQ(cricket::CS_RUNNING, |
| capturer.Start(capturer.GetSupportedFormats()->front())); |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, &capturer)); |
| channel_->SetSend(true); |
| |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| |
| webrtc::VideoCodecVP9 vp9_settings; |
| ASSERT_TRUE(stream->GetVp9Settings(&vp9_settings)) << "No VP9 config set."; |
| EXPECT_EQ(num_spatial_layers, vp9_settings.numberOfSpatialLayers); |
| EXPECT_EQ(num_temporal_layers, vp9_settings.numberOfTemporalLayers); |
| |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); |
| } |
| }; |
| |
| class Vp9SettingsTestWithNoFlag : public Vp9SettingsTestWithFieldTrial { |
| public: |
| Vp9SettingsTestWithNoFlag() : Vp9SettingsTestWithFieldTrial("") {} |
| }; |
| |
| TEST_F(Vp9SettingsTestWithNoFlag, VerifySettings) { |
| const int kNumSpatialLayers = 1; |
| const int kNumTemporalLayers = 1; |
| VerifySettings(kNumSpatialLayers, kNumTemporalLayers); |
| } |
| |
| class Vp9SettingsTestWithInvalidFlag : public Vp9SettingsTestWithFieldTrial { |
| public: |
| Vp9SettingsTestWithInvalidFlag() |
| : Vp9SettingsTestWithFieldTrial("WebRTC-SupportVP9SVC/Default/") {} |
| }; |
| |
| TEST_F(Vp9SettingsTestWithInvalidFlag, VerifySettings) { |
| const int kNumSpatialLayers = 1; |
| const int kNumTemporalLayers = 1; |
| VerifySettings(kNumSpatialLayers, kNumTemporalLayers); |
| } |
| |
| class Vp9SettingsTestWith2SL3TLFlag : public Vp9SettingsTestWithFieldTrial { |
| public: |
| Vp9SettingsTestWith2SL3TLFlag() |
| : Vp9SettingsTestWithFieldTrial( |
| "WebRTC-SupportVP9SVC/EnabledByFlag_2SL3TL/") {} |
| }; |
| |
| TEST_F(Vp9SettingsTestWith2SL3TLFlag, VerifySettings) { |
| const int kNumSpatialLayers = 2; |
| const int kNumTemporalLayers = 3; |
| VerifySettings(kNumSpatialLayers, kNumTemporalLayers); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, |
| BalancedDegradationPreferenceNotSupportedWithoutFieldtrial) { |
| webrtc::test::ScopedFieldTrials override_field_trials_( |
| "WebRTC-Video-BalancedDegradation/Disabled/"); |
| const bool kResolutionScalingEnabled = true; |
| const bool kFpsScalingEnabled = false; |
| TestDegradationPreference(kResolutionScalingEnabled, kFpsScalingEnabled); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, |
| BalancedDegradationPreferenceSupportedBehindFieldtrial) { |
| webrtc::test::ScopedFieldTrials override_field_trials_( |
| "WebRTC-Video-BalancedDegradation/Enabled/"); |
| const bool kResolutionScalingEnabled = true; |
| const bool kFpsScalingEnabled = true; |
| TestDegradationPreference(kResolutionScalingEnabled, kFpsScalingEnabled); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, AdaptsOnOveruse) { |
| TestCpuAdaptation(true, false); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, DoesNotAdaptOnOveruseWhenDisabled) { |
| TestCpuAdaptation(false, false); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, DoesNotAdaptOnOveruseWhenScreensharing) { |
| TestCpuAdaptation(true, true); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, AdaptsOnOveruseAndChangeResolution) { |
| cricket::VideoCodec codec = GetEngineCodec("VP8"); |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(codec); |
| |
| MediaConfig media_config = GetMediaConfig(); |
| channel_.reset( |
| engine_.CreateChannel(fake_call_.get(), media_config, VideoOptions())); |
| channel_->OnReadyToSend(true); |
| ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| |
| AddSendStream(); |
| |
| cricket::FakeVideoCapturer capturer; |
| ASSERT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, &capturer)); |
| ASSERT_EQ(cricket::CS_RUNNING, |
| capturer.Start(capturer.GetSupportedFormats()->front())); |
| ASSERT_TRUE(channel_->SetSend(true)); |
| |
| ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
| FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
| |
| EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); |
| EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
| EXPECT_EQ(1280, send_stream->GetLastWidth()); |
| EXPECT_EQ(720, send_stream->GetLastHeight()); |
| |
| // Trigger overuse. |
| rtc::VideoSinkWants wants; |
| wants.max_pixel_count = |
| send_stream->GetLastWidth() * send_stream->GetLastHeight() - 1; |
| send_stream->InjectVideoSinkWants(wants); |
| EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); |
| EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames()); |
| EXPECT_EQ(1280 * 3 / 4, send_stream->GetLastWidth()); |
| EXPECT_EQ(720 * 3 / 4, send_stream->GetLastHeight()); |
| |
| // Trigger overuse again. |
| wants.max_pixel_count = |
| send_stream->GetLastWidth() * send_stream->GetLastHeight() - 1; |
| send_stream->InjectVideoSinkWants(wants); |
| EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); |
| EXPECT_EQ(3, send_stream->GetNumberOfSwappedFrames()); |
| EXPECT_EQ(1280 * 2 / 4, send_stream->GetLastWidth()); |
| EXPECT_EQ(720 * 2 / 4, send_stream->GetLastHeight()); |
| |
| // Change input resolution. |
| EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724, cricket::FOURCC_I420)); |
| EXPECT_EQ(4, send_stream->GetNumberOfSwappedFrames()); |
| EXPECT_EQ(1284 / 2, send_stream->GetLastWidth()); |
| EXPECT_EQ(724 / 2, send_stream->GetLastHeight()); |
| |
| // Trigger underuse which should go back up in resolution. |
| int current_pixel_count = |
| send_stream->GetLastWidth() * send_stream->GetLastHeight(); |
| // Cap the max to 4x the pixel count (assuming max 1/2 x 1/2 scale downs) |
| // of the current stream, so we don't take too large steps. |
| wants.max_pixel_count = current_pixel_count * 4; |
| // Default step down is 3/5 pixel count, so go up by 5/3. |
| wants.target_pixel_count = rtc::Optional<int>((current_pixel_count * 5) / 3); |
| send_stream->InjectVideoSinkWants(wants); |
| EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724, cricket::FOURCC_I420)); |
| EXPECT_EQ(5, send_stream->GetNumberOfSwappedFrames()); |
| EXPECT_EQ(1284 * 3 / 4, send_stream->GetLastWidth()); |
| EXPECT_EQ(724 * 3 / 4, send_stream->GetLastHeight()); |
| |
| // Trigger underuse again, should go back up to full resolution. |
| current_pixel_count = |
| send_stream->GetLastWidth() * send_stream->GetLastHeight(); |
| wants.max_pixel_count = current_pixel_count * 4; |
| wants.target_pixel_count = rtc::Optional<int>((current_pixel_count * 5) / 3); |
| send_stream->InjectVideoSinkWants(wants); |
| EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724, cricket::FOURCC_I420)); |
| EXPECT_EQ(6, send_stream->GetNumberOfSwappedFrames()); |
| EXPECT_EQ(1284, send_stream->GetLastWidth()); |
| EXPECT_EQ(724, send_stream->GetLastHeight()); |
| |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, PreviousAdaptationDoesNotApplyToScreenshare) { |
| cricket::VideoCodec codec = GetEngineCodec("VP8"); |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(codec); |
| |
| MediaConfig media_config = GetMediaConfig(); |
| media_config.video.enable_cpu_overuse_detection = true; |
| channel_.reset( |
| engine_.CreateChannel(fake_call_.get(), media_config, VideoOptions())); |
| channel_->OnReadyToSend(true); |
| ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| |
| AddSendStream(); |
| |
| cricket::FakeVideoCapturer capturer; |
| ASSERT_EQ(cricket::CS_RUNNING, |
| capturer.Start(capturer.GetSupportedFormats()->front())); |
| ASSERT_TRUE(channel_->SetSend(true)); |
| cricket::VideoOptions camera_options; |
| camera_options.is_screencast = rtc::Optional<bool>(false); |
| channel_->SetVideoSend(last_ssrc_, true /* enable */, &camera_options, |
| &capturer); |
| |
| ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
| FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
| |
| EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); |
| EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
| EXPECT_EQ(1280, send_stream->GetLastWidth()); |
| EXPECT_EQ(720, send_stream->GetLastHeight()); |
| |
| // Trigger overuse. |
| rtc::VideoSinkWants wants; |
| wants.max_pixel_count = |
| send_stream->GetLastWidth() * send_stream->GetLastHeight() - 1; |
| send_stream->InjectVideoSinkWants(wants); |
| EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); |
| EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames()); |
| EXPECT_EQ(1280 * 3 / 4, send_stream->GetLastWidth()); |
| EXPECT_EQ(720 * 3 / 4, send_stream->GetLastHeight()); |
| |
| // Switch to screen share. Expect no CPU adaptation. |
| cricket::FakeVideoCapturer screen_share(true); |
| ASSERT_EQ(cricket::CS_RUNNING, |
| screen_share.Start(screen_share.GetSupportedFormats()->front())); |
| cricket::VideoOptions screenshare_options; |
| screenshare_options.is_screencast = rtc::Optional<bool>(true); |
| channel_->SetVideoSend(last_ssrc_, true /* enable */, &screenshare_options, |
| &screen_share); |
| EXPECT_TRUE(screen_share.CaptureCustomFrame(1284, 724, cricket::FOURCC_I420)); |
| ASSERT_EQ(2, fake_call_->GetNumCreatedSendStreams()); |
| send_stream = fake_call_->GetVideoSendStreams().front(); |
| EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
| EXPECT_EQ(1284, send_stream->GetLastWidth()); |
| EXPECT_EQ(724, send_stream->GetLastHeight()); |
| |
| // Switch back to the normal capturer. Expect the frame to be CPU adapted. |
| channel_->SetVideoSend(last_ssrc_, true /* enable */, &camera_options, |
| &capturer); |
| send_stream = fake_call_->GetVideoSendStreams().front(); |
| // We have a new fake send stream, so it doesn't remember the old sink wants. |
| // In practice, it will be populated from |
| // VideoStreamEncoder::VideoSourceProxy::SetSource(), so simulate that here. |
| send_stream->InjectVideoSinkWants(wants); |
| EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720, cricket::FOURCC_I420)); |
| ASSERT_EQ(3, fake_call_->GetNumCreatedSendStreams()); |
| send_stream = fake_call_->GetVideoSendStreams().front(); |
| EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
| EXPECT_EQ(1280 * 3 / 4, send_stream->GetLastWidth()); |
| EXPECT_EQ(720 * 3 / 4, send_stream->GetLastHeight()); |
| |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); |
| } |
| |
| // TODO(asapersson): Remove this test when the balanced field trial is removed. |
| void WebRtcVideoChannelTest::TestDegradationPreference( |
| bool resolution_scaling_enabled, |
| bool fps_scaling_enabled) { |
| cricket::VideoCodec codec = GetEngineCodec("VP8"); |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(codec); |
| |
| MediaConfig media_config = GetMediaConfig(); |
| media_config.video.enable_cpu_overuse_detection = true; |
| channel_.reset( |
| engine_.CreateChannel(fake_call_.get(), media_config, VideoOptions())); |
| channel_->OnReadyToSend(true); |
| |
| EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| |
| AddSendStream(); |
| |
| cricket::FakeVideoCapturer capturer; |
| VideoOptions options; |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, &options, &capturer)); |
| cricket::VideoFormat capture_format = capturer.GetSupportedFormats()->front(); |
| EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format)); |
| |
| EXPECT_TRUE(channel_->SetSend(true)); |
| |
| FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
| EXPECT_EQ(resolution_scaling_enabled, |
| send_stream->resolution_scaling_enabled()); |
| EXPECT_EQ(fps_scaling_enabled, send_stream->framerate_scaling_enabled()); |
| |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); |
| } |
| |
| void WebRtcVideoChannelTest::TestCpuAdaptation(bool enable_overuse, |
| bool is_screenshare) { |
| const int kDefaultFps = 30; |
| cricket::VideoCodec codec = GetEngineCodec("VP8"); |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(codec); |
| |
| MediaConfig media_config = GetMediaConfig(); |
| if (enable_overuse) { |
| media_config.video.enable_cpu_overuse_detection = true; |
| } |
| channel_.reset( |
| engine_.CreateChannel(fake_call_.get(), media_config, VideoOptions())); |
| channel_->OnReadyToSend(true); |
| |
| EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| |
| AddSendStream(); |
| |
| cricket::FakeVideoCapturer capturer; |
| VideoOptions options; |
| options.is_screencast = rtc::Optional<bool>(is_screenshare); |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, &options, &capturer)); |
| cricket::VideoFormat capture_format = capturer.GetSupportedFormats()->front(); |
| capture_format.interval = rtc::kNumNanosecsPerSec / kDefaultFps; |
| EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format)); |
| |
| EXPECT_TRUE(channel_->SetSend(true)); |
| |
| FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
| |
| if (!enable_overuse) { |
| EXPECT_FALSE(send_stream->resolution_scaling_enabled()); |
| EXPECT_FALSE(send_stream->framerate_scaling_enabled()); |
| EXPECT_EQ(is_screenshare, send_stream->framerate_scaling_enabled()); |
| |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
| |
| EXPECT_EQ(capture_format.width, send_stream->GetLastWidth()); |
| EXPECT_EQ(capture_format.height, send_stream->GetLastHeight()); |
| |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); |
| return; |
| } |
| |
| if (is_screenshare) { |
| EXPECT_FALSE(send_stream->resolution_scaling_enabled()); |
| EXPECT_TRUE(send_stream->framerate_scaling_enabled()); |
| } else { |
| EXPECT_TRUE(send_stream->resolution_scaling_enabled()); |
| EXPECT_FALSE(send_stream->framerate_scaling_enabled()); |
| } |
| |
| // Trigger overuse. |
| ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
| |
| rtc::VideoSinkWants wants; |
| if (is_screenshare) { |
| wants.max_framerate_fps = (kDefaultFps * 2) / 3; |
| } else { |
| wants.max_pixel_count = capture_format.width * capture_format.height - 1; |
| } |
| send_stream->InjectVideoSinkWants(wants); |
| |
| for (int i = 0; i < kDefaultFps; ++i) |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| |
| if (is_screenshare) { |
| // Drops every third frame. |
| EXPECT_EQ(kDefaultFps * 2 / 3, send_stream->GetNumberOfSwappedFrames()); |
| EXPECT_EQ(send_stream->GetLastWidth(), capture_format.width); |
| EXPECT_EQ(send_stream->GetLastHeight(), capture_format.height); |
| } else { |
| EXPECT_EQ(kDefaultFps, send_stream->GetNumberOfSwappedFrames()); |
| EXPECT_LT(send_stream->GetLastWidth(), capture_format.width); |
| EXPECT_LT(send_stream->GetLastHeight(), capture_format.height); |
| } |
| |
| // Trigger underuse which should go back to normal resolution. |
| int last_pixel_count = |
| send_stream->GetLastWidth() * send_stream->GetLastHeight(); |
| if (is_screenshare) { |
| wants.max_framerate_fps = kDefaultFps; |
| } else { |
| wants.max_pixel_count = last_pixel_count * 4; |
| wants.target_pixel_count.emplace((last_pixel_count * 5) / 3); |
| } |
| send_stream->InjectVideoSinkWants(wants); |
| |
| for (int i = 0; i < kDefaultFps; ++i) |
| EXPECT_TRUE(capturer.CaptureFrame()); |
| |
| if (is_screenshare) { |
| EXPECT_EQ(kDefaultFps + (kDefaultFps * 2 / 3), |
| send_stream->GetNumberOfSwappedFrames()); |
| } else { |
| EXPECT_EQ(kDefaultFps * 2, send_stream->GetNumberOfSwappedFrames()); |
| } |
| |
| EXPECT_EQ(capture_format.width, send_stream->GetLastWidth()); |
| EXPECT_EQ(capture_format.height, send_stream->GetLastHeight()); |
| |
| EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, true, nullptr, nullptr)); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, EstimatesNtpStartTimeCorrectly) { |
| // Start at last timestamp to verify that wraparounds are estimated correctly. |
| static const uint32_t kInitialTimestamp = 0xFFFFFFFFu; |
| static const int64_t kInitialNtpTimeMs = 1247891230; |
| static const int kFrameOffsetMs = 20; |
| EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); |
| |
| FakeVideoReceiveStream* stream = AddRecvStream(); |
| cricket::FakeVideoRenderer renderer; |
| EXPECT_TRUE(channel_->SetSink(last_ssrc_, &renderer)); |
| |
| webrtc::VideoFrame video_frame(CreateBlackFrameBuffer(4, 4), |
| kInitialTimestamp, 0, |
| webrtc::kVideoRotation_0); |
| // Initial NTP time is not available on the first frame, but should still be |
| // able to be estimated. |
| stream->InjectFrame(video_frame); |
| |
| EXPECT_EQ(1, renderer.num_rendered_frames()); |
| |
| // This timestamp is kInitialTimestamp (-1) + kFrameOffsetMs * 90, which |
| // triggers a constant-overflow warning, hence we're calculating it explicitly |
| // here. |
| video_frame.set_timestamp(kFrameOffsetMs * 90 - 1); |
| video_frame.set_ntp_time_ms(kInitialNtpTimeMs + kFrameOffsetMs); |
| stream->InjectFrame(video_frame); |
| |
| EXPECT_EQ(2, renderer.num_rendered_frames()); |
| |
| // Verify that NTP time has been correctly deduced. |
| cricket::VideoMediaInfo info; |
| ASSERT_TRUE(channel_->GetStats(&info)); |
| ASSERT_EQ(1u, info.receivers.size()); |
| EXPECT_EQ(kInitialNtpTimeMs, info.receivers[0].capture_start_ntp_time_ms); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, SetDefaultSendCodecs) { |
| ASSERT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| |
| VideoCodec codec; |
| EXPECT_TRUE(channel_->GetSendCodec(&codec)); |
| EXPECT_TRUE(codec.Matches(engine_.codecs()[0])); |
| |
| // Using a RTX setup to verify that the default RTX payload type is good. |
| const std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs1); |
| const std::vector<uint32_t> rtx_ssrcs = MAKE_VECTOR(kRtxSsrcs1); |
| FakeVideoSendStream* stream = AddSendStream( |
| cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs)); |
| webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| |
| // Make sure NACK and FEC are enabled on the correct payload types. |
| EXPECT_EQ(1000, config.rtp.nack.rtp_history_ms); |
| EXPECT_EQ(GetEngineCodec("ulpfec").id, config.rtp.ulpfec.ulpfec_payload_type); |
| EXPECT_EQ(GetEngineCodec("red").id, config.rtp.ulpfec.red_payload_type); |
| |
| EXPECT_EQ(1u, config.rtp.rtx.ssrcs.size()); |
| EXPECT_EQ(kRtxSsrcs1[0], config.rtp.rtx.ssrcs[0]); |
| VerifySendStreamHasRtxTypes(config, default_apt_rtx_types_); |
| // TODO(juberti): Check RTCP, PLI, TMMBR. |
| } |
| |
| // The following four tests ensures that FlexFEC is not activated by default |
| // when the field trials are not enabled. |
| // TODO(brandtr): Remove or update these tests when FlexFEC _is_ enabled by |
| // default. |
| TEST_F(WebRtcVideoChannelTest, |
| FlexfecSendCodecWithoutSsrcNotExposedByDefault) { |
| FakeVideoSendStream* stream = AddSendStream(); |
| webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| |
| EXPECT_EQ(-1, config.rtp.flexfec.payload_type); |
| EXPECT_EQ(0U, config.rtp.flexfec.ssrc); |
| EXPECT_TRUE(config.rtp.flexfec.protected_media_ssrcs.empty()); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, FlexfecSendCodecWithSsrcNotExposedByDefault) { |
| FakeVideoSendStream* stream = AddSendStream( |
| CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
| webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| |
| EXPECT_EQ(-1, config.rtp.flexfec.payload_type); |
| EXPECT_EQ(0U, config.rtp.flexfec.ssrc); |
| EXPECT_TRUE(config.rtp.flexfec.protected_media_ssrcs.empty()); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, |
| FlexfecRecvCodecWithoutSsrcNotExposedByDefault) { |
| AddRecvStream(); |
| |
| const std::vector<FakeFlexfecReceiveStream*>& streams = |
| fake_call_->GetFlexfecReceiveStreams(); |
| EXPECT_TRUE(streams.empty()); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, FlexfecRecvCodecWithSsrcNotExposedByDefault) { |
| AddRecvStream( |
| CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
| |
| const std::vector<FakeFlexfecReceiveStream*>& streams = |
| fake_call_->GetFlexfecReceiveStreams(); |
| EXPECT_TRUE(streams.empty()); |
| } |
| |
| // TODO(brandtr): When FlexFEC is no longer behind a field trial, merge all |
| // tests that use this test fixture into the corresponding "non-field trial" |
| // tests. |
| class WebRtcVideoChannelFlexfecRecvTest : public WebRtcVideoChannelTest { |
| public: |
| WebRtcVideoChannelFlexfecRecvTest() |
| : WebRtcVideoChannelTest("WebRTC-FlexFEC-03-Advertised/Enabled/") {} |
| }; |
| |
| TEST_F(WebRtcVideoChannelFlexfecRecvTest, |
| DefaultFlexfecCodecHasTransportCcAndRembFeedbackParam) { |
| EXPECT_TRUE(cricket::HasTransportCc(GetEngineCodec("flexfec-03"))); |
| EXPECT_TRUE(cricket::HasRemb(GetEngineCodec("flexfec-03"))); |
| } |
| |
| TEST_F(WebRtcVideoChannelFlexfecRecvTest, SetDefaultRecvCodecsWithoutSsrc) { |
| AddRecvStream(); |
| |
| const std::vector<FakeFlexfecReceiveStream*>& streams = |
| fake_call_->GetFlexfecReceiveStreams(); |
| EXPECT_TRUE(streams.empty()); |
| } |
| |
| TEST_F(WebRtcVideoChannelFlexfecRecvTest, SetDefaultRecvCodecsWithSsrc) { |
| AddRecvStream( |
| CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
| |
| const std::vector<FakeFlexfecReceiveStream*>& streams = |
| fake_call_->GetFlexfecReceiveStreams(); |
| ASSERT_EQ(1U, streams.size()); |
| const FakeFlexfecReceiveStream* stream = streams.front(); |
| const webrtc::FlexfecReceiveStream::Config& config = stream->GetConfig(); |
| EXPECT_EQ(GetEngineCodec("flexfec-03").id, config.payload_type); |
| EXPECT_EQ(kFlexfecSsrc, config.remote_ssrc); |
| ASSERT_EQ(1U, config.protected_media_ssrcs.size()); |
| EXPECT_EQ(kSsrcs1[0], config.protected_media_ssrcs[0]); |
| } |
| |
| TEST_F(WebRtcVideoChannelFlexfecRecvTest, |
| EnablingFlexfecDoesNotRecreateVideoReceiveStream) { |
| cricket::VideoRecvParameters recv_parameters; |
| recv_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| ASSERT_TRUE(channel_->SetRecvParameters(recv_parameters)); |
| |
| AddRecvStream( |
| CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
| EXPECT_EQ(1, fake_call_->GetNumCreatedReceiveStreams()); |
| EXPECT_EQ(1U, fake_call_->GetVideoReceiveStreams().size()); |
| |
| // Enable FlexFEC. |
| recv_parameters.codecs.push_back(GetEngineCodec("flexfec-03")); |
| ASSERT_TRUE(channel_->SetRecvParameters(recv_parameters)); |
| EXPECT_EQ(2, fake_call_->GetNumCreatedReceiveStreams()) |
| << "Enabling FlexFEC should create FlexfecReceiveStream."; |
| EXPECT_EQ(1U, fake_call_->GetVideoReceiveStreams().size()) |
| << "Enabling FlexFEC should not create VideoReceiveStream."; |
| EXPECT_EQ(1U, fake_call_->GetFlexfecReceiveStreams().size()) |
| << "Enabling FlexFEC should create a single FlexfecReceiveStream."; |
| } |
| |
| TEST_F(WebRtcVideoChannelFlexfecRecvTest, |
| DisablingFlexfecDoesNotRecreateVideoReceiveStream) { |
| cricket::VideoRecvParameters recv_parameters; |
| recv_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| recv_parameters.codecs.push_back(GetEngineCodec("flexfec-03")); |
| ASSERT_TRUE(channel_->SetRecvParameters(recv_parameters)); |
| |
| AddRecvStream( |
| CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
| EXPECT_EQ(2, fake_call_->GetNumCreatedReceiveStreams()); |
| EXPECT_EQ(1U, fake_call_->GetVideoReceiveStreams().size()); |
| EXPECT_EQ(1U, fake_call_->GetFlexfecReceiveStreams().size()); |
| |
| // Disable FlexFEC. |
| recv_parameters.codecs.clear(); |
| recv_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| ASSERT_TRUE(channel_->SetRecvParameters(recv_parameters)); |
| EXPECT_EQ(2, fake_call_->GetNumCreatedReceiveStreams()) |
| << "Disabling FlexFEC should not recreate VideoReceiveStream."; |
| EXPECT_EQ(1U, fake_call_->GetVideoReceiveStreams().size()) |
| << "Disabling FlexFEC should not destroy VideoReceiveStream."; |
| EXPECT_TRUE(fake_call_->GetFlexfecReceiveStreams().empty()) |
| << "Disabling FlexFEC should destroy FlexfecReceiveStream."; |
| } |
| |
| // TODO(brandtr): When FlexFEC is no longer behind a field trial, merge all |
| // tests that use this test fixture into the corresponding "non-field trial" |
| // tests. |
| class WebRtcVideoChannelFlexfecSendRecvTest : public WebRtcVideoChannelTest { |
| public: |
| WebRtcVideoChannelFlexfecSendRecvTest() |
| : WebRtcVideoChannelTest( |
| "WebRTC-FlexFEC-03-Advertised/Enabled/WebRTC-FlexFEC-03/Enabled/") { |
| } |
| }; |
| |
| TEST_F(WebRtcVideoChannelFlexfecSendRecvTest, |
| SetDefaultSendCodecsWithoutSsrc) { |
| FakeVideoSendStream* stream = AddSendStream(); |
| webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| |
| EXPECT_EQ(GetEngineCodec("flexfec-03").id, config.rtp.flexfec.payload_type); |
| EXPECT_EQ(0U, config.rtp.flexfec.ssrc); |
| EXPECT_TRUE(config.rtp.flexfec.protected_media_ssrcs.empty()); |
| } |
| |
| TEST_F(WebRtcVideoChannelFlexfecSendRecvTest, SetDefaultSendCodecsWithSsrc) { |
| FakeVideoSendStream* stream = AddSendStream( |
| CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
| webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| |
| EXPECT_EQ(GetEngineCodec("flexfec-03").id, config.rtp.flexfec.payload_type); |
| EXPECT_EQ(kFlexfecSsrc, config.rtp.flexfec.ssrc); |
| ASSERT_EQ(1U, config.rtp.flexfec.protected_media_ssrcs.size()); |
| EXPECT_EQ(kSsrcs1[0], config.rtp.flexfec.protected_media_ssrcs[0]); |
| } |
| |
| TEST_F(WebRtcVideoChannelTest, SetSendCodecsWithoutFec) { |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(GetEngineCodec("VP8")); |
| ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| |
| FakeVideoSendStream* stream = AddSendStream(); |
| webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| |
| EXPECT_EQ(-1, config.rtp.ulpfec.ulpfec_payload_type); |
| EXPECT_EQ(-1, config.rtp.ulpfec.red_payload_type); |
| } |
| |
| TEST_F(WebRtcVideoChannelFlexfecSendRecvTest, SetSendCodecsWithoutFec) { |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(GetEngineCodec("VP8")); |
| ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| |
| FakeVideoSendStream* stream = AddSendStream(); |
| webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| |
| EXPECT_EQ(-1, config.rtp.flexfec.payload_type); |
| } |
| |
| TEST_F(WebRtcVideoChannelFlexfecRecvTest, SetRecvCodecsWithFec) { |
| AddRecvStream( |
| CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
| |
| cricket::VideoRecvParameters recv_parameters; |
| recv_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| recv_parameters.codecs.push_back(GetEngineCodec("flexfec-03")); |
| ASSERT_TRUE(channel_->SetRecvParameters(recv_parameters)); |
| |
| const std::vector<FakeFlexfecReceiveStream*>& flexfec_streams = |
| fake_call_->GetFlexfecReceiveStreams(); |
| ASSERT_EQ(1U, flexfec_streams.size()); |
| const FakeFlexfecReceiveStream* flexfec_stream = flexfec_streams.front(); |
| const webrtc::FlexfecReceiveStream::Config& flexfec_stream_config = |
| flexfec_stream->GetConfig(); |
| EXPECT_EQ(GetEngineCodec("flexfec-03").id, |
| flexfec_stream_config.payload_type); |
| EXPECT_EQ(kFlexfecSsrc, flexfec_stream_config.remote_ssrc); |
| ASSERT_EQ(1U, flexfec_stream_config.protected_media_ssrcs.size()); |
| EXPECT_EQ(kSsrcs1[0], flexfec_stream_config.protected_media_ssrcs[0]); |
| const std::vector<FakeVideoReceiveStream*>& video_streams = |
| fake_call_->GetVideoReceiveStreams(); |
| const FakeVideoReceiveStream* video_stream = video_streams.front(); |
| const webrtc::VideoReceiveStream::Config& video_stream_config = |
| video_stream->GetConfig(); |
| EXPECT_EQ(video_stream_config.rtp.local_ssrc, |
| flexfec_stream_config.local_ssrc); |
| EXPECT_EQ(video_stream_config.rtp.rtcp_mode, flexfec_stream_config.rtcp_mode); |
| EXPECT_EQ(video_stream_config.rtcp_send_transport, |
| flexfec_stream_config.rtcp_send_transport); |
| // TODO(brandtr): Update this EXPECT when we set |transport_cc| in a |
| // spec-compliant way. |
| EXPECT_EQ(video_stream_config.rtp.transport_cc, |
| flexfec_stream_config.transport_cc); |
| EXPECT_EQ(video_stream_config.rtp.rtcp_mode, flexfec_stream_config.rtcp_mode); |
| EXPECT_EQ(video_stream_config.rtp.extensions, |
| flexfec_stream_config.rtp_header_extensions); |
| } |
| |
| // We should not send FlexFEC, even if we advertise it, unless the right |
| // field trial is set. |
| // TODO(brandtr): Remove when FlexFEC is enabled by default. |
| TEST_F(WebRtcVideoChannelFlexfecRecvTest, |
| SetSendCodecsWithoutSsrcWithFecDoesNotEnableFec) { |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(GetEngineCodec("VP8")); |
| parameters.codecs.push_back(GetEngineCodec("flexfec-03")); |
| ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| |
| FakeVideoSendStream* stream = AddSendStream(); |
| webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| |
| EXPECT_EQ(-1, config.rtp.flexfec.payload_type); |
| EXPECT_EQ(0, config.rtp.flexfec.ssrc); |
| EXPECT_TRUE(config.rtp.flexfec.protected_media_ssrcs.empty()); |
| } |
| |
| TEST_F(WebRtcVideoChannelFlexfecRecvTest, |
| SetSendCodecsWithSsrcWithFecDoesNotEnableFec) { |
| cricket::VideoSendParameters parameters; |
| parameters.codecs.push_back(GetEngineCodec("VP8"<
|