From 3b9ff38d8a10d46f69680c5634b4814fb02378e2 Mon Sep 17 00:00:00 2001 From: ossu Date: Thu, 27 Apr 2017 08:03:42 -0700 Subject: [PATCH] Have AudioSendStream register CNG payload types with the RtpRtcpModule. TBR=kwiberg@webrtc.org # Turn perf-bots green again BUG=webrtc:5806 Review-Url: https://codereview.webrtc.org/2844803003 Cr-Commit-Position: refs/heads/master@{#17911} --- webrtc/audio/audio_send_stream.cc | 30 +++++++++++++++++++++- webrtc/audio/audio_send_stream.h | 2 ++ webrtc/audio/audio_send_stream_unittest.cc | 8 ++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/webrtc/audio/audio_send_stream.cc b/webrtc/audio/audio_send_stream.cc index 28541ca62d..d413a962b7 100644 --- a/webrtc/audio/audio_send_stream.cc +++ b/webrtc/audio/audio_send_stream.cc @@ -28,7 +28,7 @@ #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" #include "webrtc/modules/congestion_controller/include/send_side_congestion_controller.h" #include "webrtc/modules/pacing/paced_sender.h" -#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" +#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" #include "webrtc/voice_engine/channel_proxy.h" #include "webrtc/voice_engine/include/voe_base.h" #include "webrtc/voice_engine/transmit_mixer.h" @@ -421,6 +421,10 @@ bool AudioSendStream::SetupSendCodec(AudioSendStream* stream, cng_config.speech_encoder = std::move(encoder); cng_config.vad_mode = Vad::kVadNormal; encoder.reset(new AudioEncoderCng(std::move(cng_config))); + + stream->RegisterCngPayloadType( + *spec.cng_payload_type, + new_config.send_codec_spec->format.clockrate_hz); } stream->channel_proxy_->SetEncoder(new_config.send_codec_spec->payload_type, @@ -498,6 +502,14 @@ void AudioSendStream::ReconfigureCNG(AudioSendStream* stream, return; } + // Register the CNG payload type if it's been added, don't do anything if CNG + // is removed. Payload types must not be redefined. + if (new_config.send_codec_spec->cng_payload_type) { + stream->RegisterCngPayloadType( + *new_config.send_codec_spec->cng_payload_type, + new_config.send_codec_spec->format.clockrate_hz); + } + // Wrap or unwrap the encoder in an AudioEncoderCNG. stream->channel_proxy_->ModifyEncoder( [&](std::unique_ptr* encoder_ptr) { @@ -572,5 +584,21 @@ void AudioSendStream::RemoveBitrateObserver() { thread_sync_event.Wait(rtc::Event::kForever); } +void AudioSendStream::RegisterCngPayloadType(int payload_type, + int clockrate_hz) { + RtpRtcp* rtpRtcpModule = nullptr; + RtpReceiver* rtpReceiver = nullptr; // Unused, but required for call. + channel_proxy_->GetRtpRtcp(&rtpRtcpModule, &rtpReceiver); + const CodecInst codec = {payload_type, "CN", clockrate_hz, 0, 1, 0}; + if (rtpRtcpModule->RegisterSendPayload(codec) != 0) { + rtpRtcpModule->DeRegisterSendPayload(codec.pltype); + if (rtpRtcpModule->RegisterSendPayload(codec) != 0) { + LOG(LS_ERROR) << "RegisterCngPayloadType() failed to register CN to " + "RTP/RTCP module"; + } + } +} + + } // namespace internal } // namespace webrtc diff --git a/webrtc/audio/audio_send_stream.h b/webrtc/audio/audio_send_stream.h index 56e099fb15..dcc28c9dbc 100644 --- a/webrtc/audio/audio_send_stream.h +++ b/webrtc/audio/audio_send_stream.h @@ -93,6 +93,8 @@ class AudioSendStream final : public webrtc::AudioSendStream, void ConfigureBitrateObserver(int min_bitrate_bps, int max_bitrate_bps); void RemoveBitrateObserver(); + void RegisterCngPayloadType(int payload_type, int clockrate_hz); + rtc::ThreadChecker worker_thread_checker_; rtc::ThreadChecker pacer_thread_checker_; rtc::TaskQueue* worker_queue_; diff --git a/webrtc/audio/audio_send_stream_unittest.cc b/webrtc/audio/audio_send_stream_unittest.cc index 3fbbb62072..dba83ca524 100644 --- a/webrtc/audio/audio_send_stream_unittest.cc +++ b/webrtc/audio/audio_send_stream_unittest.cc @@ -25,6 +25,7 @@ #include "webrtc/modules/congestion_controller/include/mock/mock_congestion_observer.h" #include "webrtc/modules/congestion_controller/include/send_side_congestion_controller.h" #include "webrtc/modules/pacing/paced_sender.h" +#include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h" #include "webrtc/modules/rtp_rtcp/mocks/mock_rtcp_rtt_stats.h" #include "webrtc/test/gtest.h" #include "webrtc/test/mock_voe_channel_proxy.h" @@ -217,6 +218,12 @@ struct ConfigHelper { void SetupDefaultChannelProxy(bool audio_bwe_enabled) { using testing::StrEq; channel_proxy_ = new testing::StrictMock(); + EXPECT_CALL(*channel_proxy_, GetRtpRtcp(_, _)) + .WillRepeatedly(Invoke( + [this](RtpRtcp** rtp_rtcp_module, RtpReceiver** rtp_receiver) { + *rtp_rtcp_module = &this->rtp_rtcp_; + *rtp_receiver = nullptr; // Not deemed necessary for tests yet. + })); EXPECT_CALL(*channel_proxy_, SetRTCPStatus(true)).Times(1); EXPECT_CALL(*channel_proxy_, SetLocalSSRC(kSsrc)).Times(1); EXPECT_CALL(*channel_proxy_, SetRTCP_CNAME(StrEq(kCName))).Times(1); @@ -321,6 +328,7 @@ struct ConfigHelper { AudioProcessing::AudioProcessingStatistics audio_processing_stats_; FakeRtpTransportController fake_transport_; MockRtcEventLog event_log_; + MockRtpRtcp rtp_rtcp_; MockRtcpRttStats rtcp_rtt_stats_; testing::NiceMock limit_observer_; BitrateAllocator bitrate_allocator_;