From 80cde33d1248b77ceacc1260732edf5cdcf7e8b4 Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Fri, 23 Nov 2018 15:01:42 +0000 Subject: [PATCH] Bug 1423241 - Always add tracks at the stream's current time. r=padenot Differential Revision: https://phabricator.services.mozilla.com/D12271 --HG-- extra : moz-landing-system : lando --- dom/media/CanvasCaptureMediaStream.cpp | 2 +- dom/media/MediaStreamGraph.cpp | 23 ++++++++--------- dom/media/MediaStreamGraph.h | 25 ++++++++----------- dom/media/mediasink/DecodedStream.cpp | 4 +-- dom/media/webrtc/MediaEngineDefault.cpp | 4 +-- .../webrtc/MediaEngineRemoteVideoSource.cpp | 2 +- .../webrtc/MediaEngineTabVideoSource.cpp | 2 +- dom/media/webrtc/MediaEngineWebRTCAudio.cpp | 2 +- .../src/mediapipeline/MediaPipeline.cpp | 5 ++-- 9 files changed, 32 insertions(+), 37 deletions(-) diff --git a/dom/media/CanvasCaptureMediaStream.cpp b/dom/media/CanvasCaptureMediaStream.cpp index 500e2465b666..a37e60b3b7f3 100644 --- a/dom/media/CanvasCaptureMediaStream.cpp +++ b/dom/media/CanvasCaptureMediaStream.cpp @@ -113,7 +113,7 @@ OutputStreamDriver::OutputStreamDriver(SourceMediaStream* aSourceStream, new TrackListener(aTrackId, aPrincipalHandle, aSourceStream)) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(mSourceStream); - mSourceStream->AddTrack(aTrackId, 0, new VideoSegment()); + mSourceStream->AddTrack(aTrackId, new VideoSegment()); mSourceStream->AddTrackListener(mTrackListener, aTrackId); mSourceStream->AdvanceKnownTracksTime(STREAM_TIME_MAX); mSourceStream->SetPullEnabled(true); diff --git a/dom/media/MediaStreamGraph.cpp b/dom/media/MediaStreamGraph.cpp index af805522c413..c1cb33ae077e 100644 --- a/dom/media/MediaStreamGraph.cpp +++ b/dom/media/MediaStreamGraph.cpp @@ -1225,7 +1225,7 @@ void MediaStreamGraphImpl::UpdateGraph(GraphTime aEndBlockingDecisions) { for (MediaStream* stream : mStreams) { if (SourceMediaStream* is = stream->AsSourceStream()) { ensureNextIteration |= is->PullNewData(aEndBlockingDecisions); - is->ExtractPendingInput(); + is->ExtractPendingInput(mStateComputedTime); } if (stream->mFinished) { // The stream's not suspended, and since it's finished, underruns won't @@ -2635,7 +2635,7 @@ void SourceMediaStream::SetPullEnabled(bool aEnabled) { GraphImpl()->AppendMessage(MakeUnique(this, aEnabled)); } -bool SourceMediaStream::PullNewData(StreamTime aDesiredUpToTime) { +bool SourceMediaStream::PullNewData(GraphTime aDesiredUpToTime) { TRACE_AUDIO_CALLBACK_COMMENT("SourceMediaStream %p", this); MutexAutoLock lock(mMutex); if (!mPullEnabled || mFinished) { @@ -2677,11 +2677,12 @@ bool SourceMediaStream::PullNewData(StreamTime aDesiredUpToTime) { return true; } -void SourceMediaStream::ExtractPendingInput() { +void SourceMediaStream::ExtractPendingInput(GraphTime aCurrentTime) { MutexAutoLock lock(mMutex); bool finished = mFinishPending; bool shouldNotifyTrackCreated = false; + StreamTime streamCurrentTime = GraphTimeToStreamTime(aCurrentTime); for (int32_t i = mUpdateTracks.Length() - 1; i >= 0; --i) { SourceMediaStream::TrackData* data = &mUpdateTracks[i]; @@ -2692,7 +2693,7 @@ void SourceMediaStream::ExtractPendingInput() { // So it is not combined with the manipulating of aStream->mTracks part. StreamTime offset = (data->mCommands & SourceMediaStream::TRACK_CREATE) - ? data->mStart + ? streamCurrentTime : mTracks.FindTrack(data->mID)->GetSegment()->GetDuration(); // Audio case. @@ -2746,11 +2747,12 @@ void SourceMediaStream::ExtractPendingInput() { LOG(LogLevel::Debug, ("%p: SourceMediaStream %p creating track %d, start %" PRId64 ", initial end %" PRId64, - GraphImpl(), this, data->mID, int64_t(data->mStart), + GraphImpl(), this, data->mID, int64_t(streamCurrentTime), int64_t(segment->GetDuration()))); data->mEndOfFlushedData += segment->GetDuration(); - mTracks.AddTrack(data->mID, data->mStart, segment); + segment->InsertNullDataAtStart(streamCurrentTime); + mTracks.AddTrack(data->mID, streamCurrentTime, segment); // The track has taken ownership of data->mData, so let's replace // data->mData with an empty clone. data->mData = segment->CreateEmptyClone(); @@ -2790,7 +2792,6 @@ void SourceMediaStream::ExtractPendingInput() { } void SourceMediaStream::AddTrackInternal(TrackID aID, TrackRate aRate, - StreamTime aStart, MediaSegment* aSegment, uint32_t aFlags) { MutexAutoLock lock(mMutex); @@ -2803,8 +2804,7 @@ void SourceMediaStream::AddTrackInternal(TrackID aID, TrackRate aRate, data->mID = aID; data->mInputRate = aRate; data->mResamplerChannelCount = 0; - data->mStart = aStart; - data->mEndOfFlushedData = aStart; + data->mEndOfFlushedData = 0; data->mCommands = TRACK_CREATE; data->mData = aSegment; ResampleAudioToGraphSampleRate(data, aSegment); @@ -2814,9 +2814,8 @@ void SourceMediaStream::AddTrackInternal(TrackID aID, TrackRate aRate, } void SourceMediaStream::AddAudioTrack(TrackID aID, TrackRate aRate, - StreamTime aStart, AudioSegment* aSegment, - uint32_t aFlags) { - AddTrackInternal(aID, aRate, aStart, aSegment, aFlags); + AudioSegment* aSegment, uint32_t aFlags) { + AddTrackInternal(aID, aRate, aSegment, aFlags); } void SourceMediaStream::FinishAddTracks() { diff --git a/dom/media/MediaStreamGraph.h b/dom/media/MediaStreamGraph.h index f608eca80ca8..055b0f876cac 100644 --- a/dom/media/MediaStreamGraph.h +++ b/dom/media/MediaStreamGraph.h @@ -702,12 +702,12 @@ class SourceMediaStream : public MediaStream { * * Returns true if new data is about to be added. */ - bool PullNewData(StreamTime aDesiredUpToTime); + bool PullNewData(GraphTime aDesiredUpToTime); /** * Extract any state updates pending in the stream, and apply them. */ - void ExtractPendingInput(); + void ExtractPendingInput(GraphTime aCurrentTime); /** * These add/remove DirectListeners, which allow bypassing the graph and any @@ -721,21 +721,19 @@ class SourceMediaStream : public MediaStream { ADDTRACK_QUEUED = 0x01 // Queue track add until FinishAddTracks() }; /** - * Add a new track to the stream starting at the given base time (which - * must be greater than or equal to the last time passed to - * AdvanceKnownTracksTime). Takes ownership of aSegment. aSegment should - * contain data starting after aStart. + * Add a new track to the stream starting at the stream's current time + * (which must be greater than or equal to the last time passed to + * AdvanceKnownTracksTime). Takes ownership of aSegment. */ - void AddTrack(TrackID aID, StreamTime aStart, MediaSegment* aSegment, - uint32_t aFlags = 0) { - AddTrackInternal(aID, GraphRate(), aStart, aSegment, aFlags); + void AddTrack(TrackID aID, MediaSegment* aSegment, uint32_t aFlags = 0) { + AddTrackInternal(aID, GraphRate(), aSegment, aFlags); } /** * Like AddTrack, but resamples audio from aRate to the graph rate. */ - void AddAudioTrack(TrackID aID, TrackRate aRate, StreamTime aStart, - AudioSegment* aSegment, uint32_t aFlags = 0); + void AddAudioTrack(TrackID aID, TrackRate aRate, AudioSegment* aSegment, + uint32_t aFlags = 0); /** * Call after a series of AddTrack or AddAudioTrack calls to implement @@ -832,7 +830,6 @@ class SourceMediaStream : public MediaStream { // MediaStreamGraph's. nsAutoRef mResampler; int mResamplerChannelCount; - StreamTime mStart; // End-time of data already flushed to the track (excluding mData) StreamTime mEndOfFlushedData; // Each time the track updates are flushed to the media graph thread, @@ -854,8 +851,8 @@ class SourceMediaStream : public MediaStream { void RemoveDirectTrackListenerImpl(DirectMediaStreamTrackListener* aListener, TrackID aTrackID) override; - void AddTrackInternal(TrackID aID, TrackRate aRate, StreamTime aStart, - MediaSegment* aSegment, uint32_t aFlags); + void AddTrackInternal(TrackID aID, TrackRate aRate, MediaSegment* aSegment, + uint32_t aFlags); TrackData* FindDataForTrack(TrackID aID) { mMutex.AssertCurrentThreadOwns(); diff --git a/dom/media/mediasink/DecodedStream.cpp b/dom/media/mediasink/DecodedStream.cpp index 613fca80be79..98256cf5bbcf 100644 --- a/dom/media/mediasink/DecodedStream.cpp +++ b/dom/media/mediasink/DecodedStream.cpp @@ -192,12 +192,12 @@ DecodedStreamData::DecodedStreamData( // Initialize tracks. if (aInit.mInfo.HasAudio()) { audioTrack = aInit.mInfo.mAudio.mTrackId; - mStream->AddAudioTrack(audioTrack, aInit.mInfo.mAudio.mRate, 0, + mStream->AddAudioTrack(audioTrack, aInit.mInfo.mAudio.mRate, new AudioSegment()); } if (aInit.mInfo.HasVideo()) { videoTrack = aInit.mInfo.mVideo.mTrackId; - mStream->AddTrack(videoTrack, 0, new VideoSegment()); + mStream->AddTrack(videoTrack, new VideoSegment()); } mOutputStreamManager->Connect(mStream, audioTrack, videoTrack); diff --git a/dom/media/webrtc/MediaEngineDefault.cpp b/dom/media/webrtc/MediaEngineDefault.cpp index 2292075c43c7..2dceae765bf1 100644 --- a/dom/media/webrtc/MediaEngineDefault.cpp +++ b/dom/media/webrtc/MediaEngineDefault.cpp @@ -175,7 +175,7 @@ nsresult MediaEngineDefaultVideoSource::SetTrack( mStream = aStream; mTrackID = aTrackID; } - aStream->AddTrack(aTrackID, 0, new VideoSegment(), + aStream->AddTrack(aTrackID, new VideoSegment(), SourceMediaStream::ADDTRACK_QUEUED); return NS_OK; } @@ -437,7 +437,7 @@ nsresult MediaEngineDefaultAudioSource::SetTrack( // AddAudioTrack will take ownership of segment mStream = aStream; mTrackID = aTrackID; - aStream->AddAudioTrack(aTrackID, aStream->GraphRate(), 0, new AudioSegment(), + aStream->AddAudioTrack(aTrackID, aStream->GraphRate(), new AudioSegment(), SourceMediaStream::ADDTRACK_QUEUED); return NS_OK; } diff --git a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp index a74b41d32b7f..444a939c705e 100644 --- a/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp +++ b/dom/media/webrtc/MediaEngineRemoteVideoSource.cpp @@ -264,7 +264,7 @@ nsresult MediaEngineRemoteVideoSource::SetTrack( mTrackID = aTrackID; mPrincipal = aPrincipal; } - aStream->AddTrack(aTrackID, 0, new VideoSegment(), + aStream->AddTrack(aTrackID, new VideoSegment(), SourceMediaStream::ADDTRACK_QUEUED); return NS_OK; } diff --git a/dom/media/webrtc/MediaEngineTabVideoSource.cpp b/dom/media/webrtc/MediaEngineTabVideoSource.cpp index 9deab342a7f2..ff6dc0e67d31 100644 --- a/dom/media/webrtc/MediaEngineTabVideoSource.cpp +++ b/dom/media/webrtc/MediaEngineTabVideoSource.cpp @@ -206,7 +206,7 @@ nsresult MediaEngineTabVideoSource::SetTrack( MOZ_ASSERT(IsTrackIDExplicit(aTrackID)); mStream = aStream; mTrackID = aTrackID; - mStream->AddTrack(mTrackID, 0, new VideoSegment()); + mStream->AddTrack(mTrackID, new VideoSegment()); return NS_OK; } diff --git a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp index da99648d3c04..0251b017991a 100644 --- a/dom/media/webrtc/MediaEngineWebRTCAudio.cpp +++ b/dom/media/webrtc/MediaEngineWebRTCAudio.cpp @@ -527,7 +527,7 @@ nsresult MediaEngineWebRTCMicrophoneSource::SetTrack( AudioSegment* segment = new AudioSegment(); - aStream->AddAudioTrack(aTrackID, aStream->GraphRate(), 0, segment, + aStream->AddAudioTrack(aTrackID, aStream->GraphRate(), segment, SourceMediaStream::ADDTRACK_QUEUED); LOG(("Stream %p registered for microphone capture", aStream.get())); diff --git a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp index 93657d7a13ea..76b096a565c6 100644 --- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp +++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp @@ -1670,10 +1670,9 @@ public: mTrack->AsVideoStreamTrack()); if (mTrack->AsAudioStreamTrack()) { - mSource->AddAudioTrack( - mTrackId, aRate, 0, new AudioSegment()); + mSource->AddAudioTrack(mTrackId, aRate, new AudioSegment()); } else if (mTrack->AsVideoStreamTrack()) { - mSource->AddTrack(mTrackId, 0, new VideoSegment()); + mSource->AddTrack(mTrackId, new VideoSegment()); } MOZ_LOG(gMediaPipelineLog, LogLevel::Debug, ("GenericReceiveListener added %s track %d (%p) to stream %p",