tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 4898c01d1df76f5e15e4f18071ae2c9dac873c77
parent 9adbbca9d8dfc50dee88b4a38431780dbd16595d
Author: agoloman <agoloman@mozilla.com>
Date:   Wed, 19 Nov 2025 08:51:06 +0200

Revert "Bug 2000076 Take graph control messages from main thread before processing control messages r=pehrsons" for causing mochitest failures @test_temporaryfile_stream.html.

This reverts commit 75573040ed7579f36fa22ac0432ff8f7e8a5041a.

Diffstat:
Mdom/media/MediaTrackGraph.cpp | 6++++--
Mdom/media/MediaTrackGraphImpl.h | 7+++++--
Mdom/media/gtest/TestAudioTrackGraph.cpp | 49+++++++++++++++++++++++++++++++++++++++----------
3 files changed, 48 insertions(+), 14 deletions(-)

diff --git a/dom/media/MediaTrackGraph.cpp b/dom/media/MediaTrackGraph.cpp @@ -1613,6 +1613,7 @@ bool MediaTrackGraphImpl::UpdateMainThreadState() { mForceShutDownReceived || (IsEmpty() && mBackMessageQueue.IsEmpty()); PrepareUpdatesToMainThreadState(finalUpdate); if (!finalUpdate) { + SwapMessageQueues(); return true; } // The JSContext will not be used again. @@ -1667,7 +1668,6 @@ auto MediaTrackGraphImpl::OneIterationImpl( WebCore::DenormalDisabler disabler; // Process graph message from the main thread for this iteration. - SwapMessageQueues(); RunMessagesInQueue(); // Process MessagePort events. @@ -2075,8 +2075,10 @@ void MediaTrackGraphImpl::RunInStableState(bool aSourceIsMTG) { if (LifecycleStateRef() == LIFECYCLE_THREAD_NOT_STARTED) { // Start the driver now. We couldn't start it earlier because the graph // might exit immediately on finding it has no tracks. The first message - // for a new graph must create a track. + // for a new graph must create a track. Ensure that his message runs on + // the first iteration. MOZ_ASSERT(MessagesQueued()); + SwapMessageQueues(); LOG(LogLevel::Debug, ("%p: Starting a graph with a %s", this, diff --git a/dom/media/MediaTrackGraphImpl.h b/dom/media/MediaTrackGraphImpl.h @@ -355,11 +355,14 @@ class MediaTrackGraphImpl : public MediaTrackGraph, */ void UpdateGraph(GraphTime aEndBlockingDecisions); - void SwapMessageQueues() { - MonitorAutoLock lock(mMonitor); + void SwapMessageQueues() MOZ_REQUIRES(mMonitor) { MOZ_ASSERT(OnGraphThreadOrNotRunning()); + mMonitor.AssertCurrentThreadOwns(); MOZ_ASSERT(mFrontMessageQueue.IsEmpty()); mFrontMessageQueue.SwapElements(mBackMessageQueue); + if (!mFrontMessageQueue.IsEmpty()) { + EnsureNextIteration(); + } } /** * Do all the processing and play the audio and video, from diff --git a/dom/media/gtest/TestAudioTrackGraph.cpp b/dom/media/gtest/TestAudioTrackGraph.cpp @@ -1376,7 +1376,10 @@ TEST(TestAudioTrackGraph, ReConnectDeviceInput) // Dispatch the disconnect message. ProcessEventQueue(); - // Run the disconnect message and switch driver. + // Run the disconnect message. + EXPECT_EQ(stream->ManualDataCallback(0), + MockCubebStream::KeepProcessing::Yes); + // Switch driver. auto initPromise = TakeN(cubeb->StreamInitEvent(), 1); EXPECT_EQ(stream->ManualDataCallback(0), MockCubebStream::KeepProcessing::No); std::tie(stream) = WaitFor(initPromise).unwrap()[0]; @@ -1410,7 +1413,10 @@ TEST(TestAudioTrackGraph, ReConnectDeviceInput) }); // Dispatch the connect message. ProcessEventQueue(); - // Run the connect message and switch driver. + // Run the connect message. + EXPECT_EQ(stream->ManualDataCallback(0), + MockCubebStream::KeepProcessing::Yes); + // Switch driver. initPromise = TakeN(cubeb->StreamInitEvent(), 1); EXPECT_EQ(stream->ManualDataCallback(0), MockCubebStream::KeepProcessing::No); std::tie(stream) = WaitFor(initPromise).unwrap()[0]; @@ -1450,7 +1456,10 @@ TEST(TestAudioTrackGraph, ReConnectDeviceInput) // Dispatch the clean-up messages. ProcessEventQueue(); - // Run the clean-up messages and shut down driver. + // Run the clean-up messages. + EXPECT_EQ(stream->ManualDataCallback(0), + MockCubebStream::KeepProcessing::Yes); + // Shut down driver. EXPECT_EQ(stream->ManualDataCallback(0), MockCubebStream::KeepProcessing::No); uint32_t inputFrequency = stream->InputFrequency(); @@ -2508,6 +2517,11 @@ void TestCrossGraphPort(uint32_t aInputRate, uint32_t aOutputRate, ProcessEventQueue(); + EXPECT_EQ(inputStream->ManualDataCallback(0), + MockCubebStream::KeepProcessing::Yes); + EXPECT_EQ(partnerStream->ManualDataCallback(0), + MockCubebStream::KeepProcessing::Yes); + EXPECT_EQ(inputStream->ManualDataCallback(128), MockCubebStream::KeepProcessing::No); EXPECT_EQ(partnerStream->ManualDataCallback(128), @@ -2965,7 +2979,10 @@ TEST(TestAudioTrackGraph, PlatformProcessing) [&] { graph->ReevaluateInputDevice(device); }); }); ProcessEventQueue(); - // Process the reevaluation message and perform the switch. + // Process the reevaluation message. + EXPECT_EQ(stream->ManualDataCallback(0), + MockCubebStream::KeepProcessing::Yes); + // Perform the switch. auto initPromise = TakeN(cubeb->StreamInitEvent(), 1); EXPECT_EQ(stream->ManualDataCallback(0), MockCubebStream::KeepProcessing::No); std::tie(stream) = WaitFor(initPromise).unwrap()[0]; @@ -3015,7 +3032,10 @@ TEST(TestAudioTrackGraph, PlatformProcessing) track->Destroy(); }); ProcessEventQueue(); - // Process the destroy message and shut down. + // Process the destroy message. + EXPECT_EQ(stream->ManualDataCallback(0), + MockCubebStream::KeepProcessing::Yes); + // Shut down. EXPECT_EQ(stream->ManualDataCallback(0), MockCubebStream::KeepProcessing::No); RefPtr<SmartMockCubebStream> destroyedStream = WaitFor(cubeb->StreamDestroyEvent()); @@ -3226,8 +3246,11 @@ TEST(TestAudioTrackGraph, PlatformProcessingNonNativeToNativeSwitch) }); ProcessEventQueue(); initPromise = TakeN(cubeb->StreamInitEvent(), 1); - // Process the disconnect message, perform the switch, - // and check that the second device is now used with the new graph driver. + // Process the disconnect message, and check that the second device is now + // used with the new graph driver. + EXPECT_EQ(nativeStream->ManualDataCallback(0), + MockCubebStream::KeepProcessing::Yes); + // Perform the switch. EXPECT_EQ(nativeStream->ManualDataCallback(0), MockCubebStream::KeepProcessing::No); std::tie(nativeStream) = WaitFor(initPromise).unwrap()[0]; @@ -3271,7 +3294,10 @@ TEST(TestAudioTrackGraph, PlatformProcessingNonNativeToNativeSwitch) auto destroyPromise = TakeN(cubeb->StreamDestroyEvent(), 1); DispatchFunction([&] { ProcessEventQueue(); - // Process the destroy message and shut down native. + // Process the destroy message. + EXPECT_EQ(nativeStream->ManualDataCallback(0), + MockCubebStream::KeepProcessing::Yes); + // Shut down native. EXPECT_EQ(nativeStream->ManualDataCallback(0), MockCubebStream::KeepProcessing::No); }); @@ -3444,8 +3470,11 @@ TEST(TestAudioTrackGraph, DefaultOutputDeviceIDTracking) }); auto initPromise = TakeN(cubeb->StreamInitEvent(), 1); ProcessEventQueue(); - // Process the disconnect message, perform the switch, - // and check that the second device is now used with the new graph driver. + // Process the disconnect message, and check that the second device is now + // used with the new graph driver. + EXPECT_EQ(stream->ManualDataCallback(0), + MockCubebStream::KeepProcessing::Yes); + // Perform the switch. EXPECT_EQ(stream->ManualDataCallback(0), MockCubebStream::KeepProcessing::No); std::tie(stream) = WaitFor(initPromise).unwrap()[0]; EXPECT_TRUE(stream->mHasInput);