bug 1406830 reimplement Shutdown() as virtual separately on each driver r?padenot
moving Stop() to AudioCallbackDriver only.
MozReview-Commit-ID: 9atG8R4wAsY
--- a/dom/media/GraphDriver.cpp
+++ b/dom/media/GraphDriver.cpp
@@ -88,29 +88,16 @@ GraphDriver::StateComputedTime() const
return mGraphImpl->mStateComputedTime;
}
void GraphDriver::EnsureNextIteration()
{
mGraphImpl->EnsureNextIteration();
}
-void GraphDriver::Shutdown()
-{
- if (AsAudioCallbackDriver()) {
- LOG(LogLevel::Debug,
- ("Releasing audio driver off main thread (GraphDriver::Shutdown)."));
- RefPtr<AsyncCubebTask> releaseEvent =
- new AsyncCubebTask(AsAudioCallbackDriver(), AsyncCubebOperation::SHUTDOWN);
- releaseEvent->Dispatch(NS_DISPATCH_SYNC);
- } else {
- Stop();
- }
-}
-
bool GraphDriver::Switching()
{
GraphImpl()->GetMonitor().AssertCurrentThreadOwns();
return mNextDriver || mPreviousDriver;
}
GraphDriver* GraphDriver::NextDriver()
{
@@ -257,17 +244,17 @@ ThreadedDriver::Revive()
}
void
ThreadedDriver::RemoveCallback()
{
}
void
-ThreadedDriver::Stop()
+ThreadedDriver::Shutdown()
{
NS_ASSERTION(NS_IsMainThread(), "Must be called on main thread");
// mGraph's thread is not running so it's OK to do whatever here
LOG(LogLevel::Debug, ("Stopping threads for MediaStreamGraph %p", this));
if (mThread) {
mThread->Shutdown();
mThread = nullptr;
@@ -858,16 +845,26 @@ AudioCallbackDriver::WaitForNextIteratio
void
AudioCallbackDriver::WakeUp()
{
mGraphImpl->GetMonitor().AssertCurrentThreadOwns();
mGraphImpl->GetMonitor().Notify();
}
+void
+AudioCallbackDriver::Shutdown()
+{
+ LOG(LogLevel::Debug,
+ ("Releasing audio driver off main thread (GraphDriver::Shutdown)."));
+ RefPtr<AsyncCubebTask> releaseEvent =
+ new AsyncCubebTask(this, AsyncCubebOperation::SHUTDOWN);
+ releaseEvent->Dispatch(NS_DISPATCH_SYNC);
+}
+
#if defined(XP_WIN)
void
AudioCallbackDriver::ResetDefaultDevice()
{
if (cubeb_stream_reset_default_device(mAudioStream) != CUBEB_OK) {
NS_WARNING("Could not reset cubeb stream to default output device.");
}
}
--- a/dom/media/GraphDriver.h
+++ b/dom/media/GraphDriver.h
@@ -117,24 +117,22 @@ public:
/* For real-time graphs, this waits until it's time to process more data. For
* offline graphs, this is a no-op. */
virtual void WaitForNextIteration() = 0;
/* Wakes up the graph if it is waiting. */
virtual void WakeUp() = 0;
virtual void Destroy() {}
/* Start the graph, init the driver, start the thread. */
virtual void Start() = 0;
- /* Stop the graph, shutting down the thread. */
- virtual void Stop() = 0;
/* Revive this driver, as more messages just arrived. */
virtual void Revive() = 0;
/* Remove Mixer callbacks when switching */
virtual void RemoveCallback() = 0;
/* Shutdown GraphDriver (synchronously) */
- void Shutdown();
+ virtual void Shutdown() = 0;
/* Rate at which the GraphDriver runs, in ms. This can either be user
* controlled (because we are using a {System,Offline}ClockDriver, and decide
* how often we want to wakeup/how much we want to process per iteration), or
* it can be indirectly set by the latency of the audio backend, and the
* number of buffers of this audio backend: say we have four buffers, and 40ms
* latency, we will get a callback approximately every 10ms. */
virtual uint32_t IterationDuration() = 0;
@@ -267,19 +265,19 @@ class MediaStreamGraphInitThreadRunnable
* This class is a driver that manages its own thread.
*/
class ThreadedDriver : public GraphDriver
{
public:
explicit ThreadedDriver(MediaStreamGraphImpl* aGraphImpl);
virtual ~ThreadedDriver();
void Start() override;
- void Stop() override;
void Revive() override;
void RemoveCallback() override;
+ void Shutdown() override;
/**
* Runs main control loop on the graph thread. Normally a single invocation
* of this runs for the entire lifetime of the graph thread.
*/
void RunThread();
friend class MediaStreamGraphInitThreadRunnable;
uint32_t IterationDuration() override {
return MEDIA_GRAPH_TARGET_PERIOD_MS;
@@ -388,21 +386,21 @@ class AudioCallbackDriver : public Graph
#endif
{
public:
explicit AudioCallbackDriver(MediaStreamGraphImpl* aGraphImpl);
virtual ~AudioCallbackDriver();
void Destroy() override;
void Start() override;
- void Stop() override;
void Revive() override;
void RemoveCallback() override;
void WaitForNextIteration() override;
void WakeUp() override;
+ void Shutdown() override;
#if defined(XP_WIN)
void ResetDefaultDevice() override;
#endif
/* Static wrapper function cubeb calls back. */
static long DataCallback_s(cubeb_stream * aStream,
void * aUser,
const void * aInputBuffer,
@@ -483,16 +481,18 @@ private:
void PanOutputIfNeeded(bool aMicrophoneActive);
/**
* This is called when the output device used by the cubeb stream changes. */
void DeviceChangedCallback();
/* Start the cubeb stream */
bool StartStream();
friend class AsyncCubebTask;
bool Init();
+ void Stop();
+
/* MediaStreamGraphs are always down/up mixed to output channels. */
uint32_t mOutputChannels;
/* The size of this buffer comes from the fact that some audio backends can
* call back with a number of frames lower than one block (128 frames), so we
* need to keep at most two block in the SpillBuffer, because we always round
* up to block boundaries during an iteration.
* This is only ever accessed on the audio callback thread. */
SpillBuffer<AudioDataValue, WEBAUDIO_BLOCK_SIZE * 2> mScratchBuffer;