Diff
Modified: branches/safari-611-branch/Source/ThirdParty/libwebrtc/ChangeLog (272273 => 272274)
--- branches/safari-611-branch/Source/ThirdParty/libwebrtc/ChangeLog 2021-02-03 01:40:52 UTC (rev 272273)
+++ branches/safari-611-branch/Source/ThirdParty/libwebrtc/ChangeLog 2021-02-03 01:40:56 UTC (rev 272274)
@@ -1,3 +1,44 @@
+2021-02-02 Alan Coon <[email protected]>
+
+ Cherry-pick r271793. rdar://problem/73887809
+
+ Resync libwebrtc with M87 latest branch
+ https://bugs.webkit.org/show_bug.cgi?id=220913
+
+ Reviewed by Eric Carlson.
+
+ Cherry-picking two changes that have been cherry-picked in upstream M87 after our latest resync.
+ This includes: https://webrtc-review.googlesource.com/c/src/+/187349 and https://webrtc-review.googlesource.com/c/src/+/191485.
+
+ * Source/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc:
+ * Source/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h:
+ * Source/webrtc/modules/audio_coding/codecs/opus/opus_interface.cc:
+ * Source/webrtc/modules/audio_coding/codecs/opus/opus_unittest.cc:
+ * Source/webrtc/modules/audio_coding/test/TestVADDTX.cc:
+ * Source/webrtc/pc/peer_connection_rtp_unittest.cc:
+ * Source/webrtc/pc/sdp_offer_answer.cc:
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@271793 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2021-01-25 Youenn Fablet <[email protected]>
+
+ Resync libwebrtc with M87 latest branch
+ https://bugs.webkit.org/show_bug.cgi?id=220913
+
+ Reviewed by Eric Carlson.
+
+ Cherry-picking two changes that have been cherry-picked in upstream M87 after our latest resync.
+ This includes: https://webrtc-review.googlesource.com/c/src/+/187349 and https://webrtc-review.googlesource.com/c/src/+/191485.
+
+ * Source/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc:
+ * Source/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h:
+ * Source/webrtc/modules/audio_coding/codecs/opus/opus_interface.cc:
+ * Source/webrtc/modules/audio_coding/codecs/opus/opus_unittest.cc:
+ * Source/webrtc/modules/audio_coding/test/TestVADDTX.cc:
+ * Source/webrtc/pc/peer_connection_rtp_unittest.cc:
+ * Source/webrtc/pc/sdp_offer_answer.cc:
+
2021-01-08 Ryan Hostetler <[email protected]>
Add support for source caching between platforms
Modified: branches/safari-611-branch/Source/ThirdParty/libwebrtc/Source/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc (272273 => 272274)
--- branches/safari-611-branch/Source/ThirdParty/libwebrtc/Source/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc 2021-02-03 01:40:52 UTC (rev 272273)
+++ branches/safari-611-branch/Source/ThirdParty/libwebrtc/Source/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc 2021-02-03 01:40:56 UTC (rev 272274)
@@ -367,7 +367,8 @@
inst_(nullptr),
packet_loss_fraction_smoother_(new PacketLossFractionSmoother()),
audio_network_adaptor_creator_(audio_network_adaptor_creator),
- bitrate_smoother_(std::move(bitrate_smoother)) {
+ bitrate_smoother_(std::move(bitrate_smoother)),
+ consecutive_dtx_frames_(0) {
RTC_DCHECK(0 <= payload_type && payload_type <= 127);
// Sanity check of the redundant payload type field that we want to get rid
@@ -589,7 +590,6 @@
Num10msFramesPerPacket() * SamplesPer10msFrame());
const size_t max_encoded_bytes = SufficientOutputBufferSize();
- const size_t start_offset_bytes = encoded->size();
EncodedInfo info;
info.encoded_bytes = encoded->AppendData(
max_encoded_bytes, [&](rtc::ArrayView<uint8_t> encoded) {
@@ -604,6 +604,8 @@
});
input_buffer_.clear();
+ bool dtx_frame = (info.encoded_bytes <= 2);
+
// Will use new packet size for next encoding.
config_.frame_size_ms = next_frame_length_ms_;
@@ -618,18 +620,14 @@
info.encoded_timestamp = first_timestamp_in_buffer_;
info.payload_type = payload_type_;
info.send_even_if_empty = true; // Allows Opus to send empty packets.
+ // After 20 DTX frames (MAX_CONSECUTIVE_DTX) Opus will send a frame
+ // coding the background noise. Avoid flagging this frame as speech
+ // (even though there is a probability of the frame being speech).
+ info.speech = !dtx_frame && (consecutive_dtx_frames_ != 20);
info.encoder_type = CodecType::kOpus;
- // Extract the VAD result from the encoded packet.
- int has_voice = WebRtcOpus_PacketHasVoiceActivity(
- &encoded->data()[start_offset_bytes], info.encoded_bytes);
- if (has_voice == -1) {
- // CELT mode packet or there was an error. This had set the speech flag to
- // true historically.
- info.speech = true;
- } else {
- info.speech = has_voice;
- }
+ // Increase or reset DTX counter.
+ consecutive_dtx_frames_ = (dtx_frame) ? (consecutive_dtx_frames_ + 1) : (0);
return info;
}
Modified: branches/safari-611-branch/Source/ThirdParty/libwebrtc/Source/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h (272273 => 272274)
--- branches/safari-611-branch/Source/ThirdParty/libwebrtc/Source/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h 2021-02-03 01:40:52 UTC (rev 272273)
+++ branches/safari-611-branch/Source/ThirdParty/libwebrtc/Source/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.h 2021-02-03 01:40:56 UTC (rev 272274)
@@ -172,6 +172,7 @@
absl::optional<size_t> overhead_bytes_per_packet_;
const std::unique_ptr<SmoothingFilter> bitrate_smoother_;
absl::optional<int64_t> bitrate_smoother_last_update_time_;
+ int consecutive_dtx_frames_;
friend struct AudioEncoderOpus;
RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderOpusImpl);
Modified: branches/safari-611-branch/Source/ThirdParty/libwebrtc/Source/webrtc/modules/audio_coding/codecs/opus/opus_interface.cc (272273 => 272274)
--- branches/safari-611-branch/Source/ThirdParty/libwebrtc/Source/webrtc/modules/audio_coding/codecs/opus/opus_interface.cc 2021-02-03 01:40:52 UTC (rev 272273)
+++ branches/safari-611-branch/Source/ThirdParty/libwebrtc/Source/webrtc/modules/audio_coding/codecs/opus/opus_interface.cc 2021-02-03 01:40:56 UTC (rev 272274)
@@ -767,7 +767,7 @@
int silk_frames = WebRtcOpus_NumSilkFrames(payload);
if (silk_frames == 0)
- return 0;
+ return -1;
const int channels = opus_packet_get_nb_channels(payload);
RTC_DCHECK(channels == 1 || channels == 2);
Modified: branches/safari-611-branch/Source/ThirdParty/libwebrtc/Source/webrtc/modules/audio_coding/codecs/opus/opus_unittest.cc (272273 => 272274)
--- branches/safari-611-branch/Source/ThirdParty/libwebrtc/Source/webrtc/modules/audio_coding/codecs/opus/opus_unittest.cc 2021-02-03 01:40:52 UTC (rev 272273)
+++ branches/safari-611-branch/Source/ThirdParty/libwebrtc/Source/webrtc/modules/audio_coding/codecs/opus/opus_unittest.cc 2021-02-03 01:40:56 UTC (rev 272274)
@@ -975,21 +975,4 @@
EXPECT_TRUE(WebRtcOpus_PacketHasVoiceActivity(twoMonoFrames, 3));
}
-TEST(OpusVadTest, DtxEmptyPacket) {
- const uint8_t dtx[] = {0x78};
- EXPECT_FALSE(WebRtcOpus_PacketHasVoiceActivity(dtx, 1));
-}
-
-TEST(OpusVadTest, DtxBackgroundNoisePacket) {
- // DTX sends a frame coding background noise every 20 packets:
- // https://tools.ietf.org/html/rfc6716#section-2.1.9
- // The packet below represents such a frame and was captured using
- // Wireshark while disabling encryption.
- const uint8_t dtx[] = {0x78, 0x07, 0xc9, 0x79, 0xc8, 0xc9, 0x57, 0xc0, 0xa2,
- 0x12, 0x23, 0xfa, 0xef, 0x67, 0xf3, 0x2e, 0xe3, 0xd3,
- 0xd5, 0xe9, 0xec, 0xdb, 0x3e, 0xbc, 0x80, 0xb6, 0x6e,
- 0x2a, 0xb7, 0x8c, 0x83, 0xcd, 0x83, 0xcd, 0x00};
- EXPECT_FALSE(WebRtcOpus_PacketHasVoiceActivity(dtx, 35));
-}
-
} // namespace webrtc
Modified: branches/safari-611-branch/Source/ThirdParty/libwebrtc/Source/webrtc/modules/audio_coding/test/TestVADDTX.cc (272273 => 272274)
--- branches/safari-611-branch/Source/ThirdParty/libwebrtc/Source/webrtc/modules/audio_coding/test/TestVADDTX.cc 2021-02-03 01:40:52 UTC (rev 272273)
+++ branches/safari-611-branch/Source/ThirdParty/libwebrtc/Source/webrtc/modules/audio_coding/test/TestVADDTX.cc 2021-02-03 01:40:56 UTC (rev 272274)
@@ -166,13 +166,11 @@
int i = &st - stats; // Calculate the current position in stats.
switch (expects[i]) {
case 0: {
- EXPECT_EQ(0u, st) << "stats[" << i << "] error. Output file "
- << out_filename;
+ EXPECT_EQ(0u, st) << "stats[" << i << "] error.";
break;
}
case 1: {
- EXPECT_GT(st, 0u) << "stats[" << i << "] error. Output file "
- << out_filename;
+ EXPECT_GT(st, 0u) << "stats[" << i << "] error.";
break;
}
}
@@ -191,29 +189,25 @@
// Test various configurations on VAD/DTX.
void TestWebRtcVadDtx::RunTestCases(const SdpAudioFormat& codec_format) {
- RegisterCodec(codec_format, absl::nullopt);
Test(/*new_outfile=*/true,
- /*expect_vad_packets=*/codec_format.name == "opus");
+ /*expect_dtx_enabled=*/RegisterCodec(codec_format, absl::nullopt));
- RegisterCodec(codec_format, Vad::kVadAggressive);
Test(/*new_outfile=*/false,
- /*expect_vad_packets=*/true);
+ /*expect_dtx_enabled=*/RegisterCodec(codec_format, Vad::kVadAggressive));
- RegisterCodec(codec_format, Vad::kVadLowBitrate);
Test(/*new_outfile=*/false,
- /*expect_vad_packets=*/true);
+ /*expect_dtx_enabled=*/RegisterCodec(codec_format, Vad::kVadLowBitrate));
- RegisterCodec(codec_format, Vad::kVadVeryAggressive);
- Test(/*new_outfile=*/false, /*expect_vad_packets=*/true);
+ Test(/*new_outfile=*/false, /*expect_dtx_enabled=*/RegisterCodec(
+ codec_format, Vad::kVadVeryAggressive));
- RegisterCodec(codec_format, Vad::kVadNormal);
Test(/*new_outfile=*/false,
- /*expect_vad_packets=*/true);
+ /*expect_dtx_enabled=*/RegisterCodec(codec_format, Vad::kVadNormal));
}
// Set the expectation and run the test.
-void TestWebRtcVadDtx::Test(bool new_outfile, bool expect_vad_packets) {
- int expects[] = {-1, 1, expect_vad_packets ? 1 : -1, 0, 0};
+void TestWebRtcVadDtx::Test(bool new_outfile, bool expect_dtx_enabled) {
+ int expects[] = {-1, 1, expect_dtx_enabled, 0, 0};
if (new_outfile) {
output_file_num_++;
}
@@ -226,20 +220,16 @@
// Following is the implementation of TestOpusDtx.
void TestOpusDtx::Perform() {
- int expects[] = {0, 0, 0, 0, 0};
+ int expects[] = {0, 1, 0, 0, 0};
// Register Opus as send codec
std::string out_filename =
webrtc::test::OutputPath() + "testOpusDtx_outFile_mono.pcm";
RegisterCodec({"opus", 48000, 2}, absl::nullopt);
-
acm_send_->ModifyEncoder([](std::unique_ptr<AudioEncoder>* encoder_ptr) {
(*encoder_ptr)->SetDtx(false);
});
- expects[static_cast<int>(AudioFrameType::kEmptyFrame)] = 0;
- expects[static_cast<int>(AudioFrameType::kAudioFrameSpeech)] = 1;
- expects[static_cast<int>(AudioFrameType::kAudioFrameCN)] = 1;
Run(webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"), 32000, 1,
out_filename, false, expects);
@@ -247,7 +237,6 @@
(*encoder_ptr)->SetDtx(true);
});
expects[static_cast<int>(AudioFrameType::kEmptyFrame)] = 1;
- expects[static_cast<int>(AudioFrameType::kAudioFrameSpeech)] = 1;
expects[static_cast<int>(AudioFrameType::kAudioFrameCN)] = 1;
Run(webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"), 32000, 1,
out_filename, true, expects);
@@ -255,12 +244,10 @@
// Register stereo Opus as send codec
out_filename = webrtc::test::OutputPath() + "testOpusDtx_outFile_stereo.pcm";
RegisterCodec({"opus", 48000, 2, {{"stereo", "1"}}}, absl::nullopt);
-
acm_send_->ModifyEncoder([](std::unique_ptr<AudioEncoder>* encoder_ptr) {
(*encoder_ptr)->SetDtx(false);
});
expects[static_cast<int>(AudioFrameType::kEmptyFrame)] = 0;
- expects[static_cast<int>(AudioFrameType::kAudioFrameSpeech)] = 1;
expects[static_cast<int>(AudioFrameType::kAudioFrameCN)] = 0;
Run(webrtc::test::ResourcePath("audio_coding/teststereo32kHz", "pcm"), 32000,
2, out_filename, false, expects);
@@ -274,7 +261,6 @@
});
expects[static_cast<int>(AudioFrameType::kEmptyFrame)] = 1;
- expects[static_cast<int>(AudioFrameType::kAudioFrameSpeech)] = 1;
expects[static_cast<int>(AudioFrameType::kAudioFrameCN)] = 1;
Run(webrtc::test::ResourcePath("audio_coding/teststereo32kHz", "pcm"), 32000,
2, out_filename, true, expects);
Modified: branches/safari-611-branch/Source/ThirdParty/libwebrtc/Source/webrtc/pc/peer_connection_rtp_unittest.cc (272273 => 272274)
--- branches/safari-611-branch/Source/ThirdParty/libwebrtc/Source/webrtc/pc/peer_connection_rtp_unittest.cc 2021-02-03 01:40:52 UTC (rev 272273)
+++ branches/safari-611-branch/Source/ThirdParty/libwebrtc/Source/webrtc/pc/peer_connection_rtp_unittest.cc 2021-02-03 01:40:56 UTC (rev 272274)
@@ -164,6 +164,28 @@
protected:
PeerConnectionRtpTestUnifiedPlan()
: PeerConnectionRtpBaseTest(SdpSemantics::kUnifiedPlan) {}
+
+ // Helper to emulate an SFU that rejects an offered media section
+ // in answer.
+ bool ExchangeOfferAnswerWhereRemoteStopsTransceiver(
+ PeerConnectionWrapper* caller,
+ PeerConnectionWrapper* callee,
+ size_t mid_to_stop) {
+ auto offer = caller->CreateOffer();
+ caller->SetLocalDescription(CloneSessionDescription(offer.get()));
+ callee->SetRemoteDescription(std::move(offer));
+ EXPECT_LT(mid_to_stop, callee->pc()->GetTransceivers().size());
+ // Must use StopInternal in order to do instant reject.
+ callee->pc()->GetTransceivers()[mid_to_stop]->StopInternal();
+ auto answer = callee->CreateAnswer();
+ EXPECT_TRUE(answer);
+ bool set_local_answer =
+ callee->SetLocalDescription(CloneSessionDescription(answer.get()));
+ EXPECT_TRUE(set_local_answer);
+ bool set_remote_answer = caller->SetRemoteDescription(std::move(answer));
+ EXPECT_TRUE(set_remote_answer);
+ return set_remote_answer;
+ }
};
// These tests cover |webrtc::PeerConnectionObserver| callbacks firing upon
@@ -1573,6 +1595,42 @@
EXPECT_EQ(0U, callee->pc()->GetReceivers().size());
}
+TEST_F(PeerConnectionRtpTestUnifiedPlan,
+ SetLocalDescriptionWorksAfterRepeatedAddRemove) {
+ auto caller = CreatePeerConnection();
+ auto callee = CreatePeerConnection();
+ auto video_track = caller->CreateVideoTrack("v");
+ auto track = caller->CreateAudioTrack("a");
+ caller->AddTransceiver(video_track);
+ auto transceiver = caller->AddTransceiver(track);
+ ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get()));
+ caller->pc()->RemoveTrack(transceiver->sender());
+ ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get()));
+ caller->AddTrack(track);
+ ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get()));
+ caller->pc()->RemoveTrack(transceiver->sender());
+ ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get()));
+}
+
+// This is a repro of Chromium bug https://crbug.com/1134686
+TEST_F(PeerConnectionRtpTestUnifiedPlan,
+ SetLocalDescriptionWorksAfterRepeatedAddRemoveWithRemoteReject) {
+ auto caller = CreatePeerConnection();
+ auto callee = CreatePeerConnection();
+ auto video_track = caller->CreateVideoTrack("v");
+ auto track = caller->CreateAudioTrack("a");
+ caller->AddTransceiver(video_track);
+ auto transceiver = caller->AddTransceiver(track);
+ ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get()));
+ caller->pc()->RemoveTrack(transceiver->sender());
+ ExchangeOfferAnswerWhereRemoteStopsTransceiver(caller.get(), callee.get(), 1);
+ ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get()));
+ caller->AddTrack(track);
+ ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get()));
+ caller->pc()->RemoveTrack(transceiver->sender());
+ ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get()));
+}
+
// Test that AddTransceiver fails if trying to use unimplemented RTP encoding
// parameters with the send_encodings parameters.
TEST_F(PeerConnectionRtpTestUnifiedPlan,
Modified: branches/safari-611-branch/Source/ThirdParty/libwebrtc/Source/webrtc/pc/sdp_offer_answer.cc (272273 => 272274)
--- branches/safari-611-branch/Source/ThirdParty/libwebrtc/Source/webrtc/pc/sdp_offer_answer.cc 2021-02-03 01:40:52 UTC (rev 272273)
+++ branches/safari-611-branch/Source/ThirdParty/libwebrtc/Source/webrtc/pc/sdp_offer_answer.cc 2021-02-03 01:40:56 UTC (rev 272274)
@@ -2802,17 +2802,16 @@
old_remote_content =
&old_remote_description->description()->contents()[i];
}
- // In the case where an m-section has completed its rejection,
- // and is not being reused, we do not expect a transceiver.
- if (old_local_content && old_local_content->rejected &&
- old_remote_content && old_remote_content->rejected &&
- new_content.rejected) {
- continue;
- }
auto transceiver_or_error =
AssociateTransceiver(source, new_session.GetType(), i, new_content,
old_local_content, old_remote_content);
if (!transceiver_or_error.ok()) {
+ // In the case where a transceiver is rejected locally, we don't
+ // expect to find a transceiver, but might find it in the case
+ // where state is still "stopping", not "stopped".
+ if (new_content.rejected) {
+ continue;
+ }
return transceiver_or_error.MoveError();
}
auto transceiver = transceiver_or_error.MoveValue();
@@ -2874,8 +2873,9 @@
transceiver = pc_->GetTransceiverByMLineIndex(mline_index);
}
if (!transceiver) {
+ // This may happen normally when media sections are rejected.
LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_PARAMETER,
- "Unknown transceiver");
+ "Transceiver not found based on m-line index");
}
} else {
RTC_DCHECK_EQ(source, cricket::CS_REMOTE);