Bug 1295352 - Use mState in MediaEngineTabVideoSource. r=jesup draft
authorAndreas Pehrson <pehrsons@gmail.com>
Thu, 25 Aug 2016 12:25:06 +0200
changeset 406786 073c1c1d4f5c4b74b0170beaa0bcd9f1335a009f
parent 406785 1ce4c822edb3a282e505423cae0235a98329f9cb
child 406787 bc1d2ac35ef460ac9c7143a131b17f9823a8a879
child 406792 d7dbeafb0a80559d320924b1420bc0bcc222c392
child 407391 fd3a8cdfb95dd926d8f74424728714809704fd39
push id27827
push userpehrsons@gmail.com
push dateMon, 29 Aug 2016 14:48:02 +0000
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;
 }