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

Side by Side Diff: talk/app/webrtc/peerconnectioninterface_unittest.cc

Issue 1563403002: Adding AddTrack/RemoveTrack to native PeerConnection API. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Adding default implementation for new methods. Created 4 years, 11 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 | « talk/app/webrtc/peerconnectioninterface.h ('k') | talk/app/webrtc/peerconnectionproxy.h » ('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 * libjingle 2 * libjingle
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 } 1013 }
1014 1014
1015 TEST_F(PeerConnectionInterfaceTest, RemoveStream) { 1015 TEST_F(PeerConnectionInterfaceTest, RemoveStream) {
1016 CreatePeerConnection(); 1016 CreatePeerConnection();
1017 AddVideoStream(kStreamLabel1); 1017 AddVideoStream(kStreamLabel1);
1018 ASSERT_EQ(1u, pc_->local_streams()->count()); 1018 ASSERT_EQ(1u, pc_->local_streams()->count());
1019 pc_->RemoveStream(pc_->local_streams()->at(0)); 1019 pc_->RemoveStream(pc_->local_streams()->at(0));
1020 EXPECT_EQ(0u, pc_->local_streams()->count()); 1020 EXPECT_EQ(0u, pc_->local_streams()->count());
1021 } 1021 }
1022 1022
1023 // Test for AddTrack and RemoveTrack methods.
1024 // Tests that the created offer includes tracks we added,
1025 // and that the RtpSenders are created correctly.
1026 // Also tests that RemoveTrack removes the tracks from subsequent offers.
1027 TEST_F(PeerConnectionInterfaceTest, AddTrackRemoveTrack) {
1028 CreatePeerConnection();
1029 // Create a dummy stream, so tracks share a stream label.
1030 scoped_refptr<MediaStreamInterface> stream(
1031 pc_factory_->CreateLocalMediaStream(kStreamLabel1));
1032 std::vector<MediaStreamInterface*> stream_list;
1033 stream_list.push_back(stream.get());
1034 scoped_refptr<AudioTrackInterface> audio_track(
1035 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1036 scoped_refptr<VideoTrackInterface> video_track(
1037 pc_factory_->CreateVideoTrack("video_track", nullptr));
1038 auto audio_sender = pc_->AddTrack(audio_track, stream_list);
1039 auto video_sender = pc_->AddTrack(video_track, stream_list);
1040 EXPECT_EQ(kStreamLabel1, audio_sender->stream_id());
1041 EXPECT_EQ("audio_track", audio_sender->id());
1042 EXPECT_EQ(audio_track, audio_sender->track());
1043 EXPECT_EQ(kStreamLabel1, video_sender->stream_id());
1044 EXPECT_EQ("video_track", video_sender->id());
1045 EXPECT_EQ(video_track, video_sender->track());
1046
1047 // Now create an offer and check for the senders.
1048 scoped_ptr<SessionDescriptionInterface> offer;
1049 ASSERT_TRUE(DoCreateOffer(offer.accept(), nullptr));
1050
1051 const cricket::ContentInfo* audio_content =
1052 cricket::GetFirstAudioContent(offer->description());
1053 const cricket::AudioContentDescription* audio_desc =
1054 static_cast<const cricket::AudioContentDescription*>(
1055 audio_content->description);
1056 EXPECT_TRUE(
1057 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1058
1059 const cricket::ContentInfo* video_content =
1060 cricket::GetFirstVideoContent(offer->description());
1061 const cricket::VideoContentDescription* video_desc =
1062 static_cast<const cricket::VideoContentDescription*>(
1063 video_content->description);
1064 EXPECT_TRUE(
1065 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1066
1067 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
1068
1069 // Now try removing the tracks.
1070 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1071 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1072
1073 // Create a new offer and ensure it doesn't contain the removed senders.
1074 ASSERT_TRUE(DoCreateOffer(offer.accept(), nullptr));
1075
1076 audio_content = cricket::GetFirstAudioContent(offer->description());
1077 audio_desc = static_cast<const cricket::AudioContentDescription*>(
1078 audio_content->description);
1079 EXPECT_FALSE(
1080 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track"));
1081
1082 video_content = cricket::GetFirstVideoContent(offer->description());
1083 video_desc = static_cast<const cricket::VideoContentDescription*>(
1084 video_content->description);
1085 EXPECT_FALSE(
1086 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track"));
1087
1088 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
1089
1090 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1091 // should return false.
1092 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1093 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1094 }
1095
1096 // Test creating senders without a stream specified,
1097 // expecting a random stream ID to be generated.
1098 TEST_F(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
1099 CreatePeerConnection();
1100 // Create a dummy stream, so tracks share a stream label.
1101 scoped_refptr<AudioTrackInterface> audio_track(
1102 pc_factory_->CreateAudioTrack("audio_track", nullptr));
1103 scoped_refptr<VideoTrackInterface> video_track(
1104 pc_factory_->CreateVideoTrack("video_track", nullptr));
1105 auto audio_sender =
1106 pc_->AddTrack(audio_track, std::vector<MediaStreamInterface*>());
1107 auto video_sender =
1108 pc_->AddTrack(video_track, std::vector<MediaStreamInterface*>());
1109 EXPECT_EQ("audio_track", audio_sender->id());
1110 EXPECT_EQ(audio_track, audio_sender->track());
1111 EXPECT_EQ("video_track", video_sender->id());
1112 EXPECT_EQ(video_track, video_sender->track());
1113 // If the ID is truly a random GUID, it should be infinitely unlikely they
1114 // will be the same.
1115 EXPECT_NE(video_sender->stream_id(), audio_sender->stream_id());
1116 }
1117
1023 TEST_F(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) { 1118 TEST_F(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
1024 InitiateCall(); 1119 InitiateCall();
1025 WaitAndVerifyOnAddStream(kStreamLabel1); 1120 WaitAndVerifyOnAddStream(kStreamLabel1);
1026 VerifyRemoteRtpHeaderExtensions(); 1121 VerifyRemoteRtpHeaderExtensions();
1027 } 1122 }
1028 1123
1029 TEST_F(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) { 1124 TEST_F(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
1030 CreatePeerConnection(); 1125 CreatePeerConnection();
1031 AddVideoStream(kStreamLabel1); 1126 AddVideoStream(kStreamLabel1);
1032 CreateOfferAsLocalDescription(); 1127 CreateOfferAsLocalDescription();
(...skipping 1374 matching lines...) Expand 10 before | Expand all | Expand 10 after
2407 FakeConstraints updated_answer_c; 2502 FakeConstraints updated_answer_c;
2408 answer_c.SetMandatoryReceiveAudio(false); 2503 answer_c.SetMandatoryReceiveAudio(false);
2409 answer_c.SetMandatoryReceiveVideo(false); 2504 answer_c.SetMandatoryReceiveVideo(false);
2410 2505
2411 cricket::MediaSessionOptions updated_answer_options; 2506 cricket::MediaSessionOptions updated_answer_options;
2412 EXPECT_TRUE( 2507 EXPECT_TRUE(
2413 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); 2508 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options));
2414 EXPECT_TRUE(updated_answer_options.has_audio()); 2509 EXPECT_TRUE(updated_answer_options.has_audio());
2415 EXPECT_TRUE(updated_answer_options.has_video()); 2510 EXPECT_TRUE(updated_answer_options.has_video());
2416 } 2511 }
OLDNEW
« no previous file with comments | « talk/app/webrtc/peerconnectioninterface.h ('k') | talk/app/webrtc/peerconnectionproxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698