Bug 1320994 - Improve SourceListener logging. r=jib
authorAndreas Pehrson <pehrsons@gmail.com>
Wed, 29 Mar 2017 12:07:45 +0200
changeset 356888 d34041d4dfe96a6872d2c4a569e0c428fa91a371
parent 356887 ebd5f2bb5c5948ae2348e62d3b71c018b0669934
child 356889 1fb2d6e0aa2d82c2db246ecd75f7225fecc449ed
push id31775
push userihsiao@mozilla.com
push dateMon, 08 May 2017 03:10:38 +0000
treeherdermozilla-central@22aaf8bad4df [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib
bugs1320994
milestone55.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 1320994 - Improve SourceListener logging. r=jib MozReview-Commit-ID: 1xuLwpMHMQB
dom/media/MediaManager.cpp
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -3372,16 +3372,18 @@ SourceListener::SourceListener()
   , mMainThreadCheck(nullptr)
   , mPrincipalHandle(PRINCIPAL_HANDLE_NONE)
   , mWindowListener(nullptr)
 {}
 
 void
 SourceListener::Register(GetUserMediaWindowListener* aListener)
 {
+  LOG(("SourceListener %p registering with window listener %p", this, aListener));
+
   if (mWindowListener) {
     MOZ_ASSERT(false, "Already registered");
     return;
   }
   if (mActivated) {
     MOZ_ASSERT(false, "Already activated");
     return;
   }
@@ -3395,16 +3397,18 @@ SourceListener::Register(GetUserMediaWin
 
 void
 SourceListener::Activate(SourceMediaStream* aStream,
                          AudioDevice* aAudioDevice,
                          VideoDevice* aVideoDevice)
 {
   MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread");
 
+  LOG(("SourceListener %p activating audio=%p video=%p", this, aAudioDevice, aVideoDevice));
+
   if (mActivated) {
     MOZ_ASSERT(false, "Already activated");
     return;
   }
 
   mActivated = true;
   mMainThreadCheck = PR_GetCurrentThread();
   mStream = aStream;
@@ -3417,16 +3421,18 @@ void
 SourceListener::Stop()
 {
   MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread");
 
   if (mStopped) {
     return;
   }
 
+  LOG(("SourceListener %p stopping", this));
+
   // StopSharing() has some special logic, at least for audio capture.
   // It must be called when all tracks have stopped, before setting mStopped.
   StopSharing();
 
   mStopped = true;
 
   if (mAudioDevice && !mAudioStopped) {
     StopTrack(kAudioTrack);
@@ -3444,17 +3450,17 @@ SourceListener::Stop()
 void
 SourceListener::Remove()
 {
   MOZ_ASSERT(NS_IsMainThread());
   if (!mStream || mRemoved) {
     return;
   }
 
-  LOG(("SourceListener removed on purpose, mFinished = %d", (int) mFinished));
+  LOG(("SourceListener %p removed on purpose, mFinished = %d", this, (int) mFinished));
   mRemoved = true; // RemoveListener is async, avoid races
   mWindowListener = nullptr;
 
   // If it's destroyed, don't call - listener will be removed and we'll be notified!
   if (!mStream->IsDestroyed()) {
     mStream->RemoveListener(this);
   }
 }
@@ -3464,30 +3470,32 @@ SourceListener::StopTrack(TrackID aTrack
 {
   MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread");
 
   RefPtr<MediaDevice> device;
   RefPtr<SourceMediaStream> source;
 
   switch (aTrackID) {
     case kAudioTrack: {
+      LOG(("SourceListener %p stopping audio track %d", this, aTrackID));
       if (!mAudioDevice) {
         NS_ASSERTION(false, "Can't stop audio. No device.");
         return;
       }
       if (mAudioStopped) {
         // Audio already stopped
         return;
       }
       device = mAudioDevice;
       source = GetSourceStream();
       mAudioStopped = true;
       break;
     }
     case kVideoTrack: {
+      LOG(("SourceListener %p stopping video track %d", this, aTrackID));
       if (!mVideoDevice) {
         NS_ASSERTION(false, "Can't stop video. No device.");
         return;
       }
       if (mVideoStopped) {
         // Video already stopped
         return;
       }
@@ -3504,16 +3512,17 @@ SourceListener::StopTrack(TrackID aTrack
 
   MediaManager::PostTask(NewTaskFrom([device, source, aTrackID]() {
     device->GetSource()->Stop(source, aTrackID);
     device->Deallocate();
   }));
 
   if ((!mAudioDevice || mAudioStopped) &&
       (!mVideoDevice || mVideoStopped)) {
+    LOG(("SourceListener %p this was the last track stopped", this));
     Stop();
   }
 
   if (!mWindowListener) {
     MOZ_ASSERT(false, "Should still have window listener");
     return;
   }
   mWindowListener->NotifySourceTrackStopped();
@@ -3524,16 +3533,18 @@ SourceListener::StopSharing()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_RELEASE_ASSERT(mWindowListener);
 
   if (mStopped) {
     return;
   }
 
+  LOG(("SourceListener %p StopSharing", this));
+
   if (mVideoDevice &&
       (mVideoDevice->GetMediaSource() == MediaSourceEnum::Screen ||
        mVideoDevice->GetMediaSource() == MediaSourceEnum::Application ||
        mVideoDevice->GetMediaSource() == MediaSourceEnum::Window)) {
     // We want to stop the whole stream if there's no audio;
     // just the video track if we have both.
     // StopTrack figures this out for us.
     StopTrack(kVideoTrack);
@@ -3649,16 +3660,18 @@ SourceListener::NotifyFinished()
 {
   MOZ_ASSERT(NS_IsMainThread());
   mFinished = true;
   if (!mWindowListener) {
     // Removed explicitly before finished.
     return;
   }
 
+  LOG(("SourceListener %p NotifyFinished", this));
+
   Stop(); // we know it's been activated
   mWindowListener->Remove(this);
 }
 
 void
 SourceListener::NotifyRemoved()
 {
   MOZ_ASSERT(NS_IsMainThread());