From 5fc615519bef5757283e70de5d536c7e40b9d1d6 Mon Sep 17 00:00:00 2001 From: Alex Chronopoulos Date: Fri, 19 Apr 2019 08:34:22 +0000 Subject: [PATCH] Bug 1541290 - Restart driver properly on revive method. r=padenot Revive method of AudioCallbackDriver was wrong because it was re-initializing an already initialized driver. That was hitting an assert. Instead of that it should stop the drained stream and start it again. Also, mStarted member should be reset properly on the stop method. Differential Revision: https://phabricator.services.mozilla.com/D26678 --HG-- extra : moz-landing-system : lando --- dom/media/GraphDriver.cpp | 35 ++++++++++++++++++++++++++++++----- dom/media/GraphDriver.h | 2 +- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/dom/media/GraphDriver.cpp b/dom/media/GraphDriver.cpp index c13049d66163..ff392bec5a8c 100644 --- a/dom/media/GraphDriver.cpp +++ b/dom/media/GraphDriver.cpp @@ -419,8 +419,9 @@ AsyncCubebTask::AsyncCubebTask(AudioCallbackDriver* aDriver, mDriver(aDriver), mOperation(aOperation), mShutdownGrip(aDriver->GraphImpl()) { - NS_WARNING_ASSERTION(mDriver->mAudioStream || aOperation == INIT, - "No audio stream!"); + NS_WARNING_ASSERTION( + mDriver->mAudioStream || aOperation == AsyncCubebOperation::INIT, + "No audio stream!"); } AsyncCubebTask::~AsyncCubebTask() {} @@ -441,6 +442,22 @@ AsyncCubebTask::Run() { mDriver->CompleteAudioContextOperations(mOperation); break; } + case AsyncCubebOperation::START: { + LOG(LogLevel::Debug, ("%p: AsyncCubebOperation::START driver=%p", + mDriver->GraphImpl(), mDriver.get())); + if (!mDriver->StartStream()) { + LOG(LogLevel::Warning, + ("%p: AsyncCubebOperation couldn't start the driver=%p.", + mDriver->GraphImpl(), mDriver.get())); + } + break; + } + case AsyncCubebOperation::STOP: { + LOG(LogLevel::Debug, ("%p: AsyncCubebOperation::STOP driver=%p", + mDriver->GraphImpl(), mDriver.get())); + mDriver->Stop(); + break; + } case AsyncCubebOperation::SHUTDOWN: { LOG(LogLevel::Debug, ("%p: AsyncCubebOperation::SHUTDOWN driver=%p", mDriver->GraphImpl(), mDriver.get())); @@ -713,6 +730,7 @@ void AudioCallbackDriver::Stop() { if (cubeb_stream_stop(mAudioStream) != CUBEB_OK) { NS_WARNING("Could not stop cubeb stream for MSG."); } + mStarted = false; } void AudioCallbackDriver::Revive() { @@ -728,9 +746,16 @@ void AudioCallbackDriver::Revive() { LOG(LogLevel::Debug, ("Starting audio threads for MediaStreamGraph %p from a new thread.", mGraphImpl.get())); - RefPtr initEvent = - new AsyncCubebTask(this, AsyncCubebOperation::INIT); - initEvent->Dispatch(); + if (IsStarted()) { + RefPtr stopEvent = + new AsyncCubebTask(this, AsyncCubebOperation::STOP); + // This dispatches to a thread pool with a maximum of one thread thus it + // is guaranteed to be executed before the start event, right below. + stopEvent->Dispatch(); + } + RefPtr startEvent = + new AsyncCubebTask(this, AsyncCubebOperation::START); + startEvent->Dispatch(); } } diff --git a/dom/media/GraphDriver.h b/dom/media/GraphDriver.h index 1cac5a76a128..7bcf6acecbf9 100644 --- a/dom/media/GraphDriver.h +++ b/dom/media/GraphDriver.h @@ -322,7 +322,7 @@ struct StreamAndPromiseForOperation { dom::AudioContextOperationFlags mFlags; }; -enum AsyncCubebOperation { INIT, SHUTDOWN }; +enum class AsyncCubebOperation { INIT, START, STOP, SHUTDOWN }; enum class AudioInputType { Unknown, Voice }; /**