Bug 1952339 - Vendor libwebrtc from c896e3a5b5

Upstream commit: https://webrtc.googlesource.com/src/+/c896e3a5b59e0169e5bc6fcf3dee9dd4a9834b8e
    Cleanup implemenation of AudioState SetRecording/SetPlayout vs. Add/Remove {Send/Recv}stream

    So that they behave in the most obvious ways:
    Set{Recording/Playout} = TRUE
      - Enables {Recording/Playout} is there are {Send/Recv} streams
      - Set state variable

    Set{Recording/Plaout} = FALSE
      - Disable {Recording/Playout}
      - Set state variable

    Add {Send/Recv} stream
      - Enables {Recording/Playout} if state variable is TRUE
      - Otherwise does nothing

    Remove {Send/Recv} stream
      - Disable {Recording/Playout} if last stream
      - Otherwise does nothing

    ---

    Before this patch the behavior was hard to non obvious,
    e.g SetRecording(false) followed by SetRecording(true)
    did not work (same for playout).


    BUG=b/397376626

    Change-Id: I530497d4a46ad73334fcb3d73f4b87264bd18486
    Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/378740
    Reviewed-by: Jakob Ivarsson‎ <jakobi@webrtc.org>
    Commit-Queue: Jonas Oreland <jonaso@webrtc.org>
    Reviewed-by: Harald Alvestrand <hta@webrtc.org>
    Cr-Commit-Position: refs/heads/main@{#44025}

Differential Revision: https://phabricator.services.mozilla.com/D244036
This commit is contained in:
Michael Froman
2025-03-07 18:17:20 -06:00
parent 108009c984
commit a1e796bc69
18 changed files with 274 additions and 69 deletions

View File

@@ -1,4 +1,4 @@
# ./mach python dom/media/webrtc/third_party_build/vendor-libwebrtc.py --from-local /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc --commit mozpatches libwebrtc
libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-03-08T00:16:16.404369+00:00.
libwebrtc updated from /home/mfroman/mozilla/elm/.moz-fast-forward/moz-libwebrtc commit mozpatches on 2025-03-08T00:17:08.925423+00:00.
# base of lastest vendoring
231ece13b7
c896e3a5b5

View File

@@ -106,6 +106,7 @@ class AudioReceiveStreamImpl final : public webrtc::AudioReceiveStreamInterface,
bool SetBaseMinimumPlayoutDelayMs(int delay_ms) override;
int GetBaseMinimumPlayoutDelayMs() const override;
std::vector<webrtc::RtpSource> GetSources() const override;
AudioMixer::Source* source() override { return this; }
// AudioMixer::Source
AudioFrameInfo GetAudioFrameWithInfo(int sample_rate_hz,

View File

@@ -51,28 +51,47 @@ AudioTransport* AudioState::audio_transport() {
return &audio_transport_;
}
void AudioState::SetPlayout(bool enabled) {
RTC_LOG(LS_INFO) << "SetPlayout(" << enabled << ")";
RTC_DCHECK_RUN_ON(&thread_checker_);
auto* adm = config_.audio_device_module.get();
if (enabled) {
if (!receiving_streams_.empty()) {
if (!adm->Playing()) {
if (adm->InitPlayout() == 0) {
adm->StartPlayout();
}
}
}
} else {
// Disable playout.
config_.audio_device_module->StopPlayout();
}
playout_enabled_ = enabled;
UpdateNullAudioPollerState();
}
void AudioState::AddReceivingStream(
webrtc::AudioReceiveStreamInterface* stream) {
RTC_DCHECK_RUN_ON(&thread_checker_);
RTC_DCHECK_EQ(0, receiving_streams_.count(stream));
receiving_streams_.insert(stream);
if (!config_.audio_mixer->AddSource(
static_cast<AudioReceiveStreamImpl*>(stream))) {
if (!config_.audio_mixer->AddSource(stream->source())) {
RTC_DLOG(LS_ERROR) << "Failed to add source to mixer.";
}
// Make sure playback is initialized; start playing if enabled.
UpdateNullAudioPollerState();
auto* adm = config_.audio_device_module.get();
if (!adm->Playing()) {
if (adm->InitPlayout() == 0) {
if (playout_enabled_) {
if (playout_enabled_) {
auto* adm = config_.audio_device_module.get();
if (!adm->Playing()) {
if (adm->InitPlayout() == 0) {
adm->StartPlayout();
}
} else {
RTC_DLOG_F(LS_ERROR) << "Failed to initialize playout.";
}
}
UpdateNullAudioPollerState();
}
void AudioState::RemoveReceivingStream(
@@ -80,12 +99,30 @@ void AudioState::RemoveReceivingStream(
RTC_DCHECK_RUN_ON(&thread_checker_);
auto count = receiving_streams_.erase(stream);
RTC_DCHECK_EQ(1, count);
config_.audio_mixer->RemoveSource(
static_cast<AudioReceiveStreamImpl*>(stream));
UpdateNullAudioPollerState();
config_.audio_mixer->RemoveSource(stream->source());
if (receiving_streams_.empty()) {
config_.audio_device_module->StopPlayout();
}
UpdateNullAudioPollerState();
}
void AudioState::SetRecording(bool enabled) {
RTC_LOG(LS_INFO) << "SetRecording(" << enabled << ")";
RTC_DCHECK_RUN_ON(&thread_checker_);
auto* adm = config_.audio_device_module.get();
if (enabled) {
if (!sending_streams_.empty()) {
if (!adm->Recording()) {
if (adm->InitRecording() == 0) {
adm->StartRecording();
}
}
}
} else {
// Disable recording.
adm->StopRecording();
}
recording_enabled_ = enabled;
}
void AudioState::AddSendingStream(webrtc::AudioSendStream* stream,
@@ -99,9 +136,9 @@ void AudioState::AddSendingStream(webrtc::AudioSendStream* stream,
// Make sure recording is initialized; start recording if enabled.
auto* adm = config_.audio_device_module.get();
if (!adm->Recording()) {
if (adm->InitRecording() == 0) {
if (recording_enabled_) {
if (recording_enabled_) {
if (!adm->Recording()) {
if (adm->InitRecording() == 0) {
adm->StartRecording();
}
} else {
@@ -120,46 +157,6 @@ void AudioState::RemoveSendingStream(webrtc::AudioSendStream* stream) {
}
}
void AudioState::SetPlayout(bool enabled) {
RTC_LOG(LS_INFO) << "SetPlayout(" << enabled << ")";
RTC_DCHECK_RUN_ON(&thread_checker_);
if (playout_enabled_ != enabled) {
playout_enabled_ = enabled;
if (enabled) {
UpdateNullAudioPollerState();
if (!receiving_streams_.empty()) {
config_.audio_device_module->StartPlayout();
}
} else {
config_.audio_device_module->StopPlayout();
UpdateNullAudioPollerState();
}
}
}
void AudioState::SetRecording(bool enabled) {
RTC_LOG(LS_INFO) << "SetRecording(" << enabled << ")";
RTC_DCHECK_RUN_ON(&thread_checker_);
auto* adm = config_.audio_device_module.get();
if (recording_enabled_ != enabled) {
auto* adm = config_.audio_device_module.get();
recording_enabled_ = enabled;
if (enabled) {
if (!sending_streams_.empty()) {
if (adm->InitRecording() == 0) {
adm->StartRecording();
}
}
} else {
adm->StopRecording();
}
} else if (!enabled && adm->RecordingIsInitialized()) {
// The recording can also be initialized by WebRtcVoiceSendChannel
// options_.init_recording_on_send.
adm->StopRecording();
}
}
void AudioState::SetStereoChannelSwapping(bool enable) {
RTC_DCHECK(thread_checker_.IsCurrent());
audio_transport_.SetStereoChannelSwapping(enable);

View File

@@ -15,10 +15,12 @@
#include <vector>
#include "api/task_queue/test/mock_task_queue_base.h"
#include "call/test/mock_audio_receive_stream.h"
#include "call/test/mock_audio_send_stream.h"
#include "modules/audio_device/include/mock_audio_device.h"
#include "modules/audio_mixer/audio_mixer_impl.h"
#include "modules/audio_processing/include/mock_audio_processing.h"
#include "rtc_base/thread.h"
#include "test/gtest.h"
namespace webrtc {
@@ -358,6 +360,38 @@ TEST_P(AudioStateTest,
audio_buffer, n_samples_out, &elapsed_time_ms, &ntp_time_ms);
}
TEST_P(AudioStateTest, StartRecordingDoesNothingWithoutStream) {
ConfigHelper helper(GetParam());
rtc::scoped_refptr<internal::AudioState> audio_state(
rtc::make_ref_counted<internal::AudioState>(helper.config()));
auto* adm = reinterpret_cast<MockAudioDeviceModule*>(
helper.config().audio_device_module.get());
EXPECT_CALL(*adm, InitRecording()).Times(0);
EXPECT_CALL(*adm, StartRecording()).Times(0);
EXPECT_CALL(*adm, StopRecording()).Times(1);
audio_state->SetRecording(false);
audio_state->SetRecording(true);
}
TEST_P(AudioStateTest, AddStreamDoesNothingIfRecordingDisabled) {
ConfigHelper helper(GetParam());
rtc::scoped_refptr<internal::AudioState> audio_state(
rtc::make_ref_counted<internal::AudioState>(helper.config()));
auto* adm = reinterpret_cast<MockAudioDeviceModule*>(
helper.config().audio_device_module.get());
EXPECT_CALL(*adm, StopRecording()).Times(2);
audio_state->SetRecording(false);
MockAudioSendStream stream;
EXPECT_CALL(*adm, StartRecording).Times(0);
audio_state->AddSendingStream(&stream, kSampleRate, kNumberOfChannels);
audio_state->RemoveSendingStream(&stream);
}
TEST_P(AudioStateTest, AlwaysCallInitRecordingBeforeStartRecording) {
ConfigHelper helper(GetParam());
rtc::scoped_refptr<internal::AudioState> audio_state(
@@ -401,11 +435,97 @@ TEST_P(AudioStateTest, CallStopRecordingIfRecordingIsInitialized) {
audio_state->SetRecording(false);
EXPECT_CALL(*adm, RecordingIsInitialized()).WillOnce(testing::Return(true));
EXPECT_CALL(*adm, StopRecording());
audio_state->SetRecording(false);
}
TEST_P(AudioStateTest, StartPlayoutDoesNothingWithoutStream) {
ConfigHelper helper(GetParam());
rtc::scoped_refptr<internal::AudioState> audio_state(
rtc::make_ref_counted<internal::AudioState>(helper.config()));
auto* adm = reinterpret_cast<MockAudioDeviceModule*>(
helper.config().audio_device_module.get());
EXPECT_CALL(*adm, InitPlayout()).Times(0);
EXPECT_CALL(*adm, StartPlayout()).Times(0);
EXPECT_CALL(*adm, StopPlayout()).Times(1);
audio_state->SetPlayout(false);
audio_state->SetPlayout(true);
}
TEST_P(AudioStateTest, AlwaysCallInitPlayoutBeforeStartPlayout) {
ConfigHelper helper(GetParam());
rtc::scoped_refptr<internal::AudioState> audio_state(
rtc::make_ref_counted<internal::AudioState>(helper.config()));
auto* adm = reinterpret_cast<MockAudioDeviceModule*>(
helper.config().audio_device_module.get());
MockAudioReceiveStream stream;
{
InSequence s;
EXPECT_CALL(*adm, InitPlayout());
EXPECT_CALL(*adm, StartPlayout());
audio_state->AddReceivingStream(&stream);
}
// SetPlayout(false) starts the NullAudioPoller...which needs a thread.
rtc::ThreadManager::Instance()->WrapCurrentThread();
EXPECT_CALL(*adm, StopPlayout());
audio_state->SetPlayout(false);
{
InSequence s;
EXPECT_CALL(*adm, InitPlayout());
EXPECT_CALL(*adm, StartPlayout());
audio_state->SetPlayout(true);
}
// Playout without streams starts the NullAudioPoller...
// which needs a thread.
rtc::ThreadManager::Instance()->WrapCurrentThread();
EXPECT_CALL(*adm, StopPlayout());
audio_state->RemoveReceivingStream(&stream);
}
TEST_P(AudioStateTest, CallStopPlayoutIfPlayoutIsInitialized) {
ConfigHelper helper(GetParam());
rtc::scoped_refptr<internal::AudioState> audio_state(
rtc::make_ref_counted<internal::AudioState>(helper.config()));
auto* adm = reinterpret_cast<MockAudioDeviceModule*>(
helper.config().audio_device_module.get());
audio_state->SetPlayout(false);
EXPECT_CALL(*adm, StopPlayout());
audio_state->SetPlayout(false);
}
TEST_P(AudioStateTest, AddStreamDoesNothingIfPlayoutDisabled) {
ConfigHelper helper(GetParam());
rtc::scoped_refptr<internal::AudioState> audio_state(
rtc::make_ref_counted<internal::AudioState>(helper.config()));
auto* adm = reinterpret_cast<MockAudioDeviceModule*>(
helper.config().audio_device_module.get());
EXPECT_CALL(*adm, StopPlayout()).Times(2);
audio_state->SetPlayout(false);
// AddReceivingStream with playout disabled start the NullAudioPoller...
// which needs a thread.
rtc::ThreadManager::Instance()->WrapCurrentThread();
MockAudioReceiveStream stream;
audio_state->AddReceivingStream(&stream);
audio_state->RemoveReceivingStream(&stream);
}
INSTANTIATE_TEST_SUITE_P(AudioStateTest,
AudioStateTest,
Values(ConfigHelper::Params({false, false}),

View File

@@ -778,9 +778,13 @@ if (rtc_include_tests) {
rtc_source_set("mock_call_interfaces") {
testonly = true
sources = [ "test/mock_audio_send_stream.h" ]
sources = [
"test/mock_audio_receive_stream.h",
"test/mock_audio_send_stream.h",
]
deps = [
":call_interfaces",
"../api/audio:audio_mixer_api",
"../test:test_support",
]
}

View File

@@ -17,6 +17,7 @@
#include <optional>
#include <string>
#include "api/audio/audio_mixer.h"
#include "api/audio_codecs/audio_codec_pair_id.h"
#include "api/audio_codecs/audio_decoder_factory.h"
#include "api/audio_codecs/audio_format.h"
@@ -213,6 +214,10 @@ class AudioReceiveStreamInterface : public MediaReceiveStreamInterface {
// post initialization.
virtual uint32_t remote_ssrc() const = 0;
// Get the object suitable to inject into the AudioMixer
// (normally "this").
virtual AudioMixer::Source* source() = 0;
protected:
virtual ~AudioReceiveStreamInterface() {}
};

View File

@@ -0,0 +1,72 @@
/*
* Copyright (c) 2025 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef CALL_TEST_MOCK_AUDIO_RECEIVE_STREAM_H_
#define CALL_TEST_MOCK_AUDIO_RECEIVE_STREAM_H_
#include <map>
#include <vector>
#include "api/audio/audio_mixer.h"
#include "call/audio_receive_stream.h"
#include "test/gmock.h"
namespace webrtc {
namespace test {
class MockAudioReceiveStream : public AudioReceiveStreamInterface,
public AudioMixer::Source {
public:
MOCK_METHOD(uint32_t, remote_ssrc, (), (const override));
MOCK_METHOD(void, Start, (), (override));
MOCK_METHOD(void, Stop, (), (override));
MOCK_METHOD(bool, IsRunning, (), (const override));
MOCK_METHOD(void,
SetDepacketizerToDecoderFrameTransformer,
(rtc::scoped_refptr<webrtc::FrameTransformerInterface>),
(override));
MOCK_METHOD(void,
SetDecoderMap,
((std::map<int, webrtc::SdpAudioFormat>)),
(override));
MOCK_METHOD(void, SetNackHistory, (int), (override));
MOCK_METHOD(void, SetRtcpMode, (webrtc::RtcpMode), (override));
MOCK_METHOD(void, SetNonSenderRttMeasurement, (bool), (override));
MOCK_METHOD(void,
SetFrameDecryptor,
(rtc::scoped_refptr<webrtc::FrameDecryptorInterface>),
(override));
MOCK_METHOD(webrtc::AudioReceiveStreamInterface::Stats,
GetStats,
(bool),
(const override));
MOCK_METHOD(void, SetSink, (webrtc::AudioSinkInterface*), (override));
MOCK_METHOD(void, SetGain, (float), (override));
MOCK_METHOD(bool, SetBaseMinimumPlayoutDelayMs, (int), (override));
MOCK_METHOD(int, GetBaseMinimumPlayoutDelayMs, (), (const override));
MOCK_METHOD(std::vector<webrtc::RtpSource>, GetSources, (), (const override));
// TODO (b/397376626): Create a MockAudioMixerSource, and instead
// have a member variable here.
AudioMixer::Source* source() override { return this; }
MOCK_METHOD(AudioFrameInfo,
GetAudioFrameWithInfo,
(int, AudioFrame*),
(override));
MOCK_METHOD(int, Ssrc, (), (const override));
MOCK_METHOD(int, PreferredSampleRate, (), (const override));
};
} // namespace test
} // namespace webrtc
#endif // CALL_TEST_MOCK_AUDIO_RECEIVE_STREAM_H_

View File

@@ -866,6 +866,7 @@ if (rtc_include_tests) {
"../api:scoped_refptr",
"../api/adaptation:resource_adaptation_api",
"../api/audio:audio_frame_api",
"../api/audio:audio_mixer_api",
"../api/audio:audio_processing",
"../api/audio_codecs:audio_codecs_api",
"../api/crypto:frame_decryptor_interface",

View File

@@ -32,6 +32,7 @@
#include "absl/strings/string_view.h"
#include "api/adaptation/resource.h"
#include "api/audio/audio_frame.h"
#include "api/audio/audio_mixer.h"
#include "api/audio_codecs/audio_format.h"
#include "api/crypto/frame_decryptor_interface.h"
#include "api/environment/environment.h"
@@ -171,6 +172,10 @@ class FakeAudioReceiveStream final
std::vector<webrtc::RtpSource> GetSources() const override {
return std::vector<webrtc::RtpSource>();
}
webrtc::AudioMixer::Source* source() override {
// TODO(b/397376626): Add a Fake AudioMixer::Source
return nullptr;
}
private:
int id_ = -1;

View File

@@ -415,7 +415,7 @@ index dd5744218f..ced44047aa 100644
bool RtpExtension::IsSupportedForVideo(absl::string_view uri) {
diff --git a/call/BUILD.gn b/call/BUILD.gn
index 8833fe9ff4..b5f9ac1daa 100644
index 09cd9eb676..7e13144381 100644
--- a/call/BUILD.gn
+++ b/call/BUILD.gn
@@ -20,6 +20,7 @@ rtc_library("call_interfaces") {

View File

@@ -476,7 +476,7 @@ index 7769526e07..f56ce3ce54 100644
if (rtc_include_tests) {
rtc_source_set("test_feedback_generator_interface") {
diff --git a/call/BUILD.gn b/call/BUILD.gn
index b5f9ac1daa..c06e7db330 100644
index 7e13144381..5646f6bff5 100644
--- a/call/BUILD.gn
+++ b/call/BUILD.gn
@@ -48,7 +48,7 @@ rtc_library("call_interfaces") {
@@ -574,7 +574,7 @@ index 0000000000..f6ff7f218f
+ #endif
+#endif
diff --git a/media/BUILD.gn b/media/BUILD.gn
index e88ef6d975..f6db71f62d 100644
index 75fd8bda50..655b155c6a 100644
--- a/media/BUILD.gn
+++ b/media/BUILD.gn
@@ -76,7 +76,7 @@ rtc_library("rtc_media_base") {

View File

@@ -113,10 +113,10 @@ index 72eb3fa9fc..fc5fa28d9d 100644
} // namespace voe
} // namespace webrtc
diff --git a/call/audio_receive_stream.h b/call/audio_receive_stream.h
index 9e64521796..e103122184 100644
index 42502f5297..25010da77b 100644
--- a/call/audio_receive_stream.h
+++ b/call/audio_receive_stream.h
@@ -21,6 +21,7 @@
@@ -22,6 +22,7 @@
#include "api/audio_codecs/audio_decoder_factory.h"
#include "api/audio_codecs/audio_format.h"
#include "api/call/transport.h"
@@ -124,7 +124,7 @@ index 9e64521796..e103122184 100644
#include "api/crypto/crypto_options.h"
#include "api/crypto/frame_decryptor_interface.h"
#include "api/frame_transformer_interface.h"
@@ -129,6 +130,8 @@ class AudioReceiveStreamInterface : public MediaReceiveStreamInterface {
@@ -130,6 +131,8 @@ class AudioReceiveStreamInterface : public MediaReceiveStreamInterface {
// See NackConfig for description.
NackConfig nack;
RtcpMode rtcp_mode = RtcpMode::kCompound;

View File

@@ -14,7 +14,7 @@ Subject: Bug 1766646 - (fix) breakout Call::Stats and SharedModuleThread into
create mode 100644 call/call_basic_stats.h
diff --git a/call/BUILD.gn b/call/BUILD.gn
index c06e7db330..fb10c44c64 100644
index 5646f6bff5..80ada68865 100644
--- a/call/BUILD.gn
+++ b/call/BUILD.gn
@@ -33,6 +33,12 @@ rtc_library("call_interfaces") {

View File

@@ -9,7 +9,7 @@ Mercurial Revision: https://hg.mozilla.org/mozilla-central/rev/60304c5d8a86fdecf
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/media/BUILD.gn b/media/BUILD.gn
index f6db71f62d..3fa9743d0a 100644
index 655b155c6a..39b31d16ce 100644
--- a/media/BUILD.gn
+++ b/media/BUILD.gn
@@ -55,6 +55,11 @@ rtc_library("rtc_media_base") {

View File

@@ -35,7 +35,7 @@ index e379d18527..c810498584 100644
# Normally, we'd use 'if (!build_with_mozilla)', but that flag isn't
# available yet.
diff --git a/media/BUILD.gn b/media/BUILD.gn
index 3fa9743d0a..9f8058855c 100644
index 39b31d16ce..50736c10af 100644
--- a/media/BUILD.gn
+++ b/media/BUILD.gn
@@ -7,7 +7,7 @@

View File

@@ -470,7 +470,7 @@ index d91a446629..3c18ef1841 100644
group("logging") {
diff --git a/media/BUILD.gn b/media/BUILD.gn
index 9f8058855c..8a63ca247e 100644
index 50736c10af..b855511fdb 100644
--- a/media/BUILD.gn
+++ b/media/BUILD.gn
@@ -6,7 +6,7 @@

View File

@@ -38,7 +38,7 @@ index b44356c790..0dd2bb4f74 100644
]
# Added when we removed deps in other places to avoid building
diff --git a/media/BUILD.gn b/media/BUILD.gn
index 8a63ca247e..15c31461fa 100644
index b855511fdb..b32e6aba0d 100644
--- a/media/BUILD.gn
+++ b/media/BUILD.gn
@@ -12,12 +12,10 @@ import("../webrtc.gni")

View File

@@ -10,7 +10,7 @@ Mercurial Revision: https://hg.mozilla.org/mozilla-central/rev/b6dd815fc9d2df718
1 file changed, 11 deletions(-)
diff --git a/media/BUILD.gn b/media/BUILD.gn
index 15c31461fa..90bdc8d682 100644
index b32e6aba0d..80127aad2b 100644
--- a/media/BUILD.gn
+++ b/media/BUILD.gn
@@ -53,11 +53,6 @@ rtc_library("rtc_media_base") {