henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 11 | #include "api/peer_connection_interface.h" |
| 12 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 13 | #include <limits.h> |
| 14 | #include <stdint.h> |
| 15 | #include <string.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 16 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 17 | #include <memory> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 18 | #include <string> |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 19 | #include <utility> |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 20 | #include <vector> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 21 | |
Steve Anton | 1c9c9fc | 2019-02-14 15:13:09 -0800 | [diff] [blame] | 22 | #include "absl/strings/str_replace.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 23 | #include "absl/types/optional.h" |
| 24 | #include "api/audio/audio_mixer.h" |
| 25 | #include "api/audio_codecs/audio_decoder_factory.h" |
| 26 | #include "api/audio_codecs/audio_encoder_factory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 27 | #include "api/audio_codecs/builtin_audio_decoder_factory.h" |
| 28 | #include "api/audio_codecs/builtin_audio_encoder_factory.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 29 | #include "api/call/call_factory_interface.h" |
Mirko Bonadei | 2ff3f49 | 2018-11-22 09:00:13 +0100 | [diff] [blame] | 30 | #include "api/create_peerconnection_factory.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 31 | #include "api/data_channel_interface.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 32 | #include "api/jsep.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 33 | #include "api/jsep_session_description.h" |
| 34 | #include "api/media_stream_interface.h" |
| 35 | #include "api/media_types.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 36 | #include "api/rtc_error.h" |
Danil Chapovalov | 9da25bd | 2019-06-20 10:19:42 +0200 | [diff] [blame] | 37 | #include "api/rtc_event_log/rtc_event_log.h" |
| 38 | #include "api/rtc_event_log/rtc_event_log_factory.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 39 | #include "api/rtc_event_log_output.h" |
Niels Möller | d8b9ed7 | 2019-05-08 13:53:51 +0200 | [diff] [blame] | 40 | #include "api/rtc_event_log_output_file.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 41 | #include "api/rtp_receiver_interface.h" |
| 42 | #include "api/rtp_sender_interface.h" |
| 43 | #include "api/rtp_transceiver_interface.h" |
Mirko Bonadei | d970807 | 2019-01-25 20:26:48 +0100 | [diff] [blame] | 44 | #include "api/scoped_refptr.h" |
Danil Chapovalov | 9da25bd | 2019-06-20 10:19:42 +0200 | [diff] [blame] | 45 | #include "api/task_queue/default_task_queue_factory.h" |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 46 | #include "api/video_codecs/builtin_video_decoder_factory.h" |
| 47 | #include "api/video_codecs/builtin_video_encoder_factory.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 48 | #include "api/video_codecs/video_decoder_factory.h" |
| 49 | #include "api/video_codecs/video_encoder_factory.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 50 | #include "media/base/codec.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 51 | #include "media/base/media_config.h" |
| 52 | #include "media/base/media_engine.h" |
| 53 | #include "media/base/stream_params.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 54 | #include "media/engine/webrtc_media_engine.h" |
Danil Chapovalov | 9da25bd | 2019-06-20 10:19:42 +0200 | [diff] [blame] | 55 | #include "media/engine/webrtc_media_engine_defaults.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 56 | #include "media/sctp/sctp_transport_internal.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 57 | #include "modules/audio_device/include/audio_device.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 58 | #include "modules/audio_processing/include/audio_processing.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 59 | #include "p2p/base/fake_port_allocator.h" |
| 60 | #include "p2p/base/p2p_constants.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 61 | #include "p2p/base/port.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 62 | #include "p2p/base/port_allocator.h" |
| 63 | #include "p2p/base/transport_description.h" |
| 64 | #include "p2p/base/transport_info.h" |
| 65 | #include "pc/audio_track.h" |
| 66 | #include "pc/media_session.h" |
| 67 | #include "pc/media_stream.h" |
| 68 | #include "pc/peer_connection.h" |
| 69 | #include "pc/peer_connection_factory.h" |
| 70 | #include "pc/rtc_stats_collector.h" |
| 71 | #include "pc/rtp_sender.h" |
| 72 | #include "pc/session_description.h" |
| 73 | #include "pc/stream_collection.h" |
| 74 | #include "pc/test/fake_audio_capture_module.h" |
| 75 | #include "pc/test/fake_rtc_certificate_generator.h" |
| 76 | #include "pc/test/fake_video_track_source.h" |
| 77 | #include "pc/test/mock_peer_connection_observers.h" |
| 78 | #include "pc/test/test_sdp_strings.h" |
| 79 | #include "pc/video_track.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 80 | #include "rtc_base/checks.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 81 | #include "rtc_base/copy_on_write_buffer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 82 | #include "rtc_base/gunit.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 83 | #include "rtc_base/ref_counted_object.h" |
| 84 | #include "rtc_base/rtc_certificate_generator.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 85 | #include "rtc_base/socket_address.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 86 | #include "rtc_base/thread.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 87 | #include "rtc_base/time_utils.h" |
| 88 | #include "rtc_base/virtual_socket_server.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 89 | #include "test/gmock.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 90 | #include "test/gtest.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 91 | #include "test/testsupport/file_utils.h" |
kwiberg | ac9f876 | 2016-09-30 22:29:43 -0700 | [diff] [blame] | 92 | |
| 93 | #ifdef WEBRTC_ANDROID |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 94 | #include "pc/test/android_test_initializer.h" |
kwiberg | ac9f876 | 2016-09-30 22:29:43 -0700 | [diff] [blame] | 95 | #endif |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 96 | |
Mirko Bonadei | ab64e8a | 2018-12-12 12:10:18 +0100 | [diff] [blame] | 97 | namespace webrtc { |
| 98 | namespace { |
| 99 | |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 100 | static const char kStreamId1[] = "local_stream_1"; |
| 101 | static const char kStreamId2[] = "local_stream_2"; |
| 102 | static const char kStreamId3[] = "local_stream_3"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 103 | static const int kDefaultStunPort = 3478; |
| 104 | static const char kStunAddressOnly[] = "stun:address"; |
| 105 | static const char kStunInvalidPort[] = "stun:address:-1"; |
| 106 | static const char kStunAddressPortAndMore1[] = "stun:address:port:more"; |
| 107 | static const char kStunAddressPortAndMore2[] = "stun:address:port more"; |
Niels Möller | db4def9 | 2019-03-18 16:53:59 +0100 | [diff] [blame] | 108 | static const char kTurnIceServerUri[] = "turn:turn.example.org"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 109 | static const char kTurnUsername[] = "user"; |
| 110 | static const char kTurnPassword[] = "password"; |
| 111 | static const char kTurnHostname[] = "turn.example.org"; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 112 | static const uint32_t kTimeout = 10000U; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 113 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 114 | static const char kStreams[][8] = {"stream1", "stream2"}; |
| 115 | static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"}; |
| 116 | static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"}; |
| 117 | |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 118 | static const char kRecvonly[] = "recvonly"; |
| 119 | static const char kSendrecv[] = "sendrecv"; |
| 120 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 121 | // Reference SDP with a MediaStream with label "stream1" and audio track with |
| 122 | // id "audio_1" and a video track with id "video_1; |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 123 | static const char kSdpStringWithStream1PlanB[] = |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 124 | "v=0\r\n" |
| 125 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 126 | "s=-\r\n" |
| 127 | "t=0 0\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 128 | "m=audio 1 RTP/AVPF 103\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 129 | "a=ice-ufrag:e5785931\r\n" |
| 130 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 131 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 132 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 133 | "a=mid:audio\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 134 | "a=sendrecv\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 135 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 136 | "a=rtpmap:103 ISAC/16000\r\n" |
| 137 | "a=ssrc:1 cname:stream1\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 +0000 | [diff] [blame] | 138 | "a=ssrc:1 mslabel:stream1\r\n" |
| 139 | "a=ssrc:1 label:audiotrack0\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 140 | "m=video 1 RTP/AVPF 120\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 141 | "a=ice-ufrag:e5785931\r\n" |
| 142 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 143 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 144 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 145 | "a=mid:video\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 146 | "a=sendrecv\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 147 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 148 | "a=rtpmap:120 VP8/90000\r\n" |
| 149 | "a=ssrc:2 cname:stream1\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 +0000 | [diff] [blame] | 150 | "a=ssrc:2 mslabel:stream1\r\n" |
| 151 | "a=ssrc:2 label:videotrack0\r\n"; |
| 152 | // Same string as above but with the MID changed to the Unified Plan default. |
| 153 | // This is needed so that this SDP can be used as an answer for a Unified Plan |
| 154 | // offer. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 155 | static const char kSdpStringWithStream1UnifiedPlan[] = |
| 156 | "v=0\r\n" |
| 157 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 158 | "s=-\r\n" |
| 159 | "t=0 0\r\n" |
| 160 | "m=audio 1 RTP/AVPF 103\r\n" |
| 161 | "a=ice-ufrag:e5785931\r\n" |
| 162 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 163 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 164 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 165 | "a=mid:0\r\n" |
| 166 | "a=sendrecv\r\n" |
| 167 | "a=rtcp-mux\r\n" |
| 168 | "a=rtpmap:103 ISAC/16000\r\n" |
| 169 | "a=ssrc:1 cname:stream1\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 +0000 | [diff] [blame] | 170 | "a=ssrc:1 mslabel:stream1\r\n" |
| 171 | "a=ssrc:1 label:audiotrack0\r\n" |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 172 | "m=video 1 RTP/AVPF 120\r\n" |
| 173 | "a=ice-ufrag:e5785931\r\n" |
| 174 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 175 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 176 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 177 | "a=mid:1\r\n" |
| 178 | "a=sendrecv\r\n" |
| 179 | "a=rtcp-mux\r\n" |
| 180 | "a=rtpmap:120 VP8/90000\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 +0000 | [diff] [blame] | 181 | "a=ssrc:2 cname:stream1\r\n" |
| 182 | "a=ssrc:2 mslabel:stream1\r\n" |
| 183 | "a=ssrc:2 label:videotrack0\r\n"; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 184 | |
zhihuang | 81c3a03 | 2016-11-17 12:06:24 -0800 | [diff] [blame] | 185 | // Reference SDP with a MediaStream with label "stream1" and audio track with |
| 186 | // id "audio_1"; |
| 187 | static const char kSdpStringWithStream1AudioTrackOnly[] = |
| 188 | "v=0\r\n" |
| 189 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 190 | "s=-\r\n" |
| 191 | "t=0 0\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 192 | "m=audio 1 RTP/AVPF 103\r\n" |
zhihuang | 81c3a03 | 2016-11-17 12:06:24 -0800 | [diff] [blame] | 193 | "a=ice-ufrag:e5785931\r\n" |
| 194 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 195 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 196 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
zhihuang | 81c3a03 | 2016-11-17 12:06:24 -0800 | [diff] [blame] | 197 | "a=mid:audio\r\n" |
| 198 | "a=sendrecv\r\n" |
| 199 | "a=rtpmap:103 ISAC/16000\r\n" |
| 200 | "a=ssrc:1 cname:stream1\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 +0000 | [diff] [blame] | 201 | "a=ssrc:1 mslabel:stream1\r\n" |
| 202 | "a=ssrc:1 label:audiotrack0\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 203 | "a=rtcp-mux\r\n"; |
zhihuang | 81c3a03 | 2016-11-17 12:06:24 -0800 | [diff] [blame] | 204 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 205 | // Reference SDP with two MediaStreams with label "stream1" and "stream2. Each |
| 206 | // MediaStreams have one audio track and one video track. |
| 207 | // This uses MSID. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 208 | static const char kSdpStringWithStream1And2PlanB[] = |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 209 | "v=0\r\n" |
| 210 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 211 | "s=-\r\n" |
| 212 | "t=0 0\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 213 | "a=msid-semantic: WMS stream1 stream2\r\n" |
| 214 | "m=audio 1 RTP/AVPF 103\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 215 | "a=ice-ufrag:e5785931\r\n" |
| 216 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 217 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 218 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 219 | "a=mid:audio\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 220 | "a=sendrecv\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 221 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 222 | "a=rtpmap:103 ISAC/16000\r\n" |
| 223 | "a=ssrc:1 cname:stream1\r\n" |
| 224 | "a=ssrc:1 msid:stream1 audiotrack0\r\n" |
| 225 | "a=ssrc:3 cname:stream2\r\n" |
| 226 | "a=ssrc:3 msid:stream2 audiotrack1\r\n" |
| 227 | "m=video 1 RTP/AVPF 120\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 228 | "a=ice-ufrag:e5785931\r\n" |
| 229 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 230 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 231 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 232 | "a=mid:video\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 233 | "a=sendrecv\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 234 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 235 | "a=rtpmap:120 VP8/0\r\n" |
| 236 | "a=ssrc:2 cname:stream1\r\n" |
| 237 | "a=ssrc:2 msid:stream1 videotrack0\r\n" |
| 238 | "a=ssrc:4 cname:stream2\r\n" |
| 239 | "a=ssrc:4 msid:stream2 videotrack1\r\n"; |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 240 | static const char kSdpStringWithStream1And2UnifiedPlan[] = |
| 241 | "v=0\r\n" |
| 242 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 243 | "s=-\r\n" |
| 244 | "t=0 0\r\n" |
| 245 | "a=msid-semantic: WMS stream1 stream2\r\n" |
| 246 | "m=audio 1 RTP/AVPF 103\r\n" |
| 247 | "a=ice-ufrag:e5785931\r\n" |
| 248 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 249 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 250 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 251 | "a=mid:0\r\n" |
| 252 | "a=sendrecv\r\n" |
| 253 | "a=rtcp-mux\r\n" |
| 254 | "a=rtpmap:103 ISAC/16000\r\n" |
| 255 | "a=ssrc:1 cname:stream1\r\n" |
| 256 | "a=ssrc:1 msid:stream1 audiotrack0\r\n" |
| 257 | "m=video 1 RTP/AVPF 120\r\n" |
| 258 | "a=ice-ufrag:e5785931\r\n" |
| 259 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 260 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 261 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 262 | "a=mid:1\r\n" |
| 263 | "a=sendrecv\r\n" |
| 264 | "a=rtcp-mux\r\n" |
| 265 | "a=rtpmap:120 VP8/0\r\n" |
| 266 | "a=ssrc:2 cname:stream1\r\n" |
| 267 | "a=ssrc:2 msid:stream1 videotrack0\r\n" |
| 268 | "m=audio 1 RTP/AVPF 103\r\n" |
| 269 | "a=ice-ufrag:e5785931\r\n" |
| 270 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 271 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 272 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 273 | "a=mid:2\r\n" |
| 274 | "a=sendrecv\r\n" |
| 275 | "a=rtcp-mux\r\n" |
| 276 | "a=rtpmap:103 ISAC/16000\r\n" |
| 277 | "a=ssrc:3 cname:stream2\r\n" |
| 278 | "a=ssrc:3 msid:stream2 audiotrack1\r\n" |
| 279 | "m=video 1 RTP/AVPF 120\r\n" |
| 280 | "a=ice-ufrag:e5785931\r\n" |
| 281 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 282 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 283 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 284 | "a=mid:3\r\n" |
| 285 | "a=sendrecv\r\n" |
| 286 | "a=rtcp-mux\r\n" |
| 287 | "a=rtpmap:120 VP8/0\r\n" |
| 288 | "a=ssrc:4 cname:stream2\r\n" |
| 289 | "a=ssrc:4 msid:stream2 videotrack1\r\n"; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 290 | |
| 291 | // Reference SDP without MediaStreams. Msid is not supported. |
| 292 | static const char kSdpStringWithoutStreams[] = |
| 293 | "v=0\r\n" |
| 294 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 295 | "s=-\r\n" |
| 296 | "t=0 0\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 297 | "m=audio 1 RTP/AVPF 103\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 298 | "a=ice-ufrag:e5785931\r\n" |
| 299 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 300 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 301 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 302 | "a=mid:audio\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 303 | "a=sendrecv\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 304 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 305 | "a=rtpmap:103 ISAC/16000\r\n" |
| 306 | "m=video 1 RTP/AVPF 120\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 307 | "a=ice-ufrag:e5785931\r\n" |
| 308 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 309 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 310 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 311 | "a=mid:video\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 312 | "a=sendrecv\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 313 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 314 | "a=rtpmap:120 VP8/90000\r\n"; |
| 315 | |
| 316 | // Reference SDP without MediaStreams. Msid is supported. |
| 317 | static const char kSdpStringWithMsidWithoutStreams[] = |
| 318 | "v=0\r\n" |
| 319 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 320 | "s=-\r\n" |
| 321 | "t=0 0\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 322 | "a=msid-semantic: WMS\r\n" |
| 323 | "m=audio 1 RTP/AVPF 103\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 324 | "a=ice-ufrag:e5785931\r\n" |
| 325 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 326 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 327 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 328 | "a=mid:audio\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 329 | "a=sendrecv\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 330 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 331 | "a=rtpmap:103 ISAC/16000\r\n" |
| 332 | "m=video 1 RTP/AVPF 120\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 333 | "a=ice-ufrag:e5785931\r\n" |
| 334 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 335 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 336 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 337 | "a=mid:video\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 338 | "a=sendrecv\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 339 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 340 | "a=rtpmap:120 VP8/90000\r\n"; |
| 341 | |
| 342 | // Reference SDP without MediaStreams and audio only. |
| 343 | static const char kSdpStringWithoutStreamsAudioOnly[] = |
| 344 | "v=0\r\n" |
| 345 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 346 | "s=-\r\n" |
| 347 | "t=0 0\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 348 | "m=audio 1 RTP/AVPF 103\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 349 | "a=ice-ufrag:e5785931\r\n" |
| 350 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 351 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 352 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 353 | "a=mid:audio\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 354 | "a=sendrecv\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 355 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 356 | "a=rtpmap:103 ISAC/16000\r\n"; |
| 357 | |
| 358 | // Reference SENDONLY SDP without MediaStreams. Msid is not supported. |
| 359 | static const char kSdpStringSendOnlyWithoutStreams[] = |
| 360 | "v=0\r\n" |
| 361 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 362 | "s=-\r\n" |
| 363 | "t=0 0\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 364 | "m=audio 1 RTP/AVPF 103\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 365 | "a=ice-ufrag:e5785931\r\n" |
| 366 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 367 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 368 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 369 | "a=mid:audio\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 370 | "a=sendrecv\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 371 | "a=sendonly\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 372 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 373 | "a=rtpmap:103 ISAC/16000\r\n" |
| 374 | "m=video 1 RTP/AVPF 120\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 375 | "a=ice-ufrag:e5785931\r\n" |
| 376 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 377 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 378 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 379 | "a=mid:video\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 380 | "a=sendrecv\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 381 | "a=sendonly\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 382 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 383 | "a=rtpmap:120 VP8/90000\r\n"; |
| 384 | |
| 385 | static const char kSdpStringInit[] = |
| 386 | "v=0\r\n" |
| 387 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 388 | "s=-\r\n" |
| 389 | "t=0 0\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 390 | "a=msid-semantic: WMS\r\n"; |
| 391 | |
| 392 | static const char kSdpStringAudio[] = |
| 393 | "m=audio 1 RTP/AVPF 103\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 394 | "a=ice-ufrag:e5785931\r\n" |
| 395 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 396 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 397 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 398 | "a=mid:audio\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 399 | "a=sendrecv\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 400 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 401 | "a=rtpmap:103 ISAC/16000\r\n"; |
| 402 | |
| 403 | static const char kSdpStringVideo[] = |
| 404 | "m=video 1 RTP/AVPF 120\r\n" |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 405 | "a=ice-ufrag:e5785931\r\n" |
| 406 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 407 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 408 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 409 | "a=mid:video\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 410 | "a=sendrecv\r\n" |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 411 | "a=rtcp-mux\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 412 | "a=rtpmap:120 VP8/90000\r\n"; |
| 413 | |
| 414 | static const char kSdpStringMs1Audio0[] = |
| 415 | "a=ssrc:1 cname:stream1\r\n" |
| 416 | "a=ssrc:1 msid:stream1 audiotrack0\r\n"; |
| 417 | |
| 418 | static const char kSdpStringMs1Video0[] = |
| 419 | "a=ssrc:2 cname:stream1\r\n" |
| 420 | "a=ssrc:2 msid:stream1 videotrack0\r\n"; |
| 421 | |
| 422 | static const char kSdpStringMs1Audio1[] = |
| 423 | "a=ssrc:3 cname:stream1\r\n" |
| 424 | "a=ssrc:3 msid:stream1 audiotrack1\r\n"; |
| 425 | |
| 426 | static const char kSdpStringMs1Video1[] = |
| 427 | "a=ssrc:4 cname:stream1\r\n" |
| 428 | "a=ssrc:4 msid:stream1 videotrack1\r\n"; |
| 429 | |
deadbeef | 8662f94 | 2017-01-20 21:20:51 -0800 | [diff] [blame] | 430 | static const char kDtlsSdesFallbackSdp[] = |
| 431 | "v=0\r\n" |
| 432 | "o=xxxxxx 7 2 IN IP4 0.0.0.0\r\n" |
| 433 | "s=-\r\n" |
| 434 | "c=IN IP4 0.0.0.0\r\n" |
| 435 | "t=0 0\r\n" |
| 436 | "a=group:BUNDLE audio\r\n" |
| 437 | "a=msid-semantic: WMS\r\n" |
| 438 | "m=audio 1 RTP/SAVPF 0\r\n" |
| 439 | "a=sendrecv\r\n" |
| 440 | "a=rtcp-mux\r\n" |
| 441 | "a=mid:audio\r\n" |
| 442 | "a=ssrc:1 cname:stream1\r\n" |
Artem Titov | f0a34f2 | 2020-03-16 17:52:04 +0000 | [diff] [blame] | 443 | "a=ssrc:1 mslabel:stream1\r\n" |
| 444 | "a=ssrc:1 label:audiotrack0\r\n" |
deadbeef | 8662f94 | 2017-01-20 21:20:51 -0800 | [diff] [blame] | 445 | "a=ice-ufrag:e5785931\r\n" |
| 446 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 447 | "a=rtpmap:0 pcmu/8000\r\n" |
| 448 | "a=fingerprint:sha-1 " |
| 449 | "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n" |
| 450 | "a=setup:actpass\r\n" |
Taylor Brandstetter | fd350d7 | 2018-04-03 16:29:26 -0700 | [diff] [blame] | 451 | "a=crypto:0 AES_CM_128_HMAC_SHA1_80 " |
deadbeef | 8662f94 | 2017-01-20 21:20:51 -0800 | [diff] [blame] | 452 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 453 | "dummy_session_params\r\n"; |
| 454 | |
Niels Möller | dec9f74 | 2019-06-03 15:25:20 +0200 | [diff] [blame] | 455 | class RtcEventLogOutputNull final : public RtcEventLogOutput { |
| 456 | public: |
| 457 | bool IsActive() const override { return true; } |
| 458 | bool Write(const std::string& output) override { return true; } |
| 459 | }; |
| 460 | |
Mirko Bonadei | ab64e8a | 2018-12-12 12:10:18 +0100 | [diff] [blame] | 461 | using ::cricket::StreamParams; |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 462 | using ::testing::Exactly; |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 463 | using ::testing::Values; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 464 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 465 | using RTCConfiguration = PeerConnectionInterface::RTCConfiguration; |
| 466 | using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 467 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 468 | // Gets the first ssrc of given content type from the ContentInfo. |
| 469 | bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) { |
| 470 | if (!content_info || !ssrc) { |
| 471 | return false; |
| 472 | } |
| 473 | const cricket::MediaContentDescription* media_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 474 | content_info->media_description(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 475 | if (!media_desc || media_desc->streams().empty()) { |
| 476 | return false; |
| 477 | } |
| 478 | *ssrc = media_desc->streams().begin()->first_ssrc(); |
| 479 | return true; |
| 480 | } |
| 481 | |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 482 | // Get the ufrags out of an SDP blob. Useful for testing ICE restart |
| 483 | // behavior. |
| 484 | std::vector<std::string> GetUfrags( |
| 485 | const webrtc::SessionDescriptionInterface* desc) { |
| 486 | std::vector<std::string> ufrags; |
| 487 | for (const cricket::TransportInfo& info : |
| 488 | desc->description()->transport_infos()) { |
| 489 | ufrags.push_back(info.description.ice_ufrag); |
| 490 | } |
| 491 | return ufrags; |
| 492 | } |
| 493 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 494 | void SetSsrcToZero(std::string* sdp) { |
| 495 | const char kSdpSsrcAtribute[] = "a=ssrc:"; |
| 496 | const char kSdpSsrcAtributeZero[] = "a=ssrc:0"; |
| 497 | size_t ssrc_pos = 0; |
| 498 | while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) != |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 499 | std::string::npos) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 500 | size_t end_ssrc = sdp->find(" ", ssrc_pos); |
| 501 | sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero); |
| 502 | ssrc_pos = end_ssrc; |
| 503 | } |
| 504 | } |
| 505 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 506 | // Check if |streams| contains the specified track. |
| 507 | bool ContainsTrack(const std::vector<cricket::StreamParams>& streams, |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 508 | const std::string& stream_id, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 509 | const std::string& track_id) { |
| 510 | for (const cricket::StreamParams& params : streams) { |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 511 | if (params.first_stream_id() == stream_id && params.id == track_id) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 512 | return true; |
| 513 | } |
| 514 | } |
| 515 | return false; |
| 516 | } |
| 517 | |
| 518 | // Check if |senders| contains the specified sender, by id. |
| 519 | bool ContainsSender( |
| 520 | const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders, |
| 521 | const std::string& id) { |
| 522 | for (const auto& sender : senders) { |
| 523 | if (sender->id() == id) { |
| 524 | return true; |
| 525 | } |
| 526 | } |
| 527 | return false; |
| 528 | } |
| 529 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 530 | // Check if |senders| contains the specified sender, by id and stream id. |
| 531 | bool ContainsSender( |
| 532 | const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders, |
| 533 | const std::string& id, |
| 534 | const std::string& stream_id) { |
| 535 | for (const auto& sender : senders) { |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 536 | if (sender->id() == id && sender->stream_ids()[0] == stream_id) { |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 537 | return true; |
| 538 | } |
| 539 | } |
| 540 | return false; |
| 541 | } |
| 542 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 543 | // Create a collection of streams. |
| 544 | // CreateStreamCollection(1) creates a collection that |
| 545 | // correspond to kSdpStringWithStream1. |
| 546 | // CreateStreamCollection(2) correspond to kSdpStringWithStream1And2. |
| 547 | rtc::scoped_refptr<StreamCollection> CreateStreamCollection( |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 548 | int number_of_streams, |
| 549 | int tracks_per_stream) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 550 | rtc::scoped_refptr<StreamCollection> local_collection( |
| 551 | StreamCollection::Create()); |
| 552 | |
| 553 | for (int i = 0; i < number_of_streams; ++i) { |
| 554 | rtc::scoped_refptr<webrtc::MediaStreamInterface> stream( |
| 555 | webrtc::MediaStream::Create(kStreams[i])); |
| 556 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 557 | for (int j = 0; j < tracks_per_stream; ++j) { |
| 558 | // Add a local audio track. |
| 559 | rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( |
| 560 | webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j], |
| 561 | nullptr)); |
| 562 | stream->AddTrack(audio_track); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 563 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 564 | // Add a local video track. |
| 565 | rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( |
| 566 | webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j], |
perkj | 773be36 | 2017-07-31 23:22:01 -0700 | [diff] [blame] | 567 | webrtc::FakeVideoTrackSource::Create(), |
| 568 | rtc::Thread::Current())); |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 569 | stream->AddTrack(video_track); |
| 570 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 571 | |
| 572 | local_collection->AddStream(stream); |
| 573 | } |
| 574 | return local_collection; |
| 575 | } |
| 576 | |
| 577 | // Check equality of StreamCollections. |
| 578 | bool CompareStreamCollections(StreamCollectionInterface* s1, |
| 579 | StreamCollectionInterface* s2) { |
| 580 | if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) { |
| 581 | return false; |
| 582 | } |
| 583 | |
| 584 | for (size_t i = 0; i != s1->count(); ++i) { |
Seth Hampson | 13b8bad | 2018-03-13 16:05:28 -0700 | [diff] [blame] | 585 | if (s1->at(i)->id() != s2->at(i)->id()) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 586 | return false; |
| 587 | } |
| 588 | webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks(); |
| 589 | webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks(); |
| 590 | webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks(); |
| 591 | webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks(); |
| 592 | |
| 593 | if (audio_tracks1.size() != audio_tracks2.size()) { |
| 594 | return false; |
| 595 | } |
| 596 | for (size_t j = 0; j != audio_tracks1.size(); ++j) { |
| 597 | if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) { |
| 598 | return false; |
| 599 | } |
| 600 | } |
| 601 | if (video_tracks1.size() != video_tracks2.size()) { |
| 602 | return false; |
| 603 | } |
| 604 | for (size_t j = 0; j != video_tracks1.size(); ++j) { |
| 605 | if (video_tracks1[j]->id() != video_tracks2[j]->id()) { |
| 606 | return false; |
| 607 | } |
| 608 | } |
| 609 | } |
| 610 | return true; |
| 611 | } |
| 612 | |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 613 | // Helper class to test Observer. |
| 614 | class MockTrackObserver : public ObserverInterface { |
| 615 | public: |
| 616 | explicit MockTrackObserver(NotifierInterface* notifier) |
| 617 | : notifier_(notifier) { |
| 618 | notifier_->RegisterObserver(this); |
| 619 | } |
| 620 | |
| 621 | ~MockTrackObserver() { Unregister(); } |
| 622 | |
| 623 | void Unregister() { |
| 624 | if (notifier_) { |
| 625 | notifier_->UnregisterObserver(this); |
| 626 | notifier_ = nullptr; |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | MOCK_METHOD0(OnChanged, void()); |
| 631 | |
| 632 | private: |
| 633 | NotifierInterface* notifier_; |
| 634 | }; |
| 635 | |
nisse | 528b793 | 2017-05-08 03:21:43 -0700 | [diff] [blame] | 636 | // The PeerConnectionMediaConfig tests below verify that configuration and |
| 637 | // constraints are propagated into the PeerConnection's MediaConfig. These |
| 638 | // settings are intended for MediaChannel constructors, but that is not |
| 639 | // exercised by these unittest. |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 640 | class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory { |
| 641 | public: |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 642 | static rtc::scoped_refptr<PeerConnectionFactoryForTest> |
| 643 | CreatePeerConnectionFactoryForTest() { |
Danil Chapovalov | f5258be | 2019-03-19 17:45:24 +0100 | [diff] [blame] | 644 | PeerConnectionFactoryDependencies dependencies; |
| 645 | dependencies.worker_thread = rtc::Thread::Current(); |
| 646 | dependencies.network_thread = rtc::Thread::Current(); |
| 647 | dependencies.signaling_thread = rtc::Thread::Current(); |
Danil Chapovalov | 9da25bd | 2019-06-20 10:19:42 +0200 | [diff] [blame] | 648 | dependencies.task_queue_factory = CreateDefaultTaskQueueFactory(); |
| 649 | cricket::MediaEngineDependencies media_deps; |
| 650 | media_deps.task_queue_factory = dependencies.task_queue_factory.get(); |
henrika | 919dc2e | 2017-10-12 14:24:55 +0200 | [diff] [blame] | 651 | // Use fake audio device module since we're only testing the interface |
| 652 | // level, and using a real one could make tests flaky when run in parallel. |
Danil Chapovalov | 9da25bd | 2019-06-20 10:19:42 +0200 | [diff] [blame] | 653 | media_deps.adm = FakeAudioCaptureModule::Create(); |
| 654 | SetMediaEngineDefaults(&media_deps); |
| 655 | dependencies.media_engine = |
| 656 | cricket::CreateMediaEngine(std::move(media_deps)); |
Danil Chapovalov | f5258be | 2019-03-19 17:45:24 +0100 | [diff] [blame] | 657 | dependencies.call_factory = webrtc::CreateCallFactory(); |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 658 | dependencies.event_log_factory = std::make_unique<RtcEventLogFactory>( |
Danil Chapovalov | 9da25bd | 2019-06-20 10:19:42 +0200 | [diff] [blame] | 659 | dependencies.task_queue_factory.get()); |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 660 | |
| 661 | return new rtc::RefCountedObject<PeerConnectionFactoryForTest>( |
Danil Chapovalov | f5258be | 2019-03-19 17:45:24 +0100 | [diff] [blame] | 662 | std::move(dependencies)); |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Danil Chapovalov | f5258be | 2019-03-19 17:45:24 +0100 | [diff] [blame] | 665 | using PeerConnectionFactory::PeerConnectionFactory; |
kwiberg | 1e4e8cb | 2017-01-31 01:48:08 -0800 | [diff] [blame] | 666 | |
Danil Chapovalov | f5258be | 2019-03-19 17:45:24 +0100 | [diff] [blame] | 667 | private: |
deadbeef | d7850b2 | 2017-08-23 10:59:19 -0700 | [diff] [blame] | 668 | rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_; |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 669 | }; |
| 670 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 671 | // TODO(steveanton): Convert to use the new PeerConnectionWrapper. |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 672 | class PeerConnectionInterfaceBaseTest : public ::testing::Test { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 673 | protected: |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 674 | explicit PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics) |
| 675 | : vss_(new rtc::VirtualSocketServer()), |
| 676 | main_(vss_.get()), |
| 677 | sdp_semantics_(sdp_semantics) { |
phoglund | 37ebcf0 | 2016-01-08 05:04:57 -0800 | [diff] [blame] | 678 | #ifdef WEBRTC_ANDROID |
| 679 | webrtc::InitializeAndroidObjects(); |
| 680 | #endif |
| 681 | } |
| 682 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 683 | virtual void SetUp() { |
deadbeef | d7850b2 | 2017-08-23 10:59:19 -0700 | [diff] [blame] | 684 | // Use fake audio capture module since we're only testing the interface |
| 685 | // level, and using a real one could make tests flaky when run in parallel. |
| 686 | fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 687 | pc_factory_ = webrtc::CreatePeerConnectionFactory( |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 688 | rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(), |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 689 | rtc::scoped_refptr<webrtc::AudioDeviceModule>( |
| 690 | fake_audio_capture_module_), |
| 691 | webrtc::CreateBuiltinAudioEncoderFactory(), |
| 692 | webrtc::CreateBuiltinAudioDecoderFactory(), |
| 693 | webrtc::CreateBuiltinVideoEncoderFactory(), |
| 694 | webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */, |
| 695 | nullptr /* audio_processing */); |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 696 | ASSERT_TRUE(pc_factory_); |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 697 | pc_factory_for_test_ = |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 698 | PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest(); |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 699 | pc_factory_for_test_->Initialize(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | void CreatePeerConnection() { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 703 | CreatePeerConnection(PeerConnectionInterface::RTCConfiguration()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 704 | } |
| 705 | |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 706 | // DTLS does not work in a loopback call, so is disabled for most of the |
| 707 | // tests in this file. |
| 708 | void CreatePeerConnectionWithoutDtls() { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 709 | RTCConfiguration config; |
| 710 | config.enable_dtls_srtp = false; |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 711 | |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 712 | CreatePeerConnection(config); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 713 | } |
| 714 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 715 | void CreatePeerConnectionWithIceTransportsType( |
| 716 | PeerConnectionInterface::IceTransportsType type) { |
| 717 | PeerConnectionInterface::RTCConfiguration config; |
| 718 | config.type = type; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 719 | return CreatePeerConnection(config); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | void CreatePeerConnectionWithIceServer(const std::string& uri, |
Niels Möller | db4def9 | 2019-03-18 16:53:59 +0100 | [diff] [blame] | 723 | const std::string& username, |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 724 | const std::string& password) { |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 725 | PeerConnectionInterface::RTCConfiguration config; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 726 | PeerConnectionInterface::IceServer server; |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 727 | server.uri = uri; |
Niels Möller | db4def9 | 2019-03-18 16:53:59 +0100 | [diff] [blame] | 728 | server.username = username; |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 729 | server.password = password; |
| 730 | config.servers.push_back(server); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 731 | CreatePeerConnection(config); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 732 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 733 | |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 734 | void CreatePeerConnection(const RTCConfiguration& config) { |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 735 | std::unique_ptr<cricket::FakePortAllocator> port_allocator( |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 736 | new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); |
| 737 | port_allocator_ = port_allocator.get(); |
jiayl@webrtc.org | a576faf | 2014-01-29 17:45:53 +0000 | [diff] [blame] | 738 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 739 | // Create certificate generator unless DTLS constraint is explicitly set to |
| 740 | // false. |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 741 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 742 | |
| 743 | if (config.enable_dtls_srtp.value_or(true)) { |
deadbeef | 8662f94 | 2017-01-20 21:20:51 -0800 | [diff] [blame] | 744 | fake_certificate_generator_ = new FakeRTCCertificateGenerator(); |
| 745 | cert_generator.reset(fake_certificate_generator_); |
jiayl@webrtc.org | a576faf | 2014-01-29 17:45:53 +0000 | [diff] [blame] | 746 | } |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 747 | RTCConfiguration modified_config = config; |
| 748 | modified_config.sdp_semantics = sdp_semantics_; |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 749 | pc_ = pc_factory_->CreatePeerConnection( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 750 | modified_config, std::move(port_allocator), std::move(cert_generator), |
| 751 | &observer_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 752 | ASSERT_TRUE(pc_.get() != NULL); |
| 753 | observer_.SetPeerConnectionInterface(pc_.get()); |
| 754 | EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); |
| 755 | } |
| 756 | |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 757 | void CreatePeerConnectionExpectFail(const std::string& uri) { |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 758 | PeerConnectionInterface::RTCConfiguration config; |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 759 | PeerConnectionInterface::IceServer server; |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 760 | server.uri = uri; |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 761 | config.servers.push_back(server); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 762 | config.sdp_semantics = sdp_semantics_; |
| 763 | rtc::scoped_refptr<PeerConnectionInterface> pc = |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 764 | pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 765 | EXPECT_EQ(nullptr, pc); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 766 | } |
| 767 | |
Steve Anton | 038834f | 2017-07-14 15:59:59 -0700 | [diff] [blame] | 768 | void CreatePeerConnectionExpectFail( |
| 769 | PeerConnectionInterface::RTCConfiguration config) { |
| 770 | PeerConnectionInterface::IceServer server; |
| 771 | server.uri = kTurnIceServerUri; |
| 772 | server.password = kTurnPassword; |
| 773 | config.servers.push_back(server); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 774 | config.sdp_semantics = sdp_semantics_; |
Steve Anton | 038834f | 2017-07-14 15:59:59 -0700 | [diff] [blame] | 775 | rtc::scoped_refptr<PeerConnectionInterface> pc = |
| 776 | pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_); |
| 777 | EXPECT_EQ(nullptr, pc); |
| 778 | } |
| 779 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 780 | void CreatePeerConnectionWithDifferentConfigurations() { |
Niels Möller | db4def9 | 2019-03-18 16:53:59 +0100 | [diff] [blame] | 781 | CreatePeerConnectionWithIceServer(kStunAddressOnly, "", ""); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 782 | EXPECT_EQ(1u, port_allocator_->stun_servers().size()); |
| 783 | EXPECT_EQ(0u, port_allocator_->turn_servers().size()); |
| 784 | EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 785 | EXPECT_EQ(kDefaultStunPort, |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 786 | port_allocator_->stun_servers().begin()->port()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 787 | |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 788 | CreatePeerConnectionExpectFail(kStunInvalidPort); |
| 789 | CreatePeerConnectionExpectFail(kStunAddressPortAndMore1); |
| 790 | CreatePeerConnectionExpectFail(kStunAddressPortAndMore2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 791 | |
Niels Möller | db4def9 | 2019-03-18 16:53:59 +0100 | [diff] [blame] | 792 | CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnUsername, |
| 793 | kTurnPassword); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 794 | EXPECT_EQ(0u, port_allocator_->stun_servers().size()); |
| 795 | EXPECT_EQ(1u, port_allocator_->turn_servers().size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 796 | EXPECT_EQ(kTurnUsername, |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 797 | port_allocator_->turn_servers()[0].credentials.username); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 798 | EXPECT_EQ(kTurnPassword, |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 799 | port_allocator_->turn_servers()[0].credentials.password); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 800 | EXPECT_EQ(kTurnHostname, |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 801 | port_allocator_->turn_servers()[0].ports[0].address.hostname()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | void ReleasePeerConnection() { |
| 805 | pc_ = NULL; |
| 806 | observer_.SetPeerConnectionInterface(NULL); |
| 807 | } |
| 808 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 809 | rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack( |
| 810 | const std::string& label) { |
Niels Möller | 215ba60 | 2019-01-18 13:59:45 +0100 | [diff] [blame] | 811 | return pc_factory_->CreateVideoTrack(label, FakeVideoTrackSource::Create()); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | void AddVideoTrack(const std::string& track_label, |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 815 | const std::vector<std::string>& stream_ids = {}) { |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 816 | auto sender_or_error = |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 817 | pc_->AddTrack(CreateVideoTrack(track_label), stream_ids); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 818 | ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 819 | } |
| 820 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 821 | void AddVideoStream(const std::string& label) { |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 822 | rtc::scoped_refptr<MediaStreamInterface> stream( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 823 | pc_factory_->CreateLocalMediaStream(label)); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 824 | stream->AddTrack(CreateVideoTrack(label + "v0")); |
| 825 | ASSERT_TRUE(pc_->AddStream(stream)); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack( |
| 829 | const std::string& label) { |
| 830 | return pc_factory_->CreateAudioTrack(label, nullptr); |
| 831 | } |
| 832 | |
| 833 | void AddAudioTrack(const std::string& track_label, |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 834 | const std::vector<std::string>& stream_ids = {}) { |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 835 | auto sender_or_error = |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 836 | pc_->AddTrack(CreateAudioTrack(track_label), stream_ids); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 837 | ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type()); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | void AddAudioStream(const std::string& label) { |
| 841 | rtc::scoped_refptr<MediaStreamInterface> stream( |
| 842 | pc_factory_->CreateLocalMediaStream(label)); |
| 843 | stream->AddTrack(CreateAudioTrack(label + "a0")); |
| 844 | ASSERT_TRUE(pc_->AddStream(stream)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 845 | } |
| 846 | |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 847 | void AddAudioVideoStream(const std::string& stream_id, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 848 | const std::string& audio_track_label, |
| 849 | const std::string& video_track_label) { |
| 850 | // Create a local stream. |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 851 | rtc::scoped_refptr<MediaStreamInterface> stream( |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 852 | pc_factory_->CreateLocalMediaStream(stream_id)); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 853 | stream->AddTrack(CreateAudioTrack(audio_track_label)); |
| 854 | stream->AddTrack(CreateVideoTrack(video_track_label)); |
| 855 | ASSERT_TRUE(pc_->AddStream(stream)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 856 | } |
| 857 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 858 | rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType( |
| 859 | cricket::MediaType media_type) { |
| 860 | for (auto receiver : pc_->GetReceivers()) { |
| 861 | if (receiver->media_type() == media_type) { |
| 862 | return receiver; |
| 863 | } |
| 864 | } |
| 865 | return nullptr; |
| 866 | } |
| 867 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 868 | bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc, |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 869 | const RTCOfferAnswerOptions* options, |
| 870 | bool offer) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 871 | rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer( |
| 872 | new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 873 | if (offer) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 874 | pc_->CreateOffer(observer, options ? *options : RTCOfferAnswerOptions()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 875 | } else { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 876 | pc_->CreateAnswer(observer, options ? *options : RTCOfferAnswerOptions()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 877 | } |
| 878 | EXPECT_EQ_WAIT(true, observer->called(), kTimeout); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 879 | *desc = observer->MoveDescription(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 880 | return observer->result(); |
| 881 | } |
| 882 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 883 | bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc, |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 884 | const RTCOfferAnswerOptions* options) { |
| 885 | return DoCreateOfferAnswer(desc, options, true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 886 | } |
| 887 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 888 | bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc, |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 889 | const RTCOfferAnswerOptions* options) { |
| 890 | return DoCreateOfferAnswer(desc, options, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 891 | } |
| 892 | |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 893 | bool DoSetSessionDescription( |
| 894 | std::unique_ptr<SessionDescriptionInterface> desc, |
| 895 | bool local) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 896 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer( |
| 897 | new rtc::RefCountedObject<MockSetSessionDescriptionObserver>()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 898 | if (local) { |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 899 | pc_->SetLocalDescription(observer, desc.release()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 900 | } else { |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 901 | pc_->SetRemoteDescription(observer, desc.release()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 902 | } |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 903 | if (pc_->signaling_state() != PeerConnectionInterface::kClosed) { |
| 904 | EXPECT_EQ_WAIT(true, observer->called(), kTimeout); |
| 905 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 906 | return observer->result(); |
| 907 | } |
| 908 | |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 909 | bool DoSetLocalDescription( |
| 910 | std::unique_ptr<SessionDescriptionInterface> desc) { |
| 911 | return DoSetSessionDescription(std::move(desc), true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 912 | } |
| 913 | |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 914 | bool DoSetRemoteDescription( |
| 915 | std::unique_ptr<SessionDescriptionInterface> desc) { |
| 916 | return DoSetSessionDescription(std::move(desc), false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | // Calls PeerConnection::GetStats and check the return value. |
| 920 | // It does not verify the values in the StatReports since a RTCP packet might |
| 921 | // be required. |
| 922 | bool DoGetStats(MediaStreamTrackInterface* track) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 923 | rtc::scoped_refptr<MockStatsObserver> observer( |
| 924 | new rtc::RefCountedObject<MockStatsObserver>()); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 925 | if (!pc_->GetStats(observer, track, |
| 926 | PeerConnectionInterface::kStatsOutputLevelStandard)) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 927 | return false; |
| 928 | EXPECT_TRUE_WAIT(observer->called(), kTimeout); |
| 929 | return observer->called(); |
| 930 | } |
| 931 | |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 932 | // Call the standards-compliant GetStats function. |
| 933 | bool DoGetRTCStats() { |
| 934 | rtc::scoped_refptr<webrtc::MockRTCStatsCollectorCallback> callback( |
| 935 | new rtc::RefCountedObject<webrtc::MockRTCStatsCollectorCallback>()); |
| 936 | pc_->GetStats(callback); |
| 937 | EXPECT_TRUE_WAIT(callback->called(), kTimeout); |
| 938 | return callback->called(); |
| 939 | } |
| 940 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 941 | void InitiateCall() { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 942 | CreatePeerConnectionWithoutDtls(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 943 | // Create a local stream with audio&video tracks. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 944 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 945 | AddAudioVideoStream(kStreamId1, "audio_track", "video_track"); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 946 | } else { |
| 947 | // Unified Plan does not support AddStream, so just add an audio and video |
| 948 | // track. |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 949 | AddAudioTrack(kAudioTracks[0], {kStreamId1}); |
| 950 | AddVideoTrack(kVideoTracks[0], {kStreamId1}); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 951 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 952 | CreateOfferReceiveAnswer(); |
| 953 | } |
| 954 | |
| 955 | // Verify that RTP Header extensions has been negotiated for audio and video. |
| 956 | void VerifyRemoteRtpHeaderExtensions() { |
| 957 | const cricket::MediaContentDescription* desc = |
| 958 | cricket::GetFirstAudioContentDescription( |
| 959 | pc_->remote_description()->description()); |
| 960 | ASSERT_TRUE(desc != NULL); |
| 961 | EXPECT_GT(desc->rtp_header_extensions().size(), 0u); |
| 962 | |
| 963 | desc = cricket::GetFirstVideoContentDescription( |
| 964 | pc_->remote_description()->description()); |
| 965 | ASSERT_TRUE(desc != NULL); |
| 966 | EXPECT_GT(desc->rtp_header_extensions().size(), 0u); |
| 967 | } |
| 968 | |
| 969 | void CreateOfferAsRemoteDescription() { |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 970 | std::unique_ptr<SessionDescriptionInterface> offer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 971 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 972 | std::string sdp; |
| 973 | EXPECT_TRUE(offer->ToString(&sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 974 | std::unique_ptr<SessionDescriptionInterface> remote_offer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 975 | webrtc::CreateSessionDescription(SdpType::kOffer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 976 | EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 977 | EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_); |
| 978 | } |
| 979 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 980 | void CreateAndSetRemoteOffer(const std::string& sdp) { |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 981 | std::unique_ptr<SessionDescriptionInterface> remote_offer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 982 | webrtc::CreateSessionDescription(SdpType::kOffer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 983 | EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 984 | EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_); |
| 985 | } |
| 986 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 987 | void CreateAnswerAsLocalDescription() { |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 988 | std::unique_ptr<SessionDescriptionInterface> answer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 989 | ASSERT_TRUE(DoCreateAnswer(&answer, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 990 | |
| 991 | // TODO(perkj): Currently SetLocalDescription fails if any parameters in an |
| 992 | // audio codec change, even if the parameter has nothing to do with |
| 993 | // receiving. Not all parameters are serialized to SDP. |
| 994 | // Since CreatePrAnswerAsLocalDescription serialize/deserialize |
| 995 | // the SessionDescription, it is necessary to do that here to in order to |
| 996 | // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass. |
| 997 | // https://code.google.com/p/webrtc/issues/detail?id=1356 |
| 998 | std::string sdp; |
| 999 | EXPECT_TRUE(answer->ToString(&sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1000 | std::unique_ptr<SessionDescriptionInterface> new_answer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 1001 | webrtc::CreateSessionDescription(SdpType::kAnswer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1002 | EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1003 | EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); |
| 1004 | } |
| 1005 | |
| 1006 | void CreatePrAnswerAsLocalDescription() { |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1007 | std::unique_ptr<SessionDescriptionInterface> answer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1008 | ASSERT_TRUE(DoCreateAnswer(&answer, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1009 | |
| 1010 | std::string sdp; |
| 1011 | EXPECT_TRUE(answer->ToString(&sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1012 | std::unique_ptr<SessionDescriptionInterface> pr_answer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 1013 | webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1014 | EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1015 | EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_); |
| 1016 | } |
| 1017 | |
| 1018 | void CreateOfferReceiveAnswer() { |
| 1019 | CreateOfferAsLocalDescription(); |
| 1020 | std::string sdp; |
| 1021 | EXPECT_TRUE(pc_->local_description()->ToString(&sdp)); |
| 1022 | CreateAnswerAsRemoteDescription(sdp); |
| 1023 | } |
| 1024 | |
| 1025 | void CreateOfferAsLocalDescription() { |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1026 | std::unique_ptr<SessionDescriptionInterface> offer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1027 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1028 | // TODO(perkj): Currently SetLocalDescription fails if any parameters in an |
| 1029 | // audio codec change, even if the parameter has nothing to do with |
| 1030 | // receiving. Not all parameters are serialized to SDP. |
| 1031 | // Since CreatePrAnswerAsLocalDescription serialize/deserialize |
| 1032 | // the SessionDescription, it is necessary to do that here to in order to |
| 1033 | // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass. |
| 1034 | // https://code.google.com/p/webrtc/issues/detail?id=1356 |
| 1035 | std::string sdp; |
| 1036 | EXPECT_TRUE(offer->ToString(&sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1037 | std::unique_ptr<SessionDescriptionInterface> new_offer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 1038 | webrtc::CreateSessionDescription(SdpType::kOffer, sdp)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1039 | |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1040 | EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1041 | EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_); |
mallinath@webrtc.org | 68cbd01 | 2014-01-22 00:16:46 +0000 | [diff] [blame] | 1042 | // Wait for the ice_complete message, so that SDP will have candidates. |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 1043 | EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1044 | } |
| 1045 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1046 | void CreateAnswerAsRemoteDescription(const std::string& sdp) { |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1047 | std::unique_ptr<SessionDescriptionInterface> answer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 1048 | webrtc::CreateSessionDescription(SdpType::kAnswer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1049 | ASSERT_TRUE(answer); |
| 1050 | EXPECT_TRUE(DoSetRemoteDescription(std::move(answer))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1051 | EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); |
| 1052 | } |
| 1053 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1054 | void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) { |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1055 | std::unique_ptr<SessionDescriptionInterface> pr_answer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 1056 | webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1057 | ASSERT_TRUE(pr_answer); |
| 1058 | EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1059 | EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1060 | std::unique_ptr<SessionDescriptionInterface> answer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 1061 | webrtc::CreateSessionDescription(SdpType::kAnswer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1062 | ASSERT_TRUE(answer); |
| 1063 | EXPECT_TRUE(DoSetRemoteDescription(std::move(answer))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1064 | EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); |
| 1065 | } |
| 1066 | |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1067 | // Waits until a remote stream with the given id is signaled. This helper |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1068 | // function will verify both OnAddTrack and OnAddStream (Plan B only) are |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1069 | // called with the given stream id and expected number of tracks. |
| 1070 | void WaitAndVerifyOnAddStream(const std::string& stream_id, |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1071 | int expected_num_tracks) { |
| 1072 | // Verify that both OnAddStream and OnAddTrack are called. |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1073 | EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1074 | EXPECT_EQ_WAIT(expected_num_tracks, |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1075 | observer_.CountAddTrackEventsForStream(stream_id), kTimeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1076 | } |
| 1077 | |
| 1078 | // Creates an offer and applies it as a local session description. |
| 1079 | // Creates an answer with the same SDP an the offer but removes all lines |
| 1080 | // that start with a:ssrc" |
| 1081 | void CreateOfferReceiveAnswerWithoutSsrc() { |
| 1082 | CreateOfferAsLocalDescription(); |
| 1083 | std::string sdp; |
| 1084 | EXPECT_TRUE(pc_->local_description()->ToString(&sdp)); |
| 1085 | SetSsrcToZero(&sdp); |
| 1086 | CreateAnswerAsRemoteDescription(sdp); |
| 1087 | } |
| 1088 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1089 | // This function creates a MediaStream with label kStreams[0] and |
| 1090 | // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the |
| 1091 | // corresponding SessionDescriptionInterface. The SessionDescriptionInterface |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1092 | // is returned and the MediaStream is stored in |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1093 | // |reference_collection_| |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1094 | std::unique_ptr<SessionDescriptionInterface> |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1095 | CreateSessionDescriptionAndReference(size_t number_of_audio_tracks, |
| 1096 | size_t number_of_video_tracks) { |
| 1097 | EXPECT_LE(number_of_audio_tracks, 2u); |
| 1098 | EXPECT_LE(number_of_video_tracks, 2u); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1099 | |
| 1100 | reference_collection_ = StreamCollection::Create(); |
| 1101 | std::string sdp_ms1 = std::string(kSdpStringInit); |
| 1102 | |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1103 | std::string mediastream_id = kStreams[0]; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1104 | |
| 1105 | rtc::scoped_refptr<webrtc::MediaStreamInterface> stream( |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1106 | webrtc::MediaStream::Create(mediastream_id)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1107 | reference_collection_->AddStream(stream); |
| 1108 | |
| 1109 | if (number_of_audio_tracks > 0) { |
| 1110 | sdp_ms1 += std::string(kSdpStringAudio); |
| 1111 | sdp_ms1 += std::string(kSdpStringMs1Audio0); |
| 1112 | AddAudioTrack(kAudioTracks[0], stream); |
| 1113 | } |
| 1114 | if (number_of_audio_tracks > 1) { |
| 1115 | sdp_ms1 += kSdpStringMs1Audio1; |
| 1116 | AddAudioTrack(kAudioTracks[1], stream); |
| 1117 | } |
| 1118 | |
| 1119 | if (number_of_video_tracks > 0) { |
| 1120 | sdp_ms1 += std::string(kSdpStringVideo); |
| 1121 | sdp_ms1 += std::string(kSdpStringMs1Video0); |
| 1122 | AddVideoTrack(kVideoTracks[0], stream); |
| 1123 | } |
| 1124 | if (number_of_video_tracks > 1) { |
| 1125 | sdp_ms1 += kSdpStringMs1Video1; |
| 1126 | AddVideoTrack(kVideoTracks[1], stream); |
| 1127 | } |
| 1128 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1129 | return std::unique_ptr<SessionDescriptionInterface>( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 1130 | webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | void AddAudioTrack(const std::string& track_id, |
| 1134 | MediaStreamInterface* stream) { |
| 1135 | rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( |
| 1136 | webrtc::AudioTrack::Create(track_id, nullptr)); |
| 1137 | ASSERT_TRUE(stream->AddTrack(audio_track)); |
| 1138 | } |
| 1139 | |
| 1140 | void AddVideoTrack(const std::string& track_id, |
| 1141 | MediaStreamInterface* stream) { |
| 1142 | rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( |
nisse | af510af | 2016-03-21 08:20:42 -0700 | [diff] [blame] | 1143 | webrtc::VideoTrack::Create(track_id, |
perkj | 773be36 | 2017-07-31 23:22:01 -0700 | [diff] [blame] | 1144 | webrtc::FakeVideoTrackSource::Create(), |
| 1145 | rtc::Thread::Current())); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1146 | ASSERT_TRUE(stream->AddTrack(video_track)); |
| 1147 | } |
| 1148 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1149 | std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1150 | CreatePeerConnectionWithoutDtls(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1151 | AddAudioTrack(kAudioTracks[0]); |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 1152 | std::unique_ptr<SessionDescriptionInterface> offer; |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 1153 | EXPECT_TRUE(DoCreateOffer(&offer, nullptr)); |
| 1154 | return offer; |
| 1155 | } |
| 1156 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1157 | std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() { |
| 1158 | CreatePeerConnectionWithoutDtls(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1159 | AddAudioStream(kStreamId1); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1160 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 1161 | EXPECT_TRUE(DoCreateOffer(&offer, nullptr)); |
| 1162 | return offer; |
| 1163 | } |
| 1164 | |
| 1165 | std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() { |
| 1166 | EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack())); |
| 1167 | std::unique_ptr<SessionDescriptionInterface> answer; |
| 1168 | EXPECT_TRUE(DoCreateAnswer(&answer, nullptr)); |
| 1169 | return answer; |
| 1170 | } |
| 1171 | |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 1172 | std::unique_ptr<SessionDescriptionInterface> |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 1173 | CreateAnswerWithOneAudioStream() { |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1174 | EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream())); |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 1175 | std::unique_ptr<SessionDescriptionInterface> answer; |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 1176 | EXPECT_TRUE(DoCreateAnswer(&answer, nullptr)); |
| 1177 | return answer; |
| 1178 | } |
| 1179 | |
| 1180 | const std::string& GetFirstAudioStreamCname( |
| 1181 | const SessionDescriptionInterface* desc) { |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 1182 | const cricket::AudioContentDescription* audio_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1183 | cricket::GetFirstAudioContentDescription(desc->description()); |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 1184 | return audio_desc->streams()[0].cname; |
| 1185 | } |
| 1186 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1187 | std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions( |
| 1188 | const RTCOfferAnswerOptions& offer_answer_options) { |
| 1189 | RTC_DCHECK(pc_); |
| 1190 | rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer( |
| 1191 | new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>()); |
| 1192 | pc_->CreateOffer(observer, offer_answer_options); |
| 1193 | EXPECT_EQ_WAIT(true, observer->called(), kTimeout); |
| 1194 | return observer->MoveDescription(); |
| 1195 | } |
| 1196 | |
| 1197 | void CreateOfferWithOptionsAsRemoteDescription( |
| 1198 | std::unique_ptr<SessionDescriptionInterface>* desc, |
| 1199 | const RTCOfferAnswerOptions& offer_answer_options) { |
| 1200 | *desc = CreateOfferWithOptions(offer_answer_options); |
| 1201 | ASSERT_TRUE(desc != nullptr); |
| 1202 | std::string sdp; |
| 1203 | EXPECT_TRUE((*desc)->ToString(&sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1204 | std::unique_ptr<SessionDescriptionInterface> remote_offer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 1205 | webrtc::CreateSessionDescription(SdpType::kOffer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1206 | EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer))); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1207 | EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_); |
| 1208 | } |
| 1209 | |
| 1210 | void CreateOfferWithOptionsAsLocalDescription( |
| 1211 | std::unique_ptr<SessionDescriptionInterface>* desc, |
| 1212 | const RTCOfferAnswerOptions& offer_answer_options) { |
| 1213 | *desc = CreateOfferWithOptions(offer_answer_options); |
| 1214 | ASSERT_TRUE(desc != nullptr); |
| 1215 | std::string sdp; |
| 1216 | EXPECT_TRUE((*desc)->ToString(&sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1217 | std::unique_ptr<SessionDescriptionInterface> new_offer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 1218 | webrtc::CreateSessionDescription(SdpType::kOffer, sdp)); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1219 | |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1220 | EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer))); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1221 | EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_); |
| 1222 | } |
| 1223 | |
| 1224 | bool HasCNCodecs(const cricket::ContentInfo* content) { |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1225 | RTC_DCHECK(content); |
| 1226 | RTC_DCHECK(content->media_description()); |
| 1227 | for (const cricket::AudioCodec& codec : |
| 1228 | content->media_description()->as_audio()->codecs()) { |
| 1229 | if (codec.name == "CN") { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1230 | return true; |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1231 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1232 | } |
| 1233 | return false; |
| 1234 | } |
| 1235 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1236 | const char* GetSdpStringWithStream1() const { |
| 1237 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 1238 | return kSdpStringWithStream1PlanB; |
| 1239 | } else { |
| 1240 | return kSdpStringWithStream1UnifiedPlan; |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | const char* GetSdpStringWithStream1And2() const { |
| 1245 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 1246 | return kSdpStringWithStream1And2PlanB; |
| 1247 | } else { |
| 1248 | return kSdpStringWithStream1And2UnifiedPlan; |
| 1249 | } |
| 1250 | } |
| 1251 | |
deadbeef | 9a6f4d4 | 2017-05-15 19:43:33 -0700 | [diff] [blame] | 1252 | std::unique_ptr<rtc::VirtualSocketServer> vss_; |
| 1253 | rtc::AutoSocketServerThread main_; |
deadbeef | d7850b2 | 2017-08-23 10:59:19 -0700 | [diff] [blame] | 1254 | rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_; |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 1255 | cricket::FakePortAllocator* port_allocator_ = nullptr; |
deadbeef | 8662f94 | 2017-01-20 21:20:51 -0800 | [diff] [blame] | 1256 | FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr; |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1257 | rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_; |
| 1258 | rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_; |
| 1259 | rtc::scoped_refptr<PeerConnectionInterface> pc_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1260 | MockPeerConnectionObserver observer_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1261 | rtc::scoped_refptr<StreamCollection> reference_collection_; |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1262 | const SdpSemantics sdp_semantics_; |
| 1263 | }; |
| 1264 | |
| 1265 | class PeerConnectionInterfaceTest |
| 1266 | : public PeerConnectionInterfaceBaseTest, |
| 1267 | public ::testing::WithParamInterface<SdpSemantics> { |
| 1268 | protected: |
| 1269 | PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {} |
| 1270 | }; |
| 1271 | |
| 1272 | class PeerConnectionInterfaceTestPlanB |
| 1273 | : public PeerConnectionInterfaceBaseTest { |
| 1274 | protected: |
| 1275 | PeerConnectionInterfaceTestPlanB() |
| 1276 | : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1277 | }; |
| 1278 | |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 1279 | // Generate different CNAMEs when PeerConnections are created. |
| 1280 | // The CNAMEs are expected to be generated randomly. It is possible |
| 1281 | // that the test fails, though the possibility is very low. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1282 | TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) { |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 1283 | std::unique_ptr<SessionDescriptionInterface> offer1 = |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1284 | CreateOfferWithOneAudioTrack(); |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 1285 | std::unique_ptr<SessionDescriptionInterface> offer2 = |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1286 | CreateOfferWithOneAudioTrack(); |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 1287 | EXPECT_NE(GetFirstAudioStreamCname(offer1.get()), |
| 1288 | GetFirstAudioStreamCname(offer2.get())); |
| 1289 | } |
| 1290 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1291 | TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) { |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 1292 | std::unique_ptr<SessionDescriptionInterface> answer1 = |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1293 | CreateAnswerWithOneAudioTrack(); |
kwiberg | fd8be34 | 2016-05-14 19:44:11 -0700 | [diff] [blame] | 1294 | std::unique_ptr<SessionDescriptionInterface> answer2 = |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1295 | CreateAnswerWithOneAudioTrack(); |
zhihuang | 8f65cdf | 2016-05-06 18:40:30 -0700 | [diff] [blame] | 1296 | EXPECT_NE(GetFirstAudioStreamCname(answer1.get()), |
| 1297 | GetFirstAudioStreamCname(answer2.get())); |
| 1298 | } |
| 1299 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1300 | TEST_P(PeerConnectionInterfaceTest, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1301 | CreatePeerConnectionWithDifferentConfigurations) { |
| 1302 | CreatePeerConnectionWithDifferentConfigurations(); |
| 1303 | } |
| 1304 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1305 | TEST_P(PeerConnectionInterfaceTest, |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 1306 | CreatePeerConnectionWithDifferentIceTransportsTypes) { |
| 1307 | CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone); |
| 1308 | EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter()); |
| 1309 | CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay); |
| 1310 | EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter()); |
| 1311 | CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost); |
| 1312 | EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST, |
| 1313 | port_allocator_->candidate_filter()); |
| 1314 | CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll); |
| 1315 | EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter()); |
| 1316 | } |
| 1317 | |
| 1318 | // Test that when a PeerConnection is created with a nonzero candidate pool |
| 1319 | // size, the pooled PortAllocatorSession is created with all the attributes |
| 1320 | // in the RTCConfiguration. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1321 | TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) { |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 1322 | PeerConnectionInterface::RTCConfiguration config; |
| 1323 | PeerConnectionInterface::IceServer server; |
| 1324 | server.uri = kStunAddressOnly; |
| 1325 | config.servers.push_back(server); |
| 1326 | config.type = PeerConnectionInterface::kRelay; |
| 1327 | config.disable_ipv6 = true; |
| 1328 | config.tcp_candidate_policy = |
| 1329 | PeerConnectionInterface::kTcpCandidatePolicyDisabled; |
honghaiz | 6034705 | 2016-05-31 18:29:12 -0700 | [diff] [blame] | 1330 | config.candidate_network_policy = |
| 1331 | PeerConnectionInterface::kCandidateNetworkPolicyLowCost; |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 1332 | config.ice_candidate_pool_size = 1; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1333 | CreatePeerConnection(config); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 1334 | |
| 1335 | const cricket::FakePortAllocatorSession* session = |
| 1336 | static_cast<const cricket::FakePortAllocatorSession*>( |
| 1337 | port_allocator_->GetPooledSession()); |
| 1338 | ASSERT_NE(nullptr, session); |
| 1339 | EXPECT_EQ(1UL, session->stun_servers().size()); |
| 1340 | EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6); |
| 1341 | EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP); |
honghaiz | 6034705 | 2016-05-31 18:29:12 -0700 | [diff] [blame] | 1342 | EXPECT_LT(0U, |
| 1343 | session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 1344 | } |
| 1345 | |
deadbeef | d21eab3 | 2017-07-26 16:50:11 -0700 | [diff] [blame] | 1346 | // Test that network-related RTCConfiguration members are applied to the |
| 1347 | // PortAllocator when CreatePeerConnection is called. Specifically: |
| 1348 | // - disable_ipv6_on_wifi |
| 1349 | // - max_ipv6_networks |
| 1350 | // - tcp_candidate_policy |
| 1351 | // - candidate_network_policy |
| 1352 | // - prune_turn_ports |
| 1353 | // |
| 1354 | // Note that the candidate filter (RTCConfiguration::type) is already tested |
| 1355 | // above. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1356 | TEST_P(PeerConnectionInterfaceTest, |
deadbeef | d21eab3 | 2017-07-26 16:50:11 -0700 | [diff] [blame] | 1357 | CreatePeerConnectionAppliesNetworkConfigToPortAllocator) { |
| 1358 | // Create fake port allocator. |
| 1359 | std::unique_ptr<cricket::FakePortAllocator> port_allocator( |
| 1360 | new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); |
| 1361 | cricket::FakePortAllocator* raw_port_allocator = port_allocator.get(); |
| 1362 | |
| 1363 | // Create RTCConfiguration with some network-related fields relevant to |
| 1364 | // PortAllocator populated. |
| 1365 | PeerConnectionInterface::RTCConfiguration config; |
| 1366 | config.disable_ipv6_on_wifi = true; |
| 1367 | config.max_ipv6_networks = 10; |
| 1368 | config.tcp_candidate_policy = |
| 1369 | PeerConnectionInterface::kTcpCandidatePolicyDisabled; |
| 1370 | config.candidate_network_policy = |
| 1371 | PeerConnectionInterface::kCandidateNetworkPolicyLowCost; |
| 1372 | config.prune_turn_ports = true; |
| 1373 | |
| 1374 | // Create the PC factory and PC with the above config. |
| 1375 | rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory( |
| 1376 | webrtc::CreatePeerConnectionFactory( |
| 1377 | rtc::Thread::Current(), rtc::Thread::Current(), |
Karl Wiberg | 1b0eae3 | 2017-10-17 14:48:54 +0200 | [diff] [blame] | 1378 | rtc::Thread::Current(), fake_audio_capture_module_, |
| 1379 | webrtc::CreateBuiltinAudioEncoderFactory(), |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 1380 | webrtc::CreateBuiltinAudioDecoderFactory(), |
| 1381 | webrtc::CreateBuiltinVideoEncoderFactory(), |
| 1382 | webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */, |
| 1383 | nullptr /* audio_processing */)); |
deadbeef | d21eab3 | 2017-07-26 16:50:11 -0700 | [diff] [blame] | 1384 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1385 | pc_factory->CreatePeerConnection(config, std::move(port_allocator), |
| 1386 | nullptr, &observer_)); |
Yves Gerey | 4e93329 | 2018-10-31 15:36:05 +0100 | [diff] [blame] | 1387 | EXPECT_TRUE(pc.get()); |
| 1388 | observer_.SetPeerConnectionInterface(pc.get()); |
deadbeef | d21eab3 | 2017-07-26 16:50:11 -0700 | [diff] [blame] | 1389 | |
| 1390 | // Now validate that the config fields set above were applied to the |
| 1391 | // PortAllocator, as flags or otherwise. |
| 1392 | EXPECT_FALSE(raw_port_allocator->flags() & |
| 1393 | cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI); |
| 1394 | EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks()); |
| 1395 | EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP); |
| 1396 | EXPECT_TRUE(raw_port_allocator->flags() & |
| 1397 | cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS); |
Honghai Zhang | f8998cf | 2019-10-14 11:27:50 -0700 | [diff] [blame] | 1398 | EXPECT_EQ(webrtc::PRUNE_BASED_ON_PRIORITY, |
| 1399 | raw_port_allocator->turn_port_prune_policy()); |
deadbeef | d21eab3 | 2017-07-26 16:50:11 -0700 | [diff] [blame] | 1400 | } |
| 1401 | |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame] | 1402 | // Check that GetConfiguration returns the configuration the PeerConnection was |
| 1403 | // constructed with, before SetConfiguration is called. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1404 | TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) { |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame] | 1405 | PeerConnectionInterface::RTCConfiguration config; |
| 1406 | config.type = PeerConnectionInterface::kRelay; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1407 | CreatePeerConnection(config); |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame] | 1408 | |
| 1409 | PeerConnectionInterface::RTCConfiguration returned_config = |
| 1410 | pc_->GetConfiguration(); |
| 1411 | EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type); |
| 1412 | } |
| 1413 | |
| 1414 | // Check that GetConfiguration returns the last configuration passed into |
| 1415 | // SetConfiguration. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1416 | TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) { |
Piotr (Peter) Slatala | 37227be | 2018-11-21 07:42:22 -0800 | [diff] [blame] | 1417 | PeerConnectionInterface::RTCConfiguration starting_config; |
| 1418 | starting_config.bundle_policy = |
| 1419 | webrtc::PeerConnection::kBundlePolicyMaxBundle; |
| 1420 | CreatePeerConnection(starting_config); |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame] | 1421 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1422 | PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration(); |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame] | 1423 | config.type = PeerConnectionInterface::kRelay; |
Bjorn A Mellem | 7a9a092 | 2019-11-26 09:19:40 -0800 | [diff] [blame] | 1424 | config.use_datagram_transport = true; |
| 1425 | config.use_datagram_transport_for_data_channels = true; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 1426 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame] | 1427 | |
| 1428 | PeerConnectionInterface::RTCConfiguration returned_config = |
| 1429 | pc_->GetConfiguration(); |
| 1430 | EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type); |
Bjorn A Mellem | 7a9a092 | 2019-11-26 09:19:40 -0800 | [diff] [blame] | 1431 | EXPECT_TRUE(returned_config.use_datagram_transport); |
| 1432 | EXPECT_TRUE(returned_config.use_datagram_transport_for_data_channels); |
deadbeef | 46c7389 | 2016-11-16 19:42:04 -0800 | [diff] [blame] | 1433 | } |
| 1434 | |
Steve Anton | c79268f | 2018-04-24 09:54:10 -0700 | [diff] [blame] | 1435 | TEST_P(PeerConnectionInterfaceTest, SetConfigurationFailsAfterClose) { |
| 1436 | CreatePeerConnection(); |
| 1437 | |
| 1438 | pc_->Close(); |
| 1439 | |
| 1440 | EXPECT_FALSE( |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 1441 | pc_->SetConfiguration(PeerConnectionInterface::RTCConfiguration()).ok()); |
Steve Anton | c79268f | 2018-04-24 09:54:10 -0700 | [diff] [blame] | 1442 | } |
| 1443 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1444 | TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1445 | CreatePeerConnectionWithoutDtls(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1446 | AddVideoStream(kStreamId1); |
| 1447 | AddAudioStream(kStreamId2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1448 | ASSERT_EQ(2u, pc_->local_streams()->count()); |
| 1449 | |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 1450 | // Test we can add multiple local streams to one peerconnection. |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1451 | rtc::scoped_refptr<MediaStreamInterface> stream( |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1452 | pc_factory_->CreateLocalMediaStream(kStreamId3)); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1453 | rtc::scoped_refptr<AudioTrackInterface> audio_track( |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1454 | pc_factory_->CreateAudioTrack(kStreamId3, |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1455 | static_cast<AudioSourceInterface*>(NULL))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1456 | stream->AddTrack(audio_track.get()); |
perkj@webrtc.org | c2dd5ee | 2014-11-04 11:31:29 +0000 | [diff] [blame] | 1457 | EXPECT_TRUE(pc_->AddStream(stream)); |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 1458 | EXPECT_EQ(3u, pc_->local_streams()->count()); |
| 1459 | |
| 1460 | // Remove the third stream. |
| 1461 | pc_->RemoveStream(pc_->local_streams()->at(2)); |
| 1462 | EXPECT_EQ(2u, pc_->local_streams()->count()); |
| 1463 | |
| 1464 | // Remove the second stream. |
| 1465 | pc_->RemoveStream(pc_->local_streams()->at(1)); |
| 1466 | EXPECT_EQ(1u, pc_->local_streams()->count()); |
| 1467 | |
| 1468 | // Remove the first stream. |
| 1469 | pc_->RemoveStream(pc_->local_streams()->at(0)); |
| 1470 | EXPECT_EQ(0u, pc_->local_streams()->count()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1471 | } |
| 1472 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1473 | // Test that the created offer includes streams we added. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1474 | // Don't run under Unified Plan since the stream API is not available. |
| 1475 | TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1476 | CreatePeerConnectionWithoutDtls(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1477 | AddAudioVideoStream(kStreamId1, "audio_track", "video_track"); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1478 | std::unique_ptr<SessionDescriptionInterface> offer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1479 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1480 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1481 | const cricket::AudioContentDescription* audio_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1482 | cricket::GetFirstAudioContentDescription(offer->description()); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1483 | EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track")); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1484 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1485 | const cricket::VideoContentDescription* video_desc = |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1486 | cricket::GetFirstVideoContentDescription(offer->description()); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1487 | EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track")); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1488 | |
| 1489 | // Add another stream and ensure the offer includes both the old and new |
| 1490 | // streams. |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1491 | AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2"); |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1492 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1493 | |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1494 | audio_desc = cricket::GetFirstAudioContentDescription(offer->description()); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1495 | EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track")); |
| 1496 | EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2")); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1497 | |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1498 | video_desc = cricket::GetFirstVideoContentDescription(offer->description()); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1499 | EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track")); |
| 1500 | EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2")); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1501 | } |
| 1502 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1503 | // Don't run under Unified Plan since the stream API is not available. |
| 1504 | TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1505 | CreatePeerConnectionWithoutDtls(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1506 | AddVideoStream(kStreamId1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1507 | ASSERT_EQ(1u, pc_->local_streams()->count()); |
| 1508 | pc_->RemoveStream(pc_->local_streams()->at(0)); |
| 1509 | EXPECT_EQ(0u, pc_->local_streams()->count()); |
| 1510 | } |
| 1511 | |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1512 | // Test for AddTrack and RemoveTrack methods. |
| 1513 | // Tests that the created offer includes tracks we added, |
| 1514 | // and that the RtpSenders are created correctly. |
| 1515 | // Also tests that RemoveTrack removes the tracks from subsequent offers. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1516 | // Only tested with Plan B since Unified Plan is covered in more detail by tests |
| 1517 | // in peerconnection_jsep_unittests.cc |
| 1518 | TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1519 | CreatePeerConnectionWithoutDtls(); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1520 | rtc::scoped_refptr<AudioTrackInterface> audio_track( |
Niels Möller | 215ba60 | 2019-01-18 13:59:45 +0100 | [diff] [blame] | 1521 | CreateAudioTrack("audio_track")); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1522 | rtc::scoped_refptr<VideoTrackInterface> video_track( |
Niels Möller | 215ba60 | 2019-01-18 13:59:45 +0100 | [diff] [blame] | 1523 | CreateVideoTrack("video_track")); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1524 | auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue(); |
| 1525 | auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue(); |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 1526 | EXPECT_EQ(1UL, audio_sender->stream_ids().size()); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1527 | EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1528 | EXPECT_EQ("audio_track", audio_sender->id()); |
| 1529 | EXPECT_EQ(audio_track, audio_sender->track()); |
deadbeef | a601f5c | 2016-06-06 14:27:39 -0700 | [diff] [blame] | 1530 | EXPECT_EQ(1UL, video_sender->stream_ids().size()); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1531 | EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1532 | EXPECT_EQ("video_track", video_sender->id()); |
| 1533 | EXPECT_EQ(video_track, video_sender->track()); |
| 1534 | |
| 1535 | // Now create an offer and check for the senders. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1536 | std::unique_ptr<SessionDescriptionInterface> offer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1537 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1538 | |
| 1539 | const cricket::ContentInfo* audio_content = |
| 1540 | cricket::GetFirstAudioContent(offer->description()); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1541 | EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(), |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1542 | kStreamId1, "audio_track")); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1543 | |
| 1544 | const cricket::ContentInfo* video_content = |
| 1545 | cricket::GetFirstVideoContent(offer->description()); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1546 | EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(), |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1547 | kStreamId1, "video_track")); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1548 | |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1549 | EXPECT_TRUE(DoSetLocalDescription(std::move(offer))); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1550 | |
| 1551 | // Now try removing the tracks. |
| 1552 | EXPECT_TRUE(pc_->RemoveTrack(audio_sender)); |
| 1553 | EXPECT_TRUE(pc_->RemoveTrack(video_sender)); |
| 1554 | |
| 1555 | // Create a new offer and ensure it doesn't contain the removed senders. |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1556 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1557 | |
| 1558 | audio_content = cricket::GetFirstAudioContent(offer->description()); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1559 | EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(), |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1560 | kStreamId1, "audio_track")); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1561 | |
| 1562 | video_content = cricket::GetFirstVideoContent(offer->description()); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 1563 | EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(), |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1564 | kStreamId1, "video_track")); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1565 | |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1566 | EXPECT_TRUE(DoSetLocalDescription(std::move(offer))); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1567 | |
| 1568 | // Calling RemoveTrack on a sender no longer attached to a PeerConnection |
| 1569 | // should return false. |
| 1570 | EXPECT_FALSE(pc_->RemoveTrack(audio_sender)); |
| 1571 | EXPECT_FALSE(pc_->RemoveTrack(video_sender)); |
| 1572 | } |
| 1573 | |
| 1574 | // Test creating senders without a stream specified, |
| 1575 | // expecting a random stream ID to be generated. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1576 | TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1577 | CreatePeerConnectionWithoutDtls(); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1578 | rtc::scoped_refptr<AudioTrackInterface> audio_track( |
Niels Möller | 215ba60 | 2019-01-18 13:59:45 +0100 | [diff] [blame] | 1579 | CreateAudioTrack("audio_track")); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1580 | rtc::scoped_refptr<VideoTrackInterface> video_track( |
Niels Möller | 215ba60 | 2019-01-18 13:59:45 +0100 | [diff] [blame] | 1581 | CreateVideoTrack("video_track")); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1582 | auto audio_sender = |
Steve Anton | 2d6c76a | 2018-01-05 17:10:52 -0800 | [diff] [blame] | 1583 | pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue(); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1584 | auto video_sender = |
Steve Anton | 2d6c76a | 2018-01-05 17:10:52 -0800 | [diff] [blame] | 1585 | pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue(); |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1586 | EXPECT_EQ("audio_track", audio_sender->id()); |
| 1587 | EXPECT_EQ(audio_track, audio_sender->track()); |
| 1588 | EXPECT_EQ("video_track", video_sender->id()); |
| 1589 | EXPECT_EQ(video_track, video_sender->track()); |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 1590 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 1591 | // If the ID is truly a random GUID, it should be infinitely unlikely they |
| 1592 | // will be the same. |
| 1593 | EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids()); |
| 1594 | } else { |
| 1595 | // We allows creating tracks without stream ids under Unified Plan |
| 1596 | // semantics. |
| 1597 | EXPECT_EQ(0u, video_sender->stream_ids().size()); |
| 1598 | EXPECT_EQ(0u, audio_sender->stream_ids().size()); |
| 1599 | } |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1600 | } |
| 1601 | |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 1602 | // Test that we can call GetStats() after AddTrack but before connecting |
| 1603 | // the PeerConnection to a peer. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1604 | TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) { |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 1605 | CreatePeerConnectionWithoutDtls(); |
| 1606 | rtc::scoped_refptr<AudioTrackInterface> audio_track( |
Niels Möller | 215ba60 | 2019-01-18 13:59:45 +0100 | [diff] [blame] | 1607 | CreateAudioTrack("audio_track")); |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 1608 | rtc::scoped_refptr<VideoTrackInterface> video_track( |
Niels Möller | 215ba60 | 2019-01-18 13:59:45 +0100 | [diff] [blame] | 1609 | CreateVideoTrack("video_track")); |
Steve Anton | 2d6c76a | 2018-01-05 17:10:52 -0800 | [diff] [blame] | 1610 | auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>()); |
| 1611 | auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>()); |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 1612 | EXPECT_TRUE(DoGetStats(nullptr)); |
| 1613 | } |
| 1614 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1615 | TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) { |
Harald Alvestrand | c72af93 | 2018-01-11 17:18:19 +0100 | [diff] [blame] | 1616 | CreatePeerConnectionWithoutDtls(); |
| 1617 | rtc::scoped_refptr<AudioTrackInterface> audio_track( |
Niels Möller | 215ba60 | 2019-01-18 13:59:45 +0100 | [diff] [blame] | 1618 | CreateAudioTrack("audio_track")); |
Harald Alvestrand | c72af93 | 2018-01-11 17:18:19 +0100 | [diff] [blame] | 1619 | rtc::scoped_refptr<VideoTrackInterface> video_track( |
Niels Möller | 215ba60 | 2019-01-18 13:59:45 +0100 | [diff] [blame] | 1620 | CreateVideoTrack("video_track")); |
Harald Alvestrand | c72af93 | 2018-01-11 17:18:19 +0100 | [diff] [blame] | 1621 | auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>()); |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 1622 | ASSERT_TRUE(audio_sender.ok()); |
| 1623 | auto* audio_sender_proxy = |
| 1624 | static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>( |
| 1625 | audio_sender.value().get()); |
| 1626 | EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId()); |
| 1627 | |
Harald Alvestrand | c72af93 | 2018-01-11 17:18:19 +0100 | [diff] [blame] | 1628 | auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>()); |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 1629 | ASSERT_TRUE(video_sender.ok()); |
| 1630 | auto* video_sender_proxy = |
| 1631 | static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>( |
| 1632 | video_sender.value().get()); |
| 1633 | EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId()); |
Harald Alvestrand | c72af93 | 2018-01-11 17:18:19 +0100 | [diff] [blame] | 1634 | } |
| 1635 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1636 | // Don't run under Unified Plan since the stream API is not available. |
| 1637 | TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) { |
Harald Alvestrand | c72af93 | 2018-01-11 17:18:19 +0100 | [diff] [blame] | 1638 | CreatePeerConnectionWithoutDtls(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1639 | AddVideoStream(kStreamId1); |
Harald Alvestrand | c72af93 | 2018-01-11 17:18:19 +0100 | [diff] [blame] | 1640 | auto senders = pc_->GetSenders(); |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 1641 | ASSERT_EQ(1u, senders.size()); |
| 1642 | auto* sender_proxy = |
| 1643 | static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>( |
| 1644 | senders[0].get()); |
| 1645 | EXPECT_NE(0, sender_proxy->internal()->AttachmentId()); |
Harald Alvestrand | c72af93 | 2018-01-11 17:18:19 +0100 | [diff] [blame] | 1646 | } |
| 1647 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1648 | TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1649 | InitiateCall(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1650 | WaitAndVerifyOnAddStream(kStreamId1, 2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1651 | VerifyRemoteRtpHeaderExtensions(); |
| 1652 | } |
| 1653 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1654 | TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1655 | CreatePeerConnectionWithoutDtls(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1656 | AddVideoTrack(kVideoTracks[0], {kStreamId1}); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1657 | CreateOfferAsLocalDescription(); |
| 1658 | std::string offer; |
| 1659 | EXPECT_TRUE(pc_->local_description()->ToString(&offer)); |
| 1660 | CreatePrAnswerAndAnswerAsRemoteDescription(offer); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1661 | WaitAndVerifyOnAddStream(kStreamId1, 1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1662 | } |
| 1663 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1664 | TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1665 | CreatePeerConnectionWithoutDtls(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1666 | AddVideoTrack(kVideoTracks[0], {kStreamId1}); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1667 | |
| 1668 | CreateOfferAsRemoteDescription(); |
| 1669 | CreateAnswerAsLocalDescription(); |
| 1670 | |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1671 | WaitAndVerifyOnAddStream(kStreamId1, 1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1672 | } |
| 1673 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1674 | TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1675 | CreatePeerConnectionWithoutDtls(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1676 | AddVideoTrack(kVideoTracks[0], {kStreamId1}); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1677 | |
| 1678 | CreateOfferAsRemoteDescription(); |
| 1679 | CreatePrAnswerAsLocalDescription(); |
| 1680 | CreateAnswerAsLocalDescription(); |
| 1681 | |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1682 | WaitAndVerifyOnAddStream(kStreamId1, 1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1683 | } |
| 1684 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1685 | // Don't run under Unified Plan since the stream API is not available. |
| 1686 | TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1687 | InitiateCall(); |
| 1688 | ASSERT_EQ(1u, pc_->remote_streams()->count()); |
| 1689 | pc_->RemoveStream(pc_->local_streams()->at(0)); |
| 1690 | CreateOfferReceiveAnswer(); |
| 1691 | EXPECT_EQ(0u, pc_->remote_streams()->count()); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1692 | AddVideoStream(kStreamId1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1693 | CreateOfferReceiveAnswer(); |
| 1694 | } |
| 1695 | |
| 1696 | // Tests that after negotiating an audio only call, the respondent can perform a |
| 1697 | // renegotiation that removes the audio stream. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1698 | TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1699 | CreatePeerConnectionWithoutDtls(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1700 | AddAudioStream(kStreamId1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1701 | CreateOfferAsRemoteDescription(); |
| 1702 | CreateAnswerAsLocalDescription(); |
| 1703 | |
| 1704 | ASSERT_EQ(1u, pc_->remote_streams()->count()); |
| 1705 | pc_->RemoveStream(pc_->local_streams()->at(0)); |
| 1706 | CreateOfferReceiveAnswer(); |
| 1707 | EXPECT_EQ(0u, pc_->remote_streams()->count()); |
| 1708 | } |
| 1709 | |
| 1710 | // Test that candidates are generated and that we can parse our own candidates. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1711 | TEST_P(PeerConnectionInterfaceTest, IceCandidates) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1712 | CreatePeerConnectionWithoutDtls(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1713 | |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 1714 | EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1715 | // SetRemoteDescription takes ownership of offer. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1716 | std::unique_ptr<SessionDescriptionInterface> offer; |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1717 | AddVideoTrack(kVideoTracks[0]); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1718 | EXPECT_TRUE(DoCreateOffer(&offer, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1719 | EXPECT_TRUE(DoSetRemoteDescription(std::move(offer))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1720 | |
| 1721 | // SetLocalDescription takes ownership of answer. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1722 | std::unique_ptr<SessionDescriptionInterface> answer; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1723 | EXPECT_TRUE(DoCreateAnswer(&answer, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1724 | EXPECT_TRUE(DoSetLocalDescription(std::move(answer))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1725 | |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 1726 | EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout); |
Steve Anton | 6f25b09 | 2017-10-23 09:39:20 -0700 | [diff] [blame] | 1727 | EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1728 | |
Steve Anton | f1c6db1 | 2017-10-13 11:13:35 -0700 | [diff] [blame] | 1729 | EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1730 | } |
| 1731 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1732 | // Test that CreateOffer and CreateAnswer will fail if the track labels are |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1733 | // not unique. |
Steve Anton | 0756373 | 2018-06-26 11:13:50 -0700 | [diff] [blame] | 1734 | TEST_F(PeerConnectionInterfaceTestPlanB, CreateOfferAnswerWithInvalidStream) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1735 | CreatePeerConnectionWithoutDtls(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1736 | // Create a regular offer for the CreateAnswer test later. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1737 | std::unique_ptr<SessionDescriptionInterface> offer; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1738 | EXPECT_TRUE(DoCreateOffer(&offer, nullptr)); |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1739 | EXPECT_TRUE(offer); |
| 1740 | offer.reset(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1741 | |
| 1742 | // Create a local stream with audio&video tracks having same label. |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1743 | AddAudioTrack("track_label", {kStreamId1}); |
| 1744 | AddVideoTrack("track_label", {kStreamId1}); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1745 | |
| 1746 | // Test CreateOffer |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1747 | EXPECT_FALSE(DoCreateOffer(&offer, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1748 | |
| 1749 | // Test CreateAnswer |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1750 | std::unique_ptr<SessionDescriptionInterface> answer; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1751 | EXPECT_FALSE(DoCreateAnswer(&answer, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | // Test that we will get different SSRCs for each tracks in the offer and answer |
| 1755 | // we created. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1756 | TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1757 | CreatePeerConnectionWithoutDtls(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1758 | // Create a local stream with audio&video tracks having different labels. |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1759 | AddAudioTrack(kAudioTracks[0], {kStreamId1}); |
| 1760 | AddVideoTrack(kVideoTracks[0], {kStreamId1}); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1761 | |
| 1762 | // Test CreateOffer |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1763 | std::unique_ptr<SessionDescriptionInterface> offer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1764 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1765 | int audio_ssrc = 0; |
| 1766 | int video_ssrc = 0; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1767 | EXPECT_TRUE( |
| 1768 | GetFirstSsrc(GetFirstAudioContent(offer->description()), &audio_ssrc)); |
| 1769 | EXPECT_TRUE( |
| 1770 | GetFirstSsrc(GetFirstVideoContent(offer->description()), &video_ssrc)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1771 | EXPECT_NE(audio_ssrc, video_ssrc); |
| 1772 | |
| 1773 | // Test CreateAnswer |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 1774 | EXPECT_TRUE(DoSetRemoteDescription(std::move(offer))); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1775 | std::unique_ptr<SessionDescriptionInterface> answer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1776 | ASSERT_TRUE(DoCreateAnswer(&answer, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1777 | audio_ssrc = 0; |
| 1778 | video_ssrc = 0; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1779 | EXPECT_TRUE( |
| 1780 | GetFirstSsrc(GetFirstAudioContent(answer->description()), &audio_ssrc)); |
| 1781 | EXPECT_TRUE( |
| 1782 | GetFirstSsrc(GetFirstVideoContent(answer->description()), &video_ssrc)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1783 | EXPECT_NE(audio_ssrc, video_ssrc); |
| 1784 | } |
| 1785 | |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1786 | // Test that it's possible to call AddTrack on a MediaStream after adding |
| 1787 | // the stream to a PeerConnection. |
| 1788 | // TODO(deadbeef): Remove this test once this behavior is no longer supported. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1789 | // Don't run under Unified Plan since the stream API is not available. |
| 1790 | TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1791 | CreatePeerConnectionWithoutDtls(); |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1792 | // Create audio stream and add to PeerConnection. |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1793 | AddAudioStream(kStreamId1); |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1794 | MediaStreamInterface* stream = pc_->local_streams()->at(0); |
| 1795 | |
| 1796 | // Add video track to the audio-only stream. |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1797 | rtc::scoped_refptr<VideoTrackInterface> video_track( |
Niels Möller | 215ba60 | 2019-01-18 13:59:45 +0100 | [diff] [blame] | 1798 | CreateVideoTrack("video_label")); |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1799 | stream->AddTrack(video_track.get()); |
| 1800 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1801 | std::unique_ptr<SessionDescriptionInterface> offer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1802 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1803 | |
| 1804 | const cricket::MediaContentDescription* video_desc = |
| 1805 | cricket::GetFirstVideoContentDescription(offer->description()); |
| 1806 | EXPECT_TRUE(video_desc != nullptr); |
| 1807 | } |
| 1808 | |
| 1809 | // Test that it's possible to call RemoveTrack on a MediaStream after adding |
| 1810 | // the stream to a PeerConnection. |
| 1811 | // TODO(deadbeef): Remove this test once this behavior is no longer supported. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1812 | // Don't run under Unified Plan since the stream API is not available. |
| 1813 | TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1814 | CreatePeerConnectionWithoutDtls(); |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1815 | // Create audio/video stream and add to PeerConnection. |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1816 | AddAudioVideoStream(kStreamId1, "audio_label", "video_label"); |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1817 | MediaStreamInterface* stream = pc_->local_streams()->at(0); |
| 1818 | |
| 1819 | // Remove the video track. |
| 1820 | stream->RemoveTrack(stream->GetVideoTracks()[0]); |
| 1821 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1822 | std::unique_ptr<SessionDescriptionInterface> offer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1823 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1824 | |
| 1825 | const cricket::MediaContentDescription* video_desc = |
| 1826 | cricket::GetFirstVideoContentDescription(offer->description()); |
| 1827 | EXPECT_TRUE(video_desc == nullptr); |
| 1828 | } |
| 1829 | |
deadbeef | bd7d8f7 | 2015-12-18 16:58:44 -0800 | [diff] [blame] | 1830 | // Test creating a sender with a stream ID, and ensure the ID is populated |
| 1831 | // in the offer. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1832 | // Don't run under Unified Plan since the stream API is not available. |
| 1833 | TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 1834 | CreatePeerConnectionWithoutDtls(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1835 | pc_->CreateSender("video", kStreamId1); |
deadbeef | bd7d8f7 | 2015-12-18 16:58:44 -0800 | [diff] [blame] | 1836 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1837 | std::unique_ptr<SessionDescriptionInterface> offer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 1838 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
deadbeef | bd7d8f7 | 2015-12-18 16:58:44 -0800 | [diff] [blame] | 1839 | |
| 1840 | const cricket::MediaContentDescription* video_desc = |
| 1841 | cricket::GetFirstVideoContentDescription(offer->description()); |
| 1842 | ASSERT_TRUE(video_desc != nullptr); |
| 1843 | ASSERT_EQ(1u, video_desc->streams().size()); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1844 | EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id()); |
deadbeef | bd7d8f7 | 2015-12-18 16:58:44 -0800 | [diff] [blame] | 1845 | } |
| 1846 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1847 | // Test that we can specify a certain track that we want statistics about. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1848 | TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1849 | InitiateCall(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1850 | ASSERT_LT(0u, pc_->GetSenders().size()); |
| 1851 | ASSERT_LT(0u, pc_->GetReceivers().size()); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1852 | rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio = |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1853 | pc_->GetReceivers()[0]->track(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1854 | EXPECT_TRUE(DoGetStats(remote_audio)); |
| 1855 | |
| 1856 | // Remove the stream. Since we are sending to our selves the local |
| 1857 | // and the remote stream is the same. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1858 | pc_->RemoveTrack(pc_->GetSenders()[0]); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1859 | // Do a re-negotiation. |
| 1860 | CreateOfferReceiveAnswer(); |
| 1861 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1862 | // Test that we still can get statistics for the old track. Even if it is not |
| 1863 | // sent any longer. |
| 1864 | EXPECT_TRUE(DoGetStats(remote_audio)); |
| 1865 | } |
| 1866 | |
| 1867 | // Test that we can get stats on a video track. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1868 | TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1869 | InitiateCall(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1870 | auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO); |
| 1871 | ASSERT_TRUE(video_receiver); |
| 1872 | EXPECT_TRUE(DoGetStats(video_receiver->track())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1873 | } |
| 1874 | |
| 1875 | // Test that we don't get statistics for an invalid track. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1876 | TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1877 | InitiateCall(); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1878 | rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1879 | pc_factory_->CreateAudioTrack("unknown track", NULL)); |
| 1880 | EXPECT_FALSE(DoGetStats(unknown_audio_track)); |
| 1881 | } |
| 1882 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1883 | TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) { |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 1884 | CreatePeerConnectionWithoutDtls(); |
| 1885 | EXPECT_TRUE(DoGetRTCStats()); |
| 1886 | // Clearing stats cache is needed now, but should be temporary. |
| 1887 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693 |
| 1888 | pc_->ClearStatsCache(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 1889 | AddAudioTrack(kAudioTracks[0], {kStreamId1}); |
| 1890 | AddVideoTrack(kVideoTracks[0], {kStreamId1}); |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 1891 | EXPECT_TRUE(DoGetRTCStats()); |
| 1892 | pc_->ClearStatsCache(); |
| 1893 | CreateOfferReceiveAnswer(); |
| 1894 | EXPECT_TRUE(DoGetRTCStats()); |
| 1895 | } |
| 1896 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1897 | // This test setup two RTP data channels in loop back. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1898 | TEST_P(PeerConnectionInterfaceTest, TestDataChannel) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1899 | RTCConfiguration config; |
| 1900 | config.enable_rtp_data_channel = true; |
| 1901 | config.enable_dtls_srtp = false; |
| 1902 | CreatePeerConnection(config); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1903 | rtc::scoped_refptr<DataChannelInterface> data1 = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1904 | pc_->CreateDataChannel("test1", NULL); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1905 | rtc::scoped_refptr<DataChannelInterface> data2 = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1906 | pc_->CreateDataChannel("test2", NULL); |
| 1907 | ASSERT_TRUE(data1 != NULL); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1908 | std::unique_ptr<MockDataChannelObserver> observer1( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1909 | new MockDataChannelObserver(data1)); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1910 | std::unique_ptr<MockDataChannelObserver> observer2( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1911 | new MockDataChannelObserver(data2)); |
| 1912 | |
| 1913 | EXPECT_EQ(DataChannelInterface::kConnecting, data1->state()); |
| 1914 | EXPECT_EQ(DataChannelInterface::kConnecting, data2->state()); |
| 1915 | std::string data_to_send1 = "testing testing"; |
| 1916 | std::string data_to_send2 = "testing something else"; |
| 1917 | EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1))); |
| 1918 | |
| 1919 | CreateOfferReceiveAnswer(); |
| 1920 | EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout); |
| 1921 | EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout); |
| 1922 | |
| 1923 | EXPECT_EQ(DataChannelInterface::kOpen, data1->state()); |
| 1924 | EXPECT_EQ(DataChannelInterface::kOpen, data2->state()); |
| 1925 | EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1))); |
| 1926 | EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2))); |
| 1927 | |
| 1928 | EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout); |
| 1929 | EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout); |
| 1930 | |
| 1931 | data1->Close(); |
| 1932 | EXPECT_EQ(DataChannelInterface::kClosing, data1->state()); |
| 1933 | CreateOfferReceiveAnswer(); |
| 1934 | EXPECT_FALSE(observer1->IsOpen()); |
| 1935 | EXPECT_EQ(DataChannelInterface::kClosed, data1->state()); |
| 1936 | EXPECT_TRUE(observer2->IsOpen()); |
| 1937 | |
| 1938 | data_to_send2 = "testing something else again"; |
| 1939 | EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2))); |
| 1940 | |
| 1941 | EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout); |
| 1942 | } |
| 1943 | |
| 1944 | // This test verifies that sendnig binary data over RTP data channels should |
| 1945 | // fail. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1946 | TEST_P(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1947 | RTCConfiguration config; |
| 1948 | config.enable_rtp_data_channel = true; |
| 1949 | config.enable_dtls_srtp = false; |
| 1950 | CreatePeerConnection(config); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1951 | rtc::scoped_refptr<DataChannelInterface> data1 = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1952 | pc_->CreateDataChannel("test1", NULL); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1953 | rtc::scoped_refptr<DataChannelInterface> data2 = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1954 | pc_->CreateDataChannel("test2", NULL); |
| 1955 | ASSERT_TRUE(data1 != NULL); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1956 | std::unique_ptr<MockDataChannelObserver> observer1( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1957 | new MockDataChannelObserver(data1)); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1958 | std::unique_ptr<MockDataChannelObserver> observer2( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1959 | new MockDataChannelObserver(data2)); |
| 1960 | |
| 1961 | EXPECT_EQ(DataChannelInterface::kConnecting, data1->state()); |
| 1962 | EXPECT_EQ(DataChannelInterface::kConnecting, data2->state()); |
| 1963 | |
| 1964 | CreateOfferReceiveAnswer(); |
| 1965 | EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout); |
| 1966 | EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout); |
| 1967 | |
| 1968 | EXPECT_EQ(DataChannelInterface::kOpen, data1->state()); |
| 1969 | EXPECT_EQ(DataChannelInterface::kOpen, data2->state()); |
| 1970 | |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 1971 | rtc::CopyOnWriteBuffer buffer("test", 4); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1972 | EXPECT_FALSE(data1->Send(DataBuffer(buffer, true))); |
| 1973 | } |
| 1974 | |
| 1975 | // This test setup a RTP data channels in loop back and test that a channel is |
| 1976 | // opened even if the remote end answer with a zero SSRC. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1977 | TEST_P(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 1978 | RTCConfiguration config; |
| 1979 | config.enable_rtp_data_channel = true; |
| 1980 | config.enable_dtls_srtp = false; |
| 1981 | CreatePeerConnection(config); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1982 | rtc::scoped_refptr<DataChannelInterface> data1 = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1983 | pc_->CreateDataChannel("test1", NULL); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1984 | std::unique_ptr<MockDataChannelObserver> observer1( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1985 | new MockDataChannelObserver(data1)); |
| 1986 | |
| 1987 | CreateOfferReceiveAnswerWithoutSsrc(); |
| 1988 | |
| 1989 | EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout); |
| 1990 | |
| 1991 | data1->Close(); |
| 1992 | EXPECT_EQ(DataChannelInterface::kClosing, data1->state()); |
| 1993 | CreateOfferReceiveAnswerWithoutSsrc(); |
| 1994 | EXPECT_EQ(DataChannelInterface::kClosed, data1->state()); |
| 1995 | EXPECT_FALSE(observer1->IsOpen()); |
| 1996 | } |
| 1997 | |
| 1998 | // This test that if a data channel is added in an answer a receive only channel |
| 1999 | // channel is created. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2000 | TEST_P(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2001 | RTCConfiguration config; |
| 2002 | config.enable_rtp_data_channel = true; |
| 2003 | config.enable_dtls_srtp = false; |
| 2004 | |
| 2005 | CreatePeerConnection(config); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2006 | |
| 2007 | std::string offer_label = "offer_channel"; |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2008 | rtc::scoped_refptr<DataChannelInterface> offer_channel = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2009 | pc_->CreateDataChannel(offer_label, NULL); |
| 2010 | |
| 2011 | CreateOfferAsLocalDescription(); |
| 2012 | |
| 2013 | // Replace the data channel label in the offer and apply it as an answer. |
| 2014 | std::string receive_label = "answer_channel"; |
| 2015 | std::string sdp; |
| 2016 | EXPECT_TRUE(pc_->local_description()->ToString(&sdp)); |
Steve Anton | 1c9c9fc | 2019-02-14 15:13:09 -0800 | [diff] [blame] | 2017 | absl::StrReplaceAll({{offer_label, receive_label}}, &sdp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2018 | CreateAnswerAsRemoteDescription(sdp); |
| 2019 | |
| 2020 | // Verify that a new incoming data channel has been created and that |
| 2021 | // it is open but can't we written to. |
| 2022 | ASSERT_TRUE(observer_.last_datachannel_ != NULL); |
| 2023 | DataChannelInterface* received_channel = observer_.last_datachannel_; |
| 2024 | EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state()); |
| 2025 | EXPECT_EQ(receive_label, received_channel->label()); |
| 2026 | EXPECT_FALSE(received_channel->Send(DataBuffer("something"))); |
| 2027 | |
| 2028 | // Verify that the channel we initially offered has been rejected. |
| 2029 | EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state()); |
| 2030 | |
| 2031 | // Do another offer / answer exchange and verify that the data channel is |
| 2032 | // opened. |
| 2033 | CreateOfferReceiveAnswer(); |
| 2034 | EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(), |
| 2035 | kTimeout); |
| 2036 | } |
| 2037 | |
| 2038 | // This test that no data channel is returned if a reliable channel is |
| 2039 | // requested. |
| 2040 | // TODO(perkj): Remove this test once reliable channels are implemented. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2041 | TEST_P(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2042 | RTCConfiguration rtc_config; |
| 2043 | rtc_config.enable_rtp_data_channel = true; |
| 2044 | CreatePeerConnection(rtc_config); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2045 | |
| 2046 | std::string label = "test"; |
| 2047 | webrtc::DataChannelInit config; |
| 2048 | config.reliable = true; |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2049 | rtc::scoped_refptr<DataChannelInterface> channel = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2050 | pc_->CreateDataChannel(label, &config); |
| 2051 | EXPECT_TRUE(channel == NULL); |
| 2052 | } |
| 2053 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2054 | // Verifies that duplicated label is not allowed for RTP data channel. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2055 | TEST_P(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2056 | RTCConfiguration config; |
| 2057 | config.enable_rtp_data_channel = true; |
| 2058 | CreatePeerConnection(config); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2059 | |
| 2060 | std::string label = "test"; |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2061 | rtc::scoped_refptr<DataChannelInterface> channel = |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2062 | pc_->CreateDataChannel(label, nullptr); |
| 2063 | EXPECT_NE(channel, nullptr); |
| 2064 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2065 | rtc::scoped_refptr<DataChannelInterface> dup_channel = |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2066 | pc_->CreateDataChannel(label, nullptr); |
| 2067 | EXPECT_EQ(dup_channel, nullptr); |
| 2068 | } |
| 2069 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2070 | // This tests that a SCTP data channel is returned using different |
| 2071 | // DataChannelInit configurations. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2072 | TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2073 | RTCConfiguration rtc_config; |
| 2074 | rtc_config.enable_dtls_srtp = true; |
| 2075 | CreatePeerConnection(rtc_config); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2076 | |
| 2077 | webrtc::DataChannelInit config; |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2078 | rtc::scoped_refptr<DataChannelInterface> channel = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2079 | pc_->CreateDataChannel("1", &config); |
| 2080 | EXPECT_TRUE(channel != NULL); |
| 2081 | EXPECT_TRUE(channel->reliable()); |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 2082 | EXPECT_TRUE(observer_.renegotiation_needed_); |
| 2083 | observer_.renegotiation_needed_ = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2084 | |
| 2085 | config.ordered = false; |
| 2086 | channel = pc_->CreateDataChannel("2", &config); |
| 2087 | EXPECT_TRUE(channel != NULL); |
| 2088 | EXPECT_TRUE(channel->reliable()); |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 2089 | EXPECT_FALSE(observer_.renegotiation_needed_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2090 | |
| 2091 | config.ordered = true; |
| 2092 | config.maxRetransmits = 0; |
| 2093 | channel = pc_->CreateDataChannel("3", &config); |
| 2094 | EXPECT_TRUE(channel != NULL); |
| 2095 | EXPECT_FALSE(channel->reliable()); |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 2096 | EXPECT_FALSE(observer_.renegotiation_needed_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2097 | |
Harald Alvestrand | f3736ed | 2019-04-08 13:09:30 +0200 | [diff] [blame] | 2098 | config.maxRetransmits = absl::nullopt; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2099 | config.maxRetransmitTime = 0; |
| 2100 | channel = pc_->CreateDataChannel("4", &config); |
| 2101 | EXPECT_TRUE(channel != NULL); |
| 2102 | EXPECT_FALSE(channel->reliable()); |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 2103 | EXPECT_FALSE(observer_.renegotiation_needed_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2104 | } |
| 2105 | |
Harald Alvestrand | f3736ed | 2019-04-08 13:09:30 +0200 | [diff] [blame] | 2106 | // For backwards compatibility, we want people who "unset" maxRetransmits |
| 2107 | // and maxRetransmitTime by setting them to -1 to get what they want. |
| 2108 | TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannelWithMinusOne) { |
| 2109 | RTCConfiguration rtc_config; |
| 2110 | rtc_config.enable_dtls_srtp = true; |
| 2111 | CreatePeerConnection(rtc_config); |
| 2112 | |
| 2113 | webrtc::DataChannelInit config; |
| 2114 | config.maxRetransmitTime = -1; |
| 2115 | config.maxRetransmits = -1; |
| 2116 | rtc::scoped_refptr<DataChannelInterface> channel = |
| 2117 | pc_->CreateDataChannel("1", &config); |
| 2118 | EXPECT_TRUE(channel != NULL); |
| 2119 | } |
| 2120 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2121 | // This tests that no data channel is returned if both maxRetransmits and |
| 2122 | // maxRetransmitTime are set for SCTP data channels. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2123 | TEST_P(PeerConnectionInterfaceTest, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2124 | CreateSctpDataChannelShouldFailForInvalidConfig) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2125 | RTCConfiguration rtc_config; |
| 2126 | rtc_config.enable_dtls_srtp = true; |
| 2127 | CreatePeerConnection(rtc_config); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2128 | |
| 2129 | std::string label = "test"; |
| 2130 | webrtc::DataChannelInit config; |
| 2131 | config.maxRetransmits = 0; |
| 2132 | config.maxRetransmitTime = 0; |
| 2133 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2134 | rtc::scoped_refptr<DataChannelInterface> channel = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2135 | pc_->CreateDataChannel(label, &config); |
| 2136 | EXPECT_TRUE(channel == NULL); |
| 2137 | } |
| 2138 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2139 | // The test verifies that creating a SCTP data channel with an id already in use |
| 2140 | // or out of range should fail. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2141 | TEST_P(PeerConnectionInterfaceTest, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2142 | CreateSctpDataChannelWithInvalidIdShouldFail) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2143 | RTCConfiguration rtc_config; |
| 2144 | rtc_config.enable_dtls_srtp = true; |
| 2145 | CreatePeerConnection(rtc_config); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2146 | |
| 2147 | webrtc::DataChannelInit config; |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2148 | rtc::scoped_refptr<DataChannelInterface> channel; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2149 | |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 2150 | config.id = 1; |
Harald Alvestrand | 5c4d2ee | 2019-04-01 12:58:15 +0200 | [diff] [blame] | 2151 | config.negotiated = true; |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 2152 | channel = pc_->CreateDataChannel("1", &config); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2153 | EXPECT_TRUE(channel != NULL); |
| 2154 | EXPECT_EQ(1, channel->id()); |
| 2155 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2156 | channel = pc_->CreateDataChannel("x", &config); |
| 2157 | EXPECT_TRUE(channel == NULL); |
| 2158 | |
| 2159 | config.id = cricket::kMaxSctpSid; |
Harald Alvestrand | 5c4d2ee | 2019-04-01 12:58:15 +0200 | [diff] [blame] | 2160 | config.negotiated = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2161 | channel = pc_->CreateDataChannel("max", &config); |
| 2162 | EXPECT_TRUE(channel != NULL); |
| 2163 | EXPECT_EQ(config.id, channel->id()); |
| 2164 | |
| 2165 | config.id = cricket::kMaxSctpSid + 1; |
Harald Alvestrand | 5c4d2ee | 2019-04-01 12:58:15 +0200 | [diff] [blame] | 2166 | config.negotiated = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2167 | channel = pc_->CreateDataChannel("x", &config); |
| 2168 | EXPECT_TRUE(channel == NULL); |
| 2169 | } |
| 2170 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2171 | // Verifies that duplicated label is allowed for SCTP data channel. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2172 | TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2173 | RTCConfiguration rtc_config; |
| 2174 | rtc_config.enable_dtls_srtp = true; |
| 2175 | CreatePeerConnection(rtc_config); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2176 | |
| 2177 | std::string label = "test"; |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2178 | rtc::scoped_refptr<DataChannelInterface> channel = |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2179 | pc_->CreateDataChannel(label, nullptr); |
| 2180 | EXPECT_NE(channel, nullptr); |
| 2181 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2182 | rtc::scoped_refptr<DataChannelInterface> dup_channel = |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2183 | pc_->CreateDataChannel(label, nullptr); |
| 2184 | EXPECT_NE(dup_channel, nullptr); |
| 2185 | } |
| 2186 | |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 2187 | // This test verifies that OnRenegotiationNeeded is fired for every new RTP |
| 2188 | // DataChannel. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2189 | TEST_P(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2190 | RTCConfiguration rtc_config; |
| 2191 | rtc_config.enable_rtp_data_channel = true; |
| 2192 | rtc_config.enable_dtls_srtp = false; |
| 2193 | CreatePeerConnection(rtc_config); |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 2194 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2195 | rtc::scoped_refptr<DataChannelInterface> dc1 = |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 2196 | pc_->CreateDataChannel("test1", NULL); |
| 2197 | EXPECT_TRUE(observer_.renegotiation_needed_); |
| 2198 | observer_.renegotiation_needed_ = false; |
| 2199 | |
Guido Urdaneta | 70c2db1 | 2019-04-16 12:24:14 +0200 | [diff] [blame] | 2200 | CreateOfferReceiveAnswer(); |
| 2201 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2202 | rtc::scoped_refptr<DataChannelInterface> dc2 = |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 2203 | pc_->CreateDataChannel("test2", NULL); |
Guido Urdaneta | 70c2db1 | 2019-04-16 12:24:14 +0200 | [diff] [blame] | 2204 | EXPECT_EQ(observer_.renegotiation_needed_, |
| 2205 | GetParam() == SdpSemantics::kPlanB); |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 2206 | } |
| 2207 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2208 | // This test that a data channel closes when a PeerConnection is deleted/closed. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2209 | TEST_P(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2210 | RTCConfiguration rtc_config; |
| 2211 | rtc_config.enable_rtp_data_channel = true; |
| 2212 | rtc_config.enable_dtls_srtp = false; |
| 2213 | CreatePeerConnection(rtc_config); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2214 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2215 | rtc::scoped_refptr<DataChannelInterface> data1 = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2216 | pc_->CreateDataChannel("test1", NULL); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2217 | rtc::scoped_refptr<DataChannelInterface> data2 = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2218 | pc_->CreateDataChannel("test2", NULL); |
| 2219 | ASSERT_TRUE(data1 != NULL); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2220 | std::unique_ptr<MockDataChannelObserver> observer1( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2221 | new MockDataChannelObserver(data1)); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2222 | std::unique_ptr<MockDataChannelObserver> observer2( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2223 | new MockDataChannelObserver(data2)); |
| 2224 | |
| 2225 | CreateOfferReceiveAnswer(); |
| 2226 | EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout); |
| 2227 | EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout); |
| 2228 | |
| 2229 | ReleasePeerConnection(); |
| 2230 | EXPECT_EQ(DataChannelInterface::kClosed, data1->state()); |
| 2231 | EXPECT_EQ(DataChannelInterface::kClosed, data2->state()); |
| 2232 | } |
| 2233 | |
Zhi Huang | 644fde4 | 2018-04-02 19:16:26 -0700 | [diff] [blame] | 2234 | // This tests that RTP data channels can be rejected in an answer. |
| 2235 | TEST_P(PeerConnectionInterfaceTest, TestRejectRtpDataChannelInAnswer) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2236 | RTCConfiguration rtc_config; |
| 2237 | rtc_config.enable_rtp_data_channel = true; |
| 2238 | rtc_config.enable_dtls_srtp = false; |
| 2239 | CreatePeerConnection(rtc_config); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2240 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2241 | rtc::scoped_refptr<DataChannelInterface> offer_channel( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2242 | pc_->CreateDataChannel("offer_channel", NULL)); |
| 2243 | |
| 2244 | CreateOfferAsLocalDescription(); |
| 2245 | |
| 2246 | // Create an answer where the m-line for data channels are rejected. |
| 2247 | std::string sdp; |
| 2248 | EXPECT_TRUE(pc_->local_description()->ToString(&sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2249 | std::unique_ptr<SessionDescriptionInterface> answer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 2250 | webrtc::CreateSessionDescription(SdpType::kAnswer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2251 | ASSERT_TRUE(answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2252 | cricket::ContentInfo* data_info = |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2253 | cricket::GetFirstDataContent(answer->description()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2254 | data_info->rejected = true; |
| 2255 | |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2256 | DoSetRemoteDescription(std::move(answer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2257 | EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state()); |
| 2258 | } |
| 2259 | |
Zhi Huang | 644fde4 | 2018-04-02 19:16:26 -0700 | [diff] [blame] | 2260 | #ifdef HAVE_SCTP |
| 2261 | // This tests that SCTP data channels can be rejected in an answer. |
| 2262 | TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer) |
| 2263 | #else |
| 2264 | TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer) |
| 2265 | #endif |
| 2266 | { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2267 | RTCConfiguration rtc_config; |
| 2268 | CreatePeerConnection(rtc_config); |
Zhi Huang | 644fde4 | 2018-04-02 19:16:26 -0700 | [diff] [blame] | 2269 | |
| 2270 | rtc::scoped_refptr<DataChannelInterface> offer_channel( |
| 2271 | pc_->CreateDataChannel("offer_channel", NULL)); |
| 2272 | |
| 2273 | CreateOfferAsLocalDescription(); |
| 2274 | |
| 2275 | // Create an answer where the m-line for data channels are rejected. |
| 2276 | std::string sdp; |
| 2277 | EXPECT_TRUE(pc_->local_description()->ToString(&sdp)); |
| 2278 | std::unique_ptr<SessionDescriptionInterface> answer( |
| 2279 | webrtc::CreateSessionDescription(SdpType::kAnswer, sdp)); |
| 2280 | ASSERT_TRUE(answer); |
| 2281 | cricket::ContentInfo* data_info = |
| 2282 | cricket::GetFirstDataContent(answer->description()); |
| 2283 | data_info->rejected = true; |
| 2284 | |
| 2285 | DoSetRemoteDescription(std::move(answer)); |
| 2286 | EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state()); |
| 2287 | } |
| 2288 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2289 | // Test that we can create a session description from an SDP string from |
| 2290 | // FireFox, use it as a remote session description, generate an answer and use |
| 2291 | // the answer as a local description. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2292 | TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2293 | RTCConfiguration rtc_config; |
| 2294 | rtc_config.enable_dtls_srtp = true; |
| 2295 | CreatePeerConnection(rtc_config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2296 | AddAudioTrack("audio_label"); |
| 2297 | AddVideoTrack("video_label"); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2298 | std::unique_ptr<SessionDescriptionInterface> desc( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 2299 | webrtc::CreateSessionDescription(SdpType::kOffer, |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2300 | webrtc::kFireFoxSdpOffer, nullptr)); |
| 2301 | EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2302 | CreateAnswerAsLocalDescription(); |
| 2303 | ASSERT_TRUE(pc_->local_description() != NULL); |
| 2304 | ASSERT_TRUE(pc_->remote_description() != NULL); |
| 2305 | |
| 2306 | const cricket::ContentInfo* content = |
| 2307 | cricket::GetFirstAudioContent(pc_->local_description()->description()); |
| 2308 | ASSERT_TRUE(content != NULL); |
| 2309 | EXPECT_FALSE(content->rejected); |
| 2310 | |
| 2311 | content = |
| 2312 | cricket::GetFirstVideoContent(pc_->local_description()->description()); |
| 2313 | ASSERT_TRUE(content != NULL); |
| 2314 | EXPECT_FALSE(content->rejected); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 2315 | #ifdef HAVE_SCTP |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2316 | content = |
| 2317 | cricket::GetFirstDataContent(pc_->local_description()->description()); |
| 2318 | ASSERT_TRUE(content != NULL); |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 2319 | EXPECT_FALSE(content->rejected); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 2320 | #endif |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2321 | } |
| 2322 | |
zhihuang | b19012e | 2017-09-19 13:47:59 -0700 | [diff] [blame] | 2323 | // Test that fallback from DTLS to SDES is not supported. |
| 2324 | // The fallback was previously supported but was removed to simplify the code |
| 2325 | // and because it's non-standard. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2326 | TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2327 | RTCConfiguration rtc_config; |
| 2328 | rtc_config.enable_dtls_srtp = true; |
| 2329 | CreatePeerConnection(rtc_config); |
deadbeef | 8662f94 | 2017-01-20 21:20:51 -0800 | [diff] [blame] | 2330 | // Wait for fake certificate to be generated. Previously, this is what caused |
| 2331 | // the "a=crypto" lines to be rejected. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2332 | AddAudioTrack("audio_label"); |
| 2333 | AddVideoTrack("video_label"); |
deadbeef | 8662f94 | 2017-01-20 21:20:51 -0800 | [diff] [blame] | 2334 | ASSERT_NE(nullptr, fake_certificate_generator_); |
| 2335 | EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(), |
| 2336 | kTimeout); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2337 | std::unique_ptr<SessionDescriptionInterface> desc( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 2338 | webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp, |
| 2339 | nullptr)); |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 2340 | EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false)); |
deadbeef | 8662f94 | 2017-01-20 21:20:51 -0800 | [diff] [blame] | 2341 | } |
| 2342 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2343 | // Test that we can create an audio only offer and receive an answer with a |
| 2344 | // limited set of audio codecs and receive an updated offer with more audio |
| 2345 | // codecs, where the added codecs are not supported. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2346 | TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2347 | CreatePeerConnectionWithoutDtls(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2348 | AddAudioTrack("audio_label"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2349 | CreateOfferAsLocalDescription(); |
| 2350 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2351 | const char* answer_sdp = |
| 2352 | (sdp_semantics_ == SdpSemantics::kPlanB ? webrtc::kAudioSdpPlanB |
| 2353 | : webrtc::kAudioSdpUnifiedPlan); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2354 | std::unique_ptr<SessionDescriptionInterface> answer( |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2355 | webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2356 | EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2357 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2358 | const char* reoffer_sdp = |
| 2359 | (sdp_semantics_ == SdpSemantics::kPlanB |
| 2360 | ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB |
| 2361 | : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2362 | std::unique_ptr<SessionDescriptionInterface> updated_offer( |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2363 | webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2364 | EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2365 | CreateAnswerAsLocalDescription(); |
| 2366 | } |
| 2367 | |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2368 | // Test that if we're receiving (but not sending) a track, subsequent offers |
| 2369 | // will have m-lines with a=recvonly. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2370 | TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2371 | RTCConfiguration rtc_config; |
| 2372 | rtc_config.enable_dtls_srtp = true; |
| 2373 | CreatePeerConnection(rtc_config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2374 | CreateAndSetRemoteOffer(GetSdpStringWithStream1()); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2375 | CreateAnswerAsLocalDescription(); |
| 2376 | |
| 2377 | // At this point we should be receiving stream 1, but not sending anything. |
| 2378 | // A new offer should be recvonly. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2379 | std::unique_ptr<SessionDescriptionInterface> offer; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2380 | DoCreateOffer(&offer, nullptr); |
| 2381 | |
| 2382 | const cricket::ContentInfo* video_content = |
| 2383 | cricket::GetFirstVideoContent(offer->description()); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2384 | ASSERT_EQ(RtpTransceiverDirection::kRecvOnly, |
| 2385 | video_content->media_description()->direction()); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2386 | |
| 2387 | const cricket::ContentInfo* audio_content = |
| 2388 | cricket::GetFirstAudioContent(offer->description()); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2389 | ASSERT_EQ(RtpTransceiverDirection::kRecvOnly, |
| 2390 | audio_content->media_description()->direction()); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2391 | } |
| 2392 | |
| 2393 | // Test that if we're receiving (but not sending) a track, and the |
| 2394 | // offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to |
| 2395 | // false, the generated m-lines will be a=inactive. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2396 | TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2397 | RTCConfiguration rtc_config; |
| 2398 | rtc_config.enable_dtls_srtp = true; |
| 2399 | CreatePeerConnection(rtc_config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2400 | CreateAndSetRemoteOffer(GetSdpStringWithStream1()); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2401 | CreateAnswerAsLocalDescription(); |
| 2402 | |
| 2403 | // At this point we should be receiving stream 1, but not sending anything. |
| 2404 | // A new offer would be recvonly, but we'll set the "no receive" constraints |
| 2405 | // to make it inactive. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2406 | std::unique_ptr<SessionDescriptionInterface> offer; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2407 | RTCOfferAnswerOptions options; |
| 2408 | options.offer_to_receive_audio = 0; |
| 2409 | options.offer_to_receive_video = 0; |
| 2410 | DoCreateOffer(&offer, &options); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2411 | |
| 2412 | const cricket::ContentInfo* video_content = |
| 2413 | cricket::GetFirstVideoContent(offer->description()); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2414 | ASSERT_EQ(RtpTransceiverDirection::kInactive, |
| 2415 | video_content->media_description()->direction()); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2416 | |
| 2417 | const cricket::ContentInfo* audio_content = |
| 2418 | cricket::GetFirstAudioContent(offer->description()); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2419 | ASSERT_EQ(RtpTransceiverDirection::kInactive, |
| 2420 | audio_content->media_description()->direction()); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2421 | } |
| 2422 | |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 2423 | // Test that we can use SetConfiguration to change the ICE servers of the |
| 2424 | // PortAllocator. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2425 | TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) { |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 2426 | CreatePeerConnection(); |
| 2427 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2428 | PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration(); |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 2429 | PeerConnectionInterface::IceServer server; |
| 2430 | server.uri = "stun:test_hostname"; |
| 2431 | config.servers.push_back(server); |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2432 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 2433 | |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 2434 | EXPECT_EQ(1u, port_allocator_->stun_servers().size()); |
| 2435 | EXPECT_EQ("test_hostname", |
| 2436 | port_allocator_->stun_servers().begin()->hostname()); |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 2437 | } |
| 2438 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2439 | TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) { |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2440 | CreatePeerConnection(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2441 | PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration(); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2442 | config.type = PeerConnectionInterface::kRelay; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2443 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2444 | EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter()); |
| 2445 | } |
| 2446 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2447 | TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2448 | PeerConnectionInterface::RTCConfiguration config; |
| 2449 | config.prune_turn_ports = false; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2450 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2451 | config = pc_->GetConfiguration(); |
Honghai Zhang | f8998cf | 2019-10-14 11:27:50 -0700 | [diff] [blame] | 2452 | EXPECT_EQ(webrtc::NO_PRUNE, port_allocator_->turn_port_prune_policy()); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2453 | |
| 2454 | config.prune_turn_ports = true; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2455 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
Honghai Zhang | f8998cf | 2019-10-14 11:27:50 -0700 | [diff] [blame] | 2456 | EXPECT_EQ(webrtc::PRUNE_BASED_ON_PRIORITY, |
| 2457 | port_allocator_->turn_port_prune_policy()); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2458 | } |
| 2459 | |
skvlad | d1f5fda | 2017-02-03 16:54:05 -0800 | [diff] [blame] | 2460 | // Test that the ice check interval can be changed. This does not verify that |
| 2461 | // the setting makes it all the way to P2PTransportChannel, as that would |
| 2462 | // require a very complex set of mocks. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2463 | TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) { |
skvlad | d1f5fda | 2017-02-03 16:54:05 -0800 | [diff] [blame] | 2464 | PeerConnectionInterface::RTCConfiguration config; |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 2465 | config.ice_check_min_interval = absl::nullopt; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2466 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2467 | config = pc_->GetConfiguration(); |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 2468 | config.ice_check_min_interval = 100; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2469 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
Qingsi Wang | bca1485 | 2019-06-26 14:56:02 -0700 | [diff] [blame] | 2470 | config = pc_->GetConfiguration(); |
| 2471 | EXPECT_EQ(config.ice_check_min_interval, 100); |
| 2472 | } |
| 2473 | |
| 2474 | TEST_P(PeerConnectionInterfaceTest, |
| 2475 | SetConfigurationChangesSurfaceIceCandidatesOnIceTransportTypeChanged) { |
| 2476 | PeerConnectionInterface::RTCConfiguration config; |
| 2477 | config.surface_ice_candidates_on_ice_transport_type_changed = false; |
| 2478 | CreatePeerConnection(config); |
| 2479 | config = pc_->GetConfiguration(); |
| 2480 | EXPECT_FALSE(config.surface_ice_candidates_on_ice_transport_type_changed); |
| 2481 | |
| 2482 | config.surface_ice_candidates_on_ice_transport_type_changed = true; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2483 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
Qingsi Wang | bca1485 | 2019-06-26 14:56:02 -0700 | [diff] [blame] | 2484 | config = pc_->GetConfiguration(); |
| 2485 | EXPECT_TRUE(config.surface_ice_candidates_on_ice_transport_type_changed); |
skvlad | d1f5fda | 2017-02-03 16:54:05 -0800 | [diff] [blame] | 2486 | } |
| 2487 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2488 | // Test that when SetConfiguration changes both the pool size and other |
| 2489 | // attributes, the pooled session is created with the updated attributes. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2490 | TEST_P(PeerConnectionInterfaceTest, |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2491 | SetConfigurationCreatesPooledSessionCorrectly) { |
| 2492 | CreatePeerConnection(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2493 | PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration(); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2494 | config.ice_candidate_pool_size = 1; |
| 2495 | PeerConnectionInterface::IceServer server; |
| 2496 | server.uri = kStunAddressOnly; |
| 2497 | config.servers.push_back(server); |
| 2498 | config.type = PeerConnectionInterface::kRelay; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2499 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2500 | |
| 2501 | const cricket::FakePortAllocatorSession* session = |
| 2502 | static_cast<const cricket::FakePortAllocatorSession*>( |
| 2503 | port_allocator_->GetPooledSession()); |
| 2504 | ASSERT_NE(nullptr, session); |
| 2505 | EXPECT_EQ(1UL, session->stun_servers().size()); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2506 | } |
| 2507 | |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2508 | // Test that after SetLocalDescription, changing the pool size is not allowed, |
| 2509 | // and an invalid modification error is returned. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2510 | TEST_P(PeerConnectionInterfaceTest, |
deadbeef | 6de92f9 | 2016-12-12 18:49:32 -0800 | [diff] [blame] | 2511 | CantChangePoolSizeAfterSetLocalDescription) { |
| 2512 | CreatePeerConnection(); |
| 2513 | // Start by setting a size of 1. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2514 | PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration(); |
deadbeef | 6de92f9 | 2016-12-12 18:49:32 -0800 | [diff] [blame] | 2515 | config.ice_candidate_pool_size = 1; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2516 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
deadbeef | 6de92f9 | 2016-12-12 18:49:32 -0800 | [diff] [blame] | 2517 | |
| 2518 | // Set remote offer; can still change pool size at this point. |
| 2519 | CreateOfferAsRemoteDescription(); |
| 2520 | config.ice_candidate_pool_size = 2; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2521 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
deadbeef | 6de92f9 | 2016-12-12 18:49:32 -0800 | [diff] [blame] | 2522 | |
| 2523 | // Set local answer; now it's too late. |
| 2524 | CreateAnswerAsLocalDescription(); |
| 2525 | config.ice_candidate_pool_size = 3; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2526 | RTCError error = pc_->SetConfiguration(config); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2527 | EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type()); |
| 2528 | } |
| 2529 | |
deadbeef | 42a4263 | 2017-03-10 15:18:00 -0800 | [diff] [blame] | 2530 | // Test that after setting an answer, extra pooled sessions are discarded. The |
| 2531 | // ICE candidate pool is only intended to be used for the first offer/answer. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2532 | TEST_P(PeerConnectionInterfaceTest, |
deadbeef | 42a4263 | 2017-03-10 15:18:00 -0800 | [diff] [blame] | 2533 | ExtraPooledSessionsDiscardedAfterApplyingAnswer) { |
| 2534 | CreatePeerConnection(); |
| 2535 | |
| 2536 | // Set a larger-than-necessary size. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2537 | PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration(); |
deadbeef | 42a4263 | 2017-03-10 15:18:00 -0800 | [diff] [blame] | 2538 | config.ice_candidate_pool_size = 4; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2539 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
deadbeef | 42a4263 | 2017-03-10 15:18:00 -0800 | [diff] [blame] | 2540 | |
| 2541 | // Do offer/answer. |
| 2542 | CreateOfferAsRemoteDescription(); |
| 2543 | CreateAnswerAsLocalDescription(); |
| 2544 | |
| 2545 | // Expect no pooled sessions to be left. |
| 2546 | const cricket::PortAllocatorSession* session = |
| 2547 | port_allocator_->GetPooledSession(); |
| 2548 | EXPECT_EQ(nullptr, session); |
| 2549 | } |
| 2550 | |
| 2551 | // After Close is called, pooled candidates should be discarded so as to not |
| 2552 | // waste network resources. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2553 | TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) { |
deadbeef | 42a4263 | 2017-03-10 15:18:00 -0800 | [diff] [blame] | 2554 | CreatePeerConnection(); |
| 2555 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2556 | PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration(); |
deadbeef | 42a4263 | 2017-03-10 15:18:00 -0800 | [diff] [blame] | 2557 | config.ice_candidate_pool_size = 3; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2558 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
deadbeef | 42a4263 | 2017-03-10 15:18:00 -0800 | [diff] [blame] | 2559 | pc_->Close(); |
| 2560 | |
| 2561 | // Expect no pooled sessions to be left. |
| 2562 | const cricket::PortAllocatorSession* session = |
| 2563 | port_allocator_->GetPooledSession(); |
| 2564 | EXPECT_EQ(nullptr, session); |
| 2565 | } |
| 2566 | |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2567 | // Test that SetConfiguration returns an invalid modification error if |
| 2568 | // modifying a field in the configuration that isn't allowed to be modified. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2569 | TEST_P(PeerConnectionInterfaceTest, |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2570 | SetConfigurationReturnsInvalidModificationError) { |
| 2571 | PeerConnectionInterface::RTCConfiguration config; |
| 2572 | config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced; |
| 2573 | config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate; |
| 2574 | config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2575 | CreatePeerConnection(config); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2576 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2577 | PeerConnectionInterface::RTCConfiguration modified_config = |
| 2578 | pc_->GetConfiguration(); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2579 | modified_config.bundle_policy = |
| 2580 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2581 | RTCError error = pc_->SetConfiguration(modified_config); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2582 | EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type()); |
| 2583 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2584 | modified_config = pc_->GetConfiguration(); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2585 | modified_config.rtcp_mux_policy = |
| 2586 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2587 | error = pc_->SetConfiguration(modified_config); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2588 | EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type()); |
| 2589 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2590 | modified_config = pc_->GetConfiguration(); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2591 | modified_config.continual_gathering_policy = |
| 2592 | PeerConnectionInterface::GATHER_CONTINUALLY; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2593 | error = pc_->SetConfiguration(modified_config); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2594 | EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type()); |
| 2595 | } |
| 2596 | |
| 2597 | // Test that SetConfiguration returns a range error if the candidate pool size |
| 2598 | // is negative or larger than allowed by the spec. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2599 | TEST_P(PeerConnectionInterfaceTest, |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2600 | SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) { |
| 2601 | PeerConnectionInterface::RTCConfiguration config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2602 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2603 | config = pc_->GetConfiguration(); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2604 | |
| 2605 | config.ice_candidate_pool_size = -1; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2606 | RTCError error = pc_->SetConfiguration(config); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2607 | EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type()); |
| 2608 | |
| 2609 | config.ice_candidate_pool_size = INT_MAX; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2610 | error = pc_->SetConfiguration(config); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2611 | EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type()); |
| 2612 | } |
| 2613 | |
| 2614 | // Test that SetConfiguration returns a syntax error if parsing an ICE server |
| 2615 | // URL failed. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2616 | TEST_P(PeerConnectionInterfaceTest, |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2617 | SetConfigurationReturnsSyntaxErrorFromBadIceUrls) { |
| 2618 | PeerConnectionInterface::RTCConfiguration config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2619 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2620 | config = pc_->GetConfiguration(); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2621 | |
| 2622 | PeerConnectionInterface::IceServer bad_server; |
| 2623 | bad_server.uri = "stunn:www.example.com"; |
| 2624 | config.servers.push_back(bad_server); |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 2625 | RTCError error = pc_->SetConfiguration(config); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2626 | EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type()); |
| 2627 | } |
| 2628 | |
| 2629 | // Test that SetConfiguration returns an invalid parameter error if a TURN |
| 2630 | // IceServer is missing a username or password. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2631 | TEST_P(PeerConnectionInterfaceTest, |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2632 | SetConfigurationReturnsInvalidParameterIfCredentialsMissing) { |
| 2633 | PeerConnectionInterface::RTCConfiguration config; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2634 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2635 | config = pc_->GetConfiguration(); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2636 | |
| 2637 | PeerConnectionInterface::IceServer bad_server; |
| 2638 | bad_server.uri = "turn:www.example.com"; |
| 2639 | // Missing password. |
| 2640 | bad_server.username = "foo"; |
| 2641 | config.servers.push_back(bad_server); |
| 2642 | RTCError error; |
Niels Möller | 340e0c5 | 2019-08-26 11:03:47 +0200 | [diff] [blame] | 2643 | EXPECT_EQ(pc_->SetConfiguration(config).type(), |
| 2644 | RTCErrorType::INVALID_PARAMETER); |
deadbeef | 6de92f9 | 2016-12-12 18:49:32 -0800 | [diff] [blame] | 2645 | } |
| 2646 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2647 | // Test that PeerConnection::Close changes the states to closed and all remote |
| 2648 | // tracks change state to ended. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2649 | TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2650 | // Initialize a PeerConnection and negotiate local and remote session |
| 2651 | // description. |
| 2652 | InitiateCall(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2653 | |
| 2654 | // With Plan B, verify the stream count. The analog with Unified Plan is the |
| 2655 | // RtpTransceiver count. |
| 2656 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2657 | ASSERT_EQ(1u, pc_->local_streams()->count()); |
| 2658 | ASSERT_EQ(1u, pc_->remote_streams()->count()); |
| 2659 | } else { |
| 2660 | ASSERT_EQ(2u, pc_->GetTransceivers().size()); |
| 2661 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2662 | |
| 2663 | pc_->Close(); |
| 2664 | |
| 2665 | EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state()); |
| 2666 | EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed, |
| 2667 | pc_->ice_connection_state()); |
| 2668 | EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete, |
| 2669 | pc_->ice_gathering_state()); |
| 2670 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2671 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2672 | EXPECT_EQ(1u, pc_->local_streams()->count()); |
| 2673 | EXPECT_EQ(1u, pc_->remote_streams()->count()); |
| 2674 | } else { |
| 2675 | // Verify that the RtpTransceivers are still present but all stopped. |
| 2676 | EXPECT_EQ(2u, pc_->GetTransceivers().size()); |
Mirko Bonadei | 739baf0 | 2019-01-27 17:29:42 +0100 | [diff] [blame] | 2677 | for (const auto& transceiver : pc_->GetTransceivers()) { |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2678 | EXPECT_TRUE(transceiver->stopped()); |
| 2679 | } |
| 2680 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2681 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2682 | auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO); |
| 2683 | ASSERT_TRUE(audio_receiver); |
| 2684 | auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO); |
| 2685 | ASSERT_TRUE(video_receiver); |
| 2686 | |
Taylor Brandstetter | d45b95c | 2016-03-29 13:16:52 -0700 | [diff] [blame] | 2687 | // Track state may be updated asynchronously. |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 2688 | EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2689 | audio_receiver->track()->state(), kTimeout); |
Taylor Brandstetter | d45b95c | 2016-03-29 13:16:52 -0700 | [diff] [blame] | 2690 | EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2691 | video_receiver->track()->state(), kTimeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2692 | } |
| 2693 | |
| 2694 | // Test that PeerConnection methods fails gracefully after |
| 2695 | // PeerConnection::Close has been called. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2696 | // Don't run under Unified Plan since the stream API is not available. |
| 2697 | TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2698 | CreatePeerConnectionWithoutDtls(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 2699 | AddAudioVideoStream(kStreamId1, "audio_label", "video_label"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2700 | CreateOfferAsRemoteDescription(); |
| 2701 | CreateAnswerAsLocalDescription(); |
| 2702 | |
| 2703 | ASSERT_EQ(1u, pc_->local_streams()->count()); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2704 | rtc::scoped_refptr<MediaStreamInterface> local_stream = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2705 | pc_->local_streams()->at(0); |
| 2706 | |
| 2707 | pc_->Close(); |
| 2708 | |
| 2709 | pc_->RemoveStream(local_stream); |
perkj@webrtc.org | c2dd5ee | 2014-11-04 11:31:29 +0000 | [diff] [blame] | 2710 | EXPECT_FALSE(pc_->AddStream(local_stream)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2711 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2712 | EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL); |
| 2713 | |
| 2714 | EXPECT_TRUE(pc_->local_description() != NULL); |
| 2715 | EXPECT_TRUE(pc_->remote_description() != NULL); |
| 2716 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2717 | std::unique_ptr<SessionDescriptionInterface> offer; |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2718 | EXPECT_FALSE(DoCreateOffer(&offer, nullptr)); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2719 | std::unique_ptr<SessionDescriptionInterface> answer; |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2720 | EXPECT_FALSE(DoCreateAnswer(&answer, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2721 | |
| 2722 | std::string sdp; |
| 2723 | ASSERT_TRUE(pc_->remote_description()->ToString(&sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2724 | std::unique_ptr<SessionDescriptionInterface> remote_offer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 2725 | webrtc::CreateSessionDescription(SdpType::kOffer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2726 | EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2727 | |
| 2728 | ASSERT_TRUE(pc_->local_description()->ToString(&sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2729 | std::unique_ptr<SessionDescriptionInterface> local_offer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 2730 | webrtc::CreateSessionDescription(SdpType::kOffer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2731 | EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2732 | } |
| 2733 | |
| 2734 | // Test that GetStats can still be called after PeerConnection::Close. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2735 | TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2736 | InitiateCall(); |
| 2737 | pc_->Close(); |
| 2738 | DoGetStats(NULL); |
| 2739 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2740 | |
| 2741 | // NOTE: The series of tests below come from what used to be |
| 2742 | // mediastreamsignaling_unittest.cc, and are mostly aimed at testing that |
| 2743 | // setting a remote or local description has the expected effects. |
| 2744 | |
| 2745 | // This test verifies that the remote MediaStreams corresponding to a received |
| 2746 | // SDP string is created. In this test the two separate MediaStreams are |
| 2747 | // signaled. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2748 | TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2749 | RTCConfiguration config; |
| 2750 | config.enable_dtls_srtp = true; |
| 2751 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2752 | CreateAndSetRemoteOffer(GetSdpStringWithStream1()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2753 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2754 | rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2755 | EXPECT_TRUE( |
| 2756 | CompareStreamCollections(observer_.remote_streams(), reference.get())); |
| 2757 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 2758 | EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr); |
| 2759 | |
| 2760 | // Create a session description based on another SDP with another |
| 2761 | // MediaStream. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2762 | CreateAndSetRemoteOffer(GetSdpStringWithStream1And2()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2763 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2764 | rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2765 | EXPECT_TRUE( |
| 2766 | CompareStreamCollections(observer_.remote_streams(), reference2.get())); |
| 2767 | } |
| 2768 | |
| 2769 | // This test verifies that when remote tracks are added/removed from SDP, the |
| 2770 | // created remote streams are updated appropriately. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2771 | // Don't run under Unified Plan since this test uses Plan B SDP to test Plan B |
| 2772 | // specific behavior. |
| 2773 | TEST_F(PeerConnectionInterfaceTestPlanB, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2774 | AddRemoveTrackFromExistingRemoteMediaStream) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2775 | RTCConfiguration config; |
| 2776 | config.enable_dtls_srtp = true; |
| 2777 | CreatePeerConnection(config); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2778 | std::unique_ptr<SessionDescriptionInterface> desc_ms1 = |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 2779 | CreateSessionDescriptionAndReference(1, 1); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2780 | EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2781 | EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), |
| 2782 | reference_collection_)); |
| 2783 | |
| 2784 | // Add extra audio and video tracks to the same MediaStream. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2785 | std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks = |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 2786 | CreateSessionDescriptionAndReference(2, 2); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2787 | EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2788 | EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), |
| 2789 | reference_collection_)); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2790 | rtc::scoped_refptr<AudioTrackInterface> audio_track2 = |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 2791 | observer_.remote_streams()->at(0)->GetAudioTracks()[1]; |
| 2792 | EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state()); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2793 | rtc::scoped_refptr<VideoTrackInterface> video_track2 = |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 2794 | observer_.remote_streams()->at(0)->GetVideoTracks()[1]; |
| 2795 | EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2796 | |
| 2797 | // Remove the extra audio and video tracks. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2798 | std::unique_ptr<SessionDescriptionInterface> desc_ms2 = |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 2799 | CreateSessionDescriptionAndReference(1, 1); |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 2800 | MockTrackObserver audio_track_observer(audio_track2); |
| 2801 | MockTrackObserver video_track_observer(video_track2); |
| 2802 | |
| 2803 | EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1)); |
| 2804 | EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2805 | EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2806 | EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), |
| 2807 | reference_collection_)); |
Taylor Brandstetter | d45b95c | 2016-03-29 13:16:52 -0700 | [diff] [blame] | 2808 | // Track state may be updated asynchronously. |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 2809 | EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded, |
Taylor Brandstetter | d45b95c | 2016-03-29 13:16:52 -0700 | [diff] [blame] | 2810 | audio_track2->state(), kTimeout); |
| 2811 | EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded, |
| 2812 | video_track2->state(), kTimeout); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2813 | } |
| 2814 | |
| 2815 | // This tests that remote tracks are ended if a local session description is set |
| 2816 | // that rejects the media content type. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2817 | TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2818 | RTCConfiguration config; |
| 2819 | config.enable_dtls_srtp = true; |
| 2820 | CreatePeerConnection(config); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2821 | // First create and set a remote offer, then reject its video content in our |
| 2822 | // answer. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2823 | CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB); |
| 2824 | auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO); |
| 2825 | ASSERT_TRUE(audio_receiver); |
| 2826 | auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO); |
| 2827 | ASSERT_TRUE(video_receiver); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2828 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2829 | rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio = |
| 2830 | audio_receiver->track(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2831 | EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state()); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2832 | rtc::scoped_refptr<MediaStreamTrackInterface> remote_video = |
| 2833 | video_receiver->track(); |
| 2834 | EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2835 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2836 | std::unique_ptr<SessionDescriptionInterface> local_answer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 2837 | EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2838 | cricket::ContentInfo* video_info = |
| 2839 | local_answer->description()->GetContentByName("video"); |
| 2840 | video_info->rejected = true; |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2841 | EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer))); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2842 | EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state()); |
| 2843 | EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2844 | |
| 2845 | // Now create an offer where we reject both video and audio. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2846 | std::unique_ptr<SessionDescriptionInterface> local_offer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 2847 | EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2848 | video_info = local_offer->description()->GetContentByName("video"); |
| 2849 | ASSERT_TRUE(video_info != nullptr); |
| 2850 | video_info->rejected = true; |
| 2851 | cricket::ContentInfo* audio_info = |
| 2852 | local_offer->description()->GetContentByName("audio"); |
| 2853 | ASSERT_TRUE(audio_info != nullptr); |
| 2854 | audio_info->rejected = true; |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2855 | EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer))); |
Taylor Brandstetter | d45b95c | 2016-03-29 13:16:52 -0700 | [diff] [blame] | 2856 | // Track state may be updated asynchronously. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2857 | EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(), |
| 2858 | kTimeout); |
| 2859 | EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(), |
| 2860 | kTimeout); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2861 | } |
| 2862 | |
| 2863 | // This tests that we won't crash if the remote track has been removed outside |
| 2864 | // of PeerConnection and then PeerConnection tries to reject the track. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2865 | // Don't run under Unified Plan since the stream API is not available. |
| 2866 | TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2867 | RTCConfiguration config; |
| 2868 | config.enable_dtls_srtp = true; |
| 2869 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2870 | CreateAndSetRemoteOffer(GetSdpStringWithStream1()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2871 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 2872 | remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]); |
| 2873 | remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]); |
| 2874 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2875 | std::unique_ptr<SessionDescriptionInterface> local_answer( |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2876 | webrtc::CreateSessionDescription(SdpType::kAnswer, |
| 2877 | GetSdpStringWithStream1(), nullptr)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2878 | cricket::ContentInfo* video_info = |
| 2879 | local_answer->description()->GetContentByName("video"); |
| 2880 | video_info->rejected = true; |
| 2881 | cricket::ContentInfo* audio_info = |
| 2882 | local_answer->description()->GetContentByName("audio"); |
| 2883 | audio_info->rejected = true; |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2884 | EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2885 | |
| 2886 | // No crash is a pass. |
| 2887 | } |
| 2888 | |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 2889 | // This tests that if a recvonly remote description is set, no remote streams |
| 2890 | // will be created, even if the description contains SSRCs/MSIDs. |
| 2891 | // See: https://code.google.com/p/webrtc/issues/detail?id=5054 |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2892 | TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2893 | RTCConfiguration config; |
| 2894 | config.enable_dtls_srtp = true; |
| 2895 | CreatePeerConnection(config); |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 2896 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2897 | std::string recvonly_offer = GetSdpStringWithStream1(); |
Steve Anton | 1c9c9fc | 2019-02-14 15:13:09 -0800 | [diff] [blame] | 2898 | absl::StrReplaceAll({{kSendrecv, kRecvonly}}, &recvonly_offer); |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 2899 | CreateAndSetRemoteOffer(recvonly_offer); |
| 2900 | |
| 2901 | EXPECT_EQ(0u, observer_.remote_streams()->count()); |
| 2902 | } |
| 2903 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2904 | // This tests that a default MediaStream is created if a remote session |
| 2905 | // description doesn't contain any streams and no MSID support. |
| 2906 | // It also tests that the default stream is updated if a video m-line is added |
| 2907 | // in a subsequent session description. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2908 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 2909 | TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2910 | RTCConfiguration config; |
| 2911 | config.enable_dtls_srtp = true; |
| 2912 | CreatePeerConnection(config); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2913 | CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly); |
| 2914 | |
| 2915 | ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 2916 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 2917 | |
| 2918 | EXPECT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 2919 | EXPECT_EQ(0u, remote_stream->GetVideoTracks().size()); |
Seth Hampson | 13b8bad | 2018-03-13 16:05:28 -0700 | [diff] [blame] | 2920 | EXPECT_EQ("default", remote_stream->id()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2921 | |
| 2922 | CreateAndSetRemoteOffer(kSdpStringWithoutStreams); |
| 2923 | ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 2924 | ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 2925 | EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id()); |
deadbeef | 884f585 | 2016-01-15 09:20:04 -0800 | [diff] [blame] | 2926 | EXPECT_EQ(MediaStreamTrackInterface::kLive, |
| 2927 | remote_stream->GetAudioTracks()[0]->state()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2928 | ASSERT_EQ(1u, remote_stream->GetVideoTracks().size()); |
| 2929 | EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id()); |
deadbeef | 884f585 | 2016-01-15 09:20:04 -0800 | [diff] [blame] | 2930 | EXPECT_EQ(MediaStreamTrackInterface::kLive, |
| 2931 | remote_stream->GetVideoTracks()[0]->state()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2932 | } |
| 2933 | |
| 2934 | // This tests that a default MediaStream is created if a remote session |
| 2935 | // description doesn't contain any streams and media direction is send only. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2936 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 2937 | TEST_F(PeerConnectionInterfaceTestPlanB, |
Taylor Brandstetter | 7ff1737 | 2016-04-01 11:50:39 -0700 | [diff] [blame] | 2938 | SendOnlySdpWithoutMsidCreatesDefaultStream) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2939 | RTCConfiguration config; |
| 2940 | config.enable_dtls_srtp = true; |
| 2941 | CreatePeerConnection(config); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2942 | CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams); |
| 2943 | |
| 2944 | ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 2945 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 2946 | |
| 2947 | EXPECT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 2948 | EXPECT_EQ(1u, remote_stream->GetVideoTracks().size()); |
Seth Hampson | 13b8bad | 2018-03-13 16:05:28 -0700 | [diff] [blame] | 2949 | EXPECT_EQ("default", remote_stream->id()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2950 | } |
| 2951 | |
| 2952 | // This tests that it won't crash when PeerConnection tries to remove |
| 2953 | // a remote track that as already been removed from the MediaStream. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2954 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 2955 | TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2956 | RTCConfiguration config; |
| 2957 | config.enable_dtls_srtp = true; |
| 2958 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2959 | CreateAndSetRemoteOffer(GetSdpStringWithStream1()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2960 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 2961 | remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]); |
| 2962 | remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]); |
| 2963 | |
| 2964 | CreateAndSetRemoteOffer(kSdpStringWithoutStreams); |
| 2965 | |
| 2966 | // No crash is a pass. |
| 2967 | } |
| 2968 | |
| 2969 | // This tests that a default MediaStream is created if the remote session |
| 2970 | // description doesn't contain any streams and don't contain an indication if |
| 2971 | // MSID is supported. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2972 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 2973 | TEST_F(PeerConnectionInterfaceTestPlanB, |
Taylor Brandstetter | 7ff1737 | 2016-04-01 11:50:39 -0700 | [diff] [blame] | 2974 | SdpWithoutMsidAndStreamsCreatesDefaultStream) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2975 | RTCConfiguration config; |
| 2976 | config.enable_dtls_srtp = true; |
| 2977 | CreatePeerConnection(config); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2978 | CreateAndSetRemoteOffer(kSdpStringWithoutStreams); |
| 2979 | |
| 2980 | ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 2981 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 2982 | EXPECT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 2983 | EXPECT_EQ(1u, remote_stream->GetVideoTracks().size()); |
| 2984 | } |
| 2985 | |
| 2986 | // This tests that a default MediaStream is not created if the remote session |
| 2987 | // description doesn't contain any streams but does support MSID. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2988 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 2989 | TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 2990 | RTCConfiguration config; |
| 2991 | config.enable_dtls_srtp = true; |
| 2992 | CreatePeerConnection(config); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2993 | CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams); |
| 2994 | EXPECT_EQ(0u, observer_.remote_streams()->count()); |
| 2995 | } |
| 2996 | |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 2997 | // This tests that when setting a new description, the old default tracks are |
| 2998 | // not destroyed and recreated. |
| 2999 | // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250 |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3000 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 3001 | TEST_F(PeerConnectionInterfaceTestPlanB, |
Taylor Brandstetter | 7ff1737 | 2016-04-01 11:50:39 -0700 | [diff] [blame] | 3002 | DefaultTracksNotDestroyedAndRecreated) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3003 | RTCConfiguration config; |
| 3004 | config.enable_dtls_srtp = true; |
| 3005 | CreatePeerConnection(config); |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 3006 | CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly); |
| 3007 | |
| 3008 | ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 3009 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 3010 | ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 3011 | |
| 3012 | // Set the track to "disabled", then set a new description and ensure the |
| 3013 | // track is still disabled, which ensures it hasn't been recreated. |
| 3014 | remote_stream->GetAudioTracks()[0]->set_enabled(false); |
| 3015 | CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly); |
| 3016 | ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 3017 | EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled()); |
| 3018 | } |
| 3019 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3020 | // This tests that a default MediaStream is not created if a remote session |
| 3021 | // description is updated to not have any MediaStreams. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3022 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 3023 | TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3024 | RTCConfiguration config; |
| 3025 | config.enable_dtls_srtp = true; |
| 3026 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3027 | CreateAndSetRemoteOffer(GetSdpStringWithStream1()); |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3028 | rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3029 | EXPECT_TRUE( |
| 3030 | CompareStreamCollections(observer_.remote_streams(), reference.get())); |
| 3031 | |
| 3032 | CreateAndSetRemoteOffer(kSdpStringWithoutStreams); |
| 3033 | EXPECT_EQ(0u, observer_.remote_streams()->count()); |
| 3034 | } |
| 3035 | |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 3036 | // This tests that a default MediaStream is created if a remote SDP comes from |
| 3037 | // an endpoint that doesn't signal SSRCs, but signals media stream IDs. |
| 3038 | TEST_F(PeerConnectionInterfaceTestPlanB, |
| 3039 | SdpWithMsidWithoutSsrcCreatesDefaultStream) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3040 | RTCConfiguration config; |
| 3041 | config.enable_dtls_srtp = true; |
| 3042 | CreatePeerConnection(config); |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 3043 | std::string sdp_string = kSdpStringWithoutStreamsAudioOnly; |
| 3044 | // Add a=msid lines to simulate a Unified Plan endpoint that only |
| 3045 | // signals stream IDs with a=msid lines. |
| 3046 | sdp_string.append("a=msid:audio_stream_id audio_track_id\n"); |
| 3047 | |
| 3048 | CreateAndSetRemoteOffer(sdp_string); |
| 3049 | |
| 3050 | ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 3051 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 3052 | EXPECT_EQ("default", remote_stream->id()); |
| 3053 | ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 3054 | } |
| 3055 | |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 3056 | // This tests that when a Plan B endpoint receives an SDP that signals no media |
| 3057 | // stream IDs indicated by the special character "-" in the a=msid line, that |
| 3058 | // a default stream ID will be used for the MediaStream ID. This can occur |
| 3059 | // when a Unified Plan endpoint signals no media stream IDs, but signals both |
| 3060 | // a=ssrc msid and a=msid lines for interop signaling with Plan B. |
| 3061 | TEST_F(PeerConnectionInterfaceTestPlanB, |
| 3062 | SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3063 | RTCConfiguration config; |
| 3064 | config.enable_dtls_srtp = true; |
| 3065 | CreatePeerConnection(config); |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 3066 | // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so |
| 3067 | // the sender's stream ID will be interpreted as no stream IDs. |
| 3068 | std::string sdp_string = kSdpStringWithStream1AudioTrackOnly; |
| 3069 | sdp_string.append("a=msid:- audiotrack0\n"); |
| 3070 | |
| 3071 | CreateAndSetRemoteOffer(sdp_string); |
| 3072 | |
| 3073 | ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 3074 | // Because SSRCs are signaled the track ID will be what was signaled in the |
| 3075 | // a=msid line. |
| 3076 | EXPECT_EQ("audiotrack0", observer_.last_added_track_label_); |
| 3077 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 3078 | EXPECT_EQ("default", remote_stream->id()); |
| 3079 | ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); |
Seth Hampson | 83d676b | 2018-04-05 18:12:09 -0700 | [diff] [blame] | 3080 | |
| 3081 | // Previously a bug ocurred when setting the remote description a second time. |
| 3082 | // This is because we checked equality of the remote StreamParams stream ID |
| 3083 | // (empty), and the previously set stream ID for the remote sender |
| 3084 | // ("default"). This cause a track to be removed, then added, when really |
| 3085 | // nothing should occur because it is the same track. |
| 3086 | CreateAndSetRemoteOffer(sdp_string); |
| 3087 | EXPECT_EQ(0u, observer_.remove_track_events_.size()); |
| 3088 | EXPECT_EQ(1u, observer_.add_track_events_.size()); |
| 3089 | EXPECT_EQ("audiotrack0", observer_.last_added_track_label_); |
| 3090 | remote_stream = observer_.remote_streams()->at(0); |
| 3091 | EXPECT_EQ("default", remote_stream->id()); |
| 3092 | ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); |
Seth Hampson | 5b4f075 | 2018-04-02 16:31:36 -0700 | [diff] [blame] | 3093 | } |
| 3094 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3095 | // This tests that an RtpSender is created when the local description is set |
| 3096 | // after adding a local stream. |
| 3097 | // TODO(deadbeef): This test and the one below it need to be updated when |
| 3098 | // an RtpSender's lifetime isn't determined by when a local description is set. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3099 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 3100 | TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3101 | RTCConfiguration config; |
| 3102 | config.enable_dtls_srtp = true; |
| 3103 | CreatePeerConnection(config); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3104 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3105 | // Create an offer with 1 stream with 2 tracks of each type. |
| 3106 | rtc::scoped_refptr<StreamCollection> stream_collection = |
| 3107 | CreateStreamCollection(1, 2); |
| 3108 | pc_->AddStream(stream_collection->at(0)); |
| 3109 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3110 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3111 | EXPECT_TRUE(DoSetLocalDescription(std::move(offer))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3112 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3113 | auto senders = pc_->GetSenders(); |
| 3114 | EXPECT_EQ(4u, senders.size()); |
| 3115 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 3116 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 3117 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1])); |
| 3118 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1])); |
| 3119 | |
| 3120 | // Remove an audio and video track. |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3121 | pc_->RemoveStream(stream_collection->at(0)); |
| 3122 | stream_collection = CreateStreamCollection(1, 1); |
| 3123 | pc_->AddStream(stream_collection->at(0)); |
| 3124 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3125 | EXPECT_TRUE(DoSetLocalDescription(std::move(offer))); |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3126 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3127 | senders = pc_->GetSenders(); |
| 3128 | EXPECT_EQ(2u, senders.size()); |
| 3129 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 3130 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 3131 | EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1])); |
| 3132 | EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1])); |
| 3133 | } |
| 3134 | |
| 3135 | // This tests that an RtpSender is created when the local description is set |
| 3136 | // before adding a local stream. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3137 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 3138 | TEST_F(PeerConnectionInterfaceTestPlanB, |
Taylor Brandstetter | 7ff1737 | 2016-04-01 11:50:39 -0700 | [diff] [blame] | 3139 | AddLocalStreamAfterLocalDescriptionChanged) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3140 | RTCConfiguration config; |
| 3141 | config.enable_dtls_srtp = true; |
| 3142 | CreatePeerConnection(config); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3143 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3144 | rtc::scoped_refptr<StreamCollection> stream_collection = |
| 3145 | CreateStreamCollection(1, 2); |
| 3146 | // Add a stream to create the offer, but remove it afterwards. |
| 3147 | pc_->AddStream(stream_collection->at(0)); |
| 3148 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3149 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
| 3150 | pc_->RemoveStream(stream_collection->at(0)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3151 | |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3152 | EXPECT_TRUE(DoSetLocalDescription(std::move(offer))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3153 | auto senders = pc_->GetSenders(); |
| 3154 | EXPECT_EQ(0u, senders.size()); |
| 3155 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3156 | pc_->AddStream(stream_collection->at(0)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3157 | senders = pc_->GetSenders(); |
| 3158 | EXPECT_EQ(4u, senders.size()); |
| 3159 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 3160 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 3161 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1])); |
| 3162 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1])); |
| 3163 | } |
| 3164 | |
| 3165 | // This tests that the expected behavior occurs if the SSRC on a local track is |
| 3166 | // changed when SetLocalDescription is called. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3167 | TEST_P(PeerConnectionInterfaceTest, |
Taylor Brandstetter | 7ff1737 | 2016-04-01 11:50:39 -0700 | [diff] [blame] | 3168 | ChangeSsrcOnTrackInLocalSessionDescription) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3169 | RTCConfiguration config; |
| 3170 | config.enable_dtls_srtp = true; |
| 3171 | CreatePeerConnection(config); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3172 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3173 | AddAudioTrack(kAudioTracks[0]); |
| 3174 | AddVideoTrack(kVideoTracks[0]); |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3175 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3176 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
| 3177 | // Grab a copy of the offer before it gets passed into the PC. |
Steve Anton | d9e4a06 | 2018-07-24 18:23:33 -0700 | [diff] [blame] | 3178 | std::unique_ptr<SessionDescriptionInterface> modified_offer = |
| 3179 | webrtc::CreateSessionDescription( |
| 3180 | webrtc::SdpType::kOffer, offer->session_id(), |
Harald Alvestrand | 4d7160e | 2019-04-12 07:01:29 +0200 | [diff] [blame] | 3181 | offer->session_version(), offer->description()->Clone()); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3182 | EXPECT_TRUE(DoSetLocalDescription(std::move(offer))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3183 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3184 | auto senders = pc_->GetSenders(); |
| 3185 | EXPECT_EQ(2u, senders.size()); |
| 3186 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 3187 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 3188 | |
| 3189 | // Change the ssrc of the audio and video track. |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3190 | cricket::MediaContentDescription* desc = |
| 3191 | cricket::GetFirstAudioContentDescription(modified_offer->description()); |
| 3192 | ASSERT_TRUE(desc != NULL); |
| 3193 | for (StreamParams& stream : desc->mutable_streams()) { |
| 3194 | for (unsigned int& ssrc : stream.ssrcs) { |
| 3195 | ++ssrc; |
| 3196 | } |
| 3197 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3198 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3199 | desc = |
| 3200 | cricket::GetFirstVideoContentDescription(modified_offer->description()); |
| 3201 | ASSERT_TRUE(desc != NULL); |
| 3202 | for (StreamParams& stream : desc->mutable_streams()) { |
| 3203 | for (unsigned int& ssrc : stream.ssrcs) { |
| 3204 | ++ssrc; |
| 3205 | } |
| 3206 | } |
| 3207 | |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3208 | EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3209 | senders = pc_->GetSenders(); |
| 3210 | EXPECT_EQ(2u, senders.size()); |
| 3211 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 3212 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 3213 | // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC |
| 3214 | // changed. |
| 3215 | } |
| 3216 | |
| 3217 | // This tests that the expected behavior occurs if a new session description is |
| 3218 | // set with the same tracks, but on a different MediaStream. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3219 | // Don't run under Unified Plan since the stream API is not available. |
| 3220 | TEST_F(PeerConnectionInterfaceTestPlanB, |
Taylor Brandstetter | 7ff1737 | 2016-04-01 11:50:39 -0700 | [diff] [blame] | 3221 | SignalSameTracksInSeparateMediaStream) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3222 | RTCConfiguration config; |
| 3223 | config.enable_dtls_srtp = true; |
| 3224 | CreatePeerConnection(config); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3225 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3226 | rtc::scoped_refptr<StreamCollection> stream_collection = |
| 3227 | CreateStreamCollection(2, 1); |
| 3228 | pc_->AddStream(stream_collection->at(0)); |
| 3229 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3230 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3231 | EXPECT_TRUE(DoSetLocalDescription(std::move(offer))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3232 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3233 | auto senders = pc_->GetSenders(); |
| 3234 | EXPECT_EQ(2u, senders.size()); |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3235 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0])); |
| 3236 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0])); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3237 | |
| 3238 | // Add a new MediaStream but with the same tracks as in the first stream. |
| 3239 | rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1( |
| 3240 | webrtc::MediaStream::Create(kStreams[1])); |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3241 | stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]); |
| 3242 | stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3243 | pc_->AddStream(stream_1); |
| 3244 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3245 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3246 | EXPECT_TRUE(DoSetLocalDescription(std::move(offer))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3247 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3248 | auto new_senders = pc_->GetSenders(); |
| 3249 | // Should be the same senders as before, but with updated stream id. |
| 3250 | // Note that this behavior is subject to change in the future. |
| 3251 | // We may decide the PC should ignore existing tracks in AddStream. |
| 3252 | EXPECT_EQ(senders, new_senders); |
| 3253 | EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1])); |
| 3254 | EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1])); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3255 | } |
| 3256 | |
zhihuang | 81c3a03 | 2016-11-17 12:06:24 -0800 | [diff] [blame] | 3257 | // This tests that PeerConnectionObserver::OnAddTrack is correctly called. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3258 | TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) { |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3259 | RTCConfiguration config; |
| 3260 | config.enable_dtls_srtp = true; |
| 3261 | CreatePeerConnection(config); |
zhihuang | 81c3a03 | 2016-11-17 12:06:24 -0800 | [diff] [blame] | 3262 | CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly); |
| 3263 | EXPECT_EQ(observer_.num_added_tracks_, 1); |
| 3264 | EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]); |
| 3265 | |
| 3266 | // Create and set the updated remote SDP. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3267 | CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB); |
Steve Anton | 0f5400a | 2018-07-17 14:25:36 -0700 | [diff] [blame] | 3268 | EXPECT_EQ(observer_.num_added_tracks_, 2); |
zhihuang | 81c3a03 | 2016-11-17 12:06:24 -0800 | [diff] [blame] | 3269 | EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]); |
| 3270 | } |
| 3271 | |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3272 | // Test that when SetConfiguration is called and the configuration is |
| 3273 | // changing, the next offer causes an ICE restart. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3274 | TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) { |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3275 | PeerConnectionInterface::RTCConfiguration config; |
| 3276 | config.type = PeerConnectionInterface::kRelay; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3277 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3278 | config = pc_->GetConfiguration(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 3279 | AddAudioTrack(kAudioTracks[0], {kStreamId1}); |
| 3280 | AddVideoTrack(kVideoTracks[0], {kStreamId1}); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3281 | |
| 3282 | // Do initial offer/answer so there's something to restart. |
| 3283 | CreateOfferAsLocalDescription(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3284 | CreateAnswerAsRemoteDescription(GetSdpStringWithStream1()); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3285 | |
| 3286 | // Grab the ufrags. |
| 3287 | std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description()); |
| 3288 | |
| 3289 | // Change ICE policy, which should trigger an ICE restart on the next offer. |
| 3290 | config.type = PeerConnectionInterface::kAll; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 3291 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3292 | CreateOfferAsLocalDescription(); |
| 3293 | |
| 3294 | // Grab the new ufrags. |
| 3295 | std::vector<std::string> subsequent_ufrags = |
| 3296 | GetUfrags(pc_->local_description()); |
| 3297 | |
| 3298 | // Sanity check. |
| 3299 | EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size()); |
| 3300 | // Check that each ufrag is different. |
| 3301 | for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) { |
| 3302 | EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]); |
| 3303 | } |
| 3304 | } |
| 3305 | |
| 3306 | // Test that when SetConfiguration is called and the configuration *isn't* |
| 3307 | // changing, the next offer does *not* cause an ICE restart. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3308 | TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) { |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3309 | PeerConnectionInterface::RTCConfiguration config; |
| 3310 | config.type = PeerConnectionInterface::kRelay; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3311 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3312 | config = pc_->GetConfiguration(); |
| 3313 | AddAudioTrack(kAudioTracks[0]); |
| 3314 | AddVideoTrack(kVideoTracks[0]); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3315 | |
| 3316 | // Do initial offer/answer so there's something to restart. |
| 3317 | CreateOfferAsLocalDescription(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3318 | CreateAnswerAsRemoteDescription(GetSdpStringWithStream1()); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3319 | |
| 3320 | // Grab the ufrags. |
| 3321 | std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description()); |
| 3322 | |
| 3323 | // Call SetConfiguration with a config identical to what the PC was |
| 3324 | // constructed with. |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 3325 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3326 | CreateOfferAsLocalDescription(); |
| 3327 | |
| 3328 | // Grab the new ufrags. |
| 3329 | std::vector<std::string> subsequent_ufrags = |
| 3330 | GetUfrags(pc_->local_description()); |
| 3331 | |
| 3332 | EXPECT_EQ(initial_ufrags, subsequent_ufrags); |
| 3333 | } |
| 3334 | |
| 3335 | // Test for a weird corner case scenario: |
| 3336 | // 1. Audio/video session established. |
| 3337 | // 2. SetConfiguration changes ICE config; ICE restart needed. |
| 3338 | // 3. ICE restart initiated by remote peer, but only for one m= section. |
| 3339 | // 4. Next createOffer should initiate an ICE restart, but only for the other |
| 3340 | // m= section; it would be pointless to do an ICE restart for the m= section |
| 3341 | // that was already restarted. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3342 | TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) { |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3343 | PeerConnectionInterface::RTCConfiguration config; |
| 3344 | config.type = PeerConnectionInterface::kRelay; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3345 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3346 | config = pc_->GetConfiguration(); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 3347 | AddAudioTrack(kAudioTracks[0], {kStreamId1}); |
| 3348 | AddVideoTrack(kVideoTracks[0], {kStreamId1}); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3349 | |
| 3350 | // Do initial offer/answer so there's something to restart. |
| 3351 | CreateOfferAsLocalDescription(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3352 | CreateAnswerAsRemoteDescription(GetSdpStringWithStream1()); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3353 | |
| 3354 | // Change ICE policy, which should set the "needs-ice-restart" flag. |
| 3355 | config.type = PeerConnectionInterface::kAll; |
Niels Möller | 2579f0c | 2019-08-19 09:58:17 +0200 | [diff] [blame] | 3356 | EXPECT_TRUE(pc_->SetConfiguration(config).ok()); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3357 | |
| 3358 | // Do ICE restart for the first m= section, initiated by remote peer. |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3359 | std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer( |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3360 | webrtc::CreateSessionDescription(SdpType::kOffer, |
| 3361 | GetSdpStringWithStream1(), nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3362 | ASSERT_TRUE(remote_offer); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3363 | remote_offer->description()->transport_infos()[0].description.ice_ufrag = |
| 3364 | "modified"; |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3365 | EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer))); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3366 | CreateAnswerAsLocalDescription(); |
| 3367 | |
| 3368 | // Grab the ufrags. |
| 3369 | std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description()); |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 3370 | ASSERT_EQ(2U, initial_ufrags.size()); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3371 | |
| 3372 | // Create offer and grab the new ufrags. |
| 3373 | CreateOfferAsLocalDescription(); |
| 3374 | std::vector<std::string> subsequent_ufrags = |
| 3375 | GetUfrags(pc_->local_description()); |
Mirko Bonadei | e12c1fe | 2018-07-03 12:53:23 +0200 | [diff] [blame] | 3376 | ASSERT_EQ(2U, subsequent_ufrags.size()); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3377 | |
| 3378 | // Ensure that only the ufrag for the second m= section changed. |
| 3379 | EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]); |
| 3380 | EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]); |
| 3381 | } |
| 3382 | |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3383 | // Tests that the methods to return current/pending descriptions work as |
| 3384 | // expected at different points in the offer/answer exchange. This test does |
| 3385 | // one offer/answer exchange as the offerer, then another as the answerer. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3386 | TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) { |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3387 | // This disables DTLS so we can apply an answer to ourselves. |
| 3388 | CreatePeerConnection(); |
| 3389 | |
| 3390 | // Create initial local offer and get SDP (which will also be used as |
| 3391 | // answer/pranswer); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3392 | std::unique_ptr<SessionDescriptionInterface> local_offer; |
| 3393 | ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr)); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3394 | std::string sdp; |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3395 | EXPECT_TRUE(local_offer->ToString(&sdp)); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3396 | |
| 3397 | // Set local offer. |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3398 | SessionDescriptionInterface* local_offer_ptr = local_offer.get(); |
| 3399 | EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer))); |
| 3400 | EXPECT_EQ(local_offer_ptr, pc_->pending_local_description()); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3401 | EXPECT_EQ(nullptr, pc_->pending_remote_description()); |
| 3402 | EXPECT_EQ(nullptr, pc_->current_local_description()); |
| 3403 | EXPECT_EQ(nullptr, pc_->current_remote_description()); |
| 3404 | |
| 3405 | // Set remote pranswer. |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3406 | std::unique_ptr<SessionDescriptionInterface> remote_pranswer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 3407 | webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3408 | SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get(); |
| 3409 | EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer))); |
| 3410 | EXPECT_EQ(local_offer_ptr, pc_->pending_local_description()); |
| 3411 | EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description()); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3412 | EXPECT_EQ(nullptr, pc_->current_local_description()); |
| 3413 | EXPECT_EQ(nullptr, pc_->current_remote_description()); |
| 3414 | |
| 3415 | // Set remote answer. |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3416 | std::unique_ptr<SessionDescriptionInterface> remote_answer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 3417 | webrtc::CreateSessionDescription(SdpType::kAnswer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3418 | SessionDescriptionInterface* remote_answer_ptr = remote_answer.get(); |
| 3419 | EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer))); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3420 | EXPECT_EQ(nullptr, pc_->pending_local_description()); |
| 3421 | EXPECT_EQ(nullptr, pc_->pending_remote_description()); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3422 | EXPECT_EQ(local_offer_ptr, pc_->current_local_description()); |
| 3423 | EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description()); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3424 | |
| 3425 | // Set remote offer. |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3426 | std::unique_ptr<SessionDescriptionInterface> remote_offer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 3427 | webrtc::CreateSessionDescription(SdpType::kOffer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3428 | SessionDescriptionInterface* remote_offer_ptr = remote_offer.get(); |
| 3429 | EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer))); |
| 3430 | EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description()); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3431 | EXPECT_EQ(nullptr, pc_->pending_local_description()); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3432 | EXPECT_EQ(local_offer_ptr, pc_->current_local_description()); |
| 3433 | EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description()); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3434 | |
| 3435 | // Set local pranswer. |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3436 | std::unique_ptr<SessionDescriptionInterface> local_pranswer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 3437 | webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3438 | SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get(); |
| 3439 | EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer))); |
| 3440 | EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description()); |
| 3441 | EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description()); |
| 3442 | EXPECT_EQ(local_offer_ptr, pc_->current_local_description()); |
| 3443 | EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description()); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3444 | |
| 3445 | // Set local answer. |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3446 | std::unique_ptr<SessionDescriptionInterface> local_answer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 3447 | webrtc::CreateSessionDescription(SdpType::kAnswer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3448 | SessionDescriptionInterface* local_answer_ptr = local_answer.get(); |
| 3449 | EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer))); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3450 | EXPECT_EQ(nullptr, pc_->pending_remote_description()); |
| 3451 | EXPECT_EQ(nullptr, pc_->pending_local_description()); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3452 | EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description()); |
| 3453 | EXPECT_EQ(local_answer_ptr, pc_->current_local_description()); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3454 | } |
| 3455 | |
zhihuang | 7798501 | 2017-02-07 15:45:16 -0800 | [diff] [blame] | 3456 | // Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog |
| 3457 | // after the PeerConnection is closed. |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 3458 | // This version tests the StartRtcEventLog version that receives an object |
| 3459 | // of type |RtcEventLogOutput|. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3460 | TEST_P(PeerConnectionInterfaceTest, |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 3461 | StartAndStopLoggingToOutputAfterPeerConnectionClosed) { |
| 3462 | CreatePeerConnection(); |
| 3463 | // The RtcEventLog will be reset when the PeerConnection is closed. |
| 3464 | pc_->Close(); |
| 3465 | |
Niels Möller | dec9f74 | 2019-06-03 15:25:20 +0200 | [diff] [blame] | 3466 | EXPECT_FALSE( |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 3467 | pc_->StartRtcEventLog(std::make_unique<webrtc::RtcEventLogOutputNull>(), |
Niels Möller | dec9f74 | 2019-06-03 15:25:20 +0200 | [diff] [blame] | 3468 | webrtc::RtcEventLog::kImmediateOutput)); |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 3469 | pc_->StopRtcEventLog(); |
| 3470 | } |
| 3471 | |
deadbeef | 30952b4 | 2017-04-21 02:41:29 -0700 | [diff] [blame] | 3472 | // Test that generated offers/answers include "ice-option:trickle". |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3473 | TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) { |
deadbeef | 30952b4 | 2017-04-21 02:41:29 -0700 | [diff] [blame] | 3474 | CreatePeerConnection(); |
| 3475 | |
| 3476 | // First, create an offer with audio/video. |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3477 | RTCOfferAnswerOptions options; |
| 3478 | options.offer_to_receive_audio = 1; |
| 3479 | options.offer_to_receive_video = 1; |
deadbeef | 30952b4 | 2017-04-21 02:41:29 -0700 | [diff] [blame] | 3480 | std::unique_ptr<SessionDescriptionInterface> offer; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3481 | ASSERT_TRUE(DoCreateOffer(&offer, &options)); |
deadbeef | 30952b4 | 2017-04-21 02:41:29 -0700 | [diff] [blame] | 3482 | cricket::SessionDescription* desc = offer->description(); |
| 3483 | ASSERT_EQ(2u, desc->transport_infos().size()); |
| 3484 | EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle")); |
| 3485 | EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle")); |
| 3486 | |
| 3487 | // Apply the offer as a remote description, then create an answer. |
Harald Alvestrand | 61f74d9 | 2020-03-02 11:20:00 +0100 | [diff] [blame] | 3488 | EXPECT_FALSE(pc_->can_trickle_ice_candidates()); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3489 | EXPECT_TRUE(DoSetRemoteDescription(std::move(offer))); |
Harald Alvestrand | 61f74d9 | 2020-03-02 11:20:00 +0100 | [diff] [blame] | 3490 | ASSERT_TRUE(pc_->can_trickle_ice_candidates()); |
| 3491 | EXPECT_TRUE(*(pc_->can_trickle_ice_candidates())); |
deadbeef | 30952b4 | 2017-04-21 02:41:29 -0700 | [diff] [blame] | 3492 | std::unique_ptr<SessionDescriptionInterface> answer; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3493 | ASSERT_TRUE(DoCreateAnswer(&answer, &options)); |
deadbeef | 30952b4 | 2017-04-21 02:41:29 -0700 | [diff] [blame] | 3494 | desc = answer->description(); |
| 3495 | ASSERT_EQ(2u, desc->transport_infos().size()); |
| 3496 | EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle")); |
| 3497 | EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle")); |
| 3498 | } |
| 3499 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3500 | // Test that ICE renomination isn't offered if it's not enabled in the PC's |
| 3501 | // RTCConfiguration. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3502 | TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3503 | PeerConnectionInterface::RTCConfiguration config; |
| 3504 | config.enable_ice_renomination = false; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3505 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3506 | AddAudioTrack("foo"); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3507 | |
| 3508 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3509 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
| 3510 | cricket::SessionDescription* desc = offer->description(); |
| 3511 | EXPECT_EQ(1u, desc->transport_infos().size()); |
| 3512 | EXPECT_FALSE( |
| 3513 | desc->transport_infos()[0].description.GetIceParameters().renomination); |
| 3514 | } |
| 3515 | |
| 3516 | // Test that the ICE renomination option is present in generated offers/answers |
| 3517 | // if it's enabled in the PC's RTCConfiguration. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3518 | TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3519 | PeerConnectionInterface::RTCConfiguration config; |
| 3520 | config.enable_ice_renomination = true; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3521 | CreatePeerConnection(config); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3522 | AddAudioTrack("foo"); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3523 | |
| 3524 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3525 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
| 3526 | cricket::SessionDescription* desc = offer->description(); |
| 3527 | EXPECT_EQ(1u, desc->transport_infos().size()); |
| 3528 | EXPECT_TRUE( |
| 3529 | desc->transport_infos()[0].description.GetIceParameters().renomination); |
| 3530 | |
| 3531 | // Set the offer as a remote description, then create an answer and ensure it |
| 3532 | // has the renomination flag too. |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3533 | EXPECT_TRUE(DoSetRemoteDescription(std::move(offer))); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3534 | std::unique_ptr<SessionDescriptionInterface> answer; |
| 3535 | ASSERT_TRUE(DoCreateAnswer(&answer, nullptr)); |
| 3536 | desc = answer->description(); |
| 3537 | EXPECT_EQ(1u, desc->transport_infos().size()); |
| 3538 | EXPECT_TRUE( |
| 3539 | desc->transport_infos()[0].description.GetIceParameters().renomination); |
| 3540 | } |
| 3541 | |
| 3542 | // Test that if CreateOffer is called with the deprecated "offer to receive |
| 3543 | // audio/video" constraints, they're processed and result in an offer with |
| 3544 | // audio/video sections just as if RTCOfferAnswerOptions had been used. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3545 | TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3546 | CreatePeerConnection(); |
| 3547 | |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3548 | RTCOfferAnswerOptions options; |
| 3549 | options.offer_to_receive_audio = 1; |
| 3550 | options.offer_to_receive_video = 1; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3551 | std::unique_ptr<SessionDescriptionInterface> offer; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3552 | ASSERT_TRUE(DoCreateOffer(&offer, &options)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3553 | |
| 3554 | cricket::SessionDescription* desc = offer->description(); |
| 3555 | const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc); |
| 3556 | const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc); |
| 3557 | ASSERT_NE(nullptr, audio); |
| 3558 | ASSERT_NE(nullptr, video); |
| 3559 | EXPECT_FALSE(audio->rejected); |
| 3560 | EXPECT_FALSE(video->rejected); |
| 3561 | } |
| 3562 | |
| 3563 | // Test that if CreateAnswer is called with the deprecated "offer to receive |
| 3564 | // audio/video" constraints, they're processed and can be used to reject an |
| 3565 | // offered m= section just as can be done with RTCOfferAnswerOptions; |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3566 | // Don't run under Unified Plan since this behavior is not supported. |
| 3567 | TEST_F(PeerConnectionInterfaceTestPlanB, |
| 3568 | CreateAnswerWithOfferToReceiveConstraints) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3569 | CreatePeerConnection(); |
| 3570 | |
| 3571 | // First, create an offer with audio/video and apply it as a remote |
| 3572 | // description. |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3573 | RTCOfferAnswerOptions options; |
| 3574 | options.offer_to_receive_audio = 1; |
| 3575 | options.offer_to_receive_video = 1; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3576 | std::unique_ptr<SessionDescriptionInterface> offer; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3577 | ASSERT_TRUE(DoCreateOffer(&offer, &options)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3578 | EXPECT_TRUE(DoSetRemoteDescription(std::move(offer))); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3579 | |
| 3580 | // Now create answer that rejects audio/video. |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3581 | options.offer_to_receive_audio = 0; |
| 3582 | options.offer_to_receive_video = 0; |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3583 | std::unique_ptr<SessionDescriptionInterface> answer; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3584 | ASSERT_TRUE(DoCreateAnswer(&answer, &options)); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3585 | |
| 3586 | cricket::SessionDescription* desc = answer->description(); |
| 3587 | const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc); |
| 3588 | const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc); |
| 3589 | ASSERT_NE(nullptr, audio); |
| 3590 | ASSERT_NE(nullptr, video); |
| 3591 | EXPECT_TRUE(audio->rejected); |
| 3592 | EXPECT_TRUE(video->rejected); |
| 3593 | } |
| 3594 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3595 | // Test that negotiation can succeed with a data channel only, and with the max |
| 3596 | // bundle policy. Previously there was a bug that prevented this. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3597 | #ifdef HAVE_SCTP |
| 3598 | TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) { |
| 3599 | #else |
| 3600 | TEST_P(PeerConnectionInterfaceTest, |
| 3601 | DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) { |
| 3602 | #endif // HAVE_SCTP |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3603 | PeerConnectionInterface::RTCConfiguration config; |
| 3604 | config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3605 | CreatePeerConnection(config); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3606 | |
| 3607 | // First, create an offer with only a data channel and apply it as a remote |
| 3608 | // description. |
| 3609 | pc_->CreateDataChannel("test", nullptr); |
| 3610 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3611 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3612 | EXPECT_TRUE(DoSetRemoteDescription(std::move(offer))); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3613 | |
| 3614 | // Create and set answer as well. |
| 3615 | std::unique_ptr<SessionDescriptionInterface> answer; |
| 3616 | ASSERT_TRUE(DoCreateAnswer(&answer, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3617 | EXPECT_TRUE(DoSetLocalDescription(std::move(answer))); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3618 | } |
| 3619 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3620 | TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) { |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3621 | CreatePeerConnection(); |
| 3622 | PeerConnectionInterface::BitrateParameters bitrate; |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 3623 | bitrate.current_bitrate_bps = 100000; |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3624 | EXPECT_TRUE(pc_->SetBitrate(bitrate).ok()); |
| 3625 | } |
| 3626 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3627 | TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) { |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3628 | CreatePeerConnection(); |
| 3629 | PeerConnectionInterface::BitrateParameters bitrate; |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 3630 | bitrate.min_bitrate_bps = -1; |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3631 | EXPECT_FALSE(pc_->SetBitrate(bitrate).ok()); |
| 3632 | } |
| 3633 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3634 | TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) { |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3635 | CreatePeerConnection(); |
| 3636 | PeerConnectionInterface::BitrateParameters bitrate; |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 3637 | bitrate.min_bitrate_bps = 5; |
| 3638 | bitrate.current_bitrate_bps = 3; |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3639 | EXPECT_FALSE(pc_->SetBitrate(bitrate).ok()); |
| 3640 | } |
| 3641 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3642 | TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) { |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3643 | CreatePeerConnection(); |
| 3644 | PeerConnectionInterface::BitrateParameters bitrate; |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 3645 | bitrate.current_bitrate_bps = -1; |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3646 | EXPECT_FALSE(pc_->SetBitrate(bitrate).ok()); |
| 3647 | } |
| 3648 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3649 | TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) { |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3650 | CreatePeerConnection(); |
| 3651 | PeerConnectionInterface::BitrateParameters bitrate; |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 3652 | bitrate.current_bitrate_bps = 10; |
| 3653 | bitrate.max_bitrate_bps = 8; |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3654 | EXPECT_FALSE(pc_->SetBitrate(bitrate).ok()); |
| 3655 | } |
| 3656 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3657 | TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) { |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3658 | CreatePeerConnection(); |
| 3659 | PeerConnectionInterface::BitrateParameters bitrate; |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 3660 | bitrate.min_bitrate_bps = 10; |
| 3661 | bitrate.max_bitrate_bps = 8; |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3662 | EXPECT_FALSE(pc_->SetBitrate(bitrate).ok()); |
| 3663 | } |
| 3664 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3665 | TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) { |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3666 | CreatePeerConnection(); |
| 3667 | PeerConnectionInterface::BitrateParameters bitrate; |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 3668 | bitrate.max_bitrate_bps = -1; |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3669 | EXPECT_FALSE(pc_->SetBitrate(bitrate).ok()); |
| 3670 | } |
| 3671 | |
Niels Möller | 0c4f7be | 2018-05-07 14:01:37 +0200 | [diff] [blame] | 3672 | // The current bitrate from BitrateSettings is currently clamped |
Sebastian Jansson | fc8d26b | 2018-02-21 09:52:06 +0100 | [diff] [blame] | 3673 | // by Call's BitrateConstraints, which comes from the SDP or a default value. |
| 3674 | // This test checks that a call to SetBitrate with a current bitrate that will |
| 3675 | // be clamped succeeds. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3676 | TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) { |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3677 | CreatePeerConnection(); |
| 3678 | PeerConnectionInterface::BitrateParameters bitrate; |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 3679 | bitrate.current_bitrate_bps = 1; |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3680 | EXPECT_TRUE(pc_->SetBitrate(bitrate).ok()); |
| 3681 | } |
| 3682 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3683 | // The following tests verify that the offer can be created correctly. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3684 | TEST_P(PeerConnectionInterfaceTest, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3685 | CreateOfferFailsWithInvalidOfferToReceiveAudio) { |
| 3686 | RTCOfferAnswerOptions rtc_options; |
| 3687 | |
| 3688 | // Setting offer_to_receive_audio to a value lower than kUndefined or greater |
| 3689 | // than kMaxOfferToReceiveMedia should be treated as invalid. |
| 3690 | rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1; |
| 3691 | CreatePeerConnection(); |
| 3692 | EXPECT_FALSE(CreateOfferWithOptions(rtc_options)); |
| 3693 | |
| 3694 | rtc_options.offer_to_receive_audio = |
| 3695 | RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1; |
| 3696 | EXPECT_FALSE(CreateOfferWithOptions(rtc_options)); |
| 3697 | } |
| 3698 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3699 | TEST_P(PeerConnectionInterfaceTest, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3700 | CreateOfferFailsWithInvalidOfferToReceiveVideo) { |
| 3701 | RTCOfferAnswerOptions rtc_options; |
| 3702 | |
| 3703 | // Setting offer_to_receive_video to a value lower than kUndefined or greater |
| 3704 | // than kMaxOfferToReceiveMedia should be treated as invalid. |
| 3705 | rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1; |
| 3706 | CreatePeerConnection(); |
| 3707 | EXPECT_FALSE(CreateOfferWithOptions(rtc_options)); |
| 3708 | |
| 3709 | rtc_options.offer_to_receive_video = |
| 3710 | RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1; |
| 3711 | EXPECT_FALSE(CreateOfferWithOptions(rtc_options)); |
| 3712 | } |
| 3713 | |
| 3714 | // Test that the audio and video content will be added to an offer if both |
| 3715 | // |offer_to_receive_audio| and |offer_to_receive_video| options are 1. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3716 | TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3717 | RTCOfferAnswerOptions rtc_options; |
| 3718 | rtc_options.offer_to_receive_audio = 1; |
| 3719 | rtc_options.offer_to_receive_video = 1; |
| 3720 | |
| 3721 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3722 | CreatePeerConnection(); |
| 3723 | offer = CreateOfferWithOptions(rtc_options); |
| 3724 | ASSERT_TRUE(offer); |
| 3725 | EXPECT_NE(nullptr, GetFirstAudioContent(offer->description())); |
| 3726 | EXPECT_NE(nullptr, GetFirstVideoContent(offer->description())); |
| 3727 | } |
| 3728 | |
| 3729 | // Test that only audio content will be added to the offer if only |
| 3730 | // |offer_to_receive_audio| options is 1. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3731 | TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3732 | RTCOfferAnswerOptions rtc_options; |
| 3733 | rtc_options.offer_to_receive_audio = 1; |
| 3734 | rtc_options.offer_to_receive_video = 0; |
| 3735 | |
| 3736 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3737 | CreatePeerConnection(); |
| 3738 | offer = CreateOfferWithOptions(rtc_options); |
| 3739 | ASSERT_TRUE(offer); |
| 3740 | EXPECT_NE(nullptr, GetFirstAudioContent(offer->description())); |
| 3741 | EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description())); |
| 3742 | } |
| 3743 | |
| 3744 | // Test that only video content will be added if only |offer_to_receive_video| |
| 3745 | // options is 1. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3746 | TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3747 | RTCOfferAnswerOptions rtc_options; |
| 3748 | rtc_options.offer_to_receive_audio = 0; |
| 3749 | rtc_options.offer_to_receive_video = 1; |
| 3750 | |
| 3751 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3752 | CreatePeerConnection(); |
| 3753 | offer = CreateOfferWithOptions(rtc_options); |
| 3754 | ASSERT_TRUE(offer); |
| 3755 | EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description())); |
| 3756 | EXPECT_NE(nullptr, GetFirstVideoContent(offer->description())); |
| 3757 | } |
| 3758 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3759 | // Test that no media content will be added to the offer if using default |
| 3760 | // RTCOfferAnswerOptions. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3761 | TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3762 | RTCOfferAnswerOptions rtc_options; |
| 3763 | |
| 3764 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3765 | CreatePeerConnection(); |
| 3766 | offer = CreateOfferWithOptions(rtc_options); |
| 3767 | ASSERT_TRUE(offer); |
| 3768 | EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description())); |
| 3769 | EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description())); |
| 3770 | } |
| 3771 | |
| 3772 | // Test that if |ice_restart| is true, the ufrag/pwd will change, otherwise |
| 3773 | // ufrag/pwd will be the same in the new offer. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3774 | TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) { |
| 3775 | CreatePeerConnection(); |
| 3776 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3777 | RTCOfferAnswerOptions rtc_options; |
| 3778 | rtc_options.ice_restart = false; |
| 3779 | rtc_options.offer_to_receive_audio = 1; |
| 3780 | |
| 3781 | std::unique_ptr<SessionDescriptionInterface> offer; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3782 | CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3783 | std::string mid = cricket::GetFirstAudioContent(offer->description())->name; |
| 3784 | auto ufrag1 = |
| 3785 | offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag; |
| 3786 | auto pwd1 = |
| 3787 | offer->description()->GetTransportInfoByName(mid)->description.ice_pwd; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3788 | |
| 3789 | // |ice_restart| is false, the ufrag/pwd shouldn't change. |
| 3790 | CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3791 | auto ufrag2 = |
| 3792 | offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag; |
| 3793 | auto pwd2 = |
| 3794 | offer->description()->GetTransportInfoByName(mid)->description.ice_pwd; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3795 | |
| 3796 | // |ice_restart| is true, the ufrag/pwd should change. |
| 3797 | rtc_options.ice_restart = true; |
| 3798 | CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3799 | auto ufrag3 = |
| 3800 | offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag; |
| 3801 | auto pwd3 = |
| 3802 | offer->description()->GetTransportInfoByName(mid)->description.ice_pwd; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3803 | |
| 3804 | EXPECT_EQ(ufrag1, ufrag2); |
| 3805 | EXPECT_EQ(pwd1, pwd2); |
| 3806 | EXPECT_NE(ufrag2, ufrag3); |
| 3807 | EXPECT_NE(pwd2, pwd3); |
| 3808 | } |
| 3809 | |
| 3810 | // Test that if |use_rtp_mux| is true, the bundling will be enabled in the |
| 3811 | // offer; if it is false, there won't be any bundle group in the offer. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3812 | TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3813 | RTCOfferAnswerOptions rtc_options; |
| 3814 | rtc_options.offer_to_receive_audio = 1; |
| 3815 | rtc_options.offer_to_receive_video = 1; |
| 3816 | |
| 3817 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3818 | CreatePeerConnection(); |
| 3819 | |
| 3820 | rtc_options.use_rtp_mux = true; |
| 3821 | offer = CreateOfferWithOptions(rtc_options); |
| 3822 | ASSERT_TRUE(offer); |
| 3823 | EXPECT_NE(nullptr, GetFirstAudioContent(offer->description())); |
| 3824 | EXPECT_NE(nullptr, GetFirstVideoContent(offer->description())); |
| 3825 | EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE)); |
| 3826 | |
| 3827 | rtc_options.use_rtp_mux = false; |
| 3828 | offer = CreateOfferWithOptions(rtc_options); |
| 3829 | ASSERT_TRUE(offer); |
| 3830 | EXPECT_NE(nullptr, GetFirstAudioContent(offer->description())); |
| 3831 | EXPECT_NE(nullptr, GetFirstVideoContent(offer->description())); |
| 3832 | EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE)); |
| 3833 | } |
| 3834 | |
zhihuang | 141aacb | 2017-08-29 13:23:53 -0700 | [diff] [blame] | 3835 | // This test ensures OnRenegotiationNeeded is called when we add track with |
| 3836 | // MediaStream -> AddTrack in the same way it is called when we add track with |
| 3837 | // PeerConnection -> AddTrack. |
| 3838 | // The test can be removed once addStream is rewritten in terms of addTrack |
| 3839 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=7815 |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3840 | // Don't run under Unified Plan since the stream API is not available. |
| 3841 | TEST_F(PeerConnectionInterfaceTestPlanB, |
| 3842 | MediaStreamAddTrackRemoveTrackRenegotiate) { |
zhihuang | 141aacb | 2017-08-29 13:23:53 -0700 | [diff] [blame] | 3843 | CreatePeerConnectionWithoutDtls(); |
| 3844 | rtc::scoped_refptr<MediaStreamInterface> stream( |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 3845 | pc_factory_->CreateLocalMediaStream(kStreamId1)); |
zhihuang | 141aacb | 2017-08-29 13:23:53 -0700 | [diff] [blame] | 3846 | pc_->AddStream(stream); |
| 3847 | rtc::scoped_refptr<AudioTrackInterface> audio_track( |
Niels Möller | 215ba60 | 2019-01-18 13:59:45 +0100 | [diff] [blame] | 3848 | CreateAudioTrack("audio_track")); |
zhihuang | 141aacb | 2017-08-29 13:23:53 -0700 | [diff] [blame] | 3849 | rtc::scoped_refptr<VideoTrackInterface> video_track( |
Niels Möller | 215ba60 | 2019-01-18 13:59:45 +0100 | [diff] [blame] | 3850 | CreateVideoTrack("video_track")); |
zhihuang | 141aacb | 2017-08-29 13:23:53 -0700 | [diff] [blame] | 3851 | stream->AddTrack(audio_track); |
| 3852 | EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); |
| 3853 | observer_.renegotiation_needed_ = false; |
| 3854 | |
Guido Urdaneta | 70c2db1 | 2019-04-16 12:24:14 +0200 | [diff] [blame] | 3855 | CreateOfferReceiveAnswer(); |
zhihuang | 141aacb | 2017-08-29 13:23:53 -0700 | [diff] [blame] | 3856 | stream->AddTrack(video_track); |
| 3857 | EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); |
| 3858 | observer_.renegotiation_needed_ = false; |
| 3859 | |
Guido Urdaneta | 70c2db1 | 2019-04-16 12:24:14 +0200 | [diff] [blame] | 3860 | CreateOfferReceiveAnswer(); |
zhihuang | 141aacb | 2017-08-29 13:23:53 -0700 | [diff] [blame] | 3861 | stream->RemoveTrack(audio_track); |
| 3862 | EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); |
| 3863 | observer_.renegotiation_needed_ = false; |
| 3864 | |
Guido Urdaneta | 70c2db1 | 2019-04-16 12:24:14 +0200 | [diff] [blame] | 3865 | CreateOfferReceiveAnswer(); |
zhihuang | 141aacb | 2017-08-29 13:23:53 -0700 | [diff] [blame] | 3866 | stream->RemoveTrack(video_track); |
| 3867 | EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); |
| 3868 | observer_.renegotiation_needed_ = false; |
| 3869 | } |
| 3870 | |
Zhi Huang | b2d355e | 2017-10-26 17:26:37 -0700 | [diff] [blame] | 3871 | // Tests that an error is returned if a description is applied that has fewer |
| 3872 | // media sections than the existing description. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3873 | TEST_P(PeerConnectionInterfaceTest, |
Zhi Huang | b2d355e | 2017-10-26 17:26:37 -0700 | [diff] [blame] | 3874 | MediaSectionCountEnforcedForSubsequentOffer) { |
| 3875 | CreatePeerConnection(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3876 | AddAudioTrack("audio_label"); |
| 3877 | AddVideoTrack("video_label"); |
| 3878 | |
Zhi Huang | b2d355e | 2017-10-26 17:26:37 -0700 | [diff] [blame] | 3879 | std::unique_ptr<SessionDescriptionInterface> offer; |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3880 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Zhi Huang | b2d355e | 2017-10-26 17:26:37 -0700 | [diff] [blame] | 3881 | EXPECT_TRUE(DoSetRemoteDescription(std::move(offer))); |
| 3882 | |
| 3883 | // A remote offer with fewer media sections should be rejected. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3884 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Zhi Huang | b2d355e | 2017-10-26 17:26:37 -0700 | [diff] [blame] | 3885 | offer->description()->contents().pop_back(); |
| 3886 | offer->description()->contents().pop_back(); |
| 3887 | ASSERT_TRUE(offer->description()->contents().empty()); |
| 3888 | EXPECT_FALSE(DoSetRemoteDescription(std::move(offer))); |
| 3889 | |
| 3890 | std::unique_ptr<SessionDescriptionInterface> answer; |
| 3891 | ASSERT_TRUE(DoCreateAnswer(&answer, nullptr)); |
| 3892 | EXPECT_TRUE(DoSetLocalDescription(std::move(answer))); |
| 3893 | |
| 3894 | // A subsequent local offer with fewer media sections should be rejected. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3895 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Zhi Huang | b2d355e | 2017-10-26 17:26:37 -0700 | [diff] [blame] | 3896 | offer->description()->contents().pop_back(); |
| 3897 | offer->description()->contents().pop_back(); |
| 3898 | ASSERT_TRUE(offer->description()->contents().empty()); |
| 3899 | EXPECT_FALSE(DoSetLocalDescription(std::move(offer))); |
| 3900 | } |
| 3901 | |
Johannes Kron | 89f874e | 2018-11-12 10:25:48 +0100 | [diff] [blame] | 3902 | TEST_P(PeerConnectionInterfaceTest, ExtmapAllowMixedIsConfigurable) { |
| 3903 | RTCConfiguration config; |
| 3904 | // Default behavior is false. |
| 3905 | CreatePeerConnection(config); |
| 3906 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3907 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
| 3908 | EXPECT_FALSE(offer->description()->extmap_allow_mixed()); |
| 3909 | // Possible to set to true. |
| 3910 | config.offer_extmap_allow_mixed = true; |
| 3911 | CreatePeerConnection(config); |
| 3912 | offer.release(); |
| 3913 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
| 3914 | EXPECT_TRUE(offer->description()->extmap_allow_mixed()); |
| 3915 | } |
| 3916 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 3917 | INSTANTIATE_TEST_SUITE_P(PeerConnectionInterfaceTest, |
| 3918 | PeerConnectionInterfaceTest, |
| 3919 | Values(SdpSemantics::kPlanB, |
| 3920 | SdpSemantics::kUnifiedPlan)); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3921 | |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 3922 | class PeerConnectionMediaConfigTest : public ::testing::Test { |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3923 | protected: |
| 3924 | void SetUp() override { |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 3925 | pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest(); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3926 | pcf_->Initialize(); |
| 3927 | } |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 3928 | const cricket::MediaConfig TestCreatePeerConnection( |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3929 | const RTCConfiguration& config) { |
| 3930 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
| 3931 | pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_)); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3932 | EXPECT_TRUE(pc.get()); |
Yves Gerey | f3ff14c | 2018-10-25 10:28:12 +0200 | [diff] [blame] | 3933 | observer_.SetPeerConnectionInterface(pc.get()); |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 3934 | return pc->GetConfiguration().media_config; |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3935 | } |
| 3936 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 3937 | rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_; |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3938 | MockPeerConnectionObserver observer_; |
| 3939 | }; |
| 3940 | |
Yves Gerey | f3ff14c | 2018-10-25 10:28:12 +0200 | [diff] [blame] | 3941 | // This sanity check validates the test infrastructure itself. |
| 3942 | TEST_F(PeerConnectionMediaConfigTest, TestCreateAndClose) { |
| 3943 | PeerConnectionInterface::RTCConfiguration config; |
| 3944 | rtc::scoped_refptr<PeerConnectionInterface> pc( |
| 3945 | pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_)); |
| 3946 | EXPECT_TRUE(pc.get()); |
| 3947 | observer_.SetPeerConnectionInterface(pc.get()); // Required. |
| 3948 | pc->Close(); // No abort -> ok. |
| 3949 | SUCCEED(); |
| 3950 | } |
| 3951 | |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3952 | // This test verifies the default behaviour with no constraints and a |
| 3953 | // default RTCConfiguration. |
| 3954 | TEST_F(PeerConnectionMediaConfigTest, TestDefaults) { |
| 3955 | PeerConnectionInterface::RTCConfiguration config; |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3956 | |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3957 | const cricket::MediaConfig& media_config = TestCreatePeerConnection(config); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3958 | |
| 3959 | EXPECT_FALSE(media_config.enable_dscp); |
Niels Möller | 1d7ecd2 | 2018-01-18 15:25:12 +0100 | [diff] [blame] | 3960 | EXPECT_TRUE(media_config.video.enable_cpu_adaptation); |
| 3961 | EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing); |
nisse | 0db023a | 2016-03-01 04:29:59 -0800 | [diff] [blame] | 3962 | EXPECT_FALSE(media_config.video.suspend_below_min_bitrate); |
Niels Möller | 6539f69 | 2018-01-18 08:58:50 +0100 | [diff] [blame] | 3963 | EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3964 | } |
| 3965 | |
Niels Möller | 1d7ecd2 | 2018-01-18 15:25:12 +0100 | [diff] [blame] | 3966 | // This test verifies that the enable_prerenderer_smoothing flag is |
nisse | 528b793 | 2017-05-08 03:21:43 -0700 | [diff] [blame] | 3967 | // propagated from RTCConfiguration to the PeerConnection. |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3968 | TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) { |
| 3969 | PeerConnectionInterface::RTCConfiguration config; |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3970 | |
Niels Möller | 71bdda0 | 2016-03-31 12:59:59 +0200 | [diff] [blame] | 3971 | config.set_prerenderer_smoothing(false); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3972 | const cricket::MediaConfig& media_config = TestCreatePeerConnection(config); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3973 | |
Niels Möller | 1d7ecd2 | 2018-01-18 15:25:12 +0100 | [diff] [blame] | 3974 | EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing); |
nisse | 0db023a | 2016-03-01 04:29:59 -0800 | [diff] [blame] | 3975 | } |
| 3976 | |
Niels Möller | 6539f69 | 2018-01-18 08:58:50 +0100 | [diff] [blame] | 3977 | // This test verifies that the experiment_cpu_load_estimator flag is |
| 3978 | // propagated from RTCConfiguration to the PeerConnection. |
| 3979 | TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) { |
| 3980 | PeerConnectionInterface::RTCConfiguration config; |
Niels Möller | 6539f69 | 2018-01-18 08:58:50 +0100 | [diff] [blame] | 3981 | |
| 3982 | config.set_experiment_cpu_load_estimator(true); |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 3983 | const cricket::MediaConfig& media_config = TestCreatePeerConnection(config); |
Niels Möller | 6539f69 | 2018-01-18 08:58:50 +0100 | [diff] [blame] | 3984 | |
| 3985 | EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator); |
| 3986 | } |
| 3987 | |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 3988 | // Tests a few random fields being different. |
| 3989 | TEST(RTCConfigurationTest, ComparisonOperators) { |
| 3990 | PeerConnectionInterface::RTCConfiguration a; |
| 3991 | PeerConnectionInterface::RTCConfiguration b; |
| 3992 | EXPECT_EQ(a, b); |
| 3993 | |
| 3994 | PeerConnectionInterface::RTCConfiguration c; |
| 3995 | c.servers.push_back(PeerConnectionInterface::IceServer()); |
| 3996 | EXPECT_NE(a, c); |
| 3997 | |
| 3998 | PeerConnectionInterface::RTCConfiguration d; |
| 3999 | d.type = PeerConnectionInterface::kRelay; |
| 4000 | EXPECT_NE(a, d); |
| 4001 | |
| 4002 | PeerConnectionInterface::RTCConfiguration e; |
| 4003 | e.audio_jitter_buffer_max_packets = 5; |
| 4004 | EXPECT_NE(a, e); |
| 4005 | |
| 4006 | PeerConnectionInterface::RTCConfiguration f; |
| 4007 | f.ice_connection_receiving_timeout = 1337; |
| 4008 | EXPECT_NE(a, f); |
| 4009 | |
| 4010 | PeerConnectionInterface::RTCConfiguration g; |
| 4011 | g.disable_ipv6 = true; |
| 4012 | EXPECT_NE(a, g); |
| 4013 | |
| 4014 | PeerConnectionInterface::RTCConfiguration h( |
| 4015 | PeerConnectionInterface::RTCConfigurationType::kAggressive); |
| 4016 | EXPECT_NE(a, h); |
| 4017 | } |
Mirko Bonadei | ab64e8a | 2018-12-12 12:10:18 +0100 | [diff] [blame] | 4018 | |
| 4019 | } // namespace |
| 4020 | } // namespace webrtc |