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
This commit is contained in:
Andreas Pehrson 2018-11-23 15:01:42 +00:00
Родитель 43f4e58733
Коммит 80cde33d12
9 изменённых файлов: 32 добавлений и 37 удалений

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

@ -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);

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

@ -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<Message>(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() {

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

@ -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<SpeexResamplerState> 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();

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

@ -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);

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

@ -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;
}

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

@ -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;
}

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

@ -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;
}

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

@ -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()));

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

@ -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",