From f48bca7baea246433c692136fe26a114ac4b937e Mon Sep 17 00:00:00 2001 From: Minyue Li Date: Thu, 20 Jun 2019 23:37:02 +0200 Subject: [PATCH] Avoid triggering a false error logging when using encryptor and sending DTX. Bug: b/135554070 Change-Id: I82e97da6fedd3fdbe90176dbec8eda524ad20624 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/143170 Reviewed-by: Oskar Sundbom Commit-Queue: Minyue Li Cr-Commit-Position: refs/heads/master@{#28351} --- audio/channel_send.cc | 49 +++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/audio/channel_send.cc b/audio/channel_send.cc index f8b94ca274..8bb54d6f2d 100644 --- a/audio/channel_send.cc +++ b/audio/channel_send.cc @@ -516,32 +516,35 @@ int32_t ChannelSend::SendRtpAudio(AudioFrameType frameType, // DTMF, or the encoder entered DTX. // TODO(minyue): see whether DTMF packets should be encrypted or not. In // current implementation, they are not. - if (frame_encryptor_ != nullptr && !payload.empty()) { - // TODO(benwright@webrtc.org) - Allocate enough to always encrypt inline. - // Allocate a buffer to hold the maximum possible encrypted payload. - size_t max_ciphertext_size = frame_encryptor_->GetMaxCiphertextByteSize( - cricket::MEDIA_TYPE_AUDIO, payload.size()); - encrypted_audio_payload.SetSize(max_ciphertext_size); + if (!payload.empty()) { + if (frame_encryptor_ != nullptr) { + // TODO(benwright@webrtc.org) - Allocate enough to always encrypt inline. + // Allocate a buffer to hold the maximum possible encrypted payload. + size_t max_ciphertext_size = frame_encryptor_->GetMaxCiphertextByteSize( + cricket::MEDIA_TYPE_AUDIO, payload.size()); + encrypted_audio_payload.SetSize(max_ciphertext_size); - // Encrypt the audio payload into the buffer. - size_t bytes_written = 0; - int encrypt_status = frame_encryptor_->Encrypt( - cricket::MEDIA_TYPE_AUDIO, _rtpRtcpModule->SSRC(), - /*additional_data=*/nullptr, payload, encrypted_audio_payload, - &bytes_written); - if (encrypt_status != 0) { - RTC_DLOG(LS_ERROR) << "Channel::SendData() failed encrypt audio payload: " - << encrypt_status; + // Encrypt the audio payload into the buffer. + size_t bytes_written = 0; + int encrypt_status = frame_encryptor_->Encrypt( + cricket::MEDIA_TYPE_AUDIO, _rtpRtcpModule->SSRC(), + /*additional_data=*/nullptr, payload, encrypted_audio_payload, + &bytes_written); + if (encrypt_status != 0) { + RTC_DLOG(LS_ERROR) + << "Channel::SendData() failed encrypt audio payload: " + << encrypt_status; + return -1; + } + // Resize the buffer to the exact number of bytes actually used. + encrypted_audio_payload.SetSize(bytes_written); + // Rewrite the payloadData and size to the new encrypted payload. + payload = encrypted_audio_payload; + } else if (crypto_options_.sframe.require_frame_encryption) { + RTC_DLOG(LS_ERROR) << "Channel::SendData() failed sending audio payload: " + << "A frame encryptor is required but one is not set."; return -1; } - // Resize the buffer to the exact number of bytes actually used. - encrypted_audio_payload.SetSize(bytes_written); - // Rewrite the payloadData and size to the new encrypted payload. - payload = encrypted_audio_payload; - } else if (crypto_options_.sframe.require_frame_encryption) { - RTC_DLOG(LS_ERROR) << "Channel::SendData() failed sending audio payload: " - << "A frame encryptor is required but one is not set."; - return -1; } // Push data from ACM to RTP/RTCP-module to deliver audio frame for