Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 static const char kSdpStringMs1Video1[] = | 232 static const char kSdpStringMs1Video1[] = |
| 233 "a=ssrc:4 cname:stream1\r\n" | 233 "a=ssrc:4 cname:stream1\r\n" |
| 234 "a=ssrc:4 msid:stream1 videotrack1\r\n"; | 234 "a=ssrc:4 msid:stream1 videotrack1\r\n"; |
| 235 | 235 |
| 236 #define MAYBE_SKIP_TEST(feature) \ | 236 #define MAYBE_SKIP_TEST(feature) \ |
| 237 if (!(feature())) { \ | 237 if (!(feature())) { \ |
| 238 LOG(LS_INFO) << "Feature disabled... skipping"; \ | 238 LOG(LS_INFO) << "Feature disabled... skipping"; \ |
| 239 return; \ | 239 return; \ |
| 240 } | 240 } |
| 241 | 241 |
| 242 using ::testing::Exactly; | |
| 243 using cricket::StreamParams; | |
| 242 using rtc::scoped_refptr; | 244 using rtc::scoped_refptr; |
| 243 using ::testing::Exactly; | |
| 244 using webrtc::AudioSourceInterface; | 245 using webrtc::AudioSourceInterface; |
| 245 using webrtc::AudioTrack; | 246 using webrtc::AudioTrack; |
| 246 using webrtc::AudioTrackInterface; | 247 using webrtc::AudioTrackInterface; |
| 247 using webrtc::DataBuffer; | 248 using webrtc::DataBuffer; |
| 248 using webrtc::DataChannelInterface; | 249 using webrtc::DataChannelInterface; |
| 249 using webrtc::FakeConstraints; | 250 using webrtc::FakeConstraints; |
| 250 using webrtc::IceCandidateInterface; | 251 using webrtc::IceCandidateInterface; |
| 252 using webrtc::JsepSessionDescription; | |
| 251 using webrtc::MediaConstraintsInterface; | 253 using webrtc::MediaConstraintsInterface; |
| 252 using webrtc::MediaStream; | 254 using webrtc::MediaStream; |
| 253 using webrtc::MediaStreamInterface; | 255 using webrtc::MediaStreamInterface; |
| 254 using webrtc::MediaStreamTrackInterface; | 256 using webrtc::MediaStreamTrackInterface; |
| 255 using webrtc::MockCreateSessionDescriptionObserver; | 257 using webrtc::MockCreateSessionDescriptionObserver; |
| 256 using webrtc::MockDataChannelObserver; | 258 using webrtc::MockDataChannelObserver; |
| 257 using webrtc::MockSetSessionDescriptionObserver; | 259 using webrtc::MockSetSessionDescriptionObserver; |
| 258 using webrtc::MockStatsObserver; | 260 using webrtc::MockStatsObserver; |
| 259 using webrtc::NotifierInterface; | 261 using webrtc::NotifierInterface; |
| 260 using webrtc::ObserverInterface; | 262 using webrtc::ObserverInterface; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders, | 320 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders, |
| 319 const std::string& id) { | 321 const std::string& id) { |
| 320 for (const auto& sender : senders) { | 322 for (const auto& sender : senders) { |
| 321 if (sender->id() == id) { | 323 if (sender->id() == id) { |
| 322 return true; | 324 return true; |
| 323 } | 325 } |
| 324 } | 326 } |
| 325 return false; | 327 return false; |
| 326 } | 328 } |
| 327 | 329 |
| 330 // Check if |senders| contains the specified sender, by id and stream id. | |
| 331 bool ContainsSender( | |
| 332 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders, | |
| 333 const std::string& id, | |
| 334 const std::string& stream_id) { | |
| 335 for (const auto& sender : senders) { | |
| 336 if (sender->id() == id && sender->stream_id() == stream_id) { | |
| 337 return true; | |
| 338 } | |
| 339 } | |
| 340 return false; | |
| 341 } | |
| 342 | |
| 328 // Create a collection of streams. | 343 // Create a collection of streams. |
| 329 // CreateStreamCollection(1) creates a collection that | 344 // CreateStreamCollection(1) creates a collection that |
| 330 // correspond to kSdpStringWithStream1. | 345 // correspond to kSdpStringWithStream1. |
| 331 // CreateStreamCollection(2) correspond to kSdpStringWithStream1And2. | 346 // CreateStreamCollection(2) correspond to kSdpStringWithStream1And2. |
| 332 rtc::scoped_refptr<StreamCollection> CreateStreamCollection( | 347 rtc::scoped_refptr<StreamCollection> CreateStreamCollection( |
| 333 int number_of_streams) { | 348 int number_of_streams, |
| 349 int tracks_per_stream) { | |
| 334 rtc::scoped_refptr<StreamCollection> local_collection( | 350 rtc::scoped_refptr<StreamCollection> local_collection( |
| 335 StreamCollection::Create()); | 351 StreamCollection::Create()); |
| 336 | 352 |
| 337 for (int i = 0; i < number_of_streams; ++i) { | 353 for (int i = 0; i < number_of_streams; ++i) { |
| 338 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream( | 354 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream( |
| 339 webrtc::MediaStream::Create(kStreams[i])); | 355 webrtc::MediaStream::Create(kStreams[i])); |
| 340 | 356 |
| 341 // Add a local audio track. | 357 for (int j = 0; j < tracks_per_stream; ++j) { |
| 342 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( | 358 // Add a local audio track. |
| 343 webrtc::AudioTrack::Create(kAudioTracks[i], nullptr)); | 359 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( |
| 344 stream->AddTrack(audio_track); | 360 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j], |
| 361 nullptr)); | |
| 362 stream->AddTrack(audio_track); | |
| 345 | 363 |
| 346 // Add a local video track. | 364 // Add a local video track. |
| 347 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( | 365 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( |
| 348 webrtc::VideoTrack::Create(kVideoTracks[i], | 366 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j], |
| 349 webrtc::FakeVideoTrackSource::Create())); | 367 webrtc::FakeVideoTrackSource::Create())); |
| 350 stream->AddTrack(video_track); | 368 stream->AddTrack(video_track); |
| 369 } | |
| 351 | 370 |
| 352 local_collection->AddStream(stream); | 371 local_collection->AddStream(stream); |
| 353 } | 372 } |
| 354 return local_collection; | 373 return local_collection; |
| 355 } | 374 } |
| 356 | 375 |
| 357 // Check equality of StreamCollections. | 376 // Check equality of StreamCollections. |
| 358 bool CompareStreamCollections(StreamCollectionInterface* s1, | 377 bool CompareStreamCollections(StreamCollectionInterface* s1, |
| 359 StreamCollectionInterface* s2) { | 378 StreamCollectionInterface* s2) { |
| 360 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) { | 379 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) { |
| (...skipping 1616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1977 // This test verifies that the remote MediaStreams corresponding to a received | 1996 // This test verifies that the remote MediaStreams corresponding to a received |
| 1978 // SDP string is created. In this test the two separate MediaStreams are | 1997 // SDP string is created. In this test the two separate MediaStreams are |
| 1979 // signaled. | 1998 // signaled. |
| 1980 TEST_F(PeerConnectionInterfaceTest, UpdateRemoteStreams) { | 1999 TEST_F(PeerConnectionInterfaceTest, UpdateRemoteStreams) { |
| 1981 FakeConstraints constraints; | 2000 FakeConstraints constraints; |
| 1982 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | 2001 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1983 true); | 2002 true); |
| 1984 CreatePeerConnection(&constraints); | 2003 CreatePeerConnection(&constraints); |
| 1985 CreateAndSetRemoteOffer(kSdpStringWithStream1); | 2004 CreateAndSetRemoteOffer(kSdpStringWithStream1); |
| 1986 | 2005 |
| 1987 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1)); | 2006 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1)); |
| 1988 EXPECT_TRUE( | 2007 EXPECT_TRUE( |
| 1989 CompareStreamCollections(observer_.remote_streams(), reference.get())); | 2008 CompareStreamCollections(observer_.remote_streams(), reference.get())); |
| 1990 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); | 2009 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 1991 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr); | 2010 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr); |
| 1992 | 2011 |
| 1993 // Create a session description based on another SDP with another | 2012 // Create a session description based on another SDP with another |
| 1994 // MediaStream. | 2013 // MediaStream. |
| 1995 CreateAndSetRemoteOffer(kSdpStringWithStream1And2); | 2014 CreateAndSetRemoteOffer(kSdpStringWithStream1And2); |
| 1996 | 2015 |
| 1997 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2)); | 2016 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1)); |
| 1998 EXPECT_TRUE( | 2017 EXPECT_TRUE( |
| 1999 CompareStreamCollections(observer_.remote_streams(), reference2.get())); | 2018 CompareStreamCollections(observer_.remote_streams(), reference2.get())); |
| 2000 } | 2019 } |
| 2001 | 2020 |
| 2002 // This test verifies that when remote tracks are added/removed from SDP, the | 2021 // This test verifies that when remote tracks are added/removed from SDP, the |
| 2003 // created remote streams are updated appropriately. | 2022 // created remote streams are updated appropriately. |
| 2004 TEST_F(PeerConnectionInterfaceTest, | 2023 TEST_F(PeerConnectionInterfaceTest, |
| 2005 AddRemoveTrackFromExistingRemoteMediaStream) { | 2024 AddRemoveTrackFromExistingRemoteMediaStream) { |
| 2006 FakeConstraints constraints; | 2025 FakeConstraints constraints; |
| 2007 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | 2026 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2253 } | 2272 } |
| 2254 | 2273 |
| 2255 // This tests that a default MediaStream is not created if a remote session | 2274 // This tests that a default MediaStream is not created if a remote session |
| 2256 // description is updated to not have any MediaStreams. | 2275 // description is updated to not have any MediaStreams. |
| 2257 TEST_F(PeerConnectionInterfaceTest, VerifyDefaultStreamIsNotCreated) { | 2276 TEST_F(PeerConnectionInterfaceTest, VerifyDefaultStreamIsNotCreated) { |
| 2258 FakeConstraints constraints; | 2277 FakeConstraints constraints; |
| 2259 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | 2278 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2260 true); | 2279 true); |
| 2261 CreatePeerConnection(&constraints); | 2280 CreatePeerConnection(&constraints); |
| 2262 CreateAndSetRemoteOffer(kSdpStringWithStream1); | 2281 CreateAndSetRemoteOffer(kSdpStringWithStream1); |
| 2263 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1)); | 2282 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1)); |
| 2264 EXPECT_TRUE( | 2283 EXPECT_TRUE( |
| 2265 CompareStreamCollections(observer_.remote_streams(), reference.get())); | 2284 CompareStreamCollections(observer_.remote_streams(), reference.get())); |
| 2266 | 2285 |
| 2267 CreateAndSetRemoteOffer(kSdpStringWithoutStreams); | 2286 CreateAndSetRemoteOffer(kSdpStringWithoutStreams); |
| 2268 EXPECT_EQ(0u, observer_.remote_streams()->count()); | 2287 EXPECT_EQ(0u, observer_.remote_streams()->count()); |
| 2269 } | 2288 } |
| 2270 | 2289 |
| 2271 // This tests that an RtpSender is created when the local description is set | 2290 // This tests that an RtpSender is created when the local description is set |
| 2272 // after adding a local stream. | 2291 // after adding a local stream. |
| 2273 // TODO(deadbeef): This test and the one below it need to be updated when | 2292 // TODO(deadbeef): This test and the one below it need to be updated when |
| 2274 // an RtpSender's lifetime isn't determined by when a local description is set. | 2293 // an RtpSender's lifetime isn't determined by when a local description is set. |
| 2275 TEST_F(PeerConnectionInterfaceTest, LocalDescriptionChanged) { | 2294 TEST_F(PeerConnectionInterfaceTest, LocalDescriptionChanged) { |
| 2276 FakeConstraints constraints; | 2295 FakeConstraints constraints; |
| 2277 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | 2296 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2278 true); | 2297 true); |
| 2279 CreatePeerConnection(&constraints); | 2298 CreatePeerConnection(&constraints); |
| 2280 // Create an offer just to ensure we have an identity before we manually | |
| 2281 // call SetLocalDescription. | |
| 2282 std::unique_ptr<SessionDescriptionInterface> throwaway; | |
| 2283 ASSERT_TRUE(DoCreateOffer(&throwaway, nullptr)); | |
| 2284 | 2299 |
| 2285 std::unique_ptr<SessionDescriptionInterface> desc_1 = | 2300 // Create an offer with 1 stream with 2 tracks of each type. |
| 2286 CreateSessionDescriptionAndReference(2, 2); | 2301 rtc::scoped_refptr<StreamCollection> stream_collection = |
| 2302 CreateStreamCollection(1, 2); | |
| 2303 pc_->AddStream(stream_collection->at(0)); | |
| 2304 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 2305 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 2306 EXPECT_TRUE(DoSetLocalDescription(offer.release())); | |
| 2287 | 2307 |
| 2288 pc_->AddStream(reference_collection_->at(0)); | |
| 2289 EXPECT_TRUE(DoSetLocalDescription(desc_1.release())); | |
| 2290 auto senders = pc_->GetSenders(); | 2308 auto senders = pc_->GetSenders(); |
| 2291 EXPECT_EQ(4u, senders.size()); | 2309 EXPECT_EQ(4u, senders.size()); |
| 2292 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); | 2310 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 2293 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); | 2311 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 2294 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1])); | 2312 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1])); |
| 2295 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1])); | 2313 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1])); |
| 2296 | 2314 |
| 2297 // Remove an audio and video track. | 2315 // Remove an audio and video track. |
| 2298 pc_->RemoveStream(reference_collection_->at(0)); | 2316 pc_->RemoveStream(stream_collection->at(0)); |
| 2299 std::unique_ptr<SessionDescriptionInterface> desc_2 = | 2317 stream_collection = CreateStreamCollection(1, 1); |
| 2300 CreateSessionDescriptionAndReference(1, 1); | 2318 pc_->AddStream(stream_collection->at(0)); |
| 2301 pc_->AddStream(reference_collection_->at(0)); | 2319 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
| 2302 EXPECT_TRUE(DoSetLocalDescription(desc_2.release())); | 2320 EXPECT_TRUE(DoSetLocalDescription(offer.release())); |
| 2321 | |
| 2303 senders = pc_->GetSenders(); | 2322 senders = pc_->GetSenders(); |
| 2304 EXPECT_EQ(2u, senders.size()); | 2323 EXPECT_EQ(2u, senders.size()); |
| 2305 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); | 2324 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 2306 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); | 2325 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 2307 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1])); | 2326 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1])); |
| 2308 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1])); | 2327 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1])); |
| 2309 } | 2328 } |
| 2310 | 2329 |
| 2311 // This tests that an RtpSender is created when the local description is set | 2330 // This tests that an RtpSender is created when the local description is set |
| 2312 // before adding a local stream. | 2331 // before adding a local stream. |
| 2313 TEST_F(PeerConnectionInterfaceTest, | 2332 TEST_F(PeerConnectionInterfaceTest, |
| 2314 AddLocalStreamAfterLocalDescriptionChanged) { | 2333 AddLocalStreamAfterLocalDescriptionChanged) { |
| 2315 FakeConstraints constraints; | 2334 FakeConstraints constraints; |
| 2316 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | 2335 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2317 true); | 2336 true); |
| 2318 CreatePeerConnection(&constraints); | 2337 CreatePeerConnection(&constraints); |
| 2319 // Create an offer just to ensure we have an identity before we manually | |
| 2320 // call SetLocalDescription. | |
| 2321 std::unique_ptr<SessionDescriptionInterface> throwaway; | |
| 2322 ASSERT_TRUE(DoCreateOffer(&throwaway, nullptr)); | |
| 2323 | 2338 |
| 2324 std::unique_ptr<SessionDescriptionInterface> desc_1 = | 2339 rtc::scoped_refptr<StreamCollection> stream_collection = |
| 2325 CreateSessionDescriptionAndReference(2, 2); | 2340 CreateStreamCollection(1, 2); |
| 2341 // Add a stream to create the offer, but remove it afterwards. | |
| 2342 pc_->AddStream(stream_collection->at(0)); | |
| 2343 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 2344 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 2345 pc_->RemoveStream(stream_collection->at(0)); | |
| 2326 | 2346 |
| 2327 EXPECT_TRUE(DoSetLocalDescription(desc_1.release())); | 2347 EXPECT_TRUE(DoSetLocalDescription(offer.release())); |
| 2328 auto senders = pc_->GetSenders(); | 2348 auto senders = pc_->GetSenders(); |
| 2329 EXPECT_EQ(0u, senders.size()); | 2349 EXPECT_EQ(0u, senders.size()); |
| 2330 | 2350 |
| 2331 pc_->AddStream(reference_collection_->at(0)); | 2351 pc_->AddStream(stream_collection->at(0)); |
| 2332 senders = pc_->GetSenders(); | 2352 senders = pc_->GetSenders(); |
| 2333 EXPECT_EQ(4u, senders.size()); | 2353 EXPECT_EQ(4u, senders.size()); |
| 2334 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); | 2354 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 2335 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); | 2355 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 2336 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1])); | 2356 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1])); |
| 2337 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1])); | 2357 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1])); |
| 2338 } | 2358 } |
| 2339 | 2359 |
| 2340 // This tests that the expected behavior occurs if the SSRC on a local track is | 2360 // This tests that the expected behavior occurs if the SSRC on a local track is |
| 2341 // changed when SetLocalDescription is called. | 2361 // changed when SetLocalDescription is called. |
| 2342 TEST_F(PeerConnectionInterfaceTest, | 2362 TEST_F(PeerConnectionInterfaceTest, |
| 2343 ChangeSsrcOnTrackInLocalSessionDescription) { | 2363 ChangeSsrcOnTrackInLocalSessionDescription) { |
| 2344 FakeConstraints constraints; | 2364 FakeConstraints constraints; |
| 2345 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | 2365 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2346 true); | 2366 true); |
| 2347 CreatePeerConnection(&constraints); | 2367 CreatePeerConnection(&constraints); |
| 2348 // Create an offer just to ensure we have an identity before we manually | |
| 2349 // call SetLocalDescription. | |
| 2350 std::unique_ptr<SessionDescriptionInterface> throwaway; | |
| 2351 ASSERT_TRUE(DoCreateOffer(&throwaway, nullptr)); | |
| 2352 | 2368 |
| 2353 std::unique_ptr<SessionDescriptionInterface> desc = | 2369 rtc::scoped_refptr<StreamCollection> stream_collection = |
| 2354 CreateSessionDescriptionAndReference(1, 1); | 2370 CreateStreamCollection(2, 1); |
| 2355 std::string sdp; | 2371 pc_->AddStream(stream_collection->at(0)); |
| 2356 desc->ToString(&sdp); | 2372 std::unique_ptr<SessionDescriptionInterface> offer; |
| 2373 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 2374 // Grab a copy of the offer before it gets passed into the PC. | |
| 2375 std::unique_ptr<JsepSessionDescription> modified_offer( | |
| 2376 new JsepSessionDescription(JsepSessionDescription::kOffer)); | |
| 2377 modified_offer->Initialize(offer->description()->Copy(), offer->session_id(), | |
| 2378 offer->session_version()); | |
| 2379 EXPECT_TRUE(DoSetLocalDescription(offer.release())); | |
| 2357 | 2380 |
| 2358 pc_->AddStream(reference_collection_->at(0)); | |
| 2359 EXPECT_TRUE(DoSetLocalDescription(desc.release())); | |
| 2360 auto senders = pc_->GetSenders(); | 2381 auto senders = pc_->GetSenders(); |
| 2361 EXPECT_EQ(2u, senders.size()); | 2382 EXPECT_EQ(2u, senders.size()); |
| 2362 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); | 2383 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 2363 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); | 2384 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 2364 | 2385 |
| 2365 // Change the ssrc of the audio and video track. | 2386 // Change the ssrc of the audio and video track. |
| 2366 std::string ssrc_org = "a=ssrc:1"; | 2387 cricket::MediaContentDescription* desc = |
| 2367 std::string ssrc_to = "a=ssrc:97"; | 2388 cricket::GetFirstAudioContentDescription(modified_offer->description()); |
| 2368 rtc::replace_substrs(ssrc_org.c_str(), ssrc_org.length(), ssrc_to.c_str(), | 2389 ASSERT_TRUE(desc != NULL); |
| 2369 ssrc_to.length(), &sdp); | 2390 for (StreamParams& stream : desc->mutable_streams()) { |
| 2370 ssrc_org = "a=ssrc:2"; | 2391 for (unsigned int& ssrc : stream.ssrcs) { |
|
tommi
2016/05/12 11:41:44
nit: since we rarely use unsigned int, and should
| |
| 2371 ssrc_to = "a=ssrc:98"; | 2392 ++ssrc; |
| 2372 rtc::replace_substrs(ssrc_org.c_str(), ssrc_org.length(), ssrc_to.c_str(), | 2393 } |
| 2373 ssrc_to.length(), &sdp); | 2394 } |
| 2374 std::unique_ptr<SessionDescriptionInterface> updated_desc( | |
| 2375 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, sdp, | |
| 2376 nullptr)); | |
| 2377 | 2395 |
| 2378 EXPECT_TRUE(DoSetLocalDescription(updated_desc.release())); | 2396 desc = |
| 2397 cricket::GetFirstVideoContentDescription(modified_offer->description()); | |
| 2398 ASSERT_TRUE(desc != NULL); | |
| 2399 for (StreamParams& stream : desc->mutable_streams()) { | |
| 2400 for (unsigned int& ssrc : stream.ssrcs) { | |
| 2401 ++ssrc; | |
| 2402 } | |
| 2403 } | |
| 2404 | |
| 2405 EXPECT_TRUE(DoSetLocalDescription(modified_offer.release())); | |
| 2379 senders = pc_->GetSenders(); | 2406 senders = pc_->GetSenders(); |
| 2380 EXPECT_EQ(2u, senders.size()); | 2407 EXPECT_EQ(2u, senders.size()); |
| 2381 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); | 2408 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 2382 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); | 2409 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 2383 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC | 2410 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC |
| 2384 // changed. | 2411 // changed. |
| 2385 } | 2412 } |
| 2386 | 2413 |
| 2387 // This tests that the expected behavior occurs if a new session description is | 2414 // This tests that the expected behavior occurs if a new session description is |
| 2388 // set with the same tracks, but on a different MediaStream. | 2415 // set with the same tracks, but on a different MediaStream. |
| 2389 TEST_F(PeerConnectionInterfaceTest, | 2416 TEST_F(PeerConnectionInterfaceTest, |
| 2390 SignalSameTracksInSeparateMediaStream) { | 2417 SignalSameTracksInSeparateMediaStream) { |
| 2391 FakeConstraints constraints; | 2418 FakeConstraints constraints; |
| 2392 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | 2419 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2393 true); | 2420 true); |
| 2394 CreatePeerConnection(&constraints); | 2421 CreatePeerConnection(&constraints); |
| 2395 // Create an offer just to ensure we have an identity before we manually | |
| 2396 // call SetLocalDescription. | |
| 2397 std::unique_ptr<SessionDescriptionInterface> throwaway; | |
| 2398 ASSERT_TRUE(DoCreateOffer(&throwaway, nullptr)); | |
| 2399 | 2422 |
| 2400 std::unique_ptr<SessionDescriptionInterface> desc = | 2423 rtc::scoped_refptr<StreamCollection> stream_collection = |
| 2401 CreateSessionDescriptionAndReference(1, 1); | 2424 CreateStreamCollection(2, 1); |
| 2402 std::string sdp; | 2425 pc_->AddStream(stream_collection->at(0)); |
| 2403 desc->ToString(&sdp); | 2426 std::unique_ptr<SessionDescriptionInterface> offer; |
| 2427 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 2428 EXPECT_TRUE(DoSetLocalDescription(offer.release())); | |
| 2404 | 2429 |
| 2405 pc_->AddStream(reference_collection_->at(0)); | |
| 2406 EXPECT_TRUE(DoSetLocalDescription(desc.release())); | |
| 2407 auto senders = pc_->GetSenders(); | 2430 auto senders = pc_->GetSenders(); |
| 2408 EXPECT_EQ(2u, senders.size()); | 2431 EXPECT_EQ(2u, senders.size()); |
| 2409 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); | 2432 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0])); |
| 2410 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); | 2433 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0])); |
| 2411 | 2434 |
| 2412 // Add a new MediaStream but with the same tracks as in the first stream. | 2435 // Add a new MediaStream but with the same tracks as in the first stream. |
| 2413 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1( | 2436 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1( |
| 2414 webrtc::MediaStream::Create(kStreams[1])); | 2437 webrtc::MediaStream::Create(kStreams[1])); |
| 2415 stream_1->AddTrack(reference_collection_->at(0)->GetVideoTracks()[0]); | 2438 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]); |
| 2416 stream_1->AddTrack(reference_collection_->at(0)->GetAudioTracks()[0]); | 2439 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]); |
| 2417 pc_->AddStream(stream_1); | 2440 pc_->AddStream(stream_1); |
| 2418 | 2441 |
| 2419 // Replace msid in the original SDP. | 2442 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
| 2420 rtc::replace_substrs(kStreams[0], strlen(kStreams[0]), kStreams[1], | 2443 EXPECT_TRUE(DoSetLocalDescription(offer.release())); |
| 2421 strlen(kStreams[1]), &sdp); | |
| 2422 | 2444 |
| 2423 std::unique_ptr<SessionDescriptionInterface> updated_desc( | 2445 auto new_senders = pc_->GetSenders(); |
| 2424 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, sdp, | 2446 // Should be the same senders as before, but with updated stream id. |
| 2425 nullptr)); | 2447 // Note that this behavior is subject to change in the future. |
| 2426 | 2448 // We may decide the PC should ignore existing tracks in AddStream. |
| 2427 EXPECT_TRUE(DoSetLocalDescription(updated_desc.release())); | 2449 EXPECT_EQ(senders, new_senders); |
| 2428 senders = pc_->GetSenders(); | 2450 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1])); |
| 2429 EXPECT_EQ(2u, senders.size()); | 2451 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1])); |
| 2430 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); | |
| 2431 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); | |
| 2432 } | 2452 } |
| 2433 | 2453 |
| 2434 // The PeerConnectionMediaConfig tests below verify that configuration | 2454 // The PeerConnectionMediaConfig tests below verify that configuration |
| 2435 // and constraints are propagated into the MediaConfig passed to | 2455 // and constraints are propagated into the MediaConfig passed to |
| 2436 // CreateMediaController. These settings are intended for MediaChannel | 2456 // CreateMediaController. These settings are intended for MediaChannel |
| 2437 // constructors, but that is not exercised by these unittest. | 2457 // constructors, but that is not exercised by these unittest. |
| 2438 class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory { | 2458 class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory { |
| 2439 public: | 2459 public: |
| 2440 webrtc::MediaControllerInterface* CreateMediaController( | 2460 webrtc::MediaControllerInterface* CreateMediaController( |
| 2441 const cricket::MediaConfig& config) const override { | 2461 const cricket::MediaConfig& config) const override { |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2710 FakeConstraints updated_answer_c; | 2730 FakeConstraints updated_answer_c; |
| 2711 answer_c.SetMandatoryReceiveAudio(false); | 2731 answer_c.SetMandatoryReceiveAudio(false); |
| 2712 answer_c.SetMandatoryReceiveVideo(false); | 2732 answer_c.SetMandatoryReceiveVideo(false); |
| 2713 | 2733 |
| 2714 cricket::MediaSessionOptions updated_answer_options; | 2734 cricket::MediaSessionOptions updated_answer_options; |
| 2715 EXPECT_TRUE( | 2735 EXPECT_TRUE( |
| 2716 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); | 2736 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); |
| 2717 EXPECT_TRUE(updated_answer_options.has_audio()); | 2737 EXPECT_TRUE(updated_answer_options.has_audio()); |
| 2718 EXPECT_TRUE(updated_answer_options.has_video()); | 2738 EXPECT_TRUE(updated_answer_options.has_video()); |
| 2719 } | 2739 } |
| OLD | NEW |