Bug 1295352 - Use mState in MediaEngineTabVideoSource. r=jesup
☠☠ backed out by b527ef0a9dd2 ☠ ☠
authorAndreas Pehrson <pehrsons@gmail.com>
Thu, 25 Aug 2016 12:25:06 +0200
changeset 337843 c809cf08cc13f26ab7dfa87c000b7f84679fe061
parent 337842 2bfe422ebb4577d330fce02426e26ec9939bb66f
child 337844 6ee63db87f1eed63337409fa50007961e1e5bf07
push id10033
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:50:26 +0000
treeherdermozilla-aurora@5dddbefdf759 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1295352
milestone51.0a1
Bug 1295352 - Use mState in MediaEngineTabVideoSource. r=jesup MozReview-Commit-ID: 1zZlMXAqpo7
dom/media/webrtc/MediaEngineTabVideoSource.cpp
--- a/dom/media/webrtc/MediaEngineTabVideoSource.cpp
+++ b/dom/media/webrtc/MediaEngineTabVideoSource.cpp
@@ -144,16 +144,22 @@ MediaEngineTabVideoSource::Allocate(cons
                                     const char** aOutBadConstraint)
 {
   // windowId is not a proper constraint, so just read it.
   // It has no well-defined behavior in advanced, so ignore it there.
 
   mWindowId = aConstraints.mBrowserWindow.WasPassed() ?
               aConstraints.mBrowserWindow.Value() : -1;
   *aOutHandle = nullptr;
+
+  {
+    MonitorAutoLock mon(mMonitor);
+    mState = kAllocated;
+  }
+
   return Restart(nullptr, aConstraints, aPrefs, aDeviceId, aOutBadConstraint);
 }
 
 nsresult
 MediaEngineTabVideoSource::Restart(AllocationHandle* aHandle,
                                    const dom::MediaTrackConstraints& aConstraints,
                                    const mozilla::MediaEnginePrefs& aPrefs,
                                    const nsString& aDeviceId,
@@ -182,31 +188,40 @@ MediaEngineTabVideoSource::Restart(Alloc
   }
   return NS_OK;
 }
 
 nsresult
 MediaEngineTabVideoSource::Deallocate(AllocationHandle* aHandle)
 {
   MOZ_ASSERT(!aHandle);
+  {
+    MonitorAutoLock mon(mMonitor);
+    mState = kReleased;
+  }
   return NS_OK;
 }
 
 nsresult
 MediaEngineTabVideoSource::Start(SourceMediaStream* aStream, TrackID aID,
                                  const PrincipalHandle& aPrincipalHandle)
 {
   nsCOMPtr<nsIRunnable> runnable;
   if (!mWindow)
     runnable = new InitRunnable(this);
   else
     runnable = new StartRunnable(this);
   NS_DispatchToMainThread(runnable);
   aStream->AddTrack(aID, 0, new VideoSegment());
 
+  {
+    MonitorAutoLock mon(mMonitor);
+    mState = kStarted;
+  }
+
   return NS_OK;
 }
 
 void
 MediaEngineTabVideoSource::NotifyPull(MediaStreamGraph*,
                                       SourceMediaStream* aSource,
                                       TrackID aID, StreamTime aDesiredTime,
                                       const PrincipalHandle& aPrincipalHandle)
@@ -333,25 +348,32 @@ MediaEngineTabVideoSource::Draw() {
 
   RefPtr<layers::SourceSurfaceImage> image = new layers::SourceSurfaceImage(size, surface);
 
   MonitorAutoLock mon(mMonitor);
   mImage = image;
 }
 
 nsresult
-MediaEngineTabVideoSource::Stop(mozilla::SourceMediaStream*, mozilla::TrackID)
+MediaEngineTabVideoSource::Stop(mozilla::SourceMediaStream* aSource,
+                                mozilla::TrackID aID)
 {
   // If mBlackedoutWindow is true, we may be running
   // despite mWindow == nullptr.
   if (!mWindow && !mBlackedoutWindow) {
     return NS_OK;
   }
 
   NS_DispatchToMainThread(new StopRunnable(this));
+
+  {
+    MonitorAutoLock mon(mMonitor);
+    mState = kStopped;
+    aSource->EndTrack(aID);
+  }
   return NS_OK;
 }
 
 bool
 MediaEngineTabVideoSource::IsFake()
 {
   return false;
 }