From a3533d7c93d83c82bf9f94ae47f9da7d9bfe8b91 Mon Sep 17 00:00:00 2001 From: Paul Adenot Date: Tue, 26 Aug 2014 17:02:28 +0200 Subject: [PATCH] Bug 848954 - Part 20 - Remove the now useless DriverHolder class. r=roc --- content/media/GraphDriver.cpp | 18 ------------- content/media/GraphDriver.h | 38 ---------------------------- content/media/MediaStreamGraph.cpp | 9 +++---- content/media/MediaStreamGraphImpl.h | 21 ++++++++++++++- 4 files changed, 24 insertions(+), 62 deletions(-) diff --git a/content/media/GraphDriver.cpp b/content/media/GraphDriver.cpp index 00df8816e765..2e0d4c29fd3e 100644 --- a/content/media/GraphDriver.cpp +++ b/content/media/GraphDriver.cpp @@ -41,24 +41,6 @@ GraphDriver::GraphDriver(MediaStreamGraphImpl* aGraphImpl) mNextDriver(nullptr) { } -DriverHolder::DriverHolder(MediaStreamGraphImpl* aGraphImpl) - : mGraphImpl(aGraphImpl) -{ } - -GraphTime -DriverHolder::GetCurrentTime() -{ - MOZ_ASSERT(mDriver, "Can't get current time without a clock."); - return mDriver->GetCurrentTime(); -} - -void -DriverHolder::Switch(GraphDriver* aDriver) -{ - MOZ_ASSERT(!mDriver, "This is only for initial switch."); - mDriver = aDriver; -} - void GraphDriver::SetGraphTime(GraphDriver* aPreviousDriver, GraphTime aLastSwitchNextIterationStart, GraphTime aLastSwitchNextIterationEnd, diff --git a/content/media/GraphDriver.h b/content/media/GraphDriver.h index 2731c98d0a31..e96390313f59 100644 --- a/content/media/GraphDriver.h +++ b/content/media/GraphDriver.h @@ -228,44 +228,6 @@ protected: { } }; -/** - * A driver holder allows a MediaStreamGraph to seamlessly switch between - * different Drivers, remembering the current time of the graph at time of - * switch. - */ -class DriverHolder -{ -public: - DriverHolder(MediaStreamGraphImpl* aGraphImpl); - GraphTime GetCurrentTime(); - - // Immediately switch to another driver. - void Switch(GraphDriver* aDriver); - // Create the new driver, but switch to a new one when the new driver is - // ready. System drivers don't have much problems here, but audio drivers can - // take a little while to start to fire callbacks. - void SwitchAtNextIteration(GraphDriver* aDriver); - - GraphDriver* GetDriver() { - MOZ_ASSERT(mDriver); - return mDriver.get(); - } - - void SetCurrentDriver(GraphDriver* aDriver) { - mDriver = aDriver; - } - -protected: - // The current driver - nsRefPtr mDriver; - // The lifetime of this pointer is equal to the lifetime of the graph, so it - // will never be null. - MediaStreamGraphImpl* mGraphImpl; - // XXX - GraphTime mNextIterationStart; - GraphTime mNextStateComputedTime; -}; - class MediaStreamGraphInitThreadRunnable; /** diff --git a/content/media/MediaStreamGraph.cpp b/content/media/MediaStreamGraph.cpp index eb48fb03d958..b8b6cb52b66d 100644 --- a/content/media/MediaStreamGraph.cpp +++ b/content/media/MediaStreamGraph.cpp @@ -2640,8 +2640,7 @@ MediaStreamGraphImpl::MediaStreamGraphImpl(bool aRealtime, TrackRate aSampleRate, DOMMediaStream::TrackTypeHints aHint= DOMMediaStream::HINT_CONTENTS_UNKNOWN, dom::AudioChannel aChannel) - : mDriverHolder(MOZ_THIS_IN_INITIALIZER_LIST()) - , mProcessingGraphUpdateIndex(0) + : mProcessingGraphUpdateIndex(0) , mPortCount(0) , mMonitor("MediaStreamGraphImpl") , mLifecycleState(LIFECYCLE_THREAD_NOT_STARTED) @@ -2673,13 +2672,13 @@ MediaStreamGraphImpl::MediaStreamGraphImpl(bool aRealtime, if (mRealtime) { if (aHint & DOMMediaStream::HINT_CONTENTS_AUDIO) { AudioCallbackDriver* driver = new AudioCallbackDriver(this, aChannel); - mDriverHolder.Switch(driver); + mDriver = driver; mMixer.AddCallback(driver); } else { - mDriverHolder.Switch(new SystemClockDriver(this)); + mDriver = new SystemClockDriver(this); } } else { - mDriverHolder.Switch(new OfflineClockDriver(this, MEDIA_GRAPH_TARGET_PERIOD_MS)); + mDriver = new OfflineClockDriver(this, MEDIA_GRAPH_TARGET_PERIOD_MS); } mLastMainThreadUpdate = TimeStamp::Now(); diff --git a/content/media/MediaStreamGraphImpl.h b/content/media/MediaStreamGraphImpl.h index a6297f8c09a1..9749f15be144 100644 --- a/content/media/MediaStreamGraphImpl.h +++ b/content/media/MediaStreamGraphImpl.h @@ -398,6 +398,17 @@ public: return RateConvertTicksRoundDown(aRate, GraphRate(), aTime); } + /** + * Signal to the graph that the thread has paused indefinitly, + * or resumed. + */ + void PausedIndefinitly(); + void ResumedFromPaused(); + + GraphDriver* CurrentDriver() { + return mDriver; + } + /** * Effectively set the new driver, while we are switching. * It is only safe to call this at the very end of an iteration, when there @@ -405,7 +416,7 @@ public: * should return and pass the control to the new driver shortly after. */ void SetCurrentDriver(GraphDriver* aDriver) { - mDriverHolder.SetCurrentDriver(aDriver); + mDriver = aDriver; } Monitor& GetMonitor() { @@ -413,6 +424,14 @@ public: } // Data members + // + /** + * Graphs own owning references to their driver, until shutdown. When a driver + * switch occur, previous driver is either deleted, or it's ownership is + * passed to a event that will take care of the asynchronous cleanup, as + * audio stream can take some time to shut down. + */ + nsRefPtr mDriver; // The following state is managed on the graph thread only, unless // mLifecycleState > LIFECYCLE_RUNNING in which case the graph thread