Make sure OnChanged() notifications are handled, post construction.

If an instance of AudioRtpReceiver was initialized with a valid media
channel pointer (i.e. SetMediaChannel() was not being called), then
OnChanged() notification would not be handled correctly.

This fixes the issue by making sure the safety flag is marked as
'alive' when [re]starting the media channel.

Bug: webrtc:13854
Fixes: webrtc:13854
Change-Id: Iaa5cfeb4036bfc9dc2efbfa9e1319d508ab151a9
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/256361
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36290}
This commit is contained in:
Tommi
2022-03-22 11:54:09 +01:00
committed by WebRTC LUCI CQ
parent 6dbc1723f1
commit ed3832b89f
2 changed files with 36 additions and 0 deletions

View File

@ -191,6 +191,11 @@ void AudioRtpReceiver::RestartMediaChannel_w(
if (!media_channel_)
return; // Can't restart.
// Make sure the safety flag is marked as `alive` for cases where the media
// channel was provided via the ctor and not an explicit call to
// SetMediaChannel.
worker_thread_safety_->SetAlive();
if (state != MediaSourceInterface::kInitializing) {
if (ssrc_ == ssrc)
return;

View File

@ -18,6 +18,7 @@
#include "rtc_base/thread.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/run_loop.h"
using ::testing::_;
using ::testing::InvokeWithoutArgs;
@ -93,4 +94,34 @@ TEST_F(AudioRtpReceiverTest, VolumesSetBeforeStartingAreRespected) {
receiver_->SetupMediaChannel(kSsrc);
}
// Tests that OnChanged notifications are processed correctly on the worker
// thread when a media channel pointer is passed to the receiver via the
// constructor.
TEST(AudioRtpReceiver, OnChangedNotificationsAfterConstruction) {
webrtc::test::RunLoop loop;
auto* thread = rtc::Thread::Current(); // Points to loop's thread.
cricket::MockVoiceMediaChannel media_channel(thread);
auto receiver = rtc::make_ref_counted<AudioRtpReceiver>(
thread, std::string(), std::vector<std::string>(), true, &media_channel);
EXPECT_CALL(media_channel, SetDefaultRawAudioSink(_)).Times(1);
EXPECT_CALL(media_channel, SetDefaultOutputVolume(kDefaultVolume)).Times(1);
receiver->SetupUnsignaledMediaChannel();
loop.Flush();
// Mark the track as disabled.
receiver->track()->set_enabled(false);
// When the track was marked as disabled, an async notification was queued
// for the worker thread. This notification should trigger the volume
// of the media channel to be set to kVolumeMuted.
// Flush the worker thread, but set the expectation first for the call.
EXPECT_CALL(media_channel, SetDefaultOutputVolume(kVolumeMuted)).Times(1);
loop.Flush();
EXPECT_CALL(media_channel, SetDefaultOutputVolume(kVolumeMuted)).Times(1);
receiver->SetMediaChannel(nullptr);
}
} // namespace webrtc