diff --git a/pc/media_session.cc b/pc/media_session.cc index c08d5393f3..b4fc63439a 100644 --- a/pc/media_session.cc +++ b/pc/media_session.cc @@ -1515,10 +1515,6 @@ std::unique_ptr MediaSessionDescriptionFactory::CreateOffer( VideoCodecs offer_video_codecs; GetCodecsForOffer(current_active_contents, &offer_audio_codecs, &offer_video_codecs); - if (!session_options.vad_enabled) { - // If application doesn't want CN codecs in offer. - StripCNCodecs(&offer_audio_codecs); - } AudioVideoRtpHeaderExtensions extensions_with_ids = GetOfferedRtpHeaderExtensionsWithIds( current_active_contents, session_options.offer_extmap_allow_mixed, @@ -1664,11 +1660,6 @@ MediaSessionDescriptionFactory::CreateAnswer( GetCodecsForAnswer(current_active_contents, *offer, &answer_audio_codecs, &answer_video_codecs); - if (!session_options.vad_enabled) { - // If application doesn't want CN codecs in answer. - StripCNCodecs(&answer_audio_codecs); - } - auto answer = std::make_unique(); // If the offer supports BUNDLE, and we want to use it too, create a BUNDLE @@ -2183,6 +2174,10 @@ bool MediaSessionDescriptionFactory::AddAudioContentForOffer( } } } + if (!session_options.vad_enabled) { + // If application doesn't want CN codecs in offer. + StripCNCodecs(&filtered_codecs); + } cricket::SecurePolicy sdes_policy = IsDtlsActive(current_content, current_description) ? cricket::SEC_DISABLED @@ -2458,6 +2453,10 @@ bool MediaSessionDescriptionFactory::AddAudioContentForAnswer( } } } + if (!session_options.vad_enabled) { + // If application doesn't want CN codecs in answer. + StripCNCodecs(&filtered_codecs); + } bool bundle_enabled = offer_description->HasGroup(GROUP_TYPE_BUNDLE) && session_options.bundle_enabled; diff --git a/pc/peer_connection_media_unittest.cc b/pc/peer_connection_media_unittest.cc index f078144d4f..28413f6ba9 100644 --- a/pc/peer_connection_media_unittest.cc +++ b/pc/peer_connection_media_unittest.cc @@ -1736,6 +1736,26 @@ TEST_F(PeerConnectionMediaTestUnifiedPlan, EXPECT_TRUE(CompareCodecs(video_codecs_vpx_reverse, recv_codecs)); } +TEST_F(PeerConnectionMediaTestUnifiedPlan, + SetCodecPreferencesVoiceActivityDetection) { + auto fake_engine = std::make_unique(); + AddComfortNoiseCodecsToSend(fake_engine.get()); + auto caller = CreatePeerConnectionWithAudio(std::move(fake_engine)); + + RTCOfferAnswerOptions options; + auto offer = caller->CreateOffer(options); + EXPECT_TRUE(HasAnyComfortNoiseCodecs(offer->description())); + + auto transceiver = caller->pc()->GetTransceivers().front(); + auto capabilities = caller->pc_factory()->GetRtpSenderCapabilities( + cricket::MediaType::MEDIA_TYPE_AUDIO); + EXPECT_TRUE(transceiver->SetCodecPreferences(capabilities.codecs).ok()); + + options.voice_activity_detection = false; + offer = caller->CreateOffer(options); + EXPECT_FALSE(HasAnyComfortNoiseCodecs(offer->description())); +} + INSTANTIATE_TEST_SUITE_P(PeerConnectionMediaTest, PeerConnectionMediaTest, Values(SdpSemantics::kPlanB,