hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #include "pc/track_media_info_map.h" |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 12 | |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 13 | #include <stddef.h> |
| 14 | |
| 15 | #include <cstdint> |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 16 | #include <initializer_list> |
Steve Anton | 5dfde18 | 2018-02-06 18:34:40 | [diff] [blame] | 17 | #include <string> |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 18 | #include <type_traits> |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 19 | #include <utility> |
| 20 | #include <vector> |
| 21 | |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 22 | #include "api/media_types.h" |
| 23 | #include "api/rtp_parameters.h" |
Florent Castelli | 63cc46c | 2021-07-16 23:32:40 | [diff] [blame] | 24 | #include "api/test/mock_video_track.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 25 | #include "media/base/media_channel.h" |
| 26 | #include "pc/audio_track.h" |
| 27 | #include "pc/test/fake_video_track_source.h" |
| 28 | #include "pc/test/mock_rtp_receiver_internal.h" |
| 29 | #include "pc/test/mock_rtp_sender_internal.h" |
| 30 | #include "pc/video_track.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 31 | #include "rtc_base/checks.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 32 | #include "rtc_base/thread.h" |
| 33 | #include "test/gmock.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 34 | #include "test/gtest.h" |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 35 | |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 36 | using ::testing::ElementsAre; |
| 37 | |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 38 | namespace webrtc { |
| 39 | |
| 40 | namespace { |
| 41 | |
| 42 | RtpParameters CreateRtpParametersWithSsrcs( |
| 43 | std::initializer_list<uint32_t> ssrcs) { |
| 44 | RtpParameters params; |
| 45 | for (uint32_t ssrc : ssrcs) { |
| 46 | RtpEncodingParameters encoding_params; |
Oskar Sundbom | 36f8f3e | 2017-11-16 09:54:27 | [diff] [blame] | 47 | encoding_params.ssrc = ssrc; |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 48 | params.encodings.push_back(encoding_params); |
| 49 | } |
| 50 | return params; |
| 51 | } |
| 52 | |
Steve Anton | 57858b3 | 2018-02-15 23:19:50 | [diff] [blame] | 53 | rtc::scoped_refptr<MockRtpSenderInternal> CreateMockRtpSender( |
deadbeef | 804c1af | 2017-02-12 03:07:31 | [diff] [blame] | 54 | cricket::MediaType media_type, |
| 55 | std::initializer_list<uint32_t> ssrcs, |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 56 | rtc::scoped_refptr<MediaStreamTrackInterface> track) { |
| 57 | uint32_t first_ssrc; |
| 58 | if (ssrcs.size()) { |
| 59 | first_ssrc = *ssrcs.begin(); |
| 60 | } else { |
| 61 | first_ssrc = 0; |
| 62 | } |
Tommi | 87f7090 | 2021-04-27 12:43:08 | [diff] [blame] | 63 | auto sender = rtc::make_ref_counted<MockRtpSenderInternal>(); |
Mirko Bonadei | c61ce0d | 2017-11-21 16:04:20 | [diff] [blame] | 64 | EXPECT_CALL(*sender, track()) |
Mirko Bonadei | 6a489f2 | 2019-04-09 13:11:12 | [diff] [blame] | 65 | .WillRepeatedly(::testing::Return(std::move(track))); |
| 66 | EXPECT_CALL(*sender, ssrc()).WillRepeatedly(::testing::Return(first_ssrc)); |
deadbeef | 804c1af | 2017-02-12 03:07:31 | [diff] [blame] | 67 | EXPECT_CALL(*sender, media_type()) |
Mirko Bonadei | 6a489f2 | 2019-04-09 13:11:12 | [diff] [blame] | 68 | .WillRepeatedly(::testing::Return(media_type)); |
deadbeef | 804c1af | 2017-02-12 03:07:31 | [diff] [blame] | 69 | EXPECT_CALL(*sender, GetParameters()) |
Mirko Bonadei | 6a489f2 | 2019-04-09 13:11:12 | [diff] [blame] | 70 | .WillRepeatedly(::testing::Return(CreateRtpParametersWithSsrcs(ssrcs))); |
| 71 | EXPECT_CALL(*sender, AttachmentId()).WillRepeatedly(::testing::Return(1)); |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 72 | return sender; |
| 73 | } |
| 74 | |
Steve Anton | 57858b3 | 2018-02-15 23:19:50 | [diff] [blame] | 75 | rtc::scoped_refptr<MockRtpReceiverInternal> CreateMockRtpReceiver( |
deadbeef | 804c1af | 2017-02-12 03:07:31 | [diff] [blame] | 76 | cricket::MediaType media_type, |
| 77 | std::initializer_list<uint32_t> ssrcs, |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 78 | rtc::scoped_refptr<MediaStreamTrackInterface> track) { |
Tommi | 87f7090 | 2021-04-27 12:43:08 | [diff] [blame] | 79 | auto receiver = rtc::make_ref_counted<MockRtpReceiverInternal>(); |
Mirko Bonadei | c61ce0d | 2017-11-21 16:04:20 | [diff] [blame] | 80 | EXPECT_CALL(*receiver, track()) |
Mirko Bonadei | 6a489f2 | 2019-04-09 13:11:12 | [diff] [blame] | 81 | .WillRepeatedly(::testing::Return(std::move(track))); |
deadbeef | 804c1af | 2017-02-12 03:07:31 | [diff] [blame] | 82 | EXPECT_CALL(*receiver, media_type()) |
Mirko Bonadei | 6a489f2 | 2019-04-09 13:11:12 | [diff] [blame] | 83 | .WillRepeatedly(::testing::Return(media_type)); |
deadbeef | 804c1af | 2017-02-12 03:07:31 | [diff] [blame] | 84 | EXPECT_CALL(*receiver, GetParameters()) |
Mirko Bonadei | 6a489f2 | 2019-04-09 13:11:12 | [diff] [blame] | 85 | .WillRepeatedly(::testing::Return(CreateRtpParametersWithSsrcs(ssrcs))); |
| 86 | EXPECT_CALL(*receiver, AttachmentId()).WillRepeatedly(::testing::Return(1)); |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 87 | return receiver; |
| 88 | } |
| 89 | |
Tommi | 816134a | 2021-05-24 14:54:41 | [diff] [blame] | 90 | rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack( |
| 91 | const std::string& id) { |
| 92 | return VideoTrack::Create(id, FakeVideoTrackSource::Create(false), |
| 93 | rtc::Thread::Current()); |
| 94 | } |
| 95 | |
| 96 | rtc::scoped_refptr<VideoTrackInterface> CreateMockVideoTrack( |
| 97 | const std::string& id) { |
Florent Castelli | 63cc46c | 2021-07-16 23:32:40 | [diff] [blame] | 98 | auto track = MockVideoTrack::Create(); |
Tommi | 816134a | 2021-05-24 14:54:41 | [diff] [blame] | 99 | EXPECT_CALL(*track, kind()) |
| 100 | .WillRepeatedly(::testing::Return(VideoTrack::kVideoKind)); |
| 101 | return track; |
| 102 | } |
| 103 | |
Mirko Bonadei | 6a489f2 | 2019-04-09 13:11:12 | [diff] [blame] | 104 | class TrackMediaInfoMapTest : public ::testing::Test { |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 105 | public: |
Tommi | ec3ba73 | 2020-05-17 12:33:40 | [diff] [blame] | 106 | TrackMediaInfoMapTest() : TrackMediaInfoMapTest(true) {} |
| 107 | |
Tommi | 816134a | 2021-05-24 14:54:41 | [diff] [blame] | 108 | explicit TrackMediaInfoMapTest(bool use_real_video_track) |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 109 | : local_audio_track_(AudioTrack::Create("LocalAudioTrack", nullptr)), |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 110 | remote_audio_track_(AudioTrack::Create("RemoteAudioTrack", nullptr)), |
Tommi | 816134a | 2021-05-24 14:54:41 | [diff] [blame] | 111 | local_video_track_(use_real_video_track |
| 112 | ? CreateVideoTrack("LocalVideoTrack") |
| 113 | : CreateMockVideoTrack("LocalVideoTrack")), |
| 114 | remote_video_track_(use_real_video_track |
| 115 | ? CreateVideoTrack("RemoteVideoTrack") |
| 116 | : CreateMockVideoTrack("LocalVideoTrack")) {} |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 117 | |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 118 | void AddRtpSenderWithSsrcs(std::initializer_list<uint32_t> ssrcs, |
| 119 | MediaStreamTrackInterface* local_track) { |
Steve Anton | 57858b3 | 2018-02-15 23:19:50 | [diff] [blame] | 120 | rtc::scoped_refptr<MockRtpSenderInternal> rtp_sender = CreateMockRtpSender( |
deadbeef | 804c1af | 2017-02-12 03:07:31 | [diff] [blame] | 121 | local_track->kind() == MediaStreamTrackInterface::kAudioKind |
| 122 | ? cricket::MEDIA_TYPE_AUDIO |
| 123 | : cricket::MEDIA_TYPE_VIDEO, |
Niels Möller | e7cc883 | 2022-01-04 14:20:03 | [diff] [blame] | 124 | ssrcs, rtc::scoped_refptr<MediaStreamTrackInterface>(local_track)); |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 125 | rtp_senders_.push_back(rtp_sender); |
| 126 | |
| 127 | if (local_track->kind() == MediaStreamTrackInterface::kAudioKind) { |
| 128 | cricket::VoiceSenderInfo voice_sender_info; |
| 129 | size_t i = 0; |
| 130 | for (uint32_t ssrc : ssrcs) { |
| 131 | voice_sender_info.local_stats.push_back(cricket::SsrcSenderInfo()); |
| 132 | voice_sender_info.local_stats[i++].ssrc = ssrc; |
| 133 | } |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 134 | voice_media_info_.senders.push_back(voice_sender_info); |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 135 | } else { |
| 136 | cricket::VideoSenderInfo video_sender_info; |
| 137 | size_t i = 0; |
| 138 | for (uint32_t ssrc : ssrcs) { |
| 139 | video_sender_info.local_stats.push_back(cricket::SsrcSenderInfo()); |
| 140 | video_sender_info.local_stats[i++].ssrc = ssrc; |
| 141 | } |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 142 | video_media_info_.senders.push_back(video_sender_info); |
| 143 | video_media_info_.aggregated_senders.push_back(video_sender_info); |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | |
| 147 | void AddRtpReceiverWithSsrcs(std::initializer_list<uint32_t> ssrcs, |
| 148 | MediaStreamTrackInterface* remote_track) { |
Steve Anton | 57858b3 | 2018-02-15 23:19:50 | [diff] [blame] | 149 | auto rtp_receiver = CreateMockRtpReceiver( |
deadbeef | 804c1af | 2017-02-12 03:07:31 | [diff] [blame] | 150 | remote_track->kind() == MediaStreamTrackInterface::kAudioKind |
| 151 | ? cricket::MEDIA_TYPE_AUDIO |
| 152 | : cricket::MEDIA_TYPE_VIDEO, |
Niels Möller | e7cc883 | 2022-01-04 14:20:03 | [diff] [blame] | 153 | ssrcs, rtc::scoped_refptr<MediaStreamTrackInterface>(remote_track)); |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 154 | rtp_receivers_.push_back(rtp_receiver); |
| 155 | |
| 156 | if (remote_track->kind() == MediaStreamTrackInterface::kAudioKind) { |
| 157 | cricket::VoiceReceiverInfo voice_receiver_info; |
| 158 | size_t i = 0; |
| 159 | for (uint32_t ssrc : ssrcs) { |
| 160 | voice_receiver_info.local_stats.push_back(cricket::SsrcReceiverInfo()); |
| 161 | voice_receiver_info.local_stats[i++].ssrc = ssrc; |
| 162 | } |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 163 | voice_media_info_.receivers.push_back(voice_receiver_info); |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 164 | } else { |
| 165 | cricket::VideoReceiverInfo video_receiver_info; |
| 166 | size_t i = 0; |
| 167 | for (uint32_t ssrc : ssrcs) { |
| 168 | video_receiver_info.local_stats.push_back(cricket::SsrcReceiverInfo()); |
| 169 | video_receiver_info.local_stats[i++].ssrc = ssrc; |
| 170 | } |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 171 | video_media_info_.receivers.push_back(video_receiver_info); |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 175 | // Copies the current state of `voice_media_info_` and `video_media_info_` |
| 176 | // into the map. |
| 177 | void InitializeMap() { |
| 178 | map_.Initialize(voice_media_info_, video_media_info_, rtp_senders_, |
| 179 | rtp_receivers_); |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 180 | } |
| 181 | |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 182 | private: |
Niels Möller | 83830f3 | 2022-05-20 07:12:57 | [diff] [blame] | 183 | rtc::AutoThread main_thread_; |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 184 | cricket::VoiceMediaInfo voice_media_info_; |
| 185 | cricket::VideoMediaInfo video_media_info_; |
| 186 | |
| 187 | protected: |
Steve Anton | 57858b3 | 2018-02-15 23:19:50 | [diff] [blame] | 188 | std::vector<rtc::scoped_refptr<RtpSenderInternal>> rtp_senders_; |
| 189 | std::vector<rtc::scoped_refptr<RtpReceiverInternal>> rtp_receivers_; |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 190 | TrackMediaInfoMap map_; |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 191 | rtc::scoped_refptr<AudioTrack> local_audio_track_; |
| 192 | rtc::scoped_refptr<AudioTrack> remote_audio_track_; |
Tommi | 816134a | 2021-05-24 14:54:41 | [diff] [blame] | 193 | rtc::scoped_refptr<VideoTrackInterface> local_video_track_; |
| 194 | rtc::scoped_refptr<VideoTrackInterface> remote_video_track_; |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 195 | }; |
| 196 | |
| 197 | } // namespace |
| 198 | |
| 199 | TEST_F(TrackMediaInfoMapTest, SingleSenderReceiverPerTrackWithOneSsrc) { |
Niels Möller | afb246b | 2022-04-20 12:26:50 | [diff] [blame] | 200 | AddRtpSenderWithSsrcs({1}, local_audio_track_.get()); |
| 201 | AddRtpReceiverWithSsrcs({2}, remote_audio_track_.get()); |
| 202 | AddRtpSenderWithSsrcs({3}, local_video_track_.get()); |
| 203 | AddRtpReceiverWithSsrcs({4}, remote_video_track_.get()); |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 204 | InitializeMap(); |
Henrik Boström | 4e231ee | 2023-05-24 09:24:13 | [diff] [blame] | 205 | // RTP audio sender -> local audio track |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 206 | EXPECT_EQ(map_.GetAudioTrack(map_.voice_media_info()->senders[0]), |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 207 | local_audio_track_.get()); |
Henrik Boström | 4e231ee | 2023-05-24 09:24:13 | [diff] [blame] | 208 | // RTP audio receiver -> remote audio track |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 209 | EXPECT_EQ(map_.GetAudioTrack(map_.voice_media_info()->receivers[0]), |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 210 | remote_audio_track_.get()); |
Henrik Boström | 4e231ee | 2023-05-24 09:24:13 | [diff] [blame] | 211 | // RTP video sender -> local video track |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 212 | EXPECT_EQ(map_.GetVideoTrack(map_.video_media_info()->senders[0]), |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 213 | local_video_track_.get()); |
Henrik Boström | 4e231ee | 2023-05-24 09:24:13 | [diff] [blame] | 214 | // RTP video receiver -> remote video track |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 215 | EXPECT_EQ(map_.GetVideoTrack(map_.video_media_info()->receivers[0]), |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 216 | remote_video_track_.get()); |
| 217 | } |
| 218 | |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 219 | TEST_F(TrackMediaInfoMapTest, |
| 220 | SingleSenderReceiverPerTrackWithAudioAndVideoUseSameSsrc) { |
Niels Möller | afb246b | 2022-04-20 12:26:50 | [diff] [blame] | 221 | AddRtpSenderWithSsrcs({1}, local_audio_track_.get()); |
| 222 | AddRtpReceiverWithSsrcs({2}, remote_audio_track_.get()); |
| 223 | AddRtpSenderWithSsrcs({1}, local_video_track_.get()); |
| 224 | AddRtpReceiverWithSsrcs({2}, remote_video_track_.get()); |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 225 | InitializeMap(); |
Henrik Boström | 4e231ee | 2023-05-24 09:24:13 | [diff] [blame] | 226 | // RTP audio sender -> local audio track |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 227 | EXPECT_EQ(map_.GetAudioTrack(map_.voice_media_info()->senders[0]), |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 228 | local_audio_track_.get()); |
Henrik Boström | 4e231ee | 2023-05-24 09:24:13 | [diff] [blame] | 229 | // RTP audio receiver -> remote audio track |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 230 | EXPECT_EQ(map_.GetAudioTrack(map_.voice_media_info()->receivers[0]), |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 231 | remote_audio_track_.get()); |
Henrik Boström | 4e231ee | 2023-05-24 09:24:13 | [diff] [blame] | 232 | // RTP video sender -> local video track |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 233 | EXPECT_EQ(map_.GetVideoTrack(map_.video_media_info()->senders[0]), |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 234 | local_video_track_.get()); |
Henrik Boström | 4e231ee | 2023-05-24 09:24:13 | [diff] [blame] | 235 | // RTP video receiver -> remote video track |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 236 | EXPECT_EQ(map_.GetVideoTrack(map_.video_media_info()->receivers[0]), |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 237 | remote_video_track_.get()); |
| 238 | } |
| 239 | |
| 240 | TEST_F(TrackMediaInfoMapTest, SingleMultiSsrcSenderPerTrack) { |
Niels Möller | afb246b | 2022-04-20 12:26:50 | [diff] [blame] | 241 | AddRtpSenderWithSsrcs({1, 2}, local_audio_track_.get()); |
| 242 | AddRtpSenderWithSsrcs({3, 4}, local_video_track_.get()); |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 243 | InitializeMap(); |
Henrik Boström | 4e231ee | 2023-05-24 09:24:13 | [diff] [blame] | 244 | // RTP audio senders -> local audio track |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 245 | EXPECT_EQ(map_.GetAudioTrack(map_.voice_media_info()->senders[0]), |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 246 | local_audio_track_.get()); |
Henrik Boström | 4e231ee | 2023-05-24 09:24:13 | [diff] [blame] | 247 | // RTP video senders -> local video track |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 248 | EXPECT_EQ(map_.GetVideoTrack(map_.video_media_info()->senders[0]), |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 249 | local_video_track_.get()); |
| 250 | } |
| 251 | |
| 252 | TEST_F(TrackMediaInfoMapTest, MultipleOneSsrcSendersPerTrack) { |
Niels Möller | afb246b | 2022-04-20 12:26:50 | [diff] [blame] | 253 | AddRtpSenderWithSsrcs({1}, local_audio_track_.get()); |
| 254 | AddRtpSenderWithSsrcs({2}, local_audio_track_.get()); |
| 255 | AddRtpSenderWithSsrcs({3}, local_video_track_.get()); |
| 256 | AddRtpSenderWithSsrcs({4}, local_video_track_.get()); |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 257 | InitializeMap(); |
Henrik Boström | 4e231ee | 2023-05-24 09:24:13 | [diff] [blame] | 258 | // RTP audio senders -> local audio track |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 259 | EXPECT_EQ(map_.GetAudioTrack(map_.voice_media_info()->senders[0]), |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 260 | local_audio_track_.get()); |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 261 | EXPECT_EQ(map_.GetAudioTrack(map_.voice_media_info()->senders[1]), |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 262 | local_audio_track_.get()); |
Henrik Boström | 4e231ee | 2023-05-24 09:24:13 | [diff] [blame] | 263 | // RTP video senders -> local video track |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 264 | EXPECT_EQ(map_.GetVideoTrack(map_.video_media_info()->senders[0]), |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 265 | local_video_track_.get()); |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 266 | EXPECT_EQ(map_.GetVideoTrack(map_.video_media_info()->senders[1]), |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 267 | local_video_track_.get()); |
| 268 | } |
| 269 | |
| 270 | TEST_F(TrackMediaInfoMapTest, MultipleMultiSsrcSendersPerTrack) { |
Niels Möller | afb246b | 2022-04-20 12:26:50 | [diff] [blame] | 271 | AddRtpSenderWithSsrcs({1, 2}, local_audio_track_.get()); |
| 272 | AddRtpSenderWithSsrcs({3, 4}, local_audio_track_.get()); |
| 273 | AddRtpSenderWithSsrcs({5, 6}, local_video_track_.get()); |
| 274 | AddRtpSenderWithSsrcs({7, 8}, local_video_track_.get()); |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 275 | InitializeMap(); |
Henrik Boström | 4e231ee | 2023-05-24 09:24:13 | [diff] [blame] | 276 | // RTP audio senders -> local audio track |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 277 | EXPECT_EQ(map_.GetAudioTrack(map_.voice_media_info()->senders[0]), |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 278 | local_audio_track_.get()); |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 279 | EXPECT_EQ(map_.GetAudioTrack(map_.voice_media_info()->senders[1]), |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 280 | local_audio_track_.get()); |
Henrik Boström | 4e231ee | 2023-05-24 09:24:13 | [diff] [blame] | 281 | // RTP video senders -> local video track |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 282 | EXPECT_EQ(map_.GetVideoTrack(map_.video_media_info()->senders[0]), |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 283 | local_video_track_.get()); |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 284 | EXPECT_EQ(map_.GetVideoTrack(map_.video_media_info()->senders[1]), |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 285 | local_video_track_.get()); |
| 286 | } |
| 287 | |
hbos | fe90ad1 | 2017-02-20 10:05:13 | [diff] [blame] | 288 | // SSRCs can be reused for send and receive in loopback. |
| 289 | TEST_F(TrackMediaInfoMapTest, SingleSenderReceiverPerTrackWithSsrcNotUnique) { |
Niels Möller | afb246b | 2022-04-20 12:26:50 | [diff] [blame] | 290 | AddRtpSenderWithSsrcs({1}, local_audio_track_.get()); |
| 291 | AddRtpReceiverWithSsrcs({1}, remote_audio_track_.get()); |
| 292 | AddRtpSenderWithSsrcs({2}, local_video_track_.get()); |
| 293 | AddRtpReceiverWithSsrcs({2}, remote_video_track_.get()); |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 294 | InitializeMap(); |
Henrik Boström | 4e231ee | 2023-05-24 09:24:13 | [diff] [blame] | 295 | // RTP audio senders -> local audio track |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 296 | EXPECT_EQ(map_.GetAudioTrack(map_.voice_media_info()->senders[0]), |
hbos | fe90ad1 | 2017-02-20 10:05:13 | [diff] [blame] | 297 | local_audio_track_.get()); |
Henrik Boström | 4e231ee | 2023-05-24 09:24:13 | [diff] [blame] | 298 | // RTP audio receiver -> remote audio track |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 299 | EXPECT_EQ(map_.GetAudioTrack(map_.voice_media_info()->receivers[0]), |
hbos | fe90ad1 | 2017-02-20 10:05:13 | [diff] [blame] | 300 | remote_audio_track_.get()); |
Henrik Boström | 4e231ee | 2023-05-24 09:24:13 | [diff] [blame] | 301 | // RTP video senders -> local video track |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 302 | EXPECT_EQ(map_.GetVideoTrack(map_.video_media_info()->senders[0]), |
hbos | fe90ad1 | 2017-02-20 10:05:13 | [diff] [blame] | 303 | local_video_track_.get()); |
Henrik Boström | 4e231ee | 2023-05-24 09:24:13 | [diff] [blame] | 304 | // RTP video receiver -> remote video track |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 305 | EXPECT_EQ(map_.GetVideoTrack(map_.video_media_info()->receivers[0]), |
hbos | fe90ad1 | 2017-02-20 10:05:13 | [diff] [blame] | 306 | remote_video_track_.get()); |
| 307 | } |
| 308 | |
Harald Alvestrand | 8906187 | 2018-01-02 13:08:34 | [diff] [blame] | 309 | TEST_F(TrackMediaInfoMapTest, SsrcLookupFunction) { |
Niels Möller | afb246b | 2022-04-20 12:26:50 | [diff] [blame] | 310 | AddRtpSenderWithSsrcs({1}, local_audio_track_.get()); |
| 311 | AddRtpReceiverWithSsrcs({2}, remote_audio_track_.get()); |
| 312 | AddRtpSenderWithSsrcs({3}, local_video_track_.get()); |
| 313 | AddRtpReceiverWithSsrcs({4}, remote_video_track_.get()); |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 314 | InitializeMap(); |
| 315 | EXPECT_TRUE(map_.GetVoiceSenderInfoBySsrc(1)); |
| 316 | EXPECT_TRUE(map_.GetVoiceReceiverInfoBySsrc(2)); |
| 317 | EXPECT_TRUE(map_.GetVideoSenderInfoBySsrc(3)); |
| 318 | EXPECT_TRUE(map_.GetVideoReceiverInfoBySsrc(4)); |
| 319 | EXPECT_FALSE(map_.GetVoiceSenderInfoBySsrc(2)); |
| 320 | EXPECT_FALSE(map_.GetVoiceSenderInfoBySsrc(1024)); |
Harald Alvestrand | 8906187 | 2018-01-02 13:08:34 | [diff] [blame] | 321 | } |
| 322 | |
Harald Alvestrand | c72af93 | 2018-01-11 16:18:19 | [diff] [blame] | 323 | TEST_F(TrackMediaInfoMapTest, GetAttachmentIdByTrack) { |
Niels Möller | afb246b | 2022-04-20 12:26:50 | [diff] [blame] | 324 | AddRtpSenderWithSsrcs({1}, local_audio_track_.get()); |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 325 | InitializeMap(); |
Harald Alvestrand | c72af93 | 2018-01-11 16:18:19 | [diff] [blame] | 326 | EXPECT_EQ(rtp_senders_[0]->AttachmentId(), |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 327 | map_.GetAttachmentIdByTrack(local_audio_track_.get())); |
Niels Möller | afb246b | 2022-04-20 12:26:50 | [diff] [blame] | 328 | EXPECT_EQ(absl::nullopt, |
Henrik Boström | fc67b45 | 2022-07-27 08:55:45 | [diff] [blame] | 329 | map_.GetAttachmentIdByTrack(local_video_track_.get())); |
Harald Alvestrand | c72af93 | 2018-01-11 16:18:19 | [diff] [blame] | 330 | } |
| 331 | |
hbos | 1f8239c | 2017-01-16 12:24:10 | [diff] [blame] | 332 | } // namespace webrtc |