зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1259788 - Break out AddTrackInternal() from DOMMediaStream::CreateDOMTrack. r=jesup
Sometimes a track is added to a stream synchronously (before the stream is exposed to script), and sometimes asynchronously (see the mediacapture-main spec on the "addtrack" event). In the latter case we might still need to create the MediaStreamTrack object synchronously for tracking purposes. CaptureStream of Media element playing a MediaStream wants this. MozReview-Commit-ID: 7me8xzN7rwj --HG-- extra : rebase_source : 4f129b127b855e47aad2ae9ab3981ffde057412d
This commit is contained in:
Родитель
e9d5ff0db1
Коммит
83dcc7266e
|
@ -686,8 +686,10 @@ HTMLCanvasElement::CaptureStream(const Optional<double>& aFrameRate,
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<MediaStreamTrack> track =
|
||||
stream->CreateDOMTrack(videoTrackId, MediaSegment::VIDEO,
|
||||
new BasicUnstoppableTrackSource(principal));
|
||||
stream->AddTrackInternal(track);
|
||||
|
||||
rv = RegisterFrameCaptureListener(stream->FrameCaptureListener());
|
||||
if (NS_FAILED(rv)) {
|
||||
|
|
|
@ -2288,15 +2288,19 @@ HTMLMediaElement::CaptureStreamInternal(bool aFinishWhenEnded,
|
|||
TrackID audioTrackId = mMediaInfo.mAudio.mTrackId;
|
||||
RefPtr<MediaStreamTrackSource> trackSource =
|
||||
getter->GetMediaStreamTrackSource(audioTrackId);
|
||||
out->mStream->CreateDOMTrack(audioTrackId, MediaSegment::AUDIO,
|
||||
trackSource);
|
||||
RefPtr<MediaStreamTrack> track =
|
||||
out->mStream->CreateDOMTrack(audioTrackId, MediaSegment::AUDIO,
|
||||
trackSource);
|
||||
out->mStream->AddTrackInternal(track);
|
||||
}
|
||||
if (HasVideo()) {
|
||||
TrackID videoTrackId = mMediaInfo.mVideo.mTrackId;
|
||||
RefPtr<MediaStreamTrackSource> trackSource =
|
||||
getter->GetMediaStreamTrackSource(videoTrackId);
|
||||
out->mStream->CreateDOMTrack(videoTrackId, MediaSegment::VIDEO,
|
||||
trackSource);
|
||||
RefPtr<MediaStreamTrack> track =
|
||||
out->mStream->CreateDOMTrack(videoTrackId, MediaSegment::VIDEO,
|
||||
trackSource);
|
||||
out->mStream->AddTrackInternal(track);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -162,7 +162,9 @@ public:
|
|||
nsIPrincipal* principal = doc ? doc->NodePrincipal() : nullptr;
|
||||
source = new BasicUnstoppableTrackSource(principal);
|
||||
}
|
||||
track = mStream->CreateDOMTrack(aTrackID, aType, source);
|
||||
RefPtr<MediaStreamTrack> newTrack =
|
||||
mStream->CreateDOMTrack(aTrackID, aType, source);
|
||||
mStream->AddTrackInternal(newTrack);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -809,7 +811,10 @@ DOMMediaStream::InitAudioCaptureStream(nsIPrincipal* aPrincipal, MediaStreamGrap
|
|||
InitInputStreamCommon(audioCaptureStream, aGraph);
|
||||
InitOwnedStreamCommon(aGraph);
|
||||
InitPlaybackStreamCommon(aGraph);
|
||||
CreateDOMTrack(AUDIO_TRACK, MediaSegment::AUDIO, audioCaptureSource);
|
||||
RefPtr<MediaStreamTrack> track =
|
||||
CreateDOMTrack(AUDIO_TRACK, MediaSegment::AUDIO, audioCaptureSource);
|
||||
AddTrackInternal(track);
|
||||
|
||||
audioCaptureStream->Start();
|
||||
}
|
||||
|
||||
|
@ -977,7 +982,27 @@ DOMMediaStream::RemovePrincipalChangeObserver(
|
|||
return mPrincipalChangeObservers.RemoveElement(aObserver);
|
||||
}
|
||||
|
||||
MediaStreamTrack*
|
||||
void
|
||||
DOMMediaStream::AddTrackInternal(MediaStreamTrack* aTrack)
|
||||
{
|
||||
MOZ_ASSERT(aTrack->mOwningStream == this);
|
||||
MOZ_ASSERT(FindOwnedDOMTrack(aTrack->GetInputStream(),
|
||||
aTrack->mInputTrackID,
|
||||
aTrack->mTrackID));
|
||||
MOZ_ASSERT(!FindPlaybackDOMTrack(aTrack->GetOwnedStream(),
|
||||
aTrack->mTrackID));
|
||||
|
||||
LOG(LogLevel::Debug, ("DOMMediaStream %p Adding owned track %p", this, aTrack));
|
||||
|
||||
mTracks.AppendElement(
|
||||
new TrackPort(mPlaybackPort, aTrack, TrackPort::InputPortOwnership::EXTERNAL));
|
||||
|
||||
NotifyTrackAdded(aTrack);
|
||||
|
||||
DispatchTrackEvent(NS_LITERAL_STRING("addtrack"), aTrack);
|
||||
}
|
||||
|
||||
already_AddRefed<MediaStreamTrack>
|
||||
DOMMediaStream::CreateDOMTrack(TrackID aTrackID, MediaSegment::Type aType,
|
||||
MediaStreamTrackSource* aSource,
|
||||
const MediaTrackConstraints& aConstraints)
|
||||
|
@ -987,7 +1012,7 @@ DOMMediaStream::CreateDOMTrack(TrackID aTrackID, MediaSegment::Type aType,
|
|||
|
||||
MOZ_ASSERT(FindOwnedDOMTrack(GetInputStream(), aTrackID) == nullptr);
|
||||
|
||||
MediaStreamTrack* track;
|
||||
RefPtr<MediaStreamTrack> track;
|
||||
switch (aType) {
|
||||
case MediaSegment::AUDIO:
|
||||
track = new AudioStreamTrack(this, aTrackID, aTrackID, aSource, aConstraints);
|
||||
|
@ -999,19 +1024,13 @@ DOMMediaStream::CreateDOMTrack(TrackID aTrackID, MediaSegment::Type aType,
|
|||
MOZ_CRASH("Unhandled track type");
|
||||
}
|
||||
|
||||
LOG(LogLevel::Debug, ("DOMMediaStream %p Created new track %p with ID %u", this, track, aTrackID));
|
||||
LOG(LogLevel::Debug, ("DOMMediaStream %p Created new track %p with ID %u",
|
||||
this, track.get(), aTrackID));
|
||||
|
||||
mOwnedTracks.AppendElement(
|
||||
new TrackPort(mOwnedPort, track, TrackPort::InputPortOwnership::EXTERNAL));
|
||||
|
||||
mTracks.AppendElement(
|
||||
new TrackPort(mPlaybackPort, track, TrackPort::InputPortOwnership::EXTERNAL));
|
||||
|
||||
NotifyTrackAdded(track);
|
||||
|
||||
DispatchTrackEvent(NS_LITERAL_STRING("addtrack"), track);
|
||||
|
||||
return track;
|
||||
return track.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<MediaStreamTrack>
|
||||
|
|
|
@ -511,19 +511,25 @@ public:
|
|||
}
|
||||
|
||||
/**
|
||||
* Called for each track in our owned stream to indicate to JS that we
|
||||
* are carrying that track.
|
||||
*
|
||||
* Creates a MediaStreamTrack, adds it to mTracks, raises "addtrack" and
|
||||
* returns it.
|
||||
* Adds a MediaStreamTrack to mTracks and raises "addtrack".
|
||||
*
|
||||
* Note that "addtrack" is raised synchronously and only has an effect if
|
||||
* this MediaStream is already exposed to script. For spec compliance this is
|
||||
* to be called from an async task.
|
||||
*/
|
||||
MediaStreamTrack* CreateDOMTrack(TrackID aTrackID, MediaSegment::Type aType,
|
||||
MediaStreamTrackSource* aSource,
|
||||
const MediaTrackConstraints& aConstraints = MediaTrackConstraints());
|
||||
void AddTrackInternal(MediaStreamTrack* aTrack);
|
||||
|
||||
/**
|
||||
* Called for each track in our owned stream to indicate to JS that we
|
||||
* are carrying that track.
|
||||
*
|
||||
* Pre-creates a MediaStreamTrack and returns it.
|
||||
* It is up to the caller to make sure it is added through AddTrackInternal.
|
||||
*/
|
||||
already_AddRefed<MediaStreamTrack> CreateDOMTrack(TrackID aTrackID,
|
||||
MediaSegment::Type aType,
|
||||
MediaStreamTrackSource* aSource,
|
||||
const MediaTrackConstraints& aConstraints = MediaTrackConstraints());
|
||||
|
||||
/**
|
||||
* Creates a MediaStreamTrack cloned from aTrack, adds it to mTracks and
|
||||
|
|
|
@ -1207,8 +1207,10 @@ public:
|
|||
new LocalTrackSource(principal, audioDeviceName, mListener, source,
|
||||
kAudioTrack, mPeerIdentity);
|
||||
MOZ_ASSERT(IsOn(mConstraints.mAudio));
|
||||
domStream->CreateDOMTrack(kAudioTrack, MediaSegment::AUDIO, audioSource,
|
||||
GetInvariant(mConstraints.mAudio));
|
||||
RefPtr<MediaStreamTrack> track =
|
||||
domStream->CreateDOMTrack(kAudioTrack, MediaSegment::AUDIO, audioSource,
|
||||
GetInvariant(mConstraints.mAudio));
|
||||
domStream->AddTrackInternal(track);
|
||||
}
|
||||
if (mVideoDevice) {
|
||||
nsString videoDeviceName;
|
||||
|
@ -1219,8 +1221,10 @@ public:
|
|||
new LocalTrackSource(principal, videoDeviceName, mListener, source,
|
||||
kVideoTrack, mPeerIdentity);
|
||||
MOZ_ASSERT(IsOn(mConstraints.mVideo));
|
||||
domStream->CreateDOMTrack(kVideoTrack, MediaSegment::VIDEO, videoSource,
|
||||
GetInvariant(mConstraints.mVideo));
|
||||
RefPtr<MediaStreamTrack> track =
|
||||
domStream->CreateDOMTrack(kVideoTrack, MediaSegment::VIDEO, videoSource,
|
||||
GetInvariant(mConstraints.mVideo));
|
||||
domStream->AddTrackInternal(track);
|
||||
}
|
||||
stream = domStream->GetInputStream()->AsSourceStream();
|
||||
}
|
||||
|
|
|
@ -39,9 +39,11 @@ MediaStreamAudioDestinationNode::MediaStreamAudioDestinationNode(AudioContext* a
|
|||
RefPtr<MediaStreamTrackSource> source =
|
||||
new BasicUnstoppableTrackSource(doc->NodePrincipal(),
|
||||
MediaSourceEnum::AudioCapture);
|
||||
mDOMStream->CreateDOMTrack(AudioNodeStream::AUDIO_TRACK,
|
||||
MediaSegment::AUDIO, source,
|
||||
MediaTrackConstraints());
|
||||
RefPtr<MediaStreamTrack> track =
|
||||
mDOMStream->CreateDOMTrack(AudioNodeStream::AUDIO_TRACK,
|
||||
MediaSegment::AUDIO, source,
|
||||
MediaTrackConstraints());
|
||||
mDOMStream->AddTrackInternal(track);
|
||||
|
||||
ProcessedMediaStream* outputStream = mDOMStream->GetInputStream()->AsProcessedStream();
|
||||
MOZ_ASSERT(!!outputStream);
|
||||
|
|
|
@ -1993,12 +1993,14 @@ PeerConnectionImpl::CreateNewRemoteTracks(RefPtr<PeerConnectionObserver>& aPco)
|
|||
info->GetMediaStream()->CreateDOMTrack(trackID,
|
||||
MediaSegment::AUDIO,
|
||||
source);
|
||||
info->GetMediaStream()->AddTrackInternal(domTrack);
|
||||
segment = new AudioSegment;
|
||||
} else {
|
||||
domTrack =
|
||||
info->GetMediaStream()->CreateDOMTrack(trackID,
|
||||
MediaSegment::VIDEO,
|
||||
source);
|
||||
info->GetMediaStream()->AddTrackInternal(domTrack);
|
||||
#if !defined(MOZILLA_EXTERNAL_LINKAGE)
|
||||
segment = new VideoSegment;
|
||||
#endif
|
||||
|
|
|
@ -565,16 +565,18 @@ public:
|
|||
|
||||
void SetTrackEnabled(mozilla::TrackID aTrackID, bool aEnabled) {}
|
||||
|
||||
Fake_MediaStreamTrack*
|
||||
void AddTrackInternal(Fake_MediaStreamTrack* aTrack) {}
|
||||
|
||||
already_AddRefed<Fake_MediaStreamTrack>
|
||||
CreateDOMTrack(mozilla::TrackID aTrackID, mozilla::MediaSegment::Type aType,
|
||||
Fake_MediaStreamTrackSource* aSource)
|
||||
{
|
||||
switch(aType) {
|
||||
case mozilla::MediaSegment::AUDIO: {
|
||||
return mAudioTrack;
|
||||
return do_AddRef(mAudioTrack);
|
||||
}
|
||||
case mozilla::MediaSegment::VIDEO: {
|
||||
return mVideoTrack;
|
||||
return do_AddRef(mVideoTrack);
|
||||
}
|
||||
default: {
|
||||
MOZ_CRASH("Unkown media type");
|
||||
|
|
Загрузка…
Ссылка в новой задаче