Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(956)

Side by Side Diff: webrtc/api/peerconnectioninterface_unittest.cc

Issue 1818963002: Use a FakeVideoTrackSource instead of nullptr in all VideoTrack tests. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/api/mediastream_unittest.cc ('k') | webrtc/api/rtpsenderreceiver_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #include <string> 11 #include <string>
12 #include <utility> 12 #include <utility>
13 13
14 #include "webrtc/api/audiotrack.h" 14 #include "webrtc/api/audiotrack.h"
15 #include "webrtc/api/jsepsessiondescription.h" 15 #include "webrtc/api/jsepsessiondescription.h"
16 #include "webrtc/api/mediastream.h" 16 #include "webrtc/api/mediastream.h"
17 #include "webrtc/api/mediastreaminterface.h" 17 #include "webrtc/api/mediastreaminterface.h"
18 #include "webrtc/api/peerconnection.h" 18 #include "webrtc/api/peerconnection.h"
19 #include "webrtc/api/peerconnectioninterface.h" 19 #include "webrtc/api/peerconnectioninterface.h"
20 #include "webrtc/api/rtpreceiverinterface.h" 20 #include "webrtc/api/rtpreceiverinterface.h"
21 #include "webrtc/api/rtpsenderinterface.h" 21 #include "webrtc/api/rtpsenderinterface.h"
22 #include "webrtc/api/streamcollection.h" 22 #include "webrtc/api/streamcollection.h"
23 #ifdef WEBRTC_ANDROID 23 #ifdef WEBRTC_ANDROID
24 #include "webrtc/api/test/androidtestinitializer.h" 24 #include "webrtc/api/test/androidtestinitializer.h"
25 #endif 25 #endif
26 #include "webrtc/api/test/fakeconstraints.h" 26 #include "webrtc/api/test/fakeconstraints.h"
27 #include "webrtc/api/test/fakedtlsidentitystore.h" 27 #include "webrtc/api/test/fakedtlsidentitystore.h"
28 #include "webrtc/api/test/fakevideotracksource.h"
28 #include "webrtc/api/test/mockpeerconnectionobservers.h" 29 #include "webrtc/api/test/mockpeerconnectionobservers.h"
29 #include "webrtc/api/test/testsdpstrings.h" 30 #include "webrtc/api/test/testsdpstrings.h"
30 #include "webrtc/api/videocapturertracksource.h" 31 #include "webrtc/api/videocapturertracksource.h"
31 #include "webrtc/api/videotrack.h" 32 #include "webrtc/api/videotrack.h"
32 #include "webrtc/base/gunit.h" 33 #include "webrtc/base/gunit.h"
33 #include "webrtc/base/scoped_ptr.h" 34 #include "webrtc/base/scoped_ptr.h"
34 #include "webrtc/base/ssladapter.h" 35 #include "webrtc/base/ssladapter.h"
35 #include "webrtc/base/sslstreamadapter.h" 36 #include "webrtc/base/sslstreamadapter.h"
36 #include "webrtc/base/stringutils.h" 37 #include "webrtc/base/stringutils.h"
37 #include "webrtc/base/thread.h" 38 #include "webrtc/base/thread.h"
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream( 335 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
335 webrtc::MediaStream::Create(kStreams[i])); 336 webrtc::MediaStream::Create(kStreams[i]));
336 337
337 // Add a local audio track. 338 // Add a local audio track.
338 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( 339 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
339 webrtc::AudioTrack::Create(kAudioTracks[i], nullptr)); 340 webrtc::AudioTrack::Create(kAudioTracks[i], nullptr));
340 stream->AddTrack(audio_track); 341 stream->AddTrack(audio_track);
341 342
342 // Add a local video track. 343 // Add a local video track.
343 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( 344 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
344 webrtc::VideoTrack::Create(kVideoTracks[i], nullptr)); 345 webrtc::VideoTrack::Create(kVideoTracks[i],
346 webrtc::FakeVideoTrackSource::Create()));
345 stream->AddTrack(video_track); 347 stream->AddTrack(video_track);
346 348
347 local_collection->AddStream(stream); 349 local_collection->AddStream(stream);
348 } 350 }
349 return local_collection; 351 return local_collection;
350 } 352 }
351 353
352 // Check equality of StreamCollections. 354 // Check equality of StreamCollections.
353 bool CompareStreamCollections(StreamCollectionInterface* s1, 355 bool CompareStreamCollections(StreamCollectionInterface* s1,
354 StreamCollectionInterface* s2) { 356 StreamCollectionInterface* s2) {
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 const std::string& audio_track_label, 625 const std::string& audio_track_label,
624 const std::string& video_track_label) { 626 const std::string& video_track_label) {
625 // Create a local stream. 627 // Create a local stream.
626 scoped_refptr<MediaStreamInterface> stream( 628 scoped_refptr<MediaStreamInterface> stream(
627 pc_factory_->CreateLocalMediaStream(stream_label)); 629 pc_factory_->CreateLocalMediaStream(stream_label));
628 scoped_refptr<AudioTrackInterface> audio_track( 630 scoped_refptr<AudioTrackInterface> audio_track(
629 pc_factory_->CreateAudioTrack( 631 pc_factory_->CreateAudioTrack(
630 audio_track_label, static_cast<AudioSourceInterface*>(NULL))); 632 audio_track_label, static_cast<AudioSourceInterface*>(NULL)));
631 stream->AddTrack(audio_track.get()); 633 stream->AddTrack(audio_track.get());
632 scoped_refptr<VideoTrackInterface> video_track( 634 scoped_refptr<VideoTrackInterface> video_track(
633 pc_factory_->CreateVideoTrack(video_track_label, NULL)); 635 pc_factory_->CreateVideoTrack(
636 video_track_label,
637 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer())));
634 stream->AddTrack(video_track.get()); 638 stream->AddTrack(video_track.get());
635 EXPECT_TRUE(pc_->AddStream(stream)); 639 EXPECT_TRUE(pc_->AddStream(stream));
636 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); 640 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
637 observer_.renegotiation_needed_ = false; 641 observer_.renegotiation_needed_ = false;
638 } 642 }
639 643
640 bool DoCreateOfferAnswer(rtc::scoped_ptr<SessionDescriptionInterface>* desc, 644 bool DoCreateOfferAnswer(rtc::scoped_ptr<SessionDescriptionInterface>* desc,
641 bool offer, 645 bool offer,
642 MediaConstraintsInterface* constraints) { 646 MediaConstraintsInterface* constraints) {
643 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> 647 rtc::scoped_refptr<MockCreateSessionDescriptionObserver>
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 void AddAudioTrack(const std::string& track_id, 896 void AddAudioTrack(const std::string& track_id,
893 MediaStreamInterface* stream) { 897 MediaStreamInterface* stream) {
894 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( 898 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
895 webrtc::AudioTrack::Create(track_id, nullptr)); 899 webrtc::AudioTrack::Create(track_id, nullptr));
896 ASSERT_TRUE(stream->AddTrack(audio_track)); 900 ASSERT_TRUE(stream->AddTrack(audio_track));
897 } 901 }
898 902
899 void AddVideoTrack(const std::string& track_id, 903 void AddVideoTrack(const std::string& track_id,
900 MediaStreamInterface* stream) { 904 MediaStreamInterface* stream) {
901 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( 905 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
902 webrtc::VideoTrack::Create(track_id, nullptr)); 906 webrtc::VideoTrack::Create(track_id,
907 webrtc::FakeVideoTrackSource::Create()));
903 ASSERT_TRUE(stream->AddTrack(video_track)); 908 ASSERT_TRUE(stream->AddTrack(video_track));
904 } 909 }
905 910
906 cricket::FakePortAllocator* port_allocator_ = nullptr; 911 cricket::FakePortAllocator* port_allocator_ = nullptr;
907 scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_; 912 scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
908 scoped_refptr<PeerConnectionInterface> pc_; 913 scoped_refptr<PeerConnectionInterface> pc_;
909 MockPeerConnectionObserver observer_; 914 MockPeerConnectionObserver observer_;
910 rtc::scoped_refptr<StreamCollection> reference_collection_; 915 rtc::scoped_refptr<StreamCollection> reference_collection_;
911 }; 916 };
912 917
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 // Also tests that RemoveTrack removes the tracks from subsequent offers. 1008 // Also tests that RemoveTrack removes the tracks from subsequent offers.
1004 TEST_F(PeerConnectionInterfaceTest, AddTrackRemoveTrack) { 1009 TEST_F(PeerConnectionInterfaceTest, AddTrackRemoveTrack) {
1005 CreatePeerConnection(); 1010 CreatePeerConnection();
1006 // Create a dummy stream, so tracks share a stream label. 1011 // Create a dummy stream, so tracks share a stream label.
1007 scoped_refptr<MediaStreamInterface> stream( 1012 scoped_refptr<MediaStreamInterface> stream(
1008 pc_factory_->CreateLocalMediaStream(kStreamLabel1)); 1013 pc_factory_->CreateLocalMediaStream(kStreamLabel1));
1009 std::vector<MediaStreamInterface*> stream_list; 1014 std::vector<MediaStreamInterface*> stream_list;
1010 stream_list.push_back(stream.get()); 1015 stream_list.push_back(stream.get());
1011 scoped_refptr<AudioTrackInterface> audio_track( 1016 scoped_refptr<AudioTrackInterface> audio_track(
1012 pc_factory_->CreateAudioTrack("audio_track", nullptr)); 1017 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1013 scoped_refptr<VideoTrackInterface> video_track( 1018 scoped_refptr<VideoTrackInterface> video_track(pc_factory_->CreateVideoTrack(
1014 pc_factory_->CreateVideoTrack("video_track", nullptr)); 1019 "video_track",
1020 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer())));
1015 auto audio_sender = pc_->AddTrack(audio_track, stream_list); 1021 auto audio_sender = pc_->AddTrack(audio_track, stream_list);
1016 auto video_sender = pc_->AddTrack(video_track, stream_list); 1022 auto video_sender = pc_->AddTrack(video_track, stream_list);
1017 EXPECT_EQ(kStreamLabel1, audio_sender->stream_id()); 1023 EXPECT_EQ(kStreamLabel1, audio_sender->stream_id());
1018 EXPECT_EQ("audio_track", audio_sender->id()); 1024 EXPECT_EQ("audio_track", audio_sender->id());
1019 EXPECT_EQ(audio_track, audio_sender->track()); 1025 EXPECT_EQ(audio_track, audio_sender->track());
1020 EXPECT_EQ(kStreamLabel1, video_sender->stream_id()); 1026 EXPECT_EQ(kStreamLabel1, video_sender->stream_id());
1021 EXPECT_EQ("video_track", video_sender->id()); 1027 EXPECT_EQ("video_track", video_sender->id());
1022 EXPECT_EQ(video_track, video_sender->track()); 1028 EXPECT_EQ(video_track, video_sender->track());
1023 1029
1024 // Now create an offer and check for the senders. 1030 // Now create an offer and check for the senders.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 EXPECT_FALSE(pc_->RemoveTrack(video_sender)); 1076 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1071 } 1077 }
1072 1078
1073 // Test creating senders without a stream specified, 1079 // Test creating senders without a stream specified,
1074 // expecting a random stream ID to be generated. 1080 // expecting a random stream ID to be generated.
1075 TEST_F(PeerConnectionInterfaceTest, AddTrackWithoutStream) { 1081 TEST_F(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
1076 CreatePeerConnection(); 1082 CreatePeerConnection();
1077 // Create a dummy stream, so tracks share a stream label. 1083 // Create a dummy stream, so tracks share a stream label.
1078 scoped_refptr<AudioTrackInterface> audio_track( 1084 scoped_refptr<AudioTrackInterface> audio_track(
1079 pc_factory_->CreateAudioTrack("audio_track", nullptr)); 1085 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1080 scoped_refptr<VideoTrackInterface> video_track( 1086 scoped_refptr<VideoTrackInterface> video_track(pc_factory_->CreateVideoTrack(
1081 pc_factory_->CreateVideoTrack("video_track", nullptr)); 1087 "video_track",
1088 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer())));
1082 auto audio_sender = 1089 auto audio_sender =
1083 pc_->AddTrack(audio_track, std::vector<MediaStreamInterface*>()); 1090 pc_->AddTrack(audio_track, std::vector<MediaStreamInterface*>());
1084 auto video_sender = 1091 auto video_sender =
1085 pc_->AddTrack(video_track, std::vector<MediaStreamInterface*>()); 1092 pc_->AddTrack(video_track, std::vector<MediaStreamInterface*>());
1086 EXPECT_EQ("audio_track", audio_sender->id()); 1093 EXPECT_EQ("audio_track", audio_sender->id());
1087 EXPECT_EQ(audio_track, audio_sender->track()); 1094 EXPECT_EQ(audio_track, audio_sender->track());
1088 EXPECT_EQ("video_track", video_sender->id()); 1095 EXPECT_EQ("video_track", video_sender->id());
1089 EXPECT_EQ(video_track, video_sender->track()); 1096 EXPECT_EQ(video_track, video_sender->track());
1090 // If the ID is truly a random GUID, it should be infinitely unlikely they 1097 // If the ID is truly a random GUID, it should be infinitely unlikely they
1091 // will be the same. 1098 // will be the same.
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 // Test that it's possible to call AddTrack on a MediaStream after adding 1237 // Test that it's possible to call AddTrack on a MediaStream after adding
1231 // the stream to a PeerConnection. 1238 // the stream to a PeerConnection.
1232 // TODO(deadbeef): Remove this test once this behavior is no longer supported. 1239 // TODO(deadbeef): Remove this test once this behavior is no longer supported.
1233 TEST_F(PeerConnectionInterfaceTest, AddTrackAfterAddStream) { 1240 TEST_F(PeerConnectionInterfaceTest, AddTrackAfterAddStream) {
1234 CreatePeerConnection(); 1241 CreatePeerConnection();
1235 // Create audio stream and add to PeerConnection. 1242 // Create audio stream and add to PeerConnection.
1236 AddVoiceStream(kStreamLabel1); 1243 AddVoiceStream(kStreamLabel1);
1237 MediaStreamInterface* stream = pc_->local_streams()->at(0); 1244 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1238 1245
1239 // Add video track to the audio-only stream. 1246 // Add video track to the audio-only stream.
1240 scoped_refptr<VideoTrackInterface> video_track( 1247 scoped_refptr<VideoTrackInterface> video_track(pc_factory_->CreateVideoTrack(
1241 pc_factory_->CreateVideoTrack("video_label", nullptr)); 1248 "video_label",
1249 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer())));
1242 stream->AddTrack(video_track.get()); 1250 stream->AddTrack(video_track.get());
1243 1251
1244 scoped_ptr<SessionDescriptionInterface> offer; 1252 scoped_ptr<SessionDescriptionInterface> offer;
1245 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); 1253 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
1246 1254
1247 const cricket::MediaContentDescription* video_desc = 1255 const cricket::MediaContentDescription* video_desc =
1248 cricket::GetFirstVideoContentDescription(offer->description()); 1256 cricket::GetFirstVideoContentDescription(offer->description());
1249 EXPECT_TRUE(video_desc != nullptr); 1257 EXPECT_TRUE(video_desc != nullptr);
1250 } 1258 }
1251 1259
(...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after
2422 } 2430 }
2423 2431
2424 // Mutable, so they can be modified in the above const-declared method. 2432 // Mutable, so they can be modified in the above const-declared method.
2425 mutable bool create_media_controller_called_ = false; 2433 mutable bool create_media_controller_called_ = false;
2426 mutable cricket::MediaConfig create_media_controller_config_; 2434 mutable cricket::MediaConfig create_media_controller_config_;
2427 }; 2435 };
2428 2436
2429 class PeerConnectionMediaConfigTest : public testing::Test { 2437 class PeerConnectionMediaConfigTest : public testing::Test {
2430 protected: 2438 protected:
2431 void SetUp() override { 2439 void SetUp() override {
2432 pcf_= new rtc::RefCountedObject<PeerConnectionFactoryForTest>(); 2440 pcf_ = new rtc::RefCountedObject<PeerConnectionFactoryForTest>();
2433 pcf_->Initialize(); 2441 pcf_->Initialize();
2434 } 2442 }
2435 const cricket::MediaConfig& TestCreatePeerConnection( 2443 const cricket::MediaConfig& TestCreatePeerConnection(
2436 const PeerConnectionInterface::RTCConfiguration& config, 2444 const PeerConnectionInterface::RTCConfiguration& config,
2437 const MediaConstraintsInterface *constraints) { 2445 const MediaConstraintsInterface *constraints) {
2438 pcf_->create_media_controller_called_ = false; 2446 pcf_->create_media_controller_called_ = false;
2439 2447
2440 scoped_refptr<PeerConnectionInterface> pc( 2448 scoped_refptr<PeerConnectionInterface> pc(
2441 pcf_->CreatePeerConnection(config, constraints, nullptr, nullptr, 2449 pcf_->CreatePeerConnection(config, constraints, nullptr, nullptr,
2442 &observer_)); 2450 &observer_));
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
2683 FakeConstraints updated_answer_c; 2691 FakeConstraints updated_answer_c;
2684 answer_c.SetMandatoryReceiveAudio(false); 2692 answer_c.SetMandatoryReceiveAudio(false);
2685 answer_c.SetMandatoryReceiveVideo(false); 2693 answer_c.SetMandatoryReceiveVideo(false);
2686 2694
2687 cricket::MediaSessionOptions updated_answer_options; 2695 cricket::MediaSessionOptions updated_answer_options;
2688 EXPECT_TRUE( 2696 EXPECT_TRUE(
2689 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); 2697 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options));
2690 EXPECT_TRUE(updated_answer_options.has_audio()); 2698 EXPECT_TRUE(updated_answer_options.has_audio());
2691 EXPECT_TRUE(updated_answer_options.has_video()); 2699 EXPECT_TRUE(updated_answer_options.has_video());
2692 } 2700 }
OLDNEW
« no previous file with comments | « webrtc/api/mediastream_unittest.cc ('k') | webrtc/api/rtpsenderreceiver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698