Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | |
| 11 | #include <memory> |
| 12 | #include <vector> |
| 13 | |
Karl Wiberg | 1b0eae3 | 2017-10-17 14:48:54 +0200 | [diff] [blame] | 14 | #include "api/audio_codecs/builtin_audio_decoder_factory.h" |
| 15 | #include "api/audio_codecs/builtin_audio_encoder_factory.h" |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 16 | #include "api/jsep.h" |
| 17 | #include "api/mediastreaminterface.h" |
| 18 | #include "api/peerconnectioninterface.h" |
Steve Anton | 8e20f17 | 2018-03-06 10:55:04 -0800 | [diff] [blame] | 19 | #include "api/umametrics.h" |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 20 | #include "api/video_codecs/builtin_video_decoder_factory.h" |
| 21 | #include "api/video_codecs/builtin_video_encoder_factory.h" |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 22 | #include "pc/mediasession.h" |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 23 | #include "pc/mediastream.h" |
| 24 | #include "pc/mediastreamtrack.h" |
| 25 | #include "pc/peerconnectionwrapper.h" |
Steve Anton | e831b8c | 2018-02-01 12:22:16 -0800 | [diff] [blame] | 26 | #include "pc/sdputils.h" |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 27 | #include "pc/test/fakeaudiocapturemodule.h" |
| 28 | #include "pc/test/mockpeerconnectionobservers.h" |
| 29 | #include "rtc_base/checks.h" |
| 30 | #include "rtc_base/gunit.h" |
| 31 | #include "rtc_base/ptr_util.h" |
| 32 | #include "rtc_base/refcountedobject.h" |
| 33 | #include "rtc_base/scoped_ref_ptr.h" |
| 34 | #include "rtc_base/thread.h" |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 35 | #include "test/gmock.h" |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 36 | |
| 37 | // This file contains tests for RTP Media API-related behavior of |
| 38 | // |webrtc::PeerConnection|, see https://w3c.github.io/webrtc-pc/#rtp-media-api. |
| 39 | |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 40 | namespace webrtc { |
| 41 | |
| 42 | using RTCConfiguration = PeerConnectionInterface::RTCConfiguration; |
| 43 | using ::testing::ElementsAre; |
| 44 | using ::testing::UnorderedElementsAre; |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 45 | using ::testing::Values; |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 46 | |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 47 | const uint32_t kDefaultTimeout = 10000u; |
| 48 | |
| 49 | template <typename MethodFunctor> |
| 50 | class OnSuccessObserver : public rtc::RefCountedObject< |
| 51 | webrtc::SetRemoteDescriptionObserverInterface> { |
| 52 | public: |
| 53 | explicit OnSuccessObserver(MethodFunctor on_success) |
| 54 | : on_success_(std::move(on_success)) {} |
| 55 | |
| 56 | // webrtc::SetRemoteDescriptionObserverInterface implementation. |
| 57 | void OnSetRemoteDescriptionComplete(webrtc::RTCError error) override { |
| 58 | RTC_CHECK(error.ok()); |
| 59 | on_success_(); |
| 60 | } |
| 61 | |
| 62 | private: |
| 63 | MethodFunctor on_success_; |
| 64 | }; |
| 65 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 66 | class PeerConnectionRtpBaseTest : public testing::Test { |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 67 | public: |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 68 | explicit PeerConnectionRtpBaseTest(SdpSemantics sdp_semantics) |
| 69 | : sdp_semantics_(sdp_semantics), |
| 70 | pc_factory_( |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 71 | CreatePeerConnectionFactory(rtc::Thread::Current(), |
| 72 | rtc::Thread::Current(), |
| 73 | rtc::Thread::Current(), |
| 74 | FakeAudioCaptureModule::Create(), |
| 75 | CreateBuiltinAudioEncoderFactory(), |
| 76 | CreateBuiltinAudioDecoderFactory(), |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 77 | CreateBuiltinVideoEncoderFactory(), |
| 78 | CreateBuiltinVideoDecoderFactory(), |
| 79 | nullptr /* audio_mixer */, |
| 80 | nullptr /* audio_processing */)) {} |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 81 | |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 82 | std::unique_ptr<PeerConnectionWrapper> CreatePeerConnection() { |
| 83 | return CreatePeerConnection(RTCConfiguration()); |
| 84 | } |
| 85 | |
Steve Anton | e831b8c | 2018-02-01 12:22:16 -0800 | [diff] [blame] | 86 | std::unique_ptr<PeerConnectionWrapper> CreatePeerConnectionWithPlanB() { |
| 87 | RTCConfiguration config; |
| 88 | config.sdp_semantics = SdpSemantics::kPlanB; |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 89 | return CreatePeerConnectionInternal(config); |
Steve Anton | e831b8c | 2018-02-01 12:22:16 -0800 | [diff] [blame] | 90 | } |
| 91 | |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 92 | std::unique_ptr<PeerConnectionWrapper> CreatePeerConnectionWithUnifiedPlan() { |
| 93 | RTCConfiguration config; |
| 94 | config.sdp_semantics = SdpSemantics::kUnifiedPlan; |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 95 | return CreatePeerConnectionInternal(config); |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | std::unique_ptr<PeerConnectionWrapper> CreatePeerConnection( |
| 99 | const RTCConfiguration& config) { |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 100 | RTCConfiguration modified_config = config; |
| 101 | modified_config.sdp_semantics = sdp_semantics_; |
| 102 | return CreatePeerConnectionInternal(modified_config); |
| 103 | } |
| 104 | |
| 105 | protected: |
| 106 | const SdpSemantics sdp_semantics_; |
| 107 | rtc::scoped_refptr<PeerConnectionFactoryInterface> pc_factory_; |
| 108 | |
| 109 | private: |
| 110 | // Private so that tests don't accidentally bypass the SdpSemantics |
| 111 | // adjustment. |
| 112 | std::unique_ptr<PeerConnectionWrapper> CreatePeerConnectionInternal( |
| 113 | const RTCConfiguration& config) { |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 114 | auto observer = rtc::MakeUnique<MockPeerConnectionObserver>(); |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 115 | auto pc = pc_factory_->CreatePeerConnection(config, nullptr, nullptr, |
| 116 | observer.get()); |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 117 | return rtc::MakeUnique<PeerConnectionWrapper>(pc_factory_, pc, |
| 118 | std::move(observer)); |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 119 | } |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 120 | }; |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 121 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 122 | class PeerConnectionRtpTest |
| 123 | : public PeerConnectionRtpBaseTest, |
| 124 | public ::testing::WithParamInterface<SdpSemantics> { |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 125 | protected: |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 126 | PeerConnectionRtpTest() : PeerConnectionRtpBaseTest(GetParam()) {} |
| 127 | }; |
| 128 | |
| 129 | class PeerConnectionRtpTestPlanB : public PeerConnectionRtpBaseTest { |
| 130 | protected: |
| 131 | PeerConnectionRtpTestPlanB() |
| 132 | : PeerConnectionRtpBaseTest(SdpSemantics::kPlanB) {} |
| 133 | }; |
| 134 | |
| 135 | class PeerConnectionRtpTestUnifiedPlan : public PeerConnectionRtpBaseTest { |
| 136 | protected: |
| 137 | PeerConnectionRtpTestUnifiedPlan() |
| 138 | : PeerConnectionRtpBaseTest(SdpSemantics::kUnifiedPlan) {} |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 139 | }; |
| 140 | |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 141 | // These tests cover |webrtc::PeerConnectionObserver| callbacks firing upon |
| 142 | // setting the remote description. |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 143 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 144 | TEST_P(PeerConnectionRtpTest, AddTrackWithoutStreamFiresOnAddTrack) { |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 145 | auto caller = CreatePeerConnection(); |
| 146 | auto callee = CreatePeerConnection(); |
| 147 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 148 | ASSERT_TRUE(caller->AddAudioTrack("audio_track")); |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 149 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 150 | |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 151 | ASSERT_EQ(callee->observer()->add_track_events_.size(), 1u); |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 152 | const auto& add_track_event = callee->observer()->add_track_events_[0]; |
Henrik Boström | 9e6fd2b | 2017-11-21 13:41:51 +0100 | [diff] [blame] | 153 | EXPECT_EQ(add_track_event.streams, add_track_event.receiver->streams()); |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 154 | |
| 155 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 156 | // Since we are not supporting the no stream case with Plan B, there should |
| 157 | // be a generated stream, even though we didn't set one with AddTrack. |
| 158 | ASSERT_EQ(1u, add_track_event.streams.size()); |
| 159 | EXPECT_TRUE(add_track_event.streams[0]->FindAudioTrack("audio_track")); |
| 160 | } else { |
| 161 | EXPECT_EQ(0u, add_track_event.streams.size()); |
| 162 | } |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 165 | TEST_P(PeerConnectionRtpTest, AddTrackWithStreamFiresOnAddTrack) { |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 166 | auto caller = CreatePeerConnection(); |
| 167 | auto callee = CreatePeerConnection(); |
| 168 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 169 | ASSERT_TRUE(caller->AddAudioTrack("audio_track", {"audio_stream"})); |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 170 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 171 | |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 172 | ASSERT_EQ(callee->observer()->add_track_events_.size(), 1u); |
Henrik Boström | 9e6fd2b | 2017-11-21 13:41:51 +0100 | [diff] [blame] | 173 | auto& add_track_event = callee->observer()->add_track_events_[0]; |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 174 | ASSERT_EQ(add_track_event.streams.size(), 1u); |
Seth Hampson | 13b8bad | 2018-03-13 16:05:28 -0700 | [diff] [blame] | 175 | EXPECT_EQ("audio_stream", add_track_event.streams[0]->id()); |
Henrik Boström | 9e6fd2b | 2017-11-21 13:41:51 +0100 | [diff] [blame] | 176 | EXPECT_TRUE(add_track_event.streams[0]->FindAudioTrack("audio_track")); |
| 177 | EXPECT_EQ(add_track_event.streams, add_track_event.receiver->streams()); |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 180 | TEST_P(PeerConnectionRtpTest, RemoveTrackWithoutStreamFiresOnRemoveTrack) { |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 181 | auto caller = CreatePeerConnection(); |
| 182 | auto callee = CreatePeerConnection(); |
| 183 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 184 | auto sender = caller->AddAudioTrack("audio_track", {}); |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 185 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 186 | ASSERT_EQ(callee->observer()->add_track_events_.size(), 1u); |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 187 | ASSERT_TRUE( |
| 188 | caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal())); |
| 189 | |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 190 | EXPECT_TRUE(caller->pc()->RemoveTrack(sender)); |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 191 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 192 | |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 193 | ASSERT_EQ(callee->observer()->add_track_events_.size(), 1u); |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 194 | EXPECT_EQ(callee->observer()->GetAddTrackReceivers(), |
| 195 | callee->observer()->remove_track_events_); |
| 196 | } |
| 197 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 198 | TEST_P(PeerConnectionRtpTest, RemoveTrackWithStreamFiresOnRemoveTrack) { |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 199 | auto caller = CreatePeerConnection(); |
| 200 | auto callee = CreatePeerConnection(); |
| 201 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 202 | auto sender = caller->AddAudioTrack("audio_track", {"audio_stream"}); |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 203 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 204 | ASSERT_EQ(callee->observer()->add_track_events_.size(), 1u); |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 205 | ASSERT_TRUE( |
| 206 | caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal())); |
| 207 | |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 208 | EXPECT_TRUE(caller->pc()->RemoveTrack(sender)); |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 209 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 210 | |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 211 | ASSERT_EQ(callee->observer()->add_track_events_.size(), 1u); |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 212 | EXPECT_EQ(callee->observer()->GetAddTrackReceivers(), |
| 213 | callee->observer()->remove_track_events_); |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 214 | EXPECT_EQ(0u, callee->observer()->remote_streams()->count()); |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 217 | TEST_P(PeerConnectionRtpTest, RemoveTrackWithSharedStreamFiresOnRemoveTrack) { |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 218 | auto caller = CreatePeerConnection(); |
| 219 | auto callee = CreatePeerConnection(); |
| 220 | |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 221 | const char kSharedStreamId[] = "shared_audio_stream"; |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 222 | auto sender1 = caller->AddAudioTrack("audio_track1", {kSharedStreamId}); |
| 223 | auto sender2 = caller->AddAudioTrack("audio_track2", {kSharedStreamId}); |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 224 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 225 | ASSERT_EQ(callee->observer()->add_track_events_.size(), 2u); |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 226 | ASSERT_TRUE( |
| 227 | caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal())); |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 228 | |
| 229 | // Remove "audio_track1". |
| 230 | EXPECT_TRUE(caller->pc()->RemoveTrack(sender1)); |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 231 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 232 | ASSERT_EQ(callee->observer()->add_track_events_.size(), 2u); |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 233 | EXPECT_EQ( |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 234 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>>{ |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 235 | callee->observer()->add_track_events_[0].receiver}, |
| 236 | callee->observer()->remove_track_events_); |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 237 | ASSERT_EQ(1u, callee->observer()->remote_streams()->count()); |
| 238 | ASSERT_TRUE( |
| 239 | caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal())); |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 240 | |
| 241 | // Remove "audio_track2". |
| 242 | EXPECT_TRUE(caller->pc()->RemoveTrack(sender2)); |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 243 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 244 | ASSERT_EQ(callee->observer()->add_track_events_.size(), 2u); |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 245 | EXPECT_EQ(callee->observer()->GetAddTrackReceivers(), |
| 246 | callee->observer()->remove_track_events_); |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 247 | EXPECT_EQ(0u, callee->observer()->remote_streams()->count()); |
Henrik Boström | 933d8b0 | 2017-10-10 10:05:16 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 250 | // Tests the edge case that if a stream ID changes for a given track that both |
| 251 | // OnRemoveTrack and OnAddTrack is fired. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 252 | TEST_F(PeerConnectionRtpTestPlanB, |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 253 | RemoteStreamIdChangesFiresOnRemoveAndOnAddTrack) { |
| 254 | auto caller = CreatePeerConnection(); |
| 255 | auto callee = CreatePeerConnection(); |
| 256 | |
| 257 | const char kStreamId1[] = "stream1"; |
| 258 | const char kStreamId2[] = "stream2"; |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 259 | caller->AddAudioTrack("audio_track1", {kStreamId1}); |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 260 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 261 | EXPECT_EQ(callee->observer()->add_track_events_.size(), 1u); |
| 262 | |
| 263 | // Change the stream ID of the sender in the session description. |
| 264 | auto offer = caller->CreateOfferAndSetAsLocal(); |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 265 | auto* audio_desc = |
| 266 | cricket::GetFirstAudioContentDescription(offer->description()); |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 267 | ASSERT_EQ(audio_desc->mutable_streams().size(), 1u); |
| 268 | audio_desc->mutable_streams()[0].set_stream_ids({kStreamId2}); |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 269 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 270 | |
| 271 | ASSERT_EQ(callee->observer()->add_track_events_.size(), 2u); |
| 272 | EXPECT_EQ(callee->observer()->add_track_events_[1].streams[0]->id(), |
| 273 | kStreamId2); |
| 274 | ASSERT_EQ(callee->observer()->remove_track_events_.size(), 1u); |
| 275 | EXPECT_EQ(callee->observer()->remove_track_events_[0]->streams()[0]->id(), |
| 276 | kStreamId1); |
| 277 | } |
| 278 | |
Steve Anton | 8b815cd | 2018-02-16 16:14:42 -0800 | [diff] [blame] | 279 | // Tests that setting a remote description with sending transceivers will fire |
| 280 | // the OnTrack callback for each transceiver and setting a remote description |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 281 | // with receive only transceivers will not call OnTrack. One transceiver is |
| 282 | // created without any stream_ids, while the other is created with multiple |
| 283 | // stream_ids. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 284 | TEST_F(PeerConnectionRtpTestUnifiedPlan, AddTransceiverCallsOnTrack) { |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 285 | const std::string kStreamId1 = "video_stream1"; |
| 286 | const std::string kStreamId2 = "video_stream2"; |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 287 | auto caller = CreatePeerConnection(); |
| 288 | auto callee = CreatePeerConnection(); |
Steve Anton | 8b815cd | 2018-02-16 16:14:42 -0800 | [diff] [blame] | 289 | |
| 290 | auto audio_transceiver = caller->AddTransceiver(cricket::MEDIA_TYPE_AUDIO); |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 291 | RtpTransceiverInit video_transceiver_init; |
| 292 | video_transceiver_init.stream_ids = {kStreamId1, kStreamId2}; |
| 293 | auto video_transceiver = |
| 294 | caller->AddTransceiver(cricket::MEDIA_TYPE_VIDEO, video_transceiver_init); |
Steve Anton | 8b815cd | 2018-02-16 16:14:42 -0800 | [diff] [blame] | 295 | |
| 296 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 297 | |
| 298 | ASSERT_EQ(0u, caller->observer()->on_track_transceivers_.size()); |
| 299 | ASSERT_EQ(2u, callee->observer()->on_track_transceivers_.size()); |
| 300 | EXPECT_EQ(audio_transceiver->mid(), |
| 301 | callee->pc()->GetTransceivers()[0]->mid()); |
| 302 | EXPECT_EQ(video_transceiver->mid(), |
| 303 | callee->pc()->GetTransceivers()[1]->mid()); |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 304 | std::vector<rtc::scoped_refptr<MediaStreamInterface>> audio_streams = |
| 305 | callee->pc()->GetTransceivers()[0]->receiver()->streams(); |
| 306 | std::vector<rtc::scoped_refptr<MediaStreamInterface>> video_streams = |
| 307 | callee->pc()->GetTransceivers()[1]->receiver()->streams(); |
| 308 | ASSERT_EQ(0u, audio_streams.size()); |
| 309 | ASSERT_EQ(2u, video_streams.size()); |
| 310 | EXPECT_EQ(kStreamId1, video_streams[0]->id()); |
| 311 | EXPECT_EQ(kStreamId2, video_streams[1]->id()); |
Steve Anton | 8b815cd | 2018-02-16 16:14:42 -0800 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | // Test that doing additional offer/answer exchanges with no changes to tracks |
| 315 | // will cause no additional OnTrack calls after the tracks have been negotiated. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 316 | TEST_F(PeerConnectionRtpTestUnifiedPlan, ReofferDoesNotCallOnTrack) { |
| 317 | auto caller = CreatePeerConnection(); |
| 318 | auto callee = CreatePeerConnection(); |
Steve Anton | 8b815cd | 2018-02-16 16:14:42 -0800 | [diff] [blame] | 319 | |
| 320 | caller->AddAudioTrack("audio"); |
| 321 | callee->AddAudioTrack("audio"); |
| 322 | |
| 323 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 324 | EXPECT_EQ(1u, caller->observer()->on_track_transceivers_.size()); |
| 325 | EXPECT_EQ(1u, callee->observer()->on_track_transceivers_.size()); |
| 326 | |
| 327 | // If caller reoffers with no changes expect no additional OnTrack calls. |
| 328 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 329 | EXPECT_EQ(1u, caller->observer()->on_track_transceivers_.size()); |
| 330 | EXPECT_EQ(1u, callee->observer()->on_track_transceivers_.size()); |
| 331 | |
| 332 | // Also if callee reoffers with no changes expect no additional OnTrack calls. |
| 333 | ASSERT_TRUE(callee->ExchangeOfferAnswerWith(caller.get())); |
| 334 | EXPECT_EQ(1u, caller->observer()->on_track_transceivers_.size()); |
| 335 | EXPECT_EQ(1u, callee->observer()->on_track_transceivers_.size()); |
| 336 | } |
| 337 | |
| 338 | // Test that OnTrack is called when the transceiver direction changes to send |
| 339 | // the track. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 340 | TEST_F(PeerConnectionRtpTestUnifiedPlan, SetDirectionCallsOnTrack) { |
| 341 | auto caller = CreatePeerConnection(); |
| 342 | auto callee = CreatePeerConnection(); |
Steve Anton | 8b815cd | 2018-02-16 16:14:42 -0800 | [diff] [blame] | 343 | |
| 344 | auto transceiver = caller->AddTransceiver(cricket::MEDIA_TYPE_AUDIO); |
| 345 | transceiver->SetDirection(RtpTransceiverDirection::kInactive); |
| 346 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 347 | EXPECT_EQ(0u, caller->observer()->on_track_transceivers_.size()); |
| 348 | EXPECT_EQ(0u, callee->observer()->on_track_transceivers_.size()); |
| 349 | |
| 350 | transceiver->SetDirection(RtpTransceiverDirection::kSendOnly); |
| 351 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 352 | EXPECT_EQ(0u, caller->observer()->on_track_transceivers_.size()); |
| 353 | EXPECT_EQ(1u, callee->observer()->on_track_transceivers_.size()); |
| 354 | |
| 355 | // If the direction changes but it is still receiving on the remote side, then |
| 356 | // OnTrack should not be fired again. |
| 357 | transceiver->SetDirection(RtpTransceiverDirection::kSendRecv); |
| 358 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 359 | EXPECT_EQ(0u, caller->observer()->on_track_transceivers_.size()); |
| 360 | EXPECT_EQ(1u, callee->observer()->on_track_transceivers_.size()); |
| 361 | } |
| 362 | |
| 363 | // Test that OnTrack is called twice when a sendrecv call is started, the callee |
| 364 | // changes the direction to inactive, then changes it back to sendrecv. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 365 | TEST_F(PeerConnectionRtpTestUnifiedPlan, SetDirectionHoldCallsOnTrackTwice) { |
| 366 | auto caller = CreatePeerConnection(); |
| 367 | auto callee = CreatePeerConnection(); |
Steve Anton | 8b815cd | 2018-02-16 16:14:42 -0800 | [diff] [blame] | 368 | |
| 369 | auto transceiver = caller->AddTransceiver(cricket::MEDIA_TYPE_AUDIO); |
| 370 | |
| 371 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 372 | EXPECT_EQ(0u, caller->observer()->on_track_transceivers_.size()); |
| 373 | EXPECT_EQ(1u, callee->observer()->on_track_transceivers_.size()); |
| 374 | |
| 375 | // Put the call on hold by no longer receiving the track. |
| 376 | callee->pc()->GetTransceivers()[0]->SetDirection( |
| 377 | RtpTransceiverDirection::kInactive); |
| 378 | |
| 379 | ASSERT_TRUE(callee->ExchangeOfferAnswerWith(caller.get())); |
| 380 | EXPECT_EQ(0u, caller->observer()->on_track_transceivers_.size()); |
| 381 | EXPECT_EQ(1u, callee->observer()->on_track_transceivers_.size()); |
| 382 | |
| 383 | // Resume the call by changing the direction to recvonly. This should call |
| 384 | // OnTrack again on the callee side. |
| 385 | callee->pc()->GetTransceivers()[0]->SetDirection( |
| 386 | RtpTransceiverDirection::kRecvOnly); |
| 387 | |
| 388 | ASSERT_TRUE(callee->ExchangeOfferAnswerWith(caller.get())); |
| 389 | EXPECT_EQ(0u, caller->observer()->on_track_transceivers_.size()); |
| 390 | EXPECT_EQ(2u, callee->observer()->on_track_transceivers_.size()); |
| 391 | } |
| 392 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 393 | // Test that setting a remote offer twice with no answer in the middle results |
| 394 | // in OnAddTrack being fired twice, once for each SetRemoteDescription. This |
| 395 | // happens since the RtpTransceiver's current_direction is only updated when |
| 396 | // setting the answer. |
| 397 | // TODO(bugs.webrtc.org/9236): This is spec-compliant but strange behavior. |
| 398 | TEST_F(PeerConnectionRtpTestUnifiedPlan, |
| 399 | ApplyTwoOffersWithNoAnswerResultsInTwoAddTrackEvents) { |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 400 | auto caller = CreatePeerConnection(); |
| 401 | auto callee = CreatePeerConnection(); |
| 402 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 403 | caller->AddAudioTrack("audio_track", {}); |
| 404 | |
| 405 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOffer())); |
| 406 | ASSERT_EQ(1u, callee->observer()->add_track_events_.size()); |
| 407 | |
| 408 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOffer())); |
| 409 | EXPECT_EQ(2u, callee->observer()->add_track_events_.size()); |
| 410 | } |
| 411 | |
| 412 | // Test that setting a remote offer twice with no answer in the middle and the |
| 413 | // track being removed between the two offers results in OnAddTrack being called |
| 414 | // once the first time and OnRemoveTrack never getting called. This happens |
| 415 | // since the RtpTransceiver's current_direction is only updated when setting the |
| 416 | // answer. |
| 417 | // TODO(bugs.webrtc.org/9236): This is spec-compliant but strange behavior. |
| 418 | TEST_F(PeerConnectionRtpTestUnifiedPlan, |
| 419 | ApplyTwoOffersWithNoAnswerAndTrackRemovedResultsInNoRemoveTrackEvents) { |
| 420 | auto caller = CreatePeerConnection(); |
| 421 | auto callee = CreatePeerConnection(); |
| 422 | |
| 423 | auto sender = caller->AddAudioTrack("audio_track", {}); |
| 424 | |
| 425 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOffer())); |
| 426 | ASSERT_EQ(1u, callee->observer()->add_track_events_.size()); |
| 427 | |
| 428 | caller->pc()->RemoveTrack(sender); |
| 429 | |
| 430 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOffer())); |
| 431 | EXPECT_EQ(1u, callee->observer()->add_track_events_.size()); |
| 432 | EXPECT_EQ(0u, callee->observer()->remove_track_events_.size()); |
| 433 | } |
| 434 | |
| 435 | // These tests examine the state of the peer connection as a result of |
| 436 | // performing SetRemoteDescription(). |
| 437 | |
| 438 | TEST_P(PeerConnectionRtpTest, AddTrackWithoutStreamAddsReceiver) { |
| 439 | auto caller = CreatePeerConnection(); |
| 440 | auto callee = CreatePeerConnection(); |
| 441 | |
| 442 | ASSERT_TRUE(caller->AddAudioTrack("audio_track", {})); |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 443 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 444 | |
| 445 | EXPECT_EQ(callee->pc()->GetReceivers().size(), 1u); |
| 446 | auto receiver_added = callee->pc()->GetReceivers()[0]; |
| 447 | EXPECT_EQ("audio_track", receiver_added->track()->id()); |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 448 | |
| 449 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 450 | // Since we are not supporting the no stream case with Plan B, there should |
| 451 | // be a generated stream, even though we didn't set one with AddTrack. |
| 452 | ASSERT_EQ(1u, receiver_added->streams().size()); |
| 453 | EXPECT_TRUE(receiver_added->streams()[0]->FindAudioTrack("audio_track")); |
| 454 | } else { |
| 455 | EXPECT_EQ(0u, receiver_added->streams().size()); |
| 456 | } |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 457 | } |
| 458 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 459 | TEST_P(PeerConnectionRtpTest, AddTrackWithStreamAddsReceiver) { |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 460 | auto caller = CreatePeerConnection(); |
| 461 | auto callee = CreatePeerConnection(); |
| 462 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 463 | ASSERT_TRUE(caller->AddAudioTrack("audio_track", {"audio_stream"})); |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 464 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 465 | |
| 466 | EXPECT_EQ(callee->pc()->GetReceivers().size(), 1u); |
| 467 | auto receiver_added = callee->pc()->GetReceivers()[0]; |
| 468 | EXPECT_EQ("audio_track", receiver_added->track()->id()); |
| 469 | EXPECT_EQ(receiver_added->streams().size(), 1u); |
Seth Hampson | 13b8bad | 2018-03-13 16:05:28 -0700 | [diff] [blame] | 470 | EXPECT_EQ("audio_stream", receiver_added->streams()[0]->id()); |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 471 | EXPECT_TRUE(receiver_added->streams()[0]->FindAudioTrack("audio_track")); |
| 472 | } |
| 473 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 474 | TEST_P(PeerConnectionRtpTest, RemoveTrackWithoutStreamRemovesReceiver) { |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 475 | auto caller = CreatePeerConnection(); |
| 476 | auto callee = CreatePeerConnection(); |
| 477 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 478 | auto sender = caller->AddAudioTrack("audio_track", {}); |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 479 | ASSERT_TRUE(sender); |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 480 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 481 | |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 482 | ASSERT_EQ(callee->pc()->GetReceivers().size(), 1u); |
| 483 | auto receiver = callee->pc()->GetReceivers()[0]; |
| 484 | ASSERT_TRUE(caller->pc()->RemoveTrack(sender)); |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 485 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 486 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 487 | if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) { |
| 488 | // With Unified Plan the receiver stays but the transceiver transitions to |
| 489 | // inactive. |
| 490 | ASSERT_EQ(1u, callee->pc()->GetReceivers().size()); |
| 491 | EXPECT_EQ(RtpTransceiverDirection::kInactive, |
| 492 | callee->pc()->GetTransceivers()[0]->current_direction()); |
| 493 | } else { |
| 494 | // With Plan B the receiver is removed. |
| 495 | ASSERT_EQ(0u, callee->pc()->GetReceivers().size()); |
| 496 | } |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 497 | } |
| 498 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 499 | TEST_P(PeerConnectionRtpTest, RemoveTrackWithStreamRemovesReceiver) { |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 500 | auto caller = CreatePeerConnection(); |
| 501 | auto callee = CreatePeerConnection(); |
| 502 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 503 | auto sender = caller->AddAudioTrack("audio_track", {"audio_stream"}); |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 504 | ASSERT_TRUE(sender); |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 505 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 506 | ASSERT_EQ(callee->pc()->GetReceivers().size(), 1u); |
| 507 | auto receiver = callee->pc()->GetReceivers()[0]; |
| 508 | ASSERT_TRUE(caller->pc()->RemoveTrack(sender)); |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 509 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 510 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 511 | if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) { |
| 512 | // With Unified Plan the receiver stays but the transceiver transitions to |
| 513 | // inactive. |
| 514 | EXPECT_EQ(1u, callee->pc()->GetReceivers().size()); |
| 515 | EXPECT_EQ(RtpTransceiverDirection::kInactive, |
| 516 | callee->pc()->GetTransceivers()[0]->current_direction()); |
| 517 | } else { |
| 518 | // With Plan B the receiver is removed. |
| 519 | EXPECT_EQ(0u, callee->pc()->GetReceivers().size()); |
| 520 | } |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 521 | } |
| 522 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 523 | TEST_P(PeerConnectionRtpTest, RemoveTrackWithSharedStreamRemovesReceiver) { |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 524 | auto caller = CreatePeerConnection(); |
| 525 | auto callee = CreatePeerConnection(); |
| 526 | |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 527 | const char kSharedStreamId[] = "shared_audio_stream"; |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 528 | auto sender1 = caller->AddAudioTrack("audio_track1", {kSharedStreamId}); |
| 529 | auto sender2 = caller->AddAudioTrack("audio_track2", {kSharedStreamId}); |
| 530 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 531 | ASSERT_EQ(2u, callee->pc()->GetReceivers().size()); |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 532 | |
| 533 | // Remove "audio_track1". |
| 534 | EXPECT_TRUE(caller->pc()->RemoveTrack(sender1)); |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 535 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 536 | |
| 537 | if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) { |
| 538 | // With Unified Plan the receiver stays but the transceiver transitions to |
| 539 | // inactive. |
| 540 | ASSERT_EQ(2u, callee->pc()->GetReceivers().size()); |
| 541 | auto transceiver = callee->pc()->GetTransceivers()[0]; |
| 542 | EXPECT_EQ("audio_track1", transceiver->receiver()->track()->id()); |
| 543 | EXPECT_EQ(RtpTransceiverDirection::kInactive, |
| 544 | transceiver->current_direction()); |
| 545 | } else { |
| 546 | // With Plan B the receiver is removed. |
| 547 | ASSERT_EQ(1u, callee->pc()->GetReceivers().size()); |
| 548 | EXPECT_EQ("audio_track2", callee->pc()->GetReceivers()[0]->track()->id()); |
| 549 | } |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 550 | |
| 551 | // Remove "audio_track2". |
| 552 | EXPECT_TRUE(caller->pc()->RemoveTrack(sender2)); |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 553 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 554 | |
| 555 | if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) { |
| 556 | // With Unified Plan the receiver stays but the transceiver transitions to |
| 557 | // inactive. |
| 558 | ASSERT_EQ(2u, callee->pc()->GetReceivers().size()); |
| 559 | auto transceiver = callee->pc()->GetTransceivers()[1]; |
| 560 | EXPECT_EQ("audio_track2", transceiver->receiver()->track()->id()); |
| 561 | EXPECT_EQ(RtpTransceiverDirection::kInactive, |
| 562 | transceiver->current_direction()); |
| 563 | } else { |
| 564 | // With Plan B the receiver is removed. |
| 565 | ASSERT_EQ(0u, callee->pc()->GetReceivers().size()); |
| 566 | } |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 567 | } |
| 568 | |
Florent Castelli | abe301f | 2018-06-12 18:33:49 +0200 | [diff] [blame] | 569 | TEST_P(PeerConnectionRtpTest, AudioGetParametersHasHeaderExtensions) { |
| 570 | auto caller = CreatePeerConnection(); |
| 571 | auto callee = CreatePeerConnection(); |
| 572 | auto sender = caller->AddAudioTrack("audio_track"); |
| 573 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 574 | |
| 575 | ASSERT_GT(caller->pc()->GetSenders().size(), 0u); |
| 576 | EXPECT_GT(sender->GetParameters().header_extensions.size(), 0u); |
| 577 | |
| 578 | ASSERT_GT(callee->pc()->GetReceivers().size(), 0u); |
| 579 | auto receiver = callee->pc()->GetReceivers()[0]; |
| 580 | EXPECT_GT(receiver->GetParameters().header_extensions.size(), 0u); |
| 581 | } |
| 582 | |
| 583 | TEST_P(PeerConnectionRtpTest, VideoGetParametersHasHeaderExtensions) { |
| 584 | auto caller = CreatePeerConnection(); |
| 585 | auto callee = CreatePeerConnection(); |
| 586 | auto sender = caller->AddVideoTrack("video_track"); |
| 587 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 588 | |
| 589 | ASSERT_GT(caller->pc()->GetSenders().size(), 0u); |
| 590 | EXPECT_GT(sender->GetParameters().header_extensions.size(), 0u); |
| 591 | |
| 592 | ASSERT_GT(callee->pc()->GetReceivers().size(), 0u); |
| 593 | auto receiver = callee->pc()->GetReceivers()[0]; |
| 594 | EXPECT_GT(receiver->GetParameters().header_extensions.size(), 0u); |
| 595 | } |
| 596 | |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 597 | // Invokes SetRemoteDescription() twice in a row without synchronizing the two |
| 598 | // calls and examine the state of the peer connection inside the callbacks to |
| 599 | // ensure that the second call does not occur prematurely, contaminating the |
| 600 | // state of the peer connection of the first callback. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 601 | TEST_F(PeerConnectionRtpTestPlanB, |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 602 | StatesCorrelateWithSetRemoteDescriptionCall) { |
| 603 | auto caller = CreatePeerConnection(); |
| 604 | auto callee = CreatePeerConnection(); |
| 605 | |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 606 | // Create SDP for adding a track and for removing it. This will be used in the |
| 607 | // first and second SetRemoteDescription() calls. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 608 | auto sender = caller->AddAudioTrack("audio_track", {}); |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 609 | auto srd1_sdp = caller->CreateOfferAndSetAsLocal(); |
| 610 | EXPECT_TRUE(caller->pc()->RemoveTrack(sender)); |
| 611 | auto srd2_sdp = caller->CreateOfferAndSetAsLocal(); |
| 612 | |
| 613 | // In the first SetRemoteDescription() callback, check that we have a |
| 614 | // receiver for the track. |
| 615 | auto pc = callee->pc(); |
| 616 | bool srd1_callback_called = false; |
| 617 | auto srd1_callback = [&srd1_callback_called, &pc]() { |
| 618 | EXPECT_EQ(pc->GetReceivers().size(), 1u); |
| 619 | srd1_callback_called = true; |
| 620 | }; |
| 621 | |
| 622 | // In the second SetRemoteDescription() callback, check that the receiver has |
| 623 | // been removed. |
| 624 | // TODO(hbos): When we implement Unified Plan, receivers will not be removed. |
| 625 | // Instead, the transceiver owning the receiver will become inactive. |
| 626 | // https://crbug.com/webrtc/7600 |
| 627 | bool srd2_callback_called = false; |
| 628 | auto srd2_callback = [&srd2_callback_called, &pc]() { |
| 629 | EXPECT_TRUE(pc->GetReceivers().empty()); |
| 630 | srd2_callback_called = true; |
| 631 | }; |
| 632 | |
| 633 | // Invoke SetRemoteDescription() twice in a row without synchronizing the two |
| 634 | // calls. The callbacks verify that the two calls are synchronized, as in, the |
| 635 | // effects of the second SetRemoteDescription() call must not have happened by |
| 636 | // the time the first callback is invoked. If it has then the receiver that is |
| 637 | // added as a result of the first SetRemoteDescription() call will already |
| 638 | // have been removed as a result of the second SetRemoteDescription() call |
| 639 | // when the first callback is invoked. |
| 640 | callee->pc()->SetRemoteDescription( |
| 641 | std::move(srd1_sdp), |
| 642 | new OnSuccessObserver<decltype(srd1_callback)>(srd1_callback)); |
| 643 | callee->pc()->SetRemoteDescription( |
| 644 | std::move(srd2_sdp), |
| 645 | new OnSuccessObserver<decltype(srd2_callback)>(srd2_callback)); |
| 646 | EXPECT_TRUE_WAIT(srd1_callback_called, kDefaultTimeout); |
| 647 | EXPECT_TRUE_WAIT(srd2_callback_called, kDefaultTimeout); |
| 648 | } |
| 649 | |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 650 | // Tests that a remote track is created with the signaled MSIDs when they are |
| 651 | // communicated with a=msid and no SSRCs are signaled at all (i.e., no a=ssrc |
| 652 | // lines). |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 653 | TEST_F(PeerConnectionRtpTestUnifiedPlan, UnsignaledSsrcCreatesReceiverStreams) { |
| 654 | auto caller = CreatePeerConnection(); |
| 655 | auto callee = CreatePeerConnection(); |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 656 | const char kStreamId1[] = "stream1"; |
| 657 | const char kStreamId2[] = "stream2"; |
| 658 | caller->AddTrack(caller->CreateAudioTrack("audio_track1"), |
| 659 | {kStreamId1, kStreamId2}); |
| 660 | |
| 661 | auto offer = caller->CreateOfferAndSetAsLocal(); |
| 662 | // Munge the offer to take out everything but the stream_ids. |
| 663 | auto contents = offer->description()->contents(); |
| 664 | ASSERT_TRUE(!contents.empty()); |
| 665 | ASSERT_TRUE(!contents[0].media_description()->streams().empty()); |
| 666 | std::vector<std::string> stream_ids = |
| 667 | contents[0].media_description()->streams()[0].stream_ids(); |
| 668 | contents[0].media_description()->mutable_streams().clear(); |
| 669 | cricket::StreamParams new_stream; |
| 670 | new_stream.set_stream_ids(stream_ids); |
| 671 | contents[0].media_description()->AddStream(new_stream); |
| 672 | |
| 673 | // Set the remote description and verify that the streams were added to the |
| 674 | // receiver correctly. |
| 675 | ASSERT_TRUE( |
| 676 | callee->SetRemoteDescription(CloneSessionDescription(offer.get()))); |
| 677 | auto receivers = callee->pc()->GetReceivers(); |
| 678 | ASSERT_EQ(receivers.size(), 1u); |
| 679 | ASSERT_EQ(receivers[0]->streams().size(), 2u); |
| 680 | EXPECT_EQ(receivers[0]->streams()[0]->id(), kStreamId1); |
| 681 | EXPECT_EQ(receivers[0]->streams()[1]->id(), kStreamId2); |
| 682 | } |
| 683 | |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 684 | // Tests that with Unified Plan if the the stream id changes for a track when |
| 685 | // when setting a new remote description, that the media stream is updated |
| 686 | // appropriately for the receiver. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 687 | TEST_F(PeerConnectionRtpTestUnifiedPlan, RemoteStreamIdChangesUpdatesReceiver) { |
| 688 | auto caller = CreatePeerConnection(); |
| 689 | auto callee = CreatePeerConnection(); |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 690 | |
| 691 | const char kStreamId1[] = "stream1"; |
| 692 | const char kStreamId2[] = "stream2"; |
| 693 | caller->AddTrack(caller->CreateAudioTrack("audio_track1"), {kStreamId1}); |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 694 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 695 | EXPECT_EQ(callee->observer()->add_track_events_.size(), 1u); |
| 696 | |
| 697 | // Change the stream id of the sender in the session description. |
| 698 | auto offer = caller->CreateOfferAndSetAsLocal(); |
| 699 | auto contents = offer->description()->contents(); |
| 700 | ASSERT_EQ(contents.size(), 1u); |
| 701 | ASSERT_EQ(contents[0].media_description()->mutable_streams().size(), 1u); |
| 702 | contents[0].media_description()->mutable_streams()[0].set_stream_ids( |
| 703 | {kStreamId2}); |
| 704 | |
| 705 | // Set the remote description and verify that the stream was updated properly. |
| 706 | ASSERT_TRUE( |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 707 | callee->SetRemoteDescription(CloneSessionDescription(offer.get()))); |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 708 | auto receivers = callee->pc()->GetReceivers(); |
| 709 | ASSERT_EQ(receivers.size(), 1u); |
| 710 | ASSERT_EQ(receivers[0]->streams().size(), 1u); |
| 711 | EXPECT_EQ(receivers[0]->streams()[0]->id(), kStreamId2); |
| 712 | } |
| 713 | |
| 714 | // This tests a regression caught by a downstream client, that occured when |
| 715 | // applying a remote description with a SessionDescription object that |
| 716 | // contained StreamParams that didn't have ids. Although there were multiple |
| 717 | // remote audio senders, FindSenderInfo didn't find them as unique, because |
| 718 | // it looked up by StreamParam.id, which none had. This meant only one |
| 719 | // AudioRtpReceiver was created, as opposed to one for each remote sender. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 720 | TEST_F(PeerConnectionRtpTestPlanB, |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 721 | MultipleRemoteSendersWithoutStreamParamIdAddsMultipleReceivers) { |
| 722 | auto caller = CreatePeerConnection(); |
| 723 | auto callee = CreatePeerConnection(); |
| 724 | |
| 725 | const char kStreamId1[] = "stream1"; |
| 726 | const char kStreamId2[] = "stream2"; |
| 727 | caller->AddAudioTrack("audio_track1", {kStreamId1}); |
| 728 | caller->AddAudioTrack("audio_track2", {kStreamId2}); |
| 729 | |
| 730 | auto offer = caller->CreateOfferAndSetAsLocal(); |
| 731 | auto mutable_streams = |
| 732 | cricket::GetFirstAudioContentDescription(offer->description()) |
| 733 | ->mutable_streams(); |
| 734 | ASSERT_EQ(mutable_streams.size(), 2u); |
| 735 | // Clear the IDs in the StreamParams. |
| 736 | mutable_streams[0].id.clear(); |
| 737 | mutable_streams[1].id.clear(); |
| 738 | ASSERT_TRUE( |
| 739 | callee->SetRemoteDescription(CloneSessionDescription(offer.get()))); |
| 740 | |
| 741 | auto receivers = callee->pc()->GetReceivers(); |
| 742 | ASSERT_EQ(receivers.size(), 2u); |
| 743 | ASSERT_EQ(receivers[0]->streams().size(), 1u); |
| 744 | EXPECT_EQ(kStreamId1, receivers[0]->streams()[0]->id()); |
| 745 | ASSERT_EQ(receivers[1]->streams().size(), 1u); |
| 746 | EXPECT_EQ(kStreamId2, receivers[1]->streams()[0]->id()); |
| 747 | } |
| 748 | |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 749 | // Tests for the legacy SetRemoteDescription() function signature. |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 750 | |
| 751 | // Sanity test making sure the callback is invoked. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 752 | TEST_P(PeerConnectionRtpTest, LegacyObserverOnSuccess) { |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 753 | auto caller = CreatePeerConnection(); |
| 754 | auto callee = CreatePeerConnection(); |
| 755 | |
| 756 | std::string error; |
| 757 | ASSERT_TRUE( |
| 758 | callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal(), &error)); |
| 759 | } |
| 760 | |
| 761 | // Verifies legacy behavior: The observer is not called if if the peer |
| 762 | // connection is destroyed because the asynchronous callback is executed in the |
| 763 | // peer connection's message handler. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 764 | TEST_P(PeerConnectionRtpTest, |
| 765 | LegacyObserverNotCalledIfPeerConnectionDereferenced) { |
Henrik Boström | 3163867 | 2017-11-23 17:48:32 +0100 | [diff] [blame] | 766 | auto caller = CreatePeerConnection(); |
| 767 | auto callee = CreatePeerConnection(); |
| 768 | |
| 769 | rtc::scoped_refptr<webrtc::MockSetSessionDescriptionObserver> observer = |
| 770 | new rtc::RefCountedObject<webrtc::MockSetSessionDescriptionObserver>(); |
| 771 | |
| 772 | auto offer = caller->CreateOfferAndSetAsLocal(); |
| 773 | callee->pc()->SetRemoteDescription(observer, offer.release()); |
| 774 | callee = nullptr; |
| 775 | rtc::Thread::Current()->ProcessMessages(0); |
| 776 | EXPECT_FALSE(observer->called()); |
| 777 | } |
| 778 | |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 779 | // RtpTransceiver Tests. |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 780 | |
| 781 | // Test that by default there are no transceivers with Unified Plan. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 782 | TEST_F(PeerConnectionRtpTestUnifiedPlan, PeerConnectionHasNoTransceivers) { |
| 783 | auto caller = CreatePeerConnection(); |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 784 | EXPECT_THAT(caller->pc()->GetTransceivers(), ElementsAre()); |
| 785 | } |
| 786 | |
| 787 | // Test that a transceiver created with the audio kind has the correct initial |
| 788 | // properties. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 789 | TEST_F(PeerConnectionRtpTestUnifiedPlan, |
| 790 | AddTransceiverHasCorrectInitProperties) { |
| 791 | auto caller = CreatePeerConnection(); |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 792 | |
| 793 | auto transceiver = caller->AddTransceiver(cricket::MEDIA_TYPE_AUDIO); |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 794 | EXPECT_EQ(absl::nullopt, transceiver->mid()); |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 795 | EXPECT_FALSE(transceiver->stopped()); |
| 796 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, transceiver->direction()); |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 797 | EXPECT_EQ(absl::nullopt, transceiver->current_direction()); |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | // Test that adding a transceiver with the audio kind creates an audio sender |
| 801 | // and audio receiver with the receiver having a live audio track. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 802 | TEST_F(PeerConnectionRtpTestUnifiedPlan, |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 803 | AddAudioTransceiverCreatesAudioSenderAndReceiver) { |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 804 | auto caller = CreatePeerConnection(); |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 805 | |
| 806 | auto transceiver = caller->AddTransceiver(cricket::MEDIA_TYPE_AUDIO); |
Steve Anton | 6947025 | 2018-02-09 11:43:08 -0800 | [diff] [blame] | 807 | EXPECT_EQ(cricket::MEDIA_TYPE_AUDIO, transceiver->media_type()); |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 808 | |
| 809 | ASSERT_TRUE(transceiver->sender()); |
| 810 | EXPECT_EQ(cricket::MEDIA_TYPE_AUDIO, transceiver->sender()->media_type()); |
| 811 | |
| 812 | ASSERT_TRUE(transceiver->receiver()); |
| 813 | EXPECT_EQ(cricket::MEDIA_TYPE_AUDIO, transceiver->receiver()->media_type()); |
| 814 | |
| 815 | auto track = transceiver->receiver()->track(); |
| 816 | ASSERT_TRUE(track); |
| 817 | EXPECT_EQ(MediaStreamTrackInterface::kAudioKind, track->kind()); |
| 818 | EXPECT_EQ(MediaStreamTrackInterface::TrackState::kLive, track->state()); |
| 819 | } |
| 820 | |
| 821 | // Test that adding a transceiver with the video kind creates an video sender |
| 822 | // and video receiver with the receiver having a live video track. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 823 | TEST_F(PeerConnectionRtpTestUnifiedPlan, |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 824 | AddAudioTransceiverCreatesVideoSenderAndReceiver) { |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 825 | auto caller = CreatePeerConnection(); |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 826 | |
| 827 | auto transceiver = caller->AddTransceiver(cricket::MEDIA_TYPE_VIDEO); |
Steve Anton | 6947025 | 2018-02-09 11:43:08 -0800 | [diff] [blame] | 828 | EXPECT_EQ(cricket::MEDIA_TYPE_VIDEO, transceiver->media_type()); |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 829 | |
| 830 | ASSERT_TRUE(transceiver->sender()); |
| 831 | EXPECT_EQ(cricket::MEDIA_TYPE_VIDEO, transceiver->sender()->media_type()); |
| 832 | |
| 833 | ASSERT_TRUE(transceiver->receiver()); |
| 834 | EXPECT_EQ(cricket::MEDIA_TYPE_VIDEO, transceiver->receiver()->media_type()); |
| 835 | |
| 836 | auto track = transceiver->receiver()->track(); |
| 837 | ASSERT_TRUE(track); |
| 838 | EXPECT_EQ(MediaStreamTrackInterface::kVideoKind, track->kind()); |
| 839 | EXPECT_EQ(MediaStreamTrackInterface::TrackState::kLive, track->state()); |
| 840 | } |
| 841 | |
| 842 | // Test that after a call to AddTransceiver, the transceiver shows in |
| 843 | // GetTransceivers(), the transceiver's sender shows in GetSenders(), and the |
| 844 | // transceiver's receiver shows in GetReceivers(). |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 845 | TEST_F(PeerConnectionRtpTestUnifiedPlan, AddTransceiverShowsInLists) { |
| 846 | auto caller = CreatePeerConnection(); |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 847 | |
| 848 | auto transceiver = caller->AddTransceiver(cricket::MEDIA_TYPE_AUDIO); |
| 849 | EXPECT_EQ( |
| 850 | std::vector<rtc::scoped_refptr<RtpTransceiverInterface>>{transceiver}, |
| 851 | caller->pc()->GetTransceivers()); |
| 852 | EXPECT_EQ( |
| 853 | std::vector<rtc::scoped_refptr<RtpSenderInterface>>{ |
| 854 | transceiver->sender()}, |
| 855 | caller->pc()->GetSenders()); |
| 856 | EXPECT_EQ( |
| 857 | std::vector<rtc::scoped_refptr<RtpReceiverInterface>>{ |
| 858 | transceiver->receiver()}, |
| 859 | caller->pc()->GetReceivers()); |
| 860 | } |
| 861 | |
| 862 | // Test that the direction passed in through the AddTransceiver init parameter |
| 863 | // is set in the returned transceiver. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 864 | TEST_F(PeerConnectionRtpTestUnifiedPlan, |
| 865 | AddTransceiverWithDirectionIsReflected) { |
| 866 | auto caller = CreatePeerConnection(); |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 867 | |
| 868 | RtpTransceiverInit init; |
| 869 | init.direction = RtpTransceiverDirection::kSendOnly; |
| 870 | auto transceiver = caller->AddTransceiver(cricket::MEDIA_TYPE_AUDIO, init); |
| 871 | EXPECT_EQ(RtpTransceiverDirection::kSendOnly, transceiver->direction()); |
| 872 | } |
| 873 | |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 874 | // Test that calling AddTransceiver with a track creates a transceiver which has |
| 875 | // its sender's track set to the passed-in track. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 876 | TEST_F(PeerConnectionRtpTestUnifiedPlan, |
| 877 | AddTransceiverWithTrackCreatesSenderWithTrack) { |
| 878 | auto caller = CreatePeerConnection(); |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 879 | |
| 880 | auto audio_track = caller->CreateAudioTrack("audio track"); |
| 881 | auto transceiver = caller->AddTransceiver(audio_track); |
| 882 | |
| 883 | auto sender = transceiver->sender(); |
| 884 | ASSERT_TRUE(sender->track()); |
| 885 | EXPECT_EQ(audio_track, sender->track()); |
| 886 | |
| 887 | auto receiver = transceiver->receiver(); |
| 888 | ASSERT_TRUE(receiver->track()); |
| 889 | EXPECT_EQ(MediaStreamTrackInterface::kAudioKind, receiver->track()->kind()); |
| 890 | EXPECT_EQ(MediaStreamTrackInterface::TrackState::kLive, |
| 891 | receiver->track()->state()); |
| 892 | } |
| 893 | |
| 894 | // Test that calling AddTransceiver twice with the same track creates distinct |
| 895 | // transceivers, senders with the same track. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 896 | TEST_F(PeerConnectionRtpTestUnifiedPlan, |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 897 | AddTransceiverTwiceWithSameTrackCreatesMultipleTransceivers) { |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 898 | auto caller = CreatePeerConnection(); |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 899 | |
| 900 | auto audio_track = caller->CreateAudioTrack("audio track"); |
| 901 | |
| 902 | auto transceiver1 = caller->AddTransceiver(audio_track); |
| 903 | auto transceiver2 = caller->AddTransceiver(audio_track); |
| 904 | |
| 905 | EXPECT_NE(transceiver1, transceiver2); |
| 906 | |
| 907 | auto sender1 = transceiver1->sender(); |
| 908 | auto sender2 = transceiver2->sender(); |
| 909 | EXPECT_NE(sender1, sender2); |
| 910 | EXPECT_EQ(audio_track, sender1->track()); |
| 911 | EXPECT_EQ(audio_track, sender2->track()); |
| 912 | |
| 913 | EXPECT_THAT(caller->pc()->GetTransceivers(), |
| 914 | UnorderedElementsAre(transceiver1, transceiver2)); |
| 915 | EXPECT_THAT(caller->pc()->GetSenders(), |
| 916 | UnorderedElementsAre(sender1, sender2)); |
| 917 | } |
| 918 | |
Steve Anton | 3fe1b15 | 2017-12-12 10:20:08 -0800 | [diff] [blame] | 919 | // RtpTransceiver error handling tests. |
| 920 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 921 | TEST_F(PeerConnectionRtpTestUnifiedPlan, |
| 922 | AddTransceiverWithInvalidKindReturnsError) { |
| 923 | auto caller = CreatePeerConnection(); |
Steve Anton | 3fe1b15 | 2017-12-12 10:20:08 -0800 | [diff] [blame] | 924 | |
| 925 | auto result = caller->pc()->AddTransceiver(cricket::MEDIA_TYPE_DATA); |
| 926 | EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, result.error().type()); |
| 927 | } |
| 928 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 929 | TEST_F(PeerConnectionRtpTestUnifiedPlan, |
| 930 | CanClosePeerConnectionWithoutCrashing) { |
| 931 | auto caller = CreatePeerConnection(); |
Steve Anton | 3fe1b15 | 2017-12-12 10:20:08 -0800 | [diff] [blame] | 932 | |
| 933 | caller->pc()->Close(); |
| 934 | } |
| 935 | |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 936 | // Unified Plan AddTrack tests. |
| 937 | |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 938 | // Test that adding an audio track creates a new audio RtpSender with the given |
| 939 | // track. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 940 | TEST_F(PeerConnectionRtpTestUnifiedPlan, AddAudioTrackCreatesAudioSender) { |
| 941 | auto caller = CreatePeerConnection(); |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 942 | |
| 943 | auto audio_track = caller->CreateAudioTrack("a"); |
Steve Anton | 2d6c76a | 2018-01-05 17:10:52 -0800 | [diff] [blame] | 944 | auto sender = caller->AddTrack(audio_track); |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 945 | ASSERT_TRUE(sender); |
| 946 | |
| 947 | EXPECT_EQ(cricket::MEDIA_TYPE_AUDIO, sender->media_type()); |
| 948 | EXPECT_EQ(audio_track, sender->track()); |
| 949 | } |
| 950 | |
| 951 | // Test that adding a video track creates a new video RtpSender with the given |
| 952 | // track. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 953 | TEST_F(PeerConnectionRtpTestUnifiedPlan, AddVideoTrackCreatesVideoSender) { |
| 954 | auto caller = CreatePeerConnection(); |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 955 | |
| 956 | auto video_track = caller->CreateVideoTrack("a"); |
Steve Anton | 2d6c76a | 2018-01-05 17:10:52 -0800 | [diff] [blame] | 957 | auto sender = caller->AddTrack(video_track); |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 958 | ASSERT_TRUE(sender); |
| 959 | |
| 960 | EXPECT_EQ(cricket::MEDIA_TYPE_VIDEO, sender->media_type()); |
| 961 | EXPECT_EQ(video_track, sender->track()); |
| 962 | } |
| 963 | |
| 964 | // Test that adding a track to a new PeerConnection creates an RtpTransceiver |
| 965 | // with the sender that AddTrack returns and in the sendrecv direction. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 966 | TEST_F(PeerConnectionRtpTestUnifiedPlan, AddFirstTrackCreatesTransceiver) { |
| 967 | auto caller = CreatePeerConnection(); |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 968 | |
| 969 | auto sender = caller->AddAudioTrack("a"); |
| 970 | ASSERT_TRUE(sender); |
| 971 | |
| 972 | auto transceivers = caller->pc()->GetTransceivers(); |
| 973 | ASSERT_EQ(1u, transceivers.size()); |
| 974 | EXPECT_EQ(sender, transceivers[0]->sender()); |
| 975 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, transceivers[0]->direction()); |
| 976 | } |
| 977 | |
| 978 | // Test that if a transceiver of the same type but no track had been added to |
| 979 | // the PeerConnection and later a call to AddTrack is made, the resulting sender |
| 980 | // is the transceiver's sender and the sender's track is the newly-added track. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 981 | TEST_F(PeerConnectionRtpTestUnifiedPlan, AddTrackReusesTransceiver) { |
| 982 | auto caller = CreatePeerConnection(); |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 983 | |
| 984 | auto transceiver = caller->AddTransceiver(cricket::MEDIA_TYPE_AUDIO); |
| 985 | auto audio_track = caller->CreateAudioTrack("a"); |
Steve Anton | 2d6c76a | 2018-01-05 17:10:52 -0800 | [diff] [blame] | 986 | auto sender = caller->AddTrack(audio_track); |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 987 | ASSERT_TRUE(sender); |
| 988 | |
| 989 | auto transceivers = caller->pc()->GetTransceivers(); |
| 990 | ASSERT_EQ(1u, transceivers.size()); |
| 991 | EXPECT_EQ(transceiver, transceivers[0]); |
| 992 | EXPECT_EQ(sender, transceiver->sender()); |
| 993 | EXPECT_EQ(audio_track, sender->track()); |
| 994 | } |
| 995 | |
| 996 | // Test that adding two tracks to a new PeerConnection creates two |
| 997 | // RtpTransceivers in the same order. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 998 | TEST_F(PeerConnectionRtpTestUnifiedPlan, TwoAddTrackCreatesTwoTransceivers) { |
| 999 | auto caller = CreatePeerConnection(); |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 1000 | |
| 1001 | auto sender1 = caller->AddAudioTrack("a"); |
| 1002 | auto sender2 = caller->AddVideoTrack("v"); |
| 1003 | ASSERT_TRUE(sender2); |
| 1004 | |
| 1005 | auto transceivers = caller->pc()->GetTransceivers(); |
| 1006 | ASSERT_EQ(2u, transceivers.size()); |
| 1007 | EXPECT_EQ(sender1, transceivers[0]->sender()); |
| 1008 | EXPECT_EQ(sender2, transceivers[1]->sender()); |
| 1009 | } |
| 1010 | |
| 1011 | // Test that if there are multiple transceivers with no sending track then a |
| 1012 | // later call to AddTrack will use the one of the same type as the newly-added |
| 1013 | // track. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1014 | TEST_F(PeerConnectionRtpTestUnifiedPlan, AddTrackReusesTransceiverOfType) { |
| 1015 | auto caller = CreatePeerConnection(); |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 1016 | |
| 1017 | auto audio_transceiver = caller->AddTransceiver(cricket::MEDIA_TYPE_AUDIO); |
| 1018 | auto video_transceiver = caller->AddTransceiver(cricket::MEDIA_TYPE_VIDEO); |
| 1019 | auto sender = caller->AddVideoTrack("v"); |
| 1020 | |
| 1021 | ASSERT_EQ(2u, caller->pc()->GetTransceivers().size()); |
| 1022 | EXPECT_NE(sender, audio_transceiver->sender()); |
| 1023 | EXPECT_EQ(sender, video_transceiver->sender()); |
| 1024 | } |
| 1025 | |
| 1026 | // Test that if the only transceivers that do not have a sending track have a |
| 1027 | // different type from the added track, then AddTrack will create a new |
| 1028 | // transceiver for the track. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1029 | TEST_F(PeerConnectionRtpTestUnifiedPlan, |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 1030 | AddTrackDoesNotReuseTransceiverOfWrongType) { |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1031 | auto caller = CreatePeerConnection(); |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 1032 | |
| 1033 | caller->AddTransceiver(cricket::MEDIA_TYPE_AUDIO); |
| 1034 | auto sender = caller->AddVideoTrack("v"); |
| 1035 | |
| 1036 | auto transceivers = caller->pc()->GetTransceivers(); |
| 1037 | ASSERT_EQ(2u, transceivers.size()); |
| 1038 | EXPECT_NE(sender, transceivers[0]->sender()); |
| 1039 | EXPECT_EQ(sender, transceivers[1]->sender()); |
| 1040 | } |
| 1041 | |
| 1042 | // Test that the first available transceiver is reused by AddTrack when multiple |
| 1043 | // are available. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1044 | TEST_F(PeerConnectionRtpTestUnifiedPlan, |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 1045 | AddTrackReusesFirstMatchingTransceiver) { |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1046 | auto caller = CreatePeerConnection(); |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 1047 | |
| 1048 | caller->AddTransceiver(cricket::MEDIA_TYPE_AUDIO); |
| 1049 | caller->AddTransceiver(cricket::MEDIA_TYPE_AUDIO); |
| 1050 | auto sender = caller->AddAudioTrack("a"); |
| 1051 | |
| 1052 | auto transceivers = caller->pc()->GetTransceivers(); |
| 1053 | ASSERT_EQ(2u, transceivers.size()); |
| 1054 | EXPECT_EQ(sender, transceivers[0]->sender()); |
| 1055 | EXPECT_NE(sender, transceivers[1]->sender()); |
| 1056 | } |
| 1057 | |
| 1058 | // Test that a call to AddTrack that reuses a transceiver will change the |
| 1059 | // direction from inactive to sendonly. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1060 | TEST_F(PeerConnectionRtpTestUnifiedPlan, |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 1061 | AddTrackChangesDirectionFromInactiveToSendOnly) { |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1062 | auto caller = CreatePeerConnection(); |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 1063 | |
| 1064 | RtpTransceiverInit init; |
| 1065 | init.direction = RtpTransceiverDirection::kInactive; |
| 1066 | auto transceiver = caller->AddTransceiver(cricket::MEDIA_TYPE_AUDIO, init); |
| 1067 | |
| 1068 | caller->observer()->clear_negotiation_needed(); |
| 1069 | ASSERT_TRUE(caller->AddAudioTrack("a")); |
| 1070 | EXPECT_TRUE(caller->observer()->negotiation_needed()); |
| 1071 | |
| 1072 | EXPECT_EQ(RtpTransceiverDirection::kSendOnly, transceiver->direction()); |
| 1073 | } |
| 1074 | |
| 1075 | // Test that a call to AddTrack that reuses a transceiver will change the |
| 1076 | // direction from recvonly to sendrecv. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1077 | TEST_F(PeerConnectionRtpTestUnifiedPlan, |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 1078 | AddTrackChangesDirectionFromRecvOnlyToSendRecv) { |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1079 | auto caller = CreatePeerConnection(); |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 1080 | |
| 1081 | RtpTransceiverInit init; |
| 1082 | init.direction = RtpTransceiverDirection::kRecvOnly; |
| 1083 | auto transceiver = caller->AddTransceiver(cricket::MEDIA_TYPE_AUDIO, init); |
| 1084 | |
| 1085 | caller->observer()->clear_negotiation_needed(); |
| 1086 | ASSERT_TRUE(caller->AddAudioTrack("a")); |
| 1087 | EXPECT_TRUE(caller->observer()->negotiation_needed()); |
| 1088 | |
| 1089 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, transceiver->direction()); |
| 1090 | } |
| 1091 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1092 | TEST_F(PeerConnectionRtpTestUnifiedPlan, AddTrackCreatesSenderWithTrackId) { |
Steve Anton | 02ee47c | 2018-01-10 16:26:06 -0800 | [diff] [blame] | 1093 | const std::string kTrackId = "audio_track"; |
| 1094 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1095 | auto caller = CreatePeerConnection(); |
Steve Anton | 02ee47c | 2018-01-10 16:26:06 -0800 | [diff] [blame] | 1096 | |
| 1097 | auto audio_track = caller->CreateAudioTrack(kTrackId); |
| 1098 | auto sender = caller->AddTrack(audio_track); |
| 1099 | |
| 1100 | EXPECT_EQ(kTrackId, sender->id()); |
| 1101 | } |
| 1102 | |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 1103 | // Unified Plan AddTrack error handling. |
| 1104 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1105 | TEST_F(PeerConnectionRtpTestUnifiedPlan, AddTrackErrorIfClosed) { |
| 1106 | auto caller = CreatePeerConnection(); |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 1107 | |
| 1108 | auto audio_track = caller->CreateAudioTrack("a"); |
| 1109 | caller->pc()->Close(); |
| 1110 | |
| 1111 | caller->observer()->clear_negotiation_needed(); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1112 | auto result = caller->pc()->AddTrack(audio_track, std::vector<std::string>()); |
Steve Anton | 2d6c76a | 2018-01-05 17:10:52 -0800 | [diff] [blame] | 1113 | EXPECT_EQ(RTCErrorType::INVALID_STATE, result.error().type()); |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 1114 | EXPECT_FALSE(caller->observer()->negotiation_needed()); |
| 1115 | } |
| 1116 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1117 | TEST_F(PeerConnectionRtpTestUnifiedPlan, AddTrackErrorIfTrackAlreadyHasSender) { |
| 1118 | auto caller = CreatePeerConnection(); |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 1119 | |
| 1120 | auto audio_track = caller->CreateAudioTrack("a"); |
Steve Anton | 2d6c76a | 2018-01-05 17:10:52 -0800 | [diff] [blame] | 1121 | ASSERT_TRUE(caller->AddTrack(audio_track)); |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 1122 | |
| 1123 | caller->observer()->clear_negotiation_needed(); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1124 | auto result = caller->pc()->AddTrack(audio_track, std::vector<std::string>()); |
Steve Anton | 2d6c76a | 2018-01-05 17:10:52 -0800 | [diff] [blame] | 1125 | EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, result.error().type()); |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 1126 | EXPECT_FALSE(caller->observer()->negotiation_needed()); |
| 1127 | } |
| 1128 | |
| 1129 | // Unified Plan RemoveTrack tests. |
| 1130 | |
| 1131 | // Test that calling RemoveTrack on a sender with a previously-added track |
| 1132 | // clears the sender's track. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1133 | TEST_F(PeerConnectionRtpTestUnifiedPlan, RemoveTrackClearsSenderTrack) { |
| 1134 | auto caller = CreatePeerConnection(); |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 1135 | |
| 1136 | auto sender = caller->AddAudioTrack("a"); |
| 1137 | ASSERT_TRUE(caller->pc()->RemoveTrack(sender)); |
| 1138 | |
| 1139 | EXPECT_FALSE(sender->track()); |
| 1140 | } |
| 1141 | |
| 1142 | // Test that calling RemoveTrack on a sender where the transceiver is configured |
| 1143 | // in the sendrecv direction changes the transceiver's direction to recvonly. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1144 | TEST_F(PeerConnectionRtpTestUnifiedPlan, |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 1145 | RemoveTrackChangesDirectionFromSendRecvToRecvOnly) { |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1146 | auto caller = CreatePeerConnection(); |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 1147 | |
| 1148 | RtpTransceiverInit init; |
| 1149 | init.direction = RtpTransceiverDirection::kSendRecv; |
| 1150 | auto transceiver = |
| 1151 | caller->AddTransceiver(caller->CreateAudioTrack("a"), init); |
| 1152 | |
| 1153 | caller->observer()->clear_negotiation_needed(); |
| 1154 | ASSERT_TRUE(caller->pc()->RemoveTrack(transceiver->sender())); |
| 1155 | EXPECT_TRUE(caller->observer()->negotiation_needed()); |
| 1156 | |
| 1157 | EXPECT_EQ(RtpTransceiverDirection::kRecvOnly, transceiver->direction()); |
| 1158 | EXPECT_TRUE(caller->observer()->renegotiation_needed_); |
| 1159 | } |
| 1160 | |
| 1161 | // Test that calling RemoveTrack on a sender where the transceiver is configured |
| 1162 | // in the sendonly direction changes the transceiver's direction to inactive. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1163 | TEST_F(PeerConnectionRtpTestUnifiedPlan, |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 1164 | RemoveTrackChangesDirectionFromSendOnlyToInactive) { |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1165 | auto caller = CreatePeerConnection(); |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 1166 | |
| 1167 | RtpTransceiverInit init; |
| 1168 | init.direction = RtpTransceiverDirection::kSendOnly; |
| 1169 | auto transceiver = |
| 1170 | caller->AddTransceiver(caller->CreateAudioTrack("a"), init); |
| 1171 | |
| 1172 | caller->observer()->clear_negotiation_needed(); |
| 1173 | ASSERT_TRUE(caller->pc()->RemoveTrack(transceiver->sender())); |
| 1174 | EXPECT_TRUE(caller->observer()->negotiation_needed()); |
| 1175 | |
| 1176 | EXPECT_EQ(RtpTransceiverDirection::kInactive, transceiver->direction()); |
| 1177 | } |
| 1178 | |
| 1179 | // Test that calling RemoveTrack with a sender that has a null track results in |
| 1180 | // no change in state. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1181 | TEST_F(PeerConnectionRtpTestUnifiedPlan, RemoveTrackWithNullSenderTrackIsNoOp) { |
| 1182 | auto caller = CreatePeerConnection(); |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 1183 | |
| 1184 | auto sender = caller->AddAudioTrack("a"); |
| 1185 | auto transceiver = caller->pc()->GetTransceivers()[0]; |
| 1186 | ASSERT_TRUE(sender->SetTrack(nullptr)); |
| 1187 | |
| 1188 | caller->observer()->clear_negotiation_needed(); |
| 1189 | ASSERT_TRUE(caller->pc()->RemoveTrack(sender)); |
| 1190 | EXPECT_FALSE(caller->observer()->negotiation_needed()); |
| 1191 | |
| 1192 | EXPECT_EQ(RtpTransceiverDirection::kSendRecv, transceiver->direction()); |
| 1193 | } |
| 1194 | |
| 1195 | // Unified Plan RemoveTrack error handling. |
| 1196 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1197 | TEST_F(PeerConnectionRtpTestUnifiedPlan, RemoveTrackErrorIfClosed) { |
| 1198 | auto caller = CreatePeerConnection(); |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 1199 | |
| 1200 | auto sender = caller->AddAudioTrack("a"); |
| 1201 | caller->pc()->Close(); |
| 1202 | |
| 1203 | caller->observer()->clear_negotiation_needed(); |
| 1204 | EXPECT_FALSE(caller->pc()->RemoveTrack(sender)); |
| 1205 | EXPECT_FALSE(caller->observer()->negotiation_needed()); |
| 1206 | } |
| 1207 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1208 | TEST_F(PeerConnectionRtpTestUnifiedPlan, |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 1209 | RemoveTrackNoErrorIfTrackAlreadyRemoved) { |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1210 | auto caller = CreatePeerConnection(); |
Steve Anton | f9381f0 | 2017-12-14 10:23:57 -0800 | [diff] [blame] | 1211 | |
| 1212 | auto sender = caller->AddAudioTrack("a"); |
| 1213 | ASSERT_TRUE(caller->pc()->RemoveTrack(sender)); |
| 1214 | |
| 1215 | caller->observer()->clear_negotiation_needed(); |
| 1216 | EXPECT_TRUE(caller->pc()->RemoveTrack(sender)); |
| 1217 | EXPECT_FALSE(caller->observer()->negotiation_needed()); |
| 1218 | } |
| 1219 | |
Steve Anton | 60b6c1d | 2018-06-13 11:32:27 -0700 | [diff] [blame] | 1220 | // Test that setting offers that add/remove/add a track repeatedly without |
| 1221 | // setting the appropriate answer in between works. |
| 1222 | // These are regression tests for bugs.webrtc.org/9401 |
| 1223 | TEST_F(PeerConnectionRtpTestUnifiedPlan, AddRemoveAddTrackOffersWorksAudio) { |
| 1224 | auto caller = CreatePeerConnection(); |
| 1225 | |
| 1226 | auto sender1 = caller->AddAudioTrack("audio1"); |
| 1227 | ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer())); |
| 1228 | |
| 1229 | caller->pc()->RemoveTrack(sender1); |
| 1230 | ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer())); |
| 1231 | |
| 1232 | // This will re-use the transceiver created by the first AddTrack. |
| 1233 | auto sender2 = caller->AddAudioTrack("audio2"); |
| 1234 | ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer())); |
| 1235 | |
| 1236 | EXPECT_EQ(1u, caller->pc()->GetTransceivers().size()); |
| 1237 | EXPECT_EQ(sender1, sender2); |
| 1238 | } |
| 1239 | TEST_F(PeerConnectionRtpTestUnifiedPlan, AddRemoveAddTrackOffersWorksVideo) { |
| 1240 | auto caller = CreatePeerConnection(); |
| 1241 | |
| 1242 | auto sender1 = caller->AddVideoTrack("video1"); |
| 1243 | ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer())); |
| 1244 | |
| 1245 | caller->pc()->RemoveTrack(sender1); |
| 1246 | ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer())); |
| 1247 | |
| 1248 | // This will re-use the transceiver created by the first AddTrack. |
| 1249 | auto sender2 = caller->AddVideoTrack("video2"); |
| 1250 | ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer())); |
| 1251 | |
| 1252 | EXPECT_EQ(1u, caller->pc()->GetTransceivers().size()); |
| 1253 | EXPECT_EQ(sender1, sender2); |
| 1254 | } |
| 1255 | |
Steve Anton | 0756373 | 2018-06-26 11:13:50 -0700 | [diff] [blame] | 1256 | // Test that CreateOffer succeeds if two tracks with the same label are added. |
| 1257 | TEST_F(PeerConnectionRtpTestUnifiedPlan, CreateOfferSameTrackLabel) { |
| 1258 | auto caller = CreatePeerConnection(); |
| 1259 | |
| 1260 | auto audio_sender = caller->AddAudioTrack("track", {}); |
| 1261 | auto video_sender = caller->AddVideoTrack("track", {}); |
| 1262 | |
| 1263 | EXPECT_TRUE(caller->CreateOffer()); |
| 1264 | |
| 1265 | EXPECT_EQ(audio_sender->track()->id(), video_sender->track()->id()); |
| 1266 | EXPECT_NE(audio_sender->id(), video_sender->id()); |
| 1267 | } |
| 1268 | |
| 1269 | // Test that CreateAnswer succeeds if two tracks with the same label are added. |
| 1270 | TEST_F(PeerConnectionRtpTestUnifiedPlan, CreateAnswerSameTrackLabel) { |
| 1271 | auto caller = CreatePeerConnection(); |
| 1272 | auto callee = CreatePeerConnection(); |
| 1273 | |
| 1274 | RtpTransceiverInit recvonly; |
| 1275 | recvonly.direction = RtpTransceiverDirection::kRecvOnly; |
| 1276 | caller->AddTransceiver(cricket::MEDIA_TYPE_AUDIO, recvonly); |
| 1277 | caller->AddTransceiver(cricket::MEDIA_TYPE_VIDEO, recvonly); |
| 1278 | |
| 1279 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOffer())); |
| 1280 | |
| 1281 | auto audio_sender = callee->AddAudioTrack("track", {}); |
| 1282 | auto video_sender = callee->AddVideoTrack("track", {}); |
| 1283 | |
| 1284 | EXPECT_TRUE(callee->CreateAnswer()); |
| 1285 | |
| 1286 | EXPECT_EQ(audio_sender->track()->id(), video_sender->track()->id()); |
| 1287 | EXPECT_NE(audio_sender->id(), video_sender->id()); |
| 1288 | } |
| 1289 | |
| 1290 | // Test that calling AddTrack, RemoveTrack and AddTrack again creates a second |
| 1291 | // m= section with a random sender id (different from the first, now rejected, |
| 1292 | // m= section). |
| 1293 | TEST_F(PeerConnectionRtpTestUnifiedPlan, |
| 1294 | AddRemoveAddTrackGeneratesNewSenderId) { |
| 1295 | auto caller = CreatePeerConnection(); |
| 1296 | auto callee = CreatePeerConnection(); |
| 1297 | |
| 1298 | auto track = caller->CreateVideoTrack("video"); |
| 1299 | auto sender1 = caller->AddTrack(track); |
| 1300 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 1301 | |
| 1302 | caller->pc()->RemoveTrack(sender1); |
| 1303 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 1304 | |
| 1305 | auto sender2 = caller->AddTrack(track); |
| 1306 | |
| 1307 | EXPECT_NE(sender1, sender2); |
| 1308 | EXPECT_NE(sender1->id(), sender2->id()); |
| 1309 | std::string sender2_id = sender2->id(); |
| 1310 | |
| 1311 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 1312 | |
| 1313 | // The sender's ID should not change after negotiation. |
| 1314 | EXPECT_EQ(sender2_id, sender2->id()); |
| 1315 | } |
| 1316 | |
Steve Anton | 52d8677 | 2018-02-20 15:48:12 -0800 | [diff] [blame] | 1317 | // Test that OnRenegotiationNeeded is fired if SetDirection is called on an |
| 1318 | // active RtpTransceiver with a new direction. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1319 | TEST_F(PeerConnectionRtpTestUnifiedPlan, |
Steve Anton | 52d8677 | 2018-02-20 15:48:12 -0800 | [diff] [blame] | 1320 | RenegotiationNeededAfterTransceiverSetDirection) { |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1321 | auto caller = CreatePeerConnection(); |
Steve Anton | 52d8677 | 2018-02-20 15:48:12 -0800 | [diff] [blame] | 1322 | |
| 1323 | auto transceiver = caller->AddTransceiver(cricket::MEDIA_TYPE_AUDIO); |
| 1324 | |
| 1325 | caller->observer()->clear_negotiation_needed(); |
| 1326 | transceiver->SetDirection(RtpTransceiverDirection::kInactive); |
| 1327 | EXPECT_TRUE(caller->observer()->negotiation_needed()); |
| 1328 | } |
| 1329 | |
| 1330 | // Test that OnRenegotiationNeeded is not fired if SetDirection is called on an |
| 1331 | // active RtpTransceiver with current direction. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1332 | TEST_F(PeerConnectionRtpTestUnifiedPlan, |
Steve Anton | 52d8677 | 2018-02-20 15:48:12 -0800 | [diff] [blame] | 1333 | NoRenegotiationNeededAfterTransceiverSetSameDirection) { |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1334 | auto caller = CreatePeerConnection(); |
Steve Anton | 52d8677 | 2018-02-20 15:48:12 -0800 | [diff] [blame] | 1335 | |
| 1336 | auto transceiver = caller->AddTransceiver(cricket::MEDIA_TYPE_AUDIO); |
| 1337 | |
| 1338 | caller->observer()->clear_negotiation_needed(); |
| 1339 | transceiver->SetDirection(transceiver->direction()); |
| 1340 | EXPECT_FALSE(caller->observer()->negotiation_needed()); |
| 1341 | } |
| 1342 | |
| 1343 | // Test that OnRenegotiationNeeded is not fired if SetDirection is called on a |
| 1344 | // stopped RtpTransceiver. |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1345 | TEST_F(PeerConnectionRtpTestUnifiedPlan, |
Steve Anton | 52d8677 | 2018-02-20 15:48:12 -0800 | [diff] [blame] | 1346 | NoRenegotiationNeededAfterSetDirectionOnStoppedTransceiver) { |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1347 | auto caller = CreatePeerConnection(); |
Steve Anton | 52d8677 | 2018-02-20 15:48:12 -0800 | [diff] [blame] | 1348 | |
| 1349 | auto transceiver = caller->AddTransceiver(cricket::MEDIA_TYPE_AUDIO); |
| 1350 | transceiver->Stop(); |
| 1351 | |
| 1352 | caller->observer()->clear_negotiation_needed(); |
| 1353 | transceiver->SetDirection(RtpTransceiverDirection::kInactive); |
| 1354 | EXPECT_FALSE(caller->observer()->negotiation_needed()); |
| 1355 | } |
| 1356 | |
Steve Anton | e831b8c | 2018-02-01 12:22:16 -0800 | [diff] [blame] | 1357 | // Test MSID signaling between Unified Plan and Plan B endpoints. There are two |
| 1358 | // options for this kind of signaling: media section based (a=msid) and ssrc |
| 1359 | // based (a=ssrc MSID). While JSEP only specifies media section MSID signaling, |
| 1360 | // we want to ensure compatibility with older Plan B endpoints that might expect |
| 1361 | // ssrc based MSID signaling. Thus we test here that Unified Plan offers both |
| 1362 | // types but answers with the same type as the offer. |
| 1363 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1364 | class PeerConnectionMsidSignalingTest |
| 1365 | : public PeerConnectionRtpTestUnifiedPlan {}; |
Steve Anton | e831b8c | 2018-02-01 12:22:16 -0800 | [diff] [blame] | 1366 | |
| 1367 | TEST_F(PeerConnectionMsidSignalingTest, UnifiedPlanTalkingToOurself) { |
| 1368 | auto caller = CreatePeerConnectionWithUnifiedPlan(); |
| 1369 | caller->AddAudioTrack("caller_audio"); |
| 1370 | auto callee = CreatePeerConnectionWithUnifiedPlan(); |
| 1371 | callee->AddAudioTrack("callee_audio"); |
Steve Anton | 8e20f17 | 2018-03-06 10:55:04 -0800 | [diff] [blame] | 1372 | auto caller_observer = caller->RegisterFakeMetricsObserver(); |
Steve Anton | e831b8c | 2018-02-01 12:22:16 -0800 | [diff] [blame] | 1373 | |
| 1374 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 1375 | |
| 1376 | // Offer should have had both a=msid and a=ssrc MSID lines. |
| 1377 | auto* offer = callee->pc()->remote_description(); |
| 1378 | EXPECT_EQ((cricket::kMsidSignalingMediaSection | |
| 1379 | cricket::kMsidSignalingSsrcAttribute), |
| 1380 | offer->description()->msid_signaling()); |
| 1381 | |
| 1382 | // Answer should have had only a=msid lines. |
| 1383 | auto* answer = caller->pc()->remote_description(); |
| 1384 | EXPECT_EQ(cricket::kMsidSignalingMediaSection, |
| 1385 | answer->description()->msid_signaling()); |
Harald Alvestrand | 5dbb586 | 2018-02-13 23:48:00 +0100 | [diff] [blame] | 1386 | // Check that this is counted correctly |
Steve Anton | 8e20f17 | 2018-03-06 10:55:04 -0800 | [diff] [blame] | 1387 | EXPECT_TRUE(caller_observer->ExpectOnlySingleEnumCount( |
| 1388 | kEnumCounterSdpSemanticNegotiated, kSdpSemanticNegotiatedUnifiedPlan)); |
Steve Anton | e831b8c | 2018-02-01 12:22:16 -0800 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | TEST_F(PeerConnectionMsidSignalingTest, PlanBOfferToUnifiedPlanAnswer) { |
| 1392 | auto caller = CreatePeerConnectionWithPlanB(); |
| 1393 | caller->AddAudioTrack("caller_audio"); |
| 1394 | auto callee = CreatePeerConnectionWithUnifiedPlan(); |
| 1395 | callee->AddAudioTrack("callee_audio"); |
| 1396 | |
| 1397 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 1398 | |
| 1399 | // Offer should have only a=ssrc MSID lines. |
| 1400 | auto* offer = callee->pc()->remote_description(); |
| 1401 | EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute, |
| 1402 | offer->description()->msid_signaling()); |
| 1403 | |
| 1404 | // Answer should have only a=ssrc MSID lines to match the offer. |
| 1405 | auto* answer = caller->pc()->remote_description(); |
| 1406 | EXPECT_EQ(cricket::kMsidSignalingSsrcAttribute, |
| 1407 | answer->description()->msid_signaling()); |
| 1408 | } |
| 1409 | |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 1410 | // This tests that a Plan B endpoint appropriately sets the remote description |
| 1411 | // from a Unified Plan offer. When the Unified Plan offer contains a=msid lines |
| 1412 | // that signal no stream ids or multiple stream ids we expect that the Plan B |
| 1413 | // endpoint always has exactly one media stream per track. |
| 1414 | TEST_F(PeerConnectionMsidSignalingTest, UnifiedPlanToPlanBAnswer) { |
| 1415 | const std::string kStreamId1 = "audio_stream_1"; |
| 1416 | const std::string kStreamId2 = "audio_stream_2"; |
| 1417 | |
| 1418 | auto caller = CreatePeerConnectionWithUnifiedPlan(); |
| 1419 | caller->AddAudioTrack("caller_audio", {kStreamId1, kStreamId2}); |
| 1420 | caller->AddVideoTrack("caller_video", {}); |
| 1421 | auto callee = CreatePeerConnectionWithPlanB(); |
| 1422 | callee->AddAudioTrack("callee_audio"); |
| 1423 | caller->AddVideoTrack("callee_video"); |
| 1424 | |
| 1425 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 1426 | |
| 1427 | // Offer should have had both a=msid and a=ssrc MSID lines. |
| 1428 | auto* offer = callee->pc()->remote_description(); |
| 1429 | EXPECT_EQ((cricket::kMsidSignalingMediaSection | |
| 1430 | cricket::kMsidSignalingSsrcAttribute), |
| 1431 | offer->description()->msid_signaling()); |
| 1432 | |
| 1433 | // Callee should always have 1 stream for all of it's receivers. |
| 1434 | const auto& track_events = callee->observer()->add_track_events_; |
| 1435 | ASSERT_EQ(2u, track_events.size()); |
| 1436 | ASSERT_EQ(1u, track_events[0].streams.size()); |
| 1437 | EXPECT_EQ(kStreamId1, track_events[0].streams[0]->id()); |
| 1438 | ASSERT_EQ(1u, track_events[1].streams.size()); |
| 1439 | // This autogenerated a stream id for the empty one signalled. |
| 1440 | EXPECT_FALSE(track_events[1].streams[0]->id().empty()); |
| 1441 | } |
| 1442 | |
Steve Anton | e831b8c | 2018-02-01 12:22:16 -0800 | [diff] [blame] | 1443 | TEST_F(PeerConnectionMsidSignalingTest, PureUnifiedPlanToUs) { |
| 1444 | auto caller = CreatePeerConnectionWithUnifiedPlan(); |
| 1445 | caller->AddAudioTrack("caller_audio"); |
| 1446 | auto callee = CreatePeerConnectionWithUnifiedPlan(); |
| 1447 | callee->AddAudioTrack("callee_audio"); |
| 1448 | |
| 1449 | auto offer = caller->CreateOffer(); |
| 1450 | // Simulate a pure Unified Plan offerer by setting the MSID signaling to media |
| 1451 | // section only. |
| 1452 | offer->description()->set_msid_signaling(cricket::kMsidSignalingMediaSection); |
| 1453 | |
| 1454 | ASSERT_TRUE( |
| 1455 | caller->SetLocalDescription(CloneSessionDescription(offer.get()))); |
| 1456 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 1457 | |
| 1458 | // Answer should have only a=msid to match the offer. |
| 1459 | auto answer = callee->CreateAnswer(); |
| 1460 | EXPECT_EQ(cricket::kMsidSignalingMediaSection, |
| 1461 | answer->description()->msid_signaling()); |
| 1462 | } |
| 1463 | |
Steve Anton | 8e20f17 | 2018-03-06 10:55:04 -0800 | [diff] [blame] | 1464 | // Test that the correct UMA metrics are reported for simple/complex SDP. |
| 1465 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1466 | class SdpFormatReceivedTest : public PeerConnectionRtpTestUnifiedPlan {}; |
Steve Anton | 8e20f17 | 2018-03-06 10:55:04 -0800 | [diff] [blame] | 1467 | |
| 1468 | #ifdef HAVE_SCTP |
| 1469 | TEST_F(SdpFormatReceivedTest, DataChannelOnlyIsReportedAsNoTracks) { |
| 1470 | auto caller = CreatePeerConnectionWithUnifiedPlan(); |
| 1471 | caller->CreateDataChannel("dc"); |
| 1472 | auto callee = CreatePeerConnectionWithUnifiedPlan(); |
| 1473 | auto callee_metrics = callee->RegisterFakeMetricsObserver(); |
| 1474 | |
| 1475 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOffer())); |
| 1476 | |
| 1477 | EXPECT_TRUE(callee_metrics->ExpectOnlySingleEnumCount( |
| 1478 | kEnumCounterSdpFormatReceived, kSdpFormatReceivedNoTracks)); |
| 1479 | } |
| 1480 | #endif // HAVE_SCTP |
| 1481 | |
| 1482 | TEST_F(SdpFormatReceivedTest, SimpleUnifiedPlanIsReportedAsSimple) { |
| 1483 | auto caller = CreatePeerConnectionWithUnifiedPlan(); |
| 1484 | caller->AddAudioTrack("audio"); |
| 1485 | caller->AddVideoTrack("video"); |
| 1486 | auto callee = CreatePeerConnectionWithPlanB(); |
| 1487 | auto callee_metrics = callee->RegisterFakeMetricsObserver(); |
| 1488 | |
| 1489 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOffer())); |
| 1490 | |
| 1491 | EXPECT_TRUE(callee_metrics->ExpectOnlySingleEnumCount( |
| 1492 | kEnumCounterSdpFormatReceived, kSdpFormatReceivedSimple)); |
| 1493 | } |
| 1494 | |
| 1495 | TEST_F(SdpFormatReceivedTest, SimplePlanBIsReportedAsSimple) { |
| 1496 | auto caller = CreatePeerConnectionWithPlanB(); |
| 1497 | caller->AddVideoTrack("video"); // Video only. |
| 1498 | auto callee = CreatePeerConnectionWithUnifiedPlan(); |
| 1499 | auto callee_metrics = callee->RegisterFakeMetricsObserver(); |
| 1500 | |
| 1501 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOffer())); |
| 1502 | |
| 1503 | EXPECT_TRUE(callee_metrics->ExpectOnlySingleEnumCount( |
| 1504 | kEnumCounterSdpFormatReceived, kSdpFormatReceivedSimple)); |
| 1505 | } |
| 1506 | |
| 1507 | TEST_F(SdpFormatReceivedTest, ComplexUnifiedIsReportedAsComplexUnifiedPlan) { |
| 1508 | auto caller = CreatePeerConnectionWithUnifiedPlan(); |
| 1509 | caller->AddAudioTrack("audio1"); |
| 1510 | caller->AddAudioTrack("audio2"); |
| 1511 | caller->AddVideoTrack("video"); |
| 1512 | auto callee = CreatePeerConnectionWithPlanB(); |
| 1513 | auto callee_metrics = callee->RegisterFakeMetricsObserver(); |
| 1514 | |
| 1515 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOffer())); |
| 1516 | |
| 1517 | EXPECT_TRUE(callee_metrics->ExpectOnlySingleEnumCount( |
| 1518 | kEnumCounterSdpFormatReceived, kSdpFormatReceivedComplexUnifiedPlan)); |
| 1519 | } |
| 1520 | |
| 1521 | TEST_F(SdpFormatReceivedTest, ComplexPlanBIsReportedAsComplexPlanB) { |
| 1522 | auto caller = CreatePeerConnectionWithPlanB(); |
| 1523 | caller->AddVideoTrack("video1"); |
| 1524 | caller->AddVideoTrack("video2"); |
| 1525 | auto callee = CreatePeerConnectionWithUnifiedPlan(); |
| 1526 | auto callee_metrics = callee->RegisterFakeMetricsObserver(); |
| 1527 | |
Steve Anton | ba42e99 | 2018-04-09 14:10:01 -0700 | [diff] [blame] | 1528 | // This fails since Unified Plan cannot set a session description with |
| 1529 | // multiple "Plan B tracks" in the same media section. But we still expect the |
| 1530 | // SDP Format to be recorded. |
| 1531 | ASSERT_FALSE(callee->SetRemoteDescription(caller->CreateOffer())); |
Steve Anton | 8e20f17 | 2018-03-06 10:55:04 -0800 | [diff] [blame] | 1532 | |
| 1533 | EXPECT_TRUE(callee_metrics->ExpectOnlySingleEnumCount( |
| 1534 | kEnumCounterSdpFormatReceived, kSdpFormatReceivedComplexPlanB)); |
| 1535 | } |
| 1536 | |
Henrik Boström | 91d039b | 2018-01-11 17:43:30 +0100 | [diff] [blame] | 1537 | // Sender setups in a call. |
| 1538 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1539 | TEST_P(PeerConnectionRtpTest, CreateTwoSendersWithSameTrack) { |
Henrik Boström | 91d039b | 2018-01-11 17:43:30 +0100 | [diff] [blame] | 1540 | auto caller = CreatePeerConnection(); |
| 1541 | auto callee = CreatePeerConnection(); |
| 1542 | |
| 1543 | auto track = caller->CreateAudioTrack("audio_track"); |
| 1544 | auto sender1 = caller->AddTrack(track); |
| 1545 | ASSERT_TRUE(sender1); |
| 1546 | // We need to temporarily reset the track for the subsequent AddTrack() to |
| 1547 | // succeed. |
| 1548 | EXPECT_TRUE(sender1->SetTrack(nullptr)); |
| 1549 | auto sender2 = caller->AddTrack(track); |
| 1550 | EXPECT_TRUE(sender2); |
| 1551 | EXPECT_TRUE(sender1->SetTrack(track)); |
| 1552 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1553 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 1554 | // TODO(hbos): When https://crbug.com/webrtc/8734 is resolved, this should |
| 1555 | // return true, and doing |callee->SetRemoteDescription()| should work. |
| 1556 | EXPECT_FALSE(caller->CreateOfferAndSetAsLocal()); |
| 1557 | } else { |
| 1558 | EXPECT_TRUE(caller->CreateOfferAndSetAsLocal()); |
| 1559 | } |
Henrik Boström | 91d039b | 2018-01-11 17:43:30 +0100 | [diff] [blame] | 1560 | } |
| 1561 | |
Steve Anton | 3172c03 | 2018-05-03 15:30:18 -0700 | [diff] [blame] | 1562 | INSTANTIATE_TEST_CASE_P(PeerConnectionRtpTest, |
| 1563 | PeerConnectionRtpTest, |
| 1564 | Values(SdpSemantics::kPlanB, |
| 1565 | SdpSemantics::kUnifiedPlan)); |
| 1566 | |
Steve Anton | 9158ef6 | 2017-11-27 13:01:52 -0800 | [diff] [blame] | 1567 | } // namespace webrtc |