From 4268d5984046ed1488bda0e5c0682fd988435168 Mon Sep 17 00:00:00 2001 From: Karl Tomlinson Date: Fri, 30 Sep 2022 04:13:33 +0000 Subject: [PATCH] Bug 1786306 assert that there is no more than one output for each key on a track r=padenot SetAudioOutputVolume() assumes this. Depends on D158304 Differential Revision: https://phabricator.services.mozilla.com/D158305 --- dom/media/MediaTrackGraph.cpp | 6 ++---- dom/media/MediaTrackGraphImpl.h | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/dom/media/MediaTrackGraph.cpp b/dom/media/MediaTrackGraph.cpp index fae5047ee2fd..a7039b36cb06 100644 --- a/dom/media/MediaTrackGraph.cpp +++ b/dom/media/MediaTrackGraph.cpp @@ -825,6 +825,7 @@ void MediaTrackGraphImpl::CloseAudioInputImpl(DeviceInputTrack* aTrack) { void MediaTrackGraphImpl::RegisterAudioOutput(MediaTrack* aTrack, void* aKey) { MOZ_ASSERT(OnGraphThread()); + MOZ_ASSERT(!mAudioOutputs.Contains(TrackAndKey{aTrack, aKey})); TrackKeyAndVolume* tkv = mAudioOutputs.AppendElement(); tkv->mTrack = aTrack; @@ -861,10 +862,7 @@ void MediaTrackGraphImpl::UnregisterAudioOutput(MediaTrack* aTrack, void* aKey) { MOZ_ASSERT(OnGraphThreadOrNotRunning()); - mAudioOutputs.RemoveElementsBy( - [&aKey, &aTrack](const TrackKeyAndVolume& aTkv) { - return aTkv.mKey == aKey && aTkv.mTrack == aTrack; - }); + mAudioOutputs.RemoveElement(TrackAndKey{aTrack, aKey}); } void MediaTrackGraphImpl::CloseAudioInput(DeviceInputTrack* aTrack) { diff --git a/dom/media/MediaTrackGraphImpl.h b/dom/media/MediaTrackGraphImpl.h index 33a877c71688..643d7bea1289 100644 --- a/dom/media/MediaTrackGraphImpl.h +++ b/dom/media/MediaTrackGraphImpl.h @@ -414,6 +414,10 @@ class MediaTrackGraphImpl : public MediaTrackGraph, * Queue audio (mix of track audio and silence for blocked intervals) * to the audio output track. Returns the number of frames played. */ + struct TrackAndKey { + MediaTrack* mTrack; + void* mKey; + }; struct TrackKeyAndVolume { MediaTrack* mTrack; void* mKey; @@ -1046,4 +1050,16 @@ class MediaTrackGraphImpl : public MediaTrackGraph, } // namespace mozilla +template <> +class nsDefaultComparator { + public: + bool Equals( + const mozilla::MediaTrackGraphImpl::TrackKeyAndVolume& aElement, + const mozilla::MediaTrackGraphImpl::TrackAndKey& aTrackAndKey) const { + return aElement.mTrack == aTrackAndKey.mTrack && + aElement.mKey == aTrackAndKey.mKey; + } +}; + #endif /* MEDIATRACKGRAPHIMPL_H_ */