Bug 1103188 - Keep track of stopped tracks in gUM stream listener. r=jib

This is needed to avoid something like:
* [old stream] stop track 1 -> deallocate MediaDevice for track 1
* [new stream] gUM() -> allocate MediaDevice for track 1
* [old stream] stop stream -> deallocate MediaDevice for track 1
* [new stream] gUM() -> start MediaDevice for track 1 (oops, MediaDevice was no more!)
This commit is contained in:
Andreas Pehrson 2015-09-30 14:08:33 +08:00
parent b53b7b0e03
commit 310106a37d
2 changed files with 22 additions and 6 deletions

View File

@ -3016,7 +3016,6 @@ GetUserMediaCallbackMediaStreamListener::Invalidate()
if (mStopped) {
return;
}
mStopped = true;
// We can't take a chance on blocking here, so proxy this to another
// thread.
@ -3025,8 +3024,10 @@ GetUserMediaCallbackMediaStreamListener::Invalidate()
MediaManager::PostTask(FROM_HERE,
new MediaOperationTask(MEDIA_STOP,
this, nullptr, nullptr,
mAudioDevice, mVideoDevice,
!mAudioStopped ? mAudioDevice.get() : nullptr,
!mVideoStopped ? mVideoDevice.get() : nullptr,
mFinished, mWindowID, nullptr));
mStopped = mAudioStopped = mVideoStopped = true;
}
// Doesn't kill audio
@ -3041,12 +3042,13 @@ GetUserMediaCallbackMediaStreamListener::StopSharing()
// Stop the whole stream if there's no audio; just the video track if we have both
if (!mAudioDevice) {
Invalidate();
} else {
} else if (!mVideoStopped) {
MediaManager::PostTask(FROM_HERE,
new MediaOperationTask(MEDIA_STOP_TRACK,
this, nullptr, nullptr,
nullptr, mVideoDevice,
mFinished, mWindowID, nullptr));
mVideoStopped = true;
}
} else if (mAudioDevice &&
mAudioDevice->GetMediaSource() == dom::MediaSourceEnum::AudioCapture) {
@ -3166,12 +3168,16 @@ GetUserMediaCallbackMediaStreamListener::StopTrack(TrackID aTrackID, bool aIsAud
{
// XXX to support multiple tracks of a type in a stream, this should key off
// the TrackID and not just the type
bool stopAudio = aIsAudio && !mAudioStopped;
bool stopVideo = !aIsAudio && !mVideoStopped;
MediaManager::PostTask(FROM_HERE,
new MediaOperationTask(MEDIA_STOP_TRACK,
this, nullptr, nullptr,
aIsAudio ? mAudioDevice.get() : nullptr,
!aIsAudio ? mVideoDevice.get() : nullptr,
stopAudio ? mAudioDevice.get() : nullptr,
stopVideo ? mVideoDevice.get() : nullptr,
mFinished, mWindowID, nullptr));
mAudioStopped |= stopAudio;
mVideoStopped |= stopVideo;
} else {
LOG(("gUM track %d ended, but we don't have type %s",
aTrackID, aIsAudio ? "audio" : "video"));

View File

@ -128,7 +128,9 @@ public:
, mWindowID(aWindowID)
, mStopped(false)
, mFinished(false)
, mRemoved(false) {}
, mRemoved(false)
, mAudioStopped(false)
, mVideoStopped(false) {}
~GetUserMediaCallbackMediaStreamListener()
{
@ -312,6 +314,14 @@ private:
// MainThread only.
bool mRemoved;
// true if we have sent MEDIA_STOP or MEDIA_STOP_TRACK for mAudioDevice.
// MainThread only.
bool mAudioStopped;
// true if we have sent MEDIA_STOP or MEDIA_STOP_TRACK for mAudioDevice.
// MainThread only.
bool mVideoStopped;
// Set at Activate on MainThread
// Accessed from MediaStreamGraph thread, MediaManager thread, and MainThread