diff options
author | Moonchild <moonchild@palemoon.org> | 2023-10-08 09:21:07 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2023-10-08 09:21:07 +0000 |
commit | e0746ccf3174d198b356d747c9bdeae86f29a306 (patch) | |
tree | 42201fd92f837381fb826b7e1de8c02806b2e247 /dom | |
parent | 78120a7693dfa33fa2a10ceff44923c2ee3c7150 (diff) | |
parent | ecc90c09ef4cfdf8a45d5ec17f0069120488e4e9 (diff) | |
download | uxp-e0746ccf3174d198b356d747c9bdeae86f29a306.tar.gz |
Merge pull request 'Issue #2332 - Do some cleaning around direct listeners and video sinks' (#2335) from Basilisk-Dev/UXP-contrib:master into master
Reviewed-on: https://repo.palemoon.org/MoonchildProductions/UXP/pulls/2335
Diffstat (limited to 'dom')
-rw-r--r-- | dom/media/MediaStreamGraph.cpp | 67 |
1 files changed, 29 insertions, 38 deletions
diff --git a/dom/media/MediaStreamGraph.cpp b/dom/media/MediaStreamGraph.cpp index db5fa8fa39..355261525c 100644 --- a/dom/media/MediaStreamGraph.cpp +++ b/dom/media/MediaStreamGraph.cpp @@ -2869,8 +2869,8 @@ SourceMediaStream::AddDirectTrackListenerImpl(already_AddRefed<DirectMediaStream TrackID aTrackID) { MOZ_ASSERT(IsTrackIDExplicit(aTrackID)); - TrackData* data; - bool found = false; + TrackData* updateData = nullptr; + StreamTracks::Track* track = nullptr; bool isAudio = false; bool isVideo = false; RefPtr<DirectMediaStreamTrackListener> listener = aListener; @@ -2879,44 +2879,29 @@ SourceMediaStream::AddDirectTrackListenerImpl(already_AddRefed<DirectMediaStream { MutexAutoLock lock(mMutex); - data = FindDataForTrack(aTrackID); - found = !!data; - if (found) { - isAudio = data->mData->GetType() == MediaSegment::AUDIO; - isVideo = data->mData->GetType() == MediaSegment::VIDEO; - } - - // The track might be removed from mUpdateTrack but still exist in - // mTracks. - auto streamTrack = FindTrack(aTrackID); - bool foundTrack = !!streamTrack; - if (foundTrack) { - MediaStreamVideoSink* videoSink = listener->AsMediaStreamVideoSink(); + updateData = FindDataForTrack(aTrackID); + track = FindTrack(aTrackID); + if (track) { + isAudio = track->GetType() == MediaSegment::AUDIO; + isVideo = track->GetType() == MediaSegment::VIDEO; + } + + if (track && isVideo && listener->AsMediaStreamVideoSink()) { // Re-send missed VideoSegment to new added MediaStreamVideoSink. - if (streamTrack->GetType() == MediaSegment::VIDEO && videoSink) { - VideoSegment videoSegment; - if (mTracks.GetForgottenDuration() < streamTrack->GetSegment()->GetDuration()) { - videoSegment.AppendSlice(*streamTrack->GetSegment(), - mTracks.GetForgottenDuration(), - streamTrack->GetSegment()->GetDuration()); - } else { - VideoSegment* streamTrackSegment = static_cast<VideoSegment*>(streamTrack->GetSegment()); - VideoChunk* lastChunk = streamTrackSegment->GetLastChunk(); - if (lastChunk) { - StreamTime startTime = streamTrackSegment->GetDuration() - lastChunk->GetDuration(); - videoSegment.AppendSlice(*streamTrackSegment, - startTime, - streamTrackSegment->GetDuration()); - } - } - if (found) { - videoSegment.AppendSlice(*data->mData, 0, data->mData->GetDuration()); - } - videoSink->SetCurrentFrames(videoSegment); + VideoSegment* trackSegment = static_cast<VideoSegment*>(track->GetSegment()); + VideoSegment videoSegment; + if (mTracks.GetForgottenDuration() < trackSegment->GetDuration()) { + videoSegment.AppendSlice(*trackSegment, + mTracks.GetForgottenDuration(), + trackSegment->GetDuration()); + } + if (updateData) { + videoSegment.AppendSlice(*updateData->mData, 0, updateData->mData->GetDuration()); } + listener->NotifyRealtimeTrackData(Graph(), 0, videoSegment); } - if (found && (isAudio || isVideo)) { + if (track && (isAudio || isVideo)) { for (auto entry : mDirectTrackListeners) { if (entry.mListener == listener && (entry.mTrackID == TRACK_ANY || entry.mTrackID == aTrackID)) { @@ -2932,7 +2917,7 @@ SourceMediaStream::AddDirectTrackListenerImpl(already_AddRefed<DirectMediaStream sourceListener->mTrackID = aTrackID; } } - if (!found) { + if (!track) { STREAM_LOG(LogLevel::Warning, ("Couldn't find source track for direct track listener %p", listener.get())); listener->NotifyDirectListenerInstalled( @@ -2946,9 +2931,15 @@ SourceMediaStream::AddDirectTrackListenerImpl(already_AddRefed<DirectMediaStream MOZ_ASSERT(true); return; } - STREAM_LOG(LogLevel::Debug, ("Added direct track listener %p", listener.get())); + STREAM_LOG(LogLevel::Debug, ("Added direct track listener %p. ended=%d", + listener.get(), !updateData)); listener->NotifyDirectListenerInstalled( DirectMediaStreamTrackListener::InstallationResult::SUCCESS); + if (!updateData) { + // The track exists but the mUpdateTracks entry was removed. + // This means that the track has ended. + listener->NotifyEnded(); + } } void |