From 241af1cdbcb58c545c278a523c271bf405d1259c Mon Sep 17 00:00:00 2001 From: Karl Tomlinson Date: Fri, 27 Oct 2023 07:52:45 +0000 Subject: [PATCH] Bug 1860954 add a conversion operator from MediaTrackGraphImpl to Lookup for HashSet.lookup(*graph) r=pehrsons Differential Revision: https://phabricator.services.mozilla.com/D191920 --- dom/media/MediaTrackGraph.cpp | 18 +++++++++++------- dom/media/MediaTrackGraphImpl.h | 3 +++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/dom/media/MediaTrackGraph.cpp b/dom/media/MediaTrackGraph.cpp index f82f866d0a4a..e4f1a89aa87e 100644 --- a/dom/media/MediaTrackGraph.cpp +++ b/dom/media/MediaTrackGraph.cpp @@ -117,12 +117,12 @@ void DeviceInputTrackManager::Remove(DeviceInputTrack* aTrack) { } } -namespace { /** * A hash table containing the graph instances, one per Window ID, * sample rate, and device ID combination. */ -struct GraphLookup final { + +struct MediaTrackGraphImpl::Lookup final { HashNumber Hash() const { return HashGeneric(mWindowID, mSampleRate, mOutputDeviceID); } @@ -131,8 +131,14 @@ struct GraphLookup final { const CubebUtils::AudioDeviceID mOutputDeviceID; }; +// Implicit to support GraphHashSet.lookup(*graph). +MOZ_IMPLICIT MediaTrackGraphImpl::operator MediaTrackGraphImpl::Lookup() const { + return {mWindowID, mSampleRate, mOutputDeviceID}; +} + +namespace { struct GraphHasher { // for HashSet - using Lookup = const GraphLookup; + using Lookup = const MediaTrackGraphImpl::Lookup; static HashNumber hash(const Lookup& aLookup) { return aLookup.Hash(); } @@ -3600,8 +3606,7 @@ void MediaTrackGraph::AddTrack(MediaTrack* aTrack) { MediaTrackGraphImpl* graph = static_cast(this); #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED if (graph->mRealtime) { - GraphHashSet::Ptr p = Graphs()->lookup( - {graph->mWindowID, GraphRate(), graph->mOutputDeviceID}); + GraphHashSet::Ptr p = Graphs()->lookup(*graph); MOZ_DIAGNOSTIC_ASSERT(p, "Graph must not be shutting down"); } #endif @@ -3621,8 +3626,7 @@ void MediaTrackGraphImpl::RemoveTrack(MediaTrack* aTrack) { if (mRealtime) { // Find the graph in the hash table and remove it. GraphHashSet* graphs = Graphs(); - GraphHashSet::Ptr p = - graphs->lookup({mWindowID, mSampleRate, mOutputDeviceID}); + GraphHashSet::Ptr p = graphs->lookup(*this); MOZ_ASSERT(*p == this); graphs->remove(p); diff --git a/dom/media/MediaTrackGraphImpl.h b/dom/media/MediaTrackGraphImpl.h index a28171310866..668fcaea3176 100644 --- a/dom/media/MediaTrackGraphImpl.h +++ b/dom/media/MediaTrackGraphImpl.h @@ -142,6 +142,9 @@ class MediaTrackGraphImpl : public MediaTrackGraph, static MediaTrackGraphImpl* GetInstanceIfExists( uint64_t aWindowID, TrackRate aSampleRate, CubebUtils::AudioDeviceID aOutputDeviceID); + // For GraphHashSet: + struct Lookup; + operator Lookup() const; // Intended only for assertions, either on graph thread or not running (in // which case we must be on the main thread).