--- 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());