From 6cc9cca5a6df2de77d3aad212364deee48e82226 Mon Sep 17 00:00:00 2001 From: Benjamin Wright Date: Tue, 9 Oct 2018 17:29:54 -0700 Subject: [PATCH] Don't reset streams for the FrameEncryptor / FrameDecryptor unless they changed. This change prevents resets unless someone actually set a FrameEncryptor / FrameDecryptor. Bug: webrtc:9795 Change-Id: I29910b9ecc2f6f8eea371c5961ac7e9780de65d2 Reviewed-on: https://webrtc-review.googlesource.com/c/104901 Reviewed-by: Steve Anton Commit-Queue: Benjamin Wright Cr-Commit-Position: refs/heads/master@{#25095} --- pc/rtpreceiver.cc | 22 ++++++++++++++-------- pc/rtpsender.cc | 24 ++++++++++++++++-------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/pc/rtpreceiver.cc b/pc/rtpreceiver.cc index d4a1f62f83..d2d7206a8d 100644 --- a/pc/rtpreceiver.cc +++ b/pc/rtpreceiver.cc @@ -51,8 +51,8 @@ void MaybeAttachFrameDecryptorToMediaChannel( rtc::Thread* worker_thread, rtc::scoped_refptr frame_decryptor, cricket::MediaChannel* media_channel) { - if (media_channel && ssrc.has_value()) { - return worker_thread->Invoke(RTC_FROM_HERE, [&] { + if (media_channel && frame_decryptor && ssrc.has_value()) { + worker_thread->Invoke(RTC_FROM_HERE, [&] { media_channel->SetFrameDecryptor(*ssrc, frame_decryptor); }); } @@ -156,9 +156,12 @@ bool AudioRtpReceiver::SetParameters(const RtpParameters& parameters) { void AudioRtpReceiver::SetFrameDecryptor( rtc::scoped_refptr frame_decryptor) { frame_decryptor_ = std::move(frame_decryptor); - // Attach the frame decryptor to the media channel if it exists. - MaybeAttachFrameDecryptorToMediaChannel(ssrc_, worker_thread_, - frame_decryptor_, media_channel_); + // Special Case: Set the frame decryptor to any value on any existing channel. + if (media_channel_ && ssrc_.has_value()) { + worker_thread_->Invoke(RTC_FROM_HERE, [&] { + media_channel_->SetFrameDecryptor(*ssrc_, frame_decryptor_); + }); + } } rtc::scoped_refptr @@ -347,9 +350,12 @@ bool VideoRtpReceiver::SetParameters(const RtpParameters& parameters) { void VideoRtpReceiver::SetFrameDecryptor( rtc::scoped_refptr frame_decryptor) { frame_decryptor_ = std::move(frame_decryptor); - // Attach the new frame decryptor the media channel if it exists yet. - MaybeAttachFrameDecryptorToMediaChannel(ssrc_, worker_thread_, - frame_decryptor_, media_channel_); + // Special Case: Set the frame decryptor to any value on any existing channel. + if (media_channel_ && ssrc_.has_value()) { + worker_thread_->Invoke(RTC_FROM_HERE, [&] { + media_channel_->SetFrameDecryptor(*ssrc_, frame_decryptor_); + }); + } } rtc::scoped_refptr diff --git a/pc/rtpsender.cc b/pc/rtpsender.cc index 3bb90f24da..7493542d6c 100644 --- a/pc/rtpsender.cc +++ b/pc/rtpsender.cc @@ -68,13 +68,13 @@ bool PerSenderRtpEncodingParameterHasValue( // correct worker thread only if both the media channel exists and a ssrc has // been allocated to the stream. void MaybeAttachFrameEncryptorToMediaChannel( - const absl::optional ssrc, + const uint32_t ssrc, rtc::Thread* worker_thread, rtc::scoped_refptr frame_encryptor, cricket::MediaChannel* media_channel) { - if (media_channel && ssrc.has_value()) { - return worker_thread->Invoke(RTC_FROM_HERE, [&] { - media_channel->SetFrameEncryptor(*ssrc, frame_encryptor); + if (media_channel && frame_encryptor && ssrc) { + worker_thread->Invoke(RTC_FROM_HERE, [&] { + media_channel->SetFrameEncryptor(ssrc, frame_encryptor); }); } } @@ -305,8 +305,12 @@ rtc::scoped_refptr AudioRtpSender::GetDtmfSender() const { void AudioRtpSender::SetFrameEncryptor( rtc::scoped_refptr frame_encryptor) { frame_encryptor_ = std::move(frame_encryptor); - MaybeAttachFrameEncryptorToMediaChannel(ssrc_, worker_thread_, - frame_encryptor_, media_channel_); + // Special Case: Set the frame encryptor to any value on any existing channel. + if (media_channel_ && ssrc_) { + worker_thread_->Invoke(RTC_FROM_HERE, [&] { + media_channel_->SetFrameEncryptor(ssrc_, frame_encryptor_); + }); + } } rtc::scoped_refptr AudioRtpSender::GetFrameEncryptor() @@ -557,8 +561,12 @@ rtc::scoped_refptr VideoRtpSender::GetDtmfSender() const { void VideoRtpSender::SetFrameEncryptor( rtc::scoped_refptr frame_encryptor) { frame_encryptor_ = std::move(frame_encryptor); - MaybeAttachFrameEncryptorToMediaChannel(ssrc_, worker_thread_, - frame_encryptor_, media_channel_); + // Special Case: Set the frame encryptor to any value on any existing channel. + if (media_channel_ && ssrc_) { + worker_thread_->Invoke(RTC_FROM_HERE, [&] { + media_channel_->SetFrameEncryptor(ssrc_, frame_encryptor_); + }); + } } rtc::scoped_refptr VideoRtpSender::GetFrameEncryptor()