tor-browser

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

commit 2acbcaf1528001fbce3e98685f5f2f4f47b55f6a
parent 32dd65e5b72679fead0b90882b39bf28a242f60e
Author: Narcis Beleuzu <nbeleuzu@mozilla.com>
Date:   Fri, 24 Oct 2025 01:43:15 +0300

Revert "Bug 1985195 Advance OfflineClockDriver time only when rendering r=pehrsons" for GTest failures on TestOfflineClockDriver.cpp

This reverts commit 521c54a4ddafb5e33b7f6ffb39e3a87def963d15.

Diffstat:
Mdom/media/GraphDriver.cpp | 5++---
Mdom/media/GraphDriver.h | 10----------
Mdom/media/MediaTrackGraph.cpp | 37+++++++++++++++++++++++--------------
Mdom/media/gtest/MockGraphInterface.h | 2--
Mdom/media/gtest/TestMediaDataEncoder.cpp | 1-
Ddom/media/gtest/TestOfflineClockDriver.cpp | 55-------------------------------------------------------
Mdom/media/gtest/moz.build | 1-
7 files changed, 25 insertions(+), 86 deletions(-)

diff --git a/dom/media/GraphDriver.cpp b/dom/media/GraphDriver.cpp @@ -275,9 +275,8 @@ void OfflineClockDriver::RunThread() { } MediaTime OfflineClockDriver::GetIntervalForIteration() { - return MediaTrackGraphImpl::RoundUpToEndOfAudioBlock(std::clamp<MediaTime>( - mEndTime - mStateComputedTime, 0, - MillisecondsToMediaTime(MEDIA_GRAPH_TARGET_PERIOD_MS))); + return MediaTrackGraphImpl::RoundUpToEndOfAudioBlock( + MillisecondsToMediaTime(MEDIA_GRAPH_TARGET_PERIOD_MS)); } /* Helper to proxy the GraphInterface methods used by a running diff --git a/dom/media/GraphDriver.h b/dom/media/GraphDriver.h @@ -520,19 +520,9 @@ class OfflineClockDriver final : public ThreadedDriver { void RunThread() override; - void SetTickCountToRender(uint32_t aTicksToProcess) { - MOZ_ASSERT(InIteration()); - MOZ_ASSERT(mEndTime == 0); - mEndTime = aTicksToProcess; - } - protected: TimeDuration NextIterationWaitDuration() override { return TimeDuration(); } MediaTime GetIntervalForIteration() override; - - private: - // The graph will advance up to this time. Graph thread. - GraphTime mEndTime = 0; }; enum class AudioInputType { Unknown, Voice }; diff --git a/dom/media/MediaTrackGraph.cpp b/dom/media/MediaTrackGraph.cpp @@ -1678,13 +1678,14 @@ auto MediaTrackGraphImpl::OneIterationImpl( NS_ProcessPendingEvents(nullptr); } - UpdateGraph(aStateTime); + GraphTime stateTime = std::min(aStateTime, GraphTime(mEndTime)); + UpdateGraph(stateTime); - mStateComputedTime = aStateTime; + mStateComputedTime = stateTime; GraphTime oldProcessedTime = mProcessedTime; Process(aMixerReceiver); - MOZ_ASSERT(mProcessedTime == aStateTime); + MOZ_ASSERT(mProcessedTime == stateTime); UpdateCurrentTimeForTracks(oldProcessedTime); @@ -4123,17 +4124,25 @@ void MediaTrackGraph::StartNonRealtimeProcessing(uint32_t aTicksToProcess) { MediaTrackGraphImpl* graph = static_cast<MediaTrackGraphImpl*>(this); NS_ASSERTION(!graph->mRealtime, "non-realtime only"); - graph->QueueControlMessageWithNoShutdown([graph = RefPtr{graph}, - aTicksToProcess]() { - TRACE("MTG::StartNonRealtimeProcessing ControlMessage"); - MOZ_ASSERT(graph->mStateComputedTime == 0); - MOZ_ASSERT(graph->mEndTime == 0, - "StartNonRealtimeProcessing should be called only once"); - graph->mEndTime = aTicksToProcess; - OfflineClockDriver* driver = graph->CurrentDriver()->AsOfflineClockDriver(); - MOZ_ASSERT(driver); - driver->SetTickCountToRender(aTicksToProcess); - }); + class Message : public ControlMessage { + public: + explicit Message(MediaTrackGraphImpl* aGraph, uint32_t aTicksToProcess) + : ControlMessage(nullptr), + mGraph(aGraph), + mTicksToProcess(aTicksToProcess) {} + void Run() override { + TRACE("MTG::StartNonRealtimeProcessing ControlMessage"); + MOZ_ASSERT(mGraph->mEndTime == 0, + "StartNonRealtimeProcessing should be called only once"); + mGraph->mEndTime = mGraph->RoundUpToEndOfAudioBlock( + mGraph->mStateComputedTime + mTicksToProcess); + } + // The graph owns this message. + MediaTrackGraphImpl* MOZ_NON_OWNING_REF mGraph; + uint32_t mTicksToProcess; + }; + + graph->AppendMessage(MakeUnique<Message>(graph, aTicksToProcess)); } void MediaTrackGraphImpl::InterruptJS() { diff --git a/dom/media/gtest/MockGraphInterface.h b/dom/media/gtest/MockGraphInterface.h @@ -27,10 +27,8 @@ class MockGraphInterface : public GraphInterface { #endif /* OneIteration cannot be mocked because IterationResult is non-memmovable and * cannot be passed as a parameter, which GMock does internally. */ - MOCK_METHOD(void, MockIteration, (GraphTime aStateComputedTime), ()); IterationResult OneIteration(GraphTime aStateComputedTime, MixerCallbackReceiver* aMixerReceiver) { - MockIteration(aStateComputedTime); GraphDriver* driver = mCurrentDriver; if (aMixerReceiver) { mMixer.StartMixing(); diff --git a/dom/media/gtest/TestMediaDataEncoder.cpp b/dom/media/gtest/TestMediaDataEncoder.cpp @@ -1160,6 +1160,5 @@ TEST_F(MediaDataEncoderTest, VP9EncodeWithScalabilityModeL1T3) { # endif #endif -#undef BLOCK_SIZE #undef GET_OR_RETURN_ON_ERROR #undef RUN_IF_SUPPORTED diff --git a/dom/media/gtest/TestOfflineClockDriver.cpp b/dom/media/gtest/TestOfflineClockDriver.cpp @@ -1,55 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this file, - * You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "MockGraphInterface.h" -#include "gtest/gtest.h" -#include "mozilla/gtest/WaitFor.h" - -using namespace mozilla; -using testing::InSequence; -using testing::Return; - -TEST(TestOfflineClockDriver, TimeAdvance) -MOZ_CAN_RUN_SCRIPT_BOUNDARY { - TrackRate rate = - CubebUtils::PreferredSampleRate(/* aShouldResistFingerprinting */ false); - RefPtr graph = new MockGraphInterface(rate); - RefPtr driver = new OfflineClockDriver(graph, rate); - MozPromiseHolder<GenericPromise> doneHolder; - RefPtr<GenericPromise> done = doneHolder.Ensure(__func__); - { - GraphTime length = WEBAUDIO_BLOCK_SIZE / 4; // < WEBAUDIO_BLOCK_SIZE - auto EnsureNextIteration = [&](GraphTime aTime) { - driver->EnsureNextIteration(); - }; - InSequence s; - EXPECT_CALL(*graph, MockIteration(0)) - // Time should not advance on the first iteration to process control - // messages - .WillOnce(EnsureNextIteration) - // ... nor on subsequent. - .WillOnce([&](GraphTime aTime) { - driver->SetTickCountToRender(length); - driver->EnsureNextIteration(); - }); - EXPECT_CALL(*graph, MockIteration(WEBAUDIO_BLOCK_SIZE)) - // Rendering iteration - .WillOnce(EnsureNextIteration) - // Time should not advance after rendering. - .WillOnce([&](GraphTime aTime) { - // Tell the driver to exit its event loop. - graph->StopIterating(); - doneHolder.Resolve(true, __func__); - }); - } - - graph->SetCurrentDriver(driver); - driver->EnsureNextIteration(); - driver->Start(); - WaitForResolve(done); - // Clean up. - driver->Shutdown(); -} diff --git a/dom/media/gtest/moz.build b/dom/media/gtest/moz.build @@ -58,7 +58,6 @@ UNIFIED_SOURCES += [ "TestMP3Demuxer.cpp", "TestMP4Demuxer.cpp", "TestMuxer.cpp", - "TestOfflineClockDriver.cpp", "TestOggWriter.cpp", "TestOpusParser.cpp", "TestRust.cpp",