Remove audio stream from old sync group on update. If the sync group for an audio receive stream is updated, it must be removed from the old sync group as well so that the old group does not have an invalid reference. Bug: chromium:504599749 Change-Id: I548e194d4f8ac6461388d639836e1f62f6b7f7e7 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/465663 Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org> Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#47504}
diff --git a/call/call.cc b/call/call.cc index 0efef93..39905c0 100644 --- a/call/call.cc +++ b/call/call.cc
@@ -1229,7 +1229,11 @@ RTC_DCHECK_RUN_ON(worker_thread_); webrtc::AudioReceiveStreamImpl& receive_stream = static_cast<webrtc::AudioReceiveStreamImpl&>(stream); + std::string old_sync_group(receive_stream.sync_group()); receive_stream.SetSyncGroup(sync_group); + if (old_sync_group != sync_group) { + ConfigureSync(old_sync_group); + } ConfigureSync(sync_group); }
diff --git a/call/call_unittest.cc b/call/call_unittest.cc index 1a4f1e5..e024898 100644 --- a/call/call_unittest.cc +++ b/call/call_unittest.cc
@@ -28,6 +28,7 @@ #include "api/test/mock_audio_mixer.h" #include "api/test/mock_video_decoder_factory.h" #include "api/test/video/function_video_encoder_factory.h" +#include "api/units/time_delta.h" #include "api/units/timestamp.h" #include "api/video/builtin_video_bitrate_allocator_factory.h" #include "api/video_codecs/sdp_video_format.h" @@ -55,6 +56,7 @@ #include "test/mock_audio_decoder_factory.h" #include "test/mock_transport.h" #include "test/run_loop.h" +#include "test/time_controller/simulated_time_controller.h" #include "video/config/video_encoder_config.h" namespace webrtc { @@ -614,4 +616,53 @@ un_demuxable_packet_handler_.AsStdFunction()); } +TEST(CallTest, HandlesAudioSyncGroupUpdate) { + // Set up a call with an audio stream and a video stream in the same sync + // group. + GlobalSimulatedTimeController time_controller(Timestamp::Seconds(1)); + Environment env = CreateTestEnvironment({.time = &time_controller}); + + AudioState::Config audio_state_config; + audio_state_config.audio_mixer = make_ref_counted<MockAudioMixer>(); + audio_state_config.audio_device_module = + make_ref_counted<MockAudioDeviceModule>(); + CallConfig config(env); + config.audio_state = AudioState::Create(audio_state_config); + std::unique_ptr<Call> call(Call::Create(std::move(config))); + + AudioReceiveStreamInterface::Config audio_config; + MockTransport rtcp_send_transport; + audio_config.rtp.remote_ssrc = 42; + audio_config.rtcp_send_transport = &rtcp_send_transport; + audio_config.decoder_factory = make_ref_counted<MockAudioDecoderFactory>(); + audio_config.sync_group = "group1"; + AudioReceiveStreamInterface* audio_stream = + call->CreateAudioReceiveStream(audio_config); + ASSERT_NE(audio_stream, nullptr); + + MockTransport video_rtcp_transport; + test::FakeVideoRenderer video_renderer; + VideoReceiveStreamInterface::Config video_config(&video_rtcp_transport); + video_config.rtp.remote_ssrc = 43; + video_config.sync_group = "group1"; + video_config.renderer = &video_renderer; + MockVideoDecoderFactory video_decoder_factory; + video_config.decoder_factory = &video_decoder_factory; + VideoReceiveStreamInterface::Decoder decoder; + decoder.payload_type = 96; + decoder.video_format = SdpVideoFormat("VP8"); + video_config.decoders.push_back(decoder); + VideoReceiveStreamInterface* video_stream = + call->CreateVideoReceiveStream(std::move(video_config)); + ASSERT_NE(video_stream, nullptr); + + // Move the audio stream to a new sync group and then remove it. + call->OnUpdateSyncGroup(*audio_stream, "group2"); + call->DestroyAudioReceiveStream(audio_stream); + + // The video stream should not be affected. + time_controller.AdvanceTime(TimeDelta::Seconds(2)); + call->DestroyVideoReceiveStream(video_stream); +} + } // namespace webrtc