Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | // This file contains tests that check the interaction between the |
| 12 | // PeerConnection and the underlying media engine, as well as tests that check |
| 13 | // the media-related aspects of SDP. |
| 14 | |
| 15 | #include <tuple> |
| 16 | |
Niels Möller | 8366e17 | 2018-02-14 11:20:13 | [diff] [blame] | 17 | #include "api/call/callfactoryinterface.h" |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 18 | #include "logging/rtc_event_log/rtc_event_log_factory.h" |
| 19 | #include "media/base/fakemediaengine.h" |
| 20 | #include "p2p/base/fakeportallocator.h" |
| 21 | #include "pc/mediasession.h" |
| 22 | #include "pc/peerconnectionwrapper.h" |
Steve Anton | 1d03a75 | 2017-11-27 22:30:09 | [diff] [blame] | 23 | #include "pc/rtpmediautils.h" |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 24 | #include "pc/sdputils.h" |
| 25 | #ifdef WEBRTC_ANDROID |
| 26 | #include "pc/test/androidtestinitializer.h" |
| 27 | #endif |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame] | 28 | #include "absl/memory/memory.h" |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 29 | #include "pc/test/fakertccertificategenerator.h" |
| 30 | #include "rtc_base/gunit.h" |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 31 | #include "rtc_base/virtualsocketserver.h" |
| 32 | #include "test/gmock.h" |
| 33 | |
| 34 | namespace webrtc { |
| 35 | |
| 36 | using cricket::FakeMediaEngine; |
| 37 | using RTCConfiguration = PeerConnectionInterface::RTCConfiguration; |
| 38 | using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions; |
| 39 | using ::testing::Bool; |
| 40 | using ::testing::Combine; |
| 41 | using ::testing::Values; |
| 42 | using ::testing::ElementsAre; |
| 43 | |
| 44 | class PeerConnectionWrapperForMediaTest : public PeerConnectionWrapper { |
| 45 | public: |
| 46 | using PeerConnectionWrapper::PeerConnectionWrapper; |
| 47 | |
| 48 | FakeMediaEngine* media_engine() { return media_engine_; } |
| 49 | void set_media_engine(FakeMediaEngine* media_engine) { |
| 50 | media_engine_ = media_engine; |
| 51 | } |
| 52 | |
| 53 | private: |
| 54 | FakeMediaEngine* media_engine_; |
| 55 | }; |
| 56 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 57 | class PeerConnectionMediaBaseTest : public ::testing::Test { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 58 | protected: |
| 59 | typedef std::unique_ptr<PeerConnectionWrapperForMediaTest> WrapperPtr; |
| 60 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 61 | explicit PeerConnectionMediaBaseTest(SdpSemantics sdp_semantics) |
| 62 | : vss_(new rtc::VirtualSocketServer()), |
| 63 | main_(vss_.get()), |
| 64 | sdp_semantics_(sdp_semantics) { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 65 | #ifdef WEBRTC_ANDROID |
| 66 | InitializeAndroidObjects(); |
| 67 | #endif |
| 68 | } |
| 69 | |
| 70 | WrapperPtr CreatePeerConnection() { |
| 71 | return CreatePeerConnection(RTCConfiguration()); |
| 72 | } |
| 73 | |
| 74 | WrapperPtr CreatePeerConnection(const RTCConfiguration& config) { |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame] | 75 | auto media_engine = absl::make_unique<FakeMediaEngine>(); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 76 | auto* media_engine_ptr = media_engine.get(); |
| 77 | auto pc_factory = CreateModularPeerConnectionFactory( |
| 78 | rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(), |
| 79 | std::move(media_engine), CreateCallFactory(), |
| 80 | CreateRtcEventLogFactory()); |
| 81 | |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame] | 82 | auto fake_port_allocator = absl::make_unique<cricket::FakePortAllocator>( |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 83 | rtc::Thread::Current(), nullptr); |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame] | 84 | auto observer = absl::make_unique<MockPeerConnectionObserver>(); |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 85 | auto modified_config = config; |
| 86 | modified_config.sdp_semantics = sdp_semantics_; |
| 87 | auto pc = pc_factory->CreatePeerConnection(modified_config, |
| 88 | std::move(fake_port_allocator), |
| 89 | nullptr, observer.get()); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 90 | if (!pc) { |
| 91 | return nullptr; |
| 92 | } |
| 93 | |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame] | 94 | auto wrapper = absl::make_unique<PeerConnectionWrapperForMediaTest>( |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 95 | pc_factory, pc, std::move(observer)); |
| 96 | wrapper->set_media_engine(media_engine_ptr); |
| 97 | return wrapper; |
| 98 | } |
| 99 | |
| 100 | // Accepts the same arguments as CreatePeerConnection and adds default audio |
| 101 | // and video tracks. |
| 102 | template <typename... Args> |
| 103 | WrapperPtr CreatePeerConnectionWithAudioVideo(Args&&... args) { |
| 104 | auto wrapper = CreatePeerConnection(std::forward<Args>(args)...); |
| 105 | if (!wrapper) { |
| 106 | return nullptr; |
| 107 | } |
| 108 | wrapper->AddAudioTrack("a"); |
| 109 | wrapper->AddVideoTrack("v"); |
| 110 | return wrapper; |
| 111 | } |
| 112 | |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 113 | RtpTransceiverDirection GetMediaContentDirection( |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 114 | const SessionDescriptionInterface* sdesc, |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 115 | cricket::MediaType media_type) { |
| 116 | auto* content = |
| 117 | cricket::GetFirstMediaContent(sdesc->description(), media_type); |
| 118 | RTC_DCHECK(content); |
| 119 | return content->media_description()->direction(); |
| 120 | } |
| 121 | |
| 122 | bool IsUnifiedPlan() const { |
| 123 | return sdp_semantics_ == SdpSemantics::kUnifiedPlan; |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | std::unique_ptr<rtc::VirtualSocketServer> vss_; |
| 127 | rtc::AutoSocketServerThread main_; |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 128 | const SdpSemantics sdp_semantics_; |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 129 | }; |
| 130 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 131 | class PeerConnectionMediaTest |
| 132 | : public PeerConnectionMediaBaseTest, |
| 133 | public ::testing::WithParamInterface<SdpSemantics> { |
| 134 | protected: |
| 135 | PeerConnectionMediaTest() : PeerConnectionMediaBaseTest(GetParam()) {} |
| 136 | }; |
| 137 | |
| 138 | class PeerConnectionMediaTestUnifiedPlan : public PeerConnectionMediaBaseTest { |
| 139 | protected: |
| 140 | PeerConnectionMediaTestUnifiedPlan() |
| 141 | : PeerConnectionMediaBaseTest(SdpSemantics::kUnifiedPlan) {} |
| 142 | }; |
| 143 | |
| 144 | class PeerConnectionMediaTestPlanB : public PeerConnectionMediaBaseTest { |
| 145 | protected: |
| 146 | PeerConnectionMediaTestPlanB() |
| 147 | : PeerConnectionMediaBaseTest(SdpSemantics::kPlanB) {} |
| 148 | }; |
| 149 | |
| 150 | TEST_P(PeerConnectionMediaTest, |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 151 | FailToSetRemoteDescriptionIfCreateMediaChannelFails) { |
| 152 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 153 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 154 | callee->media_engine()->set_fail_create_channel(true); |
| 155 | |
| 156 | std::string error; |
| 157 | ASSERT_FALSE(callee->SetRemoteDescription(caller->CreateOffer(), &error)); |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 158 | EXPECT_PRED_FORMAT2(AssertStartsWith, error, |
| 159 | "Failed to set remote offer sdp: Failed to create"); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 160 | } |
| 161 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 162 | TEST_P(PeerConnectionMediaTest, |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 163 | FailToSetLocalDescriptionIfCreateMediaChannelFails) { |
| 164 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 165 | caller->media_engine()->set_fail_create_channel(true); |
| 166 | |
| 167 | std::string error; |
| 168 | ASSERT_FALSE(caller->SetLocalDescription(caller->CreateOffer(), &error)); |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 169 | EXPECT_PRED_FORMAT2(AssertStartsWith, error, |
| 170 | "Failed to set local offer sdp: Failed to create"); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | std::vector<std::string> GetIds( |
| 174 | const std::vector<cricket::StreamParams>& streams) { |
| 175 | std::vector<std::string> ids; |
| 176 | for (const auto& stream : streams) { |
| 177 | ids.push_back(stream.id); |
| 178 | } |
| 179 | return ids; |
| 180 | } |
| 181 | |
| 182 | // Test that exchanging an offer and answer with each side having an audio and |
| 183 | // video stream creates the appropriate send/recv streams in the underlying |
| 184 | // media engine on both sides. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 185 | TEST_P(PeerConnectionMediaTest, AudioVideoOfferAnswerCreateSendRecvStreams) { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 186 | const std::string kCallerAudioId = "caller_a"; |
| 187 | const std::string kCallerVideoId = "caller_v"; |
| 188 | const std::string kCalleeAudioId = "callee_a"; |
| 189 | const std::string kCalleeVideoId = "callee_v"; |
| 190 | |
| 191 | auto caller = CreatePeerConnection(); |
| 192 | caller->AddAudioTrack(kCallerAudioId); |
| 193 | caller->AddVideoTrack(kCallerVideoId); |
| 194 | |
| 195 | auto callee = CreatePeerConnection(); |
| 196 | callee->AddAudioTrack(kCalleeAudioId); |
| 197 | callee->AddVideoTrack(kCalleeVideoId); |
| 198 | |
| 199 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 200 | ASSERT_TRUE( |
| 201 | caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal())); |
| 202 | |
| 203 | auto* caller_voice = caller->media_engine()->GetVoiceChannel(0); |
| 204 | EXPECT_THAT(GetIds(caller_voice->recv_streams()), |
| 205 | ElementsAre(kCalleeAudioId)); |
| 206 | EXPECT_THAT(GetIds(caller_voice->send_streams()), |
| 207 | ElementsAre(kCallerAudioId)); |
| 208 | |
| 209 | auto* caller_video = caller->media_engine()->GetVideoChannel(0); |
| 210 | EXPECT_THAT(GetIds(caller_video->recv_streams()), |
| 211 | ElementsAre(kCalleeVideoId)); |
| 212 | EXPECT_THAT(GetIds(caller_video->send_streams()), |
| 213 | ElementsAre(kCallerVideoId)); |
| 214 | |
| 215 | auto* callee_voice = callee->media_engine()->GetVoiceChannel(0); |
| 216 | EXPECT_THAT(GetIds(callee_voice->recv_streams()), |
| 217 | ElementsAre(kCallerAudioId)); |
| 218 | EXPECT_THAT(GetIds(callee_voice->send_streams()), |
| 219 | ElementsAre(kCalleeAudioId)); |
| 220 | |
| 221 | auto* callee_video = callee->media_engine()->GetVideoChannel(0); |
| 222 | EXPECT_THAT(GetIds(callee_video->recv_streams()), |
| 223 | ElementsAre(kCallerVideoId)); |
| 224 | EXPECT_THAT(GetIds(callee_video->send_streams()), |
| 225 | ElementsAre(kCalleeVideoId)); |
| 226 | } |
| 227 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 228 | // Test that stopping the caller transceivers causes the media channels on the |
| 229 | // callee to be destroyed after calling SetRemoteDescription on the generated |
| 230 | // offer. |
| 231 | // See next test for equivalent behavior with Plan B semantics. |
| 232 | TEST_F(PeerConnectionMediaTestUnifiedPlan, |
| 233 | StoppedRemoteTransceiversRemovesMediaChannels) { |
| 234 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 235 | auto callee = CreatePeerConnection(); |
| 236 | |
| 237 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 238 | |
| 239 | // Stop both audio and video transceivers on the caller. |
| 240 | auto transceivers = caller->pc()->GetTransceivers(); |
| 241 | ASSERT_EQ(2u, transceivers.size()); |
| 242 | transceivers[0]->Stop(); |
| 243 | transceivers[1]->Stop(); |
| 244 | |
| 245 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 246 | |
| 247 | ASSERT_FALSE(callee->media_engine()->GetVoiceChannel(0)); |
| 248 | ASSERT_FALSE(callee->media_engine()->GetVideoChannel(0)); |
| 249 | } |
| 250 | |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 251 | // Test that removing streams from a subsequent offer causes the receive streams |
| 252 | // on the callee to be removed. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 253 | // See previous test for equivalent behavior with Unified Plan semantics. |
| 254 | TEST_F(PeerConnectionMediaTestPlanB, EmptyRemoteOfferRemovesRecvStreams) { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 255 | auto caller = CreatePeerConnection(); |
| 256 | auto caller_audio_track = caller->AddAudioTrack("a"); |
| 257 | auto caller_video_track = caller->AddVideoTrack("v"); |
| 258 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 259 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 260 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 261 | |
| 262 | // Remove both tracks from caller. |
| 263 | caller->pc()->RemoveTrack(caller_audio_track); |
| 264 | caller->pc()->RemoveTrack(caller_video_track); |
| 265 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 266 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 267 | |
| 268 | auto callee_voice = callee->media_engine()->GetVoiceChannel(0); |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 269 | auto callee_video = callee->media_engine()->GetVideoChannel(0); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 270 | EXPECT_EQ(1u, callee_voice->send_streams().size()); |
| 271 | EXPECT_EQ(0u, callee_voice->recv_streams().size()); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 272 | EXPECT_EQ(1u, callee_video->send_streams().size()); |
| 273 | EXPECT_EQ(0u, callee_video->recv_streams().size()); |
| 274 | } |
| 275 | |
Jonas Oreland | fc1acd2 | 2018-08-24 08:58:37 | [diff] [blame] | 276 | // Test enabling of simulcast with Plan B semantics. |
| 277 | // This test creating an offer. |
| 278 | TEST_F(PeerConnectionMediaTestPlanB, SimulcastOffer) { |
| 279 | auto caller = CreatePeerConnection(); |
| 280 | auto caller_video_track = caller->AddVideoTrack("v"); |
| 281 | RTCOfferAnswerOptions options; |
| 282 | options.num_simulcast_layers = 3; |
| 283 | auto offer = caller->CreateOffer(options); |
| 284 | auto* description = cricket::GetFirstMediaContent( |
| 285 | offer->description(), |
| 286 | cricket::MEDIA_TYPE_VIDEO)->media_description(); |
| 287 | ASSERT_EQ(1u, description->streams().size()); |
| 288 | ASSERT_TRUE(description->streams()[0].get_ssrc_group("SIM")); |
| 289 | EXPECT_EQ(3u, description->streams()[0].get_ssrc_group("SIM")->ssrcs.size()); |
| 290 | |
| 291 | // Check that it actually creates simulcast aswell. |
| 292 | caller->SetLocalDescription(std::move(offer)); |
| 293 | auto senders = caller->pc()->GetSenders(); |
| 294 | ASSERT_EQ(1u, senders.size()); |
| 295 | EXPECT_EQ(cricket::MediaType::MEDIA_TYPE_VIDEO, senders[0]->media_type()); |
| 296 | EXPECT_EQ(3u, senders[0]->GetParameters().encodings.size()); |
| 297 | } |
| 298 | |
| 299 | // Test enabling of simulcast with Plan B semantics. |
| 300 | // This test creating an answer. |
| 301 | TEST_F(PeerConnectionMediaTestPlanB, SimulcastAnswer) { |
| 302 | auto caller = CreatePeerConnection(); |
| 303 | caller->AddVideoTrack("v0"); |
| 304 | auto offer = caller->CreateOffer(); |
| 305 | auto callee = CreatePeerConnection(); |
| 306 | auto callee_video_track = callee->AddVideoTrack("v1"); |
| 307 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 308 | RTCOfferAnswerOptions options; |
| 309 | options.num_simulcast_layers = 3; |
| 310 | auto answer = callee->CreateAnswer(options); |
| 311 | auto* description = cricket::GetFirstMediaContent( |
| 312 | answer->description(), |
| 313 | cricket::MEDIA_TYPE_VIDEO)->media_description(); |
| 314 | ASSERT_EQ(1u, description->streams().size()); |
| 315 | ASSERT_TRUE(description->streams()[0].get_ssrc_group("SIM")); |
| 316 | EXPECT_EQ(3u, description->streams()[0].get_ssrc_group("SIM")->ssrcs.size()); |
| 317 | |
| 318 | // Check that it actually creates simulcast aswell. |
| 319 | callee->SetLocalDescription(std::move(answer)); |
| 320 | auto senders = callee->pc()->GetSenders(); |
| 321 | ASSERT_EQ(1u, senders.size()); |
| 322 | EXPECT_EQ(cricket::MediaType::MEDIA_TYPE_VIDEO, senders[0]->media_type()); |
| 323 | EXPECT_EQ(3u, senders[0]->GetParameters().encodings.size()); |
| 324 | } |
| 325 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 326 | // Test that stopping the callee transceivers causes the media channels to be |
| 327 | // destroyed on the callee after calling SetLocalDescription on the local |
| 328 | // answer. |
| 329 | // See next test for equivalent behavior with Plan B semantics. |
| 330 | TEST_F(PeerConnectionMediaTestUnifiedPlan, |
| 331 | StoppedLocalTransceiversRemovesMediaChannels) { |
| 332 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 333 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 334 | |
| 335 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 336 | |
| 337 | // Stop both audio and video transceivers on the callee. |
| 338 | auto transceivers = callee->pc()->GetTransceivers(); |
| 339 | ASSERT_EQ(2u, transceivers.size()); |
| 340 | transceivers[0]->Stop(); |
| 341 | transceivers[1]->Stop(); |
| 342 | |
| 343 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 344 | |
| 345 | EXPECT_FALSE(callee->media_engine()->GetVoiceChannel(0)); |
| 346 | EXPECT_FALSE(callee->media_engine()->GetVideoChannel(0)); |
| 347 | } |
| 348 | |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 349 | // Test that removing streams from a subsequent answer causes the send streams |
| 350 | // on the callee to be removed when applied locally. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 351 | // See previous test for equivalent behavior with Unified Plan semantics. |
| 352 | TEST_F(PeerConnectionMediaTestPlanB, EmptyLocalAnswerRemovesSendStreams) { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 353 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 354 | auto callee = CreatePeerConnection(); |
| 355 | auto callee_audio_track = callee->AddAudioTrack("a"); |
| 356 | auto callee_video_track = callee->AddVideoTrack("v"); |
| 357 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 358 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 359 | |
| 360 | // Remove both tracks from callee. |
| 361 | callee->pc()->RemoveTrack(callee_audio_track); |
| 362 | callee->pc()->RemoveTrack(callee_video_track); |
| 363 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 364 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 365 | |
| 366 | auto callee_voice = callee->media_engine()->GetVoiceChannel(0); |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 367 | auto callee_video = callee->media_engine()->GetVideoChannel(0); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 368 | EXPECT_EQ(0u, callee_voice->send_streams().size()); |
| 369 | EXPECT_EQ(1u, callee_voice->recv_streams().size()); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 370 | EXPECT_EQ(0u, callee_video->send_streams().size()); |
| 371 | EXPECT_EQ(1u, callee_video->recv_streams().size()); |
| 372 | } |
| 373 | |
| 374 | // Test that a new stream in a subsequent offer causes a new receive stream to |
| 375 | // be created on the callee. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 376 | TEST_P(PeerConnectionMediaTest, NewStreamInRemoteOfferAddsRecvStreams) { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 377 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 378 | auto callee = CreatePeerConnection(); |
| 379 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 380 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 381 | |
| 382 | // Add second set of tracks to the caller. |
| 383 | caller->AddAudioTrack("a2"); |
| 384 | caller->AddVideoTrack("v2"); |
| 385 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 386 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 387 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 388 | auto a1 = callee->media_engine()->GetVoiceChannel(0); |
| 389 | auto a2 = callee->media_engine()->GetVoiceChannel(1); |
| 390 | auto v1 = callee->media_engine()->GetVideoChannel(0); |
| 391 | auto v2 = callee->media_engine()->GetVideoChannel(1); |
| 392 | if (IsUnifiedPlan()) { |
| 393 | ASSERT_TRUE(a1); |
| 394 | EXPECT_EQ(1u, a1->recv_streams().size()); |
| 395 | ASSERT_TRUE(a2); |
| 396 | EXPECT_EQ(1u, a2->recv_streams().size()); |
| 397 | ASSERT_TRUE(v1); |
| 398 | EXPECT_EQ(1u, v1->recv_streams().size()); |
| 399 | ASSERT_TRUE(v2); |
| 400 | EXPECT_EQ(1u, v2->recv_streams().size()); |
| 401 | } else { |
| 402 | ASSERT_TRUE(a1); |
| 403 | EXPECT_EQ(2u, a1->recv_streams().size()); |
| 404 | ASSERT_FALSE(a2); |
| 405 | ASSERT_TRUE(v1); |
| 406 | EXPECT_EQ(2u, v1->recv_streams().size()); |
| 407 | ASSERT_FALSE(v2); |
| 408 | } |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | // Test that a new stream in a subsequent answer causes a new send stream to be |
| 412 | // created on the callee when added locally. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 413 | TEST_P(PeerConnectionMediaTest, NewStreamInLocalAnswerAddsSendStreams) { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 414 | auto caller = CreatePeerConnection(); |
| 415 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 416 | |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 417 | RTCOfferAnswerOptions offer_options; |
| 418 | offer_options.offer_to_receive_audio = |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 419 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 420 | offer_options.offer_to_receive_video = |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 421 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 422 | RTCOfferAnswerOptions answer_options; |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 423 | |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 424 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get(), offer_options, |
| 425 | answer_options)); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 426 | |
| 427 | // Add second set of tracks to the callee. |
| 428 | callee->AddAudioTrack("a2"); |
| 429 | callee->AddVideoTrack("v2"); |
| 430 | |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 431 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get(), offer_options, |
| 432 | answer_options)); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 433 | |
| 434 | auto callee_voice = callee->media_engine()->GetVoiceChannel(0); |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 435 | ASSERT_TRUE(callee_voice); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 436 | auto callee_video = callee->media_engine()->GetVideoChannel(0); |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 437 | ASSERT_TRUE(callee_video); |
| 438 | |
| 439 | if (IsUnifiedPlan()) { |
| 440 | EXPECT_EQ(1u, callee_voice->send_streams().size()); |
| 441 | EXPECT_EQ(1u, callee_video->send_streams().size()); |
| 442 | } else { |
| 443 | EXPECT_EQ(2u, callee_voice->send_streams().size()); |
| 444 | EXPECT_EQ(2u, callee_video->send_streams().size()); |
| 445 | } |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | // A PeerConnection with no local streams and no explicit answer constraints |
| 449 | // should not reject any offered media sections. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 450 | TEST_P(PeerConnectionMediaTest, |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 451 | CreateAnswerWithNoStreamsAndDefaultOptionsDoesNotReject) { |
| 452 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 453 | auto callee = CreatePeerConnection(); |
| 454 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 455 | auto answer = callee->CreateAnswer(); |
| 456 | |
| 457 | const auto* audio_content = |
| 458 | cricket::GetFirstAudioContent(answer->description()); |
| 459 | ASSERT_TRUE(audio_content); |
| 460 | EXPECT_FALSE(audio_content->rejected); |
| 461 | |
| 462 | const auto* video_content = |
| 463 | cricket::GetFirstVideoContent(answer->description()); |
| 464 | ASSERT_TRUE(video_content); |
| 465 | EXPECT_FALSE(video_content->rejected); |
| 466 | } |
| 467 | |
| 468 | class PeerConnectionMediaOfferDirectionTest |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 469 | : public PeerConnectionMediaBaseTest, |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 470 | public ::testing::WithParamInterface< |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 471 | std::tuple<SdpSemantics, |
| 472 | std::tuple<bool, int, RtpTransceiverDirection>>> { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 473 | protected: |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 474 | PeerConnectionMediaOfferDirectionTest() |
| 475 | : PeerConnectionMediaBaseTest(std::get<0>(GetParam())) { |
| 476 | auto param = std::get<1>(GetParam()); |
| 477 | send_media_ = std::get<0>(param); |
| 478 | offer_to_receive_ = std::get<1>(param); |
| 479 | expected_direction_ = std::get<2>(param); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | bool send_media_; |
| 483 | int offer_to_receive_; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 484 | RtpTransceiverDirection expected_direction_; |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 485 | }; |
| 486 | |
| 487 | // Tests that the correct direction is set on the media description according |
| 488 | // to the presence of a local media track and the offer_to_receive setting. |
| 489 | TEST_P(PeerConnectionMediaOfferDirectionTest, VerifyDirection) { |
| 490 | auto caller = CreatePeerConnection(); |
| 491 | if (send_media_) { |
| 492 | caller->AddAudioTrack("a"); |
| 493 | } |
| 494 | |
| 495 | RTCOfferAnswerOptions options; |
| 496 | options.offer_to_receive_audio = offer_to_receive_; |
| 497 | auto offer = caller->CreateOffer(options); |
| 498 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 499 | auto* content = cricket::GetFirstMediaContent(offer->description(), |
| 500 | cricket::MEDIA_TYPE_AUDIO); |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 501 | if (expected_direction_ == RtpTransceiverDirection::kInactive) { |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 502 | EXPECT_FALSE(content); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 503 | } else { |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 504 | EXPECT_EQ(expected_direction_, content->media_description()->direction()); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 505 | } |
| 506 | } |
| 507 | |
| 508 | // Note that in these tests, MD_INACTIVE indicates that no media section is |
| 509 | // included in the offer, not that the media direction is inactive. |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 510 | INSTANTIATE_TEST_CASE_P( |
| 511 | PeerConnectionMediaTest, |
| 512 | PeerConnectionMediaOfferDirectionTest, |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 513 | Combine( |
| 514 | Values(SdpSemantics::kPlanB, SdpSemantics::kUnifiedPlan), |
| 515 | Values(std::make_tuple(false, -1, RtpTransceiverDirection::kInactive), |
| 516 | std::make_tuple(false, 0, RtpTransceiverDirection::kInactive), |
| 517 | std::make_tuple(false, 1, RtpTransceiverDirection::kRecvOnly), |
| 518 | std::make_tuple(true, -1, RtpTransceiverDirection::kSendRecv), |
| 519 | std::make_tuple(true, 0, RtpTransceiverDirection::kSendOnly), |
| 520 | std::make_tuple(true, 1, RtpTransceiverDirection::kSendRecv)))); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 521 | |
| 522 | class PeerConnectionMediaAnswerDirectionTest |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 523 | : public PeerConnectionMediaBaseTest, |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 524 | public ::testing::WithParamInterface< |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 525 | std::tuple<SdpSemantics, RtpTransceiverDirection, bool, int>> { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 526 | protected: |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 527 | PeerConnectionMediaAnswerDirectionTest() |
| 528 | : PeerConnectionMediaBaseTest(std::get<0>(GetParam())) { |
| 529 | offer_direction_ = std::get<1>(GetParam()); |
| 530 | send_media_ = std::get<2>(GetParam()); |
| 531 | offer_to_receive_ = std::get<3>(GetParam()); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 532 | } |
| 533 | |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 534 | RtpTransceiverDirection offer_direction_; |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 535 | bool send_media_; |
| 536 | int offer_to_receive_; |
| 537 | }; |
| 538 | |
| 539 | // Tests that the direction in an answer is correct according to direction sent |
| 540 | // in the offer, the presence of a local media track on the receive side and the |
| 541 | // offer_to_receive setting. |
| 542 | TEST_P(PeerConnectionMediaAnswerDirectionTest, VerifyDirection) { |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 543 | if (IsUnifiedPlan() && |
| 544 | offer_to_receive_ != RTCOfferAnswerOptions::kUndefined) { |
| 545 | // offer_to_receive_ is not implemented when creating answers with Unified |
| 546 | // Plan semantics specified. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 547 | return; |
| 548 | } |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 549 | |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 550 | auto caller = CreatePeerConnection(); |
| 551 | caller->AddAudioTrack("a"); |
| 552 | |
| 553 | // Create the offer with an audio section and set its direction. |
| 554 | auto offer = caller->CreateOffer(); |
| 555 | cricket::GetFirstAudioContentDescription(offer->description()) |
| 556 | ->set_direction(offer_direction_); |
| 557 | |
| 558 | auto callee = CreatePeerConnection(); |
| 559 | if (send_media_) { |
| 560 | callee->AddAudioTrack("a"); |
| 561 | } |
| 562 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 563 | |
| 564 | // Create the answer according to the test parameters. |
| 565 | RTCOfferAnswerOptions options; |
| 566 | options.offer_to_receive_audio = offer_to_receive_; |
| 567 | auto answer = callee->CreateAnswer(options); |
| 568 | |
| 569 | // The expected direction in the answer is the intersection of each side's |
| 570 | // capability to send/recv media. |
| 571 | // For the offerer, the direction is given in the offer (offer_direction_). |
| 572 | // For the answerer, the direction has two components: |
| 573 | // 1. Send if the answerer has a local track to send. |
| 574 | // 2. Receive if the answerer has explicitly set the offer_to_receive to 1 or |
| 575 | // if it has been left as default. |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 576 | bool offer_send = RtpTransceiverDirectionHasSend(offer_direction_); |
| 577 | bool offer_recv = RtpTransceiverDirectionHasRecv(offer_direction_); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 578 | |
| 579 | // The negotiated components determine the direction set in the answer. |
Steve Anton | 1d03a75 | 2017-11-27 22:30:09 | [diff] [blame] | 580 | bool negotiate_send = (send_media_ && offer_recv); |
| 581 | bool negotiate_recv = ((offer_to_receive_ != 0) && offer_send); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 582 | |
| 583 | auto expected_direction = |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 584 | RtpTransceiverDirectionFromSendRecv(negotiate_send, negotiate_recv); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 585 | EXPECT_EQ(expected_direction, |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 586 | GetMediaContentDirection(answer.get(), cricket::MEDIA_TYPE_AUDIO)); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | // Tests that the media section is rejected if and only if the callee has no |
| 590 | // local media track and has set offer_to_receive to 0, no matter which |
| 591 | // direction the caller indicated in the offer. |
| 592 | TEST_P(PeerConnectionMediaAnswerDirectionTest, VerifyRejected) { |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 593 | if (IsUnifiedPlan() && |
| 594 | offer_to_receive_ != RTCOfferAnswerOptions::kUndefined) { |
| 595 | // offer_to_receive_ is not implemented when creating answers with Unified |
| 596 | // Plan semantics specified. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 597 | return; |
| 598 | } |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 599 | |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 600 | auto caller = CreatePeerConnection(); |
| 601 | caller->AddAudioTrack("a"); |
| 602 | |
| 603 | // Create the offer with an audio section and set its direction. |
| 604 | auto offer = caller->CreateOffer(); |
| 605 | cricket::GetFirstAudioContentDescription(offer->description()) |
| 606 | ->set_direction(offer_direction_); |
| 607 | |
| 608 | auto callee = CreatePeerConnection(); |
| 609 | if (send_media_) { |
| 610 | callee->AddAudioTrack("a"); |
| 611 | } |
| 612 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 613 | |
| 614 | // Create the answer according to the test parameters. |
| 615 | RTCOfferAnswerOptions options; |
| 616 | options.offer_to_receive_audio = offer_to_receive_; |
| 617 | auto answer = callee->CreateAnswer(options); |
| 618 | |
| 619 | // The media section is rejected if and only if offer_to_receive is explicitly |
| 620 | // set to 0 and there is no media to send. |
| 621 | auto* audio_content = cricket::GetFirstAudioContent(answer->description()); |
| 622 | ASSERT_TRUE(audio_content); |
| 623 | EXPECT_EQ((offer_to_receive_ == 0 && !send_media_), audio_content->rejected); |
| 624 | } |
| 625 | |
| 626 | INSTANTIATE_TEST_CASE_P(PeerConnectionMediaTest, |
| 627 | PeerConnectionMediaAnswerDirectionTest, |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 628 | Combine(Values(SdpSemantics::kPlanB, |
| 629 | SdpSemantics::kUnifiedPlan), |
| 630 | Values(RtpTransceiverDirection::kInactive, |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 631 | RtpTransceiverDirection::kSendOnly, |
| 632 | RtpTransceiverDirection::kRecvOnly, |
| 633 | RtpTransceiverDirection::kSendRecv), |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 634 | Bool(), |
| 635 | Values(-1, 0, 1))); |
| 636 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 637 | TEST_P(PeerConnectionMediaTest, OfferHasDifferentDirectionForAudioVideo) { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 638 | auto caller = CreatePeerConnection(); |
| 639 | caller->AddVideoTrack("v"); |
| 640 | |
| 641 | RTCOfferAnswerOptions options; |
| 642 | options.offer_to_receive_audio = 1; |
| 643 | options.offer_to_receive_video = 0; |
| 644 | auto offer = caller->CreateOffer(options); |
| 645 | |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 646 | EXPECT_EQ(RtpTransceiverDirection::kRecvOnly, |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 647 | GetMediaContentDirection(offer.get(), cricket::MEDIA_TYPE_AUDIO)); |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 648 | EXPECT_EQ(RtpTransceiverDirection::kSendOnly, |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 649 | GetMediaContentDirection(offer.get(), cricket::MEDIA_TYPE_VIDEO)); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 650 | } |
| 651 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 652 | TEST_P(PeerConnectionMediaTest, AnswerHasDifferentDirectionsForAudioVideo) { |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 653 | if (IsUnifiedPlan()) { |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 654 | // offer_to_receive_ is not implemented when creating answers with Unified |
| 655 | // Plan semantics specified. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 656 | return; |
| 657 | } |
| 658 | |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 659 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 660 | auto callee = CreatePeerConnection(); |
| 661 | callee->AddVideoTrack("v"); |
| 662 | |
| 663 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 664 | |
| 665 | RTCOfferAnswerOptions options; |
| 666 | options.offer_to_receive_audio = 1; |
| 667 | options.offer_to_receive_video = 0; |
| 668 | auto answer = callee->CreateAnswer(options); |
| 669 | |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 670 | EXPECT_EQ(RtpTransceiverDirection::kRecvOnly, |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 671 | GetMediaContentDirection(answer.get(), cricket::MEDIA_TYPE_AUDIO)); |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 672 | EXPECT_EQ(RtpTransceiverDirection::kSendOnly, |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 673 | GetMediaContentDirection(answer.get(), cricket::MEDIA_TYPE_VIDEO)); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | void AddComfortNoiseCodecsToSend(cricket::FakeMediaEngine* media_engine) { |
| 677 | const cricket::AudioCodec kComfortNoiseCodec8k(102, "CN", 8000, 0, 1); |
| 678 | const cricket::AudioCodec kComfortNoiseCodec16k(103, "CN", 16000, 0, 1); |
| 679 | |
| 680 | auto codecs = media_engine->audio_send_codecs(); |
| 681 | codecs.push_back(kComfortNoiseCodec8k); |
| 682 | codecs.push_back(kComfortNoiseCodec16k); |
| 683 | media_engine->SetAudioCodecs(codecs); |
| 684 | } |
| 685 | |
| 686 | bool HasAnyComfortNoiseCodecs(const cricket::SessionDescription* desc) { |
| 687 | const auto* audio_desc = cricket::GetFirstAudioContentDescription(desc); |
| 688 | for (const auto& codec : audio_desc->codecs()) { |
| 689 | if (codec.name == "CN") { |
| 690 | return true; |
| 691 | } |
| 692 | } |
| 693 | return false; |
| 694 | } |
| 695 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 696 | TEST_P(PeerConnectionMediaTest, |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 697 | CreateOfferWithNoVoiceActivityDetectionIncludesNoComfortNoiseCodecs) { |
| 698 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 699 | AddComfortNoiseCodecsToSend(caller->media_engine()); |
| 700 | |
| 701 | RTCOfferAnswerOptions options; |
| 702 | options.voice_activity_detection = false; |
| 703 | auto offer = caller->CreateOffer(options); |
| 704 | |
| 705 | EXPECT_FALSE(HasAnyComfortNoiseCodecs(offer->description())); |
| 706 | } |
| 707 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 708 | TEST_P(PeerConnectionMediaTest, |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 709 | CreateAnswerWithNoVoiceActivityDetectionIncludesNoComfortNoiseCodecs) { |
| 710 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 711 | AddComfortNoiseCodecsToSend(caller->media_engine()); |
| 712 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 713 | AddComfortNoiseCodecsToSend(callee->media_engine()); |
| 714 | |
| 715 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 716 | |
| 717 | RTCOfferAnswerOptions options; |
| 718 | options.voice_activity_detection = false; |
| 719 | auto answer = callee->CreateAnswer(options); |
| 720 | |
| 721 | EXPECT_FALSE(HasAnyComfortNoiseCodecs(answer->description())); |
| 722 | } |
| 723 | |
| 724 | // The following test group verifies that we reject answers with invalid media |
| 725 | // sections as per RFC 3264. |
| 726 | |
| 727 | class PeerConnectionMediaInvalidMediaTest |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 728 | : public PeerConnectionMediaBaseTest, |
| 729 | public ::testing::WithParamInterface<std::tuple< |
| 730 | SdpSemantics, |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 731 | std::tuple<std::string, |
| 732 | std::function<void(cricket::SessionDescription*)>, |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 733 | std::string>>> { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 734 | protected: |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 735 | PeerConnectionMediaInvalidMediaTest() |
| 736 | : PeerConnectionMediaBaseTest(std::get<0>(GetParam())) { |
| 737 | auto param = std::get<1>(GetParam()); |
| 738 | mutator_ = std::get<1>(param); |
| 739 | expected_error_ = std::get<2>(param); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | std::function<void(cricket::SessionDescription*)> mutator_; |
| 743 | std::string expected_error_; |
| 744 | }; |
| 745 | |
| 746 | TEST_P(PeerConnectionMediaInvalidMediaTest, FailToSetRemoteAnswer) { |
| 747 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 748 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 749 | |
| 750 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 751 | |
| 752 | auto answer = callee->CreateAnswer(); |
| 753 | mutator_(answer->description()); |
| 754 | |
| 755 | std::string error; |
| 756 | ASSERT_FALSE(caller->SetRemoteDescription(std::move(answer), &error)); |
| 757 | EXPECT_EQ("Failed to set remote answer sdp: " + expected_error_, error); |
| 758 | } |
| 759 | |
| 760 | TEST_P(PeerConnectionMediaInvalidMediaTest, FailToSetLocalAnswer) { |
| 761 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 762 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 763 | |
| 764 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 765 | |
| 766 | auto answer = callee->CreateAnswer(); |
| 767 | mutator_(answer->description()); |
| 768 | |
| 769 | std::string error; |
| 770 | ASSERT_FALSE(callee->SetLocalDescription(std::move(answer), &error)); |
| 771 | EXPECT_EQ("Failed to set local answer sdp: " + expected_error_, error); |
| 772 | } |
| 773 | |
| 774 | void RemoveVideoContent(cricket::SessionDescription* desc) { |
| 775 | auto content_name = cricket::GetFirstVideoContent(desc)->name; |
| 776 | desc->RemoveContentByName(content_name); |
| 777 | desc->RemoveTransportInfoByName(content_name); |
| 778 | } |
| 779 | |
| 780 | void RenameVideoContent(cricket::SessionDescription* desc) { |
| 781 | auto* video_content = cricket::GetFirstVideoContent(desc); |
| 782 | auto* transport_info = desc->GetTransportInfoByName(video_content->name); |
| 783 | video_content->name = "video_renamed"; |
| 784 | transport_info->content_name = video_content->name; |
| 785 | } |
| 786 | |
| 787 | void ReverseMediaContent(cricket::SessionDescription* desc) { |
| 788 | std::reverse(desc->contents().begin(), desc->contents().end()); |
| 789 | std::reverse(desc->transport_infos().begin(), desc->transport_infos().end()); |
| 790 | } |
| 791 | |
| 792 | void ChangeMediaTypeAudioToVideo(cricket::SessionDescription* desc) { |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 793 | std::string audio_mid = cricket::GetFirstAudioContent(desc)->name; |
| 794 | desc->RemoveContentByName(audio_mid); |
| 795 | auto* video_content = cricket::GetFirstVideoContent(desc); |
| 796 | desc->AddContent(audio_mid, video_content->type, |
Steve Anton | b1c1de1 | 2017-12-21 23:14:30 | [diff] [blame] | 797 | video_content->media_description()->Copy()); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | constexpr char kMLinesOutOfOrder[] = |
| 801 | "The order of m-lines in answer doesn't match order in offer. Rejecting " |
| 802 | "answer."; |
| 803 | |
| 804 | INSTANTIATE_TEST_CASE_P( |
| 805 | PeerConnectionMediaTest, |
| 806 | PeerConnectionMediaInvalidMediaTest, |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 807 | Combine(Values(SdpSemantics::kPlanB, SdpSemantics::kUnifiedPlan), |
| 808 | Values(std::make_tuple("remove video", |
| 809 | RemoveVideoContent, |
| 810 | kMLinesOutOfOrder), |
| 811 | std::make_tuple("rename video", |
| 812 | RenameVideoContent, |
| 813 | kMLinesOutOfOrder), |
| 814 | std::make_tuple("reverse media sections", |
| 815 | ReverseMediaContent, |
| 816 | kMLinesOutOfOrder), |
| 817 | std::make_tuple("change audio type to video type", |
| 818 | ChangeMediaTypeAudioToVideo, |
| 819 | kMLinesOutOfOrder)))); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 820 | |
| 821 | // Test that the correct media engine send/recv streams are created when doing |
| 822 | // a series of offer/answers where audio/video are both sent, then audio is |
| 823 | // rejected, then both audio/video sent again. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 824 | TEST_P(PeerConnectionMediaTest, TestAVOfferWithAudioOnlyAnswer) { |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 825 | if (IsUnifiedPlan()) { |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 826 | // offer_to_receive_ is not implemented when creating answers with Unified |
| 827 | // Plan semantics specified. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 828 | return; |
| 829 | } |
| 830 | |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 831 | RTCOfferAnswerOptions options_reject_video; |
| 832 | options_reject_video.offer_to_receive_audio = |
| 833 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 834 | options_reject_video.offer_to_receive_video = 0; |
| 835 | |
| 836 | auto caller = CreatePeerConnection(); |
| 837 | caller->AddAudioTrack("a"); |
| 838 | caller->AddVideoTrack("v"); |
| 839 | auto callee = CreatePeerConnection(); |
| 840 | |
| 841 | // Caller initially offers to send/recv audio and video. |
| 842 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 843 | // Callee accepts the audio as recv only but rejects the video. |
| 844 | ASSERT_TRUE(caller->SetRemoteDescription( |
| 845 | callee->CreateAnswerAndSetAsLocal(options_reject_video))); |
| 846 | |
| 847 | auto caller_voice = caller->media_engine()->GetVoiceChannel(0); |
| 848 | ASSERT_TRUE(caller_voice); |
| 849 | EXPECT_EQ(0u, caller_voice->recv_streams().size()); |
| 850 | EXPECT_EQ(1u, caller_voice->send_streams().size()); |
| 851 | auto caller_video = caller->media_engine()->GetVideoChannel(0); |
| 852 | EXPECT_FALSE(caller_video); |
| 853 | |
| 854 | // Callee adds its own audio/video stream and offers to receive audio/video |
| 855 | // too. |
| 856 | callee->AddAudioTrack("a"); |
| 857 | auto callee_video_track = callee->AddVideoTrack("v"); |
| 858 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 859 | ASSERT_TRUE( |
| 860 | caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal())); |
| 861 | |
| 862 | auto callee_voice = callee->media_engine()->GetVoiceChannel(0); |
| 863 | ASSERT_TRUE(callee_voice); |
| 864 | EXPECT_EQ(1u, callee_voice->recv_streams().size()); |
| 865 | EXPECT_EQ(1u, callee_voice->send_streams().size()); |
| 866 | auto callee_video = callee->media_engine()->GetVideoChannel(0); |
| 867 | ASSERT_TRUE(callee_video); |
| 868 | EXPECT_EQ(1u, callee_video->recv_streams().size()); |
| 869 | EXPECT_EQ(1u, callee_video->send_streams().size()); |
| 870 | |
| 871 | // Callee removes video but keeps audio and rejects the video once again. |
| 872 | callee->pc()->RemoveTrack(callee_video_track); |
| 873 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 874 | ASSERT_TRUE( |
| 875 | callee->SetLocalDescription(callee->CreateAnswer(options_reject_video))); |
| 876 | |
| 877 | callee_voice = callee->media_engine()->GetVoiceChannel(0); |
| 878 | ASSERT_TRUE(callee_voice); |
| 879 | EXPECT_EQ(1u, callee_voice->recv_streams().size()); |
| 880 | EXPECT_EQ(1u, callee_voice->send_streams().size()); |
| 881 | callee_video = callee->media_engine()->GetVideoChannel(0); |
| 882 | EXPECT_FALSE(callee_video); |
| 883 | } |
| 884 | |
| 885 | // Test that the correct media engine send/recv streams are created when doing |
| 886 | // a series of offer/answers where audio/video are both sent, then video is |
| 887 | // rejected, then both audio/video sent again. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 888 | TEST_P(PeerConnectionMediaTest, TestAVOfferWithVideoOnlyAnswer) { |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 889 | if (IsUnifiedPlan()) { |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 890 | // offer_to_receive_ is not implemented when creating answers with Unified |
| 891 | // Plan semantics specified. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 892 | return; |
| 893 | } |
| 894 | |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 895 | // Disable the bundling here. If the media is bundled on audio |
| 896 | // transport, then we can't reject the audio because switching the bundled |
| 897 | // transport is not currently supported. |
| 898 | // (https://bugs.chromium.org/p/webrtc/issues/detail?id=6704) |
| 899 | RTCOfferAnswerOptions options_no_bundle; |
| 900 | options_no_bundle.use_rtp_mux = false; |
| 901 | RTCOfferAnswerOptions options_reject_audio = options_no_bundle; |
| 902 | options_reject_audio.offer_to_receive_audio = 0; |
| 903 | options_reject_audio.offer_to_receive_video = |
| 904 | RTCOfferAnswerOptions::kMaxOfferToReceiveMedia; |
| 905 | |
| 906 | auto caller = CreatePeerConnection(); |
| 907 | caller->AddAudioTrack("a"); |
| 908 | caller->AddVideoTrack("v"); |
| 909 | auto callee = CreatePeerConnection(); |
| 910 | |
| 911 | // Caller initially offers to send/recv audio and video. |
| 912 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 913 | // Callee accepts the video as recv only but rejects the audio. |
| 914 | ASSERT_TRUE(caller->SetRemoteDescription( |
| 915 | callee->CreateAnswerAndSetAsLocal(options_reject_audio))); |
| 916 | |
| 917 | auto caller_voice = caller->media_engine()->GetVoiceChannel(0); |
| 918 | EXPECT_FALSE(caller_voice); |
| 919 | auto caller_video = caller->media_engine()->GetVideoChannel(0); |
| 920 | ASSERT_TRUE(caller_video); |
| 921 | EXPECT_EQ(0u, caller_video->recv_streams().size()); |
| 922 | EXPECT_EQ(1u, caller_video->send_streams().size()); |
| 923 | |
| 924 | // Callee adds its own audio/video stream and offers to receive audio/video |
| 925 | // too. |
| 926 | auto callee_audio_track = callee->AddAudioTrack("a"); |
| 927 | callee->AddVideoTrack("v"); |
| 928 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 929 | ASSERT_TRUE(caller->SetRemoteDescription( |
| 930 | callee->CreateAnswerAndSetAsLocal(options_no_bundle))); |
| 931 | |
| 932 | auto callee_voice = callee->media_engine()->GetVoiceChannel(0); |
| 933 | ASSERT_TRUE(callee_voice); |
| 934 | EXPECT_EQ(1u, callee_voice->recv_streams().size()); |
| 935 | EXPECT_EQ(1u, callee_voice->send_streams().size()); |
| 936 | auto callee_video = callee->media_engine()->GetVideoChannel(0); |
| 937 | ASSERT_TRUE(callee_video); |
| 938 | EXPECT_EQ(1u, callee_video->recv_streams().size()); |
| 939 | EXPECT_EQ(1u, callee_video->send_streams().size()); |
| 940 | |
| 941 | // Callee removes audio but keeps video and rejects the audio once again. |
| 942 | callee->pc()->RemoveTrack(callee_audio_track); |
| 943 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 944 | ASSERT_TRUE( |
| 945 | callee->SetLocalDescription(callee->CreateAnswer(options_reject_audio))); |
| 946 | |
| 947 | callee_voice = callee->media_engine()->GetVoiceChannel(0); |
| 948 | EXPECT_FALSE(callee_voice); |
| 949 | callee_video = callee->media_engine()->GetVideoChannel(0); |
| 950 | ASSERT_TRUE(callee_video); |
| 951 | EXPECT_EQ(1u, callee_video->recv_streams().size()); |
| 952 | EXPECT_EQ(1u, callee_video->send_streams().size()); |
| 953 | } |
| 954 | |
| 955 | // Tests that if the underlying video encoder fails to be initialized (signaled |
| 956 | // by failing to set send codecs), the PeerConnection signals the error to the |
| 957 | // client. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 958 | TEST_P(PeerConnectionMediaTest, MediaEngineErrorPropagatedToClients) { |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 959 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 960 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 961 | |
| 962 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 963 | |
| 964 | auto video_channel = caller->media_engine()->GetVideoChannel(0); |
| 965 | video_channel->set_fail_set_send_codecs(true); |
| 966 | |
| 967 | std::string error; |
| 968 | ASSERT_FALSE(caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal(), |
| 969 | &error)); |
| 970 | EXPECT_EQ( |
Steve Anton | 80dd7b5 | 2018-02-17 01:08:42 | [diff] [blame] | 971 | "Failed to set remote answer sdp: Failed to set remote video description " |
| 972 | "send parameters.", |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 973 | error); |
| 974 | } |
| 975 | |
| 976 | // Tests that if the underlying video encoder fails once then subsequent |
| 977 | // attempts at setting the local/remote description will also fail, even if |
| 978 | // SetSendCodecs no longer fails. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 979 | TEST_P(PeerConnectionMediaTest, |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 980 | FailToApplyDescriptionIfVideoEncoderHasEverFailed) { |
| 981 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 982 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 983 | |
| 984 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 985 | |
| 986 | auto video_channel = caller->media_engine()->GetVideoChannel(0); |
| 987 | video_channel->set_fail_set_send_codecs(true); |
| 988 | |
| 989 | EXPECT_FALSE( |
| 990 | caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal())); |
| 991 | |
| 992 | video_channel->set_fail_set_send_codecs(false); |
| 993 | |
| 994 | EXPECT_FALSE(caller->SetRemoteDescription(callee->CreateAnswer())); |
| 995 | EXPECT_FALSE(caller->SetLocalDescription(caller->CreateOffer())); |
| 996 | } |
| 997 | |
| 998 | void RenameContent(cricket::SessionDescription* desc, |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 999 | cricket::MediaType media_type, |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1000 | const std::string& new_name) { |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 1001 | auto* content = cricket::GetFirstMediaContent(desc, media_type); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1002 | RTC_DCHECK(content); |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 1003 | std::string old_name = content->name; |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1004 | content->name = new_name; |
| 1005 | auto* transport = desc->GetTransportInfoByName(old_name); |
| 1006 | RTC_DCHECK(transport); |
| 1007 | transport->content_name = new_name; |
Zhi Huang | d2248f8 | 2018-04-10 21:41:03 | [diff] [blame] | 1008 | |
| 1009 | // Rename the content name in the BUNDLE group. |
| 1010 | cricket::ContentGroup new_bundle_group = |
| 1011 | *desc->GetGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 1012 | new_bundle_group.RemoveContentName(old_name); |
| 1013 | new_bundle_group.AddContentName(new_name); |
| 1014 | desc->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 1015 | desc->AddGroup(new_bundle_group); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | // Tests that an answer responds with the same MIDs as the offer. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 1019 | TEST_P(PeerConnectionMediaTest, AnswerHasSameMidsAsOffer) { |
Zhi Huang | 365381f | 2018-04-13 23:44:34 | [diff] [blame] | 1020 | const std::string kAudioMid = "notdefault1"; |
| 1021 | const std::string kVideoMid = "notdefault2"; |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1022 | |
| 1023 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1024 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1025 | |
| 1026 | auto offer = caller->CreateOffer(); |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 1027 | RenameContent(offer->description(), cricket::MEDIA_TYPE_AUDIO, kAudioMid); |
| 1028 | RenameContent(offer->description(), cricket::MEDIA_TYPE_VIDEO, kVideoMid); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1029 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 1030 | |
| 1031 | auto answer = callee->CreateAnswer(); |
| 1032 | EXPECT_EQ(kAudioMid, |
| 1033 | cricket::GetFirstAudioContent(answer->description())->name); |
| 1034 | EXPECT_EQ(kVideoMid, |
| 1035 | cricket::GetFirstVideoContent(answer->description())->name); |
| 1036 | } |
| 1037 | |
| 1038 | // Test that if the callee creates a re-offer, the MIDs are the same as the |
| 1039 | // original offer. |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 1040 | TEST_P(PeerConnectionMediaTest, ReOfferHasSameMidsAsFirstOffer) { |
Zhi Huang | 365381f | 2018-04-13 23:44:34 | [diff] [blame] | 1041 | const std::string kAudioMid = "notdefault1"; |
| 1042 | const std::string kVideoMid = "notdefault2"; |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1043 | |
| 1044 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 1045 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 1046 | |
| 1047 | auto offer = caller->CreateOffer(); |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 1048 | RenameContent(offer->description(), cricket::MEDIA_TYPE_AUDIO, kAudioMid); |
| 1049 | RenameContent(offer->description(), cricket::MEDIA_TYPE_VIDEO, kVideoMid); |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1050 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 1051 | ASSERT_TRUE(callee->SetLocalDescription(callee->CreateAnswer())); |
| 1052 | |
| 1053 | auto reoffer = callee->CreateOffer(); |
| 1054 | EXPECT_EQ(kAudioMid, |
| 1055 | cricket::GetFirstAudioContent(reoffer->description())->name); |
| 1056 | EXPECT_EQ(kVideoMid, |
| 1057 | cricket::GetFirstVideoContent(reoffer->description())->name); |
| 1058 | } |
| 1059 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 1060 | TEST_P(PeerConnectionMediaTest, |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1061 | CombinedAudioVideoBweConfigPropagatedToMediaEngine) { |
| 1062 | RTCConfiguration config; |
| 1063 | config.combined_audio_video_bwe.emplace(true); |
| 1064 | auto caller = CreatePeerConnectionWithAudioVideo(config); |
| 1065 | |
| 1066 | ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer())); |
| 1067 | |
| 1068 | auto caller_voice = caller->media_engine()->GetVoiceChannel(0); |
| 1069 | ASSERT_TRUE(caller_voice); |
| 1070 | const cricket::AudioOptions& audio_options = caller_voice->options(); |
| 1071 | EXPECT_EQ(config.combined_audio_video_bwe, |
| 1072 | audio_options.combined_audio_video_bwe); |
| 1073 | } |
| 1074 | |
Steve Anton | ad7bffc | 2018-01-22 18:21:56 | [diff] [blame] | 1075 | INSTANTIATE_TEST_CASE_P(PeerConnectionMediaTest, |
| 1076 | PeerConnectionMediaTest, |
| 1077 | Values(SdpSemantics::kPlanB, |
| 1078 | SdpSemantics::kUnifiedPlan)); |
| 1079 | |
Steve Anton | 8d3444d | 2017-10-20 22:30:51 | [diff] [blame] | 1080 | } // namespace webrtc |