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