Bug 1677520 - Make MockCubebStream::Stop idempotent. r=padenot
authorAndreas Pehrson <apehrson@mozilla.com>
Wed, 18 Nov 2020 09:20:32 +0000
changeset 557783 05f509ea5a75ce98b12dd76dc5a46b6c1e4b626e
parent 557782 c93bd52311d8bde1856d56dee77211e27c2b29c5
child 557784 03bfb9c8a6bac08dce5d3dddccaf43f63f825f5c
push id37961
push userccoroiu@mozilla.com
push dateWed, 18 Nov 2020 16:05:35 +0000
treeherdermozilla-central@2f08ec7e57c3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1677520
milestone85.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1677520 - Make MockCubebStream::Stop idempotent. r=padenot Differential Revision: https://phabricator.services.mozilla.com/D97305
dom/media/gtest/MockCubeb.cpp
dom/media/gtest/MockCubeb.h
--- a/dom/media/gtest/MockCubeb.cpp
+++ b/dom/media/gtest/MockCubeb.cpp
@@ -49,20 +49,22 @@ int MockCubebStream::Start() {
   return CUBEB_OK;
 }
 
 int MockCubebStream::Stop() {
   mStreamStop = true;
   mOutputVerificationEvent.Notify(MakeTuple(
       mAudioVerifier.PreSilenceSamples(), mAudioVerifier.EstimatedFreq(),
       mAudioVerifier.CountDiscontinuities()));
-  reinterpret_cast<MockCubeb*>(context)->StopStream(this);
-  cubeb_stream* stream = reinterpret_cast<cubeb_stream*>(this);
-  mStateCallback(stream, mUserPtr, CUBEB_STATE_STOPPED);
-  return CUBEB_OK;
+  int rv = reinterpret_cast<MockCubeb*>(context)->StopStream(this);
+  if (rv == CUBEB_OK) {
+    cubeb_stream* stream = reinterpret_cast<cubeb_stream*>(this);
+    mStateCallback(stream, mUserPtr, CUBEB_STATE_STOPPED);
+  }
+  return rv;
 }
 
 cubeb_devid MockCubebStream::GetInputDeviceID() const { return mInputDeviceID; }
 
 cubeb_devid MockCubebStream::GetOutputDeviceID() const {
   return mOutputDeviceID;
 }
 
@@ -317,30 +319,34 @@ void MockCubeb::StartStream(MockCubebStr
   auto streams = mLiveStreams.Lock();
   MOZ_ASSERT(!streams->Contains(aStream));
   streams->AppendElement(aStream);
   if (!mFakeAudioThread) {
     mFakeAudioThread = WrapUnique(new std::thread(ThreadFunction_s, this));
   }
 }
 
-void MockCubeb::StopStream(MockCubebStream* aStream) {
+int MockCubeb::StopStream(MockCubebStream* aStream) {
   UniquePtr<std::thread> audioThread;
   {
     auto streams = mLiveStreams.Lock();
+    if (!streams->Contains(aStream)) {
+      return CUBEB_ERROR;
+    }
     MOZ_ASSERT(streams->Contains(aStream));
     streams->RemoveElement(aStream);
     MOZ_ASSERT(mFakeAudioThread);
     if (streams->IsEmpty()) {
       audioThread = std::move(mFakeAudioThread);
     }
   }
   if (audioThread) {
     audioThread->join();
   }
+  return CUBEB_OK;
 }
 
 void MockCubeb::ThreadFunction() {
   while (true) {
     {
       auto streams = mLiveStreams.Lock();
       for (auto& stream : *streams) {
         stream->Process10Ms();
--- a/dom/media/gtest/MockCubeb.h
+++ b/dom/media/gtest/MockCubeb.h
@@ -244,17 +244,17 @@ class MockCubeb {
   void GoFaster();
   void DontGoFaster();
 
   MediaEventSource<MockCubebStream*>& StreamInitEvent();
   MediaEventSource<void>& StreamDestroyEvent();
 
   // MockCubeb specific API
   void StartStream(MockCubebStream* aStream);
-  void StopStream(MockCubebStream* aStream);
+  int StopStream(MockCubebStream* aStream);
 
   // Simulates the audio thread. The thread is created at Start and destroyed
   // at Stop. At next StreamStart a new thread is created.
   static void ThreadFunction_s(MockCubeb* aContext) {
     aContext->ThreadFunction();
   }
 
   void ThreadFunction();