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