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