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