diff --git a/pc/BUILD.gn b/pc/BUILD.gn index 866f213e2b..db9fb5fad7 100644 --- a/pc/BUILD.gn +++ b/pc/BUILD.gn @@ -1340,6 +1340,7 @@ rtc_source_set("track_media_info_map") { deps = [ ":rtp_receiver", ":rtp_sender", + "../api:array_view", "../api:media_stream_interface", "../api:rtp_parameters", "../api:scoped_refptr", diff --git a/pc/track_media_info_map.cc b/pc/track_media_info_map.cc index 914bb5b5cc..c5d2daa9a6 100644 --- a/pc/track_media_info_map.cc +++ b/pc/track_media_info_map.cc @@ -38,8 +38,8 @@ const V* FindAddressOrNull(const std::map& map, const K& key) { } void GetAudioAndVideoTrackBySsrc( - const std::vector>& rtp_senders, - const std::vector>& rtp_receivers, + rtc::ArrayView> rtp_senders, + rtc::ArrayView> rtp_receivers, std::map* local_audio_track_by_ssrc, std::map* local_video_track_by_ssrc, std::map* remote_audio_track_by_ssrc, @@ -109,8 +109,8 @@ TrackMediaInfoMap::TrackMediaInfoMap() = default; void TrackMediaInfoMap::Initialize( absl::optional voice_media_info, absl::optional video_media_info, - const std::vector>& rtp_senders, - const std::vector>& rtp_receivers) { + rtc::ArrayView> rtp_senders, + rtc::ArrayView> rtp_receivers) { rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; RTC_DCHECK(!is_initialized_); is_initialized_ = true; diff --git a/pc/track_media_info_map.h b/pc/track_media_info_map.h index b0d9e16588..5a24aaad2b 100644 --- a/pc/track_media_info_map.h +++ b/pc/track_media_info_map.h @@ -19,6 +19,7 @@ #include #include "absl/types/optional.h" +#include "api/array_view.h" #include "api/media_stream_interface.h" #include "api/scoped_refptr.h" #include "media/base/media_channel.h" @@ -50,12 +51,14 @@ class TrackMediaInfoMap { public: TrackMediaInfoMap(); + // Takes ownership of the "infos". Does not affect the lifetime of the senders + // or receivers, but TrackMediaInfoMap will keep their associated tracks alive + // through reference counting until the map is destroyed. void Initialize( absl::optional voice_media_info, absl::optional video_media_info, - const std::vector>& rtp_senders, - const std::vector>& - rtp_receivers); + rtc::ArrayView> rtp_senders, + rtc::ArrayView> rtp_receivers); const absl::optional& voice_media_info() const { RTC_DCHECK(is_initialized_); @@ -104,6 +107,8 @@ class TrackMediaInfoMap { absl::optional video_media_info_; // These maps map tracks (identified by a pointer) to their corresponding info // object of the correct kind. One track can map to multiple info objects. + // Known tracks are guaranteed to be alive because they are also stored as + // entries in the reverse maps below. std::map> voice_infos_by_local_track_; std::map @@ -114,7 +119,8 @@ class TrackMediaInfoMap { video_info_by_remote_track_; // These maps map info objects to their corresponding tracks. They are always // the inverse of the maps above. One info object always maps to only one - // track. + // track. The use of scoped_refptr<> here ensures the tracks outlive + // TrackMediaInfoMap. std::map> audio_track_by_sender_info_;