diff --git a/modules/audio_coding/codecs/opus/opus_interface.cc b/modules/audio_coding/codecs/opus/opus_interface.cc index 033791971f..67d8619b34 100644 --- a/modules/audio_coding/codecs/opus/opus_interface.cc +++ b/modules/audio_coding/codecs/opus/opus_interface.cc @@ -42,6 +42,9 @@ constexpr char kPlcUsePrevDecodedSamplesFieldTrial[] = constexpr char kAvoidNoisePumpingDuringDtxFieldTrial[] = "WebRTC-Audio-OpusAvoidNoisePumpingDuringDtx"; +constexpr char kSetSignalVoiceWithDtxFieldTrial[] = + "WebRTC-Audio-OpusSetSignalVoiceWithDtx"; + static int FrameSizePerChannel(int frame_size_ms, int sample_rate_hz) { RTC_DCHECK_GT(frame_size_ms, 0); RTC_DCHECK_EQ(frame_size_ms % 10, 0); @@ -358,27 +361,27 @@ int16_t WebRtcOpus_DisableFec(OpusEncInst* inst) { } int16_t WebRtcOpus_EnableDtx(OpusEncInst* inst) { - if (!inst) { + if (inst) { + if (webrtc::field_trial::IsEnabled(kSetSignalVoiceWithDtxFieldTrial)) { + int ret = ENCODER_CTL(inst, OPUS_SET_SIGNAL(OPUS_SIGNAL_VOICE)); + if (ret != OPUS_OK) { + return ret; + } + } + return ENCODER_CTL(inst, OPUS_SET_DTX(1)); + } else { return -1; } - - // To prevent Opus from entering CELT-only mode by forcing signal type to - // voice to make sure that DTX behaves correctly. Currently, DTX does not - // last long during a pure silence, if the signal type is not forced. - // TODO(minyue): Remove the signal type forcing when Opus DTX works properly - // without it. - int ret = ENCODER_CTL(inst, OPUS_SET_SIGNAL(OPUS_SIGNAL_VOICE)); - if (ret != OPUS_OK) - return ret; - - return ENCODER_CTL(inst, OPUS_SET_DTX(1)); } int16_t WebRtcOpus_DisableDtx(OpusEncInst* inst) { if (inst) { - int ret = ENCODER_CTL(inst, OPUS_SET_SIGNAL(OPUS_AUTO)); - if (ret != OPUS_OK) - return ret; + if (webrtc::field_trial::IsEnabled(kSetSignalVoiceWithDtxFieldTrial)) { + int ret = ENCODER_CTL(inst, OPUS_SET_SIGNAL(OPUS_AUTO)); + if (ret != OPUS_OK) { + return ret; + } + } return ENCODER_CTL(inst, OPUS_SET_DTX(0)); } else { return -1; diff --git a/modules/audio_coding/codecs/opus/opus_unittest.cc b/modules/audio_coding/codecs/opus/opus_unittest.cc index b40d73805f..4a9156ad58 100644 --- a/modules/audio_coding/codecs/opus/opus_unittest.cc +++ b/modules/audio_coding/codecs/opus/opus_unittest.cc @@ -736,7 +736,8 @@ TEST_P(OpusTest, OpusDtxOff) { } TEST_P(OpusTest, OpusDtxOn) { - if (channels_ > 2) { + if (channels_ > 2 || application_ != 0) { + // DTX does not work with OPUS_APPLICATION_AUDIO at low complexity settings. // TODO(webrtc:10218): adapt the test to the sizes and order of multi-stream // DTX packets. return; diff --git a/modules/audio_coding/test/TestVADDTX.cc b/modules/audio_coding/test/TestVADDTX.cc index 19367d9bde..de26cafb68 100644 --- a/modules/audio_coding/test/TestVADDTX.cc +++ b/modules/audio_coding/test/TestVADDTX.cc @@ -235,30 +235,6 @@ void TestOpusDtx::Perform() { expects[static_cast(AudioFrameType::kAudioFrameCN)] = 1; Run(webrtc::test::ResourcePath("audio_coding/testfile32kHz", "pcm"), 32000, 1, out_filename, true, expects); - - // 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* encoder_ptr) { - (*encoder_ptr)->SetDtx(false); - }); - expects[static_cast(AudioFrameType::kEmptyFrame)] = 0; - expects[static_cast(AudioFrameType::kAudioFrameCN)] = 0; - Run(webrtc::test::ResourcePath("audio_coding/teststereo32kHz", "pcm"), 32000, - 2, out_filename, false, expects); - - acm_send_->ModifyEncoder([](std::unique_ptr* encoder_ptr) { - (*encoder_ptr)->SetDtx(true); - // The default bitrate will not generate frames recognized as CN on desktop - // since the frames will be encoded as CELT. Set a low target bitrate to get - // consistent behaviour across platforms. - (*encoder_ptr)->OnReceivedTargetAudioBitrate(24000); - }); - - expects[static_cast(AudioFrameType::kEmptyFrame)] = 1; - expects[static_cast(AudioFrameType::kAudioFrameCN)] = 1; - Run(webrtc::test::ResourcePath("audio_coding/teststereo32kHz", "pcm"), 32000, - 2, out_filename, true, expects); } } // namespace webrtc