Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | // 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 12:20:13 +0100 | [diff] [blame] | 17 | #include "api/call/callfactoryinterface.h" |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [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 14:30:09 -0800 | [diff] [blame] | 23 | #include "pc/rtpmediautils.h" |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 24 | #include "pc/sdputils.h" |
| 25 | #ifdef WEBRTC_ANDROID |
| 26 | #include "pc/test/androidtestinitializer.h" |
| 27 | #endif |
| 28 | #include "pc/test/fakertccertificategenerator.h" |
| 29 | #include "rtc_base/gunit.h" |
| 30 | #include "rtc_base/ptr_util.h" |
| 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 10:21:56 -0800 | [diff] [blame] | 57 | class PeerConnectionMediaBaseTest : public ::testing::Test { |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 58 | protected: |
| 59 | typedef std::unique_ptr<PeerConnectionWrapperForMediaTest> WrapperPtr; |
| 60 | |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [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 15:30:51 -0700 | [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) { |
| 75 | auto media_engine = rtc::MakeUnique<FakeMediaEngine>(); |
| 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 | |
| 82 | auto fake_port_allocator = rtc::MakeUnique<cricket::FakePortAllocator>( |
| 83 | rtc::Thread::Current(), nullptr); |
| 84 | auto observer = rtc::MakeUnique<MockPeerConnectionObserver>(); |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [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 15:30:51 -0700 | [diff] [blame] | 90 | if (!pc) { |
| 91 | return nullptr; |
| 92 | } |
| 93 | |
| 94 | auto wrapper = rtc::MakeUnique<PeerConnectionWrapperForMediaTest>( |
| 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 14:57:10 -0800 | [diff] [blame] | 113 | RtpTransceiverDirection GetMediaContentDirection( |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 114 | const SessionDescriptionInterface* sdesc, |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [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 15:30:51 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | std::unique_ptr<rtc::VirtualSocketServer> vss_; |
| 127 | rtc::AutoSocketServerThread main_; |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 128 | const SdpSemantics sdp_semantics_; |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 129 | }; |
| 130 | |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [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 15:30:51 -0700 | [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 10:21:56 -0800 | [diff] [blame] | 158 | EXPECT_PRED_FORMAT2(AssertStartsWith, error, |
| 159 | "Failed to set remote offer sdp: Failed to create"); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 162 | TEST_P(PeerConnectionMediaTest, |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [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 10:21:56 -0800 | [diff] [blame] | 169 | EXPECT_PRED_FORMAT2(AssertStartsWith, error, |
| 170 | "Failed to set local offer sdp: Failed to create"); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [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 10:21:56 -0800 | [diff] [blame] | 185 | TEST_P(PeerConnectionMediaTest, AudioVideoOfferAnswerCreateSendRecvStreams) { |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [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 10:21:56 -0800 | [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 15:30:51 -0700 | [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 10:21:56 -0800 | [diff] [blame] | 253 | // See previous test for equivalent behavior with Unified Plan semantics. |
| 254 | TEST_F(PeerConnectionMediaTestPlanB, EmptyRemoteOfferRemovesRecvStreams) { |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [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 10:21:56 -0800 | [diff] [blame] | 260 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [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 10:21:56 -0800 | [diff] [blame] | 266 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 267 | |
| 268 | auto callee_voice = callee->media_engine()->GetVoiceChannel(0); |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 269 | auto callee_video = callee->media_engine()->GetVideoChannel(0); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [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 15:30:51 -0700 | [diff] [blame] | 272 | EXPECT_EQ(1u, callee_video->send_streams().size()); |
| 273 | EXPECT_EQ(0u, callee_video->recv_streams().size()); |
| 274 | } |
| 275 | |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 276 | // Test that stopping the callee transceivers causes the media channels to be |
| 277 | // destroyed on the callee after calling SetLocalDescription on the local |
| 278 | // answer. |
| 279 | // See next test for equivalent behavior with Plan B semantics. |
| 280 | TEST_F(PeerConnectionMediaTestUnifiedPlan, |
| 281 | StoppedLocalTransceiversRemovesMediaChannels) { |
| 282 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 283 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 284 | |
| 285 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 286 | |
| 287 | // Stop both audio and video transceivers on the callee. |
| 288 | auto transceivers = callee->pc()->GetTransceivers(); |
| 289 | ASSERT_EQ(2u, transceivers.size()); |
| 290 | transceivers[0]->Stop(); |
| 291 | transceivers[1]->Stop(); |
| 292 | |
| 293 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
| 294 | |
| 295 | EXPECT_FALSE(callee->media_engine()->GetVoiceChannel(0)); |
| 296 | EXPECT_FALSE(callee->media_engine()->GetVideoChannel(0)); |
| 297 | } |
| 298 | |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 299 | // Test that removing streams from a subsequent answer causes the send streams |
| 300 | // on the callee to be removed when applied locally. |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 301 | // See previous test for equivalent behavior with Unified Plan semantics. |
| 302 | TEST_F(PeerConnectionMediaTestPlanB, EmptyLocalAnswerRemovesSendStreams) { |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 303 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 304 | auto callee = CreatePeerConnection(); |
| 305 | auto callee_audio_track = callee->AddAudioTrack("a"); |
| 306 | auto callee_video_track = callee->AddVideoTrack("v"); |
| 307 | |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 308 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 309 | |
| 310 | // Remove both tracks from callee. |
| 311 | callee->pc()->RemoveTrack(callee_audio_track); |
| 312 | callee->pc()->RemoveTrack(callee_video_track); |
| 313 | |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 314 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 315 | |
| 316 | auto callee_voice = callee->media_engine()->GetVoiceChannel(0); |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 317 | auto callee_video = callee->media_engine()->GetVideoChannel(0); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 318 | EXPECT_EQ(0u, callee_voice->send_streams().size()); |
| 319 | EXPECT_EQ(1u, callee_voice->recv_streams().size()); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 320 | EXPECT_EQ(0u, callee_video->send_streams().size()); |
| 321 | EXPECT_EQ(1u, callee_video->recv_streams().size()); |
| 322 | } |
| 323 | |
| 324 | // Test that a new stream in a subsequent offer causes a new receive stream to |
| 325 | // be created on the callee. |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 326 | TEST_P(PeerConnectionMediaTest, NewStreamInRemoteOfferAddsRecvStreams) { |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 327 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 328 | auto callee = CreatePeerConnection(); |
| 329 | |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 330 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 331 | |
| 332 | // Add second set of tracks to the caller. |
| 333 | caller->AddAudioTrack("a2"); |
| 334 | caller->AddVideoTrack("v2"); |
| 335 | |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 336 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get())); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 337 | |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 338 | auto a1 = callee->media_engine()->GetVoiceChannel(0); |
| 339 | auto a2 = callee->media_engine()->GetVoiceChannel(1); |
| 340 | auto v1 = callee->media_engine()->GetVideoChannel(0); |
| 341 | auto v2 = callee->media_engine()->GetVideoChannel(1); |
| 342 | if (IsUnifiedPlan()) { |
| 343 | ASSERT_TRUE(a1); |
| 344 | EXPECT_EQ(1u, a1->recv_streams().size()); |
| 345 | ASSERT_TRUE(a2); |
| 346 | EXPECT_EQ(1u, a2->recv_streams().size()); |
| 347 | ASSERT_TRUE(v1); |
| 348 | EXPECT_EQ(1u, v1->recv_streams().size()); |
| 349 | ASSERT_TRUE(v2); |
| 350 | EXPECT_EQ(1u, v2->recv_streams().size()); |
| 351 | } else { |
| 352 | ASSERT_TRUE(a1); |
| 353 | EXPECT_EQ(2u, a1->recv_streams().size()); |
| 354 | ASSERT_FALSE(a2); |
| 355 | ASSERT_TRUE(v1); |
| 356 | EXPECT_EQ(2u, v1->recv_streams().size()); |
| 357 | ASSERT_FALSE(v2); |
| 358 | } |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | // Test that a new stream in a subsequent answer causes a new send stream to be |
| 362 | // created on the callee when added locally. |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 363 | TEST_P(PeerConnectionMediaTest, NewStreamInLocalAnswerAddsSendStreams) { |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 364 | auto caller = CreatePeerConnection(); |
| 365 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 366 | |
Steve Anton | 22da89f | 2018-01-25 13:58:07 -0800 | [diff] [blame] | 367 | RTCOfferAnswerOptions offer_options; |
| 368 | offer_options.offer_to_receive_audio = |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 369 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
Steve Anton | 22da89f | 2018-01-25 13:58:07 -0800 | [diff] [blame] | 370 | offer_options.offer_to_receive_video = |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 371 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
Steve Anton | 22da89f | 2018-01-25 13:58:07 -0800 | [diff] [blame] | 372 | RTCOfferAnswerOptions answer_options; |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 373 | |
Steve Anton | 22da89f | 2018-01-25 13:58:07 -0800 | [diff] [blame] | 374 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get(), offer_options, |
| 375 | answer_options)); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 376 | |
| 377 | // Add second set of tracks to the callee. |
| 378 | callee->AddAudioTrack("a2"); |
| 379 | callee->AddVideoTrack("v2"); |
| 380 | |
Steve Anton | 22da89f | 2018-01-25 13:58:07 -0800 | [diff] [blame] | 381 | ASSERT_TRUE(caller->ExchangeOfferAnswerWith(callee.get(), offer_options, |
| 382 | answer_options)); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 383 | |
| 384 | auto callee_voice = callee->media_engine()->GetVoiceChannel(0); |
Steve Anton | 22da89f | 2018-01-25 13:58:07 -0800 | [diff] [blame] | 385 | ASSERT_TRUE(callee_voice); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 386 | auto callee_video = callee->media_engine()->GetVideoChannel(0); |
Steve Anton | 22da89f | 2018-01-25 13:58:07 -0800 | [diff] [blame] | 387 | ASSERT_TRUE(callee_video); |
| 388 | |
| 389 | if (IsUnifiedPlan()) { |
| 390 | EXPECT_EQ(1u, callee_voice->send_streams().size()); |
| 391 | EXPECT_EQ(1u, callee_video->send_streams().size()); |
| 392 | } else { |
| 393 | EXPECT_EQ(2u, callee_voice->send_streams().size()); |
| 394 | EXPECT_EQ(2u, callee_video->send_streams().size()); |
| 395 | } |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | // A PeerConnection with no local streams and no explicit answer constraints |
| 399 | // should not reject any offered media sections. |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 400 | TEST_P(PeerConnectionMediaTest, |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 401 | CreateAnswerWithNoStreamsAndDefaultOptionsDoesNotReject) { |
| 402 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 403 | auto callee = CreatePeerConnection(); |
| 404 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 405 | auto answer = callee->CreateAnswer(); |
| 406 | |
| 407 | const auto* audio_content = |
| 408 | cricket::GetFirstAudioContent(answer->description()); |
| 409 | ASSERT_TRUE(audio_content); |
| 410 | EXPECT_FALSE(audio_content->rejected); |
| 411 | |
| 412 | const auto* video_content = |
| 413 | cricket::GetFirstVideoContent(answer->description()); |
| 414 | ASSERT_TRUE(video_content); |
| 415 | EXPECT_FALSE(video_content->rejected); |
| 416 | } |
| 417 | |
| 418 | class PeerConnectionMediaOfferDirectionTest |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 419 | : public PeerConnectionMediaBaseTest, |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 420 | public ::testing::WithParamInterface< |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 421 | std::tuple<SdpSemantics, |
| 422 | std::tuple<bool, int, RtpTransceiverDirection>>> { |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 423 | protected: |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 424 | PeerConnectionMediaOfferDirectionTest() |
| 425 | : PeerConnectionMediaBaseTest(std::get<0>(GetParam())) { |
| 426 | auto param = std::get<1>(GetParam()); |
| 427 | send_media_ = std::get<0>(param); |
| 428 | offer_to_receive_ = std::get<1>(param); |
| 429 | expected_direction_ = std::get<2>(param); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | bool send_media_; |
| 433 | int offer_to_receive_; |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 434 | RtpTransceiverDirection expected_direction_; |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 435 | }; |
| 436 | |
| 437 | // Tests that the correct direction is set on the media description according |
| 438 | // to the presence of a local media track and the offer_to_receive setting. |
| 439 | TEST_P(PeerConnectionMediaOfferDirectionTest, VerifyDirection) { |
| 440 | auto caller = CreatePeerConnection(); |
| 441 | if (send_media_) { |
| 442 | caller->AddAudioTrack("a"); |
| 443 | } |
| 444 | |
| 445 | RTCOfferAnswerOptions options; |
| 446 | options.offer_to_receive_audio = offer_to_receive_; |
| 447 | auto offer = caller->CreateOffer(options); |
| 448 | |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 449 | auto* content = cricket::GetFirstMediaContent(offer->description(), |
| 450 | cricket::MEDIA_TYPE_AUDIO); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 451 | if (expected_direction_ == RtpTransceiverDirection::kInactive) { |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 452 | EXPECT_FALSE(content); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 453 | } else { |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 454 | EXPECT_EQ(expected_direction_, content->media_description()->direction()); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 455 | } |
| 456 | } |
| 457 | |
| 458 | // Note that in these tests, MD_INACTIVE indicates that no media section is |
| 459 | // included in the offer, not that the media direction is inactive. |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 460 | INSTANTIATE_TEST_CASE_P( |
| 461 | PeerConnectionMediaTest, |
| 462 | PeerConnectionMediaOfferDirectionTest, |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 463 | Combine( |
| 464 | Values(SdpSemantics::kPlanB, SdpSemantics::kUnifiedPlan), |
| 465 | Values(std::make_tuple(false, -1, RtpTransceiverDirection::kInactive), |
| 466 | std::make_tuple(false, 0, RtpTransceiverDirection::kInactive), |
| 467 | std::make_tuple(false, 1, RtpTransceiverDirection::kRecvOnly), |
| 468 | std::make_tuple(true, -1, RtpTransceiverDirection::kSendRecv), |
| 469 | std::make_tuple(true, 0, RtpTransceiverDirection::kSendOnly), |
| 470 | std::make_tuple(true, 1, RtpTransceiverDirection::kSendRecv)))); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 471 | |
| 472 | class PeerConnectionMediaAnswerDirectionTest |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 473 | : public PeerConnectionMediaBaseTest, |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 474 | public ::testing::WithParamInterface< |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 475 | std::tuple<SdpSemantics, RtpTransceiverDirection, bool, int>> { |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 476 | protected: |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 477 | PeerConnectionMediaAnswerDirectionTest() |
| 478 | : PeerConnectionMediaBaseTest(std::get<0>(GetParam())) { |
| 479 | offer_direction_ = std::get<1>(GetParam()); |
| 480 | send_media_ = std::get<2>(GetParam()); |
| 481 | offer_to_receive_ = std::get<3>(GetParam()); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 482 | } |
| 483 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 484 | RtpTransceiverDirection offer_direction_; |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 485 | bool send_media_; |
| 486 | int offer_to_receive_; |
| 487 | }; |
| 488 | |
| 489 | // Tests that the direction in an answer is correct according to direction sent |
| 490 | // in the offer, the presence of a local media track on the receive side and the |
| 491 | // offer_to_receive setting. |
| 492 | TEST_P(PeerConnectionMediaAnswerDirectionTest, VerifyDirection) { |
Steve Anton | 22da89f | 2018-01-25 13:58:07 -0800 | [diff] [blame] | 493 | if (IsUnifiedPlan() && |
| 494 | offer_to_receive_ != RTCOfferAnswerOptions::kUndefined) { |
| 495 | // offer_to_receive_ is not implemented when creating answers with Unified |
| 496 | // Plan semantics specified. |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 497 | return; |
| 498 | } |
Steve Anton | 22da89f | 2018-01-25 13:58:07 -0800 | [diff] [blame] | 499 | |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 500 | auto caller = CreatePeerConnection(); |
| 501 | caller->AddAudioTrack("a"); |
| 502 | |
| 503 | // Create the offer with an audio section and set its direction. |
| 504 | auto offer = caller->CreateOffer(); |
| 505 | cricket::GetFirstAudioContentDescription(offer->description()) |
| 506 | ->set_direction(offer_direction_); |
| 507 | |
| 508 | auto callee = CreatePeerConnection(); |
| 509 | if (send_media_) { |
| 510 | callee->AddAudioTrack("a"); |
| 511 | } |
| 512 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 513 | |
| 514 | // Create the answer according to the test parameters. |
| 515 | RTCOfferAnswerOptions options; |
| 516 | options.offer_to_receive_audio = offer_to_receive_; |
| 517 | auto answer = callee->CreateAnswer(options); |
| 518 | |
| 519 | // The expected direction in the answer is the intersection of each side's |
| 520 | // capability to send/recv media. |
| 521 | // For the offerer, the direction is given in the offer (offer_direction_). |
| 522 | // For the answerer, the direction has two components: |
| 523 | // 1. Send if the answerer has a local track to send. |
| 524 | // 2. Receive if the answerer has explicitly set the offer_to_receive to 1 or |
| 525 | // if it has been left as default. |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 526 | bool offer_send = RtpTransceiverDirectionHasSend(offer_direction_); |
| 527 | bool offer_recv = RtpTransceiverDirectionHasRecv(offer_direction_); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 528 | |
| 529 | // The negotiated components determine the direction set in the answer. |
Steve Anton | 1d03a75 | 2017-11-27 14:30:09 -0800 | [diff] [blame] | 530 | bool negotiate_send = (send_media_ && offer_recv); |
| 531 | bool negotiate_recv = ((offer_to_receive_ != 0) && offer_send); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 532 | |
| 533 | auto expected_direction = |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 534 | RtpTransceiverDirectionFromSendRecv(negotiate_send, negotiate_recv); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 535 | EXPECT_EQ(expected_direction, |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 536 | GetMediaContentDirection(answer.get(), cricket::MEDIA_TYPE_AUDIO)); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | // Tests that the media section is rejected if and only if the callee has no |
| 540 | // local media track and has set offer_to_receive to 0, no matter which |
| 541 | // direction the caller indicated in the offer. |
| 542 | TEST_P(PeerConnectionMediaAnswerDirectionTest, VerifyRejected) { |
Steve Anton | 22da89f | 2018-01-25 13:58:07 -0800 | [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 10:21:56 -0800 | [diff] [blame] | 547 | return; |
| 548 | } |
Steve Anton | 22da89f | 2018-01-25 13:58:07 -0800 | [diff] [blame] | 549 | |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [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 media section is rejected if and only if offer_to_receive is explicitly |
| 570 | // set to 0 and there is no media to send. |
| 571 | auto* audio_content = cricket::GetFirstAudioContent(answer->description()); |
| 572 | ASSERT_TRUE(audio_content); |
| 573 | EXPECT_EQ((offer_to_receive_ == 0 && !send_media_), audio_content->rejected); |
| 574 | } |
| 575 | |
| 576 | INSTANTIATE_TEST_CASE_P(PeerConnectionMediaTest, |
| 577 | PeerConnectionMediaAnswerDirectionTest, |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 578 | Combine(Values(SdpSemantics::kPlanB, |
| 579 | SdpSemantics::kUnifiedPlan), |
| 580 | Values(RtpTransceiverDirection::kInactive, |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 581 | RtpTransceiverDirection::kSendOnly, |
| 582 | RtpTransceiverDirection::kRecvOnly, |
| 583 | RtpTransceiverDirection::kSendRecv), |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 584 | Bool(), |
| 585 | Values(-1, 0, 1))); |
| 586 | |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 587 | TEST_P(PeerConnectionMediaTest, OfferHasDifferentDirectionForAudioVideo) { |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 588 | auto caller = CreatePeerConnection(); |
| 589 | caller->AddVideoTrack("v"); |
| 590 | |
| 591 | RTCOfferAnswerOptions options; |
| 592 | options.offer_to_receive_audio = 1; |
| 593 | options.offer_to_receive_video = 0; |
| 594 | auto offer = caller->CreateOffer(options); |
| 595 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 596 | EXPECT_EQ(RtpTransceiverDirection::kRecvOnly, |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 597 | GetMediaContentDirection(offer.get(), cricket::MEDIA_TYPE_AUDIO)); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 598 | EXPECT_EQ(RtpTransceiverDirection::kSendOnly, |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 599 | GetMediaContentDirection(offer.get(), cricket::MEDIA_TYPE_VIDEO)); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 600 | } |
| 601 | |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 602 | TEST_P(PeerConnectionMediaTest, AnswerHasDifferentDirectionsForAudioVideo) { |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 603 | if (IsUnifiedPlan()) { |
Steve Anton | 22da89f | 2018-01-25 13:58:07 -0800 | [diff] [blame] | 604 | // offer_to_receive_ is not implemented when creating answers with Unified |
| 605 | // Plan semantics specified. |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 606 | return; |
| 607 | } |
| 608 | |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 609 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 610 | auto callee = CreatePeerConnection(); |
| 611 | callee->AddVideoTrack("v"); |
| 612 | |
| 613 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 614 | |
| 615 | RTCOfferAnswerOptions options; |
| 616 | options.offer_to_receive_audio = 1; |
| 617 | options.offer_to_receive_video = 0; |
| 618 | auto answer = callee->CreateAnswer(options); |
| 619 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 620 | EXPECT_EQ(RtpTransceiverDirection::kRecvOnly, |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 621 | GetMediaContentDirection(answer.get(), cricket::MEDIA_TYPE_AUDIO)); |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 622 | EXPECT_EQ(RtpTransceiverDirection::kSendOnly, |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 623 | GetMediaContentDirection(answer.get(), cricket::MEDIA_TYPE_VIDEO)); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | void AddComfortNoiseCodecsToSend(cricket::FakeMediaEngine* media_engine) { |
| 627 | const cricket::AudioCodec kComfortNoiseCodec8k(102, "CN", 8000, 0, 1); |
| 628 | const cricket::AudioCodec kComfortNoiseCodec16k(103, "CN", 16000, 0, 1); |
| 629 | |
| 630 | auto codecs = media_engine->audio_send_codecs(); |
| 631 | codecs.push_back(kComfortNoiseCodec8k); |
| 632 | codecs.push_back(kComfortNoiseCodec16k); |
| 633 | media_engine->SetAudioCodecs(codecs); |
| 634 | } |
| 635 | |
| 636 | bool HasAnyComfortNoiseCodecs(const cricket::SessionDescription* desc) { |
| 637 | const auto* audio_desc = cricket::GetFirstAudioContentDescription(desc); |
| 638 | for (const auto& codec : audio_desc->codecs()) { |
| 639 | if (codec.name == "CN") { |
| 640 | return true; |
| 641 | } |
| 642 | } |
| 643 | return false; |
| 644 | } |
| 645 | |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 646 | TEST_P(PeerConnectionMediaTest, |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 647 | CreateOfferWithNoVoiceActivityDetectionIncludesNoComfortNoiseCodecs) { |
| 648 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 649 | AddComfortNoiseCodecsToSend(caller->media_engine()); |
| 650 | |
| 651 | RTCOfferAnswerOptions options; |
| 652 | options.voice_activity_detection = false; |
| 653 | auto offer = caller->CreateOffer(options); |
| 654 | |
| 655 | EXPECT_FALSE(HasAnyComfortNoiseCodecs(offer->description())); |
| 656 | } |
| 657 | |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 658 | TEST_P(PeerConnectionMediaTest, |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 659 | CreateAnswerWithNoVoiceActivityDetectionIncludesNoComfortNoiseCodecs) { |
| 660 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 661 | AddComfortNoiseCodecsToSend(caller->media_engine()); |
| 662 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 663 | AddComfortNoiseCodecsToSend(callee->media_engine()); |
| 664 | |
| 665 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 666 | |
| 667 | RTCOfferAnswerOptions options; |
| 668 | options.voice_activity_detection = false; |
| 669 | auto answer = callee->CreateAnswer(options); |
| 670 | |
| 671 | EXPECT_FALSE(HasAnyComfortNoiseCodecs(answer->description())); |
| 672 | } |
| 673 | |
| 674 | // The following test group verifies that we reject answers with invalid media |
| 675 | // sections as per RFC 3264. |
| 676 | |
| 677 | class PeerConnectionMediaInvalidMediaTest |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 678 | : public PeerConnectionMediaBaseTest, |
| 679 | public ::testing::WithParamInterface<std::tuple< |
| 680 | SdpSemantics, |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 681 | std::tuple<std::string, |
| 682 | std::function<void(cricket::SessionDescription*)>, |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 683 | std::string>>> { |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 684 | protected: |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 685 | PeerConnectionMediaInvalidMediaTest() |
| 686 | : PeerConnectionMediaBaseTest(std::get<0>(GetParam())) { |
| 687 | auto param = std::get<1>(GetParam()); |
| 688 | mutator_ = std::get<1>(param); |
| 689 | expected_error_ = std::get<2>(param); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | std::function<void(cricket::SessionDescription*)> mutator_; |
| 693 | std::string expected_error_; |
| 694 | }; |
| 695 | |
| 696 | TEST_P(PeerConnectionMediaInvalidMediaTest, FailToSetRemoteAnswer) { |
| 697 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 698 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 699 | |
| 700 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 701 | |
| 702 | auto answer = callee->CreateAnswer(); |
| 703 | mutator_(answer->description()); |
| 704 | |
| 705 | std::string error; |
| 706 | ASSERT_FALSE(caller->SetRemoteDescription(std::move(answer), &error)); |
| 707 | EXPECT_EQ("Failed to set remote answer sdp: " + expected_error_, error); |
| 708 | } |
| 709 | |
| 710 | TEST_P(PeerConnectionMediaInvalidMediaTest, FailToSetLocalAnswer) { |
| 711 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 712 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 713 | |
| 714 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 715 | |
| 716 | auto answer = callee->CreateAnswer(); |
| 717 | mutator_(answer->description()); |
| 718 | |
| 719 | std::string error; |
| 720 | ASSERT_FALSE(callee->SetLocalDescription(std::move(answer), &error)); |
| 721 | EXPECT_EQ("Failed to set local answer sdp: " + expected_error_, error); |
| 722 | } |
| 723 | |
| 724 | void RemoveVideoContent(cricket::SessionDescription* desc) { |
| 725 | auto content_name = cricket::GetFirstVideoContent(desc)->name; |
| 726 | desc->RemoveContentByName(content_name); |
| 727 | desc->RemoveTransportInfoByName(content_name); |
| 728 | } |
| 729 | |
| 730 | void RenameVideoContent(cricket::SessionDescription* desc) { |
| 731 | auto* video_content = cricket::GetFirstVideoContent(desc); |
| 732 | auto* transport_info = desc->GetTransportInfoByName(video_content->name); |
| 733 | video_content->name = "video_renamed"; |
| 734 | transport_info->content_name = video_content->name; |
| 735 | } |
| 736 | |
| 737 | void ReverseMediaContent(cricket::SessionDescription* desc) { |
| 738 | std::reverse(desc->contents().begin(), desc->contents().end()); |
| 739 | std::reverse(desc->transport_infos().begin(), desc->transport_infos().end()); |
| 740 | } |
| 741 | |
| 742 | void ChangeMediaTypeAudioToVideo(cricket::SessionDescription* desc) { |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 743 | std::string audio_mid = cricket::GetFirstAudioContent(desc)->name; |
| 744 | desc->RemoveContentByName(audio_mid); |
| 745 | auto* video_content = cricket::GetFirstVideoContent(desc); |
| 746 | desc->AddContent(audio_mid, video_content->type, |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 747 | video_content->media_description()->Copy()); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | constexpr char kMLinesOutOfOrder[] = |
| 751 | "The order of m-lines in answer doesn't match order in offer. Rejecting " |
| 752 | "answer."; |
| 753 | |
| 754 | INSTANTIATE_TEST_CASE_P( |
| 755 | PeerConnectionMediaTest, |
| 756 | PeerConnectionMediaInvalidMediaTest, |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 757 | Combine(Values(SdpSemantics::kPlanB, SdpSemantics::kUnifiedPlan), |
| 758 | Values(std::make_tuple("remove video", |
| 759 | RemoveVideoContent, |
| 760 | kMLinesOutOfOrder), |
| 761 | std::make_tuple("rename video", |
| 762 | RenameVideoContent, |
| 763 | kMLinesOutOfOrder), |
| 764 | std::make_tuple("reverse media sections", |
| 765 | ReverseMediaContent, |
| 766 | kMLinesOutOfOrder), |
| 767 | std::make_tuple("change audio type to video type", |
| 768 | ChangeMediaTypeAudioToVideo, |
| 769 | kMLinesOutOfOrder)))); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 770 | |
| 771 | // Test that the correct media engine send/recv streams are created when doing |
| 772 | // a series of offer/answers where audio/video are both sent, then audio is |
| 773 | // rejected, then both audio/video sent again. |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 774 | TEST_P(PeerConnectionMediaTest, TestAVOfferWithAudioOnlyAnswer) { |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 775 | if (IsUnifiedPlan()) { |
Steve Anton | 22da89f | 2018-01-25 13:58:07 -0800 | [diff] [blame] | 776 | // offer_to_receive_ is not implemented when creating answers with Unified |
| 777 | // Plan semantics specified. |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 778 | return; |
| 779 | } |
| 780 | |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 781 | RTCOfferAnswerOptions options_reject_video; |
| 782 | options_reject_video.offer_to_receive_audio = |
| 783 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 784 | options_reject_video.offer_to_receive_video = 0; |
| 785 | |
| 786 | auto caller = CreatePeerConnection(); |
| 787 | caller->AddAudioTrack("a"); |
| 788 | caller->AddVideoTrack("v"); |
| 789 | auto callee = CreatePeerConnection(); |
| 790 | |
| 791 | // Caller initially offers to send/recv audio and video. |
| 792 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 793 | // Callee accepts the audio as recv only but rejects the video. |
| 794 | ASSERT_TRUE(caller->SetRemoteDescription( |
| 795 | callee->CreateAnswerAndSetAsLocal(options_reject_video))); |
| 796 | |
| 797 | auto caller_voice = caller->media_engine()->GetVoiceChannel(0); |
| 798 | ASSERT_TRUE(caller_voice); |
| 799 | EXPECT_EQ(0u, caller_voice->recv_streams().size()); |
| 800 | EXPECT_EQ(1u, caller_voice->send_streams().size()); |
| 801 | auto caller_video = caller->media_engine()->GetVideoChannel(0); |
| 802 | EXPECT_FALSE(caller_video); |
| 803 | |
| 804 | // Callee adds its own audio/video stream and offers to receive audio/video |
| 805 | // too. |
| 806 | callee->AddAudioTrack("a"); |
| 807 | auto callee_video_track = callee->AddVideoTrack("v"); |
| 808 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 809 | ASSERT_TRUE( |
| 810 | caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal())); |
| 811 | |
| 812 | auto callee_voice = callee->media_engine()->GetVoiceChannel(0); |
| 813 | ASSERT_TRUE(callee_voice); |
| 814 | EXPECT_EQ(1u, callee_voice->recv_streams().size()); |
| 815 | EXPECT_EQ(1u, callee_voice->send_streams().size()); |
| 816 | auto callee_video = callee->media_engine()->GetVideoChannel(0); |
| 817 | ASSERT_TRUE(callee_video); |
| 818 | EXPECT_EQ(1u, callee_video->recv_streams().size()); |
| 819 | EXPECT_EQ(1u, callee_video->send_streams().size()); |
| 820 | |
| 821 | // Callee removes video but keeps audio and rejects the video once again. |
| 822 | callee->pc()->RemoveTrack(callee_video_track); |
| 823 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 824 | ASSERT_TRUE( |
| 825 | callee->SetLocalDescription(callee->CreateAnswer(options_reject_video))); |
| 826 | |
| 827 | callee_voice = callee->media_engine()->GetVoiceChannel(0); |
| 828 | ASSERT_TRUE(callee_voice); |
| 829 | EXPECT_EQ(1u, callee_voice->recv_streams().size()); |
| 830 | EXPECT_EQ(1u, callee_voice->send_streams().size()); |
| 831 | callee_video = callee->media_engine()->GetVideoChannel(0); |
| 832 | EXPECT_FALSE(callee_video); |
| 833 | } |
| 834 | |
| 835 | // Test that the correct media engine send/recv streams are created when doing |
| 836 | // a series of offer/answers where audio/video are both sent, then video is |
| 837 | // rejected, then both audio/video sent again. |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 838 | TEST_P(PeerConnectionMediaTest, TestAVOfferWithVideoOnlyAnswer) { |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 839 | if (IsUnifiedPlan()) { |
Steve Anton | 22da89f | 2018-01-25 13:58:07 -0800 | [diff] [blame] | 840 | // offer_to_receive_ is not implemented when creating answers with Unified |
| 841 | // Plan semantics specified. |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 842 | return; |
| 843 | } |
| 844 | |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 845 | // Disable the bundling here. If the media is bundled on audio |
| 846 | // transport, then we can't reject the audio because switching the bundled |
| 847 | // transport is not currently supported. |
| 848 | // (https://bugs.chromium.org/p/webrtc/issues/detail?id=6704) |
| 849 | RTCOfferAnswerOptions options_no_bundle; |
| 850 | options_no_bundle.use_rtp_mux = false; |
| 851 | RTCOfferAnswerOptions options_reject_audio = options_no_bundle; |
| 852 | options_reject_audio.offer_to_receive_audio = 0; |
| 853 | options_reject_audio.offer_to_receive_video = |
| 854 | RTCOfferAnswerOptions::kMaxOfferToReceiveMedia; |
| 855 | |
| 856 | auto caller = CreatePeerConnection(); |
| 857 | caller->AddAudioTrack("a"); |
| 858 | caller->AddVideoTrack("v"); |
| 859 | auto callee = CreatePeerConnection(); |
| 860 | |
| 861 | // Caller initially offers to send/recv audio and video. |
| 862 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 863 | // Callee accepts the video as recv only but rejects the audio. |
| 864 | ASSERT_TRUE(caller->SetRemoteDescription( |
| 865 | callee->CreateAnswerAndSetAsLocal(options_reject_audio))); |
| 866 | |
| 867 | auto caller_voice = caller->media_engine()->GetVoiceChannel(0); |
| 868 | EXPECT_FALSE(caller_voice); |
| 869 | auto caller_video = caller->media_engine()->GetVideoChannel(0); |
| 870 | ASSERT_TRUE(caller_video); |
| 871 | EXPECT_EQ(0u, caller_video->recv_streams().size()); |
| 872 | EXPECT_EQ(1u, caller_video->send_streams().size()); |
| 873 | |
| 874 | // Callee adds its own audio/video stream and offers to receive audio/video |
| 875 | // too. |
| 876 | auto callee_audio_track = callee->AddAudioTrack("a"); |
| 877 | callee->AddVideoTrack("v"); |
| 878 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 879 | ASSERT_TRUE(caller->SetRemoteDescription( |
| 880 | callee->CreateAnswerAndSetAsLocal(options_no_bundle))); |
| 881 | |
| 882 | auto callee_voice = callee->media_engine()->GetVoiceChannel(0); |
| 883 | ASSERT_TRUE(callee_voice); |
| 884 | EXPECT_EQ(1u, callee_voice->recv_streams().size()); |
| 885 | EXPECT_EQ(1u, callee_voice->send_streams().size()); |
| 886 | auto callee_video = callee->media_engine()->GetVideoChannel(0); |
| 887 | ASSERT_TRUE(callee_video); |
| 888 | EXPECT_EQ(1u, callee_video->recv_streams().size()); |
| 889 | EXPECT_EQ(1u, callee_video->send_streams().size()); |
| 890 | |
| 891 | // Callee removes audio but keeps video and rejects the audio once again. |
| 892 | callee->pc()->RemoveTrack(callee_audio_track); |
| 893 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 894 | ASSERT_TRUE( |
| 895 | callee->SetLocalDescription(callee->CreateAnswer(options_reject_audio))); |
| 896 | |
| 897 | callee_voice = callee->media_engine()->GetVoiceChannel(0); |
| 898 | EXPECT_FALSE(callee_voice); |
| 899 | callee_video = callee->media_engine()->GetVideoChannel(0); |
| 900 | ASSERT_TRUE(callee_video); |
| 901 | EXPECT_EQ(1u, callee_video->recv_streams().size()); |
| 902 | EXPECT_EQ(1u, callee_video->send_streams().size()); |
| 903 | } |
| 904 | |
| 905 | // Tests that if the underlying video encoder fails to be initialized (signaled |
| 906 | // by failing to set send codecs), the PeerConnection signals the error to the |
| 907 | // client. |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 908 | TEST_P(PeerConnectionMediaTest, MediaEngineErrorPropagatedToClients) { |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 909 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 910 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 911 | |
| 912 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 913 | |
| 914 | auto video_channel = caller->media_engine()->GetVideoChannel(0); |
| 915 | video_channel->set_fail_set_send_codecs(true); |
| 916 | |
| 917 | std::string error; |
| 918 | ASSERT_FALSE(caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal(), |
| 919 | &error)); |
| 920 | EXPECT_EQ( |
Steve Anton | 80dd7b5 | 2018-02-16 17:08:42 -0800 | [diff] [blame] | 921 | "Failed to set remote answer sdp: Failed to set remote video description " |
| 922 | "send parameters.", |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 923 | error); |
| 924 | } |
| 925 | |
| 926 | // Tests that if the underlying video encoder fails once then subsequent |
| 927 | // attempts at setting the local/remote description will also fail, even if |
| 928 | // SetSendCodecs no longer fails. |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 929 | TEST_P(PeerConnectionMediaTest, |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 930 | FailToApplyDescriptionIfVideoEncoderHasEverFailed) { |
| 931 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 932 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 933 | |
| 934 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 935 | |
| 936 | auto video_channel = caller->media_engine()->GetVideoChannel(0); |
| 937 | video_channel->set_fail_set_send_codecs(true); |
| 938 | |
| 939 | EXPECT_FALSE( |
| 940 | caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal())); |
| 941 | |
| 942 | video_channel->set_fail_set_send_codecs(false); |
| 943 | |
| 944 | EXPECT_FALSE(caller->SetRemoteDescription(callee->CreateAnswer())); |
| 945 | EXPECT_FALSE(caller->SetLocalDescription(caller->CreateOffer())); |
| 946 | } |
| 947 | |
| 948 | void RenameContent(cricket::SessionDescription* desc, |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 949 | cricket::MediaType media_type, |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 950 | const std::string& new_name) { |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 951 | auto* content = cricket::GetFirstMediaContent(desc, media_type); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 952 | RTC_DCHECK(content); |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 953 | std::string old_name = content->name; |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 954 | content->name = new_name; |
| 955 | auto* transport = desc->GetTransportInfoByName(old_name); |
| 956 | RTC_DCHECK(transport); |
| 957 | transport->content_name = new_name; |
| 958 | } |
| 959 | |
| 960 | // Tests that an answer responds with the same MIDs as the offer. |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 961 | TEST_P(PeerConnectionMediaTest, AnswerHasSameMidsAsOffer) { |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 962 | const std::string kAudioMid = "not default1"; |
| 963 | const std::string kVideoMid = "not default2"; |
| 964 | |
| 965 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 966 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 967 | |
| 968 | auto offer = caller->CreateOffer(); |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 969 | RenameContent(offer->description(), cricket::MEDIA_TYPE_AUDIO, kAudioMid); |
| 970 | RenameContent(offer->description(), cricket::MEDIA_TYPE_VIDEO, kVideoMid); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 971 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 972 | |
| 973 | auto answer = callee->CreateAnswer(); |
| 974 | EXPECT_EQ(kAudioMid, |
| 975 | cricket::GetFirstAudioContent(answer->description())->name); |
| 976 | EXPECT_EQ(kVideoMid, |
| 977 | cricket::GetFirstVideoContent(answer->description())->name); |
| 978 | } |
| 979 | |
| 980 | // Test that if the callee creates a re-offer, the MIDs are the same as the |
| 981 | // original offer. |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 982 | TEST_P(PeerConnectionMediaTest, ReOfferHasSameMidsAsFirstOffer) { |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 983 | const std::string kAudioMid = "not default1"; |
| 984 | const std::string kVideoMid = "not default2"; |
| 985 | |
| 986 | auto caller = CreatePeerConnectionWithAudioVideo(); |
| 987 | auto callee = CreatePeerConnectionWithAudioVideo(); |
| 988 | |
| 989 | auto offer = caller->CreateOffer(); |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 990 | RenameContent(offer->description(), cricket::MEDIA_TYPE_AUDIO, kAudioMid); |
| 991 | RenameContent(offer->description(), cricket::MEDIA_TYPE_VIDEO, kVideoMid); |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 992 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 993 | ASSERT_TRUE(callee->SetLocalDescription(callee->CreateAnswer())); |
| 994 | |
| 995 | auto reoffer = callee->CreateOffer(); |
| 996 | EXPECT_EQ(kAudioMid, |
| 997 | cricket::GetFirstAudioContent(reoffer->description())->name); |
| 998 | EXPECT_EQ(kVideoMid, |
| 999 | cricket::GetFirstVideoContent(reoffer->description())->name); |
| 1000 | } |
| 1001 | |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 1002 | TEST_P(PeerConnectionMediaTest, |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 1003 | CombinedAudioVideoBweConfigPropagatedToMediaEngine) { |
| 1004 | RTCConfiguration config; |
| 1005 | config.combined_audio_video_bwe.emplace(true); |
| 1006 | auto caller = CreatePeerConnectionWithAudioVideo(config); |
| 1007 | |
| 1008 | ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer())); |
| 1009 | |
| 1010 | auto caller_voice = caller->media_engine()->GetVoiceChannel(0); |
| 1011 | ASSERT_TRUE(caller_voice); |
| 1012 | const cricket::AudioOptions& audio_options = caller_voice->options(); |
| 1013 | EXPECT_EQ(config.combined_audio_video_bwe, |
| 1014 | audio_options.combined_audio_video_bwe); |
| 1015 | } |
| 1016 | |
Steve Anton | ad7bffc | 2018-01-22 10:21:56 -0800 | [diff] [blame] | 1017 | INSTANTIATE_TEST_CASE_P(PeerConnectionMediaTest, |
| 1018 | PeerConnectionMediaTest, |
| 1019 | Values(SdpSemantics::kPlanB, |
| 1020 | SdpSemantics::kUnifiedPlan)); |
| 1021 | |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 1022 | } // namespace webrtc |