diff --git a/pc/rtp_sender.cc b/pc/rtp_sender.cc index 43744ab73e..698d7ffe61 100644 --- a/pc/rtp_sender.cc +++ b/pc/rtp_sender.cc @@ -697,9 +697,21 @@ rtc::scoped_refptr VideoRtpSender::GetDtmfSender() const { RTCError VideoRtpSender::GenerateKeyFrame( const std::vector& rids) { RTC_DCHECK_RUN_ON(signaling_thread_); - // TODO(crbug.com/1354101): check that rids are a subset of this senders rids - // (or empty). if (video_media_channel() && ssrc_ && !stopped_) { + auto parameters = GetParameters(); + for (const auto& rid : rids) { + if (rid.empty()) { + LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, + "Attempted to specify an empty rid."); + } + if (!absl::c_any_of(parameters.encodings, + [&rid](const RtpEncodingParameters& parameters) { + return parameters.rid == rid; + })) { + LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER, + "Attempted to specify a rid not configured."); + } + } worker_thread_->PostTask([&, rids] { video_media_channel()->GenerateSendKeyFrame(ssrc_, rids); }); diff --git a/pc/rtp_sender_receiver_unittest.cc b/pc/rtp_sender_receiver_unittest.cc index d66ee65f4c..5df57958c8 100644 --- a/pc/rtp_sender_receiver_unittest.cc +++ b/pc/rtp_sender_receiver_unittest.cc @@ -1468,6 +1468,36 @@ TEST_F(RtpSenderReceiverTest, VideoReceiverCanGetParametersWithSimulcast) { DestroyVideoRtpReceiver(); } +TEST_F(RtpSenderReceiverTest, GenerateKeyFrameWithAudio) { + CreateAudioRtpSender(); + + auto error = audio_rtp_sender_->GenerateKeyFrame({}); + EXPECT_FALSE(error.ok()); + EXPECT_EQ(error.type(), RTCErrorType::UNSUPPORTED_OPERATION); + + DestroyAudioRtpSender(); +} + +TEST_F(RtpSenderReceiverTest, GenerateKeyFrameWithVideo) { + CreateVideoRtpSenderWithSimulcast({"1", "2", "3"}); + + auto error = video_rtp_sender_->GenerateKeyFrame({}); + EXPECT_TRUE(error.ok()); + + error = video_rtp_sender_->GenerateKeyFrame({"1"}); + EXPECT_TRUE(error.ok()); + + error = video_rtp_sender_->GenerateKeyFrame({""}); + EXPECT_FALSE(error.ok()); + EXPECT_EQ(error.type(), RTCErrorType::INVALID_PARAMETER); + + error = video_rtp_sender_->GenerateKeyFrame({"no-such-rid"}); + EXPECT_FALSE(error.ok()); + EXPECT_EQ(error.type(), RTCErrorType::INVALID_PARAMETER); + + DestroyVideoRtpSender(); +} + // Test that makes sure that a video track content hint translates to the proper // value for sources that are not screencast. TEST_F(RtpSenderReceiverTest, PropagatesVideoTrackContentHint) {