Bug 1942171 - use WebrtcEnvironmentWrapper in WebrtcCallWrapper. r=pehrsons

Differential Revision: https://phabricator.services.mozilla.com/D236615
This commit is contained in:
Michael Froman
2025-02-05 18:04:00 +00:00
parent 8258aa075c
commit 2639efa306
5 changed files with 32 additions and 33 deletions

View File

@@ -31,6 +31,7 @@
#include "libwebrtcglue/AudioConduit.h"
#include "libwebrtcglue/VideoConduit.h"
#include "libwebrtcglue/WebrtcCallWrapper.h"
#include "libwebrtcglue/WebrtcEnvironmentWrapper.h"
#include "MediaTrackGraph.h"
#include "transport/runnable_utils.h"
#include "IPeerConnection.h"
@@ -4640,8 +4641,9 @@ already_AddRefed<dom::RTCRtpTransceiver> PeerConnectionImpl::CreateTransceiver(
dom::MediaStreamTrack* aSendTrack, bool aAddTrackMagic, ErrorResult& aRv) {
PeerConnectionCtx* ctx = PeerConnectionCtx::GetInstance();
if (!mCall) {
auto envWrapper = WebrtcEnvironmentWrapper::Create(GetTimestampMaker());
mCall = WebrtcCallWrapper::Create(
GetTimestampMaker(),
std::move(envWrapper), GetTimestampMaker(),
media::ShutdownBlockingTicket::Create(
u"WebrtcCallWrapper shutdown blocker"_ns,
NS_LITERAL_STRING_FROM_CSTRING(__FILE__), __LINE__),

View File

@@ -7,39 +7,32 @@
#include "WebrtcCallWrapper.h"
#include "jsapi/PeerConnectionCtx.h"
#include "libwebrtcglue/WebrtcEnvironmentWrapper.h"
#include "MediaConduitInterface.h"
#include "TaskQueueWrapper.h"
// libwebrtc includes
#include "api/environment/environment.h"
#include "api/environment/environment_factory.h"
#include "call/rtp_transport_controller_send_factory.h"
namespace mozilla {
/* static */ RefPtr<WebrtcCallWrapper> WebrtcCallWrapper::Create(
RefPtr<WebrtcEnvironmentWrapper> aEnvWrapper,
const dom::RTCStatsTimestampMaker& aTimestampMaker,
UniquePtr<media::ShutdownBlockingTicket> aShutdownTicket,
const RefPtr<SharedWebrtcState>& aSharedState) {
auto eventLog = MakeUnique<webrtc::RtcEventLogNull>();
auto taskQueueFactory = MakeUnique<SharedThreadPoolWebRtcTaskQueueFactory>();
auto videoBitrateAllocatorFactory =
WrapUnique(webrtc::CreateBuiltinVideoBitrateAllocatorFactory().release());
RefPtr<WebrtcCallWrapper> wrapper = new WebrtcCallWrapper(
aSharedState, std::move(videoBitrateAllocatorFactory),
std::move(eventLog), std::move(taskQueueFactory), aTimestampMaker,
std::move(aShutdownTicket));
webrtc::Environment env = CreateEnvironment(
wrapper->mEventLog.get(), wrapper->mClock.GetRealTimeClockRaw(),
wrapper->mTaskQueueFactory.get(), aSharedState->mTrials.get());
std::move(aEnvWrapper), aTimestampMaker, std::move(aShutdownTicket));
wrapper->mCallThread->Dispatch(
NS_NewRunnableFunction(__func__, [wrapper, aSharedState, env] {
webrtc::CallConfig config(env, nullptr);
NS_NewRunnableFunction(__func__, [wrapper, aSharedState] {
webrtc::CallConfig config(wrapper->mEnvWrapper->Environment(), nullptr);
config.audio_state =
webrtc::AudioState::Create(aSharedState->mAudioStateConfig);
wrapper->SetCall(WrapUnique(webrtc::Call::Create(std::move(config)).release()));
wrapper->SetCall(
WrapUnique(webrtc::Call::Create(std::move(config)).release()));
}));
return wrapper;
@@ -90,8 +83,7 @@ WebrtcCallWrapper::WebrtcCallWrapper(
RefPtr<SharedWebrtcState> aSharedState,
UniquePtr<webrtc::VideoBitrateAllocatorFactory>
aVideoBitrateAllocatorFactory,
UniquePtr<webrtc::RtcEventLog> aEventLog,
UniquePtr<webrtc::TaskQueueFactory> aTaskQueueFactory,
RefPtr<WebrtcEnvironmentWrapper> aEnvWrapper,
const dom::RTCStatsTimestampMaker& aTimestampMaker,
UniquePtr<media::ShutdownBlockingTicket> aShutdownTicket)
: mSharedState(std::move(aSharedState)),
@@ -100,7 +92,6 @@ WebrtcCallWrapper::WebrtcCallWrapper(
mCallThread(mSharedState->mCallWorkerThread),
mAudioDecoderFactory(mSharedState->mAudioDecoderFactory),
mVideoBitrateAllocatorFactory(std::move(aVideoBitrateAllocatorFactory)),
mEventLog(std::move(aEventLog)),
mTaskQueueFactory(std::move(aTaskQueueFactory)) {}
mEnvWrapper(std::move(aEnvWrapper)) {}
} // namespace mozilla

View File

@@ -23,6 +23,7 @@ namespace mozilla {
class AbstractThread;
class MediaSessionConduit;
class SharedWebrtcState;
class WebrtcEnvironmentWrapper;
namespace media {
class ShutdownBlockingTicket;
@@ -34,6 +35,7 @@ class WebrtcCallWrapper {
typedef webrtc::CallConfig Config;
static RefPtr<WebrtcCallWrapper> Create(
RefPtr<WebrtcEnvironmentWrapper> aEnvWrapper,
const dom::RTCStatsTimestampMaker& aTimestampMaker,
UniquePtr<media::ShutdownBlockingTicket> aShutdownTicket,
const RefPtr<SharedWebrtcState>& aSharedState);
@@ -83,8 +85,7 @@ class WebrtcCallWrapper {
WebrtcCallWrapper(RefPtr<SharedWebrtcState> aSharedState,
UniquePtr<webrtc::VideoBitrateAllocatorFactory>
aVideoBitrateAllocatorFactory,
UniquePtr<webrtc::RtcEventLog> aEventLog,
UniquePtr<webrtc::TaskQueueFactory> aTaskQueueFactory,
RefPtr<WebrtcEnvironmentWrapper> aEnvWrapper,
const dom::RTCStatsTimestampMaker& aTimestampMaker,
UniquePtr<media::ShutdownBlockingTicket> aShutdownTicket);
@@ -101,8 +102,7 @@ class WebrtcCallWrapper {
const RefPtr<webrtc::AudioDecoderFactory> mAudioDecoderFactory;
const UniquePtr<webrtc::VideoBitrateAllocatorFactory>
mVideoBitrateAllocatorFactory;
const UniquePtr<webrtc::RtcEventLog> mEventLog;
const UniquePtr<webrtc::TaskQueueFactory> mTaskQueueFactory;
const RefPtr<WebrtcEnvironmentWrapper> mEnvWrapper;
protected:
// Call worker thread only.

View File

@@ -10,6 +10,7 @@
#include "mozilla/Maybe.h"
#include "mozilla/media/MediaUtils.h"
#include "WebrtcCallWrapper.h"
#include "WebrtcEnvironmentWrapper.h"
#include "PeerConnectionCtx.h"
// libwebrtc
@@ -351,7 +352,8 @@ class MockCallWrapper : public mozilla::WebrtcCallWrapper {
aShutdownTicket)
: mozilla::WebrtcCallWrapper(
std::move(aSharedState), std::move(aVideoBitrateAllocatorFactory),
std::move(aEventLog), std::move(aTaskQueueFactory), aTimestampMaker,
mozilla::WebrtcEnvironmentWrapper::Create(aTimestampMaker),
aTimestampMaker,
std::move(aShutdownTicket)) {}
static RefPtr<MockCallWrapper> Create() {

View File

@@ -256,12 +256,13 @@ class LoopbackTransport : public MediaTransportHandler {
class TestAgent {
public:
explicit TestAgent(const RefPtr<SharedWebrtcState>& aSharedState)
explicit TestAgent(const RefPtr<WebrtcEnvironmentWrapper>& aEnvWrapper,
const RefPtr<SharedWebrtcState>& aSharedState)
: control_(aSharedState->mCallWorkerThread),
audio_config_(109, "opus", 48000, 2, false),
call_(WebrtcCallWrapper::Create(
mozilla::dom::RTCStatsTimestampMaker::Create(), nullptr,
aSharedState)),
aEnvWrapper, mozilla::dom::RTCStatsTimestampMaker::Create(),
nullptr, aSharedState)),
audio_conduit_(
AudioSessionConduit::Create(call_, test_utils->sts_target())),
transport_(new LoopbackTransport) {
@@ -356,8 +357,9 @@ class TestAgent {
class TestAgentSend : public TestAgent {
public:
explicit TestAgentSend(const RefPtr<SharedWebrtcState>& aSharedState)
: TestAgent(aSharedState) {
explicit TestAgentSend(const RefPtr<WebrtcEnvironmentWrapper>& aEnvWrapper,
const RefPtr<SharedWebrtcState>& aSharedState)
: TestAgent(aEnvWrapper, aSharedState) {
control_.Update([&](auto& aControl) {
aControl.mAudioSendCodec = Some(audio_config_);
});
@@ -385,8 +387,9 @@ class TestAgentSend : public TestAgent {
class TestAgentReceive : public TestAgent {
public:
explicit TestAgentReceive(const RefPtr<SharedWebrtcState>& aSharedState)
: TestAgent(aSharedState) {
explicit TestAgentReceive(const RefPtr<WebrtcEnvironmentWrapper>& aEnvWrapper,
const RefPtr<SharedWebrtcState>& aSharedState)
: TestAgent(aEnvWrapper, aSharedState) {
control_.Update([&](auto& aControl) {
std::vector<AudioCodecConfig> codecs;
codecs.push_back(audio_config_);
@@ -438,6 +441,7 @@ webrtc::AudioState::Config CreateAudioStateConfig(
const webrtc::Environment& aEnv) {
webrtc::AudioState::Config audio_state_config;
audio_state_config.audio_mixer = webrtc::AudioMixerImpl::Create();
webrtc::BuiltinAudioProcessingBuilder audio_processing_builder;
audio_state_config.audio_processing = audio_processing_builder.Build(aEnv);
audio_state_config.audio_device_module = new webrtc::FakeAudioDeviceModule();
@@ -458,8 +462,8 @@ class MediaPipelineTest : public ::testing::Test {
already_AddRefed(
webrtc::CreateBuiltinAudioDecoderFactory().release()),
WrapUnique(new webrtc::MozTrialsConfig()))),
p1_(shared_state_),
p2_(shared_state_) {}
p1_(env_wrapper_, shared_state_),
p2_(env_wrapper_, shared_state_) {}
~MediaPipelineTest() {
p1_.Shutdown();