diff --git a/dom/media/AudioStreamTrack.cpp b/dom/media/AudioStreamTrack.cpp index 146fdd364da9..d589f62a7ca2 100644 --- a/dom/media/AudioStreamTrack.cpp +++ b/dom/media/AudioStreamTrack.cpp @@ -40,10 +40,5 @@ void AudioStreamTrack::GetLabel(nsAString& aLabel, CallerType aCallerType) { MediaStreamTrack::GetLabel(aLabel, aCallerType); } -already_AddRefed AudioStreamTrack::CloneInternal() { - return do_AddRef(new AudioStreamTrack(mWindow, mInputStream, mTrackID, - mSource, ReadyState(), mConstraints)); -} - } // namespace dom } // namespace mozilla diff --git a/dom/media/AudioStreamTrack.h b/dom/media/AudioStreamTrack.h index ce16d17c8d42..fcbf1ee2a40f 100644 --- a/dom/media/AudioStreamTrack.h +++ b/dom/media/AudioStreamTrack.h @@ -17,9 +17,8 @@ class AudioStreamTrack : public MediaStreamTrack { AudioStreamTrack( nsPIDOMWindowInner* aWindow, MediaStream* aInputStream, TrackID aTrackID, MediaStreamTrackSource* aSource, - MediaStreamTrackState aReadyState = MediaStreamTrackState::Live, const MediaTrackConstraints& aConstraints = MediaTrackConstraints()) - : MediaStreamTrack(aWindow, aInputStream, aTrackID, aSource, aReadyState, + : MediaStreamTrack(aWindow, aInputStream, aTrackID, aSource, aConstraints) {} AudioStreamTrack* AsAudioStreamTrack() override { return this; } @@ -35,7 +34,11 @@ class AudioStreamTrack : public MediaStreamTrack { void GetLabel(nsAString& aLabel, CallerType aCallerType) override; protected: - already_AddRefed CloneInternal() override; + already_AddRefed CloneInternal() override { + return do_AddRef( + new AudioStreamTrack(mWindow, Ended() ? nullptr : mInputStream.get(), + mTrackID, mSource, mConstraints)); + } }; } // namespace dom diff --git a/dom/media/MediaManager.cpp b/dom/media/MediaManager.cpp index 9839bd401448..d8ff7065ecbf 100644 --- a/dom/media/MediaManager.cpp +++ b/dom/media/MediaManager.cpp @@ -1180,7 +1180,6 @@ class GetUserMediaStreamRunnable : public Runnable { MOZ_ASSERT(IsOn(mConstraints.mAudio)); RefPtr track = new dom::AudioStreamTrack( window, stream, kAudioTrack, audioTrackSource, - dom::MediaStreamTrackState::Live, GetInvariant(mConstraints.mAudio)); domStream->AddTrackInternal(track); } @@ -1194,7 +1193,6 @@ class GetUserMediaStreamRunnable : public Runnable { MOZ_ASSERT(IsOn(mConstraints.mVideo)); RefPtr track = new dom::VideoStreamTrack( window, stream, kVideoTrack, videoTrackSource, - dom::MediaStreamTrackState::Live, GetInvariant(mConstraints.mVideo)); domStream->AddTrackInternal(track); switch (mVideoDevice->GetMediaSource()) { diff --git a/dom/media/MediaStreamGraph.cpp b/dom/media/MediaStreamGraph.cpp index 51e08350bcfe..0e1ce66bf9a5 100644 --- a/dom/media/MediaStreamGraph.cpp +++ b/dom/media/MediaStreamGraph.cpp @@ -2959,11 +2959,8 @@ bool SourceMediaStream::HasPendingAudioTrack() { void MediaInputPort::Init() { LOG(LogLevel::Debug, ("%p: Adding MediaInputPort %p (from %p to %p)", mSource->GraphImpl(), this, mSource, mDest)); - // Only connect the port if it wasn't disconnected on allocation. - if (mSource) { - mSource->AddConsumer(this); - mDest->AddInput(this); - } + mSource->AddConsumer(this); + mDest->AddInput(this); // mPortCount decremented via MediaInputPort::Destroy's message ++mDest->GraphImpl()->mPortCount; } @@ -3107,6 +3104,7 @@ already_AddRefed ProcessedMediaStream::AllocateInputPort( RefPtr mPort; }; + MOZ_ASSERT(aStream->GraphImpl() == GraphImpl()); MOZ_ASSERT(aTrackID == TRACK_ANY || IsTrackIDExplicit(aTrackID), "Only TRACK_ANY and explicit ID are allowed for source track"); MOZ_ASSERT( @@ -3115,18 +3113,8 @@ already_AddRefed ProcessedMediaStream::AllocateInputPort( MOZ_ASSERT( aTrackID != TRACK_ANY || aDestTrackID == TRACK_ANY, "Generic MediaInputPort cannot produce a single destination track"); - RefPtr port; - if (aStream->IsDestroyed()) { - // Create a port that's disconnected, which is what it'd be after its source - // stream is Destroy()ed normally. Disconnect() is idempotent so destroying - // this later is fine. - port = new MediaInputPort(nullptr, aTrackID, nullptr, aDestTrackID, - aInputNumber, aOutputNumber); - } else { - MOZ_ASSERT(aStream->GraphImpl() == GraphImpl()); - port = new MediaInputPort(aStream, aTrackID, this, aDestTrackID, - aInputNumber, aOutputNumber); - } + RefPtr port = new MediaInputPort( + aStream, aTrackID, this, aDestTrackID, aInputNumber, aOutputNumber); if (aBlockedTracks) { for (TrackID trackID : *aBlockedTracks) { port->BlockSourceTrackIdImpl(trackID, BlockingMode::CREATION); diff --git a/dom/media/MediaStreamTrack.cpp b/dom/media/MediaStreamTrack.cpp index be824914824f..cbbc2e959a6e 100644 --- a/dom/media/MediaStreamTrack.cpp +++ b/dom/media/MediaStreamTrack.cpp @@ -181,24 +181,22 @@ class MediaStreamTrack::TrackSink : public MediaStreamTrackSource::Sink { MediaStreamTrack::MediaStreamTrack(nsPIDOMWindowInner* aWindow, MediaStream* aInputStream, TrackID aTrackID, MediaStreamTrackSource* aSource, - MediaStreamTrackState aReadyState, const MediaTrackConstraints& aConstraints) : mWindow(aWindow), mInputStream(aInputStream), - mStream(aReadyState == MediaStreamTrackState::Live - ? mInputStream->Graph()->CreateTrackUnionStream() - : nullptr), + mStream(mInputStream ? mInputStream->Graph()->CreateTrackUnionStream() + : nullptr), mPort(mStream ? mStream->AllocateInputPort(mInputStream) : nullptr), mTrackID(aTrackID), mSource(aSource), mSink(MakeUnique(this)), mPrincipal(aSource->GetPrincipal()), - mReadyState(aReadyState), + mReadyState(mStream ? MediaStreamTrackState::Live + : MediaStreamTrackState::Ended), mEnabled(true), mMuted(false), mConstraints(aConstraints) { if (!Ended()) { - MOZ_DIAGNOSTIC_ASSERT(!mInputStream->IsDestroyed()); GetSource().RegisterSink(mSink.get()); mMSGListener = new MSGListener(this); @@ -501,6 +499,7 @@ already_AddRefed MediaStreamTrack::Clone() { RefPtr newTrack = CloneInternal(); newTrack->SetEnabled(Enabled()); newTrack->SetMuted(Muted()); + MOZ_DIAGNOSTIC_ASSERT(newTrack->ReadyState() == ReadyState()); return newTrack.forget(); } @@ -604,7 +603,10 @@ already_AddRefed MediaStreamTrack::ForwardTrackContentsTo( ProcessedMediaStream* aStream) { MOZ_ASSERT(NS_IsMainThread()); MOZ_RELEASE_ASSERT(aStream); - return aStream->AllocateInputPort(mStream, mTrackID, mTrackID); + MOZ_DIAGNOSTIC_ASSERT(!Ended()); + RefPtr port = + aStream->AllocateInputPort(mStream, mTrackID, mTrackID); + return port.forget(); } } // namespace dom diff --git a/dom/media/MediaStreamTrack.h b/dom/media/MediaStreamTrack.h index c8f34d0c52ff..b21afef6502a 100644 --- a/dom/media/MediaStreamTrack.h +++ b/dom/media/MediaStreamTrack.h @@ -416,7 +416,6 @@ class MediaStreamTrack : public DOMEventTargetHelper, MediaStreamTrack( nsPIDOMWindowInner* aWindow, MediaStream* aInputStream, TrackID aTrackID, MediaStreamTrackSource* aSource, - MediaStreamTrackState aReadyState = MediaStreamTrackState::Live, const MediaTrackConstraints& aConstraints = MediaTrackConstraints()); NS_DECL_ISUPPORTS_INHERITED @@ -617,9 +616,9 @@ class MediaStreamTrack : public DOMEventTargetHelper, // We need this to track our parent object. nsCOMPtr mWindow; - // The input MediaStream assigned us by the data producer. + // The input MediaStream assigned us by the data producer. Valid until we end. // Owned by the producer. - const RefPtr mInputStream; + RefPtr mInputStream; // The MediaStream representing this MediaStreamTrack in the MediaStreamGraph. // Valid until we end. Owned by us. RefPtr mStream; diff --git a/dom/media/VideoStreamTrack.cpp b/dom/media/VideoStreamTrack.cpp index 142c64eda595..f9f34664bbe4 100644 --- a/dom/media/VideoStreamTrack.cpp +++ b/dom/media/VideoStreamTrack.cpp @@ -17,10 +17,9 @@ namespace dom { VideoStreamTrack::VideoStreamTrack(nsPIDOMWindowInner* aWindow, MediaStream* aInputStream, TrackID aTrackID, MediaStreamTrackSource* aSource, - MediaStreamTrackState aReadyState, const MediaTrackConstraints& aConstraints) - : MediaStreamTrack(aWindow, aInputStream, aTrackID, aSource, aReadyState, - aConstraints) {} + : MediaStreamTrack(aWindow, aInputStream, aTrackID, aSource, aConstraints) { +} void VideoStreamTrack::Destroy() { mVideoOutputs.Clear(); @@ -80,10 +79,5 @@ void VideoStreamTrack::GetLabel(nsAString& aLabel, CallerType aCallerType) { MediaStreamTrack::GetLabel(aLabel, aCallerType); } -already_AddRefed VideoStreamTrack::CloneInternal() { - return do_AddRef(new VideoStreamTrack(mWindow, mInputStream, mTrackID, - mSource, ReadyState(), mConstraints)); -} - } // namespace dom } // namespace mozilla diff --git a/dom/media/VideoStreamTrack.h b/dom/media/VideoStreamTrack.h index e85fbda5020a..8ed55534eec3 100644 --- a/dom/media/VideoStreamTrack.h +++ b/dom/media/VideoStreamTrack.h @@ -21,7 +21,6 @@ class VideoStreamTrack : public MediaStreamTrack { VideoStreamTrack( nsPIDOMWindowInner* aWindow, MediaStream* aInputStream, TrackID aTrackID, MediaStreamTrackSource* aSource, - MediaStreamTrackState aState = MediaStreamTrackState::Live, const MediaTrackConstraints& aConstraints = MediaTrackConstraints()); void Destroy() override; @@ -40,7 +39,11 @@ class VideoStreamTrack : public MediaStreamTrack { void GetLabel(nsAString& aLabel, CallerType aCallerType) override; protected: - already_AddRefed CloneInternal() override; + already_AddRefed CloneInternal() override { + return do_AddRef( + new VideoStreamTrack(mWindow, Ended() ? nullptr : mInputStream.get(), + mTrackID, mSource, mConstraints)); + } private: nsTArray> mVideoOutputs;