From e6ea00c8f4fb435323d45d2a1642ccda0da1d91c Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Thu, 5 Nov 2020 16:42:41 +0000 Subject: [PATCH] Bug 1651745 - Use the right thread for AudioInputProcessing::SetPassThrough and constify some ControlMessages. r=padenot Differential Revision: https://phabricator.services.mozilla.com/D95937 --- dom/media/gtest/TestAudioTrackGraph.cpp | 37 +++++++++++++++------ dom/media/webrtc/MediaEngineWebRTCAudio.cpp | 6 ++-- dom/media/webrtc/MediaEngineWebRTCAudio.h | 2 +- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/dom/media/gtest/TestAudioTrackGraph.cpp b/dom/media/gtest/TestAudioTrackGraph.cpp index 84a75ba8de36..423c83bb33e1 100644 --- a/dom/media/gtest/TestAudioTrackGraph.cpp +++ b/dom/media/gtest/TestAudioTrackGraph.cpp @@ -104,11 +104,10 @@ void WaitUntil(MediaEventSource& aEvent, const CallbackFunction& aF) { /* * Common ControlMessages */ -class StartInputProcessing : public ControlMessage { - RefPtr mInputTrack; - RefPtr mInputProcessing; +struct StartInputProcessing : public ControlMessage { + const RefPtr mInputTrack; + const RefPtr mInputProcessing; - public: StartInputProcessing(AudioInputTrack* aTrack, AudioInputProcessing* aInputProcessing) : ControlMessage(aTrack), @@ -117,14 +116,29 @@ class StartInputProcessing : public ControlMessage { void Run() override { mInputProcessing->Start(); } }; -class StopInputProcessing : public ControlMessage { - RefPtr mInputProcessing; +struct StopInputProcessing : public ControlMessage { + const RefPtr mInputProcessing; - public: explicit StopInputProcessing(AudioInputProcessing* aInputProcessing) : ControlMessage(nullptr), mInputProcessing(aInputProcessing) {} void Run() override { mInputProcessing->Stop(); } }; + +struct SetPassThrough : public ControlMessage { + const RefPtr mInputProcessing; + const bool mPassThrough; + + SetPassThrough(MediaTrack* aTrack, AudioInputProcessing* aInputProcessing, + bool aPassThrough) + : ControlMessage(aTrack), + mInputProcessing(aInputProcessing), + mPassThrough(aPassThrough) {} + void Run() override { + EXPECT_EQ(mInputProcessing->PassThrough(mTrack->GraphImpl()), + !mPassThrough); + mInputProcessing->SetPassThrough(mTrack->GraphImpl(), mPassThrough); + } +}; #endif // MOZ_WEBRTC class GoFaster : public ControlMessage { @@ -276,7 +290,8 @@ TEST(TestAudioTrackGraph, ErrorCallback) Unused << WaitFor(Invoke([&] { inputTrack = AudioInputTrack::Create(graph); listener = new AudioInputProcessing(2, PRINCIPAL_HANDLE_NONE); - listener->SetPassThrough(true); + inputTrack->GraphImpl()->AppendMessage( + MakeUnique(inputTrack, listener, true)); inputTrack->SetInputProcessing(listener); inputTrack->GraphImpl()->AppendMessage( MakeUnique(inputTrack, listener)); @@ -342,7 +357,8 @@ TEST(TestAudioTrackGraph, AudioInputTrack) port = outputTrack->AllocateInputPort(inputTrack); /* Primary graph: Open Audio Input through SourceMediaTrack */ listener = new AudioInputProcessing(2, PRINCIPAL_HANDLE_NONE); - listener->SetPassThrough(true); + inputTrack->GraphImpl()->AppendMessage( + MakeUnique(inputTrack, listener, true)); inputTrack->SetInputProcessing(listener); inputTrack->GraphImpl()->AppendMessage( MakeUnique(inputTrack, listener)); @@ -429,7 +445,8 @@ void TestCrossGraphPort(uint32_t aInputRate, uint32_t aOutputRate, DispatchFunction([&] { inputTrack = AudioInputTrack::Create(primary); listener = new AudioInputProcessing(2, PRINCIPAL_HANDLE_NONE); - listener->SetPassThrough(true); + inputTrack->GraphImpl()->AppendMessage( + MakeUnique(inputTrack, listener, true)); inputTrack->SetInputProcessing(listener); inputTrack->GraphImpl()->AppendMessage( MakeUnique(inputTrack, listener)); diff --git a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp index b46a15bf87d4..244159591a1d 100644 --- a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp +++ b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp @@ -386,7 +386,7 @@ void MediaEngineWebRTCMicrophoneSource::ApplySettings( mRequestedInputChannelCount(aRequestedInputChannelCount) {} void Run() override { - mInputProcessing->SetPassThrough(mPassThrough); + mInputProcessing->SetPassThrough(mTrack->GraphImpl(), mPassThrough); mInputProcessing->SetRequestedInputChannelCount( mTrack->GraphImpl(), mRequestedInputChannelCount); } @@ -649,7 +649,9 @@ bool AudioInputProcessing::PassThrough(MediaTrackGraphImpl* aGraph) const { return mSkipProcessing; } -void AudioInputProcessing::SetPassThrough(bool aPassThrough) { +void AudioInputProcessing::SetPassThrough(MediaTrackGraphImpl* aGraph, + bool aPassThrough) { + MOZ_ASSERT(aGraph->OnGraphThread()); if (!mSkipProcessing && aPassThrough && mPacketizerInput) { MOZ_ASSERT(mPacketizerInput->PacketsAvailable() == 0); mSegment.AppendNullData(mPacketizerInput->FramesAvailable()); diff --git a/dom/media/webrtc/MediaEngineWebRTCAudio.h b/dom/media/webrtc/MediaEngineWebRTCAudio.h index 9cf95ad0891b..ae9e123e91e7 100644 --- a/dom/media/webrtc/MediaEngineWebRTCAudio.h +++ b/dom/media/webrtc/MediaEngineWebRTCAudio.h @@ -176,7 +176,7 @@ class AudioInputProcessing : public AudioDataListener { const AudioDataValue* aBuffer, size_t aFrames, TrackRate aRate, uint32_t aChannels); - void SetPassThrough(bool aPassThrough); + void SetPassThrough(MediaTrackGraphImpl* aGraph, bool aPassThrough); uint32_t GetRequestedInputChannelCount(); void SetRequestedInputChannelCount(MediaTrackGraphImpl* aGraph, uint32_t aRequestedInputChannelCount);