From 5263b3c1ddb10ecca58d9f08364aad2d6ba1d95d Mon Sep 17 00:00:00 2001 From: Henrik Lundin Date: Mon, 1 Jun 2015 10:29:41 +0200 Subject: [PATCH] Add options for NetEq fast accelerate mode through libjingle This CL connects RTCConfiguration::audioJitterBufferFastMode in PeerConnection.java, through libjingle, down to NetEq::Config::enable_fast_accelerate in native WebRTC. When enabled, it will allow NetEq to do faster time-compression when the buffer level is very high. BUG=4691 R=henrika@webrtc.org, mflodman@webrtc.org, pthatcher@webrtc.org Review URL: https://webrtc-codereview.appspot.com/55479004 Cr-Commit-Position: refs/heads/master@{#9344} --- talk/app/webrtc/java/jni/peerconnection_jni.cc | 4 ++++ .../webrtc/java/src/org/webrtc/PeerConnection.java | 2 ++ talk/app/webrtc/peerconnectioninterface.h | 4 +++- talk/app/webrtc/webrtcsession.cc | 3 +++ talk/media/base/mediachannel.h | 8 ++++++++ talk/media/webrtc/fakewebrtcvoiceengine.h | 11 ++++++++++- talk/media/webrtc/webrtcvoiceengine.cc | 9 +++++++++ talk/media/webrtc/webrtcvoiceengine_unittest.cc | 2 ++ webrtc/config.h | 6 ++++++ webrtc/voice_engine/channel.cc | 2 ++ 10 files changed, 49 insertions(+), 2 deletions(-) diff --git a/talk/app/webrtc/java/jni/peerconnection_jni.cc b/talk/app/webrtc/java/jni/peerconnection_jni.cc index f96b026bb..69078e6b7 100644 --- a/talk/app/webrtc/java/jni/peerconnection_jni.cc +++ b/talk/app/webrtc/java/jni/peerconnection_jni.cc @@ -1330,6 +1330,8 @@ JOW(jlong, PeerConnectionFactory_nativeCreatePeerConnection)( jfieldID j_audio_jitter_buffer_max_packets_id = GetFieldID( jni, j_rtc_config_class, "audioJitterBufferMaxPackets", "I"); + jfieldID j_audio_jitter_buffer_fast_accelerate_id = GetFieldID( + jni, j_rtc_config_class, "audioJitterBufferFastAccelerate", "Z"); PeerConnectionInterface::RTCConfiguration rtc_config; rtc_config.type = @@ -1342,6 +1344,8 @@ JOW(jlong, PeerConnectionFactory_nativeCreatePeerConnection)( JavaIceServersToJsepIceServers(jni, j_ice_servers, &rtc_config.servers); rtc_config.audio_jitter_buffer_max_packets = GetIntField(jni, j_rtc_config, j_audio_jitter_buffer_max_packets_id); + rtc_config.audio_jitter_buffer_fast_accelerate = GetBooleanField( + jni, j_rtc_config, j_audio_jitter_buffer_fast_accelerate_id); PCOJava* observer = reinterpret_cast(observer_p); observer->SetConstraints(new ConstraintsWrapper(jni, j_constraints)); diff --git a/talk/app/webrtc/java/src/org/webrtc/PeerConnection.java b/talk/app/webrtc/java/src/org/webrtc/PeerConnection.java index a229e17d0..8da2c4510 100644 --- a/talk/app/webrtc/java/src/org/webrtc/PeerConnection.java +++ b/talk/app/webrtc/java/src/org/webrtc/PeerConnection.java @@ -134,6 +134,7 @@ public class PeerConnection { public RtcpMuxPolicy rtcpMuxPolicy; public TcpCandidatePolicy tcpCandidatePolicy; public int audioJitterBufferMaxPackets; + public boolean audioJitterBufferFastAccelerate; public RTCConfiguration(List iceServers) { iceTransportsType = IceTransportsType.ALL; @@ -142,6 +143,7 @@ public class PeerConnection { tcpCandidatePolicy = TcpCandidatePolicy.ENABLED; this.iceServers = iceServers; audioJitterBufferMaxPackets = 50; + audioJitterBufferFastAccelerate = false; } }; diff --git a/talk/app/webrtc/peerconnectioninterface.h b/talk/app/webrtc/peerconnectioninterface.h index 59cc7008e..3e4cb556f 100644 --- a/talk/app/webrtc/peerconnectioninterface.h +++ b/talk/app/webrtc/peerconnectioninterface.h @@ -222,13 +222,15 @@ class PeerConnectionInterface : public rtc::RefCountInterface { RtcpMuxPolicy rtcp_mux_policy; TcpCandidatePolicy tcp_candidate_policy; int audio_jitter_buffer_max_packets; + bool audio_jitter_buffer_fast_accelerate; RTCConfiguration() : type(kAll), bundle_policy(kBundlePolicyBalanced), rtcp_mux_policy(kRtcpMuxPolicyNegotiate), tcp_candidate_policy(kTcpCandidatePolicyEnabled), - audio_jitter_buffer_max_packets(50) {} + audio_jitter_buffer_max_packets(50), + audio_jitter_buffer_fast_accelerate(false) {} }; struct RTCOfferAnswerOptions { diff --git a/talk/app/webrtc/webrtcsession.cc b/talk/app/webrtc/webrtcsession.cc index 766c5d418..5c8b2df75 100644 --- a/talk/app/webrtc/webrtcsession.cc +++ b/talk/app/webrtc/webrtcsession.cc @@ -644,6 +644,9 @@ bool WebRtcSession::Initialize( audio_options_.audio_jitter_buffer_max_packets.Set( rtc_configuration.audio_jitter_buffer_max_packets); + audio_options_.audio_jitter_buffer_fast_accelerate.Set( + rtc_configuration.audio_jitter_buffer_fast_accelerate); + const cricket::VideoCodec default_codec( JsepSessionDescription::kDefaultVideoCodecId, JsepSessionDescription::kDefaultVideoCodecName, diff --git a/talk/media/base/mediachannel.h b/talk/media/base/mediachannel.h index 68e01cefd..d96fe1c71 100644 --- a/talk/media/base/mediachannel.h +++ b/talk/media/base/mediachannel.h @@ -152,6 +152,8 @@ struct AudioOptions { stereo_swapping.SetFrom(change.stereo_swapping); audio_jitter_buffer_max_packets.SetFrom( change.audio_jitter_buffer_max_packets); + audio_jitter_buffer_fast_accelerate.SetFrom( + change.audio_jitter_buffer_fast_accelerate); typing_detection.SetFrom(change.typing_detection); aecm_generate_comfort_noise.SetFrom(change.aecm_generate_comfort_noise); conference_mode.SetFrom(change.conference_mode); @@ -183,6 +185,8 @@ struct AudioOptions { highpass_filter == o.highpass_filter && stereo_swapping == o.stereo_swapping && audio_jitter_buffer_max_packets == o.audio_jitter_buffer_max_packets && + audio_jitter_buffer_fast_accelerate == + o.audio_jitter_buffer_fast_accelerate && typing_detection == o.typing_detection && aecm_generate_comfort_noise == o.aecm_generate_comfort_noise && conference_mode == o.conference_mode && @@ -215,6 +219,8 @@ struct AudioOptions { ost << ToStringIfSet("swap", stereo_swapping); ost << ToStringIfSet("audio_jitter_buffer_max_packets", audio_jitter_buffer_max_packets); + ost << ToStringIfSet("audio_jitter_buffer_fast_accelerate", + audio_jitter_buffer_fast_accelerate); ost << ToStringIfSet("typing", typing_detection); ost << ToStringIfSet("comfort_noise", aecm_generate_comfort_noise); ost << ToStringIfSet("conference", conference_mode); @@ -255,6 +261,8 @@ struct AudioOptions { Settable stereo_swapping; // Audio receiver jitter buffer (NetEq) max capacity in number of packets. Settable audio_jitter_buffer_max_packets; + // Audio receiver jitter buffer (NetEq) fast accelerate mode. + Settable audio_jitter_buffer_fast_accelerate; // Audio processing to detect typing. Settable typing_detection; Settable aecm_generate_comfort_noise; diff --git a/talk/media/webrtc/fakewebrtcvoiceengine.h b/talk/media/webrtc/fakewebrtcvoiceengine.h index 673e3e0ac..971f9f07c 100644 --- a/talk/media/webrtc/fakewebrtcvoiceengine.h +++ b/talk/media/webrtc/fakewebrtcvoiceengine.h @@ -216,7 +216,8 @@ class FakeWebRtcVoiceEngine send_absolute_sender_time_ext_(-1), receive_absolute_sender_time_ext_(-1), associate_send_channel(-1), - neteq_capacity(-1) { + neteq_capacity(-1), + neteq_fast_accelerate(false) { memset(&send_codec, 0, sizeof(send_codec)); memset(&rx_agc_config, 0, sizeof(rx_agc_config)); } @@ -254,6 +255,7 @@ class FakeWebRtcVoiceEngine webrtc::PacketTime last_rtp_packet_time; std::list packets; int neteq_capacity; + bool neteq_fast_accelerate; }; FakeWebRtcVoiceEngine(const cricket::AudioCodec* const* codecs, @@ -409,6 +411,8 @@ class FakeWebRtcVoiceEngine if (config.Get().enabled) { ch->neteq_capacity = config.Get().capacity; } + ch->neteq_fast_accelerate = + config.Get().enabled; channels_[++last_channel_] = ch; return last_channel_; } @@ -1193,6 +1197,11 @@ class FakeWebRtcVoiceEngine ASSERT(ch != channels_.end()); return ch->second->neteq_capacity; } + bool GetNetEqFastAccelerate() const { + auto ch = channels_.find(last_channel_); + ASSERT(ch != channels_.end()); + return ch->second->neteq_fast_accelerate; + } private: int GetNumDevices(int& num) { diff --git a/talk/media/webrtc/webrtcvoiceengine.cc b/talk/media/webrtc/webrtcvoiceengine.cc index 230953e88..7f000ab6b 100644 --- a/talk/media/webrtc/webrtcvoiceengine.cc +++ b/talk/media/webrtc/webrtcvoiceengine.cc @@ -352,6 +352,7 @@ static AudioOptions GetDefaultEngineOptions() { options.highpass_filter.Set(true); options.stereo_swapping.Set(false); options.audio_jitter_buffer_max_packets.Set(50); + options.audio_jitter_buffer_fast_accelerate.Set(false); options.typing_detection.Set(true); options.conference_mode.Set(false); options.adjust_agc_delta.Set(0); @@ -801,6 +802,14 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { new webrtc::NetEqCapacityConfig(audio_jitter_buffer_max_packets)); } + bool audio_jitter_buffer_fast_accelerate; + if (options.audio_jitter_buffer_fast_accelerate.Get( + &audio_jitter_buffer_fast_accelerate)) { + LOG(LS_INFO) << "NetEq fast mode? " << audio_jitter_buffer_fast_accelerate; + voe_config_.Set( + new webrtc::NetEqFastAccelerate(audio_jitter_buffer_fast_accelerate)); + } + bool typing_detection; if (options.typing_detection.Get(&typing_detection)) { LOG(LS_INFO) << "Typing detection is enabled? " << typing_detection; diff --git a/talk/media/webrtc/webrtcvoiceengine_unittest.cc b/talk/media/webrtc/webrtcvoiceengine_unittest.cc index 658001104..0f2c73a5c 100644 --- a/talk/media/webrtc/webrtcvoiceengine_unittest.cc +++ b/talk/media/webrtc/webrtcvoiceengine_unittest.cc @@ -2843,6 +2843,8 @@ TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) { EXPECT_EQ(ec_mode, webrtc::kEcConference); EXPECT_EQ(ns_mode, webrtc::kNsHighSuppression); EXPECT_EQ(50, voe_.GetNetEqCapacity()); // From GetDefaultEngineOptions(). + EXPECT_FALSE( + voe_.GetNetEqFastAccelerate()); // From GetDefaultEngineOptions(). // Turn echo cancellation off options.echo_cancellation.Set(false); diff --git a/webrtc/config.h b/webrtc/config.h index 09633ed49..804f54d93 100644 --- a/webrtc/config.h +++ b/webrtc/config.h @@ -127,6 +127,12 @@ struct NetEqCapacityConfig { int capacity; }; +struct NetEqFastAccelerate { + NetEqFastAccelerate() : enabled(false) {} + explicit NetEqFastAccelerate(bool value) : enabled(value) {} + bool enabled; +}; + } // namespace webrtc #endif // WEBRTC_CONFIG_H_ diff --git a/webrtc/voice_engine/channel.cc b/webrtc/voice_engine/channel.cc index af2c58e4e..063ffa680 100644 --- a/webrtc/voice_engine/channel.cc +++ b/webrtc/voice_engine/channel.cc @@ -817,6 +817,8 @@ Channel::Channel(int32_t channelId, acm_config.neteq_config.max_packets_in_buffer = std::max(20, config.Get().capacity); } + acm_config.neteq_config.enable_fast_accelerate = + config.Get().enabled; audio_coding_.reset(AudioCodingModule::Create(acm_config)); _inbandDtmfQueue.ResetDtmf();