Bug 1571705 - Clarify mInputStream guarantees in MediaStreamTrack. r=karlt

Differential Revision: https://phabricator.services.mozilla.com/D41508

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andreas Pehrson 2019-08-19 19:26:25 +00:00
Родитель 76f9f724f2
Коммит 49244b4fad
8 изменённых файлов: 32 добавлений и 24 удалений

Просмотреть файл

@ -40,5 +40,10 @@ void AudioStreamTrack::GetLabel(nsAString& aLabel, CallerType aCallerType) {
MediaStreamTrack::GetLabel(aLabel, aCallerType);
}
already_AddRefed<MediaStreamTrack> AudioStreamTrack::CloneInternal() {
return do_AddRef(new AudioStreamTrack(mWindow, mInputStream, mTrackID,
mSource, ReadyState(), mConstraints));
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -17,8 +17,9 @@ 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,
: MediaStreamTrack(aWindow, aInputStream, aTrackID, aSource, aReadyState,
aConstraints) {}
AudioStreamTrack* AsAudioStreamTrack() override { return this; }
@ -34,11 +35,7 @@ class AudioStreamTrack : public MediaStreamTrack {
void GetLabel(nsAString& aLabel, CallerType aCallerType) override;
protected:
already_AddRefed<MediaStreamTrack> CloneInternal() override {
return do_AddRef(
new AudioStreamTrack(mWindow, Ended() ? nullptr : mInputStream.get(),
mTrackID, mSource, mConstraints));
}
already_AddRefed<MediaStreamTrack> CloneInternal() override;
};
} // namespace dom

Просмотреть файл

@ -1180,6 +1180,7 @@ class GetUserMediaStreamRunnable : public Runnable {
MOZ_ASSERT(IsOn(mConstraints.mAudio));
RefPtr<MediaStreamTrack> track = new dom::AudioStreamTrack(
window, stream, kAudioTrack, audioTrackSource,
dom::MediaStreamTrackState::Live,
GetInvariant(mConstraints.mAudio));
domStream->AddTrackInternal(track);
}
@ -1193,6 +1194,7 @@ class GetUserMediaStreamRunnable : public Runnable {
MOZ_ASSERT(IsOn(mConstraints.mVideo));
RefPtr<MediaStreamTrack> track = new dom::VideoStreamTrack(
window, stream, kVideoTrack, videoTrackSource,
dom::MediaStreamTrackState::Live,
GetInvariant(mConstraints.mVideo));
domStream->AddTrackInternal(track);
switch (mVideoDevice->GetMediaSource()) {

Просмотреть файл

@ -181,22 +181,24 @@ 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(mInputStream ? mInputStream->Graph()->CreateTrackUnionStream()
: nullptr),
mStream(aReadyState == MediaStreamTrackState::Live
? mInputStream->Graph()->CreateTrackUnionStream()
: nullptr),
mPort(mStream ? mStream->AllocateInputPort(mInputStream) : nullptr),
mTrackID(aTrackID),
mSource(aSource),
mSink(MakeUnique<TrackSink>(this)),
mPrincipal(aSource->GetPrincipal()),
mReadyState(mStream ? MediaStreamTrackState::Live
: MediaStreamTrackState::Ended),
mReadyState(aReadyState),
mEnabled(true),
mMuted(false),
mConstraints(aConstraints) {
if (!Ended()) {
MOZ_DIAGNOSTIC_ASSERT(!mInputStream->IsDestroyed());
GetSource().RegisterSink(mSink.get());
mMSGListener = new MSGListener(this);
@ -499,7 +501,6 @@ already_AddRefed<MediaStreamTrack> MediaStreamTrack::Clone() {
RefPtr<MediaStreamTrack> newTrack = CloneInternal();
newTrack->SetEnabled(Enabled());
newTrack->SetMuted(Muted());
MOZ_DIAGNOSTIC_ASSERT(newTrack->ReadyState() == ReadyState());
return newTrack.forget();
}
@ -604,9 +605,7 @@ already_AddRefed<MediaInputPort> MediaStreamTrack::ForwardTrackContentsTo(
MOZ_ASSERT(NS_IsMainThread());
MOZ_RELEASE_ASSERT(aStream);
MOZ_DIAGNOSTIC_ASSERT(!Ended());
RefPtr<MediaInputPort> port =
aStream->AllocateInputPort(mStream, mTrackID, mTrackID);
return port.forget();
return aStream->AllocateInputPort(mStream, mTrackID, mTrackID);
}
} // namespace dom

Просмотреть файл

@ -416,6 +416,7 @@ 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
@ -616,9 +617,9 @@ class MediaStreamTrack : public DOMEventTargetHelper,
// We need this to track our parent object.
nsCOMPtr<nsPIDOMWindowInner> mWindow;
// The input MediaStream assigned us by the data producer. Valid until we end.
// The input MediaStream assigned us by the data producer.
// Owned by the producer.
RefPtr<MediaStream> mInputStream;
const RefPtr<MediaStream> mInputStream;
// The MediaStream representing this MediaStreamTrack in the MediaStreamGraph.
// Valid until we end. Owned by us.
RefPtr<ProcessedMediaStream> mStream;

Просмотреть файл

@ -17,9 +17,10 @@ namespace dom {
VideoStreamTrack::VideoStreamTrack(nsPIDOMWindowInner* aWindow,
MediaStream* aInputStream, TrackID aTrackID,
MediaStreamTrackSource* aSource,
MediaStreamTrackState aReadyState,
const MediaTrackConstraints& aConstraints)
: MediaStreamTrack(aWindow, aInputStream, aTrackID, aSource, aConstraints) {
}
: MediaStreamTrack(aWindow, aInputStream, aTrackID, aSource, aReadyState,
aConstraints) {}
void VideoStreamTrack::Destroy() {
mVideoOutputs.Clear();
@ -79,5 +80,10 @@ void VideoStreamTrack::GetLabel(nsAString& aLabel, CallerType aCallerType) {
MediaStreamTrack::GetLabel(aLabel, aCallerType);
}
already_AddRefed<MediaStreamTrack> VideoStreamTrack::CloneInternal() {
return do_AddRef(new VideoStreamTrack(mWindow, mInputStream, mTrackID,
mSource, ReadyState(), mConstraints));
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -21,6 +21,7 @@ class VideoStreamTrack : public MediaStreamTrack {
VideoStreamTrack(
nsPIDOMWindowInner* aWindow, MediaStream* aInputStream, TrackID aTrackID,
MediaStreamTrackSource* aSource,
MediaStreamTrackState aState = MediaStreamTrackState::Live,
const MediaTrackConstraints& aConstraints = MediaTrackConstraints());
void Destroy() override;
@ -39,11 +40,7 @@ class VideoStreamTrack : public MediaStreamTrack {
void GetLabel(nsAString& aLabel, CallerType aCallerType) override;
protected:
already_AddRefed<MediaStreamTrack> CloneInternal() override {
return do_AddRef(
new VideoStreamTrack(mWindow, Ended() ? nullptr : mInputStream.get(),
mTrackID, mSource, mConstraints));
}
already_AddRefed<MediaStreamTrack> CloneInternal() override;
private:
nsTArray<RefPtr<VideoOutput>> mVideoOutputs;

Просмотреть файл

@ -55,7 +55,8 @@ class FakeMediaStreamTrackSource : public mozilla::dom::MediaStreamTrackSource {
class FakeAudioStreamTrack : public mozilla::dom::AudioStreamTrack {
public:
FakeAudioStreamTrack()
: AudioStreamTrack(nullptr, nullptr, 0, new FakeMediaStreamTrackSource()),
: AudioStreamTrack(nullptr, nullptr, 0, new FakeMediaStreamTrackSource(),
mozilla::dom::MediaStreamTrackState::Ended),
mMutex("Fake AudioStreamTrack"),
mStop(false),
mCount(0) {