From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- third_party/libwebrtc/pc/track_media_info_map.h | 151 ++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 third_party/libwebrtc/pc/track_media_info_map.h (limited to 'third_party/libwebrtc/pc/track_media_info_map.h') diff --git a/third_party/libwebrtc/pc/track_media_info_map.h b/third_party/libwebrtc/pc/track_media_info_map.h new file mode 100644 index 0000000000..5a24aaad2b --- /dev/null +++ b/third_party/libwebrtc/pc/track_media_info_map.h @@ -0,0 +1,151 @@ +/* + * Copyright 2016 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef PC_TRACK_MEDIA_INFO_MAP_H_ +#define PC_TRACK_MEDIA_INFO_MAP_H_ + +#include + +#include +#include +#include +#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" +#include "pc/rtp_receiver.h" +#include "pc/rtp_sender.h" +#include "rtc_base/ref_count.h" + +namespace webrtc { + +// Audio/video tracks and sender/receiver statistical information are associated +// with each other based on attachments to RTP senders/receivers. This class +// maps that relationship, in both directions, so that stats about a track can +// be retrieved on a per-attachment basis. +// +// An RTP sender/receiver sends or receives media for a set of SSRCs. The media +// comes from an audio/video track that is attached to it. +// |[Voice/Video][Sender/Receiver]Info| has statistical information for a set of +// SSRCs. Looking at the RTP senders and receivers uncovers the track <-> info +// relationships, which this class does. +// +// In the spec, "track" attachment stats have been made obsolete, and in Unified +// Plan there is just one sender and one receiver per transceiver, so we may be +// able to simplify/delete this class. +// TODO(https://crbug.com/webrtc/14175): Simplify or delete this class when +// "track" stats have been deleted. +// TODO(https://crbug.com/webrtc/13528): Simplify or delete this class when +// Plan B is gone from the native library (already gone for Chrome). +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, + rtc::ArrayView> rtp_senders, + rtc::ArrayView> rtp_receivers); + + const absl::optional& voice_media_info() const { + RTC_DCHECK(is_initialized_); + return voice_media_info_; + } + const absl::optional& video_media_info() const { + RTC_DCHECK(is_initialized_); + return video_media_info_; + } + + const std::vector* GetVoiceSenderInfos( + const AudioTrackInterface& local_audio_track) const; + const cricket::VoiceReceiverInfo* GetVoiceReceiverInfo( + const AudioTrackInterface& remote_audio_track) const; + const std::vector* GetVideoSenderInfos( + const VideoTrackInterface& local_video_track) const; + const cricket::VideoReceiverInfo* GetVideoReceiverInfo( + const VideoTrackInterface& remote_video_track) const; + + const cricket::VoiceSenderInfo* GetVoiceSenderInfoBySsrc(uint32_t ssrc) const; + const cricket::VoiceReceiverInfo* GetVoiceReceiverInfoBySsrc( + uint32_t ssrc) const; + const cricket::VideoSenderInfo* GetVideoSenderInfoBySsrc(uint32_t ssrc) const; + const cricket::VideoReceiverInfo* GetVideoReceiverInfoBySsrc( + uint32_t ssrc) const; + + rtc::scoped_refptr GetAudioTrack( + const cricket::VoiceSenderInfo& voice_sender_info) const; + rtc::scoped_refptr GetAudioTrack( + const cricket::VoiceReceiverInfo& voice_receiver_info) const; + rtc::scoped_refptr GetVideoTrack( + const cricket::VideoSenderInfo& video_sender_info) const; + rtc::scoped_refptr GetVideoTrack( + const cricket::VideoReceiverInfo& video_receiver_info) const; + + // TODO(hta): Remove this function, and redesign the callers not to need it. + // It is not going to work if a track is attached multiple times, and + // it is not going to work if a received track is attached as a sending + // track (loopback). + absl::optional GetAttachmentIdByTrack( + const MediaStreamTrackInterface* track) const; + + private: + bool is_initialized_ = false; + absl::optional voice_media_info_; + 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 + voice_info_by_remote_track_; + std::map> + video_infos_by_local_track_; + std::map + 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. The use of scoped_refptr<> here ensures the tracks outlive + // TrackMediaInfoMap. + std::map> + audio_track_by_sender_info_; + std::map> + audio_track_by_receiver_info_; + std::map> + video_track_by_sender_info_; + std::map> + video_track_by_receiver_info_; + // Map of tracks to attachment IDs. + // Necessary because senders and receivers live on the signaling thread, + // but the attachment IDs are needed while building stats on the networking + // thread, so we can't look them up in the senders/receivers without + // thread jumping. + std::map attachment_id_by_track_; + // These maps map SSRCs to the corresponding voice or video info objects. + std::map voice_info_by_sender_ssrc_; + std::map voice_info_by_receiver_ssrc_; + std::map video_info_by_sender_ssrc_; + std::map video_info_by_receiver_ssrc_; +}; + +} // namespace webrtc + +#endif // PC_TRACK_MEDIA_INFO_MAP_H_ -- cgit v1.2.3